scope Magic initializer init
globals
private constant integer DUMMY_ID = 'h000'
private constant integer ABILITY_CODE = 'BOLT'
private constant real ARC_PER_LEVEL = .15
private constant real OFFSET = 20
private constant attacktype ATTACK_TYPE = ATTACK_TYPE_NORMAL
private constant damagetype DAMAGE_TYPE = DAMAGE_TYPE_NORMAL
private constant weapontype WEAPON_TYPE = null
endglobals
private function DAMAGE takes integer lvl, unit u returns real
return (1.1 + (lvl * .1)) * GetHeroInt(u, true)
endfunction
private function DUMMY_UNITS takes integer lvl returns real
return 3 + (lvl * 1.)
endfunction
struct Bolts
unit Caster
unit Target
unit Dummyunit
real Disttogo
real Disthalved
endstruct
private function MoveUnits takes nothing returns boolean
local Bolts b = KT_GetData()
local integer level = GetUnitAbilityLevel(b.Caster, ABILITY_CODE)
local real damage = DAMAGE(level, b.Caster)
local real units = DUMMY_UNITS(level)
local real casterx = GetUnitX(b.Caster)
local real castery = GetUnitY(b.Caster)
local real targetx = GetUnitX(b.Target)
local real targety = GetUnitY(b.Target)
local real dummyx = GetUnitX(b.Dummyunit)
local real dummyy = GetUnitY(b.Dummyunit)
local real distx = targetx - dummyx
local real disty = targety - dummyy
local real distance = SquareRoot(distx * distx + disty * disty)
local real offsetx
local real offsety
local real angle = GetUnitFacing(b.Dummyunit)
if distance <= 50 then
call UnitDamageTarget(b.Caster, b.Target, (damage / units), false, false, ATTACK_TYPE, DAMAGE_TYPE, WEAPON_TYPE)
call KillUnit(b.Dummyunit)
call b.destroy()
return true
elseif b.Disttogo <= b.Disthalved then
set angle = bj_RADTODEG * Atan2(targety - dummyy, targetx - dummyx)
set offsetx = dummyx + OFFSET * Cos(angle * bj_DEGTORAD)
set offsety = dummyy + OFFSET * Sin(angle * bj_DEGTORAD)
call SetUnitX(b.Dummyunit, offsetx)
call SetUnitY(b.Dummyunit, offsety)
call SetUnitFacing(b.Dummyunit, angle)
else
set b.Disttogo = b.Disttogo - OFFSET
set offsetx = dummyx + OFFSET * Cos(angle * bj_DEGTORAD)
set offsety = dummyy + OFFSET * Sin(angle * bj_DEGTORAD)
call SetUnitX(b.Dummyunit, offsetx)
call SetUnitY(b.Dummyunit, offsety)
call SetUnitFacing(b.Dummyunit, angle + .25)
endif
return false
endfunction
private function CreateStructs takes unit caster, unit target, real facing returns nothing
local Bolts b = Bolts.create()
local integer level = GetUnitAbilityLevel(b.Caster, ABILITY_CODE)
local real units = DUMMY_UNITS(level)
local real casterx = GetUnitX(caster)
local real castery = GetUnitY(caster)
local real targetx = GetUnitX(target)
local real targety = GetUnitY(target)
local real Distx = targetx - casterx
local real Disty = targety - castery
set b.Caster = caster
set b.Target = target
set b.Disttogo = SquareRoot(Distx * Distx + Disty * Disty)
set b.Disthalved = b.Disttogo / 2
set b.Dummyunit = CreateUnit( GetTriggerPlayer(), DUMMY_ID, casterx, castery, facing)
call KT_Add( function MoveUnits, b, 0.03)
endfunction
private function OnCast takes nothing returns nothing
local integer level = GetUnitAbilityLevel(GetTriggerUnit(), ABILITY_CODE)
local real units = DUMMY_UNITS(level)
local unit caster = GetTriggerUnit()
local unit target = GetSpellTargetUnit()
local integer i = 0
local real angle = bj_RADTODEG * Atan2(GetUnitY(target) - GetUnitY(caster), GetUnitX(target) - GetUnitX(caster)) + 50
if GetSpellAbilityId() == ABILITY_CODE then
loop
exitwhen i == units
call CreateStructs(caster, target, (angle - 10 * i))
set i = i + 1
endloop
set caster = null
set target = null
endif
endfunction
//===========================================================================
private function init takes nothing returns nothing
local trigger t = CreateTrigger( )
call TriggerAddAction( t, function OnCast )
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
endfunction
endscope