Thread Tools Display Modes
10-15-15, 11:21 PM   #1
Nikita S. Doroshenko
A Cyclonian
 
Nikita S. Doroshenko's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2015
Posts: 45
Can we get Global Cooldown time info for our spells/abilitys/itmes?

I would like to enhance spells, abilitys and itmes tooltips with information about their Global Cooldown (GC), and get GC time (if i'm right GC depends of haste and for monks GC time cut, so it's not static value).
And then I would like to add GC countdown timer near Player Portrait and if possible even on Enemy Player Target Portrait (but that part could be tricky and not accurate because of ping and unknown haste).

Accordion to this article's comments: http://www.wowhead.com/spell=61304/global-cooldown we can get GC info right after we use an ability, with this code for example:
Lua Code:
  1. /use Ice Barrier
  2. /run local _,gc = GetSpellCooldown(61304); print(gc)
Sure i can make table:
Lua Code:
  1. spellsWithGC = {72183 = {affectedByHaste = true}, 12831 = {affectedByHaste = true}, 90128, 89218}
  2. itemsWithGC = {82993, 29101}
And update this tables each time used uses new ability, but i think it's an ineffective way to do this, and we have to recheck this tables each time Blizzard updates their game, so we get actual updated info.

As well, there are some debuffs that makes your GC time, very long, and i would like to dynamically update tooltips as well.

Could you please give my your thoughts, and advises how I can make it most effective, stable and optimized, and how can i build such a table (how can I run GetSpellCooldown(index) right after spell/ability/item cast with correct index and add it's data to my table)?

Last edited by Nikita S. Doroshenko : 10-16-15 at 12:13 AM.
  Reply With Quote
10-18-15, 11:30 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Well, assuming you only care about your own spells, then rather than hand-maintaining a list of spells that are on the GCD, you can just scan the spellbook for spells with a cooldown, and assume everything else is on the GCD:

lua Code:
  1. -- Top of your file:
  2. local gcdSpells = {}
  3. local gcdMasterSpell

lua Code:
  1. -- In response to SPELLS_CHANGED event:
  2. wipe(gcdSpells)
  3. local _, _, offset, numSpells = GetSpellTabInfo(2)
  4. for i = 1, offset + numSpells do
  5.      local slotType, slotID = GetSpellBookItemInfo(i, "spell")
  6.      if slotType == "SPELL" then
  7.           local slotName = GetSpellBookItemName(i, "spell")
  8.           local spellName, _, _, _, _, _, spellID = GetSpellInfo(slotName)
  9.           local spellCD = GetSpellBaseCooldown(spellID or 0) -- spellID can be nil during loading
  10.           if spellCD == 0 then
  11.                gcdSpells[spellID] = true
  12.           end
  13.      end
  14. end
  15. gcdMasterSpell = next(gcdSpells)

lua Code:
  1. -- To get the real GCD at any given time:
  2. local start, duration = GetSpellCooldown(gcdMasterSpell)

Note that the ID and name from the GetSpellBookItem* functions may not be the real ID and/or name of the spell, in cases where the spell changes based on spec, talents, or other conditions. Doing a reverse lookup on the provided name with GetSpellInfo will get you correct information at any given time.

Then to get the actual GCD time, you only need to look at the current cooldown of one spell; it doesn't matter which one, so the above code just picks one basically at random.

If you only need to know the GCD at any given moment, and don't need a list of spells, it's even easier:

lua Code:
  1. local gcdSpell
  2.  
  3. local _, _, offset, numSpells = GetSpellTabInfo(2)
  4. for i = 1, offset + numSpells do
  5.      local slotType, slotID = GetSpellBookItemInfo(i, "spell")
  6.      if slotType == "SPELL" then
  7.           local slotName = GetSpellBookItemName(i, "spell")
  8.           local spellName, _, _, _, _, _, spellID = GetSpellInfo(slotName)
  9.           local spellCD = GetSpellBaseCooldown(spellID or 0) -- spellID can be nil during loading
  10.           if spellCD == 0 then
  11.                gcdSpell = spellID
  12.                break
  13.           end
  14.      end
  15. end
  16.  
  17. local start, duration = GetSpellCooldown(gcdSpell)

Items are slightly trickier, but as long as you know the GCD you can just compare the cooldown of the item to find out if the item is on the GCD or has its own cooldown. You could alternatively use tooltip parsing but that may not always be accurate.

Trying to guess the GCD of enemy players is probably a lost cause.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Can we get Global Cooldown time info for our spells/abilitys/itmes?

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off