0b3d41a - Allow frame creation without clickheal
[wowui.git] / kehys / auras.lua
1 -- auras.lua
2 -- 2019 Aleksi Blinnikka
3 local _, addon = ...;
4 local CombatLogGetCurrentEventInfo = CombatLogGetCurrentEventInfo;
5
6 local guids = addon.FrameGuids;
7 local watchedAuras = {
8     --[286988] = duration, -- Searing Embers
9     --[257908] = {bar=false}, -- Oiled Blade
10     --[268391] = {bar=false}, -- Mental Assault
11     --[272571] = {bar=false}, -- Choking Waters
12     --[268008] = {bar=false}, -- Snake Charm
13     --[260741] = {bar=false}, -- Jagged Nettles
14     --[280605] = {bar=false}, -- Brain Freeze
15     --[268797] = {bar=false}, -- Transmute to Goo
16     --[265889] = {bar=false}, -- Torch Strike
17     --[266209] = {bar=false}, -- Wicked Frenzy
18     --[258323] = {bar=false}, -- Infected Wound
19     --[262513] = {bar=false}, -- Azerite Heartseeker
20     -- Uldir
21     [265264] = {2, "alert"}, -- Void Lash (Zek'voz)
22     -- Battle of Dazar'alor
23     [285213] = {1, "alert"}, -- Caress of Death (Rastakhan)
24     [285195] = {12, "heal"}, -- Deathly Withering (Rastakhan)
25 };
26
27 local auraEvents = {};
28 auraEvents.SPELL_AURA_APPLIED = function(frame, id, _, _, _, amount)
29     if (amount == nil and watchedAuras[id][1] == 1) or (amount ~= nil and amount >= watchedAuras[id][1]) then
30         if watchedAuras[id][2] == "alert" then
31             frame.alert[id] = true;
32         else
33             frame.heal[id] = true;
34         end
35     end
36 end
37 auraEvents.SPELL_AURA_APPLIED_DOSE = auraEvents.SPELL_AURA_APPLIED;
38 auraEvents.SPELL_AURA_REFRESH = auraEvents.SPELL_AURA_APPLIED;
39 auraEvents.SPELL_AURA_REMOVED = function(frame, id, _, _, _, amount)
40     if amount == nil or amount == 0 then
41         if watchedAuras[id][2] == "alert" then
42             frame.alert[id] = nil;
43         else
44             frame.heal[id] = nil;
45         end
46     end
47 end
48 auraEvents.SPELL_AURA_REMOVED_DOSE = auraEvents.SPELL_AURA_REMOVED;
49 auraEvents.SPELL_AURA_BROKEN = function(frame, id)
50     return auraEvents.SPELL_AURA_REMOVED(frame, id, nil, nil, nil, 0);
51 end
52 auraEvents.SPELL_AURA_BROKEN_SPELL = auraEvents.SPELL_AURA_BROKEN;
53
54 local counter = 0;
55 local function clog(ts, event, _, _, _, _, _, dest, _, flags, _, spellid, ...)
56     if auraEvents[event] and watchedAuras[spellid] and guids[dest] then
57         auraEvents[event](guids[dest], spellid, ...);
58     end
59 end
60 addon.Events.Clog = clog;
61
62 local frame = CreateFrame("Frame");
63 frame:Hide();
64 frame:SetScript("OnEvent", function()
65     frame:UnregisterAllEvents();
66     frame:SetScript("OnEvent", function()
67         return clog(CombatLogGetCurrentEventInfo());
68     end);
69     frame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED");
70 end);
71 frame:RegisterEvent("PLAYER_LOGIN");