//***************************************************************************
//*
//* Aspect of Lightning.
//*
//***************************************************************************
//===========================================================================
// AoL_Tick
// takes nothing
// returns nothing
//
// Handles the periodic effect of Aspect of Lightning (defaulted at 1 second).
// This is called internally by the aura system with Aura_Index set to the aura's id number.
//===========================================================================
function AoL_Tick takes nothing returns nothing
// ***** Local variables *****
local unit Caster =Aura_Caster[Aura_Index] // The owner of the aura.
local unit Target =GroupPickRandomUnit(Aura_TargetsAdd[Aura_Index])// The potential target for the aura to zap.
local real X =GetUnitX(Caster) // The x coordinate of the owner of the aura.
local real Y =GetUnitY(Caster) // The y coordinate of the owner of the aura.
local unit Dummy // The potential dummy caster to zap the potential target.
local integer SpellId=AoL_LightningId // The zap spell's object id.
local real Mana =GetUnitState(Caster,UNIT_STATE_MANA) // How much mana the owner of the aura has.
local integer Number =25 // How many lightning bolts to create.
local real Angle // The start point of the lightning bolt.
local real Angle2 // The end point of the lightning bolt.
local real Radius =Aura_Radius[Aura_Index] // The radius of the aura.
// ***** Zap random target *****
if(Target!=null)then // If a target exists, zap it.
// ***** Check empowered *****
if(AoL_Empowered[Aura_Index])then
// Check the mana of the caster to see if we can be empowered.
if(Mana>=AoL_ManaUseage)then
set SpellId=AoL_EmpoweredId
call SetUnitState(Caster,UNIT_STATE_MANA,Mana-AoL_ManaUseage)
// ***** Create lightning pulse effect denoting the AoE of the aura *****
loop
exitwhen Number==0
set Angle=GetRandomReal(0,TWO_PI)
set Angle2=Angle+GetRandomReal(.5,1.5)
call Bolt(AoL_EmpoweredType,X+Radius*Cos(Angle),Y+Radius*Sin(Angle),X+Radius*Cos(Angle2),Y+Radius*Sin(Angle2),GetRandomReal(0.5,1))
set Number=Number-1
endloop
else // Not enough mana, unempower the aura.
call IssueImmediateOrderById(Caster,AoL_UnempowerOrderId)
endif
endif
set Dummy=CreateUnit(GetOwningPlayer(Caster),Cast_DummyId,X,Y,Atan2(GetUnitY(Target)-Y,GetUnitX(Target)-X))
call UnitAddAbility(Dummy,SpellId)
call SetUnitAbilityLevel(Dummy,SpellId,GetUnitAbilityLevel(Caster,AoL_AbilityId))
call IssueTargetOrderById(Dummy,AoL_LightningOrderId,Target)
call UnitApplyTimedLife(Dummy,'BTLF',1)
set Dummy=null
set Target=null
endif
// ***** Clean-up *****
set Caster=null
endfunction
//===========================================================================
// AoL_Update
// takes nothing
// returns nothing
//
// Updates the aura every Aura_TIMEOUT seconds. Called internally by the
// aura system with Aura_Index set to the aura's id number.
//===========================================================================
function AoL_Update takes nothing returns nothing
local unit Caster=Aura_Caster[Aura_Index]
local string LightningType=AoL_LightningType
local real Angle=GetRandomReal(0,TWO_PI)
local real Angle2=Angle+GetRandomReal(.5,1.5)
local real X=GetUnitX(Caster)
local real Y=GetUnitY(Caster)
local real Radius=Aura_Radius[Aura_Index]
if(AoL_Empowered[Aura_Index])then
set LightningType=AoL_EmpoweredType
endif
call Bolt(LightningType,X+Radius*Cos(Angle),Y+Radius*Sin(Angle),X+Radius*Cos(Angle2),Y+Radius*Sin(Angle2),GetRandomReal(0.5,1))
set Caster=null
endfunction
//===========================================================================
// AoL_Enter
// takes nothing
// returns boolean - true means add the unit to the aura's targets, false means don't add the unit to the aura's targets.
//
// This is called in response to a unit entering the area of effect of the aura.
// The trigger has the aura's id number stored in it. This aura filters based
// on if the unit is allied. Only enemies are added.
//===========================================================================
function AoL_Enter takes nothing returns boolean
return not IsUnitAlly(GetTriggerUnit(),GetOwningPlayer(Aura_Caster[LoadInteger(Hash,GetHandleId(GetTriggeringTrigger()),0)]))
endfunction
//===========================================================================
// AoL_Create
// takes unit Unit - The unit to attach the aura to.
// real Radius - How big the aura is.
// returns integer - The aura id of the newly created aura.
//
// Creates a new instance of the Aspect of Lightning aura.
// Attaches the aura to the unit via hashtable.
//===========================================================================
function AoL_Create takes unit Unit,real Radius returns integer
local integer AuraId=AS_Create(Unit,Radius,1,AoL_EnterFilter,AoL_TickFilter,AoL_UpdateFilter)
set AoL_Empowered[AuraId]=false
call SaveInteger(Hash,GetHandleId(Unit),AoL_Index,AuraId)
return AuraId
endfunction
//===========================================================================
// AoL_SwitchState
// takes nothing
// returns nothing
//
// This switches the aura's empowered state from on to off and off to on
// based on handling issued unit orders. This catches right-clicking
// the aura's icon (autocast toggling).
//===========================================================================
function AoL_SwitchState takes nothing returns nothing
set AoL_Empowered[LoadInteger(Hash,GetHandleId(GetTriggerUnit()),AoL_Index)]=GetIssuedOrderId()==AoL_EmpowerOrderId
endfunction
//===========================================================================
// AoL_Cast
// takes nothing
// returns nothing
//
// Triggers when the owner of the aura activates the aura by left-clicking it (casting).
// The triggering unit has the aura id number attached to it.
//===========================================================================
function AoL_Cast takes nothing returns nothing
// ***** Local variables *****
local unit Caster =GetTriggerUnit() // The owner of the aura that just activated it.
local player Owner =GetTriggerPlayer() // The player that owns the aura's owner.
local integer AuraId =LoadInteger(Hash,GetHandleId(Caster),AoL_Index)// The aura id the aura's owner is attached to.
local integer Level =GetUnitAbilityLevel(Caster,AoL_AbilityId) // The level of the aura.
local group GroupIterate=Aura_TargetsAdd[AuraId] // The group of targets to iterate over.
local group GroupAdd =Aura_TargetsPtr[AuraId] // The new group of targets to add iterated targets to.
local unit Unit // The current target.
local unit Dummy // Dummy casters to cast 'Purge' on the iterated targets.
// ***** Iterate over targets *****
loop
// ***** Set-up loop *****
set Unit=FirstOfGroup(GroupIterate)
exitwhen Unit==null // Exit once iterated group is empty.
// ***** Swap the unit *****
call GroupRemoveUnit(GroupIterate,Unit)
call GroupAddUnit(GroupAdd,Unit)
// ***** Cast 'Purge' on the unit *****
set Dummy=CreateUnit(Owner,Cast_DummyId,GetUnitX(Unit),GetUnitY(Unit),0)
call UnitAddAbility(Dummy,AoL_PurgeId)
call SetUnitAbilityLevel(Dummy,AoL_PurgeId,Level)
call IssueTargetOrderById(Dummy,AoL_PurgeOrderId,Unit)
call UnitApplyTimedLife(Dummy,'BTLF',1)
// ***** Clean-up loop *****
set Dummy=null
set Unit=null
endloop
// ***** Swap unit groups *****
set Aura_TargetsAdd[AuraId]=GroupAdd
set Aura_TargetsPtr[AuraId]=GroupIterate
// ***** Clean-up *****
set GroupAdd=null
set GroupIterate=null
set Caster=null
set Owner=null
endfunction