641e1289a9c590ee4830ca668cacf5a8eb57d703
[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     [287280] = {1, "buff1"}, -- Glimmer of Light
21     [194384] = {1, "buff1"}, -- Atonement
22     [61295] = {1, "buff1"}, -- Riptide
23     -- Tank defensives
24     [6940] = {1, "tankcd"}, -- Blessing of Sacrifice
25     [33206] = {1, "tankcd"}, -- Pain Suppression
26     [47788] = {1, "tankcd"}, -- Guardian Spirit
27     [102342] = {1, "tankcd"}, -- Ironbark
28     [116849] = {1, "tankcd"}, -- Life Cocoon
29     [196555] = {1, "tankcd"}, -- Netherwalk
30     -- M+
31     [209858] = {1, "stacks"}, -- Necrotic Wound (M+)
32     [240559] = {1, "stacks"}, -- Grievous Wound (M+)
33     [240443] = {1, "stacks"}, -- Burst (M+)
34     -- Uldir
35     [265264] = {2, "alert"}, -- Void Lash (Zek'voz)
36     -- Battle of Dazar'alor
37     [285213] = {1, "alert"}, -- Caress of Death (Rastakhan)
38     [288415] = {1, "alert"}, -- Caress of Death in Death realm (Rastakhan)
39     [285195] = {8, "stacks"}, -- Deathly Withering (Rastakhan)
40     [286646] = {1, "heal"}, -- Gigavolt Charge (Mekkatorque)
41     [287891] = {1, "stacks"}, -- Sheep Shrapnel (Mekkatorque)
42     [287993] = {1, "stacks"}, -- Chilling Touch (Jaina)
43     [283507] = {1, "heal"}, -- Volatile Charge (Opulence)
44     [287648] = {1, "heal"}, -- Volatile Charge (Opulence)
45     [284556] = {1, "stacks"}, -- Shadow-Touched (Opulence)
46     [287072] = {1, "heal"}, -- Liquid Gold (Opulence)
47     [284781] = {1, "heal"}, -- Grievous Axe (Rastakhan)
48     [290955] = {1, "heal"}, -- Grievous Axe (Rastakhan)
49     --[284663] = {1, "alert"}, -- Bwonsamdi's Wrath (Conclave)
50     -- Crucible of Storms
51     [282566] = {1, "stacks"}, -- Promises of Power (Restless Cabal)
52     [282738] = {1, "alert"}, -- Embrace of the Void (Restless Cabal)
53     [285652] = {1, "alert"}, -- Insatiable Torment (Uu'nat)
54     [285367] = {2, "stacks"}, -- Piercing Gaze of N'Zoth (Uu'nat)
55     [284733] = {1, "alert"}, -- Embrace of the Void (Uu'nat)
56     [285685] = {1, "alert"}, -- Gift of N'Zoth: Lunacy (Uu'nat)
57     -- The Eternal Palace
58     [292127] = {1, "alert"}, -- Darkest Depths (Underwater)
59     [298569] = {1, "stacks"}, -- Drained Soul (Queen Azshara)
60     [297586] = {1, "alert"}, -- Suffering (Queen's Court)
61     [294711] = {5, "heal"}, -- Frost (Sivara)
62     [294715] = {5, "heal"}, -- Toxic (Sivara)
63     [296693] = {1, "stacks"}, -- Waterlogged (Ashvane)
64     [297333] = {1, "heal"}, -- Briny Bubble (Ashvane)
65     [298306] = {1, "stacks"}, -- Incubation Fluid (Orgozoa)
66 };
67 local playerGuid = nil;
68
69 local auraEvents = {};
70 auraEvents.SPELL_AURA_APPLIED = function(frame, id, source, _, _, atype, amount)
71     if (amount == nil and watchedAuras[id][1] == 1) or (amount ~= nil and amount >= watchedAuras[id][1]) then
72         amount = amount or 1;
73         if atype == "BUFF" and source == playerGuid then
74             frame[watchedAuras[id][2]][id] = amount;
75         elseif atype == "DEBUFF" then
76             frame[watchedAuras[id][2]][id] = amount;
77         end
78     end
79 end
80 auraEvents.SPELL_AURA_APPLIED_DOSE = auraEvents.SPELL_AURA_APPLIED;
81 auraEvents.SPELL_AURA_REFRESH = auraEvents.SPELL_AURA_APPLIED;
82 auraEvents.SPELL_AURA_REMOVED = function(frame, id, source, _, _, atype, amount)
83     if amount == nil or amount == 0 then
84         if atype == "BUFF" and source == playerGuid then
85             frame[watchedAuras[id][2]][id] = nil;
86         elseif atype == "DEBUFF" then
87             frame[watchedAuras[id][2]][id] = nil;
88         end
89     end
90 end
91 auraEvents.SPELL_AURA_REMOVED_DOSE = auraEvents.SPELL_AURA_REMOVED;
92 auraEvents.SPELL_AURA_BROKEN = function(frame, id, source)
93     return auraEvents.SPELL_AURA_REMOVED(frame, id, source, nil, nil, nil, 0);
94 end
95 auraEvents.SPELL_AURA_BROKEN_SPELL = auraEvents.SPELL_AURA_BROKEN;
96
97 local counter = 0;
98 local function clog(ts, event, _, source, _, _, _, dest, _, _, _, spellid, ...)
99     if auraEvents[event] and watchedAuras[spellid] and guids[dest] then
100         auraEvents[event](guids[dest], spellid, source, ...);
101     end
102 end
103 addon.Events.Clog = clog;
104
105 local types = {["HELPFUL"] = "BUFF", ["HARMFUL"] = "DEBUFF"};
106 local function setAuras(unit, guid)
107     local name;
108     local spellid, count, source;
109     for filter, atype in pairs(types) do
110         local i = 1;
111         while true do
112             name, _, count, _, _, _, source, _, _, spellid = UnitAura(unit, i, filter);
113             if not spellid then break end
114             if count == 0 then count = nil end
115             if source ~= nil then
116                 clog(0, "SPELL_AURA_APPLIED", nil, UnitGUID(source), nil, nil, nil,
117                      guid, nil, nil, nil, spellid, nil, nil, atype, count);
118             elseif filter == "HARMFUL" then
119                 clog(0, "SPELL_AURA_APPLIED", nil, nil, nil, nil, nil,
120                      guid, nil, nil, nil, spellid, nil, nil, atype, count);
121             end
122             i = i + 1;
123         end
124     end
125 end
126 addon.SetAuras = setAuras;
127
128 local frame = CreateFrame("Frame");
129 frame:Hide();
130 frame:SetScript("OnEvent", function()
131     playerGuid = UnitGUID("player");
132     frame:UnregisterAllEvents();
133     frame:SetScript("OnEvent", function()
134         return clog(CombatLogGetCurrentEventInfo());
135     end);
136     frame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED");
137 end);
138 frame:RegisterEvent("PLAYER_LOGIN");