- Joined
- Mar 3, 2006
- Messages
- 1,564
JASS:
scope AoETemplate initializer Init
private keyword Data
globals
private constant real TIMER_INTERVAL = 0.02
private constant real DIST = 32.00
private constant real NOVA_RADIUS = 512.00 // radius of the Nova
private constant integer NOVA_SIZE = 64 // number of the Nova Units
private constant integer UNIT_ID = 'e001' // rawcode of the Nova Unit
private constant integer ABIL_ID = 'A001' // rawcode of the Dummy Spell
private timer tm
private Data array temp_dat
private integer index = 0
endglobals
private struct Data
unit caster
unit array Nova[NOVA_SIZE]
player owner
static real cx // cx: Centre X
static real cy // cy: Centre Y
static real r = 32.00 // current radius of the nova. initial value = 32.00
static real dr = DIST // radius increment
static real array nux[NOVA_SIZE] // nux: Nova Unit X
static real array nuy[NOVA_SIZE] // nuy: Nova Unit Y
static method NovaExpand takes nothing returns nothing
local Data dat
local integer i = 0
local real rmax = NOVA_RADIUS
local real A = 0
local real dA = 360.00 / NOVA_SIZE
// nova expanding
loop
exitwhen i >= NOVA_SIZE
set dat = temp_dat[i]
set dat.nux[i] = Data.cx + Data.r * Cos( A * bj_DEGTORAD )
set dat.nuy[i] = Data.cy + Data.r * Sin( A * bj_DEGTORAD )
call SetUnitX( dat.Nova[i] , Data.nux[i] )
call SetUnitY( dat.Nova[i] , Data.nuy[i] )
set i = i + 1
set A = A + dA
endloop
if Data.r >= rmax then
call dat.destroy()
endif
set Data.r = Data.r + Data.dr
endmethod
static method NovaCreate takes unit caster, location centre returns Data
local Data dat = Data.allocate()
local integer i = 0
local real A = 0.00
local real dA = 360.00 / NOVA_SIZE
set dat.caster = caster
set dat.owner = GetOwningPlayer(dat.caster)
set Data.cx = GetLocationX(centre)
set Data.cy = GetLocationY(centre)
loop
exitwhen i >= NOVA_SIZE
set dat.Nova[i] = CreateUnit( dat.owner , UNIT_ID , dat.cx , dat.cy , A )
set A = A + dA
set i = i + 1
endloop
if index == 0 then
call TimerStart(tm,TIMER_INTERVAL,true,function Data.NovaExpand)
endif
set temp_dat[index] = dat
set index = index + 1
return dat
endmethod
method onDestroy takes nothing returns nothing
local integer i = 0
call PauseTimer(tm)
loop
exitwhen i >= NOVA_SIZE
call KillUnit(.Nova[i])
set .Nova[i] = null
set i = i + 1
endloop
set index = index - 1
endmethod
endstruct
private function Conditions takes nothing returns boolean
return GetSpellAbilityId() == ABIL_ID
endfunction
private function Actions takes nothing returns nothing
call Data.NovaCreate(GetTriggerUnit(), GetUnitLoc(GetTriggerUnit()))
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t,Condition(function Conditions))
call TriggerAddAction(t,function Actions)
set tm = CreateTimer()
endfunction
endscope
Why isn't onDestroy called ?