scope Rend initializer Init
globals
//ability id of Rend
private constant integer ABILITY_ID = 'A005'
//refresh rate of timer
private constant real INTERVAL = 0.01
//total ticks of spell
private constant integer TICKS = 9
//number of "INTERVAL"s between ticks
private constant integer TIME = 100
//damage attack type
private constant attacktype ATTACK_TYPE = ATTACK_TYPE_NORMAL
//damage damage type
private constant damagetype DAMAGE_TYPE = DAMAGE_TYPE_NORMAL
//damage weapon type
private constant weapontype WEAPON_TYPE = WEAPON_TYPE_WHOKNOWS
//blood effect when dealing damage
private constant string BLOOD_EFFECT = "Objects\\Spawnmodels\\Critters\\Albatross\\CritterBloodAlbatross.mdl"
//attach point
private constant string EFFECT_ATTACH = "chest"
private hashtable h = InitHashtable()
endglobals
private function Damage takes integer level, integer agi, integer str returns real
return I2R(level) * ( I2R(agi) + 3.00 * (I2R(str)) ) / 5.00
endfunction
private struct data
unit c
unit t
timer tim = CreateTimer()
integer lvl
integer ticks = TICKS
integer time = TIME
integer agi
integer str
endstruct
private function periodic takes nothing returns nothing
local data dat = LoadInteger(h,GetHandleId(GetExpiredTimer()),0)
if dat.time >= 0 then
set dat.time = dat.time - 1
else
if dat.ticks > 0 then
set dat.ticks = dat.ticks - 1
call UnitDamageTarget(dat.c, dat.t, Damage(dat.lvl, dat.agi, dat.str), true, false, ATTACK_TYPE, DAMAGE_TYPE, WEAPON_TYPE)
call DestroyEffect(AddSpecialEffectTarget(BLOOD_EFFECT, dat.t, EFFECT_ATTACH))
if dat.ticks > 0 then
set dat.time = TIME
else
call PauseTimer(dat.tim)
call DestroyTimer(dat.tim)
call FlushChildHashtable(h,GetHandleId(dat.tim))
call dat.destroy()
endif
endif
endif
endfunction
private function Conditions takes nothing returns boolean
local data dat
if GetSpellAbilityId() == ABILITY_ID then
set dat = data.create()
set dat.t = GetSpellTargetUnit()
set dat.c = GetTriggerUnit()
set dat.lvl = GetUnitAbilityLevel(dat.c, ABILITY_ID)
set dat.agi = GetHeroAgi(dat.c, true)
set dat.str = GetHeroStr(dat.c, true)
call SaveInteger(h,GetHandleId(dat.tim),0,dat)
call TimerStart(dat.tim,INTERVAL,true,function periodic)
endif
return false
endfunction
//===========================================================================
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( t, Condition( function Conditions ) )
call Preload(BLOOD_EFFECT)
set t = null
endfunction
endscope