scope Formation initializer Init
struct formation
unit caster
integer spellLvl
integer auraLvl
boolean isAlive
filterfunc filter
group alliesInRange
static integer array Ar
static integer Total = 0
static timer Tim = CreateTimer()
static integer spellId = 'A002'
static integer auraId = 'ForA'
static real radius = 400.0
method filterAlliesInRange takes nothing returns boolean
local formation f
local unit filteredUnit = GetFilterUnit()
return (IsUnitAlly(filteredUnit, GetTriggerPlayer()) and IsUnitType(filteredUnit, UNIT_TYPE_HERO) and not (filteredUnit == f.caster))
endmethod
method getAuraLevel takes nothing returns integer
local formation f
local integer n = CountUnitsInGroup(f.alliesInRange)
return (f.spellLvl + n)
endmethod
method tic takes nothing returns nothing
local formation f
local integer i = 0
loop
exitwhen i >= f.Total
set f = f.Ar[i]
set f.isAlive = (GetUnitState(f.caster, UNIT_STATE_LIFE) <= 0)
call GroupEnumUnitsInRange(f.alliesInRange, GetUnitX(f.caster), GetUnitY(f.caster), f.radius, f.filter)
if f.isAlive == TRUE then
set f.spellLvl = GetUnitAbilityLevel(f.caster, f.spellId)
set f.auraLvl = GetUnitAbilityLevel(f.caster, f.auraId)
call SetUnitAbilityLevel(f.caster, f.auraId, f.getAuraLevel())
endif
set i = i + 1
endloop
if f.Total == 0 then
call PauseTimer(f.Tim)
endif
endmethod
static method create takes unit u returns formation
local formation f = formation.allocate()
set filter = Filter(function f.filterAlliesInRange()) //Syntax Error
set f.caster = u
set f.isAlive = TRUE
if f.Total == 0 then
call TimerStart(f.Tim, 0.1, TRUE, function f.tic) //f is not a struct name
endif
set f.Ar[f.Total] = f
set f.Total = f.Total + 1
return f
endmethod
endstruct
///////////////////////////////////////////////////////////
function Conditions takes nothing returns boolean
local formation f
return (GetUnitAbilityLevel(f.caster, f.spellId) == 1)
endfunction
function Actions takes nothing returns nothing
local formation f
call UnitAddAbility(f.caster, f.auraId)
set f = formation.create(GetTriggerUnit())
endfunction
//===========================================================================
function Init takes nothing returns nothing
local trigger trig = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_HERO_SKILL )
call TriggerAddCondition( trig, Condition( function Conditions ) )
call TriggerAddAction( trig, function Actions )
endfunction
endscope