scope DarkOrb initializer Init
globals
private constant integer SPELL_ID = 'A00C'
private constant integer PROJ_MODEL = 'e00F'
private constant string IMPACT_SFX = "DarkFlash.mdx"
private constant real RANGE = 1000.
endglobals
struct darkorb
unit caster
unit dummy
real angle
integer tick
real distance
real dmg
endstruct
private function Conds takes nothing returns boolean
return GetSpellAbilityId() == SPELL_ID
endfunction
private function TargetFilter takes nothing returns boolean
return IsUnitEnemy(GetFilterUnit(), (GetOwningPlayer(GetTriggerUnit()))) and IsUnitAliveBJ(GetFilterUnit()) and IsUnitType(GetFilterUnit(), UNIT_TYPE_MAGIC_IMMUNE) and IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE)
endfunction
private function Fire takes nothing returns nothing
local timer ti = GetExpiredTimer()
local darkorb do = GetTimerData(ti)
local location loc1 = GetUnitLoc(do.dummy)
local location loc2 = GetSpellTargetLoc()
local location loc3
local real x = GetLocationX(loc3)
local real y = GetLocationY(loc3)
local unit u = GetClosestUnit(x, y, Condition(function TargetFilter))
set do.angle = AngleBetweenPoints(loc1, loc2)
set loc3 = PolarProjectionBJ(loc1, do.distance, do.angle)
call SetUnitFacing(do.dummy, do.angle)
call SetUnitPositionLoc(do.dummy, loc3)
call RemoveLocation(loc1)
call RemoveLocation(loc2)
call RemoveLocation(loc3)
set loc1 = null
set loc2 = null
set loc3 = null
set do.tick = do.tick - 1
if do.tick <= 0 then
call do.destroy()
call ReleaseTimer(ti)
call RemoveUnit(do.dummy)
call DestroyEffect(AddSpecialEffect(IMPACT_SFX, x, y))
else
call UnitDamageTargetEx(do.caster, u, do.dmg, false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, null)
endif
set u = null
set ti = null
endfunction
private function Setup takes unit caster, unit dummy, real angle, real distance, real dmg returns nothing
local darkorb do = darkorb.create()
local timer ti = NewTimer()
set do.caster = caster
set do.dmg = dmg
set do.dummy = dummy
set do.angle = angle
set do.tick = R2I(RANGE/0.04)
set do.distance = RANGE/do.tick
call SetTimerData(ti, do)
call TimerStart(ti, 0.04, true, function Fire)
set ti = null
endfunction
private function Actions takes nothing returns nothing
local unit c = GetTriggerUnit()
local real angle = GetUnitFacing(c)
local location cloc = GetUnitLoc(c)
local real dmg = (I2R(GetUnitAbilityLevel(c, SPELL_ID)*10)+20)+((I2R(GetHeroInt(c, true)))*GetRandomReal(0.5,1.5))
local unit dummy
call CreateUnitAtLoc(GetOwningPlayer(c), PROJ_MODEL, cloc, angle)
set dummy = GetLastCreatedUnit()
call Setup(c, dummy, angle, RANGE, dmg)
call RemoveLocation(cloc)
set dummy = null
set cloc = null
set c = null
endfunction
//===========================================================================
private function Init takes nothing returns nothing
local trigger trg = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( trg, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddAction(trg, function Actions)
call TriggerAddCondition(trg, function Conds)
endfunction
endscope