scope StormEarthFire //initializer InitTrig_SEF
globals
boolean array SB // Storm boolean - a storm unit has been absorbed
boolean array EB // Earth boolean - an earth unit has been absorbed
boolean array FB // Fire boolean - a fire unit has been absorbed
unit array SU // Storm unit
unit array EU // Earth unit
unit array FU // Fire unit
unit array SEF_U // Caster
real array SEF_X // X of cast point
real array SEF_Y // Y of cast point
timer array SEF_T // Cooldown timers
integer array SEF_C // Storm Earth and Fire count - counts how many units have been absorbed
integer array TC // time count
integer array Current_Type
effect array SEF_E
endglobals
private function Fade takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer id = GetHandleId(t)
local unit c = LoadUnitHandle(udg_Table, id, 'unit')
local unit u = LoadUnitHandle(udg_Table, id, 'targ')
local real dist = LoadReal(udg_Table, id, 'dist')
local real x = GetUnitX(u)
local real y = GetUnitY(u)
local real xc = GetUnitX(c)
local real yc = GetUnitY(c)
local real h = y-yc
local real w = x-xc
local integer i = GetPlayerId(GetOwningPlayer(u))
if IsUnitAliveBJ( u ) then
if h*h+w*w <= 10000.00 then
call RecTimer(t)
call ShowUnit( c , false )
call UnitRemoveAbility( u , 'A02J' )
if Current_Type[i] == 1 then
call UnitAddAbility( u , 'A02L' )
elseif Current_Type[i] == 2 then
call UnitAddAbility( u , 'A02K' )
elseif Current_Type[i] == 3 then
call UnitAddAbility( u , 'A02M' )
endif
set SEF_C[i] = SEF_C[i] + 1
set Current_Type[i] = 0
if SEF_C[i] < 3 then
call UnitAddAbility( u , 'A02J' )
else
call UnitAddAbility( u , 'A02N' )
endif
else
call SetUnitVertexColor(c, 255, 255, 255, (255*R2I(h*h+w*w)/250000)-10)
endif
else
call RecTimer(t)
endif
set t = null
set c = null
set u = null
endfunction
private function PeriodicCheck takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer id = GetHandleId(t)
local unit c = LoadUnitHandle(udg_Table, id, 'cast')
local unit u = LoadUnitHandle(udg_Table, id, 'targ')
local integer i = GetPlayerId(GetOwningPlayer(c))
set TC[i] = TC[i] + 1
if IsUnitDeadBJ(c) or IsUnitDeadBJ(u) then
set TC[i] = 0
call DestroyEffect(SEF_E[i])
call RecTimer(t)
if Current_Type[i] == 1 then
set SU[i] = null
set SB[i] = false
elseif Current_Type[i] == 2 then
set EU[i] = null
set EB[i] = false
elseif Current_Type[i] == 3 then
set FU[i] = null
set FB[i] = false
endif
set Current_Type[i] = 0
elseif TC[i] >= 20 then
call DestroyEffect(SEF_E[i])
set TC[i] = 0
call SetUnitInvulnerable( u , true )
call RecTimer(t)
call SlideToUnit( u , c , 400.00 , function Fade)
endif
set t = null
set c = null
set u = null
endfunction
function SEF_Init takes unit u, unit c returns nothing
local timer t = GetFreeTimer()
local real x = GetUnitX(u)
local real y = GetUnitY(u)
local real xc = GetUnitX(c)
local real yc = GetUnitY(c)
local integer id = GetHandleId(t)
set SEF_E[GetPlayerId(GetOwningPlayer(c))] = AddSpecialEffectTarget( "Abilities\\Spells\\Items\\StaffOfSanctuary\\Staff_Sanctuary_Target.mdl", u, "chest")
call SaveUnitHandle(udg_Table, id, 'cast', c)
call SaveUnitHandle(udg_Table, id, 'targ', u)
call SetUnitFacing( u, bj_RADTODEG*Atan2(yc-y,xc-x))
call PauseUnit( u , true )
call TimerStart( t, 0.10, true, function PeriodicCheck)
endfunction
function SEF_Cast takes integer i returns nothing
endfunction
function SEF_Check takes nothing returns boolean
local unit c = GetTriggerUnit()
local unit t = GetSpellTargetUnit()
local integer utid = GetUnitTypeId(t)
local player p = GetOwningPlayer(c)
local integer i = GetPlayerId(p)
if GetSpellAbilityId() == 'A02J' then
if utid == 'odoc' then
if not FB[i] then
set SEF_U[i] = c
set FU[i] = t
set FB[i] = true
set Current_Type[i] = 3
call SEF_Init(t, c)
else
call DisplayTextToPlayer(p, 0, 0, "You already have a chosen caster for the Fire part of the spell.")
endif
elseif utid == 'oshm' then
if not SB[i] then
set SEF_U[i] = c
set SU[i] = t
set SB[i] = true
set Current_Type[i] = 1
call SEF_Init(t, c)
else
call DisplayTextToPlayer(p, 0, 0, "You already have a chosen caster for the Storm part of the spell.")
endif
elseif utid == 'ospw' then
if not EB[i] then
set SEF_U[i] = c
set EU[i] = t
set EB[i] = true
set Current_Type[i] = 2
call SEF_Init(t, c)
else
call DisplayTextToPlayer(p, 0, 0, "You already have a chosen caster for the Earth part of the spell.")
endif
else
call UnitRemoveAbility( c , 'A02J' )
call UnitAddAbility( c , 'A02J' )
call DisplayTextToPlayer(p, 0, 0, "You need to target a Shaman, Witch Doctor or a Spirit Walker with this spell")
endif
elseif GetSpellAbilityId() == 'A02N' then
set SEF_X[i] = GetSpellTargetX()
set SEF_Y[i] = GetSpellTargetY()
call SEF_Cast(i)
endif
set c = null
set t = null
set p = null
return false
endfunction
private function OnDeath takes nothing returns boolean
local unit u = GetTriggerUnit()
local integer i = GetPlayerId(GetOwningPlayer(u))
if u == SEF_U[i] and SEF_C[i] > 0 then
if Current_Type[i] == 1 then
call SetUnitInvulnerable( SU[i] , false )
call SetUnitVertexColor(SU[i], 255, 255, 255, 255)
call PauseUnit( SU[i], false)
set SB[i] = false
set SU[i] = null
elseif Current_Type[i] == 2 then
call SetUnitInvulnerable( EU[i] , false )
call SetUnitVertexColor( EU[i], 255, 255, 255, 255)
call PauseUnit( EU[i], false)
set EB[i] = false
set EU[i] = null
elseif Current_Type[i] == 3 then
call SetUnitInvulnerable( FU[i] , false )
call SetUnitVertexColor( FU[i], 255, 255, 255, 255)
call PauseUnit( FU[i], false)
set FB[i] = false
set FU[i] = null
endif
if SB[i] then
call SetUnitX( SU[i], GetUnitX(u))
call SetUnitY( SU[i], GetUnitY(u)+75)
call ShowUnit( SU[i], true )
call SetUnitInvulnerable( SU[i] , false )
call SetUnitVertexColor( SU[i], 255, 255, 255, 255)
call PauseUnit( SU[i], false)
set SB[i] = false
set SU[i] = null
endif
if EB[i] then
call SetUnitX( EU[i], GetUnitX(u)-64.952)
call SetUnitY( EU[i], GetUnitY(u)-37.5)
call ShowUnit( EU[i], true )
call SetUnitInvulnerable( EU[i] , false )
call SetUnitVertexColor( EU[i], 255, 255, 255, 255)
call PauseUnit( EU[i], false)
set EB[i] = false
set EU[i] = null
endif
if FB[i] then
call SetUnitX( FU[i], GetUnitX(u)+64.952)
call SetUnitY( FU[i], GetUnitY(u)-37.5)
call ShowUnit( FU[i], true )
call SetUnitInvulnerable( FU[i] , false )
call SetUnitVertexColor( FU[i], 255, 255, 255, 255)
call PauseUnit( FU[i], false)
set FB[i] = false
set FU[i] = null
endif
set SEF_C[i] = 0
endif
return false
endfunction
//==============================================================================
function InitTrig_SEF takes nothing returns nothing
local integer i = 0
local trigger t = CreateTrigger()
set gg_trg_SEF = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( gg_trg_SEF, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_SEF, Condition( function SEF_Check ) )
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition( t, Condition( function OnDeath ))
loop
exitwhen i > 11
set SB[i] = false
set EB[i] = false
set FB[i] = false
set i = i + 1
endloop
set t = null
endfunction
endscope