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:
-- Top of your file:
local gcdSpells = {}
local gcdMasterSpell
lua Code:
-- In response to SPELLS_CHANGED event:
wipe(gcdSpells)
local _, _, offset, numSpells = GetSpellTabInfo(2)
for i = 1, offset + numSpells do
local slotType, slotID = GetSpellBookItemInfo(i, "spell")
if slotType == "SPELL" then
local slotName = GetSpellBookItemName(i, "spell")
local spellName, _, _, _, _, _, spellID = GetSpellInfo(slotName)
local spellCD = GetSpellBaseCooldown(spellID or 0) -- spellID can be nil during loading
if spellCD == 0 then
gcdSpells[spellID] = true
end
end
end
gcdMasterSpell = next(gcdSpells)
lua Code:
-- To get the real GCD at any given time:
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:
local gcdSpell
local _, _, offset, numSpells = GetSpellTabInfo(2)
for i = 1, offset + numSpells do
local slotType, slotID = GetSpellBookItemInfo(i, "spell")
if slotType == "SPELL" then
local slotName = GetSpellBookItemName(i, "spell")
local spellName, _, _, _, _, _, spellID = GetSpellInfo(slotName)
local spellCD = GetSpellBaseCooldown(spellID or 0) -- spellID can be nil during loading
if spellCD == 0 then
gcdSpell = spellID
break
end
end
end
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.