- Joined
- Oct 11, 2012
- Messages
- 711
Hi all. I am making a spell that can increase a group of hero's stats for a certain period of time. The code looks like the following:
It does work but is it leakless? Thanks all.
JASS:
struct Spell
private static constant integer ABIL_CODE = 'Arej'
private static constant real TIMEOUT = 20.00
private thistype next
private thistype prev
//private static integer count = 0
private unit caster
private unit target
private unit u
private real damage
private real duration
private real x
private real y
private timer iterator
private group g
private method destroy takes nothing returns nothing
call this.deallocate()
set this.next.prev = this.prev
set this.prev.next = this.next
//set count = count - 1
//if count == 0 then
call PauseTimer(this.iterator)
//endif
call DestroyGroup(this.g)
set this.caster = null
set this.target = null
set this.g=null
set this.iterator=null
endmethod
private static method Add takes nothing returns nothing
local unit enumm=GetEnumUnit()
local integer str=GetHeroStr(enumm,false)
local integer agi=GetHeroAgi(enumm,false)
local integer intt=GetHeroInt(enumm,false)
call SetHeroStr(enumm,str+1000,true)
call SetHeroAgi(enumm,agi+1000,true)
call SetHeroInt(enumm,intt+1000,true)
call BJDebugMsg("+1000")
set enumm=null
endmethod
private static method Subtract takes nothing returns nothing
local unit enumm=GetEnumUnit()
local integer str=GetHeroStr(enumm,false)
local integer agi=GetHeroAgi(enumm,false)
local integer intt=GetHeroInt(enumm,false)
call SetHeroStr(enumm,str-1000,true)
call SetHeroAgi(enumm,agi-1000,true)
call SetHeroInt(enumm,intt-1000,true)
call BJDebugMsg("-1000")
set enumm=null
endmethod
private static method callback takes nothing returns nothing
local thistype this = thistype(0).next
call ForGroup(this.g,function thistype.Subtract)
call BJDebugMsg("destroy")
call this.destroy()
set this = this.next
endmethod
private static method run takes nothing returns boolean
local thistype this = thistype.allocate()
set this.next = 0
set this.prev = thistype(0).prev
set thistype(0).prev.next = this
set thistype(0).prev = this
set this.caster = GetTriggerUnit()
set this.target = GetSpellTargetUnit()
set this.g=CreateGroup()
set this.x=GetUnitX(this.target)
set this.y=GetUnitY(this.target)
set this.iterator=CreateTimer()
call GroupEnumUnitsInRange(this.g,this.x,this.y,500.,null)
call ForGroup(this.g,function thistype.Add)
//set count = count + 1
//if count == 1 then
call TimerStart(this.iterator, TIMEOUT, false, function thistype.callback)
//endif
return false
endmethod
private static method spell takes nothing returns boolean
if GetSpellAbilityId()==ABIL_CODE then
call thistype.run()
endif
return false
endmethod
private static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t, Condition(function thistype.spell))
set t = null
endmethod
endstruct
It does work but is it leakless? Thanks all.