scope TimeBomb initializer Init
globals
//ability that is used to palce bombs (single target)
private constant integer TRIGGER_SPELL = 'A000'
//ability the bombed unit has to display the buff (tornado slow aura)
private constant integer BUFF_SPELL = 'A001'
private constant attacktype ATTACK_TYPE = ATTACK_TYPE_NORMAL
private constant damagetype DAMAGE_TYPE = DAMAGE_TYPE_MAGIC
endglobals
private function GetBombDelay takes integer level returns real
return 5.-1*level
endfunction
private function GetBombTargetDamage takes integer level returns real
return 50.*level
endfunction
private function GetBombAOEDamage takes integer level returns real
return 50.*level
endfunction
private function GetBombAOERange takes integer level returns real
return 150.+50*level
endfunction
//Return true, if the target should be damaged by the area of effect
private function AllowedTargets takes unit caster, unit target returns boolean
return TRUE
endfunction
/*====================================================================
======================= END OF CONFIGURATION =========================
====================================================================*/
globals
private hashtable hash
private group bombedUnits
endglobals
private function DeathConditions takes nothing returns boolean
return IsUnitInGroup(GetTriggerUnit(), bombedUnits)
endfunction
private function DeathActions takes nothing returns nothing
local unit target = GetTriggerUnit()
call UnitRemoveAbility(target, BUFF_SPELL)
call FlushChildHashtable(hash, GetHandleId(target))
call GroupRemoveUnit(bombedUnits, target)
set target = null
endfunction
private function Conditions takes nothing returns boolean
return GetSpellAbilityId() == TRIGGER_SPELL
endfunction
private function Explode takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer h = GetHandleId(t)
local unit caster = LoadUnitHandle(hash, h, 0)
local unit target = LoadUnitHandle(hash, h, 1)
local integer level = LoadInteger(hash, h, 2)
local group g = CreateGroup()
local unit u
local integer bombCount
if(not IsUnitInGroup(target, bombedUnits)) then
call PauseTimer(t)
call DestroyTimer(t)
call DestroyGroup(g)
set u = null
set g = null
set caster = null
set target = null
set t = null
return
endif
call UnitDamageTarget(caster, target, GetBombTargetDamage(level), TRUE, FALSE, ATTACK_TYPE, DAMAGE_TYPE, WEAPON_TYPE_WHOKNOWS)
call GroupEnumUnitsInRange(g, GetUnitX(target), GetUnitY(target), GetBombAOERange(level), null)
loop
set u = FirstOfGroup(g)
exitwhen u == null
call GroupRemoveUnit(g, u)
if(AllowedTargets(caster, u) )then
call UnitDamageTarget(caster, u, GetBombAOEDamage(level), TRUE, FALSE, ATTACK_TYPE, DAMAGE_TYPE, WEAPON_TYPE_WHOKNOWS)
endif
endloop
call FlushChildHashtable(hash, h)
set h = GetHandleId(target)
set bombCount = LoadInteger(hash, h, 0)-1
call SaveInteger(hash, h, 0, bombCount)
if(bombCount == 0) then
call UnitRemoveAbility(target, BUFF_SPELL)
call FlushChildHashtable(hash, h)
call GroupRemoveUnit(bombedUnits, target)
endif
call PauseTimer(t)
call DestroyTimer(t)
call DestroyGroup(g)
set u = null
set g = null
set caster = null
set target = null
set t = null
endfunction
private function Actions takes nothing returns nothing
local unit caster = GetTriggerUnit()
local unit target = GetSpellTargetUnit()
local integer level = GetUnitAbilityLevel(caster, TRIGGER_SPELL)
local timer t = CreateTimer()
local integer h = GetHandleId(t)
call TimerStart(t, GetBombDelay(level), FALSE, function Explode)
call SaveUnitHandle(hash, h, 0, caster)
call SaveUnitHandle(hash, h, 1, target)
call SaveInteger(hash, h, 2, level)
call UnitAddAbility(target, BUFF_SPELL)
set h = GetHandleId(target)
call SaveInteger(hash, h, 0, LoadInteger(hash, h, 0)+1)
call GroupAddUnit(bombedUnits, target)
set caster = null
set target = null
set t = null
endfunction
private function Init takes nothing returns nothing
local trigger trg = CreateTrigger( )
local integer i = 0
call TriggerRegisterAnyUnitEventBJ( trg, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( trg, Condition( function Conditions ) )
call TriggerAddAction( trg, function Actions )
set trg = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( trg, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition( trg, Condition( function DeathConditions ) )
call TriggerAddAction( trg, function DeathActions )
set hash = InitHashtable()
set bombedUnits = CreateGroup()
set trg = null
endfunction
endscope