globals
integer TG_Index = 0
unit array TG_Caster
unit array TG_Dummy
unit array TG_Dummy_Effect
unit array TG_Grappled_U
unit array TG_Target
unit array TG_Stun_Dummy
unit array TG_Stunned_U
unit TG_Effect
real array TG_Angel
real array TG_Process
real array TG_Stun_Dur
real array TG_Max_Targets
integer array TG_Counter
timer TG_Timer = CreateTimer()
timer TG_Stun_Timer = CreateTimer()
integer TG_Loop_Int = 0
integer TG_Hash = 0
group TG_Group = CreateGroup()
group TG_Effects_Group = CreateGroup()
boolean array TG_Unit_Is_Grappled
boolean array TG_Stun_Removed
boolean array TG_Stun_Finished
//configurations
real TG_Stun_Max_Dur = 3.0
real TG_Dmg = 100 * 0.0312500 / TG_Stun_Max_Dur
real TG_Dist = 800
real TG_Speed = 1300 * 0.0312500
real TG_Aoe = 64
endglobals
function Trig_Tentacle_Grapple_ActionsV2 takes nothing returns nothing
set TG_Loop_Int = 1
loop
exitwhen TG_Loop_Int > TG_Index
if TG_Stun_Dur[TG_Loop_Int] >= TG_Stun_Max_Dur and not TG_Stun_Finished[TG_Loop_Int] then
call IssueImmediateOrder(TG_Caster[TG_Loop_Int], "stop")
call BJDebugMsg("StunFinished")
set TG_Stun_Finished[TG_Loop_Int] = true
elseif GetUnitCurrentOrder(TG_Caster[TG_Loop_Int]) != String2OrderIdBJ("absorb") and TG_Unit_Is_Grappled[TG_Loop_Int] and not TG_Stun_Removed[TG_Loop_Int] and not TG_Stun_Finished[TG_Loop_Int] then
call UnitRemoveBuffBJ( 'B00C', TG_Stunned_U[TG_Loop_Int] )
call BJDebugMsg("RemoveStun")
set TG_Stun_Removed[TG_Loop_Int] = true
elseif GetUnitCurrentOrder(TG_Caster[TG_Loop_Int]) != String2OrderIdBJ("absorb") or TG_Process[TG_Loop_Int] > TG_Dist or TG_Unit_Is_Grappled[TG_Loop_Int] and not UnitHasBuffBJ(TG_Stunned_U[TG_Loop_Int], 'B00C') then
//after the stun finished, return the dummy and delete Effects
set TG_Counter[TG_Loop_Int] = TG_Counter[TG_Loop_Int] - 1
//set TG_Effect = LoadUnitHandleBJ((TG_Counter[TG_Loop_Int] + 1 ), TG_Loop_Int, Hash)
set TG_Effect = LoadUnitHandle(Hash, TG_Loop_Int, (TG_Counter[TG_Loop_Int] + 1 ))
call KillUnit(TG_Effect)
call RemoveUnit(TG_Effect)
call GroupRemoveUnit(TG_Effects_Group,TG_Effect)
call SetUnitX(TG_Dummy[TG_Loop_Int], GetUnitX(TG_Dummy[TG_Loop_Int]) + TG_Speed * Cos((TG_Angel[TG_Loop_Int] - 180) * bj_DEGTORAD))
call SetUnitY(TG_Dummy[TG_Loop_Int], GetUnitY(TG_Dummy[TG_Loop_Int]) + TG_Speed * Sin((TG_Angel[TG_Loop_Int] - 180) * bj_DEGTORAD))
if TG_Counter[TG_Loop_Int] == 0 then
call KillUnit(TG_Dummy[TG_Loop_Int])
call RemoveUnit(TG_Dummy[TG_Loop_Int])
set TG_Caster[TG_Loop_Int] = TG_Caster[TG_Index]
set TG_Dummy[TG_Loop_Int] = TG_Dummy[TG_Index]
set TG_Process[TG_Loop_Int] = TG_Process[TG_Index]
set TG_Unit_Is_Grappled[TG_Loop_Int] = TG_Unit_Is_Grappled[TG_Index]
set TG_Stun_Removed[TG_Loop_Int] = TG_Stun_Removed[TG_Index]
set TG_Stun_Finished[TG_Loop_Int] = TG_Stun_Finished[TG_Index]
set TG_Dummy_Effect[TG_Loop_Int] = TG_Dummy_Effect[TG_Index]
set TG_Grappled_U[TG_Loop_Int] = TG_Grappled_U[TG_Index]
set TG_Target[TG_Loop_Int] = TG_Target[TG_Index]
set TG_Stun_Dummy[TG_Loop_Int] = TG_Stun_Dummy[TG_Index]
set TG_Stunned_U[TG_Loop_Int] = TG_Stunned_U[TG_Index]
set TG_Angel[TG_Loop_Int] = TG_Angel[TG_Index]
set TG_Process[TG_Loop_Int] = TG_Process[TG_Index]
set TG_Stun_Dur[TG_Loop_Int] = TG_Stun_Dur[TG_Index]
set TG_Counter[TG_Loop_Int] = TG_Counter[TG_Index]
set TG_Max_Targets[TG_Loop_Int] = TG_Max_Targets[TG_Index]
set TG_Hash=1
loop
exitwhen TG_Hash>TG_Counter[TG_Index]
call SaveUnitHandle(Hash, TG_Loop_Int, TG_Hash, LoadUnitHandle(Hash, TG_Index, TG_Hash))
set TG_Hash=TG_Hash+1
endloop
call FlushChildHashtable(Hash, TG_Loop_Int)
set TG_Index = TG_Index - 1
set TG_Loop_Int = TG_Loop_Int - 1
if TG_Loop_Int == 0 then
call PauseTimer(TG_Timer)
endif
endif
elseif TG_Unit_Is_Grappled[TG_Loop_Int] and UnitHasBuffBJ(TG_Stunned_U[TG_Loop_Int], 'B00C') and TG_Stun_Dur[TG_Loop_Int] < TG_Stun_Max_Dur then
set TG_Stun_Dur[TG_Loop_Int] = TG_Stun_Dur[TG_Loop_Int] + 0.0312500
call UnitDamageTarget(TG_Caster[TG_Loop_Int], TG_Stunned_U[TG_Loop_Int], TG_Dmg, false, false, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_MAGIC, null)
else
//Move Dummy and Create Effects
set TG_Counter[TG_Loop_Int] = TG_Counter[TG_Loop_Int] + 1
set TG_Process[TG_Loop_Int] = TG_Process[TG_Loop_Int] + TG_Speed
set TG_Dummy_Effect[TG_Loop_Int] = CreateUnit(GetOwningPlayer(TG_Caster[TG_Loop_Int]), 'h003', GetUnitX(TG_Dummy[TG_Loop_Int]), GetUnitY(TG_Dummy[TG_Loop_Int]), TG_Angel[TG_Loop_Int])
call GroupAddUnit(TG_Effects_Group, TG_Dummy_Effect[TG_Loop_Int])
call SaveUnitHandle(Hash, TG_Loop_Int, TG_Counter[TG_Loop_Int], TG_Dummy_Effect[TG_Loop_Int])
call SetUnitX(TG_Dummy[TG_Loop_Int], GetUnitX(TG_Dummy[TG_Loop_Int]) + TG_Speed * Cos(TG_Angel[TG_Loop_Int] * bj_DEGTORAD))
call SetUnitY(TG_Dummy[TG_Loop_Int], GetUnitY(TG_Dummy[TG_Loop_Int]) + TG_Speed * Sin(TG_Angel[TG_Loop_Int] * bj_DEGTORAD))
//Pick Units Around Dummy
call GroupEnumUnitsInRange(TG_Group, GetUnitX(TG_Dummy[TG_Loop_Int]), GetUnitY(TG_Dummy[TG_Loop_Int]), TG_Aoe, null)
loop
set TG_Target[TG_Loop_Int] = FirstOfGroup(TG_Group)
exitwhen TG_Max_Targets[TG_Loop_Int] == 0 or TG_Target[TG_Loop_Int] == null
if GetWidgetLife(TG_Target[TG_Loop_Int]) > 0.405 and not IsUnitType(TG_Target[TG_Loop_Int], UNIT_TYPE_MAGIC_IMMUNE) and IsUnitEnemy(TG_Target[TG_Loop_Int], GetOwningPlayer(TG_Caster[TG_Index])) and IsUnitType(TG_Target[TG_Loop_Int], UNIT_TYPE_STRUCTURE) == false then
set TG_Stunned_U[TG_Loop_Int] = TG_Target[TG_Loop_Int]
set TG_Unit_Is_Grappled[TG_Loop_Int] = true
TG_Max_Targets[TG_Loop_Int] = TG_Max_Targets[TG_Loop_Int] - 1
set TG_Stun_Dummy[TG_Loop_Int] = CreateUnit(GetOwningPlayer(TG_Caster[TG_Loop_Int]), 'h001', GetUnitX(TG_Caster[TG_Loop_Int]), GetUnitY(TG_Caster[TG_Loop_Int]), 270)
call UnitAddAbilityBJ( 'A00K', TG_Stun_Dummy[TG_Loop_Int])
call IssueTargetOrder(TG_Stun_Dummy[TG_Loop_Int], "thunderbolt", TG_Target[TG_Loop_Int])
endif
call GroupRemoveUnit(TG_Group, TG_Target[TG_Loop_Int])
endloop
endif
set TG_Loop_Int = TG_Loop_Int + 1
endloop
endfunction
function Trig_Tentacle_Grapple_Actions takes nothing returns nothing
set TG_Index = (TG_Index + 1)
set TG_Caster[TG_Index] = GetTriggerUnit()
local real xCaster = GetUnitX(TG_Caster[TG_Index])
local real yCaster = GetUnitY(TG_Caster[TG_Index])
local real xTarget = GetSpellTargetX()
local real yTarget = GetSpellTargetY()
set TG_Angel[TG_Index] = bj_RADTODEG * Atan2(yTarget - yCaster, xTarget - xCaster)
set TG_Dummy[TG_Index] = CreateUnit(GetOwningPlayer(TG_Caster[TG_Index]), 'h003', xCaster + 0 * Cos(TG_Angel[TG_Index] * bj_DEGTORAD), yCaster + 0 * Sin(TG_Angel[TG_Index] * bj_DEGTORAD), TG_Angel[TG_Index])
call SetUnitPathing(TG_Dummy[TG_Index], false)
//Animation, Sounds
call SetUnitAnimationByIndex(TG_Caster[TG_Index], 5)
//Addtional Settings
set TG_Process[TG_Index] = 0
set TG_Counter[TG_Index] = 0
set TG_Unit_Is_Grappled[TG_Index] = false
set TG_Grappled_U[TG_Index] = null
set TG_Stun_Removed[TG_Index] = false
set TG_Stun_Finished[TG_Index] = false
set TG_Target[TG_Index] = null
set TG_Dummy_Effect[TG_Index] = null
set TG_Stun_Dummy[TG_Index] = null
set TG_Stunned_U[TG_Index] = null
set TG_Stun_Dur[TG_Index] = 0
set TG_Max_Targets[TG_Index] = 1
//Timer
if TG_Index == 1 then
call TimerStart(TG_Timer, 0.0312500, true, function Trig_Tentacle_Grapple_ActionsV2)
endif
endfunction
function Trig_Tentacle_Grapple_Conditions takes nothing returns boolean
return GetSpellAbilityId() == 'A00J'
endfunction
//===========================================================================
function InitTrig_Tentacle_Grapple takes nothing returns nothing
set gg_trg_Tentacle_Grapple = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Tentacle_Grapple, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_Tentacle_Grapple, Condition( function Trig_Tentacle_Grapple_Conditions ) )
call TriggerAddAction( gg_trg_Tentacle_Grapple, function Trig_Tentacle_Grapple_Actions )
endfunction