-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathData.lua
More file actions
executable file
·1262 lines (1087 loc) · 39.3 KB
/
Data.lua
File metadata and controls
executable file
·1262 lines (1087 loc) · 39.3 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
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
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- HonorLog Data Layer
-- Handles SavedVariables, data structures, and persistence
local ADDON_NAME, HonorLog = ...
HonorLog = HonorLog or {}
_G.HonorLog = HonorLog
-- Default database structure
local DEFAULTS = {
global = {
-- Account-wide lifetime stats per BG
battlegrounds = {
AV = { played = 0, wins = 0, losses = 0, totalDuration = 0, honorLifetime = 0, marksLifetime = 0 },
AB = { played = 0, wins = 0, losses = 0, totalDuration = 0, honorLifetime = 0, marksLifetime = 0 },
WSG = { played = 0, wins = 0, losses = 0, totalDuration = 0, honorLifetime = 0, marksLifetime = 0 },
EotS = { played = 0, wins = 0, losses = 0, totalDuration = 0, honorLifetime = 0, marksLifetime = 0 },
},
-- Account-wide world PvP stats
worldPvP = {
kills = 0,
deaths = 0,
honor = 0,
},
history = {}, -- Account-wide history
historyLimit = 200,
characters = {}, -- Track which characters contributed
},
char = {
-- Per-character stats
battlegrounds = {
AV = { played = 0, wins = 0, losses = 0, totalDuration = 0, honorLifetime = 0, marksLifetime = 0 },
AB = { played = 0, wins = 0, losses = 0, totalDuration = 0, honorLifetime = 0, marksLifetime = 0 },
WSG = { played = 0, wins = 0, losses = 0, totalDuration = 0, honorLifetime = 0, marksLifetime = 0 },
EotS = { played = 0, wins = 0, losses = 0, totalDuration = 0, honorLifetime = 0, marksLifetime = 0 },
},
-- Per-character world PvP stats
worldPvP = {
kills = 0,
deaths = 0,
honor = 0,
},
history = {}, -- Per-character history
historyLimit = 200,
-- Gear Goals system
goals = {
items = {}, -- Array of { itemID, addedAt, priority }
completed = {}, -- Array of { itemID, addedAt, completedAt }
settings = {
autoRemoveCompleted = false,
showInLDB = true,
celebrateCompletion = true,
},
-- No goal limit
},
-- Daily stats (persists across /reload, resets at midnight)
session = {
AV = { played = 0, wins = 0, losses = 0, honor = 0, marks = 0 },
AB = { played = 0, wins = 0, losses = 0, honor = 0, marks = 0 },
WSG = { played = 0, wins = 0, losses = 0, honor = 0, marks = 0 },
EotS = { played = 0, wins = 0, losses = 0, honor = 0, marks = 0 },
worldPvP = { kills = 0, deaths = 0, honor = 0 },
},
sessionStartTime = 0, -- Timestamp when session started (deprecated, use sessionTotalDuration)
sessionTotalDuration = 0, -- Cumulative BG duration in seconds (for accurate hourly rate)
lastUpdateTime = 0, -- Timestamp when session was last updated
wasLogout = false, -- Track if last exit was logout vs reload (deprecated, kept for migration)
lastGameTime = 0, -- GetTime() at last save - used to detect reload vs fresh login
-- BG state (persists across /reload for mid-BG continuity)
bgState = {
currentBG = nil,
bgStartTime = nil,
bgStartHonor = nil,
bgHonorAccumulated = 0,
isInBG = false,
},
},
settings = {
frameVisible = true,
frameExpanded = false,
frameLocked = false,
framePoint = { "CENTER", nil, "CENTER", 0, 0 },
frameScale = 1.0,
frameSize = nil, -- nil = use default, or { width, height } for custom size
frameResizable = true, -- Allow frame resizing
viewMode = "character", -- "character" or "account"
exportFormat = "text", -- "text" or "csv"
notificationsEnabled = false,
ldbEnabled = true,
minimapButton = {
hide = false,
},
goalProgressMode = "shared", -- "shared" (all show same %) or "waterfall" (fills top-to-bottom)
visibleCards = { -- Which stat cards to show
AV = true,
AB = true,
WSG = true,
EotS = true,
World = true,
},
},
}
-- Deep copy utility
local function DeepCopy(orig)
local copy
if type(orig) == "table" then
copy = {}
for k, v in pairs(orig) do
copy[k] = DeepCopy(v)
end
else
copy = orig
end
return copy
end
-- Deep merge (target inherits missing keys from source)
local function DeepMerge(target, source)
for k, v in pairs(source) do
if type(v) == "table" then
if type(target[k]) ~= "table" then
target[k] = {}
end
DeepMerge(target[k], v)
elseif target[k] == nil then
target[k] = DeepCopy(v)
end
end
end
-- Initialize database
function HonorLog:InitializeDB()
-- Global (account-wide) saved variables
if not HonorLogDB then
HonorLogDB = DeepCopy(DEFAULTS.global)
else
DeepMerge(HonorLogDB, DEFAULTS.global)
end
-- Per-character saved variables
if not HonorLogCharDB then
HonorLogCharDB = DeepCopy(DEFAULTS.char)
else
DeepMerge(HonorLogCharDB, DEFAULTS.char)
end
-- Settings (stored in global)
if not HonorLogDB.settings then
HonorLogDB.settings = DeepCopy(DEFAULTS.settings)
else
DeepMerge(HonorLogDB.settings, DEFAULTS.settings)
end
-- Session reset logic: Daily reset + reload detection
-- Session = "today's stats" - resets at midnight, persists across /reload
local now = time()
local currentGameTime = GetTime()
local lastGameTime = HonorLogCharDB.lastGameTime or 0
local lastSessionDate = HonorLogCharDB.sessionDate
-- Get today's date as YYYYMMDD number for easy comparison
local today = tonumber(date("%Y%m%d", now))
-- Debug: Print session state on load
local sessionDebug = false -- Set to true to debug session issues
if sessionDebug then
print("|cffff00ff[HonorLog Session Debug]|r")
print(" lastSessionDate: " .. tostring(lastSessionDate) .. " (type: " .. type(lastSessionDate) .. ")")
print(" today: " .. tostring(today) .. " (type: " .. type(today) .. ")")
print(" currentGameTime: " .. tostring(currentGameTime))
print(" lastGameTime: " .. tostring(lastGameTime))
-- Show current session stats before any reset
if HonorLogCharDB.session then
for bgType, s in pairs(HonorLogCharDB.session) do
if s.played then
print(" session." .. bgType .. ": " .. s.played .. " played, " .. s.wins .. " wins")
end
end
end
end
-- Check if we need to reset session
local shouldResetSession = false
local resetReason = ""
-- Migration: if sessionDate was never set, this is first run after update
-- Don't reset existing session data, just set the date
-- sessionStartTime will be handled by the safety check below
if not lastSessionDate then
HonorLogCharDB.sessionDate = today
lastSessionDate = today
self.isReload = true
resetReason = "migration (keeping existing session)"
-- Reset if it's a new day
elseif lastSessionDate ~= today then
shouldResetSession = true
resetReason = "new day"
-- Reset if client was restarted (GetTime() reset)
elseif currentGameTime < lastGameTime and lastGameTime > 0 then
-- Client restart on same day keeps session (daily stats)
-- But we do need to clear BG state since that's mid-game tracking
HonorLogCharDB.bgState = DeepCopy(DEFAULTS.char.bgState)
self.isReload = false
resetReason = "client restart (keeping daily session)"
else
-- This is a /reload - keep everything
self.isReload = true
resetReason = "reload (keeping everything)"
end
if sessionDebug then
print(" Decision: " .. resetReason .. ", shouldReset: " .. tostring(shouldResetSession))
end
if shouldResetSession then
-- Silent reset - no chat spam
HonorLogCharDB.session = DeepCopy(DEFAULTS.char.session)
HonorLogCharDB.bgState = DeepCopy(DEFAULTS.char.bgState)
HonorLogCharDB.sessionStartTime = 0 -- Deprecated, kept for backwards compatibility
HonorLogCharDB.sessionTotalDuration = 0 -- Reset cumulative BG time
HonorLogCharDB.sessionDate = today
self.isReload = false
else
HonorLogCharDB.lastUpdateTime = now
end
-- Update tracking values
HonorLogCharDB.lastGameTime = currentGameTime
-- Track this character
local charKey = UnitName("player") .. "-" .. GetRealmName()
HonorLogDB.characters[charKey] = true
self.db = {
global = HonorLogDB,
char = HonorLogCharDB,
settings = HonorLogDB.settings,
}
return self.db
end
-- Get stats for a specific BG
function HonorLog:GetBGStats(bgType, scope)
scope = scope or self.db.settings.viewMode
if scope == "account" then
return self.db.global.battlegrounds[bgType]
else
return self.db.char.battlegrounds[bgType]
end
end
-- Get session stats for a BG
function HonorLog:GetSessionStats(bgType)
return self.db.char.session[bgType]
end
-- Get all BG stats
function HonorLog:GetAllBGStats(scope)
scope = scope or self.db.settings.viewMode
if scope == "account" then
return self.db.global.battlegrounds
else
return self.db.char.battlegrounds
end
end
-- Calculate derived stats
function HonorLog:GetDerivedStats(bgType, scope)
local stats = self:GetBGStats(bgType, scope)
local session = self:GetSessionStats(bgType)
local winrate = 0
if stats.played > 0 then
winrate = (stats.wins / stats.played) * 100
end
local avgDuration = 0
if stats.played > 0 then
avgDuration = stats.totalDuration / stats.played
end
local sessionWinrate = 0
if session.played > 0 then
sessionWinrate = (session.wins / session.played) * 100
end
return {
winrate = winrate,
avgDuration = avgDuration,
sessionWinrate = sessionWinrate,
}
end
-- Record a completed game
function HonorLog:RecordGame(bgType, won, duration, honor, marks)
-- Track cumulative BG time for accurate hourly rate calculation
self.db.char.sessionTotalDuration = (self.db.char.sessionTotalDuration or 0) + duration
-- Update character stats
local charBG = self.db.char.battlegrounds[bgType]
charBG.played = charBG.played + 1
if won then
charBG.wins = charBG.wins + 1
else
charBG.losses = charBG.losses + 1
end
charBG.totalDuration = charBG.totalDuration + duration
charBG.honorLifetime = charBG.honorLifetime + honor
charBG.marksLifetime = charBG.marksLifetime + marks
-- Update account stats
local globalBG = self.db.global.battlegrounds[bgType]
globalBG.played = globalBG.played + 1
if won then
globalBG.wins = globalBG.wins + 1
else
globalBG.losses = globalBG.losses + 1
end
globalBG.totalDuration = globalBG.totalDuration + duration
globalBG.honorLifetime = globalBG.honorLifetime + honor
globalBG.marksLifetime = globalBG.marksLifetime + marks
-- Update session stats
local session = self.db.char.session[bgType]
session.played = session.played + 1
if won then
session.wins = session.wins + 1
else
session.losses = session.losses + 1
end
session.honor = session.honor + honor
session.marks = session.marks + marks
-- Add to history
local historyEntry = {
bgType = bgType,
win = won,
duration = duration,
honor = honor,
marks = marks,
timestamp = time(),
character = UnitName("player"),
}
-- Character history
table.insert(self.db.char.history, 1, historyEntry)
while #self.db.char.history > self.db.char.historyLimit do
table.remove(self.db.char.history)
end
-- Account history
table.insert(self.db.global.history, 1, historyEntry)
while #self.db.global.history > self.db.global.historyLimit do
table.remove(self.db.global.history)
end
-- Check milestones
self:CheckMilestones(bgType)
-- Fire callback for UI update
if self.OnDataUpdated then
self:OnDataUpdated()
end
end
-- Reset session stats
function HonorLog:ResetSession(bgType)
if bgType then
self.db.char.session[bgType] = DeepCopy(DEFAULTS.char.session[bgType])
else
self.db.char.session = DeepCopy(DEFAULTS.char.session)
self.db.char.sessionTotalDuration = 0 -- Reset cumulative BG time
end
if self.OnDataUpdated then
self:OnDataUpdated()
end
return true
end
-- Get history
function HonorLog:GetHistory(scope, limit)
scope = scope or self.db.settings.viewMode
limit = limit or 10
local history
if scope == "account" then
history = self.db.global.history
else
history = self.db.char.history
end
local result = {}
for i = 1, math.min(limit, #history) do
result[i] = history[i]
end
return result
end
-- Set history limit
function HonorLog:SetHistoryLimit(limit)
limit = math.max(10, math.min(100, limit))
self.db.char.historyLimit = limit
self.db.global.historyLimit = limit
-- Trim existing history
while #self.db.char.history > limit do
table.remove(self.db.char.history)
end
while #self.db.global.history > limit do
table.remove(self.db.global.history)
end
end
-- Milestone checking
local MILESTONES = {
wins = { 10, 25, 50, 100, 250, 500, 1000 },
played = { 10, 50, 100, 250, 500, 1000 },
winrate = { 50, 60, 70, 80, 90 },
}
function HonorLog:CheckMilestones(bgType)
if not self.db.settings.notificationsEnabled then return end
local stats = self:GetBGStats(bgType, "character")
local derived = self:GetDerivedStats(bgType, "character")
-- Check win milestones
for _, milestone in ipairs(MILESTONES.wins) do
if stats.wins == milestone then
self:AnnounceMilestone(bgType, "wins", milestone)
end
end
-- Check games played milestones
for _, milestone in ipairs(MILESTONES.played) do
if stats.played == milestone then
self:AnnounceMilestone(bgType, "played", milestone)
end
end
-- Check winrate milestones (only if 10+ games)
if stats.played >= 10 then
for _, milestone in ipairs(MILESTONES.winrate) do
local prevWinrate = ((stats.wins - 1) / (stats.played - 1)) * 100
if prevWinrate < milestone and derived.winrate >= milestone then
self:AnnounceMilestone(bgType, "winrate", milestone)
end
end
end
end
function HonorLog:AnnounceMilestone(bgType, statType, value)
local messages = {
wins = string.format("|cff00ff00[HonorLog]|r Milestone! %d wins in %s!", value, bgType),
played = string.format("|cff00ff00[HonorLog]|r Milestone! %d games played in %s!", value, bgType),
winrate = string.format("|cff00ff00[HonorLog]|r Milestone! %d%% winrate achieved in %s!", value, bgType),
}
DEFAULT_CHAT_FRAME:AddMessage(messages[statType])
end
-- Settings accessors
function HonorLog:GetSetting(key)
return self.db.settings[key]
end
function HonorLog:SetSetting(key, value)
self.db.settings[key] = value
end
-- Format time duration
function HonorLog:FormatDuration(seconds)
if seconds < 60 then
return string.format("%ds", seconds)
elseif seconds < 3600 then
return string.format("%dm %ds", math.floor(seconds / 60), seconds % 60)
else
return string.format("%dh %dm", math.floor(seconds / 3600), math.floor((seconds % 3600) / 60))
end
end
-- Get total session stats across all BGs
function HonorLog:GetTotalSessionStats()
local total = {
played = 0,
wins = 0,
losses = 0,
honor = 0,
marks = 0,
hourlyRate = 0,
sessionDuration = 0,
}
for bgType, session in pairs(self.db.char.session) do
-- Skip non-BG entries (like worldPvP)
if session.played then
total.played = total.played + session.played
total.wins = total.wins + session.wins
total.losses = total.losses + session.losses
total.honor = total.honor + session.honor
total.marks = total.marks + session.marks
end
end
total.winrate = total.played > 0 and (total.wins / total.played * 100) or 0
-- Calculate hourly rate based on cumulative BG duration (actual play time)
local cumulativeDuration = self.db.char.sessionTotalDuration or 0
-- Include current in-progress BG duration for live rate updates
local bgState = self.db.char.bgState
if bgState and bgState.isInBG and bgState.bgStartTime then
local currentBGElapsed = GetTime() - bgState.bgStartTime
if currentBGElapsed > 0 then
cumulativeDuration = cumulativeDuration + currentBGElapsed
end
end
if cumulativeDuration > 0 and total.honor > 0 then
total.sessionDuration = cumulativeDuration
-- Only calculate rate if we have at least 1 minute of BG time
if cumulativeDuration >= 60 then
local hours = cumulativeDuration / 3600
total.hourlyRate = math.floor(total.honor / hours)
end
end
return total
end
--[[
============================================================================
WORLD PVP TRACKING APIs
============================================================================
--]]
-- Record a world kill (outside battlegrounds)
function HonorLog:RecordWorldKill()
-- Update character stats
self.db.char.worldPvP.kills = self.db.char.worldPvP.kills + 1
-- Update account stats
self.db.global.worldPvP.kills = self.db.global.worldPvP.kills + 1
-- Update session stats
self.db.char.session.worldPvP.kills = self.db.char.session.worldPvP.kills + 1
-- Fire callback for UI update
if self.OnDataUpdated then
self:OnDataUpdated()
end
end
-- Record a world death (killed by enemy player outside battlegrounds)
function HonorLog:RecordWorldDeath()
-- Update character stats
self.db.char.worldPvP.deaths = self.db.char.worldPvP.deaths + 1
-- Update account stats
self.db.global.worldPvP.deaths = self.db.global.worldPvP.deaths + 1
-- Update session stats
self.db.char.session.worldPvP.deaths = self.db.char.session.worldPvP.deaths + 1
-- Fire callback for UI update
if self.OnDataUpdated then
self:OnDataUpdated()
end
end
-- Record honor earned from world PvP
function HonorLog:RecordWorldHonor(amount)
if not amount or amount <= 0 then return end
-- Update character stats
self.db.char.worldPvP.honor = self.db.char.worldPvP.honor + amount
-- Update account stats
self.db.global.worldPvP.honor = self.db.global.worldPvP.honor + amount
-- Update session stats
self.db.char.session.worldPvP.honor = self.db.char.session.worldPvP.honor + amount
-- Fire callback for UI update
if self.OnDataUpdated then
self:OnDataUpdated()
end
end
-- Get world PvP stats
function HonorLog:GetWorldPvPStats(scope)
scope = scope or self.db.settings.viewMode
if scope == "account" then
return self.db.global.worldPvP
else
return self.db.char.worldPvP
end
end
-- Get session world PvP stats
function HonorLog:GetSessionWorldPvPStats()
return self.db.char.session.worldPvP
end
--[[
============================================================================
CURRENCY APIs - For Gear Goal Tracking
============================================================================
--]]
-- Get current honor points
function HonorLog:GetCurrentHonor()
-- Try C_CurrencyInfo API first (TBC Classic Anniversary uses this)
if C_CurrencyInfo and C_CurrencyInfo.GetCurrencyInfo then
-- Honor currency ID 1901 is used in TBC Classic Anniversary
local info = C_CurrencyInfo.GetCurrencyInfo(1901)
if info and info.quantity and info.quantity > 0 then
return info.quantity
end
-- Try other known honor currency IDs as fallback
local currencyIDs = {1792, 392, 43308}
for _, currencyID in ipairs(currencyIDs) do
info = C_CurrencyInfo.GetCurrencyInfo(currencyID)
if info and info.quantity and info.quantity > 0 then
return info.quantity
end
end
end
-- TBC Classic (original) uses GetHonorCurrency
if GetHonorCurrency then
local honor = GetHonorCurrency()
if honor and honor > 0 then
return honor
end
end
-- Fallback: GetPVPCurrency (older Classic)
if GetPVPCurrency then
local _, honor = GetPVPCurrency()
if honor and honor > 0 then
return honor
end
end
return 0
end
-- Get current arena points
function HonorLog:GetCurrentArenaPoints()
-- Try C_CurrencyInfo API first (TBC Classic Anniversary)
if C_CurrencyInfo and C_CurrencyInfo.GetCurrencyInfo then
-- Arena Points currency ID 1900 in TBC Classic Anniversary
local info = C_CurrencyInfo.GetCurrencyInfo(1900)
if info and info.quantity and info.quantity > 0 then
return info.quantity
end
end
-- TBC Classic (original) uses GetArenaCurrency
if GetArenaCurrency then
return GetArenaCurrency()
end
return 0
end
-- Get current marks for a specific BG type
function HonorLog:GetCurrentMarks(bgType)
if not self.MARK_ITEMS then return 0 end
local itemID = self.MARK_ITEMS[bgType]
if itemID then
return GetItemCount(itemID, true) -- true = include bank
end
return 0
end
-- Get all current marks
function HonorLog:GetAllCurrentMarks()
return {
AV = self:GetCurrentMarks("AV"),
AB = self:GetCurrentMarks("AB"),
WSG = self:GetCurrentMarks("WSG"),
EotS = self:GetCurrentMarks("EotS"),
}
end
--[[
============================================================================
AVERAGE CALCULATION APIs - For Game Estimates
============================================================================
--]]
-- Get average honor per game (based on lifetime stats)
function HonorLog:GetAverageHonorPerGame(scope)
scope = scope or "character"
local stats = scope == "account" and self.db.global.battlegrounds or self.db.char.battlegrounds
local totalHonor = 0
local totalGames = 0
for bgType, bgStats in pairs(stats) do
totalHonor = totalHonor + (bgStats.honorLifetime or 0)
totalGames = totalGames + (bgStats.played or 0)
end
if totalGames > 0 then
return totalHonor / totalGames
end
-- Fallback: reasonable estimate for TBC Classic (~250 honor/game average)
return 250
end
-- Get average marks per game for a specific BG
function HonorLog:GetAverageMarksPerGame(bgType, scope)
scope = scope or "character"
local stats = scope == "account" and self.db.global.battlegrounds or self.db.char.battlegrounds
local bgStats = stats[bgType]
if bgStats and (bgStats.played or 0) > 0 then
return (bgStats.marksLifetime or 0) / bgStats.played
end
-- Fallback: ~1.5 marks per game (3 for win, 0-1 for loss)
return 1.5
end
-- Get average honor per game for a specific BG
function HonorLog:GetAverageHonorPerBG(bgType, scope)
scope = scope or "character"
local stats = scope == "account" and self.db.global.battlegrounds or self.db.char.battlegrounds
local bgStats = stats[bgType]
if bgStats and (bgStats.played or 0) > 0 then
return (bgStats.honorLifetime or 0) / bgStats.played
end
-- Fallback: reasonable estimate for TBC Classic
return 250
end
--[[
============================================================================
GOAL MANAGEMENT APIs
============================================================================
--]]
-- Get all goals
function HonorLog:GetGoals()
return self.db.char.goals.items or {}
end
-- Get goal count
function HonorLog:GetGoalCount()
return #(self.db.char.goals.items or {})
end
-- Check if can add more goals (no limit)
function HonorLog:CanAddGoal()
return true
end
-- Check if item is already a goal
function HonorLog:IsGoal(itemID)
for _, goal in ipairs(self.db.char.goals.items) do
if goal.itemID == itemID then
return true
end
end
return false
end
-- Add a goal
function HonorLog:AddGoal(itemID)
if not self:CanAddGoal() then
return false, "Maximum goals reached"
end
if self:IsGoal(itemID) then
return false, "Item is already a goal"
end
local item = self:GetGearItem(itemID)
if not item then
return false, "Item not found in gear database"
end
table.insert(self.db.char.goals.items, {
itemID = itemID,
addedAt = time(),
priority = self:GetGoalCount() + 1,
})
if self.OnDataUpdated then
self:OnDataUpdated()
end
return true
end
-- Remove a goal
function HonorLog:RemoveGoal(itemID)
local goals = self.db.char.goals.items
for i, goal in ipairs(goals) do
if goal.itemID == itemID then
table.remove(goals, i)
-- Re-prioritize remaining goals
for j = i, #goals do
goals[j].priority = j
end
if self.OnDataUpdated then
self:OnDataUpdated()
end
return true
end
end
return false
end
-- Complete a goal (move from active to completed)
function HonorLog:CompleteGoal(itemID)
local goals = self.db.char.goals.items
local completed = self.db.char.goals.completed
for i, goal in ipairs(goals) do
if goal.itemID == itemID then
-- Move to completed list
table.insert(completed, {
itemID = goal.itemID,
addedAt = goal.addedAt,
completedAt = time(),
})
-- Remove from active list
table.remove(goals, i)
-- Re-prioritize remaining goals
for j = i, #goals do
goals[j].priority = j
end
if self.OnDataUpdated then
self:OnDataUpdated()
end
return true
end
end
return false
end
-- Restore a completed goal back to active
function HonorLog:RestoreGoal(itemID)
local goals = self.db.char.goals.items
local completed = self.db.char.goals.completed
for i, goal in ipairs(completed) do
if goal.itemID == itemID then
-- Add back to active list at the end
table.insert(goals, {
itemID = goal.itemID,
addedAt = goal.addedAt,
priority = #goals + 1,
})
-- Remove from completed list
table.remove(completed, i)
if self.OnDataUpdated then
self:OnDataUpdated()
end
return true
end
end
return false
end
-- Remove a completed goal permanently
function HonorLog:RemoveCompletedGoal(itemID)
local completed = self.db.char.goals.completed
for i, goal in ipairs(completed) do
if goal.itemID == itemID then
table.remove(completed, i)
if self.OnDataUpdated then
self:OnDataUpdated()
end
return true
end
end
return false
end
-- Get completed goals list
function HonorLog:GetCompletedGoals()
return self.db.char.goals.completed or {}
end
-- Check if an item is in player's bags or equipped
function HonorLog:IsItemInInventory(itemID)
-- Check bags (0 = backpack, 1-4 = additional bags)
for bag = 0, 4 do
local numSlots = 0
if C_Container and C_Container.GetContainerNumSlots then
numSlots = C_Container.GetContainerNumSlots(bag) or 0
elseif GetContainerNumSlots then
numSlots = GetContainerNumSlots(bag) or 0
end
for slot = 1, numSlots do
local slotItemID = nil
if C_Container and C_Container.GetContainerItemID then
slotItemID = C_Container.GetContainerItemID(bag, slot)
elseif GetContainerItemID then
slotItemID = GetContainerItemID(bag, slot)
end
if slotItemID and slotItemID == itemID then
return true
end
end
end
-- Check equipped items (slots 1-19 cover all equipment slots)
for slot = 1, 19 do
local equippedItemID = GetInventoryItemID("player", slot)
if equippedItemID and equippedItemID == itemID then
return true
end
end
return false
end
-- Scan all active goals and auto-complete any that are in inventory
function HonorLog:ScanGoalsForAcquiredItems()
local goals = self.db.char.goals.items
local acquiredItems = {}
-- First pass: find all acquired items
for _, goal in ipairs(goals) do
if self:IsItemInInventory(goal.itemID) then
table.insert(acquiredItems, goal.itemID)
end
end
-- Second pass: complete them (separate loop to avoid modifying table while iterating)
for _, itemID in ipairs(acquiredItems) do
local itemName, _, itemQuality = GetItemInfo(itemID)
itemName = itemName or "Item"
self:CompleteGoal(itemID)
-- Celebratory notification!
-- 1. Play quest complete sound
PlaySound(878) -- SOUNDKIT.IG_QUEST_LIST_COMPLETE
-- 2. Show center-screen alert (like achievements)
if RaidNotice_AddMessage and RaidBossEmoteFrame then
RaidNotice_AddMessage(RaidBossEmoteFrame, "|cff00ff00Goal Acquired!|r " .. itemName, ChatTypeInfo["RAID_WARNING"])
end
-- 3. Show in UIErrorsFrame (green, top of screen)
if UIErrorsFrame then
UIErrorsFrame:AddMessage("|cff40d860[HonorLog]|r Goal acquired: " .. itemName, 0.25, 0.85, 0.37, 1, 3)
end
-- 4. Chat message (for log)
print("|cff40d860[HonorLog]|r \124\124 Goal acquired: |cffffffff" .. itemName .. "|r")
end
return #acquiredItems
end
-- Reorder a goal
function HonorLog:ReorderGoal(itemID, newPosition)
local goals = self.db.char.goals.items
local oldIndex = nil
-- Find current position
for i, goal in ipairs(goals) do
if goal.itemID == itemID then
oldIndex = i
break
end
end
if not oldIndex then return false end
if newPosition < 1 or newPosition > #goals then return false end
if oldIndex == newPosition then return true end
-- Remove from old position and insert at new position
local goal = table.remove(goals, oldIndex)
table.insert(goals, newPosition, goal)
-- Update priorities
for i, g in ipairs(goals) do
g.priority = i
end
if self.OnDataUpdated then
self:OnDataUpdated()
end