library DoT
globals
private constant real FPS = 0.0100
endglobals
struct DoT extends array
private unit caster
private unit target
private real interval
private real during
private real dmg
private real temp
private static integer count
private thistype prev
private thistype next
private static timer period
private static method iterate takes nothing returns nothing
local thistype this = thistype(0)
loop
set this = this.next
exitwhen this == 0
set this.temp = this.temp + FPS
if this.temp+FPS >= this.interval then
call UnitDamageTarget(this.caster, this.target, this.dmg, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC, null)
set this.temp = 0
endif
set this.during = this.during - FPS
if this.during <= 0 then
call this.destroy()
endif
endloop
endmethod
static method add takes unit cast, unit targ, real dur, real inter, real dm returns nothing
local thistype this
if thistype(0).prev == 0 then
set count = count + 1
set this = count
else
set this = thistype(0).prev
set thistype(0).prev = thistype(0).prev.prev
endif
if thistype(0).next == 0 then
call TimerStart(period, FPS, true, function thistype.iterate)
else
set thistype(0).next.prev = this
endif
set this.next = thistype(0).next
set thistype(0).next = this
set this.prev = thistype(0)
set this.caster = cast
set this.target = targ
set this.interval = inter
set this.during = dur
set this.dmg = dm
set this.temp = 0
endmethod
private method destroy takes nothing returns nothing
if this.next != 0 then
set this.next.prev = this.prev
endif
set this.prev.next = this.next
set this.prev = thistype(0).prev
set thistype(0).prev = this
if thistype(0).next == 0 then
call PauseTimer(period)
endif
set this.caster = null
set this.target = null
endmethod
private static method onInit takes nothing returns nothing
set count = 0
set period = CreateTimer()
endmethod
endstruct
endlibrary