library UnitInRangeEvent
struct UnitInRangeEvent
private static hashtable HASHTABLE = InitHashtable()
readonly trigger trig
readonly unit whichUnit
public static method create takes unit whichUnit, real range, code action returns thistype
local thistype this = .allocate()
set .whichUnit = whichUnit
set .trig = CreateTrigger()
call TriggerRegisterUnitInRange(.trig, whichUnit, range, action)
call SaveInteger(.HASHTABLE, GetHandleId(.trig), 0, this)
call SaveInteger(.HASHTABLE, GetHandleId(whichUnit), 0, this)
return this
endmethod
public static method parseFromUnit takes unit whichUnit returns thistype
return LoadInteger(.HASHTABLE, GetHandleId(whichUnit), 0)
endmethod
public static method parseFromTrigger takes trigger trig returns thistype
return LoadInteger(.HASHTABLE, GetHandleId(trig), 0)
endmethod
public method destroy takes nothing returns nothing
call FlushChildHashtable(.HASHTABLE, GetHandleId(.trig))
call FlushChildHashtable(.HASHTABLE, GetHandleId(.whichUnit))
call DestroyTrigger(.trig)
set .trig = null
set .whichUnit = null
call .deallocate()
endmethod
endstruct
endlibrary
scope Test// for libraries: uses UnitInRangeEvent
function End takes unit whichUnit returns nothing
// for example when the unit dies, unlearns the spell, loses the buff, whatever
call UnitInRangeEvent.parseFromUnit(whichUnit).destroy()
endfunction
function Action takes nothing returns nothing
local UnitInRangeEvent e = UnitInRangeEvent.parseFromTrigger(GetTriggeringTrigger())
local unit whichUnit = e.whichUnit
local unit otherUnit = GetTriggerUnit()
// do stuff
endfunction
function Start takes unit whichUnit returns nothing
// when you want to start having this stuff
local UnitInRangeEvent e = UnitInRangeEvent.create(whichUnit, 500, function Action)
endfunction
endscope