package Buff import UnitClass import BuffTypes import ObjectIds //import Bonus public class Buff Action action Bonus bon = null Unit u bufftype btyp effect fx timer fxTimer timer t int fxCounter string fxType string attachment construct(Unit u, string buffname, real duration) this.u = u btyp = getBuffType(buffname) // print(idInteger2IdString(btyp.abiId)) // print(idInteger2IdString(btyp.buffId)) u.allBuffs.add(this) UnitAddAbility(u.u, btyp.abiId) fx = null fxTimer = null action = u.registerDeath((Units data) -> destroy this) t = getTimer() t.setData(this castTo int) t.start(duration, function timerDestroyBuff) static function timerDestroyBuff() destroy GetExpiredTimer().getData() castTo Buff function addEffect(string fx, string attachment) this.fx = u.u.addEffect(fx, attachment) function attachBonus(Bonus b) this.bon = b function addEffectTimed(string fx, string attachment, real interval) DestroyEffect(u.u.addEffect(fx, attachment)) real time = TimerGetRemaining(t) fxCounter = R2I(time / interval) if fxCounter > 0 fxType = fx this.attachment = attachment fxTimer = getTimer() fxTimer.setData(this castTo int) fxTimer.startPeriodic(interval, function createEffect) static function createEffect() timer t = GetExpiredTimer() var b = t.getData() castTo Buff if b.fxCounter > 0 DestroyEffect(b.u.u.addEffect(b.fxType, b.attachment)) b.fxCounter-- else t.release() ondestroy destroy action t.release() u.allBuffs.remove(this) if fxTimer != null fxTimer.release() UnitRemoveAbility(u.u, btyp.abiId) UnitRemoveAbility(u.u, btyp.buffId) if bon != null destroy bon if fx != null DestroyEffect(fx) endpackage