I'm making an addon that shows procs and the time left on them on my screen, everything is mostly done except the timers. Since there will be multiple timers running at the same time I'm wondering how to best handle this. (and please don't point me to a lib :rolleyes:)
Here's what I had in mind (warning pseudo code)
function frame:COMBAT_LOG_UNFILTERED(event, timestamp, eventType, etc etc)
if eventType == "SPELL_AURA_APPLIED" then
local spell = ...
if spell == "buff1" then
elseif spell == "buff2" then
etc etc buff3, buff4
if UnitBuff("player", "buff1") then
buff1:set fontstring accordingly
if UnitBuff("player", "buff2") then
do the same stuff
Out of curiosity, why don't you want to use a library? AceTimer-3.0 is specifically designed for this kind of thing, and is totally standalone (unlike Ace2 where you had to use about 5 libs to get any one feature). If you're using bars, LibCandyBar-3.0 is also very lightweight.
Anyway, if you want to do it yourself, a much better solution would be to insert timers into a table as they're started (eg. when the buff is applied), and then iterate over the table in your OnUpdate. That way, you're not wasting time checking for a bunch of stuff that isn't active.
Also, you shouldn't check the duration of a buff in every OnUpdate. Instead, when the buff is applied, cache its expiration time, and then just check that against GetTime() in OnUpdate to find the remaining duration.
Rather than writing some bad pseudocode, I'll just point you at Haste's addon oCD. It does pretty much exactly what you're looking to do (though it handles spell/item cooldowns, not buff durations), and doesn't use any libraries.
BTW, do not use COMBATLOG_EVENT_UNFILTERED (CLEU) to detect auras, use UNIT_AURA instead :
- CLEU is fired for lots of thing that are not related to buffs,
- CLEU is often fired before UnitBuff data are up to date,
- CLEU provides a name and GUID but no unit identifier (like "player", "raid1" or "target") that is required for UnitBuff.
Ok this gave me some ideas, I changed most of my buff detection to UNIT_AURA but some skills still need to be found through CLEU. For example when I kill something that yields experience or honor certain skills are available, in my case Victory Rush (for warriors).
To catch this event i'm using PARTY_KILL and it seems to work except that it triggers on any type of "killing blow". So how do I detect if the unit I just killed yields honor or experience?
I tried checking if the skill was usable with IsUsableSpell() but it always returned false because (I'm guessing) the information wasn't available exactly after the kill.