library SpellToL
globals
// Ability Code
private constant integer ABIL_CODE = 'A003'
// Maximum Distance between lightnings
private constant real MAX_DISTANCE = 200
// The Spell Dummy
private constant integer DUMMY_CODE = 'h000'
// The Damaging Lightning Ability ID
private constant integer DUMMY_CAST1 = 'A000'
// The Healing Lightning Ability ID
private constant integer DUMMY_CAST2 = 'A002'
// The Healing Lightning
private constant string LIGHTNING_HEAL = "healingwave"
// The Damaging Lightning
private constant string LIGHTNING_CHAIN = "chainlightning"
endglobals
private module Init
private static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t,Condition(function thistype.cast))
set t = null
endmethod
endmodule
private struct Spell extends array
static method filter takes nothing returns boolean
local unit u = GetFilterUnit()
if GetWidgetLife(u)>0.405 and not IsUnitType(u,UNIT_TYPE_STRUCTURE) then
set u=null
return true
endif
set u=null
return false
endmethod
static method cast takes nothing returns boolean
local unit u
local unit t
local unit d
local real x
local real y
local player p
local integer l
local integer i=0
local group g = CreateGroup()
if GetSpellAbilityId()==ABIL_CODE then
set u = GetTriggerUnit()
set p = GetTriggerPlayer()
set t = GetSpellTargetUnit()
set l = GetUnitAbilityLevel(u,ABIL_CODE)
loop
set x = GetUnitX(t)
set y = GetUnitY(t)
set d = CreateUnit(p,DUMMY_CODE,x,y,0)
call UnitApplyTimedLife(d,'BTLF',1.0)
if IsUnitEnemy(t,p) then
call UnitAddAbility(d,DUMMY_CAST1)
call SetUnitAbilityLevel(d,DUMMY_CAST1,l)
call IssueTargetOrder(d,LIGHTNING_CHAIN,t)
else
call UnitAddAbility(d,DUMMY_CAST2)
call SetUnitAbilityLevel(d,DUMMY_CAST2,l)
call IssueTargetOrder(d,LIGHTNING_HEAL,t)
endif
call GroupEnumUnitsInRange(g,x,y,MAX_DISTANCE,function thistype.filter)
set t=FirstOfGroup(g)
call GroupClear(g)
set i=i+1
exitwhen i>4
endloop
endif
call DestroyGroup(g)
set u = null
set t = null
set d = null
set p = null
set g = null
return false
endmethod
implement Init
endstruct
endlibrary