forked from Xruptor/BagSync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBagSync.lua
1825 lines (1536 loc) · 58.7 KB
/
BagSync.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
--[[
BagSync.lua
A item tracking addon that works with practically any bag addon available.
This addon has been heavily rewritten several times since it's creation back in 2007.
This addon was inspired by Tuller and his Bagnon addon. (Thanks Tuller!)
Author: Xruptor
--]]
local BSYC = select(2, ...) --grab the addon namespace
BSYC = LibStub("AceAddon-3.0"):NewAddon(BSYC, "BagSync", "AceEvent-3.0", "AceConsole-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale("BagSync", true)
local debugf = tekDebug and tekDebug:GetFrame("BagSync")
function BSYC:Debug(...)
if debugf then debugf:AddMessage(string.join(", ", tostringall(...))) end
end
----------------------
-- Local --
----------------------
local function rgbhex(r, g, b)
if type(r) == "table" then
if r.r then
r, g, b = r.r, r.g, r.b
else
r, g, b = unpack(r)
end
end
return string.format("|cff%02x%02x%02x", (r or 1) * 255, (g or 1) * 255, (b or 1) * 255)
end
local function tooltipColor(color, str)
return string.format("|cff%02x%02x%02x%s|r", (color.r or 1) * 255, (color.g or 1) * 255, (color.b or 1) * 255, tostring(str))
end
local function ParseItemLink(link)
if not link then return nil end
if tonumber(link) then return link end
local result = link:match("item:([%d:]+)") --strip the item: portion of the string
if result then
result = gsub(result, ":0:", "::") --supposedly blizzard removed all the zero's in patch 7.0. Lets do it just in case!
--split everything into a table so we can count up to the bonusID portion
local countSplit = {strsplit(":", result)}
--make sure we have a bonusID count
if countSplit and #countSplit > 13 then
local count = countSplit[13] or 0 -- do we have a bonusID number count?
count = count == "" and 0 or count --make sure we have a count if not default to zero
count = tonumber(count)
--check if we have even anything to work with for the amount of bonusID's
--btw any numbers after the bonus ID are either upgradeValue which we don't care about or unknown use right now
--http://wow.gamepedia.com/ItemString
if count > 0 and countSplit[1] then
--return the string with just the bonusID's in it
local newItemStr = ""
--11th place because 13 is bonus ID, one less from 13 (12) would be technically correct, but we have to compensate for ItemID we added in front so substract another one (11).
--string.rep repeats a pattern.
newItemStr = countSplit[1]..string.rep(":", 11)
--lets add the bonusID's, ignore the end past bonusID's
for i=13, (13 + count) do
--check for certain bonus ID's
if i == 14 and tonumber(countSplit[i]) == 3407 then
--the tradeskill window returns a 1:3407 for bonusID on regeant info and craft item in C_TradeSkillUI, ignore it
return result:match("^(%d+):")
end
newItemStr = newItemStr..":"..countSplit[i]
end
--add the unknowns at the end, upgradeValue doesn't always have to be supplied.
newItemStr = newItemStr..":::"
return newItemStr
end
end
--we don't have any bonusID's that we care about, so return just the ItemID which is the first number
return result:match("^(%d+):")
end
--nothing to return so return nil
return nil
end
local function ToShortItemID(link)
if not link then return nil end
if tonumber(link) then return link end
link = gsub(link, ":0:", "::")
return link:match("^(%d+):") or nil
end
local function IsInBG()
if (GetNumBattlefieldScores() > 0) then
return true
end
return false
end
local function IsInArena()
local a,b = IsActiveBattlefieldArena()
if not a then
return false
end
return true
end
--sort by key element rather then value
local function pairsByKeys (t, f)
local a = {}
for n in pairs(t) do table.insert(a, n) end
table.sort(a, f)
local i = 0 -- iterator variable
local iter = function () -- iterator function
i = i + 1
if a[i] == nil then return nil
else return a[i], t[a[i]]
end
end
return iter
end
----------------------
-- DB Functions --
----------------------
function BSYC:StartupDB()
BagSyncOpt = BagSyncOpt or {}
self.options = BagSyncOpt
if self.options.showTotal == nil then self.options.showTotal = true end
if self.options.showGuildNames == nil then self.options.showGuildNames = false end
if self.options.enableGuild == nil then self.options.enableGuild = true end
if self.options.enableMailbox == nil then self.options.enableMailbox = true end
if self.options.enableUnitClass == nil then self.options.enableUnitClass = false end
if self.options.enableMinimap == nil then self.options.enableMinimap = true end
if self.options.enableFaction == nil then self.options.enableFaction = true end
if self.options.enableAuction == nil then self.options.enableAuction = true end
if self.options.tooltipOnlySearch == nil then self.options.tooltipOnlySearch = false end
if self.options.enableTooltips == nil then self.options.enableTooltips = true end
if self.options.enableTooltipSeperator == nil then self.options.enableTooltipSeperator = true end
if self.options.enableCrossRealmsItems == nil then self.options.enableCrossRealmsItems = true end
if self.options.enableBNetAccountItems == nil then self.options.enableBNetAccountItems = false end
if self.options.enableTooltipItemID == nil then self.options.enableTooltipItemID = false end
if self.options.enableTooltipGreenCheck == nil then self.options.enableTooltipGreenCheck = true end
if self.options.enableRealmIDTags == nil then self.options.enableRealmIDTags = true end
if self.options.enableRealmAstrickName == nil then self.options.enableRealmAstrickName = false end
if self.options.enableRealmShortName == nil then self.options.enableRealmShortName = false end
if self.options.enableLoginVersionInfo == nil then self.options.enableLoginVersionInfo = true end
if self.options.enableFactionIcons == nil then self.options.enableFactionIcons = true end
if self.options.enableShowUniqueItemsTotals == nil then self.options.enableShowUniqueItemsTotals = true end
--setup the default colors
if self.options.colors == nil then self.options.colors = {} end
if self.options.colors.first == nil then self.options.colors.first = { r = 128/255, g = 1, b = 0 } end
if self.options.colors.second == nil then self.options.colors.second = { r = 1, g = 1, b = 1 } end
if self.options.colors.total == nil then self.options.colors.total = { r = 244/255, g = 164/255, b = 96/255 } end
if self.options.colors.guild == nil then self.options.colors.guild = { r = 101/255, g = 184/255, b = 192/255 } end
if self.options.colors.cross == nil then self.options.colors.cross = { r = 1, g = 125/255, b = 10/255 } end
if self.options.colors.bnet == nil then self.options.colors.bnet = { r = 53/255, g = 136/255, b = 1 } end
if self.options.colors.itemid == nil then self.options.colors.itemid = { r = 82/255, g = 211/255, b = 134/255 } end
self.db = {}
--initiate global db variable
BagSyncDB = BagSyncDB or {}
self.db.global = BagSyncDB
--the player DB defaults to the current realm, if you want more then you need to use db.global
BagSyncDB[self.currentRealm] = BagSyncDB[self.currentRealm] or {}
BagSyncDB[self.currentRealm][self.currentPlayer] = BagSyncDB[self.currentRealm][self.currentPlayer] or {}
self.db.player = BagSyncDB[self.currentRealm][self.currentPlayer]
BagSyncGUILD_DB = BagSyncGUILD_DB or {}
BagSyncGUILD_DB[self.currentRealm] = BagSyncGUILD_DB[self.currentRealm] or {}
self.db.guild = BagSyncGUILD_DB
BagSyncCURRENCY_DB = BagSyncCURRENCY_DB or {}
BagSyncCURRENCY_DB[self.currentRealm] = BagSyncCURRENCY_DB[self.currentRealm] or {}
self.db.currency = BagSyncCURRENCY_DB
BagSyncPROFESSION_DB = BagSyncPROFESSION_DB or {}
BagSyncPROFESSION_DB[self.currentRealm] = BagSyncPROFESSION_DB[self.currentRealm] or {}
BagSyncPROFESSION_DB[self.currentRealm][self.currentPlayer] = BagSyncPROFESSION_DB[self.currentRealm][self.currentPlayer] or {}
self.db.profession = BagSyncPROFESSION_DB
BagSyncBLACKLIST_DB = BagSyncBLACKLIST_DB or {}
BagSyncBLACKLIST_DB[self.currentRealm] = BagSyncBLACKLIST_DB[self.currentRealm] or {}
self.db.blacklist = BagSyncBLACKLIST_DB
BagSync_REALMKEY = BagSync_REALMKEY or {}
BagSync_REALMKEY[self.currentRealm] = GetRealmName()
BagSync_REALMKEY[0] = BagSync_REALMKEY[0] or {} --this will maintain a list of connected realms
self.db.realmkey = BagSync_REALMKEY
end
function BSYC:FixDB(onlyChkGuild)
--Removes obsolete character information
--Removes obsolete guild information
--Removes obsolete characters from currency db
--Removes obsolete profession information
--removes obsolete blacklist information
--Will only check guild related information if the paramater is passed as true
--Adds realm name to characters profiles if missing, v8.6
local storeUsers = {}
local storeGuilds = {}
for realm, rd in pairs(BagSyncDB) do
if string.find(realm, " ") then
--get rid of old realm names with whitespaces, we aren't going to use it anymore
BagSyncDB[realm] = nil
else
--realm
storeUsers[realm] = storeUsers[realm] or {}
storeGuilds[realm] = storeGuilds[realm] or {}
for k, v in pairs(rd) do
--users
storeUsers[realm][k] = storeUsers[realm][k] or 1
if v.realm == nil then v.realm = realm end --Adds realm name to characters profiles if missing, v8.6
for q, r in pairs(v) do
if q == "guild" then
storeGuilds[realm][r] = true
end
end
end
end
end
--guildbank data
for realm, rd in pairs(BagSyncGUILD_DB) do
if string.find(realm, " ") then
--get rid of old realm names with whitespaces, we aren't going to use it anymore
BagSyncGUILD_DB[realm] = nil
else
--realm
for k, v in pairs(rd) do
--users
if not storeGuilds[realm][k] then
--delete the guild because no one has it
BagSyncGUILD_DB[realm][k] = nil
end
end
end
end
--currency data and profession data, only do if were not doing a guild check
--also display fixdb message only if were not doing a guild check
if not onlyChkGuild then
--fix currency
for realm, rd in pairs(BagSyncCURRENCY_DB) do
if string.find(realm, " ") then
--get rid of old realm names with whitespaces, we aren't going to use it anymore
BagSyncCURRENCY_DB[realm] = nil
else
--realm
if not storeUsers[realm] then
--if it's not a realm that ANY users are on then delete it
BagSyncCURRENCY_DB[realm] = nil
else
for k, v in pairs(rd) do
if not storeUsers[realm][k] then
--if the user doesn't exist then delete data
BagSyncCURRENCY_DB[realm][k] = nil
end
end
end
end
end
--fix professions
for realm, rd in pairs(BagSyncPROFESSION_DB) do
if string.find(realm, " ") then
--get rid of old realm names with whitespaces, we aren't going to use it anymore
BagSyncPROFESSION_DB[realm] = nil
else
--realm
if not storeUsers[realm] then
--if it's not a realm that ANY users are on then delete it
BagSyncPROFESSION_DB[realm] = nil
else
for k, v in pairs(rd) do
if not storeUsers[realm][k] then
--if the user doesn't exist then delete data
BagSyncPROFESSION_DB[realm][k] = nil
end
end
end
end
end
--fix blacklist
for realm, rd in pairs(BagSyncBLACKLIST_DB) do
if string.find(realm, " ") then
--get rid of old realm names with whitespaces, we aren't going to use it anymore
BagSyncBLACKLIST_DB[realm] = nil
else
--realm
if not storeUsers[realm] then
--if it's not a realm that ANY users are on then delete it
BagSyncBLACKLIST_DB[realm] = nil
end
end
end
if BagSyncCRAFT_DB then BagSyncCRAFT_DB = nil end --remove old crafting DB
if BagSyncTOKEN_DB then BagSyncTOKEN_DB = nil end --remove old tokens db
self:Print("|cFFFF9900"..L.FixDBComplete.."|r")
end
end
function BSYC:CleanAuctionsDB()
--this function will remove expired auctions for all characters in every realm
local timestampChk = { 30*60, 2*60*60, 12*60*60, 48*60*60 }
for realm, rd in pairs(BagSyncDB) do
--realm
for k, v in pairs(rd) do
--users k=name, v=values
if BagSyncDB[realm][k].AH_LastScan and BagSyncDB[realm][k].AH_Count then --only proceed if we have an auction house time to work with
--check to see if we even have something to work with
if BagSyncDB[realm][k]["auction"] then
--we do so lets do a loop
local bVal = BagSyncDB[realm][k].AH_Count
--do a loop through all of them and check to see if any expired
for x = 1, bVal do
if BagSyncDB[realm][k]["auction"][0][x] then
--check for expired and remove if necessary
--it's okay if the auction count is showing more then actually stored, it's just used as a means
--to scan through all our items. Even if we have only 3 and the count is 6 it will just skip the last 3.
local dblink, dbcount, dbtimeleft = strsplit(",", BagSyncDB[realm][k]["auction"][0][x])
--only proceed if we have everything to work with, otherwise this auction data is corrupt
if dblink and dbcount and dbtimeleft then
if tonumber(dbtimeleft) < 1 or tonumber(dbtimeleft) > 4 then dbtimeleft = 4 end --just in case
--now do the time checks
local diff = time() - BagSyncDB[realm][k].AH_LastScan
if diff > timestampChk[tonumber(dbtimeleft)] then
--technically this isn't very realiable. but I suppose it's better the nothing
BagSyncDB[realm][k]["auction"][0][x] = nil
end
else
--it's corrupt delete it
BagSyncDB[realm][k]["auction"][0][x] = nil
end
end
end
end
end
end
end
end
function BSYC:FilterDB(dbSelect)
local xIndex = {}
local dbObj = self.db.global
if dbSelect and dbSelect == 1 then
--use BagSyncPROFESSION_DB
dbObj = self.db.profession
elseif dbSelect and dbSelect == 2 then
--use BagSyncCURRENCY_DB
dbObj = self.db.currency
end
--add more realm names if necessary based on BNet or Cross Realms
if self.options.enableBNetAccountItems then
for k, v in pairs(dbObj) do
for q, r in pairs(v) do
--we do this incase there are multiple characters with same name
xIndex[q.."^"..k] = r
end
end
elseif self.options.enableCrossRealmsItems then
for k, v in pairs(dbObj) do
if k == self.currentRealm or self.crossRealmNames[k] then
for q, r in pairs(v) do
----we do this incase there are multiple characters with same name
xIndex[q.."^"..k] = r
end
end
end
else
--do only the current realm if they don't have anything else configured
for k, v in pairs(dbObj) do
if k == self.currentRealm then
for q, r in pairs(v) do
----can't have multiple characters on same realm, but we need formatting anyways
xIndex[q.."^"..k] = r
end
end
end
end
return xIndex
end
function BSYC:GetRealmTags(srcName, srcRealm, isGuild)
local tagName = srcName
local fullRealmName = srcRealm --default to shortened realm first
if self.db.realmkey[srcRealm] then fullRealmName = self.db.realmkey[srcRealm] end --second, if we have a realmkey with a true realm name then use it
if not isGuild then
local ReadyCheck = [[|TInterface\RaidFrame\ReadyCheck-Ready:0|t]]
--local NotReadyCheck = [[|TInterface\RaidFrame\ReadyCheck-NotReady:0|t]]
--Interface\\TargetingFrame\\UI-PVP-FFA
--put a green check next to the currently logged in character name, make sure to put it as current realm only. You can have toons with same name on multiple realms
if srcName == self.currentPlayer and srcRealm == self.currentRealm and self.options.enableTooltipGreenCheck then
tagName = tagName.." "..ReadyCheck
end
else
--sometimes a person has characters on multiple connected servers joined to the same guild.
--the guild information is saved twice because although the guild is on the connected server, the characters themselves are on different servers.
--too compensate for this, lets check the connected server and return only the guild name. So it doesn't get processed twice.
for k, v in pairs(self.crossRealmNames) do
--check to see if the guild exists already on a connected realm and not the current realm
if k ~= srcRealm and self.db.guild[k] and self.db.guild[k][srcName] then
--return non-modified guild name, we only want the guild listed once for the cross-realm
return srcName
end
end
end
--make sure we work with player data not guild data
if self.options.enableFactionIcons and self.db.global[srcRealm] and self.db.global[srcRealm][srcName] then
local FactionIcon = [[|TInterface\Icons\Achievement_worldevent_brewmaster:18|t]]
if self.db.global[srcRealm][srcName].faction == "Alliance" then
FactionIcon = [[|TInterface\Icons\Inv_misc_tournaments_banner_human:18|t]]
elseif self.db.global[srcRealm][srcName].faction == "Horde" then
FactionIcon = [[|TInterface\Icons\Inv_misc_tournaments_banner_orc:18|t]]
end
tagName = FactionIcon.." "..tagName
end
--add Cross-Realm and BNet identifiers to Characters not on same realm
local crossString = ""
local bnetString = ""
if self.options.enableRealmIDTags then
crossString = "XR-"
bnetString = "BNet-"
end
if self.options.enableRealmAstrickName then
fullRealmName = "*"
elseif self.options.enableRealmShortName then
fullRealmName = string.sub(fullRealmName, 1, 5) --only use 5 characters of the server name
end
if self.options.enableBNetAccountItems then
if srcRealm and srcRealm ~= self.currentRealm then
if not self.crossRealmNames[srcRealm] then
tagName = tagName.." "..rgbhex(self.options.colors.bnet).."["..bnetString..fullRealmName.."]|r"
else
tagName = tagName.." "..rgbhex(self.options.colors.cross).."["..crossString..fullRealmName.."]|r"
end
end
elseif self.options.enableCrossRealmsItems then
if srcRealm and srcRealm ~= self.currentRealm then
tagName = tagName.." "..rgbhex(self.options.colors.cross).."["..crossString..fullRealmName.."]|r"
end
end
return tagName
end
----------------------
-- Bag Functions --
----------------------
function BSYC:SaveBag(bagname, bagid)
if not bagname or not bagid then return end
self.db.player[bagname] = self.db.player[bagname] or {}
--reset our tooltip data since we scanned new items (we want current data not old)
self.PreviousItemLink = nil
self.PreviousItemTotals = {}
if GetContainerNumSlots(bagid) > 0 then
local slotItems = {}
for slot = 1, GetContainerNumSlots(bagid) do
local _, count, _,_,_,_, link = GetContainerItemInfo(bagid, slot)
if ParseItemLink(link) then
count = (count > 1 and count) or nil
if count then
slotItems[slot] = format("%s,%d", ParseItemLink(link), count)
else
slotItems[slot] = ParseItemLink(link)
end
end
end
self.db.player[bagname][bagid] = slotItems
else
self.db.player[bagname][bagid] = nil
end
end
function BSYC:SaveEquipment()
self.db.player["equip"] = self.db.player["equip"] or {}
--reset our tooltip data since we scanned new items (we want current data not old)
self.PreviousItemLink = nil
self.PreviousItemTotals = {}
local slotItems = {}
local NUM_EQUIPMENT_SLOTS = 19
--start at 1, 0 used to be the old range slot (not needed anymore)
for slot = 1, NUM_EQUIPMENT_SLOTS do
local link = GetInventoryItemLink("player", slot)
if link and ParseItemLink(link) then
local count = GetInventoryItemCount("player", slot)
count = (count and count > 1) or nil
if count then
slotItems[slot] = format("%s,%d", ParseItemLink(link), count)
else
slotItems[slot] = ParseItemLink(link)
end
end
end
self.db.player["equip"][0] = slotItems
end
function BSYC:ScanEntireBank()
--force scan of bank bag -1, since blizzard never sends updates for it
self:SaveBag("bank", BANK_CONTAINER)
for i = NUM_BAG_SLOTS + 1, NUM_BAG_SLOTS + NUM_BANKBAGSLOTS do
self:SaveBag("bank", i)
end
if IsReagentBankUnlocked() then
self:SaveBag("reagentbank", REAGENTBANK_CONTAINER)
end
end
function BSYC:ScanVoidBank()
if not self.atVoidBank then return end
self.db.player["void"] = self.db.player["void"] or {}
--reset our tooltip data since we scanned new items (we want current data not old)
self.PreviousItemLink = nil
self.PreviousItemTotals = {}
local numTabs = 2
local index = 0
local slotItems = {}
for tab = 1, numTabs do
for i = 1, 80 do
local itemID, textureName, locked, recentDeposit, isFiltered = GetVoidItemInfo(tab, i)
if (itemID) then
index = index + 1
slotItems[index] = itemID and tostring(itemID) or nil
end
end
end
self.db.player["void"][0] = slotItems
end
function BSYC:ScanGuildBank()
if not IsInGuild() then return end
local MAX_GUILDBANK_SLOTS_PER_TAB = 98
--reset our tooltip data since we scanned new items (we want current data not old)
self.PreviousItemLink = nil
self.PreviousItemTotals = {}
local numTabs = GetNumGuildBankTabs()
local index = 0
local slotItems = {}
for tab = 1, numTabs do
local name, icon, isViewable, canDeposit, numWithdrawals, remainingWithdrawals = GetGuildBankTabInfo(tab)
--if we don't check for isViewable we get a weirdo permissions error for the player when they attempt it
if isViewable then
for slot = 1, MAX_GUILDBANK_SLOTS_PER_TAB do
local link = GetGuildBankItemLink(tab, slot)
if link and ParseItemLink(link) then
index = index + 1
local _, count = GetGuildBankItemInfo(tab, slot)
count = (count > 1 and count) or nil
if count then
slotItems[index] = format("%s,%d", ParseItemLink(link), count)
else
slotItems[index] = ParseItemLink(link)
end
end
end
end
end
self.db.guild[self.currentRealm][self.db.player.guild] = slotItems
end
function BSYC:ScanMailbox()
--this is to prevent buffer overflow from the CheckInbox() function calling ScanMailbox too much :)
if self.isCheckingMail then return end
self.isCheckingMail = true
--used to initiate mail check from server, for some reason GetInboxNumItems() returns zero sometimes
--even though the user has mail in the mailbox. This can be attributed to lag.
CheckInbox()
self.db.player["mailbox"] = self.db.player["mailbox"] or {}
local slotItems = {}
local mailCount = 0
local numInbox = GetInboxNumItems()
--reset our tooltip data since we scanned new items (we want current data not old)
self.PreviousItemLink = nil
self.PreviousItemTotals = {}
--scan the inbox
if (numInbox > 0) then
for mailIndex = 1, numInbox do
for i=1, ATTACHMENTS_MAX_RECEIVE do
local name, itemID, itemTexture, count, quality, canUse = GetInboxItem(mailIndex, i)
local link = GetInboxItemLink(mailIndex, i)
if name and link and ParseItemLink(link) then
mailCount = mailCount + 1
count = (count > 1 and count) or nil
if count then
slotItems[mailCount] = format("%s,%d", ParseItemLink(link), count)
else
slotItems[mailCount] = ParseItemLink(link)
end
end
end
end
end
self.db.player["mailbox"][0] = slotItems
self.isCheckingMail = false
end
function BSYC:ScanAuctionHouse()
self.db.player["auction"] = self.db.player["auction"] or {}
local slotItems = {}
local ahCount = 0
local numActiveAuctions = GetNumAuctionItems("owner")
--reset our tooltip data since we scanned new items (we want current data not old)
self.PreviousItemLink = nil
self.PreviousItemTotals = {}
--scan the auction house
if (numActiveAuctions > 0) then
for ahIndex = 1, numActiveAuctions do
local name, texture, count, quality, canUse, level, minBid, minIncrement, buyoutPrice, bidAmount, highBidder, owner, saleStatus = GetAuctionItemInfo("owner", ahIndex)
if name then
local link = GetAuctionItemLink("owner", ahIndex)
local timeLeft = GetAuctionItemTimeLeft("owner", ahIndex)
if link and ParseItemLink(link) and timeLeft then
ahCount = ahCount + 1
count = (count or 1)
slotItems[ahCount] = format("%s,%s,%s", ParseItemLink(link), count, timeLeft)
end
end
end
end
self.db.player["auction"][0] = slotItems
self.db.player.AH_Count = ahCount
end
------------------------
-- Money Tooltip --
------------------------
function BSYC:ShowMoneyTooltip(objTooltip)
local tooltip = _G["BagSyncMoneyTooltip"] or nil
if (not tooltip) then
tooltip = CreateFrame("GameTooltip", "BagSyncMoneyTooltip", UIParent, "GameTooltipTemplate")
local closeButton = CreateFrame("Button", nil, tooltip, "UIPanelCloseButton")
closeButton:SetPoint("TOPRIGHT", tooltip, 1, 0)
tooltip:SetToplevel(true)
tooltip:EnableMouse(true)
tooltip:SetMovable(true)
tooltip:SetClampedToScreen(true)
tooltip:SetScript("OnMouseDown",function(self)
self.isMoving = true
self:StartMoving();
end)
tooltip:SetScript("OnMouseUp",function(self)
if( self.isMoving ) then
self.isMoving = nil
self:StopMovingOrSizing()
end
end)
end
local usrData = {}
tooltip:ClearLines()
tooltip:ClearAllPoints()
if objTooltip then
tooltip:SetOwner(objTooltip, "ANCHOR_NONE")
tooltip:SetPoint("CENTER",objTooltip,"CENTER",0,0)
else
tooltip:SetOwner(UIParent, "ANCHOR_NONE")
tooltip:SetPoint("CENTER",UIParent,"CENTER",0,0)
end
tooltip:AddLine("BagSync")
tooltip:AddLine(" ")
--loop through our characters
local xDB = self:FilterDB()
for k, v in pairs(xDB) do
local yName, yRealm = strsplit("^", k)
local playerName = BSYC:GetRealmTags(yName, yRealm)
if v.gold then
playerName = self:GetClassColor(playerName or "Unknown", v.class)
table.insert(usrData, { name=playerName, gold=v.gold } )
end
end
table.sort(usrData, function(a,b) return (a.name < b.name) end)
local gldTotal = 0
for i=1, table.getn(usrData) do
tooltip:AddDoubleLine(usrData[i].name, GetCoinTextureString(usrData[i].gold), 1, 1, 1, 1, 1, 1)
gldTotal = gldTotal + usrData[i].gold
end
if self.options.showTotal and gldTotal > 0 then
tooltip:AddLine(" ")
tooltip:AddDoubleLine(tooltipColor(self.options.colors.total, L.TooltipTotal), GetCoinTextureString(gldTotal), 1, 1, 1, 1, 1, 1)
end
tooltip:AddLine(" ")
tooltip:Show()
end
function BSYC:HideMoneyTooltip()
local tooltip = _G["BagSyncMoneyTooltip"] or nil
if tooltip then
tooltip:Hide()
end
end
------------------------
-- Currency --
------------------------
function BSYC:ScanCurrency()
--LETS AVOID CURRENCY SPAM AS MUCH AS POSSIBLE
if self.doCurrencyUpdate and self.doCurrencyUpdate > 0 then return end
if IsInBG() or IsInArena() or InCombatLockdown() or UnitAffectingCombat("player") then
--avoid (Honor point spam), avoid (arena point spam), if it's world PVP...well then it sucks to be you
self.doCurrencyUpdate = 1
BSYC:RegisterEvent("PLAYER_REGEN_ENABLED")
return
end
local lastHeader
local limit = GetCurrencyListSize()
for i=1, limit do
local name, isHeader, isExpanded, _, _, count, icon = GetCurrencyListInfo(i)
--extraCurrencyType = 1 for arena points, 2 for honor points; 0 otherwise (an item-based currency).
if name then
if(isHeader and not isExpanded) then
ExpandCurrencyList(i,1)
lastHeader = name
limit = GetCurrencyListSize()
elseif isHeader then
lastHeader = name
end
if (not isHeader) then
self.db.currency[self.currentRealm][self.currentPlayer] = self.db.currency[self.currentRealm][self.currentPlayer] or {}
self.db.currency[self.currentRealm][self.currentPlayer][name] = {}
self.db.currency[self.currentRealm][self.currentPlayer][name].count = count
self.db.currency[self.currentRealm][self.currentPlayer][name].header = lastHeader
self.db.currency[self.currentRealm][self.currentPlayer][name].icon = icon
end
end
end
--we don't want to overwrite currency, because some characters may have currency that the others dont have
end
------------------------
-- Tooltip --
------------------------
function BSYC:ResetTooltip()
self.PreviousItemTotals = {}
self.PreviousItemLink = nil
end
function BSYC:CreateItemTotals(countTable)
local info = ""
local total = 0
local grouped = 0
--order in which we want stuff displayed
local list = {
[1] = { "bag", L.TooltipBag },
[2] = { "bank", L.TooltipBank },
[3] = { "reagentbank", L.TooltipReagent },
[4] = { "equip", L.TooltipEquip },
[5] = { "guild", L.TooltipGuild },
[6] = { "mailbox", L.TooltipMail },
[7] = { "void", L.TooltipVoid },
[8] = { "auction", L.TooltipAuction },
}
for i = 1, #list do
local count = countTable[list[i][1]]
if count > 0 then
grouped = grouped + 1
info = info..L.TooltipDelimiter..tooltipColor(self.options.colors.first, list[i][2]).." "..tooltipColor(self.options.colors.second, count)
total = total + count
end
end
--remove the first delimiter since it's added to the front automatically
info = strsub(info, string.len(L.TooltipDelimiter) + 1)
if string.len(info) < 1 then return nil end --return nil for empty strings
--if it's groupped up and has more then one item then use a different color and show total
if grouped > 1 then
info = tooltipColor(self.options.colors.second, total).." ("..info..")"
end
return info
end
function BSYC:GetClassColor(sName, sClass)
if not self.options.enableUnitClass then
return tooltipColor(self.options.colors.first, sName)
else
if sName ~= "Unknown" and sClass and RAID_CLASS_COLORS[sClass] then
return rgbhex(RAID_CLASS_COLORS[sClass])..sName.."|r"
end
end
return tooltipColor(self.options.colors.first, sName)
end
function BSYC:AddCurrencyTooltip(frame, currencyName, addHeader)
if not BagSyncOpt.enableTooltips then return end
local tmp = {}
local count = 0
local xDB = BSYC:FilterDB(2) --dbSelect 2
for k, v in pairs(xDB) do
local yName, yRealm = strsplit("^", k)
local playerName = BSYC:GetRealmTags(yName, yRealm)
playerName = self:GetClassColor(playerName or "Unknown", self.db.global[yRealm][yName].class)
for q, r in pairs(v) do
if q == currencyName then
--we only really want to list the currency once for display
table.insert(tmp, { name=playerName, count=r.count} )
count = count + 1
end
end
end
if count > 0 then
table.sort(tmp, function(a,b) return (a.name < b.name) end)
if self.options.enableTooltipSeperator and not addHeader then
frame:AddLine(" ")
end
if addHeader then
local color = { r = 64/255, g = 224/255, b = 208/255 } --same color as header in Currency window
frame:AddLine(rgbhex(color)..currencyName.."|r")
end
for i=1, #tmp do
frame:AddDoubleLine(tooltipColor(BagSyncOpt.colors.first, tmp[i].name), tooltipColor(BagSyncOpt.colors.second, tmp[i].count))
end
end
frame:Show()
end
function BSYC:AddItemToTooltip(frame, link) --workaround
if not BagSyncOpt.enableTooltips then return end
--if we can't convert the item link then lets just ignore it altogether
local itemLink = ParseItemLink(link)
if not itemLink then
frame:Show()
return
end
--use our stripped itemlink, not the full link
local shortItemID = ToShortItemID(itemLink)
--short the shortID and ignore all BonusID's and stats
if self.options.enableShowUniqueItemsTotals then itemLink = shortItemID end
--only show tooltips in search frame if the option is enabled
if self.options.tooltipOnlySearch and frame:GetOwner() and frame:GetOwner():GetName() and string.sub(frame:GetOwner():GetName(), 1, 16) ~= "BagSyncSearchRow" then
frame:Show()
return
end
local permIgnore ={
[6948] = "Hearthstone",
[110560] = "Garrison Hearthstone",
[140192] = "Dalaran Hearthstone",
[128353] = "Admiral's Compass",
}
--ignore the hearthstone and blacklisted items
if shortItemID and tonumber(shortItemID) then
if permIgnore[tonumber(shortItemID)] or self.db.blacklist[self.currentRealm][tonumber(shortItemID)] then
frame:Show()
return
end
end
--lag check (check for previously displayed data) if so then display it
if self.PreviousItemLink and itemLink and itemLink == self.PreviousItemLink then
if table.getn(self.PreviousItemTotals) > 0 then
for i = 1, #self.PreviousItemTotals do
local ename, ecount = strsplit("@", self.PreviousItemTotals[i])
if ename and ecount then
local color = self.options.colors.total
frame:AddDoubleLine(ename, ecount, color.r, color.g, color.b, color.r, color.g, color.b)
else
local color = self.options.colors.second
frame:AddLine(self.PreviousItemTotals[i], color.r, color.g, color.b)
end
end
end
frame:Show()
return
end
--reset our last displayed
self.PreviousItemTotals = {}
self.PreviousItemLink = itemLink
--this is so we don't scan the same guild multiple times
local previousGuilds = {}
local previousGuildsXRList = {}
local grandTotal = 0
local first = true
local xDB = self:FilterDB()
--loop through our characters
--k = player, v = stored data for player
for k, v in pairs(xDB) do
local allowList = {
["bag"] = 0,
["bank"] = 0,
["reagentbank"] = 0,
["equip"] = 0,
["mailbox"] = 0,
["void"] = 0,
["auction"] = 0,
["guild"] = 0,
}
local infoString
local pFaction = v.faction or self.playerFaction --just in case ;) if we dont know the faction yet display it anyways
--check if we should show both factions or not