-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
core.lua
831 lines (735 loc) · 27 KB
/
core.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
local ADDON_NAME = ...;
local Addon = LibStub("AceAddon-3.0"):NewAddon(select(2, ...), ADDON_NAME, "AceConsole-3.0", "AceEvent-3.0");
local L = LibStub("AceLocale-3.0"):GetLocale(ADDON_NAME);
local AceGUI = LibStub("AceGUI-3.0")
local private = {
atBank = false,
atGuildBank = false,
atAccountBank = false,
ignoreSet = {},
allowedSet = {},
useAllowSet = false,
}
local isRetail = WOW_PROJECT_ID == (WOW_PROJECT_MAINLINE or 1)
local isClassic = WOW_PROJECT_ID == (WOW_PROJECT_CLASSIC or 2)
local isBCC = WOW_PROJECT_ID == (WOW_PROJECT_BURNING_CRUSADE_CLASSIC or 5)
local isWrath = WOW_PROJECT_ID == (WOW_PROJECT_WRATH_CLASSIC or 11)
local currentCharacter = UnitName("player")
local currentRealm = GetRealmName()
local FIRST_PERSONAL_BAG_SLOT = Enum.BagIndex.Backpack or BACKPACK_CONTAINER
local LAST_PERSONAL_BAG_SLOT = Enum.BagIndex.Bag_4 or NUM_BAG_SLOTS
local FIRST_BANK_SLOT = BANK_CONTAINER
local LAST_BANK_SLOT = BANK_CONTAINER + NUM_BANKBAGSLOTS
local GUILD_BANK_TAB_SLOTS = 98 -- MAX_GUILDBANK_SLOTS_PER_TAB
local FIRST_WARBAND_BANK_SLOT = Enum.BagIndex.AccountBankTab_1 or 13
local LAST_WARBAND_BANK_SLOT = FIRST_WARBAND_BANK_SLOT + (Constants.InventoryConstants.NumAccountBankSlots or 0) - 1
local getContainerNumSlots = GetContainerNumSlots or C_Container.GetContainerNumSlots
local getContainerItemLink = GetContainerItemLink or C_Container.GetContainerItemLink
local getContainerItemInfo = function(bag, slot)
if GetContainerItemInfo then
local _, count, _, itemQuality = GetContainerItemInfo(bag, slot);
return count or 0, itemQuality or 0
end
local itemInfo = C_Container.GetContainerItemInfo(bag, slot)
return itemInfo.stackCount or 0, itemInfo.quality or 0
end
local AddonDB_Defaults = {
global = {
Characters = {
['*'] = { -- ["Realm.Name"]
},
},
},
profile = {
newFeatures = {},
minimapIcon = { hide = false, minimapPos = 220, radius = 80, },
pricesource = {
source = "DBMarket"
},
ldbsource = "combinedtotal",
topContributors = {
enabled = true,
limit = 5,
},
guildBank = {
enabled = false,
},
accountBank = {
enabled = false,
},
qualityFilter = {
value = "1",
enabled = true,
},
itemFilter = {
items = {},
enabled = false,
},
itemAllow = {
items = {},
enabled = false,
},
moneyPrecision = {
ldb = 0,
tooltip = 0,
},
bagFilter = {
selectedBags = "all",
},
},
}
function Addon:OnInitialize()
Addon.Debug.Log("Addon - Init")
Addon.db = LibStub("AceDB-3.0"):New(ADDON_NAME .. "DB", AddonDB_Defaults, true) -- set true to prefer 'Default' profile as default
Addon.db.RegisterCallback(Addon, "OnProfileChanged", "UpdateData")
Addon.db.RegisterCallback(Addon, "OnProfileCopied", "UpdateData")
Addon.db.RegisterCallback(Addon, "OnProfileReset", "UpdateData")
Addon:InitializeDataBroker();
Addon.Debug.Log("Addon - Complete")
if isRetail then
AddonCompartmentFrame:RegisterAddon({
text = ADDON_NAME,
icon = [[Interface\Icons\Inv_Ingot_03]],
func = function(btn, arg1, arg2, checked, mouseButton)
if mouseButton == "LeftButton" then
Settings.OpenToCategory(Addon.CONST.METADATA.NAME)
Settings.OpenToCategory(Addon.CONST.METADATA.NAME)
end
end,
funcOnEnter = function()
local tooltip = AceGUI.tooltip
tooltip:SetOwner(AddonCompartmentFrame, "ANCHOR_BOTTOM")
Addon.DisplayToolTip(tooltip)
tooltip:Show()
end,
funcOnLeave = function()
AceGUI.tooltip:Hide()
end,
notCheckable = true,
})
end
end
function Addon:OnEnable()
private.PreparePriceSources();
Addon:RegisterChatCommand("ba", private.chatCmdShowConfig)
if isClassic or isBCC then
Addon:RegisterEvent("BAG_UPDATE", private.OnBagUpdateDelayed)
end
if isWrath or isRetail then
Addon:RegisterEvent("BAG_UPDATE_DELAYED", private.OnBagUpdateDelayed)
end
if isRetail or isWrath then
Addon:RegisterEvent("PLAYER_INTERACTION_MANAGER_FRAME_SHOW", function(event, arg)
if arg == 8 then -- bank
private.OnBankFrameOpened()
end
if arg == 10 then -- gbank
private.OnGuildBankFrameOpened();
end
end)
Addon:RegisterEvent("PLAYER_INTERACTION_MANAGER_FRAME_HIDE", function(event, arg)
if arg == 8 then -- bank
private.OnBankFrameClosed();
end
if arg == 10 then -- gbank
private.OnGuildBankFrameClosed();
end
end)
end
if isClassic or isBCC then
Addon:RegisterEvent("BANKFRAME_OPENED", private.OnBankFrameOpened)
Addon:RegisterEvent("BANKFRAME_CLOSED", private.OnBankFrameClosed)
Addon:RegisterEvent("GUILDBANKFRAME_OPENED", private.OnGuildBankFrameOpened)
Addon:RegisterEvent("GUILDBANKFRAME_CLOSED", private.OnGuildBankFrameClosed)
end
Addon:Print(format(L["welcome_message"], Addon.CONST.METADATA.VERSION))
Addon.HandleWhatsNew()
end
function Addon.HandleWhatsNew()
-- Shown ignore list?
if not Addon.GetFromDb("newFeatures", "ignoreList") then
Addon:Print(L["feature_filter"])
Addon.db.profile.newFeatures.ignoreList = true;
Addon.db.profile.newFeatures.allowList = true;
elseif not Addon.GetFromDb("newFeatures", "allowList") then
-- Shown allow list?
Addon:Print(L["feature_allowlist"]);
Addon.db.profile.newFeatures.allowList = true;
end
-- Advertised classic?
if not Addon.GetFromDb("newFeatures", "classicSupport") then
if isRetail then
Addon:Print(L["feature_classic"]);
end
Addon.db.profile.newFeatures.classicSupport = true;
end
-- Advertised localizations?
if not Addon.GetFromDb("newFeatures", "localization") then
Addon:Print(L["feature_localization"]);
Addon.db.profile.newFeatures.localization = true;
end
-- Advertised additional price sources?
if not Addon.GetFromDb("newFeatures", "expandedPricingSources") then
Addon:Print(L["feature_pricing_sources"]);
Addon.db.profile.newFeatures.expandedPricingSources = true;
end
-- Advertised TWW and warband bank?
if not Addon.GetFromDb("newFeatures", "twwSupport") then
Addon:Print(L["feature_tww_support"]);
Addon.db.profile.newFeatures.twwSupport = true;
end
-- Advertised reagent bag only?
if not Addon.GetFromDb("newFeatures", "reagentBagOnly") then
Addon:Print(L["feature_reagent_bag_only"]);
Addon.db.profile.newFeatures.reagentBagOnly = true;
end
end
function Addon:UpdateData()
local buildTopContributors = Addon.GetFromDb("topContributors", "enabled")
local topContributorsLimit = Addon.GetFromDb("topContributors", "limit")
Addon.Debug.Log("UpdateData() started")
-- Do this once for performance reasons
private.ignoreSet = private.getIgnoredItemSet();
private.allowedSet = private.getAllowedItemSet();
private.useAllowSet = Addon.GetFromDb("itemAllow", "enabled");
-- Iterate personal bags
local bagTopContributors = {};
for k, v in pairs(private.GetPersonalBagIDs()) do
local bagValue = private.ValuateBag(k)
private.SaveValue("Bag", k, bagValue.value)
if buildTopContributors then
private.insertContributors(bagTopContributors, bagValue.items)
end
end
if buildTopContributors then
private.persistTopContributors("Bag", bagTopContributors, topContributorsLimit)
end
-- If at the bank, iterate those bags
if private.atBank then
local bankTopContributors = {};
for k, v in pairs(private.GetBankBagIDs()) do
local bagValue = private.ValuateBag(k)
private.SaveValue("Bag", k, bagValue.value)
private.SaveBankLastUpdated(time())
if buildTopContributors then
private.insertContributors(bankTopContributors, bagValue.items)
end
end
if buildTopContributors then
private.persistTopContributors("Bank", bankTopContributors, topContributorsLimit)
end
end
-- If at the gbank and option is enabled, iterate those bags
if private.atGuildBank and Addon.GetFromDb("guildBank", "enabled") then
local gbankTopContributors = {};
for tab = 1, GetNumGuildBankTabs() do
-- Addon.Debug.Log(format("GBANK: evaluate bag %d", tab));
local tabValue = private.ValuateGBankTab(tab)
private.SaveValue("GBankTab", tab, tabValue.value)
private.SaveGBankLastUpdated(time())
if buildTopContributors then
private.insertContributors(gbankTopContributors, tabValue.items)
end
end
if buildTopContributors then
private.persistTopContributors("GuildBank", gbankTopContributors, topContributorsLimit)
end
end
-- If at the account bank and option is enabled, iterate those bags
-- Note this is disabled for classic and if the bag filter is not set to 'all'
if isRetail and private.atAccountBank and Addon.GetFromDb("accountBank", "enabled") and Addon.GetFromDb("bagFilter", "selectedBags") == "all" then
local accountBankTopContributors = {};
for slot = FIRST_WARBAND_BANK_SLOT, LAST_WARBAND_BANK_SLOT do
local bagValue = private.ValuateBag(slot)
private.SaveValue("Bag", slot, bagValue.value)
private.SaveAccountBankLastUpdated(time())
if buildTopContributors then
private.insertContributors(accountBankTopContributors, bagValue.items)
end
end
if buildTopContributors then
private.persistTopContributors("AccountBank", accountBankTopContributors, topContributorsLimit)
end
end
local bankLastUpdated = private.GetBankLastUpdated();
if bankLastUpdated then
Addon:UpdateBankLastUpdatedText(date("%x %X", bankLastUpdated))
end
if isRetail then
local accountBankLastUpdated = private.GetAccountBankLastUpdated();
if accountBankLastUpdated then
Addon:UpdateAccountBankLastUpdatedText(date("%x %X", accountBankLastUpdated))
end
end
local gbankLastUpdated = private.GetGBankLastUpdated();
if gbankLastUpdated then
Addon:UpdateGBankLastUpdatedText(date("%x %X", gbankLastUpdated));
end
private.RecalculateTotals();
Addon.Debug.Log("UpdateData() complete")
end
function Addon.GetFromDb(grp, key, ...)
if not key then
return Addon.db.profile[grp]
end
return Addon.db.profile[grp][key]
end
function private.insertContributors(targetTbl, itemsTbl)
-- walk the items tbl
for itemLink, v in pairs(itemsTbl) do
-- Addon.Debug.Log(format(" insertContributors(): checking %s", itemLink))
-- is this item already in the table?
if targetTbl[itemLink] then
-- increment the existing count
-- Addon.Debug.Log(format(" insertContributors(): appending %dx %s", v.count, itemLink))
targetTbl[itemLink].count = targetTbl[itemLink].count + v.count
else
-- wasnt already in the table, append
-- Addon.Debug.Log(format(" insertContributors(): inserting %dx %s", v.count, itemLink))
targetTbl[itemLink] = v
end
end
end
function private.persistTopContributors(type, items, limit)
-- Convert to a standard integer-indexed array
local topContributors = private.convertContributorTableToArray(items);
-- Sort by value desc
table.sort(topContributors, function(a, b) return a.totalValue > b.totalValue end)
-- Take the top N results
topContributors = private.limitTopContributors(topContributors, limit);
-- Persist
private.SetTopContributors(type, topContributors);
end
function private.convertContributorTableToArray(contributorTbl)
local result = {};
local idx = 1;
for k, v in pairs(contributorTbl) do
result[idx] = v;
idx = idx + 1;
end
return result;
end
function private.limitTopContributors(targetTbl, limit)
-- empty array? return
local tableLen = table.getn(targetTbl)
if tableLen == 0 then
return {};
end
-- do we have less than 'limit' items? if so, just return what we have
if table.getn(targetTbl) <= limit then
return targetTbl;
end
-- limit to top 'limit' results and return
local result = {};
for i = 1, limit do
result[i] = targetTbl[i]
end
return result
end
function private.OnBagUpdateDelayed()
Addon:UpdateData();
end
function private.OnBankFrameOpened()
private.atBank = true;
private.atAccountBank = true;
Addon:UpdateData();
end
function private.OnBankFrameClosed()
private.atBank = false;
private.atAccountBank = false;
end
function private.OnGuildBankFrameOpened()
private.atGuildBank = true;
Addon:UpdateData();
end
function private.OnGuildBankFrameClosed()
private.atGuildBank = false;
end
-- function private.OnAccountBankFrameOpened()
-- private.atAccountBank = true;
-- end
-- function private.OnAccountBankFrameClosed()
-- private.atAccountBank = false;
-- end
function private.ValuateBag(bag)
Addon.Debug.Log(format("ValuateBag(): %d", bag))
local result = {
value = 0,
items = {},
}
local size = getContainerNumSlots(bag);
if size > 0 then
for slot = 1, size do
-- Grab the itemlink
local itemLink = getContainerItemLink(bag, slot);
if itemLink then
-- Lets skip bound items for now
local isBoundItem = C_Item.IsBound(ItemLocation:CreateFromBagAndSlot(bag, slot));
if isBoundItem then
-- Addon.Debug.Log(format(" skipping %s because it is soulbound", itemLink))
else
-- Seems like a real item and not soulbound, get info about item and valuate
local count, itemQuality = getContainerItemInfo(bag, slot);
private.handleItemValuation(itemLink, itemQuality, count, result)
end
end
end
end
-- Addon.Debug.Log(format(" ValuateBag(): %d", bag))
-- Addon.Debug.TableToString(result)
return result
end
function private.ValuateGBankTab(tab)
local result = {
value = 0,
items = {},
}
for slot = 1, GUILD_BANK_TAB_SLOTS do
local itemLink = GetGuildBankItemLink(tab, slot)
local _, count, _, _, itemQuality = GetGuildBankItemInfo(tab, slot)
if itemLink and count > 0 then
-- Addon.Debug.Log(format("GBANK: %s has a quality of %d", itemLink, itemQuality));
private.handleItemValuation(itemLink, itemQuality, count, result)
end
end
return result
end
function private.handleItemValuation(itemLink, itemQuality, count, resultTbl)
-- Use info to lookup value
local priceSource = Addon.GetFromDb("pricesource", "source");
local qualityFilterEnabled = Addon.GetFromDb("qualityFilter", "enabled");
local qualityFilterValue = tonumber(Addon.GetFromDb("qualityFilter", "value"));
-- Should we consider this item?
if private.ignoreSet[itemLink] then
-- Addon.Debug.Log(format(" skipping %s because it's on the item blocklist", itemLink));
return
end
if private.useAllowSet and not private.allowedSet[itemLink] then
-- Addon.Debug.Log(format(" skipping %s because it's not on the item allowlist", itemLink));
return
end
-- Should we consider this items quality?
if qualityFilterEnabled then
if itemQuality < qualityFilterValue then
-- Addon.Debug.Log(format(" skipping %s because its quality is lower then required", itemLink));
return
end
end
-- Addon.Debug.Log(format(" private.handleItemValuation(): %s %s %s", itemLink, itemQuality, priceSource))
local singleItemValue = private.GetItemValue(itemLink, priceSource) or 0;
local totalValue = singleItemValue * count;
Addon.Debug.Log(format(" found %d %s", count, itemLink));
-- If the item is already in the result, just increment the count
if resultTbl.items[itemLink] then
-- Addon.Debug.Log(format(" item already in list, adding %d", count))
resultTbl.items[itemLink]["count"] = resultTbl.items[itemLink]["count"] + count;
resultTbl.items[itemLink]["totalValue"] = resultTbl.items[itemLink]["totalValue"] + totalValue;
else
-- Addon.Debug.Log(format(" new item, adding %d", count))
-- Otherwise add it
resultTbl.items[itemLink] = {
count = count,
itemValue = singleItemValue,
totalValue = totalValue,
itemLink = itemLink,
};
end
-- Addon.Debug.Log(format(" current total is: %d", result.items[itemLink]["count"]))
resultTbl.value = resultTbl.value + totalValue;
end
function private.GetCharacterTable()
-- determine where we should be looking for this data
local charKey = format("%s.%s", currentRealm, currentCharacter)
if not Addon.db.global.Characters[charKey] then
Addon.db.global.Characters[charKey] = {};
end
return Addon.db.global.Characters[charKey];
end
function private.SaveValue(type, bag, value)
local charTable = private.GetCharacterTable();
local bagKey = format("%s%s", type, bag);
charTable[bagKey] = value;
end
function private.GetBankLastUpdated()
local charTable = private.GetCharacterTable();
return charTable["BankLastUpdated"];
end
function private.GetGBankLastUpdated()
local charTable = private.GetCharacterTable();
return charTable["GBankLastUpdated"];
end
function private.GetAccountBankLastUpdated()
local charTable = private.GetCharacterTable();
return charTable["AccountBankLastUpdated"];
end
function private.SaveBankLastUpdated(time)
local charTable = private.GetCharacterTable();
charTable["BankLastUpdated"] = time;
end
function private.SaveGBankLastUpdated(time)
local charTable = private.GetCharacterTable();
charTable["GBankLastUpdated"] = time;
end
function private.SaveAccountBankLastUpdated(time)
local charTable = private.GetCharacterTable();
charTable["AccountBankLastUpdated"] = time;
end
function private.GetTopContributors(type)
local charTable = private.GetCharacterTable();
return charTable[format("%sTopContributors", type)] or {};
end
function private.SetTopContributors(type, tbl)
local charTable = private.GetCharacterTable();
charTable[format("%sTopContributors", type)] = tbl;
end
function private.GetPersonalBagIDs()
local arr = {};
-- Add the bags we want to track based on the selectedBags setting
local selectedBags = Addon.GetFromDb("bagFilter", "selectedBags");
if selectedBags == "all" then
for i = FIRST_PERSONAL_BAG_SLOT, LAST_PERSONAL_BAG_SLOT do
arr[i] = 0;
end
end
if selectedBags == "all" or selectedBags == "reagent" then
arr[LAST_PERSONAL_BAG_SLOT + 1] = 0; -- reagent bag is the next slot
end
return arr;
end
function private.GetBankBagIDs()
local arr = {};
-- Add the bags we want to track based on the selectedBags setting
local selectedBags = Addon.GetFromDb("bagFilter", "selectedBags");
if selectedBags == "all" then
for i = FIRST_BANK_SLOT, LAST_BANK_SLOT do
arr[i] = 0;
end
end
if selectedBags == "all" or selectedBags == "reagent" then
arr[REAGENTBANK_CONTAINER] = 0;
end
return arr;
end
function private.GetAccountBankBagIDs()
local arr = {};
for i = FIRST_WARBAND_BANK_SLOT, LAST_WARBAND_BANK_SLOT do
arr[i] = 0;
end
return arr;
end
function private.GetSavedTotalForBags(tbl)
-- load table
local charTable = private.GetCharacterTable();
local bagTotal = 0;
for k, v in pairs(tbl) do
local bagKey = format("Bag%s", k);
if charTable[bagKey] then
bagTotal = bagTotal + charTable[bagKey];
end
end
return bagTotal;
end
function private.GetSavedTotalForGBank()
local charTable = private.GetCharacterTable();
local bagTotal = 0;
for k, v in pairs(charTable) do
if k:match("GBankTab.*") then
bagTotal = bagTotal + v;
end
end
-- Addon.Debug.Log(format("GetSavedTotalForGBank(): %s", bagTotal))
return bagTotal;
end
function Addon:round(number, digit_position)
local precision = math.pow(10, digit_position)
number = number + (precision / 2); -- this causes value #.5 and up to round up
-- and #.4 and lower to round down.
return math.floor(number / precision) * precision
end
function private.RecalculateTotals()
local ldbLabelSetting = Addon.GetFromDb("ldbsource");
local ldbMoneyPrecision = Addon.GetFromDb("moneyPrecision", "ldb");
local tooltipMoneyPrecision = Addon.GetFromDb("moneyPrecision", "tooltip");
-- Iterate personal bags
local bagTotal = private.GetSavedTotalForBags(private.GetPersonalBagIDs());
local bagTotalString = GetMoneyString(Addon:round(bagTotal, tooltipMoneyPrecision), true);
Addon:UpdateBagTotalText(bagTotalString);
if ldbLabelSetting == "bagtotal" then
local ldbBagTotalString = GetMoneyString(Addon:round(bagTotal, ldbMoneyPrecision), true);
Addon:UpdateDataBrokerText(ldbBagTotalString);
end
-- Iterate bank bags
local bankTotal = private.GetSavedTotalForBags(private.GetBankBagIDs());
local bankTotalString = GetMoneyString(Addon:round(bankTotal, tooltipMoneyPrecision), true);
Addon:UpdateBankTotalText(bankTotalString);
if ldbLabelSetting == "banktotal" then
local ldbBankTotalString = GetMoneyString(Addon:round(bankTotal, ldbMoneyPrecision), true);
Addon:UpdateDataBrokerText(ldbBankTotalString);
end
-- Iterate GBank bags
local gbankTotal = 0;
if Addon.GetFromDb("guildBank", "enabled") and IsInGuild() then
gbankTotal = private.GetSavedTotalForGBank()
local gbankTotalString = GetMoneyString(Addon:round(gbankTotal, tooltipMoneyPrecision), true);
Addon:UpdateGBankTotalText(gbankTotalString);
end
-- Iterate Account Bank bags
local accountBankTotal = 0;
if isRetail and Addon.GetFromDb("accountBank", "enabled") and Addon.GetFromDb("bagFilter", "selectedBags") == "all" then
accountBankTotal = private.GetSavedTotalForBags(private.GetAccountBankBagIDs());
local accountBankTotalString = GetMoneyString(Addon:round(accountBankTotal, tooltipMoneyPrecision), true);
Addon:UpdateAccountBankTotalText(accountBankTotalString);
end
-- convert to text and update databroker
local grandTotalString = GetMoneyString(Addon:round(bagTotal + bankTotal + gbankTotal + accountBankTotal, tooltipMoneyPrecision), true);
Addon:UpdateGrandTotalText(grandTotalString);
if ldbLabelSetting == "combinedtotal" then
local ldbGrandTotalString = GetMoneyString(Addon:round(bagTotal + bankTotal + gbankTotal + accountBankTotal, ldbMoneyPrecision), true);
Addon:UpdateDataBrokerText(ldbGrandTotalString);
end
-- reload last calculated top contributors, if necessary
if Addon.GetFromDb("topContributors", "enabled") then
local topContributors = {
Bag = private.GetTopContributors("Bag"),
Bank = private.GetTopContributors("Bank"),
GuildBank = private.GetTopContributors("GuildBank"),
}
if isRetail then
topContributors.AccountBank = private.GetTopContributors("AccountBank");
end
Addon:SetTopContributors(topContributors);
else
Addon:SetTopContributors({});
end
end
function private.PreparePriceSources()
Addon.Debug.Log("PreparePriceSources()")
-- price source check --
local priceSources = private.GetAvailablePriceSources() or {}
Addon.Debug.Log(format("loaded %d price sources", private.tablelength(priceSources)));
-- only 2 or less price sources -> chat msg: missing modules
if private.tablelength(priceSources) < 1 then
StaticPopupDialogs["BA_NO_PRICESOURCES"] = {
text =
L["no_price_sources"],
button1 = OKAY,
timeout = 0,
whileDead = true,
hideOnEscape = true
}
StaticPopup_Show("BA_NO_PRICESOURCES");
Addon:Print(L["addon_disabled"]);
Addon:Disable();
return
else
-- current preselected price source
local priceSource = Addon.GetFromDb("pricesource", "source")
-- normal price source check against prepared list
if not priceSources[priceSource] then
StaticPopupDialogs["BA_INVALID_CUSTOM_PRICESOURCE"] = {
text =
L["missing_price_source"],
button1 = OKAY,
timeout = 0,
whileDead = true,
hideOnEscape = true
}
StaticPopup_Show("BA_INVALID_CUSTOM_PRICESOURCE")
end
end
-- sort the list of price sources
table.sort(priceSources, function(k1, k2) return priceSources[k1] < priceSources[k2] end)
Addon.availablePriceSources = priceSources
end
function private.tablelength(T)
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
end
function private.startsWith(String, Start)
return string.sub(String, 1, string.len(Start)) == Start
end
function private.chatCmdShowConfig()
-- happens twice because there is a bug in the blizz implementation and the first call doesn't work. subsequent calls do.
Settings.OpenToCategory(Addon.CONST.METADATA.NAME)
Settings.OpenToCategory(Addon.CONST.METADATA.NAME)
end
function private.getIgnoredItemSet()
local set = {};
if not Addon.GetFromDb("itemFilter", "enabled") then
return set;
end
local items = Addon.GetFromDb("itemFilter", "items");
for k, v in ipairs(items) do
set[v] = true;
end
return set;
end
function private.getAllowedItemSet()
local set = {};
if not Addon.GetFromDb("itemAllow", "enabled") then
return set;
end
local items = Addon.GetFromDb("itemAllow", "items");
for k, v in ipairs(items) do
set[v] = true;
end
return set;
end
-- get available price sources from the different modules
function private.GetAvailablePriceSources()
local priceSources = {}
-- TSM
if Addon.TSM.IsLoaded() then
local ps = Addon.TSM.GetAvailablePriceSources() or {}
for k, v in pairs(ps) do
priceSources[k] = v
end
end
-- Oribos Exchange
if Addon.OE.IsLoaded() then
local ps = Addon.OE.GetAvailablePriceSources() or {}
for k, v in pairs(ps) do
priceSources[k] = v
end
end
-- Auctionator
if Addon.ATR.IsLoaded() then
local ps = Addon.ATR.GetAvailablePriceSources() or {}
for k, v in pairs(ps) do
priceSources[k] = v
end
end
-- AHDB
if Addon.AHDB.IsLoaded() then
local ps = Addon.AHDB.GetAvailablePriceSources() or {}
for k, v in pairs(ps) do
priceSources[k] = v
end
end
-- TUJ
if Addon.TUJ.IsLoaded() then
local ps = Addon.TUJ.GetAvailablePriceSources() or {}
for k, v in pairs(ps) do
priceSources[k] = v
end
end
-- Addon.Debug.TableToString(priceSources);
return priceSources
end
-- Valuate with selected pricing source
function private.GetItemValue(itemLink, priceSource)
-- from which addon is our selected price source?
local selectedPriceSource = Addon.CONST.PRICE_SOURCE[Addon.GetFromDb("pricesource", "source")]
if private.startsWith(selectedPriceSource, "TUJ:") then
return Addon.TUJ.GetItemValue(itemLink, priceSource)
elseif private.startsWith(selectedPriceSource, "OE:") then
return Addon.OE.GetItemValue(itemLink, priceSource)
elseif private.startsWith(selectedPriceSource, "ATR:") then
return Addon.ATR.GetItemValue(itemLink, priceSource)
elseif private.startsWith(selectedPriceSource, "AHDB:") then
return Addon.AHDB.GetItemValue(itemLink, priceSource)
else
return Addon.TSM.GetItemValue(itemLink, priceSource)
end
end