library dotStack
private struct dotDat
unit source
unit target
integer dps
integer length
string fx
method onCreate takes nothing returns nothing
set this.source=null
set this.target=null
set this.dps=0
set this.dps=1
set this.fx=""
endmethod
endstruct
globals
private constant real REPEATTIME=.5 //How often the periodic damage runs. DPS will automatically update.
private dotDat array dotDB
private integer dbIndex=-1
private timer time=CreateTimer()
endglobals
private function p takes nothing returns nothing
local dotDat tempDat
local integer index=0
local effect fx
loop
exitwhen index>dbIndex
set tempDat=dotDB[index]
set fx=AddSpecialEffect(tempDat.fx,GetUnitX(tempDat.target),GetUnitY(tempDat.target))
call DestroyEffect(fx)
call UnitDamageTarget(tempDat.source,tempDat.target,tempDat.dps*REPEATTIME,true,true,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
set tempDat.length=tempDat.length-1
if tempDat.length<1 or GetWidgetLife(tempDat.target)<1 then
call tempDat.destroy()
set dotDB[index]=dotDB[dbIndex]
set dbIndex=dbIndex-1
if dbIndex==-1 then
call PauseTimer(time)
endif
endif
set index=index+1
endloop
endfunction
function addDot takes unit source, unit target, integer dps, integer length, string fx returns nothing
local dotDat tempDat=dotDat.create()
set tempDat.source=source
set tempDat.target=target
set tempDat.dps=dps
set tempDat.length=length
set tempDat.fx=fx
set dbIndex=dbIndex+1
set dotDB[dbIndex]=tempDat
if dbIndex==0 then
call TimerStart(time,REPEATTIME,true,function p)
endif
endfunction
endlibrary