f86034a82577fd63d8ab8fd196ff4659e9605dad
[wowui.git] / kehys / auras.lua
1 -- auras.lua
2 -- 2019 Aleksi Blinnikka
3 local _, addon = ...;
4 local CombatLogGetCurrentEventInfo = CombatLogGetCurrentEventInfo;
5 local UnitAura = UnitAura;
6 local UnitGUID = UnitGUID;
7
8 local guids = addon.FrameGuids;
9 local watchedAuras = {
10     --[286988] = duration, -- Searing Embers
11     --[257908] = {bar=false}, -- Oiled Blade
12     --[268391] = {bar=false}, -- Mental Assault
13     --[272571] = {bar=false}, -- Choking Waters
14     --[268008] = {bar=false}, -- Snake Charm
15     --[280605] = {bar=false}, -- Brain Freeze
16     --[268797] = {bar=false}, -- Transmute to Goo
17     --[265889] = {bar=false}, -- Torch Strike
18     --[266209] = {bar=false}, -- Wicked Frenzy
19     --[258323] = {bar=false}, -- Infected Wound
20     --[262513] = {bar=false}, -- Azerite Heartseeker
21     [287280] = {1, "buff1"}, -- Glimmer of Light
22     [194384] = {1, "buff1"}, -- Atonement
23     [61295] = {1, "buff1"}, -- Riptide
24     [53563] = {1, "buff2"}, -- Beacon of Light
25     [156910] = {1, "buff2"}, -- Beacon of Faith
26     [200025] = {1, "buff2"}, -- Beacon of Virtue
27     -- Tank defensives
28     [6940] = {1, "tankcd"}, -- Blessing of Sacrifice
29     [33206] = {1, "tankcd"}, -- Pain Suppression
30     [47788] = {1, "tankcd"}, -- Guardian Spirit
31     [102342] = {1, "tankcd"}, -- Ironbark
32     [116849] = {1, "tankcd"}, -- Life Cocoon
33     [196555] = {1, "tankcd"}, -- Netherwalk
34     -- M+
35     [209858] = {1, "stacks"}, -- Necrotic Wound (M+)
36     [240559] = {1, "stacks"}, -- Grievous Wound (M+)
37     [240443] = {1, "stacks"}, -- Burst (M+)
38     [260741] = {1, "heal"}, -- Jagged Nettles (Waycrest Manor)
39     -- Uldir
40     [265264] = {2, "alert"}, -- Void Lash (Zek'voz)
41     -- Battle of Dazar'alor
42     [285213] = {1, "alert"}, -- Caress of Death (Rastakhan)
43     [288415] = {1, "alert"}, -- Caress of Death in Death realm (Rastakhan)
44     [285195] = {8, "stacks"}, -- Deathly Withering (Rastakhan)
45     [286646] = {1, "heal"}, -- Gigavolt Charge (Mekkatorque)
46     [288939] = {1, "heal"}, -- Gigavolt Radiation (Mekkatorque)
47     [287891] = {1, "stacks"}, -- Sheep Shrapnel (Mekkatorque)
48     [287114] = {1, "alert"}, -- Miscalculated Teleport (Mekkatorque)
49     [287167] = {1, "stacks"}, -- Discombobulation (Mekkatorque)
50     [287993] = {1, "stacks"}, -- Chilling Touch (Jaina)
51     [283507] = {1, "heal"}, -- Volatile Charge (Opulence)
52     [287648] = {1, "heal"}, -- Volatile Charge (Opulence)
53     [284556] = {1, "stacks"}, -- Shadow-Touched (Opulence)
54     [287072] = {1, "heal"}, -- Liquid Gold (Opulence)
55     [284781] = {1, "heal"}, -- Grievous Axe (Rastakhan)
56     [290955] = {1, "heal"}, -- Grievous Axe (Rastakhan)
57     -- Crucible of Storms
58     [282566] = {1, "stacks"}, -- Promises of Power (Restless Cabal)
59     [282738] = {1, "alert"}, -- Embrace of the Void (Restless Cabal)
60     [285652] = {1, "alert"}, -- Insatiable Torment (Uu'nat)
61     [285367] = {2, "stacks"}, -- Piercing Gaze of N'Zoth (Uu'nat)
62     [284733] = {1, "alert"}, -- Embrace of the Void (Uu'nat)
63     [285685] = {1, "alert"}, -- Gift of N'Zoth: Lunacy (Uu'nat)
64     -- The Eternal Palace
65     [292127] = {1, "alert"}, -- Darkest Depths (Underwater)
66     [298569] = {1, "stacks"}, -- Drained Soul (Queen Azshara)
67     [297586] = {1, "alert"}, -- Suffering (Queen's Court)
68     [294711] = {5, "heal"}, -- Frost (Sivara)
69     [294715] = {5, "heal"}, -- Toxic (Sivara)
70     [296693] = {1, "stacks"}, -- Waterlogged (Ashvane)
71     [297333] = {1, "heal"}, -- Briny Bubble (Ashvane)
72     [298306] = {1, "stacks"}, -- Incubation Fluid (Orgozoa)
73     -- Ny'alotha
74     [313255] = {20, "stacks"}, -- Creeping Madness (Wrathion)
75     [310224] = {1, "stacks"}, -- Annihilation (Vexiona)
76     [307358] = {1, "heal"}, -- Debilitating Spit (Shad'har)
77     [318078] = {1, "alert"}, -- Fixate (Shad'har)
78     [312486] = {1, "stacks"}, -- Recurring Nightmare (Il'gynoth)
79     [313400] = {1, "stacks"}, -- Corrupted Mind (N'zoth)
80     [319346] = {1, "heal"}, -- Infinity's Toll (N'zoth) phase marker
81     [316506] = {1, "alert"}, -- Heartpiercer Venom (Trash)
82     [315025] = {1, "heal"}, -- Ancient Curse (Maut)
83     [315311] = {1, "stacks"}, -- Ravage (Hivemind)
84     [313460] = {1, "alert"}, -- Nullification (Hivemind)
85     [313461] = {1, "heal"}, -- Corrosion (Hivemind)
86     [307359] = {1, "heal"}, -- Despair (Vexiona)
87     [313077] = {1, "heal"}, -- Unleashed Nightmare (Ra-den)
88     [316065] = {1, "alert"}, -- Corrupted Existence (Ra-den)
89     [313364] = {1, "heal"}, -- Mental Decay (Carapace of N'zoth)
90 };
91 local playerGuid = nil;
92
93 local auraEvents = {};
94 auraEvents.SPELL_AURA_APPLIED = function(frame, id, source, _, _, atype, amount)
95     if (amount == nil and watchedAuras[id][1] == 1) or (amount ~= nil and amount >= watchedAuras[id][1]) then
96         amount = amount or 1;
97         if atype == "BUFF" and source == playerGuid then
98             frame[watchedAuras[id][2]][id] = amount;
99         elseif atype == "DEBUFF" then
100             frame[watchedAuras[id][2]][id] = amount;
101         end
102     end
103 end
104 auraEvents.SPELL_AURA_APPLIED_DOSE = auraEvents.SPELL_AURA_APPLIED;
105 auraEvents.SPELL_AURA_REFRESH = auraEvents.SPELL_AURA_APPLIED;
106 auraEvents.SPELL_AURA_REMOVED = function(frame, id, source, _, _, atype, amount)
107     if amount == nil or amount == 0 then
108         if atype == "BUFF" and source == playerGuid then
109             frame[watchedAuras[id][2]][id] = nil;
110         elseif atype == "DEBUFF" then
111             frame[watchedAuras[id][2]][id] = nil;
112         end
113     end
114 end
115 auraEvents.SPELL_AURA_REMOVED_DOSE = auraEvents.SPELL_AURA_REMOVED;
116 auraEvents.SPELL_AURA_BROKEN = function(frame, id, source)
117     return auraEvents.SPELL_AURA_REMOVED(frame, id, source, nil, nil, nil, 0);
118 end
119 auraEvents.SPELL_AURA_BROKEN_SPELL = auraEvents.SPELL_AURA_BROKEN;
120
121 local counter = 0;
122 local function clog(ts, event, _, source, _, _, _, dest, _, _, _, spellid, ...)
123     if auraEvents[event] and watchedAuras[spellid] and guids[dest] then
124         auraEvents[event](guids[dest], spellid, source, ...);
125     end
126 end
127 addon.Events.Clog = clog;
128
129 local types = {["HELPFUL"] = "BUFF", ["HARMFUL"] = "DEBUFF"};
130 local function setAuras(unit, guid)
131     local name;
132     local spellid, count, source;
133     for filter, atype in pairs(types) do
134         local i = 1;
135         while true do
136             name, _, count, _, _, _, source, _, _, spellid = UnitAura(unit, i, filter);
137             if not spellid then break end
138             if count == 0 then count = nil end
139             if source ~= nil then
140                 clog(0, "SPELL_AURA_APPLIED", nil, UnitGUID(source), nil, nil, nil,
141                      guid, nil, nil, nil, spellid, nil, nil, atype, count);
142             elseif filter == "HARMFUL" then
143                 clog(0, "SPELL_AURA_APPLIED", nil, nil, nil, nil, nil,
144                      guid, nil, nil, nil, spellid, nil, nil, atype, count);
145             end
146             i = i + 1;
147         end
148     end
149 end
150 addon.SetAuras = setAuras;
151
152 local frame = CreateFrame("Frame");
153 frame:Hide();
154 frame:SetScript("OnEvent", function()
155     playerGuid = UnitGUID("player");
156     frame:UnregisterAllEvents();
157     frame:SetScript("OnEvent", function()
158         return clog(CombatLogGetCurrentEventInfo());
159     end);
160     frame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED");
161 end);
162 frame:RegisterEvent("PLAYER_LOGIN");
163
164 -- debug slash command to get target auras
165 SLASH_KEHYS1 = "/kaura"
166 function SlashCmdList.KEHYS(msg, editBox)
167     local name, spellid, count, source;
168     local unit = "target";
169     if msg and msg ~= "" then
170         unit = msg;
171     end
172     for filter, atype in pairs(types) do
173         local i = 1;
174         while true do
175             name, _, count, _, _, _, source, _, _, spellid = UnitAura(unit, i, filter);
176             if not spellid then break end
177             print(atype, name, count, source, spellid);
178             i = i + 1;
179         end
180     end
181 end