View Single Post
Old 09-12-2009, 07:33 PM   #24
Bobo_The_Kodo
oO
 
Bobo_The_Kodo's Avatar
 
Join Date: Jul 2008
Posts: 580

Bobo_The_Kodo has a spectacular aura about (109)Bobo_The_Kodo has a spectacular aura about (109)Bobo_The_Kodo has a spectacular aura about (109)Bobo_The_Kodo has a spectacular aura about (109)

Default

For any possible buff(other than auras), you should have callbacks :

onRefresh
onEnd
onExpire
onPurge
onApply
onPeriodic

(Also if you're wondering why your system doublefrees)
If unit dies on last execute of onPeriodic -> doublefree

edit://

Collapse JASS:
private function BuffTimeout takes nothing returns nothing
    local timer t  = GetExpiredTimer()
    local dbuff db = dbuff(GetTimerData(t))
    
    //Different behavior for periodic buffs than one-timers
    if db.isPeriod then
        //Run the onPeriod callback no matter what
        set TempBuff = db
        call db.onPeriod.execute()
        //Check if this iteration kills the buff
        set db.elapsed = db.elapsed + db.period
        if db.elapsed >= db.duration then
            //Kill the buff completely
            call db.destroy() //Timer gets recycled in here!
        endif
    else
        //Kill the buff completely
        call db.destroy() //Timer gets recycled in here!
    endif
    
    set t = null
endfunction
I like that part, using single timer, but you need :

Collapse JASS:
private function BuffTimeout takes nothing returns nothing
    local timer t  = GetExpiredTimer()
    local dbuff db = dbuff(GetTimerData(t))
    
    //Different behavior for periodic buffs than one-timers
    if db.isPeriod then
        //Run the onPeriod callback no matter what
        set TempBuff = db
        call db.onPeriod.execute()
        //Check if this iteration kills the buff
        set db.elapsed = db.elapsed + db.period
        if db.elapsed >= db.duration then
            //Kill the buff completely
            call db.destroy() //Timer gets recycled in here!
        elseif db.elapsed + db.period > db.duration
            set db.isPeriod = false
            call TimerStart(db.tmr, db.duration-db.elapsed, false, function BuffTimeout)
        endif
    else
        //Kill the buff completely
        call db.destroy() //Timer gets recycled in here!
    endif
    
    set t = null
endfunction
-> but the duration could get changed during that timeout -> hmmm
Bobo_The_Kodo is offline   Reply With Quote