scope RotatingBlades
globals
//edit the values to customize
private integer ABILITY_CODE = 'A000'
private integer DUMMY_UNIT_CODE = 'h000'
private attacktype ATTACK_TYPE = ATTACK_TYPE_HERO
private damagetype DAMAGE_TYPE = DAMAGE_TYPE_NORMAL
private real LOOP_INTERVAL = 0.0315
private real HOVER_DIST = 150
private real HOVER_DIST_DUR_DAM = 50
private real MOVE_SPEED = 20
private real ROTATE_SPEED = 1.5 //in degrees
private integer DAM_DUR = 16
private integer HOVER_DUR = 33
private string ATTACH_MODEL = "Abilities\\Spells\\Other\\Stampede\\StampedeMissileDeath.mdl" //effect when dealing damage
private string ATTACH_POINT = "chest"
//do not edit below
private timer LoopTimer = CreateTimer()
endglobals
//edit the return value to change the no of times blade swoops per level
private function NoOfSwoopsPerLevel takes integer lvl returns integer
return 2+lvl
endfunction
//edit the return value to change the damage dealt by blade per loop
private function DamagePerLevel takes integer lvl returns real
return 3.0+lvl //this * DAM_DUR gives total damage per swoop
endfunction
private struct Blade
unit blade
unit caster
unit target
integer lvl
integer dur
integer swoops
integer status
real angle
effect model
static Blade array Data
static integer top = 0
static method BladeLoop takes nothing returns nothing
local integer i = 1
local Blade bld
local real dist
local real x
local real y
local real tx
local real ty
local boolean kill
loop
exitwhen i > top
set kill = false
set bld = Data[i]
if bld.status == 2 then
set bld.angle = bld.angle + ROTATE_SPEED
set dist = HOVER_DIST
if bld.dur < 5 then
set dist = HOVER_DIST*(bld.dur)/5
elseif HOVER_DUR - bld.dur < 5 then
set dist = HOVER_DIST*(HOVER_DUR - bld.dur)/5
endif
set x = GetUnitX(bld.target)
set y = GetUnitY(bld.target)
set bld.dur = bld.dur - 1
if bld.dur == 0 then
set bld.status = 3
set bld.dur = DAM_DUR
set bld.model = AddSpecialEffectTarget(ATTACH_MODEL, bld.target, ATTACH_POINT)
endif
elseif bld.status == 1 then
set tx = GetUnitX(bld.target)
set ty = GetUnitY(bld.target)
set x = GetUnitX(bld.blade)
set y = GetUnitY(bld.blade)
set bld.angle = Atan2(ty - y, tx - x)
set dist = MOVE_SPEED
if RAbsBJ(x - tx) < HOVER_DIST and RAbsBJ(y - ty) < HOVER_DIST then
set bld.status = 2
set bld.dur = HOVER_DUR
set bld.swoops = NoOfSwoopsPerLevel(bld.lvl)
endif
else
set bld.dur = bld.dur - 1
set dist = HOVER_DIST_DUR_DAM
set x = GetUnitX(bld.target)
set y = GetUnitY(bld.target)
call UnitDamageTarget(bld.caster, bld.target, DamagePerLevel(bld.lvl), true, false, ATTACK_TYPE, DAMAGE_TYPE, null)
if bld.dur == 0 then
set bld.swoops = bld.swoops - 1
set bld.status = 2
set bld.dur = HOVER_DUR
call DestroyEffect(bld.model)
set bld.model = null
endif
endif
call SetUnitPosition(bld.blade, x + dist*Cos(bld.angle), y + dist*Sin(bld.angle))
//call SetUnitX(bld.blade, x + dist*Cos(bld.angle))
//call SetUnitY(bld.blade, y + dist*Sin(bld.angle))
if IsUnitType(bld.target, UNIT_TYPE_DEAD) or bld.swoops == 0 then
call RemoveUnit(bld.blade)
call bld.destroy()
set Data[i] = Data[top]
set top = top - 1
if top == 0 then
call PauseTimer(LoopTimer)
return
endif
else
set i = i + 1
endif
endloop
endmethod
static method Create takes nothing returns boolean
local Blade bld = .allocate()
local unit trig = GetTriggerUnit()
local unit tar = GetSpellTargetUnit()
local real x = GetUnitX(trig)
local real y = GetUnitY(trig)
local real tx = GetUnitX(tar)
local real ty = GetUnitY(tar)
set bld = .allocate()
set bld.caster = trig
set bld.target = tar
set bld.angle = Atan2(ty - y, tx - x)
set bld.blade = CreateUnit(GetTriggerPlayer(), DUMMY_UNIT_CODE, x, y, bld.angle)
set bld.lvl = GetUnitAbilityLevel(bld.caster, ABILITY_CODE)
set bld.status = 1
set bld.dur = 1
set bld.swoops = 1
set top = top + 1
set Data[top] = bld
if top == 1 then
call TimerStart(LoopTimer, LOOP_INTERVAL, true, function Blade.BladeLoop)
endif
return false
endmethod
static method onInit takes nothing returns nothing
call RegisterSpellEffectEvent(ABILITY_CODE, function Blade.Create)
endmethod
endstruct
endscope