d8ca67c5ea40b3dd4cdc487080ab9f33614315dd
[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     [288939] = {1, "heal"}, -- Gigavolt Radiation (Mekkatorque)
42     [287891] = {1, "stacks"}, -- Sheep Shrapnel (Mekkatorque)
43     [287993] = {1, "stacks"}, -- Chilling Touch (Jaina)
44     [283507] = {1, "heal"}, -- Volatile Charge (Opulence)
45     [287648] = {1, "heal"}, -- Volatile Charge (Opulence)
46     [284556] = {1, "stacks"}, -- Shadow-Touched (Opulence)
47     [287072] = {1, "heal"}, -- Liquid Gold (Opulence)
48     [284781] = {1, "heal"}, -- Grievous Axe (Rastakhan)
49     [290955] = {1, "heal"}, -- Grievous Axe (Rastakhan)
50     --[284663] = {1, "alert"}, -- Bwonsamdi's Wrath (Conclave)
51     -- Crucible of Storms
52     [282566] = {1, "stacks"}, -- Promises of Power (Restless Cabal)
53     [282738] = {1, "alert"}, -- Embrace of the Void (Restless Cabal)
54     [285652] = {1, "alert"}, -- Insatiable Torment (Uu'nat)
55     [285367] = {2, "stacks"}, -- Piercing Gaze of N'Zoth (Uu'nat)
56     [284733] = {1, "alert"}, -- Embrace of the Void (Uu'nat)
57     [285685] = {1, "alert"}, -- Gift of N'Zoth: Lunacy (Uu'nat)
58     -- The Eternal Palace
59     [292127] = {1, "alert"}, -- Darkest Depths (Underwater)
60     [298569] = {1, "stacks"}, -- Drained Soul (Queen Azshara)
61     [297586] = {1, "alert"}, -- Suffering (Queen's Court)
62     [294711] = {5, "heal"}, -- Frost (Sivara)
63     [294715] = {5, "heal"}, -- Toxic (Sivara)
64     [296693] = {1, "stacks"}, -- Waterlogged (Ashvane)
65     [297333] = {1, "heal"}, -- Briny Bubble (Ashvane)
66     [298306] = {1, "stacks"}, -- Incubation Fluid (Orgozoa)
67 };
68 local playerGuid = nil;
69
70 local auraEvents = {};
71 auraEvents.SPELL_AURA_APPLIED = function(frame, id, source, _, _, atype, amount)
72     if (amount == nil and watchedAuras[id][1] == 1) or (amount ~= nil and amount >= watchedAuras[id][1]) then
73         amount = amount or 1;
74         if atype == "BUFF" and source == playerGuid then
75             frame[watchedAuras[id][2]][id] = amount;
76         elseif atype == "DEBUFF" then
77             frame[watchedAuras[id][2]][id] = amount;
78         end
79     end
80 end
81 auraEvents.SPELL_AURA_APPLIED_DOSE = auraEvents.SPELL_AURA_APPLIED;
82 auraEvents.SPELL_AURA_REFRESH = auraEvents.SPELL_AURA_APPLIED;
83 auraEvents.SPELL_AURA_REMOVED = function(frame, id, source, _, _, atype, amount)
84     if amount == nil or amount == 0 then
85         if atype == "BUFF" and source == playerGuid then
86             frame[watchedAuras[id][2]][id] = nil;
87         elseif atype == "DEBUFF" then
88             frame[watchedAuras[id][2]][id] = nil;
89         end
90     end
91 end
92 auraEvents.SPELL_AURA_REMOVED_DOSE = auraEvents.SPELL_AURA_REMOVED;
93 auraEvents.SPELL_AURA_BROKEN = function(frame, id, source)
94     return auraEvents.SPELL_AURA_REMOVED(frame, id, source, nil, nil, nil, 0);
95 end
96 auraEvents.SPELL_AURA_BROKEN_SPELL = auraEvents.SPELL_AURA_BROKEN;
97
98 local counter = 0;
99 local function clog(ts, event, _, source, _, _, _, dest, _, _, _, spellid, ...)
100     if auraEvents[event] and watchedAuras[spellid] and guids[dest] then
101         auraEvents[event](guids[dest], spellid, source, ...);
102     end
103 end
104 addon.Events.Clog = clog;
105
106 local types = {["HELPFUL"] = "BUFF", ["HARMFUL"] = "DEBUFF"};
107 local function setAuras(unit, guid)
108     local name;
109     local spellid, count, source;
110     for filter, atype in pairs(types) do
111         local i = 1;
112         while true do
113             name, _, count, _, _, _, source, _, _, spellid = UnitAura(unit, i, filter);
114             if not spellid then break end
115             if count == 0 then count = nil end
116             if source ~= nil then
117                 clog(0, "SPELL_AURA_APPLIED", nil, UnitGUID(source), nil, nil, nil,
118                      guid, nil, nil, nil, spellid, nil, nil, atype, count);
119             elseif filter == "HARMFUL" then
120                 clog(0, "SPELL_AURA_APPLIED", nil, nil, nil, nil, nil,
121                      guid, nil, nil, nil, spellid, nil, nil, atype, count);
122             end
123             i = i + 1;
124         end
125     end
126 end
127 addon.SetAuras = setAuras;
128
129 local frame = CreateFrame("Frame");
130 frame:Hide();
131 frame:SetScript("OnEvent", function()
132     playerGuid = UnitGUID("player");
133     frame:UnregisterAllEvents();
134     frame:SetScript("OnEvent", function()
135         return clog(CombatLogGetCurrentEventInfo());
136     end);
137     frame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED");
138 end);
139 frame:RegisterEvent("PLAYER_LOGIN");