function FilterTargets takes nothing returns boolean
if not IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) then //is hero?
return FALSE
elseif not IsUnitAlly(GetFilterUnit(), GetTriggerPlayer()) then //is an ally?
return FALSE
elseif not UnitHasBuffBJ(GetFilterUnit(), 'B000') then //has buff?
return FALSE
elseif not (GetUnitLifePercent(GetFilterUnit()) < GetUnitLifePercent(GetTriggerUnit())) then //has less hp then caster?
return FALSE
else
return TRUE
endif
endfunction
function Trig_BloodTransfusion_Conditions takes nothing returns boolean
return ((GetUnitAbilityLevel(GetTriggerUnit(), 'A000') == 1) and (GetUnitTypeId(GetTriggerUnit()) == 'O000' ))
endfunction
function Trig_BloodTransfusion_Actions takes nothing returns nothing
local unit caster = GetTriggerUnit()
local unit target
local integer abilityLevel = GetUnitAbilityLevel(caster, 'A000')
local group targetGroup = CreateGroup()
local real points
local real casterHP
local real casterMP
local filterfunc filter
set filter = Filter(function FilterTargets)
loop
set casterHP = GetUnitState(caster, UNIT_STATE_LIFE)
set casterMP = GetUnitState(caster, UNIT_STATE_MANA)
set points = 0.01 * abilityLevel * GetUnitState(caster, UNIT_STATE_MAX_LIFE)
call GroupEnumUnitsInRect(targetGroup, GetPlayableMapRect(), filter)
if CountUnitsInGroup(targetGroup) > 0 then
loop
set target = GroupPickRandomUnit(targetGroup)
call SetUnitLifeBJ(caster, casterHP - points)
call SetUnitLifeBJ(target, GetUnitState(target, UNIT_STATE_LIFE) + points)
call AddSpecialEffectTarget("Abilities\\Spells\\Human\\Feedback\\SpellBreakerAttack.mdl", target, "overhead")
call AddSpecialEffectTarget("Objects\\Spawnmodels\\Human\\HumanBlood\\HumanBloodPriest.mdl", caster, "chest")
call GroupRemoveUnit(targetGroup, target)
exitwhen CountUnitsInGroup(targetGroup) == 0
endloop
elseif GetUnitLifePercent(caster) > GetUnitManaPercent(caster)+1+abilityLevel then
call SetUnitLifeBJ(caster, casterHP - points)
call SetUnitManaBJ(caster, casterMP + points)
call AddSpecialEffectTarget("Abilities\\Weapons\\HydraliskImpact\\HydraliskImpact.mdl", caster, "chest")
endif
exitwhen GetUnitState(caster, UNIT_STATE_LIFE) <= 0
call DestroyFilter(filter)
call TriggerSleepAction(2.0)
endloop
endfunction
//===========================================================================
function InitTrig_Blood_Transfusion takes nothing returns nothing
set gg_trg_Blood_Transfusion = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( gg_trg_Blood_Transfusion, EVENT_PLAYER_HERO_SKILL )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Blood_Transfusion, EVENT_PLAYER_HERO_REVIVE_FINISH )
call TriggerAddCondition( gg_trg_Blood_Transfusion, Condition( function Trig_BloodTransfusion_Conditions ))
call TriggerAddAction( gg_trg_Blood_Transfusion, function Trig_BloodTransfusion_Actions )
endfunction