-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLibDispel.lua
More file actions
335 lines (288 loc) · 14.5 KB
/
LibDispel.lua
File metadata and controls
335 lines (288 loc) · 14.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
local MAJOR, MINOR = "LibDispel", 10100
assert(LibStub, MAJOR .. " requires LibStub")
local lib = LibStub:NewLibrary(MAJOR, MINOR)
if not lib then return end
-- Blizzard
local UnitCanAssist = _G.UnitCanAssist
local UnitCanAttack = _G.UnitCanAttack
-- reference: https://wowpedia.fandom.com/wiki/WOW_PROJECT_ID
-- LE_EXPANSION_LEVEL_CURRENT
local LE_EXPANSION_CLASSIC = _G.LE_EXPANSION_CLASSIC or 0 -- Vanilla / Classic Era
local LE_EXPANSION_BURNING_CRUSADE = _G.LE_EXPANSION_BURNING_CRUSADE or 1 -- The Burning Crusade
local LE_EXPANSION_WRATH_OF_THE_LICH_KING = _G.LE_EXPANSION_WRATH_OF_THE_LICH_KING or 2 -- Wrath of the Lich King
local LE_EXPANSION_CATACLYSM = _G.LE_EXPANSION_CATACLYSM or 3 -- Cataclysm
local LE_EXPANSION_MISTS_OF_PANDARIA = _G.LE_EXPANSION_MISTS_OF_PANDARIA or 4 -- Mists of Pandaria
local LE_EXPANSION_WARLORDS_OF_DRAENOR = _G.LE_EXPANSION_WARLORDS_OF_DRAENOR or 5 -- Warlords of Draenor
local LE_EXPANSION_LEGION = _G.LE_EXPANSION_LEGION or 6 -- Legion
local LE_EXPANSION_BATTLE_FOR_AZEROTH = _G.LE_EXPANSION_BATTLE_FOR_AZEROTH or 7 -- Battle for Azeroth
local LE_EXPANSION_SHADOWLANDS = _G.LE_EXPANSION_SHADOWLANDS or 8 -- Shadowlands
local LE_EXPANSION_DRAGONFLIGHT = _G.LE_EXPANSION_DRAGONFLIGHT or 9 -- Dragonflight
local LE_EXPANSION_WAR_WITHIN = _G.LE_EXPANSION_WAR_WITHIN or 10 -- The War WithIn
local isRetail = WOW_PROJECT_ID == WOW_PROJECT_MAINLINE
local isClassic = WOW_PROJECT_ID == WOW_PROJECT_CLASSIC
local isTBC = WOW_PROJECT_ID == WOW_PROJECT_BURNING_CRUSADE_CLASSIC
local isWrath = WOW_PROJECT_ID == WOW_PROJECT_WRATH_CLASSIC
local isCata = WOW_PROJECT_ID == WOW_PROJECT_CATACLYSM_CLASSIC
local isMoP = WOW_PROJECT_ID == WOW_PROJECT_MISTS_CLASSIC
-- Event Frame
if not lib.frame then
lib.frame = CreateFrame("Frame", MAJOR)
lib.frame:RegisterEvent("PLAYER_LOGIN")
lib.frame:SetScript("OnEvent", function(self, event, ...)
if event == "PLAYER_LOGIN" then
local _, class = UnitClass("player")
lib.class = class
if isRetail then
-- fired when the player's spec has changed (switching between specs)
self:RegisterUnitEvent("PLAYER_SPECIALIZATION_CHANGED", "player")
-- when player changes some talents we need to listing to the spell "Changing Talents"
-- self:RegisterUnitEvent("UNIT_SPELLCAST_SUCCEEDED", "player")
self:RegisterEvent("SPELLS_CHANGED")
else
self:RegisterEvent("PLAYER_TALENT_UPDATE")
end
-- fires when spells in the spellbook change in any way
-- fires when DRUID change form (annoying...)
-- self:RegisterEvent("SPELLS_CHANGED")
-- self:RegisterEvent("LEARNED_SPELL_IN_TAB")
-- self:RegisterEvent("CHARACTER_POINTS_CHANGED")
if class == "WARLOCK" then
-- fired when a unit's pet changes
self:RegisterEvent("UNIT_PET")
end
-- lib:ValidateSpells(lib.enrage)
-- lib:ValidateSpells(lib.bleed)
elseif event == "UNIT_SPELLCAST_SUCCEEDED" then
local unit, guid, spellID = ...
if spellID ~= 384255 then return end
end
lib:UpdateDispels()
end)
end
lib.buffs = lib.buffs or {}
lib.debuffs = lib.debuffs or {}
lib.spells = lib.spells or {}
lib.enrage = lib.enrage or {}
lib.bleed = lib.bleed or {}
-- dispelable debuffs without dispel type
lib.notype = {
-- Mithyc+ Affixes
[409472] = true, -- Diseased Spirit
[440313] = true, -- Void Rift
}
if isRetail then
function lib:GetSpellName(spellID)
return C_Spell.GetSpellName(spellID)
end
function lib:IsSpellKnown(spellID, pet)
local spellBank = pet and Enum.SpellBookSpellBank.Pet or Enum.SpellBookSpellBank.Player
return C_SpellBook.IsSpellKnown(spellID, spellBank)
end
else
function lib:GetSpellName(spellID)
local name, rank, icon, castTime, minRange, maxRange, spellID, originalIcon = GetSpellInfo(spellID)
return name
end
function lib:IsSpellKnown(spellID, pet)
if IsPlayerSpell and not pet then
return IsPlayerSpell(spellID) or false
end
return IsSpellKnown(spellID, pet) or false
end
end
function lib:GetDispelType(spellID, dispelName)
if dispelName and dispelName ~= "none" and dispelName ~= "" then
return dispelName
elseif self.enrage[spellID] then
return "Enrage"
elseif self.bleed[spellID] then
return "Bleed"
end
return "none"
end
function lib:IsDispelable(unit, spellID, dispelName, isHarmful)
-- you can not remove debuffs from a enemy
local canAttack = UnitCanAttack(unit, "player") and UnitCanAttack("player", unit)
if (isHarmful and not UnitCanAssist("player", unit)) or (not isHarmful and not canAttack) then
return false
end
local spell = self[isHarmful and "debuffs" or "buffs"][dispelName or "none"]
return (spell ~= nil) or lib.notype[spellID] or false
end
if isClassic then
function lib:UpdateDispelsTypes(class)
if class == "DRUID" then
local remove_curse = self:IsSpellKnown(2782) -- Remove Curse
local abolish_poison = self:IsSpellKnown(2893) -- Abolish Poison
self.debuffs.Curse = remove_curse
self.debuffs.Poison = abolish_poison
elseif class == "HUNTER" then
local tranquilizing_shot = self:IsSpellKnown(19801) -- Tranquilizing Shot
self.buffs.Enrage = tranquilizing_shot
elseif class == "MAGE" then
local remove_curse = self:IsSpellKnown(475) -- Remove Curse
self.debuffs.Curse = remove_curse
elseif class == "PALADIN" then
local purify = self:IsSpellKnown(1152) -- Purify
local cleanse = self:IsSpellKnown(4987) -- Cleanse
self.debuffs.Disease = cleanse or purify
self.debuffs.Poison = cleanse or purify
self.debuffs.Magic = cleanse
elseif class == "PRIEST" then
local dispel_magic = self:IsSpellKnown(527) -- Dispel Magic
local cure_disease = self:IsSpellKnown(528) -- Cure Disease
local abolish_disease = self:IsSpellKnown(552) -- Abolish Disease
self.buffs.Magic = dispel_magic
self.debuffs.Magic = dispel_magic
self.debuffs.Disease = abolish_disease or cure_disease
elseif class == "SHAMAN" then
local purge = self:IsSpellKnown(370) -- Purge
local poison_cleansing = self:IsSpellKnown(526) -- Poison Cleansing Totem
local disease_cleansing = self:IsSpellKnown(8170) -- Disease Cleansing Totem
self.debuffs.Poison = poison_cleansing
self.debuffs.Disease = disease_cleansing
self.buffs.Magic = purge
end
end
elseif isMoP then
function lib:UpdateDispelsTypes(class)
if class == "DRUID" then
local remove_corruption = self:IsSpellKnown(2782) -- Remove Corruption
local nature_cure = self:IsSpellKnown(88423) -- Nature's Cure
local soothe = self:IsSpellKnown(2908) -- Soothe
self.debuffs.Magic = nature_cure
self.debuffs.Curse = nature_cure or remove_corruption
self.debuffs.Poison = nature_cure or remove_corruption
self.buffs.Enrage = soothe
elseif class == "HUNTER" then
local tranquilizing_shot = self:IsSpellKnown(19801) -- Tranquilizing Shot
self.buffs.Magic = tranquilizing_shot
self.buffs.Enrage = tranquilizing_shot
elseif class == "MAGE" then
self.buffs.Magic = self:IsSpellKnown(30449) -- Spellsteal
self.debuffs.Curse = self:IsSpellKnown(475) -- Remove Curse
elseif class == "MONK" then
local revival = self:IsSpellKnown(115310) -- Revival (Mistweaver)
local detox = self:IsSpellKnown(115450) -- Detox (Mistweaver)
local internal_medicine = self:IsSpellKnown(115451) -- Internal Medicine (Mistweaver)
self.debuffs.Magic = revival or (detox and internal_medicine)
self.debuffs.Disease = revival or detox
self.debuffs.Poison = revival or detox
elseif class == "PALADIN" then
local cleanse = self:IsSpellKnown(4987) -- Cleanse
local sacred_cleansing = self:IsSpellKnown(53551) -- Sacred Cleansing
local absolve = self:IsSpellKnown(140333) -- Absolve (Holy)
local hand_of_sacrifice = self:IsSpellKnown(6940) -- Hand of Sacrifice
self.debuffs.Magic = (cleanse and sacred_cleansing) or (hand_of_sacrifice and absolve)
self.debuffs.Disease = cleanse
self.debuffs.Poison = cleanse
elseif class == "PRIEST" then
local purify = self:IsSpellKnown(527) -- Purify
local dispel_magic = self:IsSpellKnown(528) -- Dispel Magic
local mass_dispel = self:IsSpellKnown(32375) -- Mass Dispel
self.debuffs.Magic = purify or mass_dispel
self.debuffs.Disease = purify
self.buffs.Magic = dispel_magic or mass_dispel
elseif class == "SHAMAN" then
local purge = self:IsSpellKnown(370) -- Purge
local purify_spirit = self:IsSpellKnown(77130) -- Purify Spirit (Resto)
local cleanse_spirit = self:IsSpellKnown(51886) -- Cleanse Spirit
self.debuffs.Magic = purify_spirit
self.debuffs.Curse = cleanse_spirit
self.buffs.Magic = purge
end
end
else
function lib:UpdateDispelsTypes(class)
if class == "DEMONHUNTER" then
self.debuffs.Magic = self:IsSpellKnown(205604) -- Reverse Magic (PvP)
self.buffs.Magic = self:IsSpellKnown(278326) -- Consume Magic
elseif class == "DEATHKNIGHT" then
elseif class == "EVOKER" then
local naturalize = self:IsSpellKnown(360823) -- Naturalize (Preservation)
local expunge = self:IsSpellKnown(365585) -- Expunge (Devastation)
local cauterizing = self:IsSpellKnown(374251) -- Cauterizing Flame
local scouring_flame = self:IsSpellKnown(378438) -- Scouring Flame (PvP Talent)
self.debuffs.Magic = naturalize or scouring_flame
self.debuffs.Poison = naturalize or expunge or cauterizing
self.debuffs.Disease = cauterizing
self.debuffs.Curse = cauterizing
self.debuffs.Bleed = cauterizing
elseif class == "DRUID" then
local corruption = cure or self:IsSpellKnown(2782) -- Remove Corruption
local soothe = self:IsSpellKnown(2908) -- Soothe
local cure = self:IsSpellKnown(88423) -- Nature's Cure
local improved_cure = self:IsSpellKnown(392378) -- Improved Nature's Cure (Restoration Talent)
self.debuffs.Magic = cure or improved_cure
self.debuffs.Curse = corruption or improved_cure
self.debuffs.Poison = corruption or improved_cure
self.buffs.Enrage = soothe
elseif class == "HUNTER" then
local tranquilizing_shot = self:IsSpellKnown(19801) -- Tranquilizing Shot
local mending_bandage = self:IsSpellKnown(212640) -- Mending Bandage (PvP)
self.debuffs.Disease = mending_bandage
self.debuffs.Poison = mending_bandage
self.buffs.Magic = tranquilizing_shot
self.buffs.Enrage = tranquilizing_shot
elseif class == "MAGE" then
self.buffs.Magic = self:IsSpellKnown(30449) -- Spellsteal
self.debuffs.Curse = self:IsSpellKnown(475) -- Remove Curse
elseif class == "MONK" then
local detox_magic = self:IsSpellKnown(115450) -- Detox (Mistweaver)
local improved_detox = self:IsSpellKnown(388874) -- Improved Detox (Mistweaver Talent)
local detox = detox_magic or self:IsSpellKnown(218164) -- Detox (Brewmaster or Windwalker)
self.debuffs.Magic = detox_magic
self.debuffs.Disease = detox or improved_detox
self.debuffs.Poison = detox or improved_detox
elseif class == "PALADIN" then
local cleanse = self:IsSpellKnown(4987) -- Cleanse (Holy)
local improved_cleanse = self:IsSpellKnown(393024) -- Improved Cleanse (Holy Talent)
local toxins = self:IsSpellKnown(213644) -- Cleanse Toxins (Protection or Retribution)
self.debuffs.Magic = cleanse
self.debuffs.Poison = toxins or improved_cleanse
self.debuffs.Disease = toxins or improved_cleanse
elseif class == "PRIEST" then
local purify = self:IsSpellKnown(527) -- Purify
local dispel_magic = self:IsSpellKnown(528) -- Dispel Magic
local mass_dispel = self:IsSpellKnown(32375) -- Mass Dispel
local improved_purify = self:IsSpellKnown(390632) -- Improved Purify (Discipline or Holy)
local disease = self:IsSpellKnown(213634) -- Purify Disease (Shadow)
self.buffs.Magic = dispel_magic or mass_dispel
self.debuffs.Magic = purify or mass_dispel
self.debuffs.Disease = disease or improved_purify
elseif class == "SHAMAN" then
local purge = self:IsSpellKnown(370) -- Purge
local purify = self:IsSpellKnown(77130) -- Purify Spirit
local improved_purify = self:IsSpellKnown(383016) -- Imroved Purify Spirit (Restoration Talent)
local cleanse = self:IsSpellKnown(51886) -- Cleanse Spirit
self.debuffs.Magic = purify
self.debuffs.Curse = cleanse or improved_purify
self.buffs.Magic = purge
elseif class == "WARLOCK" then
self.buffs.Magic = self:IsSpellKnown(171021, true) -- Torch Magic (Infernal)
self.debuffs.Magic = self:IsSpellKnown(89808, true) or self:IsSpellKnown(212623) -- Singe Magic (Imp) / (PvP)
end
end
end
function lib:UpdateDispels()
table.wipe(self.buffs)
table.wipe(self.debuffs)
table.wipe(self.spells)
local class = self.class
self:UpdateDispelsTypes(class)
if self.buffs.Magic then
self.spells[self.buffs.Magic] = "offensive"
end
end
function lib:ValidateSpells(dest)
for spellID, _ in next, dest do
local spellName = self:GetSpellName(spellID)
if not spellName then
self:print("Spell " .. spellID .. " do not exists.")
dest[spellID] = nil
end
end
end
function lib:print(...)
print("|cffffa1a1" .. MAJOR .. ":|r", ...)
end