scope Shockwave initializer Init
globals
private constant integer AID = 'A009'
private constant integer SHOCKWAVE = 'e005'
private constant real MISSILE_SPEED = 1200
private constant real TICK = 0.03
private constant real OFFSET = MISSILE_SPEED * TICK
private constant real MAX_DISTANCE = 600
private constant string A = "Abilities\\Spells\\Undead\\FrostNova\\FrostNovaTarget.mdl"
private constant group GROUP = CreateGroup()
endglobals
private function Damage takes unit u returns real
return I2R(GetUnitAbilityLevel(u, AID)) * 4000
endfunction
private function Kill takes nothing returns nothing
local unit e = GetEnumUnit()
call KillUnit(e)
set e = null
endfunction
private function Callback takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer id = GetHandleId(t)
local unit u = LoadUnitHandle(udg_Hash, id, 0)
local unit e = GetEnumUnit()
local unit f
local real x = GetUnitX(e)
local real y = GetUnitY(e)
local real facing = GetUnitFacing(e) * bj_DEGTORAD
local real px = x + OFFSET * Cos(facing)
local real py = y + OFFSET * Sin(facing)
call DestroyEffect(AddSpecialEffect(A, x, y))
call SetUnitX(e, px)
call SetUnitY(e, py)
set u = null
set t = null
set e = null
endfunction
private function Periodic takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer id = GetHandleId(t)
local unit u = LoadUnitHandle(udg_Hash, id, 0)
local group g = LoadGroupHandle(udg_Hash, id, 1)
local real CURRENT_DISTANCE = LoadReal(udg_Hash, id, 2)
if CURRENT_DISTANCE <= MAX_DISTANCE then
call ForGroup(g, function Callback)
else
call ForGroup(g, function Kill)
call PauseTimer(t)
call DestroyTimer(t)
call DestroyGroup(g)
call FlushChildHashtable(udg_Hash, id)
endif
call SaveReal(udg_Hash, id, 2, CURRENT_DISTANCE + OFFSET)
set t = null
set u = null
set g = null
endfunction
private function Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
local unit s
local timer t = CreateTimer()
local integer id = GetHandleId(t)
local group g = CreateGroup()
local player p = GetOwningPlayer(u)
local real x = GetUnitX(u)
local real y = GetUnitY(u)
local real tx = GetSpellTargetX()
local real ty = GetSpellTargetY()
local real dx = tx - x
local real dy = ty - y
local real distcheck = (dx * dx) + (dy + dy)
local real facing
local real px
local real py
local integer i = 1
if distcheck > 100 * 100 then
set facing = Atan2(dy, dx)
else
set facing = GetUnitFacing(u) * bj_DEGTORAD
endif
set facing = facing + 0.523
loop
exitwhen i > 3
set px = x + 100 * Cos(facing)
set py = y + 100 * Sin(facing)
set s = CreateUnit(p, SHOCKWAVE, px, py, facing * bj_RADTODEG)
call GroupAddUnit(g, s)
set facing = facing - 0.523
set i = i + 1
set s = null
endloop
call SaveUnitHandle(udg_Hash, id, 0, u)
call SaveGroupHandle(udg_Hash, id, 1, g)
call SaveReal(udg_Hash, id, 2, 0)
call TimerStart(t, TICK, true, function Periodic)
set t = null
set u = null
set g = null
set p = null
endfunction
private function Conditions takes nothing returns boolean
if GetSpellAbilityId() == AID then
call Actions()
endif
return false
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 ) )
set t = null
endfunction
endscope