function Magical_Sword_Timer takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer id = GetHandleId(t)
local integer i
local unit u = LoadUnitHandle(udg_Spell_Table, id, 1)
local unit ut = LoadUnitHandle(udg_Spell_Table, id, 2)
local unit dummy
local real x1
local real y1
local real x2
local real y2
local real z
local real hp
local real spd
local lightning l
local real c = LoadReal(udg_Spell_Table, id, 6)
if c < 18 and not IsUnitType(u, UNIT_TYPE_DEAD) and not IsUnitType(ut, UNIT_TYPE_DEAD) then
if c == 0 then
call SaveReal(udg_Spell_Table, id, 9, 0.05)
set z = LoadReal(udg_Spell_Table, id, 4)
set i = 0
loop
exitwhen i > 4
set dummy = LoadUnitHandle(udg_Spell_Table, id, i + 10)
set x1 = GetUnitX(dummy)
set y1 = GetUnitY(dummy)
if i == 4 then
set dummy = LoadUnitHandle(udg_Spell_Table, id, 10)
else
set dummy = LoadUnitHandle(udg_Spell_Table, id, i + 11)
endif
set x2 = GetUnitX(dummy)
set y2 = GetUnitY(dummy)
set l = AddLightningEx("DRAL", true, x1, y1, z, GetUnitX(ut), GetUnitY(ut), z)
call SaveLightningHandle(udg_Spell_Table, id, 20 + i, l)
call SetLightningColor(l, 1, 0, 0, 1)
set l = AddLightningEx("LEAS", true, x1, y1, z, x2, y2, z)
call SaveLightningHandle(udg_Spell_Table, id, 30 + i, l)
call SetLightningColor(l, 0, 0, 1, 1)
set dummy = CreateUnit (Player(15), 'ewsp', GetUnitX(ut), GetUnitY(ut), 0)
call UnitAddAbility(dummy, 'Aloc' )
call SetUnitPathing(dummy, false)
call SetUnitScale(dummy, 0.5, 0.5, 0.5)
call UnitAddAbility(dummy, 'Amrf' )
call UnitRemoveAbility(dummy, 'Amrf' )
call UnitRemoveAbility( dummy, 'Amov' )
call SaveUnitHandle(udg_Spell_Table, id, i + 15, dummy)
set i = i + 1
endloop
set l = null
set dummy = null
elseif c > 0 and c < 16 then
if c == R2I(c + 1) then
set hp = LoadReal(udg_Spell_Table, id, 7)
call SetWidgetLife(u, GetWidgetLife(u) + hp)
call SetWidgetLife(ut, GetWidgetLife(ut) - hp)
endif
set i = 0
loop
exitwhen i > 4
set hp = c - R2I(c)
set x1 = GetUnitX(ut)
set y1 = GetUnitY(ut)
set x2 = x1 + (hp * 300) * Cos(bj_DEGTORAD * 72 * i)
set y2 = y1 + (hp * 300) * Sin(bj_DEGTORAD * 72 * i)
call MoveLocation(udg_p, x2, y2)
set z = LoadReal(udg_Spell_Table, id, 4) - GetLocationZ(udg_p)
set dummy = LoadUnitHandle(udg_Spell_Table, id, i + 15)
call SetUnitFlyHeight( dummy, z - 25, 0 )
call SetUnitPosition( dummy, x2, y2)
set i = i + 1
endloop
elseif c == 16 or c == 16.05 then
call SaveReal(udg_Spell_Table, id, 9, 1)
call SaveReal(udg_Spell_Table, id, 6, 16)
set c = 16
set i = 0
set spd = LoadReal(udg_Spell_Table, id, 8)
loop
exitwhen i > 4
call SetUnitFlyHeight( LoadUnitHandle(udg_Spell_Table, id, i + 10), 1500, spd * 4 )
call DestroyLightning(LoadLightningHandle(udg_Spell_Table, id, 20 + i))
call DestroyLightning(LoadLightningHandle(udg_Spell_Table, id, 30 + i))
call RemoveUnit (LoadUnitHandle(udg_Spell_Table, id, i + 15))
set i = i + 1
endloop
call UnitAddAbility( ut, 'Amrf' )
call UnitRemoveAbility( ut, 'Amrf' )
call SetUnitFlyHeight( ut, 0, spd )
elseif c == 17 then
call PauseUnit( ut, false )
call SetUnitInvulnerable( ut, false )
call DestroyEffect(LoadEffectHandle(udg_Spell_Table, id, 5))
endif
call SaveReal(udg_Spell_Table, id, 6, c + LoadReal(udg_Spell_Table, id, 9))
call TimerStart(t, LoadReal(udg_Spell_Table, id, 9), false, function Magical_Sword_Timer)
else
set i = 0
loop
exitwhen i > 4
call UnitApplyTimedLife( LoadUnitHandle(udg_Spell_Table, id, i + 10), 'BUan', 1 )
set i = i + 1
endloop
call PauseTimer(t)
call DestroyTimer(t)
call FlushChildHashtable(udg_Spell_Table, id)
endif
set t = null
set u = null
set ut = null
endfunction
function Trig_Magical_Sword_Actions takes nothing returns nothing
local timer t
local integer id
local unit u
local unit ut
local unit dummy
local real x
local real y
local real nx
local real ny
local real spd
local real hpdrain
local player p
local real z
local real z2
local real h1
local real h2
local integer i
local integer c
local real interval
if GetSpellAbilityId() == 'A000' then
set t = CreateTimer()
set id = GetHandleId(t)
set u = GetTriggerUnit()
set ut = GetSpellTargetUnit()
set x = GetUnitX(ut)
set y = GetUnitY(ut)
set spd = 100
set hpdrain = GetWidgetLife(ut) / 100.00 * GetUnitAbilityLevel(u, GetSpellAbilityId())
set p = GetTriggerPlayer()
set h1 = 330
set h2 = 320
set i = 0
set c = 0
set interval = 1
call MoveLocation(udg_p, x, y)
set z = GetLocationZ(udg_p)
call SaveUnitHandle(udg_Spell_Table, id, 1, u)
call SaveUnitHandle(udg_Spell_Table, id, 2, ut)
call SaveReal(udg_Spell_Table, id, 3, h1)
call SaveReal(udg_Spell_Table, id, 4, h2 + z)
call SaveEffectHandle(udg_Spell_Table, id, 5, AddSpecialEffectTarget("Abilities\\Spells\\Human\\DivineShield\\DivineShieldTarget.mdl", ut, "origin"))
call SaveReal(udg_Spell_Table, id, 6, c)
call SaveReal(udg_Spell_Table, id, 7, hpdrain)
call SaveReal(udg_Spell_Table, id, 8, spd)
call SaveReal(udg_Spell_Table, id, 9, interval)
call SetUnitInvulnerable( ut, true )
call PauseUnit( ut, true )
loop
exitwhen i > 4
set nx = x + 300 * Cos(bj_DEGTORAD * i * 72)
set ny = y + 300 * Sin(bj_DEGTORAD * i * 72)
set dummy = CreateUnit (p, 'h003', nx , ny, 0)
call UnitAddAbility(dummy, 'Amrf' )
call UnitRemoveAbility(dummy, 'Amrf' )
call MoveLocation(udg_p, nx, ny)
set z2 = GetLocationZ(udg_p)
call SetUnitFlyHeight( dummy, h1 + z - z2, spd * 4 )
call SaveUnitHandle(udg_Spell_Table, id, i + 10, dummy)
set i = i + 1
endloop
call UnitAddAbility(ut, 'Amrf' )
call UnitRemoveAbility(ut, 'Amrf' )
call SetUnitFlyHeight( ut, h2, spd )
call TimerStart(t, 3.5, false, function Magical_Sword_Timer)
set u = null
set ut = null
set dummy = null
set p = null
endif
endfunction
//===========================================================================
function InitTrig_Magical_sword takes nothing returns nothing
set gg_trg_Magical_sword = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Magical_sword, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddAction( gg_trg_Magical_sword, function Trig_Magical_Sword_Actions )
endfunction