library ForkedLightning initializer init requires TimerUtils
globals
private constant integer S_ID = 'A000' //This is the spell id (rawcode)
private constant attacktype A = ATTACK_TYPE_NORMAL
private constant damagetype D = DAMAGE_TYPE_NORMAL
private constant weapontype W = WEAPON_TYPE_WHOKNOWS
private constant real L_DESTROY = 0.20 //After this time, the lightning effect (L_SFT) is destroyed.
private constant string L_SFX = "AFOD" // The lightning effect (here: Finger of Death)
private constant string T_SFX = "Abilities\\Spells\\Demon\\DemonBoltImpact\\DemonBoltImpact.mdl" // The effect on the targets (Here: Finger of Death Target)
// Don't change the constants under this line please \\
private constant real L_TIME = 0.04
private constant group G = CreateGroup()
endglobals
private function damage takes integer level returns real // Here I set the damage to each target
return 85. * level
endfunction
private function maxtargets takes integer level returns integer // Here I set the maximal possible targets of the spell
return 5 + level
endfunction
private function area takes integer level returns real // This is the area around the targets and picks all possible targets for the damage
return 250.
endfunction
private function widgetlife takes integer level returns real // This is the value, how many % the caster gets to life (0.25% of the complet dealed damage)
return 0.25
endfunction
// Configuration ends here. Don't change something below, if you don't know, what to do! \\
private struct ForkedLightning
static thistype TEMP
unit caster = null
unit target = null
lightning array l[8] // You have to change this value (8 here) into the maximal possible targets!!!!!!
real c = 0.
real d = 0.
real a = 0.
real p = 0.
real w = 0.
integer i = 0
integer mt = 0
integer ct = 0
private static method filter takes nothing returns boolean
local thistype this = TEMP
local unit u = GetFilterUnit()
if .ct <= .mt and GetWidgetLife(u) > 0.405 and IsUnitEnemy(u,GetOwningPlayer(.caster)) and IsUnitType(u,UNIT_TYPE_STRUCTURE) == false and IsUnitType(u,UNIT_TYPE_MAGIC_IMMUNE) == false then
set .l[.i] = AddLightning(L_SFX,true,GetUnitX(.caster),GetUnitY(.caster),GetUnitX(u),GetUnitY(u))
call DestroyEffect(AddSpecialEffectTarget(T_SFX,u,"chest"))
set .i = .i + 1
set .ct = .ct + 1
call UnitDamageTarget(.caster,u,.d,true,false,A,D,W)
endif
set .w = .ct * .d * .p
call SetWidgetLife(.caster,GetWidgetLife(.caster) + .w)
return false
endmethod
private static method Loop takes nothing returns nothing
local timer t = GetExpiredTimer()
local thistype this = GetTimerData(t)
local integer i = 0
set .c = .c + L_TIME
call DisplayTimedTextToPlayer(Player(0),0.,0.,2.,R2S(.c))
if .c >= L_DESTROY then
loop
exitwhen i == .i
call DestroyLightning(.l[i])
set i = i + 1
endloop
call .destroy()
call ReleaseTimer(t)
endif
set t = null
endmethod
static method create takes unit caster,unit target returns thistype
local thistype this = .allocate()
local timer t = NewTimer()
set .caster = caster
set .target = target
set .d = damage(GetUnitAbilityLevel(.caster,S_ID))
set .mt = maxtargets(GetUnitAbilityLevel(.caster,S_ID))
set .a = area(GetUnitAbilityLevel(.caster,S_ID))
set .p = widgetlife(GetUnitAbilityLevel(.caster,S_ID))
set TEMP = this
call GroupEnumUnitsInRange(G,GetUnitX(.target),GetUnitY(.target),.a,Condition(function ForkedLightning.filter))
call SetTimerData(t,this)
call TimerStart(t,L_TIME,true,function ForkedLightning.Loop)
set t = null
return this
endmethod
endstruct
private function cast takes nothing returns boolean
if GetSpellAbilityId() == S_ID then
call ForkedLightning.create(GetTriggerUnit(),GetSpellTargetUnit())
endif
return false
endfunction
private function init takes nothing returns nothing
local trigger t = CreateTrigger()
local integer i = 0
loop
exitwhen i == 16
call TriggerRegisterPlayerUnitEvent(t,Player(i),EVENT_PLAYER_UNIT_SPELL_EFFECT,null)
set i = i + 1
endloop
call TriggerAddCondition(t,Condition(function cast))
call Preload(L_SFX)
call Preload(T_SFX)
set t = null
endfunction
endlibrary