-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathClassicSpellActivations.lua
581 lines (516 loc) · 18.4 KB
/
ClassicSpellActivations.lua
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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
local addonName, ns = ...
local f = CreateFrame("Frame", "ClassicSpellActivations") --, UIParent)
f:SetScript("OnEvent", function(self, event, ...)
return self[event](self, event, ...)
end)
local UnitGUID = UnitGUID
local bit_band = bit.band
local CombatLogGetCurrentEventInfo = CombatLogGetCurrentEventInfo
local AFFILIATION_MINE = COMBATLOG_OBJECT_AFFILIATION_MINE
local _, class = UnitClass("player")
local procCombatLog
local registeredFrames = {}
local activations = {}
local LocalizedOverpower = GetSpellInfo(7384)
local LocalizedRevenge = GetSpellInfo(6572)
local LocalizedRiposte = GetSpellInfo(14251)
local LocalizedCounterattack = GetSpellInfo(19306)
-- local LocalizedExecute = GetSpellInfo(20662)
-- local LocalizedShadowBolt = GetSpellInfo(686)
local LocalizedMongooseBite = GetSpellInfo(1495)
local LBG
local spellNamesByID = {
[7384] = "Overpower",
[7887] = "Overpower",
[11584] = "Overpower",
[11585] = "Overpower",
[6572] = "Revenge",
[6574] = "Revenge",
[7379] = "Revenge",
[11600] = "Revenge",
[11601] = "Revenge",
[25288] = "Revenge",
[14251] = "Riposte",
[19306] = "Counterattack",
[20909] = "Counterattack",
[20910] = "Counterattack",
[20662] = "Execute",
[20661] = "Execute",
[20660] = "Execute",
[20658] = "Execute",
[5308] = "Execute",
[686] = "ShadowBolt",
[695] = "ShadowBolt",
[705] = "ShadowBolt",
[1088] = "ShadowBolt",
[1106] = "ShadowBolt",
[7641] = "ShadowBolt",
[11659] = "ShadowBolt",
[11660] = "ShadowBolt",
[11661] = "ShadowBolt",
[25307] = "ShadowBolt",
[1495] = "MongooseBite",
[14269] = "MongooseBite",
[14270] = "MongooseBite",
[14271] = "MongooseBite",
[879] = "Exorcism",
[5614] = "Exorcism",
[5615] = "Exorcism",
[10312] = "Exorcism",
[10313] = "Exorcism",
[10314] = "Exorcism",
[24275] = "HammerOfWrath",
[24274] = "HammerOfWrath",
[24239] = "HammerOfWrath",
}
f:RegisterEvent("PLAYER_LOGIN")
function f:PLAYER_LOGIN()
if class == "WARRIOR" or class == "ROGUE" or class == "HUNTER" or class == "WARLOCK" or class == "PALADIN" then
self:RegisterEvent("SPELLS_CHANGED")
self:SPELLS_CHANGED()
local bars = {"ActionButton","MultiBarBottomLeftButton","MultiBarBottomRightButton","MultiBarLeftButton","MultiBarRightButton"}
for _,bar in ipairs(bars) do
for i = 1,12 do
local btn = _G[bar..i]
self:RegisterForActivations(btn)
end
end
hooksecurefunc("ActionButton_UpdateOverlayGlow", function(self)
ns.UpdateOverlayGlow(self)
end)
local LAB = LibStub("LibActionButton-1.0", true) -- Bartener support
if LAB then
LBG = LibStub("LibButtonGlow-1.0", true)
self:RegisterForActivations(LAB.eventFrame)
LAB:RegisterCallback("OnButtonUpdate", function(event, self)
ns.LAB_UpdateOverlayGlow(self)
end)
end
local LAB2 = LibStub("LibActionButton-1.0-ElvUI", true) -- ElvUI support
if LAB2 then
LBG = LibStub("LibButtonGlow-1.0", true)
self:RegisterForActivations(LAB2.eventFrame)
LAB2:RegisterCallback("OnButtonUpdate", function(event, self)
ns.LAB_UpdateOverlayGlow(self)
end)
end
end
-- self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
end
local UnitAura = UnitAura
local function FindAura(unit, spellID, filter)
for i=1, 100 do
local name, icon, count, debuffType, duration, expirationTime, unitCaster, canStealOrPurge, nameplateShowPersonal, auraSpellID = UnitAura(unit, i, filter)
if not name then return nil end
if spellID == auraSpellID then
return name, icon, count, debuffType, duration, expirationTime, unitCaster, canStealOrPurge, nameplateShowPersonal, auraSpellID
end
end
end
local hadShadowTrance
function f:SPELLS_CHANGED()
if class == "WARRIOR" then
self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
self:SetScript("OnUpdate", self.timerOnUpdate)
if ns.findHighestRank("Overpower") and ns.findHighestRank("Revenge") then
local CheckOverpower = ns.CheckOverpower
local CheckRevenge = ns.CheckRevenge
procCombatLog = function(...)
CheckOverpower(...)
CheckRevenge(...)
end
elseif ns.findHighestRank("Overpower") then
procCombatLog = ns.CheckOverpower
elseif ns.findHighestRank("Revenge") then
procCombatLog = ns.CheckRevenge
else
self:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
self:SetScript("OnUpdate", nil)
end
if ns.findHighestRank("Execute") then
self:RegisterEvent("PLAYER_TARGET_CHANGED")
self:RegisterUnitEvent("UNIT_HEALTH", "target")
self.PLAYER_TARGET_CHANGED = ns.ExecuteCheck
self.UNIT_HEALTH = ns.ExecuteCheck
else
self:UnregisterEvent("PLAYER_TARGET_CHANGED")
self:UnregisterEvent("UNIT_HEALTH")
end
elseif class == "ROGUE" then
if ns.findHighestRank("Riposte") then
self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
procCombatLog = ns.CheckRiposte
self:SetScript("OnUpdate", self.timerOnUpdate)
else
self:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
self:SetScript("OnUpdate", nil)
end
elseif class == "PALADIN" then
if ns.findHighestRank("Exorcism") then
self:RegisterEvent("PLAYER_TARGET_CHANGED")
self.PLAYER_TARGET_CHANGED = ns.PaladinExorcismCheck
self:SetScript("OnUpdate", self.timerOnUpdate)
if ns.findHighestRank("HammerOfWrath") then
self:RegisterUnitEvent("UNIT_HEALTH", "target")
self.PLAYER_TARGET_CHANGED = function(...)
ns.PaladinExorcismCheck(...)
ns.HOWCheck(...)
end
self.UNIT_HEALTH = ns.HOWCheck
end
end
elseif class == "HUNTER" then
self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
self:SetScript("OnUpdate", self.timerOnUpdate)
if ns.findHighestRank("Counterattack") and ns.findHighestRank("MongooseBite") then
local CheckCounterattack = ns.CheckCounterattack
local CheckMongooseBite = ns.CheckMongooseBite
procCombatLog = function(...)
CheckCounterattack(...)
CheckMongooseBite(...)
end
elseif ns.findHighestRank("MongooseBite") then
procCombatLog = ns.CheckMongooseBite
else
self:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
self:SetScript("OnUpdate", nil)
end
elseif class == "WARLOCK" then
self:SetScript("OnUpdate", self.timerOnUpdate)
if IsPlayerSpell(18094) or IsPlayerSpell(18095) then
self:RegisterUnitEvent("UNIT_AURA", "player")
self:SetScript("OnUpdate", self.timerOnUpdate)
self.UNIT_AURA = function(self, event, unit)
local name, _, _, _, duration, expirationTime = FindAura(unit, 17941, "HELPFUL") -- Shadow Trance
local haveShadowTrance = name ~= nil
if hadShadowTrance ~= haveShadowTrance then
if haveShadowTrance then
f:Activate("ShadowBolt", duration, true)
else
f:Deactivate("ShadowBolt")
end
hadShadowTrance = haveShadowTrance
end
end
else
self:SetScript("OnUpdate", nil)
self:UnregisterEvent("UNIT_AURA")
end
end
end
function f:RegisterForActivations(frame)
registeredFrames[frame] = true
-- registeredFrames:GetScript("OnEvent")
end
local function IsSpellOverlayed(spellID)
local spellName = spellNamesByID[spellID]
if not spellName then return false end
local state = activations[spellName]
if state then return state.active end
end
local GetActionInfo = _G.GetActionInfo
local GetMacroSpell = _G.GetMacroSpell
local ActionButton_ShowOverlayGlow = _G.ActionButton_ShowOverlayGlow
local ActionButton_HideOverlayGlow = _G.ActionButton_HideOverlayGlow
function ns.UpdateOverlayGlow(self)
local spellType, id, subType = GetActionInfo(self.action);
if ( spellType == "spell" and IsSpellOverlayed(id) ) then
ActionButton_ShowOverlayGlow(self);
elseif ( spellType == "macro" ) then
local spellId = GetMacroSpell(id);
if ( spellId and IsSpellOverlayed(spellId) ) then
ActionButton_ShowOverlayGlow(self);
else
ActionButton_HideOverlayGlow(self);
end
else
ActionButton_HideOverlayGlow(self);
end
end
function ns.LAB_UpdateOverlayGlow(self)
local spellId = self:GetSpellId()
if spellId and IsSpellOverlayed(spellId) then
if LBG then
LBG.ShowOverlayGlow(self)
end
else
if LBG then
LBG.HideOverlayGlow(self)
end
end
end
function f:FanoutEvent(event, ...)
for frame, _ in pairs(registeredFrames) do
local eventHandler = frame:GetScript("OnEvent")
eventHandler(frame, event, ...)
end
end
local reverseSpellRanks = {
Overpower = { 11585, 11584, 7887, 7384 },
Revenge = { 25288, 11601, 11600, 7379, 6574, 6572 },
Riposte = { 14251 },
Counterattack = { 20910, 20909, 19306 },
Execute = { 20662, 20661, 20660, 20658, 5308 },
ShadowBolt = { 25307, 11661, 11660, 11659, 7641, 1106, 1088, 705, 695, 686 },
MongooseBite = { 14271, 14270, 14269, 1495 },
Exorcism = { 10314, 10313, 10312, 5615, 5614, 879 },
HammerOfWrath = { 24239, 24274, 24275 },
}
function ns.findHighestRank(spellName)
for _, spellID in ipairs(reverseSpellRanks[spellName]) do
if IsPlayerSpell(spellID) then return spellID end
end
end
local findHighestRank = ns.findHighestRank
function f:Activate(spellName, duration, keepExpiration)
local state = activations[spellName]
if not state then
activations[spellName] = {}
state = activations[spellName]
end
if not state.active then
state.active = true
state.expirationTime = duration and GetTime() + duration
local highestRankSpellID = findHighestRank(spellName)
self:FanoutEvent("SPELL_ACTIVATION_OVERLAY_GLOW_SHOW", highestRankSpellID)
elseif not keepExpiration then
state.expirationTime = duration and GetTime() + duration
end
end
function f:Deactivate(spellName)
local state = activations[spellName]
if state and state.active == true then
state.active = false
state.expirationTime = nil
local highestRankSpellID = findHighestRank(spellName)
self:FanoutEvent("SPELL_ACTIVATION_OVERLAY_GLOW_HIDE", highestRankSpellID)
end
end
local _OnUpdateCounter = 0
local periodicCheck = nil
function f.timerOnUpdate(self, elapsed)
_OnUpdateCounter = _OnUpdateCounter + elapsed
if _OnUpdateCounter < 0.2 then return end
_OnUpdateCounter = 0
if periodicCheck then
periodicCheck()
end
local now = GetTime()
for spellName, state in pairs(activations) do
if state.expirationTime and now >= state.expirationTime then
f:Deactivate(spellName)
end
end
end
function f:COMBAT_LOG_EVENT_UNFILTERED(event)
local timestamp, eventType, hideCaster,
srcGUID, srcName, srcFlags, srcFlags2,
dstGUID, dstName, dstFlags, dstFlags2,
arg1, arg2, arg3, arg4, arg5 = CombatLogGetCurrentEventInfo()
local isSrcPlayer = bit_band(srcFlags, AFFILIATION_MINE) == AFFILIATION_MINE
local isDstPlayer = dstGUID == UnitGUID("player")
procCombatLog(eventType, isSrcPlayer, isDstPlayer, arg1, arg2, arg3, arg4, arg5)
end
-----------------
-- WARRIOR
-----------------
function ns.ExecuteCheck(self, event, unit)
if UnitExists("target") and not UnitIsFriend("player", "target") then
local h = UnitHealth("target")
local hm = UnitHealthMax("target")
local executeID = ns.findHighestRank("Execute")
if h > 0 and (h/hm < 0.2 or IsUsableSpell(executeID)) then
f:Activate("Execute", 10)
else
f:Deactivate("Execute")
end
else
f:Deactivate("Execute")
end
end
function ns.CheckOverpower(eventType, isSrcPlayer, isDstPlayer, ...)
if isSrcPlayer then
if eventType == "SWING_MISSED" or eventType == "SPELL_MISSED" then
local missedType
if eventType == "SWING_MISSED" then
missedType = select(1, ...)
elseif eventType == "SPELL_MISSED" then
missedType = select(4, ...)
end
if missedType == "DODGE" then
f:Activate("Overpower", 5)
end
end
if eventType == "SPELL_CAST_SUCCESS" then
local spellName = select(2, ...)
if spellName == LocalizedOverpower then
f:Deactivate("Overpower")
end
end
end
end
function ns.CheckRevenge(eventType, isSrcPlayer, isDstPlayer, ...)
if isDstPlayer then
if eventType == "SWING_MISSED" or eventType == "SPELL_MISSED" then
local missedType
if eventType == "SWING_MISSED" then
missedType = select(1, ...)
elseif eventType == "SPELL_MISSED" then
missedType = select(4, ...)
end
if missedType == "BLOCK" or missedType == "DODGE" or missedType == "PARRY" then
f:Activate("Revenge", 5)
end
end
if eventType == "SWING_DAMAGE" then
local blocked = select(5, ...)
if blocked then
f:Activate("Revenge", 5)
end
end
end
if isSrcPlayer and eventType == "SPELL_CAST_SUCCESS" then
local spellName = select(2, ...)
if spellName == LocalizedRevenge then
f:Deactivate("Revenge")
end
end
end
-----------------
-- ROGUE
-----------------
function ns.CheckRiposte(eventType, isSrcPlayer, isDstPlayer, ...)
if isDstPlayer then
if eventType == "SWING_MISSED" or eventType == "SPELL_MISSED" then
local missedType
if eventType == "SWING_MISSED" then
missedType = select(1, ...)
elseif eventType == "SPELL_MISSED" then
missedType = select(4, ...)
end
if missedType == "PARRY" then
f:Activate("Riposte", 5)
end
end
end
if isSrcPlayer and eventType == "SPELL_CAST_SUCCESS" then
local spellName = select(2, ...)
if spellName == LocalizedRiposte then -- Riposte
f:Deactivate("Riposte")
end
end
end
-----------------
-- HUNTER
-----------------
function ns.CheckCounterattack(eventType, isSrcPlayer, isDstPlayer, ...)
if isDstPlayer then
if eventType == "SWING_MISSED" or eventType == "SPELL_MISSED" then
local missedType
if eventType == "SWING_MISSED" then
missedType = select(1, ...)
elseif eventType == "SPELL_MISSED" then
missedType = select(4, ...)
end
if missedType == "PARRY" then
f:Activate("Counterattack", 5)
end
end
end
if isSrcPlayer and eventType == "SPELL_CAST_SUCCESS" then
local spellName = select(2, ...)
if spellName == LocalizedCounterattack then
f:Deactivate("Counterattack", 5)
end
end
end
function ns.CheckMongooseBite(eventType, isSrcPlayer, isDstPlayer, ...)
if isDstPlayer then
if eventType == "SWING_MISSED" or eventType == "SPELL_MISSED" then
local missedType
if eventType == "SWING_MISSED" then
missedType = select(1, ...)
elseif eventType == "SPELL_MISSED" then
missedType = select(4, ...)
end
if missedType == "DODGE" then
f:Activate("MongooseBite", 5)
end
end
end
if isSrcPlayer and eventType == "SPELL_CAST_SUCCESS" then
local spellName = select(2, ...)
if spellName == LocalizedMongooseBite then
f:Deactivate("MongooseBite", 5)
end
end
end
-----------------
-- PALADIN
-----------------
do
local LocalDemonTypes = { "Demon", "Dämon", "Demonio", "Demonio", "Démon", "Demone", "Demônio", "Демон", "악마", "恶魔", "惡魔" }
local LocalUndeadTypes = { "Undead", "Untoter", "No-muerto", "No-muerto", "Mort-vivant", "Non Morto", "Renegado", "Нежить", "언데드", "亡灵", "不死族" }
local LocIDs = {
["enUS"] = 1,
["deDE"] = 2,
["esES"] = 3,
["esMX"] = 4,
["frFR"] = 5,
["itIT"] = 6,
["ptBR"] = 7,
["ruRU"] = 8,
["koKR"] = 9,
["zhCN"] = 10,
["zhTW"] = 11,
}
local UndeadType
local DemonType
local locID = LocIDs[GetLocale()]
if locID then
UndeadType = LocalUndeadTypes[locID]
DemonType = LocalDemonTypes[locID]
end
local exorcismTicker
local exorcismCooldownState
local exorcismTickerFunc = function()
local startTime, duration, enabled = GetSpellCooldown(8092) -- fistt Rank
local newState
if duration <= 1.5 then
newState = false
else
newState = true
end
if newState ~= exorcismCooldownState then
if newState == false then
f:Activate("Exorcism", 5)
else
f:Deactivate("Exorcism")
end
end
exorcismCooldownState = newState
end
function ns.PaladinExorcismCheck(self, event)
if UnitExists("target") and (UnitCreatureType("target") == UndeadType or UnitCreatureType("target") == DemonType) then
exorcismCooldownState = not exorcismCooldownState
exorcismTickerFunc()
periodicCheck = exorcismTickerFunc
else
f:Deactivate("Exorcism")
periodicCheck = nil
end
end
end
function ns.HOWCheck(self, event, unit)
if UnitExists("target") and not UnitIsFriend("player", "target") then
local h = UnitHealth("target")
local hm = UnitHealthMax("target")
if h > 0 and h/hm <= 0.2 then
f:Activate("HammerOfWrath", 10)
else
f:Deactivate("HammerOfWrath")
end
else
f:Deactivate("HammerOfWrath")
end
end