View Single Post
06-07-18, 11:29 PM   #5
aallkkaa
A Warpwood Thunder Caller
 
aallkkaa's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2017
Posts: 98
On ReadySpells, which I'm working on to release an up to date version (and taking way much longer than I'd initially thought ), I came up with this:
Lua Code:
  1. -- One-time GCD getter; to be called only by getGCD() bellow
  2. local gcd = 0;  -- gcd == 0 means the GCD is not currently running
  3. local getGCDonce = function()
  4.     -- SpellID:61304 -> (Dummy)SpellName:"Global Cooldown"
  5.     local _, duration = GetSpellCooldown(61304);
  6.     gcd = duration or 0; -- in seconds, with three decimal places
  7.     -- print(AddonName.. ": GCD = ".. gcd);
  8. end
  9. -- This function will be called upon UNIT_SPELLCAST_SENT, which fires at the  start of onGCD-
  10. --  instant-cast, onGCD-overtime-cast, offGCD-cast and channeled spells.
  11. local getGCD = function()
  12.     getGCDonce();
  13.     -- We also need to update the value of the GCD when the spell has finished casting. It should
  14.     -- then be 0(ZERO), but I think it's plausible that, if a new spell had been queued by the game
  15.     -- client (within less than the set lag's time), UNIT_SPELLCAST_SENT may fire before our timer
  16.     -- elapses. Thus, instead of just doing 'gcd = 0', we'll again fetch the value from the server.
  17.     if gcd > 0 then
  18.         C_Timer.After(gcd, getGCDonce);
  19.         -- TODO: Implement routine to fetch latency and set the timer above to be "gcd - latency".
  20.         --  On second thought, this may just return that the GCD hasn't expired yet (?). INSTEAD,
  21.         --  make the function(s) that use this variable account for the latency, leaving the 'gcd'
  22.         --  var itself untouched !
  23.     end
  24. end
Pretty much all my thoughts on this subject are in that snippet. Just adding that, on ReadySpells, the "gcd" variable is used to grey out the next ready spell while the GCD is runnin, so the above (assuming the "TODO" implemented) is good enough.

I don't think there's a practical way to achieve what you want. You could cache the results of each spell the first time they're cast, but you'd need to cast each at least once.
And then there's all the game mechanics, like e.g. casting a spell while under Heroism/Bloodlust would obviously change the return value of GetSpellCooldown(61304). So... you'd basically have to take into account all the possible factors that might change the GCD every time you did your calculation (for example, last GCD-fetch Heroism was on, now it's not, you'd add 0.3 seconds to your last GCD). And, honestly, to do that, then you'd be better off following myrroddin's suggestion and adding in the other factors... Which still seems like a very bad idea to me (factoring in everythin on top of the calculation myrroddin's calculation).

IMHO either do as myrroddin suggested or as you're already doing it. Doesn't look to me that you can feasibly improve on those options. Unless BfA brings some important change to this (of which I'm not aware, nor have I done any testing).
  Reply With Quote