Repository navigation
Expand file tree
/
Copy pathCore.lua
More file actions
360 lines (303 loc) · 8.4 KB
/
Copy pathCore.lua
File metadata and controls
360 lines (303 loc) · 8.4 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
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
local ADDON_NAME = ...
RaidBuffCounter = RaidBuffCounter or {}
local RBC = RaidBuffCounter
MageBuffTracker = RaidBuffCounter
local ADDON_TITLE = "Raid Buff Counter"
local AFFILIATION_MINE = COMBATLOG_OBJECT_AFFILIATION_MINE or 0x00000001
local AFFILIATION_RAID = COMBATLOG_OBJECT_AFFILIATION_RAID or 0x00000008
local function IsSourceInMyRaid(sourceFlags)
if not sourceFlags then
return false
end
if bit.band(sourceFlags, AFFILIATION_MINE) > 0 then
return true
end
if bit.band(sourceFlags, AFFILIATION_RAID) > 0 then
return true
end
return false
end
local function StripRealm(fullName)
if not fullName or fullName == "" then
return "Unknown"
end
return (fullName:match("^([^%-]+)")) or fullName
end
local function ImportLegacyDB()
if type(RaidBuffCounterDB) ~= "table" and type(MageBuffTrackerDB) == "table" then
RaidBuffCounterDB = MageBuffTrackerDB
end
end
local function EnsureDB()
ImportLegacyDB()
if type(RaidBuffCounterDB) ~= "table" then
RaidBuffCounterDB = {}
end
local db = RaidBuffCounterDB
if type(db.counts) ~= "table" then
db.counts = {}
end
local firstKey = next(db.counts)
if firstKey and type(db.counts[firstKey]) == "table" and db.counts[firstKey].ai ~= nil and db.counts.mage == nil then
db.counts = { mage = db.counts }
end
for _, classKey in ipairs(RBC.CLASS_ORDER) do
if type(db.counts[classKey]) ~= "table" then
db.counts[classKey] = {}
end
end
if db.sessionActive == nil then
db.sessionActive = false
end
if db.persistAcrossLogouts == nil then
db.persistAcrossLogouts = false
end
if db.resetOnLogout == nil then
db.resetOnLogout = not db.persistAcrossLogouts
end
if db.resetOnLogin == nil then
db.resetOnLogin = false
end
if db.frame == nil then
db.frame = {}
end
if db.frame.hidden == nil then
db.frame.hidden = false
end
if db.frame.minimized == nil then
db.frame.minimized = true
end
if db.frame.selectedClass == nil or not RBC.CLASSES[db.frame.selectedClass] then
db.frame.selectedClass = "mage"
end
return db
end
local function ClearCounts()
local db = EnsureDB()
for _, classKey in ipairs(RBC.CLASS_ORDER) do
wipe(db.counts[classKey])
end
end
local function ShouldResetOnLogin(db)
return db.resetOnLogin ~= false
end
local function ShouldResetOnLogout(db)
return db.resetOnLogout ~= false
end
local function StartNewSession()
local db = EnsureDB()
if not db.sessionActive and ShouldResetOnLogin(db) then
ClearCounts()
end
db.sessionActive = true
end
local function EndSession()
local db = EnsureDB()
db.sessionActive = false
if ShouldResetOnLogout(db) then
ClearCounts()
end
end
function RBC.GetCounts(classKey)
local db = EnsureDB()
classKey = classKey or RBC.GetSelectedClass()
return db.counts[classKey]
end
function RBC.ResetCounts(classKey)
local db = EnsureDB()
if classKey then
if type(db.counts[classKey]) == "table" then
wipe(db.counts[classKey])
end
local label = RBC.CLASSES[classKey] and RBC.CLASSES[classKey].label or classKey
if RBC.RefreshUI then
RBC:RefreshUI()
end
print("|cff3fc7eb" .. ADDON_TITLE .. ":|r " .. label .. " counts reset.")
return
end
ClearCounts()
if RBC.RefreshUI then
RBC:RefreshUI()
end
print("|cff3fc7eb" .. ADDON_TITLE .. ":|r all class counts reset.")
end
function RBC.GetResetOnLogout()
return ShouldResetOnLogout(EnsureDB())
end
function RBC.GetResetOnLogin()
return ShouldResetOnLogin(EnsureDB())
end
function RBC.SetResetOnLogout(enabled)
local db = EnsureDB()
db.resetOnLogout = enabled and true or false
db.persistAcrossLogouts = not db.resetOnLogout
if RBC.SyncOptionsUI then
RBC:SyncOptionsUI()
end
end
function RBC.SetResetOnLogin(enabled)
local db = EnsureDB()
db.resetOnLogin = enabled and true or false
if RBC.SyncOptionsUI then
RBC:SyncOptionsUI()
end
end
function RBC.SetPersistAcrossLogouts(enabled)
RBC.SetResetOnLogout(not enabled)
print(
"|cff3fc7eb" .. ADDON_TITLE .. ":|r persist across logout is "
.. (enabled and "|cff00ff00ON|r" or "|cffff0000OFF|r")
.. "."
)
end
function RBC.UpdateRaidWindowState()
if not RBC.frame or not RBC.frame:IsShown() or not RBC.SetMinimized then
return
end
local inRaid = IsInRaid()
-- First run after load: sync state without forcing expand (respect saved minimize).
if RBC.wasInRaid == nil then
RBC.wasInRaid = inRaid
if not inRaid then
RBC:SetMinimized(true)
end
return
end
if not inRaid then
RBC:SetMinimized(true)
elseif not RBC.wasInRaid then
-- Just joined a raid — expand once.
RBC:SetMinimized(false)
end
-- Already in raid: leave minimize state alone (roster changes won't expand).
RBC.wasInRaid = inRaid
end
local function GetOrCreateEntry(classKey, shortName)
local counts = RBC.GetCounts(classKey)
local entry = counts[shortName]
if not entry then
entry = RBC.CreateEmptyEntry(classKey)
counts[shortName] = entry
end
return entry
end
local function IncrementCount(classKey, shortName, column)
local entry = GetOrCreateEntry(classKey, shortName)
entry[column] = (entry[column] or 0) + 1
if RBC.RefreshUI then
RBC:RefreshUI()
end
end
local function OnCombatLog()
local _, subEvent, _, _, srcName, sourceFlags, _, _, _, _, _, _, spellName =
CombatLogGetCurrentEventInfo()
if subEvent ~= "SPELL_CAST_SUCCESS" then
return
end
if not srcName or not spellName or not IsInRaid() then
return
end
if not IsSourceInMyRaid(sourceFlags) then
return
end
local classKey, column = RBC.MatchSpell(spellName)
if not classKey or not column then
return
end
IncrementCount(classKey, StripRealm(srcName), column)
end
local function SlashHandler(msg)
msg = strtrim(msg or ""):lower()
if msg == "reset" or msg == "reset all" then
RBC.ResetCounts()
return
end
local resetClass = msg:match("^reset (%a+)$")
if resetClass and RBC.CLASSES[resetClass] then
RBC.ResetCounts(resetClass)
return
end
if msg == "toggle" then
if RBC.ToggleFrame then
RBC:ToggleFrame()
end
return
end
if msg == "options" then
if RBC.ToggleOptionsPanel then
RBC:ToggleOptionsPanel()
end
return
end
if msg == "mini" or msg == "minimize" then
if RBC.ToggleMinimized then
RBC:ToggleMinimized()
end
return
end
if msg == "persist on" then
RBC.SetPersistAcrossLogouts(true)
return
end
if msg == "persist off" then
RBC.SetPersistAcrossLogouts(false)
return
end
for _, classKey in ipairs(RBC.CLASS_ORDER) do
if msg == classKey then
RBC.SetSelectedClass(classKey)
print("|cff3fc7eb" .. ADDON_TITLE .. ":|r showing " .. RBC.CLASSES[classKey].label .. ".")
return
end
end
print("|cff3fc7eb" .. ADDON_TITLE .. " commands:|r")
print(" /rbc - show this help")
print(" /rbc reset - clear all counts")
print(" /rbc reset all - clear all counts")
print(" /rbc reset <class> - clear one class (e.g. reset priest)")
print(" /rbc toggle - show or hide the window")
print(" /rbc options - show options panel")
print(" /rbc mini - minimize or expand the window")
print(" /rbc druid|mage|paladin|priest|warlock|warrior - switch class view")
print(" /rbc persist on|off - keep counts after logout (default off)")
end
local eventFrame = CreateFrame("Frame")
eventFrame:RegisterEvent("ADDON_LOADED")
eventFrame:RegisterEvent("PLAYER_LOGIN")
eventFrame:RegisterEvent("PLAYER_LOGOUT")
eventFrame:RegisterEvent("GROUP_ROSTER_UPDATE")
eventFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
eventFrame:SetScript("OnEvent", function(_, event, arg1)
if event == "ADDON_LOADED" and arg1 == ADDON_NAME then
EnsureDB()
StartNewSession()
return
end
if event == "PLAYER_LOGIN" then
StartNewSession()
return
end
if event == "PLAYER_LOGOUT" then
EndSession()
return
end
if event == "GROUP_ROSTER_UPDATE" then
RBC.UpdateRaidWindowState()
return
end
if event == "COMBAT_LOG_EVENT_UNFILTERED" then
OnCombatLog()
end
end)
SLASH_RAIDBUFFCOUNTER1 = "/rbc"
SLASH_RAIDBUFFCOUNTER2 = "/raidbuffcounter"
SlashCmdList["RAIDBUFFCOUNTER"] = SlashHandler
SLASH_MAGEBUFFTRACKER1 = "/mbt"
SLASH_MAGEBUFFTRACKER2 = "/magebufftracker"
SlashCmdList["MAGEBUFFTRACKER"] = function(msg)
print("|cff3fc7ebRaid Buff Counter:|r /mbt is deprecated; use /rbc instead.")
SlashHandler(msg)
end
RBC.StripRealm = StripRealm
RBC.ADDON_TITLE = ADDON_TITLE