globals
hashtable STASSkills = InitHashtable()
hashtable STASIndexer = InitHashtable()
integer ONE_SPELL = 'A000'
integer ONE_TO_TWO_SPELL = 'A001'
integer TWO_TO_THREE_SPELL = 'A002'
real ONE_TO_TWO_SPELL_ET = 3.00
real TWO_TO_ONE_SPELL_ET = 1.00
endglobals
library STAS
function CreateTemporaryAbility takes integer bs, integer ns, real nset returns nothing
call SaveInteger(STASSkills, bs, StringHash("NEXT"), ns)
call SaveReal(STASSkills, bs, StringHash("EXPTIME"), nset)
endfunction
function STASTemporaryTimeHandler takes nothing returns nothing
// USE: On timer expiration, remove the next spell
// Get the expired timer
local timer t = GetExpiredTimer()
// Get the caster unit through timer ID
local unit caster = LoadUnitHandle(STASIndexer, GetHandleId(t), StringHash("CASTER"))
// Get the next_spell spell ID
local integer NEXT = LoadInteger(STASIndexer, GetHandleId(t), StringHash("NEXT"))
// Remove the spell
call UnitRemoveAbility(caster, NEXT)
// For avoid bugs of timer, pause it
call PauseTimer(t)
// Destroy the timer
call DestroyTimer(t)
// Remove leak
set t = null
set caster = null
endfunction
function CastTemporaryAbility takes unit cu, integer cs returns nothing
local real et
local timer t
local integer ns = LoadInteger(STASSkills, cs, StringHash("NEXT"))
if (ns != 0) then
// Initialize the timer
set t = CreateTimer()
// Save expiration time
set et = LoadReal(STASSkills, cs, StringHash("EXPTIME"))
// Save to hashtable the unit that cast the spell
call SaveUnitHandle(STASIndexer, GetHandleId(t), StringHash("CASTER"), cu)
// Save the next_spell spell ID
call SaveInteger(STASIndexer, GetHandleId(t), StringHash("NEXT"), ns)
// Add new spell to caster
call UnitAddAbility(cu, ns)
// Start the timer
call TimerStart(t, et, false, function STASTemporaryTimeHandler)
else
return
endif
// Avoid leaks
set cu = null
set t = null
endfunction
endlibrary