function PolarProjectionX takes real x, real dist, real angle returns real
return x + dist * Cos(angle)
endfunction
function PolarProjectionY takes real y, real dist, real angle returns real
return y + dist * Sin(angle)
endfunction
function Vanishing_World_Periodic takes nothing returns nothing
//Variable setup
local timer t = GetExpiredTimer()
local integer id = GetHandleId(t)
local unit u = LoadUnitHandle(udg_Hash, id, 0)
local real tx = LoadReal(udg_Hash, id, 1)
local real ty = LoadReal(udg_Hash, id, 2)
local real final_damage = LoadReal(udg_Hash, id, 3)
local real periodic_damage = LoadReal(udg_Hash, id, 4)
local integer count = LoadInteger(udg_Hash, id, 5)
local real rand_distance = GetRandomReal(200, 900)
local real rand_angle = GetRandomReal(0, 6.263)
local real rx = tx + rand_distance * Cos(rand_angle)
local real ry = ty + rand_distance * Sin(rand_angle)
local unit u1 //will be used for FirstofGroup
local unit shadowball
local real sx
local real sy
local group g
local unit u2
local integer i = 0
local real angle = 0.314
local real px //x coordinate of the polar projection
local real py //y coordinate of the polar projection
local player owner = GetOwningPlayer(u)
//End of variable setup
if count < 31 then
set count = count + 1// 1 Shadow Ball has spawned.
call SaveInteger(udg_Hash, id, 5, count)
call BJDebugMsg(I2S(count))
call BJDebugMsg(I2S(id))
if count < 25 then //It'll keep creating shadow balls until the 25th tick
set g = CreateGroup()
set shadowball = CreateUnit(owner, 'e001', rx, ry, 270)
set sx = GetUnitX(shadowball)
set sy = GetUnitY(shadowball)
call KillUnit(shadowball)
call DestroyEffect(AddSpecialEffect("DarkNova.mdx", sx, sy))
call GroupEnumUnitsInRange(g, sx, sy, 350, null)
loop
set u1 = FirstOfGroup(g)
exitwhen u1 == null
if IsUnitEnemy(u1, owner) then
call UnitDamageTarget(u, u1, periodic_damage, false, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_UNIVERSAL, null)
endif
call GroupRemoveUnit(g, u1)
endloop
//clean up
set u = null
set u1 = null
set u2 = null
set shadowball = null
set owner = null
call DestroyGroup(g)
set g = null
set t = null
//Creating the big Shadow Ball at the 26th tick
elseif count == 26 then
set shadowball = CreateUnit(owner, 'e002', tx, ty, 270)
call SaveUnitHandle(udg_Hash, id, 6, shadowball)
set u = null
set shadowball = null
set owner = null
set t = null
elseif count >26 and count <31 then//to destroy leaks between 26 and 31
set u = null
set owner = null
set t = null
//Waiting for 1 second to pass
elseif count == 31 then
set g = CreateGroup()
set shadowball = LoadUnitHandle(udg_Hash, id, 6)//LOAD the unit because this is periodic trigger uses LOCAL variables. You cannot refer to a variable from a previous instance of this function.
call KillUnit(shadowball)
set u2 = CreateUnit(owner, 'e003', tx, ty, 270)
call KillUnit(u2)
loop
exitwhen i == 20
set i = i + 1
set px = PolarProjectionX(tx, 300, angle)
set py = PolarProjectionY(ty, 300, angle)
call DestroyEffect(AddSpecialEffect("DarkPillar.mdx", px, py))
call DestroyEffect(AddSpecialEffect("Nebula.mdx", px, py))
set px = PolarProjectionX(tx, 600, angle)
set py = PolarProjectionY(ty, 600, angle)
call DestroyEffect(AddSpecialEffect("DarkPillar.mdx", px, py))
call DestroyEffect(AddSpecialEffect("Nebula.mdx", px, py))
set px = PolarProjectionX(tx, 900, angle)
set py = PolarProjectionY(ty, 900, angle)
call DestroyEffect(AddSpecialEffect("DarkPillar.mdx", px, py))
call DestroyEffect(AddSpecialEffect("Nebula.mdx", px, py))
set angle = angle + 0.314
endloop
set i = 0
set angle = 0.523
loop
exitwhen i == 12
set i = i + 1
set px = PolarProjectionX(tx, 300, angle)
set py = PolarProjectionY(ty, 300, angle)
call DestroyEffect(AddSpecialEffect("StarExplosion.mdx", px, py))
set px = PolarProjectionX(tx, 600, angle)
set py = PolarProjectionY(ty, 600, angle)
call DestroyEffect(AddSpecialEffect("StarExplosion.mdx", px, py))
set px = PolarProjectionX(tx, 900, angle)
set py = PolarProjectionY(ty, 900, angle)
call DestroyEffect(AddSpecialEffect("StarExplosion.mdx", px, py))
set angle = angle + 0.523
endloop
call GroupEnumUnitsInRange(g, tx, ty, 950, null)
loop
set u1 = FirstOfGroup(g)
exitwhen u1 == null
if IsUnitEnemy(u1, GetOwningPlayer(u)) then
call UnitDamageTarget(u, u1, final_damage, false, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_UNIVERSAL, null)
endif
call GroupRemoveUnit(g, u1)
endloop
call PauseTimer(t)
call DestroyTimer(t)
set t = null
set u = null
set u1 = null
set u2 = null
set shadowball = null
set g = null
set owner = null
call DestroyGroup(g)
call FlushChildHashtable(udg_Hash, id)
endif
endif
endfunction
function Vanishing_World_Actions takes nothing returns nothing
//Variable Setup
local unit u = GetTriggerUnit()
local timer t = CreateTimer()
local real tx = GetSpellTargetX()// X coordinate of the spell target location
local real ty = GetSpellTargetY()// Y coordinate of the spell target location
local real final_damage = 1000 * GetHeroInt(u,true)//Final damage at the end
local real periodic_damage = (GetHeroInt(u,true) * 0.10) * 100//damage during the periodic actions
local integer id = GetHandleId(t)//Id of the timer, will be used as the parentKey
//End of variable set up
//Setting up the hashtable
call SaveUnitHandle(udg_Hash, id, 0, u)
call SaveReal(udg_Hash, id, 1, tx)
call SaveReal(udg_Hash, id, 2, ty)
call SaveReal(udg_Hash, id, 3, final_damage)//I'm storing the damage so the spell will still deal damage even if the Hero dies.
call SaveReal(udg_Hash, id, 4, periodic_damage)
call SaveInteger(udg_Hash, id, 5, 0)//Storing the count so, the trigger will know when to stop.
//End of hashtable setup
// Start of the periodic loop
call TimerStart(t, 0.2, true, function Vanishing_World_Periodic)
set t = null
endfunction
function Trig_Vanishing_World_v2_Conditions takes nothing returns boolean
if GetSpellAbilityId() == 'A000' then
call Vanishing_World_Actions()
endif
return false
endfunction
//===========================================================================
function InitTrig_Vanishing_World_v2 takes nothing returns nothing
local trigger t = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( t, Condition( function Trig_Vanishing_World_v2_Conditions ) )
set udg_Hash = InitHashtable()
set t = null
endfunction