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