-
Notifications
You must be signed in to change notification settings - Fork 0
/
AlltheGold.lua
2658 lines (2268 loc) · 92.9 KB
/
AlltheGold.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
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
local ATG_display_name, ATG = ...
-- AlltheGold.lua
-- $Id$
--[[ ================================================================= ]]--
--[[ Addon Initialisation ]]--
--[[ ================================================================= ]]--
-- Localize some lua globals
local _G = getfenv(0)
local floor = _G.floor
local geterrorhandler = _G.geterrorhandler
local gettime = _G.gettime
local ipairs = _G.ipairs
local min = _G.min
local mod = _G.mod
local next = _G.next
local pairs = _G.pairs
local select = _G.select
local sort = _G.sort
local time = _G.time
local tinsert = _G.tinsert
local tostring = _G.tostring
local tremove = _G.tremove
local type = _G.type
local wipe = _G.wipe
-- Debuging helper function
local function err(msg,...) _G.geterrorhandler()(msg:format(_G.tostringall(...)) .. " - " .. _G.time()) end
-- Non Blizzard globals that need to be localized
local LibStub = _G.LibStub
-- Revision
if not _G.AlltheGold_revision then _G.AlltheGold_revision = {} end
local AlltheGold_revision = _G.AlltheGold_revision
AlltheGold_revision.main = ("$Revision$"):match("(%d+)")
AlltheGold_revision.toc = _G.C_AddOns.GetAddOnMetadata(ATG_display_name, "Version"):match("%$Revision:%s(%d+)")
-- Backward and forward compatilility when playing Cataclysm
local GetHonorCurrency = _G.GetHonorCurrency or function() return select(2,C_CurrencyInfo.GetCurrencyInfo(392)) or 0 end
local GetConquestCurrency = _G.GetConquestCurrency or function() return ( C_CurrencyInfo.GetCurrencyInfo and select(2,C_CurrencyInfo.GetCurrencyInfo(390)) ) or 0 end
local GetJusticeCurrency = _G.GetJusticeCurrency or function() return ( C_CurrencyInfo.GetCurrencyInfo and select(2,C_CurrencyInfo.GetCurrencyInfo(395)) ) or 0 end
local GetValorCurrency = _G.GetValorCurrency or function() return ( C_CurrencyInfo.GetCurrencyInfo and select(2,C_CurrencyInfo.GetCurrencyInfo(396)) ) or 0 end
-- Define static values for the addon
-- Ten days in second, needed to estimate the rested XP
local TEN_DAYS = 60 * 60 * 24 * 10
-- Prototypes for local functions
--local AlltheGold.GetClassHexColour -- AlltheGold.GetClassHexColour(class)
-- Load external libraries
-- L is for localisation (to allow translation of the addon)
local L = LibStub("AceLocale-3.0"):GetLocale("AlltheGold")
-- A is for time and money formating functions
local A = LibStub("LibAbacus-3.0")
-- C is for colour management functions
local C = LibStub("LibCrayon-3.0")
-- LibDataBroker
local ldb = LibStub:GetLibrary("LibDataBroker-1.1", true)
-- LibDBIcon
local ldbicon = LibStub("LibDBIcon-1.0")
-- LibQTip
local lqt = LibStub("LibQTip-1.0")
-- Class colours
local CLASS_COLOURS = {}
-- Local cache
local XPToNextLevelCache = {}
-- Creation fo the main "object" with librairies (mixins) directly attach to the object (use self:functions)
local AlltheGold = LibStub("AceAddon-3.0"):NewAddon("AlltheGold", "AceEvent-3.0", "AceHook-3.0", "AceTimer-3.0")
_G[ATG_display_name] = AlltheGold
-- Print function
local myfullname = _G.C_AddOns.GetAddOnMetadata(ATG_display_name, "Title")
local default_channel = nil
local function setDefaultChanelForPrint()
default_channel = nil
for i=1, _G.NUM_CHAT_WINDOWS do
local name, _, _, _, _, shown = _G.GetChatWindowInfo(i)
if not default_channel and name and shown and (name:lower() == ATG_display_name:lower() or name:lower() == myfullname:lower()) then
default_channel = i
end
end
if not default_channel then
for i=1, _G.NUM_CHAT_WINDOWS do
local name, _, _, _, _, shown = _G.GetChatWindowInfo(i)
if not default_channel and name and shown and name:lower() == 'output' then
default_channel = i
end
end
end
end
function AlltheGold:Print(message, ...)
if default_channel then
_G["ChatFrame"..default_channel]:AddMessage(("|cff00dbba"..ATG_display_name.."|r: "..message):format(...));
else
_G.SELECTED_CHAT_FRAME:AddMessage(("|cff00dbba"..ATG_display_name.."|r: "..message):format(...))
end
end
-- For debuging
--AlltheGold.ATG = ATG
AlltheGold.debugging = false
function AlltheGold:Debug(msg,...)
if not self.debugging then return end
geterrorhandler()(msg:format(...))
end
function AlltheGold:Trace(msg,...)
geterrorhandler()(("%.2f: %s"):format(gettime(), msg,...))
end
-- Local objects
local AlltheGoldLDB
-- Local function prototypes
local AcquireTable
local ReleaseTable
local ClearTable
local FormatXP
local FormatMoney
local FormatJustice
local FormatValor
local FormatHonor
--local FormatPVECurrency
local FactionColour
local PercentColour
local ClassColour
local FormatCharacterName
local buildSortedTable
local PCSortByLevel
local PCSortByRevLevel
local PCSortByXP
local PCSortByRevXP
local PCSortByRestedXP
local PCSortByRevRestedXP
local PCSortByPercentRest
local PCSortByRevPercentRest
local PCSortByCoin
local PCSortByRevCoin
local PCSortByRevTimePlayed
local PCSortByTimePlayed
local PCSortByiLevel
local PCSortByReviLevel
local XPToLevel
local InitXPToLevelCache
local XPToNextLevel
local MXP
--[[ ================================================================= ]]--
--[[ Util Functions ]]--
--[[ ================================================================= ]]--
do
local table_cache = {}
-- Returns a table
function AcquireTable()
local tbl = tremove(table_cache) or {}
return tbl
end
-- Cleans the table and stores it in the cache
function ReleaseTable(tbl)
if not tbl then return end
-- Nested tables ?
for i=1,#tbl do
if type(tbl[i]) == "table" then ReleaseTable(tbl[i]) end
end
wipe(tbl)
tinsert(table_cache, tbl)
end
-- Release and Acquire in one go
function ClearTable(tbl)
ReleaseTable(tbl)
return AcquireTable()
end
end -- do block
--[[ ================================================================= ]]--
--[[ Ace Framework Init ]]--
--[[ ================================================================= ]]--
-- Default values for the save variables
local default_options = {
global = {
data = {
-- Faction
['*'] = {
-- Realm
['*'] = {
-- Name
['*'] = {
class = "", -- English class name
class_loc = "", -- Localized class name
race = "", -- English race name
race_loc = "", -- Localized race name
guild = "", -- Guild name
level = 0,
coin = 0,
rested_xp = 0,
xp = -1,
max_rested_xp = 0,
last_update = 0,
is_resting = false,
seconds_played = 0,
seconds_played_last_update = 0,
zone_text = L["Unknown"],
subzone_text = "",
valor_points = 0,
period_valor_points = 0,
max_period_valor_points = 0,
justice_points = 0,
arena_points = 0,
honor_points = 0,
conquest_points = 0,
highest_rank = nil,
honor_kills = 0,
}
}
}
},
cache = {
XPToNextLevel = {
-- Build version
['*'] = {}
}
},
options = {
show_deprecated = false,
},
},
profile = {
options = {
all_factions = true,
all_realms = true,
show_coins = true,
show_played_time = true,
show_last_login = false,
show_seconds = false,
show_progress = true,
show_rested_xp = false,
percent_rest = "100",
show_rested_xp_countdown = true,
refresh_rate = 20,
show_class_name = true,
colorize_class = true,
use_pre_210_shaman_colour = false,
show_ilevel = false,
show_location = "none",
show_guild = false,
show_xp_total = true,
show_lvl_totals = false,
tooltip_scale = 1,
opacity = .9,
tooltip_delay = 0.2,
tooltip_keep_on_mouseover = true,
sort_type = "alpha",
use_icons = false,
is_ignored = {
-- Realm
['*'] = {
-- Name
['*'] = false,
},
},
ldbicon = {
hide = nil,
},
-- Deprecated values that will be removed
show_valor_points = false,
show_valor_total = false,
show_justice_points = false,
show_justice_total = false,
show_arena_points = false,
show_conquest_points = false,
show_honor_points = false,
show_honor_kills = false,
show_pvp_totals = false,
},
},
}
-- This function is called by the Ace2 framework one time after the addon is loaded
function AlltheGold:OnInitialize()
-- code here, executed only once.
--self:SetDebugging(true) -- to have debugging through your whole app.
-- Initialize the SaveVariables table if it's the first time that AlltheGold is loaded
_G.AlltheGoldDB = _G.AlltheGoldDB or {}
local AlltheGoldDB = _G.AlltheGoldDB
-- Register the command line
-- /ATG and /AlltheGold will open the blizard interface panel
-- _G.SLASH_AlltheGold_CONFIG1 = L["/ATG"]
-- _G.SLASH_AlltheGold_CONFIG2 = L["/allthegold"]
_G.SlashCmdList["AlltheGold_CONFIG"] = function()
_G.InterfaceOptionsFrame_OpenToCategory(ATG_display_name)
end
-- Conversion of old data
AlltheGoldDB.global = AlltheGoldDB.global or {}
if AlltheGoldDB.global.data_version ~= "30300-2" and AlltheGoldDB.account then
local function tcopy(t)
local t2 = AcquireTable()
for k,v in pairs(t) do
if type(v) == 'table' then
t2[k] = tcopy(v)
else
t2[k] = v
end
end
return t2
end
AlltheGoldDB.global = tcopy(AlltheGoldDB.account)
AlltheGoldDB.profiles = nil
AlltheGoldDB.currentProfile = nil
AlltheGoldDB.global.data_version = "30300-2"
end
-- Register the varibles with the defaults
self.db = LibStub("AceDB-3.0"):New("AlltheGoldDB", default_options, true)
self.db.RegisterCallback(self, "OnProfileChanged", "RefreshConfig")
self.db.RegisterCallback(self, "OnProfileCopied", "RefreshConfig")
self.db.RegisterCallback(self, "OnProfileReset", "RefreshConfig")
-- Initial setup is done by OnEnable (not mush to do here)
-- We set total variables to zero and create the tables that will never
-- be deleted
self.total_faction = { ["Horde"] = { time_played = 0, coin = 0 },
["Alliance"] = { time_played = 0, coin = 0 },
["Neutral"] = { time_played = 0, coin = 0 },
}
self.total_realm = { }
self.total = { time_played = 0, coin = 0, xp = 0 }
self.sort_tables_done = false
-- Find the max level
-- self.max_pc_level = _G.MAX_PLAYER_LEVEL_TABLE[min(_G.GetExpansionLevel(),_G.GetAccountExpansionLevel())]
self.max_pc_level = GetMaxLevelForLatestExpansion()
-- Initialize the cache
InitXPToLevelCache()
end
function AlltheGold:OnEnable()
--self:Debug("AlltheGold:OnEnable()")
-- code here, executed after everything is loaded.
-- Find the default channel
setDefaultChanelForPrint()
-- Configuration initialization
ATG.db = self.db
ATG.InitConfig()
-- Register the events we need
-- (event unregistering is done automagicaly by ACE)
self:RegisterEvent("TIME_PLAYED_MSG", "OnTimePlayedMsg")
self:RegisterEvent("PLAYER_LEVEL_UP", "EventHandlerWithSort")
self:RegisterEvent("PLAYER_XP_UPDATE", "EventHandlerWithSort")
self:RegisterEvent("ZONE_CHANGED_NEW_AREA", "EventHandler")
self:RegisterEvent("ZONE_CHANGED", "EventHandler")
--self:RegisterEvent("MINIMAP_ZONE_CHANGED", "EventHandler")
self:RegisterEvent("PLAYER_MONEY", "EventHandler")
self:RegisterEvent("CURRENCY_DISPLAY_UPDATE", "EventHandler")
self:RegisterEvent("PLAYER_GUILD_UPDATE", "EventHandler")
self:RegisterEvent("PLAYER_UPDATE_RESTING", "EventHandler")
self:RegisterEvent("CHAT_MSG_COMBAT_HONOR_GAIN", "EventHandlerHonorGain")
self:RegisterEvent("BAG_UPDATE", "EventHandlerOnlySort")
-- Hook the functions that need hooking
--self:Hook("Logout", true)
self:RegisterEvent("PLAYER_LOGOUT", "Logout")
--self:Hook("Quit", true)
self:RegisterEvent("PLAYER_QUITING", "Quit")
-- Initialize values that don't change between reloads
self.faction, self.loc_faction = _G.UnitFactionGroup("player")
self.realm = _G.GetRealmName()
self.pc = _G.UnitName("player")
-- Initial update of values
-- Class colours
for classname in pairs(_G.RAID_CLASS_COLORS) do
CLASS_COLOURS[classname] = AlltheGold.GetClassHexColour(classname)
end
CLASS_COLOURS['PRE-210-SHAMAN'] = "00dbba"
-- What colour should be used for Shaman?
if(self:GetOption('use_pre_210_shaman_colour')) then
CLASS_COLOURS['SHAMAN'] = CLASS_COLOURS['PRE-210-SHAMAN']
end
-- Get the values for the current character
self:SaveVar()
-- Detect faction change
self:DetectFactionChange()
-- Compute Honor at least once (it will be computed only if it change afterward
self:ComputeTotalHonor()
-- Build the sorting tables
self:BuildSortTables()
-- Request the time played so we can populate seconds_played
--self:RequestTimePlayed()
-- Wait 10 seconds so that the call is not made if another addon already do it
-- at load time
self:ScheduleTimer("RequestTimePlayed", 10)
-- Set the callback for !ClassColor if present
if _G.CUSTOM_CLASS_COLORS then
_G.CUSTOM_CLASS_COLORS:RegisterCallback(function()
for class in pairs(_G.CUSTOM_CLASS_COLORS) do
CLASS_COLOURS[class] = AlltheGold.GetClassHexColour(class)
end
-- Check again for the Shamy colour
if(AlltheGold:GetOption('use_pre_210_shaman_colour')) then
CLASS_COLOURS['SHAMAN'] = CLASS_COLOURS['PRE-210-SHAMAN']
else
CLASS_COLOURS['SHAMAN'] = AlltheGold.GetClassHexColour("SHAMAN")
end
end)
end
-- Start the timer event to get an OnDataUpdate, OnUpdateText and OnUpdateTooltip every second
-- or 20 seconds depending on the refresh_rate setting
--self:ScheduleRepeatingEvent(self.name, self.MyUpdate, self:GetOption('refresh_rate'), self)
self.timer = self:ScheduleRepeatingTimer("MyUpdate", self:GetOption('refresh_rate'))
-- Create a frame with an OnUpdate event to deal with the disposal of the tooltip created for LDB
self.OnUpdate_frame = _G.CreateFrame("frame")
self.OnUpdate_frame:Hide() -- to prevent the OnUpdate until it is needed.
self.elapsed = 0
self.OnUpdate_frame:SetScript("OnUpdate", function(self, elap)
AlltheGold.elapsed = AlltheGold.elapsed + elap
if AlltheGold.elapsed < AlltheGold:GetOption('tooltip_delay') then return end
if (AlltheGold.tooltip and AlltheGold.tooltip:IsMouseOver() and AlltheGold:GetOption('tooltip_keep_on_mouseover')) or
(AlltheGold.tooltip_anchor and AlltheGold.tooltip_anchor:IsMouseOver()) then
AlltheGold.elapsed = 0
return
end
AlltheGold.tooltip = lqt:Release(AlltheGold.tooltip)
AlltheGold.tooltip_anchor = nil
AlltheGold.OnUpdate_frame:Hide()
end)
-- LDB Minimap Icon support (for users without a LDB Broker)
ldbicon:Register("AlltheGold", AlltheGoldLDB, self.db.profile.options.ldbicon)
self:MyUpdate()
end
function AlltheGold:OnDisable()
self:CancelScheduledEvent(self.name)
-- Detect faction change
self:DetectFactionChange()
end
function AlltheGold:IsDebugging() return self.db.profile.debugging end
function AlltheGold:SetDebugging(debugging) self.db.profile.debugging = debugging; self.debugging = debugging; end
--[[ ================================================================= ]]--
--[[ Update Functions ]]--
--[[ ================================================================= ]]--
function AlltheGold:MyUpdate(...)
self:Debug("MyUpdate: %d",time())
self:OnDataUpdate()
AlltheGoldLDB.text = self:FormatTime(self.total.time_played)
if self.tooltip then
self:DrawTooltip()
end
end
function AlltheGold:OnDataUpdate()
--self:Debug("AlltheGold:OnDataUpdate()")
-- Update the data that may have changed but are not tracked by an event
self.db.global.data[self.faction][self.realm][self.pc].is_resting = _G.IsResting()
-- Recompute the totals
self:ComputeTotal()
end
function AlltheGold:RefreshConfig()
-- Reapply all the settings that change behavior
self:SetOption('show_seconds',self:GetOption('show_seconds'))
self:SetOption('show_coins',self:GetOption('show_coins'))
self:SetOption('use_pre_210_shaman_colour',self:GetOption('use_pre_210_shaman_colour'))
self:SetOption('tooltip_scale',self:GetOption('tooltip_scale'))
self:SetOption('opacity',self:GetOption('opacity'))
self:SetOption('show_minimap_icon',self:GetOption('show_minimap_icon'))
-- Recompute all the totals
self:ComputeTotal()
self:ComputeTotalHonor()
end
--[[ ================================================================= ]]--
--[[ Functions specific to the addon ]]--
--[[ ================================================================= ]]--
-- Get the totals per faction and realm
function AlltheGold:ComputeTotal()
self:Debug("AlltheGold:ComputeTotal(): %d",time())
-- Let's start from scratch
self.total_faction["Horde"].time_played = 0
self.total_faction["Horde"].coin = 0
self.total_faction["Horde"].xp = 0
self.total_faction["Horde"].justice_points = 0
self.total_faction["Horde"].valor_points = 0
self.total_faction["Horde"].levels = 0
self.total_faction["Alliance"].time_played = 0
self.total_faction["Alliance"].coin = 0
self.total_faction["Alliance"].xp = 0
self.total_faction["Alliance"].justice_points = 0
self.total_faction["Alliance"].valor_points = 0
self.total_faction["Alliance"].levels = 0
self.total_faction["Neutral"].time_played = 0
self.total_faction["Neutral"].coin = 0
self.total_faction["Neutral"].xp = 0
self.total_faction["Neutral"].justice_points = 0
self.total_faction["Neutral"].valor_points = 0
self.total_faction["Neutral"].levels = 0
self.total.time_played = 0
self.total.coin = 0
self.total.xp = 0
self.total.justice_points = 0
self.total.valor_points = 0
self.total.levels = 0
-- Let all the factions, realms and PC be counted
for faction, faction_table in pairs(self.db.global.data) do
for realm, realm_table in pairs(faction_table) do
--self:Debug("faction: %s realm: %s", faction, realm)
if not self.total_realm[faction] then self.total_realm[faction] = {} end
if not self.total_realm[faction][realm] then self.total_realm[faction][realm] = {} end
self.total_realm[faction][realm].time_played = 0
self.total_realm[faction][realm].coin = 0
self.total_realm[faction][realm].xp = 0
self.total_realm[faction][realm].justice_points = 0
self.total_realm[faction][realm].valor_points = 0
self.total_realm[faction][realm].levels = 0
for pc, pc_table in pairs(realm_table) do
if not self:GetOption('is_ignored', realm, pc) then
-- Need to get the current seconds_played for the PC
local seconds_played = self:EstimateTimePlayed(pc,
realm,
pc_table.seconds_played,
pc_table.seconds_played_last_update
)
local pc_xp = pc_table.xp
if (pc_xp ==-1) then pc_xp = 0 end
if (pc_table.level == self.max_pc_level) then pc_xp = 0 end
pc_xp = pc_xp + XPToLevel(pc_table.level)
self.total_faction[faction].time_played = self.total_faction[faction].time_played + seconds_played
self.total_faction[faction].coin = self.total_faction[faction].coin + pc_table.coin
self.total_faction[faction].xp = self.total_faction[faction].xp + pc_xp
self.total_faction[faction].justice_points = self.total_faction[faction].justice_points + pc_table.justice_points
self.total_faction[faction].valor_points = self.total_faction[faction].valor_points + pc_table.valor_points
self.total_faction[faction].levels = self.total_faction[faction].levels + pc_table.level
self.total_realm[faction][realm].time_played = self.total_realm[faction][realm].time_played + seconds_played
self.total_realm[faction][realm].coin = self.total_realm[faction][realm].coin + pc_table.coin
self.total_realm[faction][realm].xp = self.total_realm[faction][realm].xp + pc_xp
self.total_realm[faction][realm].justice_points = self.total_realm[faction][realm].justice_points + pc_table.justice_points
self.total_realm[faction][realm].valor_points = self.total_realm[faction][realm].valor_points + pc_table.valor_points
self.total_realm[faction][realm].levels = self.total_realm[faction][realm].levels + pc_table.level
end
end
end
end
-- The Grand Total varies according to the options
if self:GetOption('all_realms') then
if self:GetOption('all_factions') then
-- Everything count
self.total.time_played
= self.total_faction["Horde"].time_played
+ self.total_faction["Alliance"].time_played
+ self.total_faction["Neutral"].time_played
self.total.coin
= self.total_faction["Horde"].coin
+ self.total_faction["Alliance"].coin
+ self.total_faction["Neutral"].coin
self.total.xp
= self.total_faction["Horde"].xp
+ self.total_faction["Alliance"].xp
+ self.total_faction["Neutral"].xp
self.total.justice_points
= self.total_faction["Horde"].justice_points
+ self.total_faction["Alliance"].justice_points
+ self.total_faction["Neutral"].justice_points
self.total.valor_points
= self.total_faction["Horde"].valor_points
+ self.total_faction["Alliance"].valor_points
+ self.total_faction["Neutral"].valor_points
self.total.levels
= self.total_faction["Horde"].levels
+ self.total_faction["Alliance"].levels
+ self.total_faction["Neutral"].levels
else
-- Only the current faction count
self.total.time_played = self.total_faction[self.faction].time_played
self.total.coin = self.total_faction[self.faction].coin
self.total.xp = self.total_faction[self.faction].xp
self.total.justice_points = self.total_faction[self.faction].justice_points
self.total.valor_points = self.total_faction[self.faction].valor_points
self.total.levels = self.total_faction[self.faction].levels
end
else
-- Only the current realm count (all_factions is ignore)
self.total.time_played = self.total_realm[self.faction][self.realm].time_played
self.total.coin = self.total_realm[self.faction][self.realm].coin
self.total.xp = self.total_realm[self.faction][self.realm].xp
self.total.justice_points = self.total_realm[self.faction][self.realm].justice_points
self.total.valor_points = self.total_realm[self.faction][self.realm].valor_points
self.total.levels = self.total_realm[self.faction][self.realm].levels
end
end
function AlltheGold:ComputeTotalHonor()
--self:Debug("AlltheGold:ComputeTotalHonor()")
self.total_faction["Horde"].honor_kills = 0
self.total_faction["Horde"].honor_points = 0
self.total_faction["Horde"].arena_points = 0
self.total_faction["Horde"].conquest_points = 0
self.total_faction["Alliance"].honor_kills = 0
self.total_faction["Alliance"].honor_points = 0
self.total_faction["Alliance"].arena_points = 0
self.total_faction["Alliance"].conquest_points = 0
self.total_faction["Neutral"].honor_kills = 0
self.total_faction["Neutral"].honor_points = 0
self.total_faction["Neutral"].arena_points = 0
self.total_faction["Neutral"].conquest_points = 0
self.total.honor_kills = 0
self.total.honor_points = 0
self.total.arena_points = 0
self.total.conquest_points = 0
-- Let all the factions, realms and PC be counted
for faction, faction_table in pairs(self.db.global.data) do
for realm, realm_table in pairs(faction_table) do
--self:Debug("faction: %s realm: %s", faction, realm)
if not self.total_realm[faction] then self.total_realm[faction] = {} end
if not self.total_realm[faction][realm] then self.total_realm[faction][realm] = {} end
self.total_realm[faction][realm].honor_kills = 0
self.total_realm[faction][realm].honor_points = 0
self.total_realm[faction][realm].arena_points = 0
self.total_realm[faction][realm].conquest_points = 0
for pc, pc_table in pairs(realm_table) do
if not self:GetOption('is_ignored', realm, pc) then
self.total_faction[faction].honor_kills = self.total_faction[faction].honor_kills + (pc_table.honor_kills or 0)
self.total_faction[faction].honor_points = self.total_faction[faction].honor_points + (pc_table.honor_points or 0)
self.total_faction[faction].arena_points = self.total_faction[faction].arena_points + (pc_table.arena_points or 0)
self.total_faction[faction].conquest_points = self.total_faction[faction].conquest_points + (pc_table.conquest_points or 0)
self.total_realm[faction][realm].honor_kills = self.total_realm[faction][realm].honor_kills + (pc_table.honor_kills or 0)
self.total_realm[faction][realm].honor_points = self.total_realm[faction][realm].honor_points + (pc_table.honor_points or 0)
self.total_realm[faction][realm].arena_points = self.total_realm[faction][realm].arena_points + (pc_table.arena_points or 0)
self.total_realm[faction][realm].conquest_points = self.total_realm[faction][realm].conquest_points + (pc_table.conquest_points or 0)
end
end
end
end
-- The Grand Total varies according to the options
if self:GetOption('all_realms') then
if self:GetOption('all_factions') then
-- Everything count
self.total.honor_kills
= self.total_faction["Horde"].honor_kills
+ self.total_faction["Alliance"].honor_kills
+ self.total_faction["Neutral"].honor_kills
self.total.honor_points
= self.total_faction["Horde"].honor_points
+ self.total_faction["Alliance"].honor_points
+ self.total_faction["Neutral"].honor_points
self.total.arena_points
= self.total_faction["Horde"].arena_points
+ self.total_faction["Alliance"].arena_points
+ self.total_faction["Neutral"].arena_points
self.total.conquest_points
= self.total_faction["Horde"].conquest_points
+ self.total_faction["Alliance"].conquest_points
+ self.total_faction["Neutral"].conquest_points
else
-- Only the current faction count
self.total.honor_kills = self.total_faction[self.faction].honor_kills
self.total.honor_points = self.total_faction[self.faction].honor_points
self.total.arena_points = self.total_faction[self.faction].arena_points
self.total.conquest_points = self.total_faction[self.faction].conquest_points
end
else
-- Only the current realm count (all_factions is ignore)
self.total.honor_kills = self.total_realm[self.faction][self.realm].honor_kills
self.total.honor_points = self.total_realm[self.faction][self.realm].honor_points
self.total.arena_points = self.total_realm[self.faction][self.realm].arena_points
self.total.conquest_points = self.total_realm[self.faction][self.realm].conquest_points
end
end
-- Utility function to set the tooltip alpha
function AlltheGold:SetTTOpacity(opacity)
if not self.tooltip then return end
--for i=1,self.tooltip:GetColumnCount() do
-- self.tooltip:SetColumnColor(i,0,0,0,opacity)
--end
self.tooltip:SetBackdropColor(0,0,0,opacity)
end
-- Fill the QTip witl the information
local col_text = {} -- reuse the table that is used over and over when drawing.
local col_align = {}
local pvp_columns = { 'show_arena_points', 'show_honor_points', 'show_honor_kills', 'show_conquest_points' }
function AlltheGold:DrawTooltip(anchor)
-- Keep the anchor for further use
self.tooltip_anchor = anchor or self.tooltip_anchor
-- Update the sort tables
self:BuildSortTables()
local first_category = true
local nb_columns = 1
-- Is the Location column needed?
if self:GetOption('show_location') ~= "none" then
nb_columns = nb_columns + 1
end
-- Is the Guild column needed?
if self:GetOption('show_guild') then
nb_columns = nb_columns + 1
end
-- Do we have PvP columns?
local need_pvp = false
for _,column in ipairs(pvp_columns) do
if self:GetOption(column) then
need_pvp = true
nb_columns = nb_columns + 1
end
end
-- Do we need to display the item level
local need_ilevel = self:GetOption('show_ilevel')
if need_ilevel then nb_columns = nb_columns + 1 end
-- Do we need to display the last login
local need_last_login = self:GetOption('show_last_login')
if need_last_login then nb_columns = nb_columns + 1 end
-- De we need to display the Valor Points
local need_vp = self:GetOption('show_valor_points')
if need_vp then nb_columns = nb_columns + 1 end
-- De we need to display the Justice Points
local need_jp = self:GetOption('show_justice_points')
if need_jp then nb_columns = nb_columns + 1 end
-- Is the gold/rested XP column needed?
if self:GetOption('show_coins')
or self:GetOption('show_rested_xp')
or self:GetOption('show_rested_xp_countdown')
or self:GetOption('percent_rest') ~= "0"
then
nb_columns = nb_columns + 1
end
if not self.tooltip then
self.tooltip = lqt:Acquire("AlltheGoldTooltip", nb_columns)
end
local tooltip = self.tooltip
-- Set the scale
tooltip:SetScale(self:GetOption('tooltip_scale'))
tooltip:Clear()
tooltip:SmartAnchorTo(self.tooltip_anchor)
local line, column = tooltip:AddHeader()
tooltip:SetCell(line, 1, C:White(L["AlltheGold"]), "CENTER", nb_columns)
tooltip:AddSeparator()
-- We group by factions, then by realm, then by PC
for _, faction in ipairs (self.sort_faction) do
-- We do not print the faction if no option to select it is on
-- and if the time played for the faction = 0 since this means
-- all PC in the faction are ingored.
if ((self:GetOption('all_factions') or self.faction == faction)
and self.total.time_played ~= 0
and self.sort_faction_realm[self:GetOption('display_sort_type')][faction]
) then
for _, realm in ipairs(self.sort_faction_realm[self:GetOption('display_sort_type')][faction]) do
-- We do not print the realm if no option to select it is on
-- and if the time played for the realm = 0 since this means
-- all PC in the realm are ingored.
if ( (self:GetOption('all_realms') or self.realm == realm) and
self.total_realm[faction][realm].time_played ~= 0 ) then
----self:Debug("self.total_realm[faction][realm].time_played: ",self.total_realm[faction][realm].time_played)
-- Build the Realm aggregated line
local text_realm = C:Gold(L["%s %s "]):format(realm, faction)
local text_realm_optional = ""
local first_option = true
if self:GetOption('show_played_time') then
text_realm_optional = self:FormatTime(self.total_realm[faction][realm].time_played)
first_option = false
end
if self:GetOption('show_coins') then
if first_option then
text_realm_optional = FormatMoney(self.total_realm[faction][realm].coin)
first_option = false
else
text_realm_optional = ("%s " .. C:Green(" : ") .. "%s"):format(
text_realm_optional,
FormatMoney(self.total_realm[faction][realm].coin)
)
end
end
if self:GetOption('show_xp_total') then
if first_option then
text_realm_optional = FormatXP(self.total_realm[faction][realm].xp)
first_option = false
else
text_realm_optional = ("%s " .. C:Green(" : %s")):format(
text_realm_optional,
FormatXP(self.total_realm[faction][realm].xp)
)
end
end
if self:GetOption('show_lvl_totals') then
if first_option then
text_realm_optional = C:White((L["Lvls: %d"]):format(self.total_realm[faction][realm].levels))
first_option = false
else
text_realm_optional = ("%s " .. C:Green(" : %s")):format(
text_realm_optional,
C:White((L["Lvl: %d"]):format(self.total_realm[faction][realm].levels))
)
end
end
if text_realm_optional ~= "" then
text_realm = text_realm .. C:Green("[") .. text_realm_optional .. C:Green("]")
end
--tooltip:AddSeparator()
if first_category then
first_category = false
else
-- line, column = tooltip:AddLine()
-- tooltip:SetCell(line, 1, " ")
end
--tooltip:AddSeparator()
line, column = tooltip:AddLine()
tooltip:SetCell(line, 1, text_realm, "LEFT", nb_columns)
for i, pc in ipairs(self.sort_realm_pc[self:GetOption('display_sort_type')][faction][realm]) do
if not self:GetOption('is_ignored', realm, pc) then
local pc_data = self.db.global.data[faction][realm][pc]
wipe(col_text)
wipe(col_align)
local col_no = 1
-- Seconds played are still going up for the current PC
local seconds_played = self:EstimateTimePlayed(
pc,
realm,
pc_data.seconds_played,
pc_data.seconds_played_last_update
)
if type(pc_data.last_update) ~= "number" then
err("realm = %s, pc = %s, pc_data.last_update = %s", realm, pc, pc_data.last_update)
end
col_text[col_no] = FormatCharacterName(
pc,
pc_data.level,
pc_data.xp,
seconds_played,
pc_data.class,
pc_data.class_loc,
faction,
pc_data.last_update
)
col_align[col_no] = 'LEFT'
col_no = col_no + 1
col_text[col_no] = ''
--local text_location = ""
if self:GetOption('show_location') ~= "none" then
if self:GetOption('show_location') == "loc" or
pc_data.zone_text == L["Unknown"] or
(self:GetOption('show_location') == "loc/sub" and
pc_data.subzone_text == "") then
col_text[col_no] = FactionColour(
faction,
pc_data.zone_text
)
elseif self:GetOption('show_location') == "sub" then
col_text[col_no] = FactionColour(
faction,
pc_data.subzone_text
)
else
col_text[col_no] = FactionColour(
faction,
pc_data.zone_text
.. '/' .. pc_data.subzone_text
)
end
col_align[col_no] = 'CENTER'
col_no = col_no + 1
col_text[col_no] = ''
end
if self:GetOption('show_guild') then
col_text[col_no] = FactionColour(faction, pc_data.guild)
col_align[col_no] = 'CENTER'
col_no = col_no + 1
col_text[col_no] = ''
end
if need_ilevel then
col_text[col_no] = pc_data.ilevel and (L["%.2f iLvl"]):format(pc_data.ilevel) or ""
col_align[col_no] = 'CENTER'
col_no = col_no + 1
col_text[col_no] = ''
end