library ShootLightningInFrontOfCaster initializer spellOnInit requires Missile
globals
integer ABILITY = 'A04A'
endglobals
struct MissileHandler
static method onCollide takes Missile this, unit justHit returns boolean
local boolean b
if justHit != null then and this.source != justHit and not IsUnitAlly(justHit, GetOwningPlayer(this.source)) then
if GetUnitAbilityLevel(justHit, 'A00H') > 0 then
set b = GetWidgetLife(justHit) >= 2000000.402
else
set b = GetWidgetLife(justHit) >= 0.402
endif
if b then
call UnitDamageTarget(this.source, justHit, GetHeroAgi(this.source, true) * (3 + (0.2 * GetUnitAbilityLevel(this.source,ABILITY))),true,false,ATTACK_TYPE_MAGIC,DAMAGE_TYPE_UNKNOWN,WEAPON_TYPE_WHOKNOWS)
return true
endif
endif
endif
return false
endmethod
implement MissileStruct
endstruct
private function add takes Missile m, unit caster returns nothing
set m.model = "war3mapImported\\Lightning Bolt.mdl"
set m.speed = 30
set m.collision = 100
set m.source = caster
call MissileHandler.launch(m)
endfunction
private function onCast takes nothing returns boolean
local unit caster
local AdvLoc orig
local AdvLoc dest
local Missile m
local integer numBolts
local real angleDifferentialBetweenBolts
local integer i = 0
local real currentBolt
if GetSpellAbilityId() != 'A04A' then
return false
endif
set caster = GetTriggerUnit()
set orig = AdvLoc.create(GetUnitX(caster),GetUnitY(caster),50)
set dest = AdvLoc.create(GetSpellTargetX(),GetSpellTargetY(),50)
set numBolts = 2+GetUnitAbilityLevel(caster, 'A04A')
set angleDifferentialBetweenBolts = bj_DEGTORAD*5
call AdvLoc.link(orig,dest)
if ModuloInteger(R2I(numBolts),2) == 0 then
set currentBolt = orig.angle + (angleDifferentialBetweenBolts/2)
if numBolts > 2 then
set currentBolt = currentBolt + (angleDifferentialBetweenBolts*((numBolts/2)-1))
endif
else
set currentBolt = orig.angle
if numBolts > 2 then
set currentBolt = currentBolt + (angleDifferentialBetweenBolts*((numBolts-1)/2))
endif
endif
loop
exitwhen i == numBolts
set m = Missile.create(orig.x, orig.y, 50, currentBolt, 900, 50)
set currentBolt = currentBolt - angleDifferentialBetweenBolts
call add(m,caster)
set i = i + 1
endloop
set caster = null
call orig.unlock()
call dest.unlock()
return false
endfunction
private function spellOnInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t, Filter(function onCast))
endfunction
endlibrary