- Joined
- Apr 24, 2012
- Messages
- 5,113
I have been searching for this resource and I guess noone ever made this kind of system.
Today, I created a Custom Cooldown System which, of course, applies custom cooldown to your ability.
Ability applied with custom cooldown will be disabled for n seconds and will be replaced by a passive ability that serves as an indicator that the spell is on cooldown.
Here is the code:
and some test:
I haven't tested the system yet with Channeling spells and Autocasts(I assume that autocasts are not supported)
I would like some feedbacks and suggestions about how can I improve this system.
Thank you
Today, I created a Custom Cooldown System which, of course, applies custom cooldown to your ability.
Ability applied with custom cooldown will be disabled for n seconds and will be replaced by a passive ability that serves as an indicator that the spell is on cooldown.
Here is the code:
JASS:
library Cooldown
globals
private constant real TIMEOUT = 0.031250000
private integer array CD_IDS
endglobals
private module Initializer
private static method onInit takes nothing returns nothing
call init()
endmethod
endmodule
struct Cooldown extends array
private static integer array r
private static integer ic = 0
private real cooldown
private integer source_abil
private integer cd_abil
private player owner
private unit u
private thistype n
private thistype p
private static integer c = 0
private static constant timer t = CreateTimer()
private static method allocate takes nothing returns thistype
local thistype this = r[0]
if this == 0 then
set ic = ic + 1
return ic
endif
set r[0] = r[this]
return this
endmethod
private method deallocate takes nothing returns nothing
set r[this] = r[0]
set r[0] = this
endmethod
private static method periodic takes nothing returns nothing
local thistype this = thistype(0).n
loop
exitwhen this == 0
if cooldown >= TIMEOUT then
set cooldown = cooldown - TIMEOUT
else
call UnitRemoveAbility(u, cd_abil)
call SetPlayerAbilityAvailable(owner, source_abil, true)
set cooldown = 0
set u = null
set owner = null
set source_abil = 0
set cd_abil = 0
set p.n = n
set n.p = p
call deallocate()
set c = c -1
if c == 0 then
call PauseTimer(t)
endif
endif
set this = n
endloop
endmethod
static method startEx takes player tempp, unit tempu, integer src_abil, real cd, integer cd_ability returns thistype
local thistype this = allocate()
call SetPlayerAbilityAvailable(tempp, src_abil, false)
call UnitAddAbility(tempu, cd_ability)
set owner = tempp
set u = tempu
set source_abil = src_abil
set cooldown = cd
set cd_abil = cd_ability
set n = 0
set p = thistype(0).n
set p.n = this
set thistype(0).p = this
set c = c + 1
if c == 1 then
call TimerStart(t, TIMEOUT, true, function thistype.periodic)
endif
return this
endmethod
static method start takes player tempp, unit tempu, integer src_abil, real cd, integer x, integer y returns thistype
return startEx(tempp, tempu, src_abil, cd, CD_IDS[x*3 + y])
endmethod
method operator value= takes real cd returns nothing
set cooldown = cd
endmethod
method operator value takes nothing returns real
return cooldown
endmethod
private static method init takes nothing returns nothing
set CD_IDS[0] = 'cd00'
set CD_IDS[1] = 'cd01'
set CD_IDS[2] = 'cd02'
set CD_IDS[3] = 'cd10'
set CD_IDS[4] = 'cd11'
set CD_IDS[5] = 'cd12'
set CD_IDS[6] = 'cd20'
set CD_IDS[7] = 'cd21'
set CD_IDS[8] = 'cd22'
set CD_IDS[9] = 'cd30'
set CD_IDS[10] = 'cd31'
set CD_IDS[11] = 'cd32'
endmethod
implement Initializer
endstruct
endlibrary
and some test:
|
I haven't tested the system yet with Channeling spells and Autocasts(I assume that autocasts are not supported)
I would like some feedbacks and suggestions about how can I improve this system.
Thank you