scope DeathCoil initializer Init
// It requires TimerUtils
globals
private constant integer ABIL_CODE='AHtb'
endglobals
private struct Data
unit u
unit t
player p
group g
private static method Remove takes nothing returns nothing
call RemoveUnit(GetEnumUnit())
endmethod
private static method expire2 takes nothing returns nothing
local timer tmr=GetExpiredTimer()
local thistype this=GetTimerData(tmr)
call ForGroup(g,function Data.Remove)
call PauseUnit(u,false)
call ReleaseTimer(tmr)
set tmr=null
endmethod
static method expire takes nothing returns nothing
local timer tmr=GetExpiredTimer()
local timer tmr2=NewTimer()
local thistype this=GetTimerData(tmr)
local integer i=1
local unit v
loop
exitwhen i>20
// I didn't use my World editor, so there may be syntax errors here :P
set v=CreateUnit(Player(12),'h000',GetUnitX(u)+300.*Sin(i*18.0*bj_DEGTORAD),GetUnitY(u)+300.*Cos(i*18.0*bj_DEGTORAD),270.)
call GroupAddUnit(g,v)
call IssueTargetOrder(v,"deathcoil",t)
set i=i+1
endloop
call ReleaseTimer(tmr)
call SetTimerData(tmr2,this)
call TimerStart(tmr2,0.75,false,function Data.expire2)
set tmr=null
set tmr2=null
set v=null
endmethod
static method create takes unit v, unit w returns thistype
local thistype this=thistype.allocate()
set this.u=v
set this.t=w
set this.p=GetOwningPlayer(this.u)
set this.g=CreateGroup()
return this
endmethod
method destroy takes nothing returns nothing
set this.u=null
set this.t=null
set this.p=null
call DestroyGroup(this.g)
call this.deallocate()
endmethod
endstruct
private function Actions takes nothing returns nothing
local Data d=Data.create(GetTriggerUnit(),GetSpellTargetUnit())
local timer t=NewTimer()
call PauseUnit(d.t,true)
call SetTimerData(t,d)
call TimerStart(t,0.5,false,function Data.expire)
set t=null
endfunction
private function Cond takes nothing returns boolean
return GetSpellAbilityId()==ABIL_CODE
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t,Condition(function Cond))
call TriggerAddAction(t,function Actions)
set t=null
endfunction
endscope