e8fd612 - Add more auras and dot tracking functions
[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     [974] = {1, "buff2"}, -- Earth Shield
28     -- Tank defensives
29     [6940] = {1, "tankcd"}, -- Blessing of Sacrifice
30     [33206] = {1, "tankcd"}, -- Pain Suppression
31     [47788] = {1, "tankcd"}, -- Guardian Spirit
32     [102342] = {1, "tankcd"}, -- Ironbark
33     [116849] = {1, "tankcd"}, -- Life Cocoon
34     [196555] = {1, "tankcd"}, -- Netherwalk
35     -- M+
36     [209858] = {1, "stacks"}, -- Necrotic Wound (M+)
37     [240559] = {1, "stacks"}, -- Grievous Wound (M+)
38     [240443] = {1, "stacks"}, -- Burst (M+)
39     [260741] = {1, "heal"}, -- Jagged Nettles (Waycrest Manor)
40     -- Uldir
41     [265264] = {2, "alert"}, -- Void Lash (Zek'voz)
42     -- Battle of Dazar'alor
43     [285213] = {1, "alert"}, -- Caress of Death (Rastakhan)
44     [288415] = {1, "alert"}, -- Caress of Death in Death realm (Rastakhan)
45     [285195] = {8, "stacks"}, -- Deathly Withering (Rastakhan)
46     [286646] = {1, "heal"}, -- Gigavolt Charge (Mekkatorque)
47     [288939] = {1, "heal"}, -- Gigavolt Radiation (Mekkatorque)
48     [287891] = {1, "stacks"}, -- Sheep Shrapnel (Mekkatorque)
49     [287114] = {1, "alert"}, -- Miscalculated Teleport (Mekkatorque)
50     [287167] = {1, "stacks"}, -- Discombobulation (Mekkatorque)
51     [287993] = {1, "stacks"}, -- Chilling Touch (Jaina)
52     [283507] = {1, "heal"}, -- Volatile Charge (Opulence)
53     [287648] = {1, "heal"}, -- Volatile Charge (Opulence)
54     [284556] = {1, "stacks"}, -- Shadow-Touched (Opulence)
55     [287072] = {1, "heal"}, -- Liquid Gold (Opulence)
56     [284781] = {1, "heal"}, -- Grievous Axe (Rastakhan)
57     [290955] = {1, "heal"}, -- Grievous Axe (Rastakhan)
58     -- Crucible of Storms
59     [282566] = {1, "stacks"}, -- Promises of Power (Restless Cabal)
60     [282738] = {1, "alert"}, -- Embrace of the Void (Restless Cabal)
61     [285652] = {1, "alert"}, -- Insatiable Torment (Uu'nat)
62     [285367] = {2, "stacks"}, -- Piercing Gaze of N'Zoth (Uu'nat)
63     [284733] = {1, "alert"}, -- Embrace of the Void (Uu'nat)
64     [285685] = {1, "alert"}, -- Gift of N'Zoth: Lunacy (Uu'nat)
65     -- The Eternal Palace
66     [292127] = {1, "alert"}, -- Darkest Depths (Underwater)
67     [298569] = {1, "stacks"}, -- Drained Soul (Queen Azshara)
68     [297586] = {1, "alert"}, -- Suffering (Queen's Court)
69     [294711] = {5, "heal"}, -- Frost (Sivara)
70     [294715] = {5, "heal"}, -- Toxic (Sivara)
71     [296693] = {1, "stacks"}, -- Waterlogged (Ashvane)
72     [297333] = {1, "heal"}, -- Briny Bubble (Ashvane)
73     [298306] = {1, "stacks"}, -- Incubation Fluid (Orgozoa)
74     -- Ny'alotha
75     [313255] = {20, "stacks"}, -- Creeping Madness (Wrathion)
76     [310224] = {1, "stacks"}, -- Annihilation (Vexiona)
77     [307358] = {1, "heal"}, -- Debilitating Spit (Shad'har)
78     [318078] = {1, "alert"}, -- Fixate (Shad'har)
79     [312486] = {1, "stacks"}, -- Recurring Nightmare (Il'gynoth)
80     [313400] = {1, "stacks"}, -- Corrupted Mind (N'zoth)
81     --[319346] = {1, "heal"}, -- Infinity's Toll (N'zoth) phase marker
82     [316506] = {1, "alert"}, -- Heartpiercer Venom (Trash)
83     [315025] = {1, "heal"}, -- Ancient Curse (Maut)
84     [315311] = {1, "stacks"}, -- Ravage (Hivemind)
85     [313460] = {1, "alert"}, -- Nullification (Hivemind)
86     [313461] = {1, "heal"}, -- Corrosion (Hivemind)
87     [307359] = {1, "heal"}, -- Despair (Vexiona)
88     [313077] = {1, "heal"}, -- Unleashed Nightmare (Ra-den)
89     [316065] = {1, "alert"}, -- Corrupted Existence (Ra-den)
90     [313364] = {1, "heal"}, -- Mental Decay (Carapace of N'zoth)
91     [307044] = {4, "stacks"}, -- Nightmare Antibody (Carapace of N'zoth)
92     -- SL M+
93     [323347] = {1, "stacks"}, -- Clinging Darkness (Necrotic Wake)
94     [338357] = {2, "stacks"}, -- Tenderize (Necrotic Wake)
95     [321038] = {1, "stacks"}, -- Wrack Soul (Sanguine Depths)
96     [331415] = {1, "stacks"}, -- Wicked Gash (Sanguine Depths)
97     [328737] = {1, "stacks"}, -- Fragment of Radiance (Sanguine Depths)
98     [326632] = {5, "stacks"}, -- Stony Veins (Halls of Atonement)
99     [344993] = {5, "stacks"}, -- Jagged Swipe (Halls of Atonement)
100     [323692] = {1, "stacks"}, -- Arcane Vulnerability (De Other Side)
101     [317661] = {1, "stacks"}, -- Insidious Venom (Spires of Ascension)
102     [327814] = {1, "heal"}, -- Wicked Gash (Gauntlet) (Sanguine Depths)
103     [323687] = {1, "heal"}, -- Arcane Lightning (De Other Side)
104     [324154] = {1, "heal"}, -- Dark Stride (Spires of Ascension)
105     -- Castle Nathria
106     [346301] = {1, "stacks"}, -- Bloodlight (Shriekwing)
107     [328897] = {7, "alert"}, -- Exsanguinated (Shriekwing)
108     [335304] = {1, "heal"}, -- Sinseeker (Huntsman Altimor)
109     [334971] = {2, "stacks"}, -- Jagged Claws (Huntsman Altimor)
110     [325382] = {3, "stacks"}, -- Warped Desires (Lady Inerva Darkvein)
111     [332664] = {1, "heal"}, -- Anima Add (Lady Inerva Darkvein)
112     [340477] = {1, "heal"}, -- Anima Add (Lady Inerva Darkvein)
113     [339527] = {1, "heal"}, -- Anima Add (Lady Inerva Darkvein)
114     [342321] = {1, "heal"}, -- Anima Add (Lady Inerva Darkvein)
115     [342322] = {1, "heal"}, -- Anima Add (Lady Inerva Darkvein)
116     [324982] = {1, "heal"}, -- Shared Suffering (Lady Inerva Darkvein)
117     [324983] = {1, "heal"}, -- Shared Suffering (Lady Inerva Darkvein)
118     [340860] = {1, "heal", 14}, -- Withering Touch (Artificer Xy'mox)
119     [334771] = {1, "heal"}, -- Heart Hemorrhage (Stone Legion Generals)
120     [326699] = {1, "stacks"}, -- Burden of Sin (Sire Denathrius)
121     [329298] = {1, "alert"}, -- Gluttonous Miasma (Hungering Destroyer)
122     [334755] = {14, "heal"}, -- Essence Sap (Hungering Destroyer)
123     [343320] = {1, "alert"}, -- Curse of Caramain (Trash)
124     [333913] = {2, "stacks"}, -- Wicked Laceration (Stone Legion Generals)
125 };
126 local playerGuid = nil;
127
128 local auraEvents = {};
129 auraEvents.SPELL_AURA_APPLIED = function(frame, id, source, _, _, atype, amount)
130     if (amount == nil and watchedAuras[id][1] == 1) or (amount ~= nil and amount >= watchedAuras[id][1]) then
131         amount = amount or 1;
132         if atype == "BUFF" and (source == playerGuid or watchedAuras[id][2] == "tankcd") then
133             frame[watchedAuras[id][2]][id] = amount;
134         elseif atype == "DEBUFF" then
135             frame[watchedAuras[id][2]][id] = amount;
136             if watchedAuras[id][3] ~= nil then
137                 frame.stacks[id] = watchedAuras[id][3];
138             end
139         end
140     end
141 end
142 auraEvents.SPELL_AURA_APPLIED_DOSE = auraEvents.SPELL_AURA_APPLIED;
143 auraEvents.SPELL_AURA_REFRESH = auraEvents.SPELL_AURA_APPLIED;
144 auraEvents.SPELL_AURA_REMOVED = function(frame, id, source, _, _, atype, amount)
145     if amount == nil or amount == 0 then
146         if atype == "BUFF" and (source == playerGuid or watchedAuras[id][2] == "tankcd") then
147             frame[watchedAuras[id][2]][id] = nil;
148         elseif atype == "DEBUFF" then
149             frame[watchedAuras[id][2]][id] = nil;
150         end
151     end
152 end
153 auraEvents.SPELL_AURA_REMOVED_DOSE = auraEvents.SPELL_AURA_REMOVED;
154 auraEvents.SPELL_AURA_BROKEN = function(frame, id, source)
155     return auraEvents.SPELL_AURA_REMOVED(frame, id, source, nil, nil, nil, 0);
156 end
157 auraEvents.SPELL_AURA_BROKEN_SPELL = auraEvents.SPELL_AURA_BROKEN;
158 auraEvents.SPELL_PERIODIC_DAMAGE = function(frame, id, source)
159     if watchedAuras[id][3] ~= nil then
160         if frame.stacks[id] ~= nil and frame.stacks[id] > 0 then
161             frame.stacks[id] = frame.stacks[id] - 1;
162             if frame.stacks[id] == 0 then
163                 frame.stacks[id] = nil;
164             end
165         elseif frame.stacks[id] ~= nil then
166             frame.stacks[id] = nil;
167         end
168     end
169 end
170
171 local counter = 0;
172 local function clog(ts, event, _, source, _, _, _, dest, _, _, _, spellid, ...)
173     if auraEvents[event] and watchedAuras[spellid] and guids[dest] then
174         auraEvents[event](guids[dest], spellid, source, ...);
175     end
176 end
177 addon.Events.Clog = clog;
178
179 local types = {["HELPFUL"] = "BUFF", ["HARMFUL"] = "DEBUFF"};
180 local function setAuras(unit, guid)
181     local name;
182     local spellid, count, source;
183     for filter, atype in pairs(types) do
184         local i = 1;
185         while true do
186             name, _, count, _, _, _, source, _, _, spellid = UnitAura(unit, i, filter);
187             if not spellid then break end
188             if count == 0 then count = nil end
189             if source ~= nil then
190                 clog(0, "SPELL_AURA_APPLIED", nil, UnitGUID(source), nil, nil, nil,
191                      guid, nil, nil, nil, spellid, nil, nil, atype, count);
192             elseif filter == "HARMFUL" then
193                 clog(0, "SPELL_AURA_APPLIED", nil, nil, nil, nil, nil,
194                      guid, nil, nil, nil, spellid, nil, nil, atype, count);
195             end
196             i = i + 1;
197         end
198     end
199 end
200 addon.SetAuras = setAuras;
201
202 local frame = CreateFrame("Frame");
203 frame:Hide();
204 frame:SetScript("OnEvent", function()
205     playerGuid = UnitGUID("player");
206     frame:UnregisterAllEvents();
207     frame:SetScript("OnEvent", function()
208         return clog(CombatLogGetCurrentEventInfo());
209     end);
210     frame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED");
211 end);
212 frame:RegisterEvent("PLAYER_LOGIN");
213
214 -- debug slash command to get target auras
215 SLASH_KEHYS1 = "/kaura"
216 function SlashCmdList.KEHYS(msg, editBox)
217     local name, spellid, count, source;
218     local unit = "target";
219     if msg and msg ~= "" then
220         unit = msg;
221     end
222     for filter, atype in pairs(types) do
223         local i = 1;
224         while true do
225             name, _, count, _, _, _, source, _, _, spellid = UnitAura(unit, i, filter);
226             if not spellid then break end
227             print(atype, name, count, source, spellid);
228             i = i + 1;
229         end
230     end
231 end