library Knockback uses ABC, BorderSafety
globals
private constant real INTERVAL = 0.035
private constant string EFFECT_STRING = "Abilities\\Spells\\Orc\\MirrorImage\\MirrorImageDeathCaster.mdl"
private constant string ATTACH_POINT = "origin"
endglobals
private struct KBdata
unit whichUnit
unit target
string effectPath
string attachPoint
effect knockEffect
real dx
real dy
real periodDamage
timer clock = CreateTimer ()
integer ticks
static method create takes unit whichUnit, unit target, real direction, real distance, real damage, real duration, string effectPath, string attachPoint returns KBdata
local KBdata dat = KBdata.allocate()
set dat.whichUnit = whichUnit
set dat.target = target
set dat.effectPath = effectPath
set dat.attachPoint = attachPoint
set dat.dx = ((distance / duration) * INTERVAL) * Cos (direction * bj_DEGTORAD )
set dat.dy = ((distance / duration) * INTERVAL) * Sin (direction * bj_DEGTORAD )
set dat.periodDamage = ((damage / duration) * INTERVAL)
set dat.ticks = R2I (duration / INTERVAL)
call SetTimerStructA(dat.clock, dat)
return dat
endmethod
method onDestroy takes nothing returns nothing
call ClearTimerStructA(.clock)
call PauseTimer (.clock)
call DestroyTimer (.clock)
call DestroyEffect (.knockEffect)
call SetUnitPathing (.target, true)
endmethod
endstruct
private function KnockbackUnit_Handler takes nothing returns nothing
local timer exprTimer = GetExpiredTimer ()
local KBdata dat = GetTimerStructA(exprTimer)
local real x
local real y
if (dat.ticks <= 0) then
call dat.destroy()
else
set dat.ticks = dat.ticks - 1
set x = GetUnitX (dat.target) + dat.dx
set y = GetUnitY (dat.target) + dat.dy
call DestroyEffect (dat.knockEffect)
set dat.knockEffect = AddSpecialEffectTarget (dat.effectPath, dat.target, dat.attachPoint)
call SetUnitPosition (dat.target, x, y)
call UnitDamageTarget (dat.whichUnit, dat.target, dat.periodDamage, true, false, ATTACK_TYPE_CHAOS , DAMAGE_TYPE_UNKNOWN , WEAPON_TYPE_WHOKNOWS )
call SetUnitPathing (dat.target, false)
endif
set exprTimer = null
endfunction
function UnitKnockTargetEx takes unit whichUnit, unit target, real direction, real distance, real damage, real duration, string effectPath, string attachPoint returns nothing
local KBdata dat = KBdata.create(whichUnit, target, direction, distance, damage, duration, effectPath, attachPoint)
call SetUnitPathing (dat.target, false)
call TimerStart (dat.clock, INTERVAL, true, function KnockbackUnit_Handler)
set dat.knockEffect = AddSpecialEffectTarget (dat.effectPath, dat.target, dat.attachPoint)
endfunction
function UnitKnockTarget takes unit whichUnit, unit target, real direction, real distance, real damage, real duration returns nothing
call UnitKnockTargetEx(whichUnit, target, direction, distance, damage, duration, EFFECT_STRING, ATTACH_POINT)
endfunction
endlibrary
an ugly example right?KB system