library AdvancedAbilityAnimations initializer Init
// Created by Uncle
globals
private constant boolean DOES_USE_CAST_BACKSWING = true
// Define the above DOES_USE_CAST_BACKSWING boolean.
// If any unit has an Art - Cast Backswing > 0.00 then
// keep this set to true. Otherwise, set it to false to
// make the system slightly more efficient.
// Do not modify anything else below this line
private hashtable hash = InitHashtable()
private unit caster
private integer abilityId
private integer timerHandle
private timer abilityTimer
// References to your AAA_ variables
private integer castAnim // animation index
private real castDuration // animation standard duration
private real castTime // animation desired duration
// KEYS in the Hashtable
private constant integer KEY_UNIT = 0
private constant integer KEY_ABIL = 1
private constant integer KEY_ANIM = 0
private constant integer KEY_DURATION = 1
private constant integer KEY_TIME = 2
private constant integer KEY_ANIM_ALT = 3
private constant integer KEY_DURATION_ALT = 4
private constant integer KEY_TIME_ALT = 5
endglobals
private function StopCasting takes nothing returns nothing
set abilityId = GetSpellAbilityId()
set castTime = LoadReal(hash, abilityId, KEY_TIME)
if castTime == 0.0 then
return
endif
set caster = GetTriggerUnit()
call SetUnitTimeScale(caster, 1.0)
// Seems unnecessary, commented out for now
//call ResetUnitAnimation(caster)
set abilityTimer = LoadTimerHandle(hash, GetHandleId(caster), 0)
if abilityTimer != null then
call FlushChildHashtable(hash, GetHandleId(abilityTimer))
call FlushChildHashtable(hash, GetHandleId(caster))
call DestroyTimer(abilityTimer)
endif
endfunction
private function BeginCastingCallback takes nothing returns nothing
set abilityTimer = GetExpiredTimer()
set timerHandle = GetHandleId(abilityTimer)
set caster = LoadUnitHandle(hash, timerHandle, KEY_UNIT)
if IsUnitType(caster, UNIT_TYPE_DEAD) or GetUnitTypeId(caster) == 0 then
return
endif
set abilityId = LoadInteger(hash, timerHandle, KEY_ABIL)
// Variables used to play the special cast animation
if GetUnitAbilityLevel(caster, udg_AAA__Alt_Ability) > 0 then
// It has the alternate animation tag
set castAnim = LoadInteger(hash, abilityId, KEY_ANIM_ALT)
set castDuration = LoadReal(hash, abilityId, KEY_DURATION_ALT)
set castTime = LoadReal(hash, abilityId, KEY_TIME_ALT)
else
// It does not have an alternate animation tag
set castAnim = LoadInteger(hash, abilityId, KEY_ANIM)
set castDuration = LoadReal(hash, abilityId, KEY_DURATION)
set castTime = LoadReal(hash, abilityId, KEY_TIME)
endif
call SetUnitAnimationByIndex(caster, castAnim)
call SetUnitTimeScale(caster, castDuration / castTime)
call FlushChildHashtable(hash, timerHandle)
call FlushChildHashtable(hash, GetHandleId(caster))
call DestroyTimer(abilityTimer)
endfunction
private function BeginCasting takes nothing returns nothing
set abilityId = GetSpellAbilityId()
set castTime = LoadReal(hash, abilityId, KEY_TIME)
if castTime == 0.0 then
return
endif
set caster = GetTriggerUnit()
set abilityTimer = CreateTimer()
set timerHandle = GetHandleId(abilityTimer)
call SaveUnitHandle(hash, timerHandle, KEY_UNIT, caster)
call SaveInteger(hash, timerHandle, KEY_ABIL, abilityId)
call SaveTimerHandle(hash, GetHandleId(caster), 0, abilityTimer)
call TimerStart(abilityTimer, 0, false, function BeginCastingCallback)
endfunction
// Call this after setting up the AAA_ variables
function AAA_Register_Ability takes nothing returns nothing
local integer id = udg_AAA__Abil_Type
if udg_AAA__Anim_Duration <= 0 or udg_AAA__Cast_Time <= 0 then
call DisplayTextToPlayer(Player(0), 0, 0, "[AAA Error] Ability " + GetAbilityName(id) + " was not registered! Anim Duration and Cast Time must be > 0.")
return
endif
call SaveInteger(hash, id, KEY_ANIM, udg_AAA__Anim_Index)
call SaveReal(hash, id, KEY_DURATION, udg_AAA__Anim_Duration)
call SaveReal(hash, id, KEY_TIME, udg_AAA__Cast_Time)
// A value of -1 represents unused
if udg_AAA__Anim_Index_Alt > -1 then
call SaveInteger(hash, id, KEY_ANIM_ALT, udg_AAA__Anim_Index_Alt)
call SaveReal(hash, id, KEY_DURATION_ALT, udg_AAA__Anim_Duration_Alt)
call SaveReal(hash, id, KEY_TIME_ALT, udg_AAA__Cast_Time_Alt)
endif
set udg_AAA__Anim_Index_Alt = -1
endfunction
private function Init takes nothing returns nothing
local trigger t1 = CreateTrigger()
local trigger t2 = CreateTrigger()
// Define the ability used to determine alternate animations
set udg_AAA__Alt_Ability = 'AAAT'
// A value of -1 represents unused
set udg_AAA__Anim_Index_Alt = -1
call TriggerRegisterAnyUnitEventBJ( t1, EVENT_PLAYER_UNIT_SPELL_CHANNEL )
call TriggerRegisterAnyUnitEventBJ( t2, EVENT_PLAYER_UNIT_SPELL_ENDCAST )
// Art - Cast Backswing may need to be accounted for (if > 0.00)
if DOES_USE_CAST_BACKSWING then
call TriggerRegisterAnyUnitEventBJ( t2, EVENT_PLAYER_UNIT_SPELL_EFFECT )
endif
call TriggerAddAction( t1, function BeginCasting )
call TriggerAddAction( t2, function StopCasting )
set t1 = null
set t2 = null
endfunction
endlibrary