library TauntSystem uses Table
globals
private constant real PERIOD = 0.05
endglobals
struct Taunt extends array
implement Alloc
private unit u
private unit targetUnit
private real dur
private thistype next
private thistype prev
private static Table table
private method destroy takes nothing returns nothing
/*
Taunt buff based on Slow Aura
call UnitMakeAbilityPermanent(this.u,false,'A50Z')
call UnitRemoveAbility(this.u,'A50Z')
*/
call IssueImmediateOrder(this.u,"stop")
set this.prev.next = this.next
set this.next.prev = this.prev
call this.table.remove(GetHandleId(this.u))
call this.deallocate()
endmethod
static method iterate takes nothing returns nothing
local thistype this = thistype(0)
loop
set this = this.next
exitwhen this == 0
if this.dur <= 0 or not UnitAlive(this.u) then
call this.destroy()
else
call IssueTargetOrder(this.u, "attack", this.targetUnit)
set this.dur = this.dur - PERIOD
endif
endloop
endmethod
static method remove takes unit u returns nothing
local integer id = GetHandleId(u)
if thistype.table.has(id) then
call thistype(thistype.table[id]).destroy()
endif
endmethod
static method get takes unit u returns real
local integer id = GetHandleId(u)
if thistype.table.has(id) then
return thistype(thistype.table[id]).dur
else
return 0.
endif
endmethod
static method add takes unit u,unit target, real dur returns nothing
local thistype this
local integer id = GetHandleId(u)
if target==null then
return
endif
if dur > 0 then
if thistype.table.has(id) then
set this = thistype.table[id]
else
set this = thistype.allocate()
set thistype(0).next.prev = this
set this.next = thistype(0).next
set thistype(0).next = this
set this.prev = thistype(0)
set thistype.table[id] = this
set this.u = u
set this.dur = 0
/*
Taunt buff based on Slow Aura
call UnitAddAbility(this.u,'A50Z')
call UnitMakeAbilityPermanent(this.u,true,'A50Z')
*/
endif
set this.dur=dur
set this.targetUnit=target
endif
endmethod
// initialization
private static method onInit takes nothing returns nothing
set thistype.table = Table.create()
call TimerStart(CreateTimer(),PERIOD,true,function thistype.iterate)
endmethod
endstruct
endlibrary