forked from AssemblerManiac/InventoryInsight
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInventoryInsight_DataCollection.lua
1397 lines (1195 loc) · 60.7 KB
/
InventoryInsight_DataCollection.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 task = IIfA.task or LibAsync:Create("IIfA_DataCollection")
IIfA.task = task
local function p(...)
-- Ensure IIfA and its debug function are properly initialized
if not IIfA or not IIfA.DebugOut then return end
-- Ensure the conditions for debugging are met
if not IIFA_DATABASE[IIfA.currentAccount].settings.bDebug then return end
IIfA:DebugOut(...)
end
local function NonContiguousNonNilCount(tableObject)
local count = 0
for i, v in pairs(tableObject) do
if v ~= nil then count = count + 1 end
end
return count
end
local function GetBagName(bagId)
local bagNames = {
[BAG_BACKPACK] = "Backpack",
[BAG_BANK] = "Bank",
[BAG_BUYBACK] = "Buyback",
[BAG_COMPANION_WORN] = "Companion Worn",
[BAG_GUILDBANK] = "Guild Bank",
[BAG_HOUSE_BANK_ONE] = "House Bank One",
[BAG_HOUSE_BANK_TWO] = "House Bank Two",
[BAG_HOUSE_BANK_THREE] = "House Bank Three",
[BAG_HOUSE_BANK_FOUR] = "House Bank Four",
[BAG_HOUSE_BANK_FIVE] = "House Bank Five",
[BAG_HOUSE_BANK_SIX] = "House Bank Six",
[BAG_HOUSE_BANK_SEVEN] = "House Bank Seven",
[BAG_HOUSE_BANK_EIGHT] = "House Bank Eight",
[BAG_HOUSE_BANK_NINE] = "House Bank Nine",
[BAG_HOUSE_BANK_TEN] = "House Bank Ten",
[BAG_SUBSCRIBER_BANK] = "Subscriber Bank",
[BAG_VIRTUAL] = "Virtual",
[BAG_WORN] = "Worn",
}
local bagName = bagNames[bagId]
if bagName then
return bagName
elseif bagId > BAG_MAX_VALUE then
return GetCollectibleName(bagId)
else
IIfA:dm("Warn", "[GetBagName] Unknown Bag ID: " .. tostring(bagId))
end
end
local function ItemHasLocations(databaseItem)
if not databaseItem or databaseItem.locations == nil then return end
return NonContiguousNonNilCount(databaseItem.locations) >= 1
end
local function GetItemIdString(itemLink)
if itemLink then return tostring(GetItemLinkItemId(itemLink)) end
return
end
local function getDatabaseItemLocation(bagId)
--[[ Note: when the bagId is actually a houseCollectibleId do not use
IsOwnerOfCurrentHouse() because this could be for the LAM menu
where the player is setting the house to be ignored or tracked.
Handle checking valid ownership in the function collecting the
contents of the player home, or in the function used to call
the collector function like CollectBag.]]--
local houseCollectibleId = GetCollectibleIdForHouse(GetCurrentZoneHouseId())
if (bagId == BAG_BACKPACK or bagId == BAG_WORN) then
return IIfA.currentCharacterId
elseif (bagId == BAG_COMPANION_WORN) and HasActiveCompanion() then
return IIfA.currentCompanionId
elseif (bagId == BAG_BANK or bagId == BAG_SUBSCRIBER_BANK) then
return IIFA_LOCATION_KEY_BANK
elseif (bagId == BAG_VIRTUAL) then
return IIFA_LOCATION_KEY_CRAFTBAG
elseif (bagId == BAG_GUILDBANK) then
return GetGuildName(GetSelectedGuildBankId())
elseif (bagId >= BAG_HOUSE_BANK_ONE and bagId <= BAG_HOUSE_BANK_TEN) then
return GetCollectibleForHouseBankBag(bagId)
elseif (bagId > BAG_MAX_VALUE) and houseCollectibleId then
--[[ yes we hope houseCollectibleId is valid and a player home
but, it should be since housing banks have a bagId less than
BAG_MAX_VALUE. ]]--
return houseCollectibleId
end
end
local function getBagSlotInfoLocation(bagId, location)
--[[ Using if then statements for troubleshooting discrepancies.
Note: when the bagId is actually a houseCollectibleId do not use
IsOwnerOfCurrentHouse() because this could be for the LAM menu
where the player is setting the house to be ignored or tracked.
Same goes for HasActiveCompanion() in case you are clering
the bag from the LAM menu.
Handle checking valid ownership in the function collecting the
contents of the player home, or in the function used to call
the collector function like CollectBag.]]--
local selectedGuildBankId = GetSelectedGuildBankId()
local selectedGuildBankName = GetGuildName(selectedGuildBankId)
local houseCollectibleId = GetCollectibleIdForHouse(GetCurrentZoneHouseId())
if (bagId == BAG_BACKPACK or bagId == BAG_WORN) then
return bagId
elseif (bagId == BAG_COMPANION_WORN) then
return bagId
elseif (bagId == BAG_BANK or bagId == BAG_SUBSCRIBER_BANK) then
return bagId
elseif (bagId == BAG_VIRTUAL) then
return bagId
elseif (bagId == BAG_GUILDBANK) then
return location or selectedGuildBankName
elseif (bagId >= BAG_HOUSE_BANK_ONE and bagId <= BAG_HOUSE_BANK_TEN) then
return bagId
elseif (bagId > BAG_MAX_VALUE) then
--[[ yes we hope houseCollectibleId is valid and a player home
but, it should be since housing banks have a bagId less than
BAG_MAX_VALUE. ]]--
return bagId or houseCollectibleId
end
end
-- try to read item name from bag/slot - if that's empty, we read it from item link
local function getItemName(bagId, slotId, itemLink)
-- Attempt to get the item name using bagId and slotId if provided
if bagId and slotId then
local itemName = GetItemName(bagId, slotId)
if itemName and itemName ~= "" then
return ZO_CachedStrFormat(SI_TOOLTIP_ITEM_NAME, itemName)
end
end
-- If bagId and slotId are not valid, try to use the itemLink
if IIfA:isItemLink(itemLink) then
local itemName = GetItemLinkName(itemLink)
if itemName and itemName ~= "" then
return ZO_CachedStrFormat(SI_TOOLTIP_ITEM_NAME, itemName)
end
end
-- If the itemLink is a collectible link, handle that case
if IIfA:isCollectibleLink(itemLink) then
local collectibleId = IIfA:GetCollectibleLinkItemId(itemLink)
local collectibleName = GetCollectibleName(collectibleId)
if collectibleName and collectibleName ~= "" then
return ZO_CachedStrFormat(SI_TOOLTIP_ITEM_NAME, collectibleName)
end
end
-- Return nil if no valid name could be determined
return nil
end
local function getItemCount(bagId, slotId)
local itemInfo = { GetItemInfo(bagId, slotId) }
local itemCount = itemInfo[2] or 0 -- meaning itemCount
return itemCount
end
function IIfA:GetBagSlotInfo(bagId, slotIndex)
local hasNoBagInfo = not bagId or not slotIndex
if hasNoBagInfo then return end
local locationID = getBagSlotInfoLocation(bagId)
local hasBagSlotInfo = locationID and slotIndex and IIfA.BagSlotInfo[locationID] ~= nil and IIfA.BagSlotInfo[locationID][slotIndex]
if hasBagSlotInfo then
-- IIfA:dm("Debug", "[GetBagSlotInfo] - bagId: <<1>>, slotIndex: <<2>>, locationID: '<<3>>', hasBagSlotInfo: '<<4>>'", bagId, slotIndex, locationID, hasBagSlotInfo)
return IIfA.BagSlotInfo[locationID][slotIndex]
end
return
end
function IIfA:SetBagSlotInfo(bagId, slotIndex, itemKey)
local hasNoBagInfo = not bagId or not slotIndex
if hasNoBagInfo then return end
--[[ locationID is used instead of bagId so that when the locationID
is 6400, then we are looking at IIfA.BagSlotInfo[6400] for the Hall of Champions. ]]--
local locationID = getBagSlotInfoLocation(bagId)
local untrackedBag = locationID and slotIndex and IIfA.BagSlotInfo[locationID] == nil
local untrackedSlot = locationID and slotIndex and IIfA.BagSlotInfo[locationID] and (IIfA.BagSlotInfo[locationID][slotIndex] == nil)
local hasBagSlotInfo = IIfA:GetBagSlotInfo(bagId, slotIndex)
if untrackedBag then
IIfA.BagSlotInfo[locationID] = {}
IIfA.BagSlotInfo[locationID][slotIndex] = itemKey
IIfA:dm("Debug", "[SetBagSlotInfo] Untracked Bag - locationID: <<1>>, slotIndex: <<2>>, itemKey: '<<3>>'", locationID, slotIndex, itemKey)
elseif untrackedSlot then
IIfA.BagSlotInfo[locationID][slotIndex] = itemKey
IIfA:dm("Debug", "[SetBagSlotInfo] Untracked Slot - locationID: <<1>>, slotIndex: <<2>>, itemKey: '<<3>>'", locationID, slotIndex, itemKey)
elseif hasBagSlotInfo then
IIfA:dm("Warn", "[SetBagSlotInfo] Existing BagSlotInfo! locationID: <<1>>, slotIndex: <<2>>, itemKey: '<<3>>', storedKey: '<<4>>'", locationID, slotIndex, itemKey, IIfA.BagSlotInfo[locationID][slotIndex])
else
IIfA:dm("Warn", "[SetBagSlotInfo] Condition not covered - locationID: <<1>>, slotIndex: <<2>>, itemKey: '<<3>>'", locationID, slotIndex, itemKey)
end
end
function IIfA:ClearBagSlotInfo(bagId, slotIndex)
local hasNoBagInfo = not bagId or not slotIndex
if hasNoBagInfo then return end
if bagId == BAG_COMPANION_WORN and not HasActiveCompanion() then return end
--[[ locationID is used instead of bagId so that when the locationID
is 6400, then we are looking at IIfA.BagSlotInfo[6400] for the Hall of Champions. ]]--
local locationID = getBagSlotInfoLocation(bagId)
IIfA.BagSlotInfo[locationID] = IIfA.BagSlotInfo[locationID] or {}
IIfA.BagSlotInfo[locationID][slotIndex] = nil
IIfA:dm("Debug", "[ClearBagSlotInfo] Cleared BagSlotInfo - locationID: <<1>>, bagId: <<2>>, slotIndex: <<3>>", locationID, bagId, slotIndex)
end
--[[ Only specify location for a specific guild bank from the LAM menu. ]]--
function IIfA:ClearBagSlotInfoByBagId(bagId, location)
local hasNoBagId = not bagId
if hasNoBagId then return end
--[[ locationID is used instead of bagId so that when the locationID
is 6400, then we are looking at IIfA.BagSlotInfo[6400] for the Hall of Champions. ]]--
local locationID = location or getBagSlotInfoLocation(bagId, location)
-- Ensure the BagSlotInfo for the locationID is initialized to prevent nil index errors.
IIfA.BagSlotInfo = IIfA.BagSlotInfo or {}
-- Clear the specific slotIndex.
if IIfA.BagSlotInfo and IIfA.BagSlotInfo[locationID] then
IIfA.BagSlotInfo[locationID] = nil
IIfA:dm("Debug", "[ClearBagSlotInfoByBagId] Cleared BagSlotInfo - locationID: <<1>>, bagId: <<2>>, name: <<3>>", location, bagId, GetBagName(bagId))
else
IIfA:dm("Debug", "[ClearBagSlotInfoByBagId] Unable to clear BagSlotInfo because locationID was nil or invalid. locationID: <<1>>, bagId: <<2>>, name: <<3>>", location, bagId, GetBagName(bagId))
end
end
function IIfA:SetFurnitureSlotInfo(houseCollectibleId, itemId, furnitureItemLink)
--[[ The bagId is actually the houseCollectibleId, and the slotIndex
is actually the itemId. The furnitureItemLink is from the
getAllPlacedFurniture table created within RescanHouse ]]--
local hasNoBagInfo = not houseCollectibleId or not itemId
if hasNoBagInfo then return end
local isValidLinkType = IIfA:isItemLink(furnitureItemLink) or IIfA:isCollectibleLink(furnitureItemLink)
if not isValidLinkType then
IIfA:dm("Warn", "[SetFurnitureSlotInfo] Invalid furnitureItemLink: '<<1>>', houseCollectibleId: '<<2>>', itemId: '<<3>>'", furnitureItemLink, houseCollectibleId, itemId)
return
end
local itemKey
if IIfA:isItemLink(furnitureItemLink) then
itemKey = IIfA:GetItemKey(furnitureItemLink)
elseif IIfA:isCollectibleLink(furnitureItemLink) then
itemKey = furnitureItemLink
end
local locationID = getBagSlotInfoLocation(houseCollectibleId)
local untrackedBag = locationID and itemId and IIfA.BagSlotInfo[locationID] == nil
local untrackedSlot = locationID and itemId and IIfA.BagSlotInfo[locationID] and (IIfA.BagSlotInfo[locationID][itemId] == nil)
local hasBagSlotInfo = locationID and itemId and IIfA.BagSlotInfo[locationID] ~= nil and IIfA.BagSlotInfo[locationID][itemId]
if untrackedBag then
IIfA.BagSlotInfo[locationID] = {}
IIfA.BagSlotInfo[locationID][itemId] = itemKey
IIfA:dm("Debug", "[SetFurnitureSlotInfo] Untracked Bag - locationID: <<1>>, itemId: <<2>>, furnitureItemLink: '<<3>>', itemKey: '<<4>>'", locationID, itemId, furnitureItemLink, itemKey)
elseif untrackedSlot then
IIfA.BagSlotInfo[locationID][itemId] = itemKey
IIfA:dm("Debug", "[SetFurnitureSlotInfo] Untracked Slot - locationID: <<1>>, itemId: <<2>>, furnitureItemLink: '<<3>>', itemKey: '<<4>>'", locationID, itemId, furnitureItemLink, itemKey)
elseif hasBagSlotInfo then
IIfA:dm("Warn", "[SetFurnitureSlotInfo] Existing Slot - locationID: <<1>>, itemId: <<2>>, furnitureItemLink: '<<3>>', itemKey: '<<4>>', storedKey: '<<5>>'", locationID, itemId, itemKey, furnitureItemLink, IIfA.BagSlotInfo[locationID][itemId])
else
IIfA:dm("Warn", "[SetFurnitureSlotInfo] Condition not covered - locationID: <<1>>, itemId: <<2>>, furnitureItemLink: '<<3>>', itemKey: '<<4>>'", locationID, itemId, furnitureItemLink, itemKey)
end
end
local function IsCollectibleIdPlayerHouse(houseCollectibleId)
if not houseCollectibleId then IIfA:dm("Warn", "[IsCollectibleIdPlayerHouse] houseCollectibleId was nil, will obtain from API") end
houseCollectibleId = houseCollectibleId or GetCollectibleIdForHouse(GetCurrentZoneHouseId())
return houseCollectibleId > BAG_MAX_VALUE and GetCollectibleIdForHouse(GetCurrentZoneHouseId()) > 0
end
local function IsHouseBankUnowned(bagId)
return bagId >= BAG_HOUSE_BANK_ONE and bagId <= BAG_HOUSE_BANK_TEN and not IsOwnerOfCurrentHouse()
end
local function IsCompanionInactive(bagId)
return bagId == BAG_COMPANION_WORN and (not HasActiveCompanion() or IIfA.currentCompanionId == nil)
end
local function IsBankUnavailable(bagId)
return (bagId == BAG_BANK or bagId == BAG_SUBSCRIBER_BANK) and not IsBankOpen()
end
local function IsSubscriberBank(bagId)
return bagId == BAG_SUBSCRIBER_BANK
end
local function IsBagIdNotScannable(bagId)
return bagId == BAG_GUILDBANK or bagId > BAG_MAX_VALUE
end
local function IsBagIdNotScannableWithVirtual(bagId)
return bagId == BAG_GUILDBANK or bagId == BAG_VIRTUAL or bagId > BAG_MAX_VALUE
end
local function IsHouseBankAvailable(bagId)
local collectibleHouseBankId = GetCollectibleForHouseBankBag(bagId)
return (bagId >= BAG_HOUSE_BANK_ONE and bagId <= BAG_HOUSE_BANK_TEN) and collectibleHouseBankId > 0 and IsOwnerOfCurrentHouse()
end
--[[Regardless of previous versions coding, this method is simply not
supported for the Guild Bank, Craft Bag, or any player home. ]]--
local function GetBagContents(bagId, b_useAsync)
local shouldSkipBagScan = IsHouseBankUnowned(bagId) or IsCompanionInactive(bagId) or IsBagIdNotScannableWithVirtual(bagId) or IsBankUnavailable(bagId)
if shouldSkipBagScan then
IIfA:dm("Debug", "[GetBagContents] IsHouseBankUnowned: <<1>>", tostring(IsHouseBankUnowned(bagId)))
IIfA:dm("Debug", "[GetBagContents] IsCompanionInactive: <<1>>", tostring(IsCompanionInactive(bagId)))
IIfA:dm("Debug", "[GetBagContents] IsBagIdNotScannableWithVirtual: <<1>>", tostring(IsBagIdNotScannableWithVirtual(bagId)))
IIfA:dm("Debug", "[GetBagContents] IsBankUnavailable: <<1>>", tostring(IsBankUnavailable(bagId)))
IIfA:dm("Debug", "[GetBagContents] Skipped bagId: <<1>>, name: <<2>>, useAsync: <<3>>", bagId, GetBagName(bagId), tostring(b_useAsync))
return
end
IIfA:dm("Debug", "[GetBagContents] Collecting bag contents for bagId: <<1>>, name: <<2>>, useAsync: <<3>>", bagId, GetBagName(bagId), tostring(b_useAsync))
local bagItems = GetBagSize(bagId)
-- Loop from 0 to bagItems - 1 (since GetBagSize returns the total number of slots, which is 1-based, and slotIndex is 0-based)
if b_useAsync then
task:For(0, bagItems - 1):Do(function(slotIndex)
IIfA:EvalBagItem(bagId, slotIndex)
end)
else
for slotIndex = 0, bagItems - 1 do
IIfA:EvalBagItem(bagId, slotIndex)
end
end
end
local function GetVirtualBagContents(b_useAsync)
IIfA:dm("Debug", "[GetVirtualBagContents] Collecting Virtual Bag contents, useAsync: <<1>>", tostring(b_useAsync))
local slotId = GetNextVirtualBagSlotId(nil)
if b_useAsync then
task:While(function()
return slotId ~= nil
end):Do(function()
IIfA:EvalBagItem(BAG_VIRTUAL, slotId)
slotId = GetNextVirtualBagSlotId(slotId)
end)
else
while slotId ~= nil do
IIfA:EvalBagItem(BAG_VIRTUAL, slotId)
slotId = GetNextVirtualBagSlotId(slotId)
end
end
end
function IIfA:DeleteCharacterData(characterToDelete)
if characterToDelete then
-- Access the current account and server data
local serverData = IIFA_DATABASE[IIfA.currentAccount].servers[IIfA.currentServerType]
local charNameToId = serverData.CharNameToId
local charIdToName = serverData.CharIdToName
-- Delete the selected character's data
for characterName, charId in pairs(charNameToId) do
if characterName == characterToDelete then
-- Remove the character from the lookup tables
charNameToId[characterToDelete] = nil
charIdToName[charId] = nil
IIfA:ClearUnowned()
end
end
end
end
function IIfA:DeleteGuildData(selectedGuildBankToDelete)
if selectedGuildBankToDelete then
-- Access server-specific guild bank info
local serverData = IIFA_DATABASE[IIfA.currentAccount].servers[IIfA.currentServerType]
serverData.guildBankInfo = serverData.guildBankInfo or {}
-- Check if the guild exists in guildBankInfo
if serverData.guildBankInfo[selectedGuildBankToDelete] then
p("Deleting Guild Bank data for <<1>>", selectedGuildBankToDelete)
-- Set bCollectData to false
serverData.guildBankInfo[selectedGuildBankToDelete].bCollectData = false
-- Clear location and bag slot info
IIfA:ClearLocationData(BAG_GUILDBANK, selectedGuildBankToDelete)
IIfA:ClearBagSlotInfoByBagId(BAG_GUILDBANK, selectedGuildBankToDelete)
end
end
end
function IIfA:CollectGuildBank()
IIfA:UpdateGuildBankLookup()
local selectedGuildBankId = GetSelectedGuildBankId()
local selectedGuildBankName = GetGuildName(selectedGuildBankId)
if #selectedGuildBankName == 0 or selectedGuildBankName == IIfA.EMPTY_STRING then return end
-- Access server-specific guild bank info
local serverData = IIFA_DATABASE[IIfA.currentAccount].servers[IIfA.currentServerType]
-- Check if the user wants to track this guild's data first
local guildData = serverData.guildBankInfo[selectedGuildBankName]
if not serverData.bCollectGuildBankData or not guildData.bCollectData then
return
end
-- Add Roomba support
if Roomba and Roomba.WorkInProgress and Roomba.WorkInProgress() then
CALLBACK_MANAGER:FireCallbacks("Roomba-EndStacking", function() IIfA:CollectGuildBank() end)
return
end
local guildBankOpen = IsGuildBankOpen()
if not guildBankOpen then
IIfA:dm("Debug", "[CollectGuildBank] Guild Bank '<<1>>' is not available, exiting early", selectedGuildBankName)
return
end
IIfA:dm("Debug", "[CollectGuildBank] Collecting Guild Bank Data for " .. selectedGuildBankName)
task:Call(function()
IIfA:ClearLocationData(BAG_GUILDBANK, selectedGuildBankName)
IIfA:ClearBagSlotInfoByBagId(BAG_GUILDBANK, selectedGuildBankName)
end):Then(function()
local itemsInGuildBank = 0
local slotIndex = ZO_GetNextBagSlotIndex(BAG_GUILDBANK, nil)
task:While(function()
return slotIndex ~= nil
end):Do(function()
itemsInGuildBank = itemsInGuildBank + 1
local itemLink = GetItemLink(BAG_GUILDBANK, slotIndex, LINK_STYLE_BRACKETS)
IIfA:EvalBagItem(BAG_GUILDBANK, slotIndex)
slotIndex = ZO_GetNextBagSlotIndex(BAG_GUILDBANK, slotIndex)
end):Then(function()
guildData.items = itemsInGuildBank
IIfA:dm("Debug", "[CollectGuildBank] Guild Bank Collected - <<1>>, itemCount: <<2>>", selectedGuildBankName, itemsInGuildBank)
end)
end)
end
function IIfA:ScanCurrentCharacter()
IIfA:dm("Debug", "[ScanCurrentCharacter] Starting...")
task:Call(function()
--[[ It is safe to use ClearBagSlotInfoByBagId() with the
BAG_BACKPACK because BagSlotInfo uses two separate locations
for BAG_WORN and BAG_BACKPACK.
Do not use ClearLocationData() with BAG_BACKPACK ]]--
--[[ After we clear BAG_WORN or BAG_BACKPACK both bags have
been cleared, so we have to scan both again. ]]--
IIfA:ClearLocationData(BAG_WORN)
end)
if not IIfA:IsCharacterEquipIgnored() then
-- First task: GetBagContents(BAG_WORN)
task:Call(function()
IIfA:ClearBagSlotInfoByBagId(BAG_WORN)
GetBagContents(BAG_WORN, true)
end)
end
if not IIfA:IsCharacterInventoryIgnored() then
-- Second task: GetBagContents(BAG_BACKPACK)
task:Call(function()
--[[ It is safe to use ClearBagSlotInfoByBagId() with the
BAG_BACKPACK because BagSlotInfo uses two separate locations
for BAG_WORN and BAG_BACKPACK.
Do not use ClearLocationData() with BAG_BACKPACK ]]--
IIfA:ClearBagSlotInfoByBagId(BAG_BACKPACK)
GetBagContents(BAG_BACKPACK, true)
end)
end
task:Call(function()
IIfA:MakeBSI()
end)
end
function IIfA:ScanBackpackAndCraftBag()
IIfA:dm("Debug", "[ScanBackpackAndCraftBag] Starting...")
task:Call(function()
--[[ It is safe to use ClearBagSlotInfoByBagId() with the
BAG_BACKPACK because BagSlotInfo uses two separate locations
for BAG_WORN and BAG_BACKPACK.
Do not use ClearLocationData() with BAG_BACKPACK ]]--
--[[ After we clear BAG_WORN or BAG_BACKPACK both bags have
been cleared, so we have to scan both again. ]]--
IIfA:ClearLocationData(BAG_WORN)
end)
if not IIfA:IsCharacterEquipIgnored() then
-- First task: GetBagContents(BAG_WORN)
task:Call(function()
IIfA:ClearBagSlotInfoByBagId(BAG_WORN)
GetBagContents(BAG_WORN, true)
end)
end
if not IIfA:IsCharacterInventoryIgnored() then
-- Second task: GetBagContents(BAG_BACKPACK)
task:Call(function()
--[[ It is safe to use ClearBagSlotInfoByBagId() with the
BAG_BACKPACK because BagSlotInfo uses two separate locations
for BAG_WORN and BAG_BACKPACK.
Do not use ClearLocationData() with BAG_BACKPACK ]]--
IIfA:ClearBagSlotInfoByBagId(BAG_BACKPACK)
GetBagContents(BAG_BACKPACK, true)
end)
end
task:Then(function()
IIfA:ClearLocationData(BAG_VIRTUAL)
IIfA:ClearBagSlotInfoByBagId(BAG_VIRTUAL)
GetVirtualBagContents(false)
end)
task:Then(function()
IIfA:MakeBSI()
end)
end
--[[
Developer note: In ScanHouseBanks, the call to IIfA:ClearLocationData will fail because collectibleId is zero
bagId on the other hand DOES work, possibly because it's in use by the for loop
]]--
local function ScanHouseBanks()
if not IsOwnerOfCurrentHouse() then
IIfA:dm("Debug", "[ScanHouseBanks] Skipped, not in a house...")
return
else
IIfA:dm("Debug", "[ScanHouseBanks] Starting...")
end
task:For(BAG_HOUSE_BANK_ONE, BAG_HOUSE_BANK_TEN):Do(function(bagId)
local collectibleId = GetCollectibleForHouseBankBag(bagId)
if IsCollectibleUnlocked(collectibleId) then
IIfA:dm("Debug", "Scanning House Bank (<<1>>)", collectibleId)
IIfA:ClearLocationData(bagId)
IIfA:ClearBagSlotInfoByBagId(bagId)
GetBagContents(bagId)
end
end):Then(function()
IIfA:dm("Debug", "Completed scanning all house banks")
end)
end
function IIfA:ScanBank()
IIfA:dm("Debug", "[ScanBank] Scanning BAG_BANK, BAG_SUBSCRIBER_BANK, BAG_VIRTUAL, ScanHouseBanks")
-- Start the task for scanning the player's bank and other related data
task:Call(function()
-- Retrieve the bank contents
IIfA:ClearLocationData(BAG_BANK)
IIfA:ClearBagSlotInfoByBagId(BAG_BANK)
GetBagContents(BAG_BANK, true)
end):Then(function()
--[[ It is safe to use ClearBagSlotInfoByBagId() with the
BAG_SUBSCRIBER_BANK because BagSlotInfo uses two separate locations
for BAG_BANK and BAG_SUBSCRIBER_BANK.
Do not use ClearLocationData() with BAG_SUBSCRIBER_BANK ]]--
-- Next, handle the subscriber bank after the main bank is done
IIfA:ClearBagSlotInfoByBagId(BAG_SUBSCRIBER_BANK)
GetBagContents(BAG_SUBSCRIBER_BANK, true)
end):Then(function()
-- After processing the bank, handle the craft bag (virtual bag)
IIfA:ClearLocationData(BAG_VIRTUAL)
IIfA:ClearBagSlotInfoByBagId(BAG_VIRTUAL)
GetVirtualBagContents(true)
end):Then(function()
-- Finally, attempt to scan the house bank after everything else is done
ScanHouseBanks()
end)
end
-- only grabs the content of bagpack and worn on the first login - hence we set the function to insta-return below.
function IIfA:OnFirstInventoryOpen()
IIfA:dm("Debug", "[OnFirstInventoryOpen] Starting...")
if IIfA.BagsScanned then return end
IIfA.BagsScanned = true
-- do not async this, each scan function does that itself
IIfA:ScanBank()
IIfA:ScanCurrentCharacter()
end
function IIfA:UpdateGuildBankLookup()
local serverData = IIFA_DATABASE[IIfA.currentAccount].servers[IIfA.currentServerType]
serverData.guildBankInfo = serverData.guildBankInfo or {}
IIfA:dm("Debug", serverData.guildBankInfo)
for index = 1, GetNumGuilds() do
local guildId = GetGuildId(index)
local guildName = GetGuildName(guildId)
if not serverData.guildBankInfo[guildName] then
serverData.guildBankInfo[guildName] = {
bCollectData = false,
items = 0,
}
end
end
IIfA:dm("Debug", serverData.guildBankInfo)
end
function IIfA:GuildBankReady()
-- call with libAsync to avoid lag
task:Call(function()
p("GuildBankReady...")
IIfA.isGuildBankReady = false
IIfA:CollectGuildBank()
end)
end
function IIfA:GuildBankDelayReady()
p("GuildBankDelayReady...")
if not IIfA.isGuildBankReady then
IIfA.isGuildBankReady = true
IIfA:GuildBankReady()
end
end
function IIfA:GuildBankAddRemove(eventCode, slotId, addedByLocalPlayer, itemSoundCategory, isLastUpdateForMessage)
IIfA:dm("Debug", "Guild Bank Add or Remove...")
-- Access bCollectGuildBankData from IIFA_DATABASE
local serverData = IIFA_DATABASE[IIfA.currentAccount].servers[IIfA.currentServerType]
if not serverData.bCollectGuildBankData then return end
-- Call with libAsync to avoid lag
task:Call(function()
IIfA:UpdateGuildBankLookup()
local guildName = GetGuildName(GetSelectedGuildBankId())
local itemLink, itemKey, itemLinkFromBag, itemCount = IIfA:GetBagItemDetails(BAG_GUILDBANK, slotId)
if guildName and eventCode == EVENT_GUILD_BANK_ITEM_ADDED then
IIfA:dm("Debug", "Added: '<<1>>', '<<2>>', slot: <<3>>", itemLink, guildName, slotId)
IIfA:EvalBagItem(BAG_GUILDBANK, slotId)
elseif guildName and eventCode == EVENT_GUILD_BANK_ITEM_REMOVED then
IIfA:dm("Debug", "Removed: '<<1>>', '<<2>>', slot: <<3>>", itemLink, guildName, slotId)
IIfA:EvalBagItem(BAG_GUILDBANK, slotId)
end
end)
end
function IIfA:RescanHouse(houseCollectibleId)
IIfA:dm("Debug", "[RescanHouse] Starting...")
if not houseCollectibleId then IIfA:dm("Warn", "[RescanHouse] houseCollectibleId was nil, will obtain from API") end
houseCollectibleId = houseCollectibleId or GetCollectibleIdForHouse(GetCurrentZoneHouseId())
if not houseCollectibleId or not IIfA.trackedBags[houseCollectibleId] then
IIfA:dm("Warn", "[RescanHouse] houseCollectibleId not obtained!")
return
end
local collectibleName = GetCollectibleName(houseCollectibleId)
if not IsCollectibleIdPlayerHouse(houseCollectibleId) then
IIfA:dm("Warn", "[RescanHouse] Rescan Aborted, not in a player home.")
return
end
IIfA:dm("Debug", "[RescanHouse] houseCollectibleId: <<1>>, for <<2>>", houseCollectibleId, collectibleName)
local serverData = IIFA_DATABASE[IIfA.currentAccount].servers[IIfA.currentServerType]
-- Update HouseNameToId and HouseIdToName
serverData.HouseNameToId[collectibleName] = houseCollectibleId
serverData.HouseIdToName[houseCollectibleId] = collectibleName
-- Only set collectHouseData[houseCollectibleId] if it's not already set
if serverData.collectHouseData[houseCollectibleId] == nil then
serverData.collectHouseData[houseCollectibleId] = IIfA:GetHouseTracking()
end
local isTrackedBagValid = IIfA.trackedBags and IIfA.trackedBags[houseCollectibleId]
if isTrackedBagValid then
IIfA:dm("Debug", "[RescanHouse] trackedBags for the current house: <<1>>", tostring(IIfA.trackedBags[houseCollectibleId]))
else
IIfA:dm("Warn", "[RescanHouse] trackedBags invalid!")
end
if not serverData.collectHouseData[houseCollectibleId] then
if IIfA:GetHouseTracking() and IIfA:GetIgnoredHouseIds()[houseCollectibleId] then
IIfA.trackedBags[houseCollectibleId] = false
return
end
IIfA.trackedBags[houseCollectibleId] = true
end
IIfA:dm("Debug", "[RescanHouse] Rescanning player home: id: <<1>>, name '<<2>>'", houseCollectibleId, GetCollectibleName(houseCollectibleId))
-- call with libAsync to avoid lag
task:Call(function()
-- clear and re-create, faster than conditionally updating
IIfA:ClearLocationData(houseCollectibleId)
IIfA:ClearBagSlotInfoByBagId(houseCollectibleId)
end):Then(function()
local furnitureData = {}
local furnitureId = GetNextPlacedHousingFurnitureId(nil)
local counter = 0
local identifiedItemId = nil
local identifiedLink = nil
local identifiedName = nil
task:While(function()
return furnitureId ~= nil and counter < 10000
end):Do(function()
if furnitureId then
-- These placeholders will indicate the Identified placed furniture or collectible
identifiedLink = nil
identifiedItemId = nil
local itemLink = GetPlacedFurnitureLink(furnitureId, LINK_STYLE_BRACKETS)
local itemId = GetItemLinkItemId(itemLink)
local collectibleId = GetCollectibleIdFromFurnitureId(furnitureId)
local collectibleLink = GetCollectibleLink(collectibleId, LINK_STYLE_BRACKETS)
if IIfA:isItemLink(itemLink) then
identifiedLink = itemLink
identifiedItemId = itemId
elseif IIfA:isCollectibleLink(collectibleLink) then
identifiedLink = collectibleLink
identifiedItemId = collectibleId
end
if identifiedLink then
furnitureData[identifiedLink] = furnitureData[identifiedLink] or { count = 0, itemId = identifiedItemId }
furnitureData[identifiedLink].count = furnitureData[identifiedLink].count + 1
end
counter = counter + 1
furnitureId = GetNextPlacedHousingFurnitureId(furnitureId)
end
end):Then(function()
IIfA:dm("Debug", "[RescanHouse] Starting For Loop...")
task:For(pairs(furnitureData)):Do(function(itemLink, itemData)
local itemId = itemData.itemId
local itemCount = itemData.count
if IIfA:isItemLink(itemLink) then
identifiedName = ZO_CachedStrFormat(SI_TOOLTIP_ITEM_NAME, GetItemLinkName(itemLink))
elseif IIfA:isCollectibleLink(itemLink) then
identifiedName = ZO_CachedStrFormat(SI_TOOLTIP_ITEM_NAME, GetCollectibleName(itemId))
end
IIfA:EvalFurnitureItem(houseCollectibleId, itemId, itemLink, itemCount, identifiedName)
end)
end):Then(function()
IIfA:dm("Debug", "[RescanHouse] Furniture loop completed...")
end)
end)
end
--[[
Data collection notes:
Currently crafting items are coming back from getitemlink with level info in them.
If it's a crafting item, strip the level info and store only the item number as the itemKey
Use function GetItemCraftingInfo, if usedInCraftingType indicates it's NOT a material, check for other item types
When showing items in tooltips, check for both stolen & owned, show both
--]]
--[[ GetItemKey() returns the item's db key, we only save under the item link
if we need to save level information etc, else we use the itemId.
isCollectibleLink it not used here because we use the entire collectible link to
ensure the we check for the correct link type.
]]--
function IIfA:GetItemKey(itemLink)
-- Return an empty string immediately if itemLink is nil or an empty string
local isValidLinkType = IIfA:isItemLink(itemLink)
if not isValidLinkType then
return IIfA.EMPTY_STRING
end
if CanItemLinkBeVirtual(itemLink) then
-- Anything that goes in the craft bag - must be a crafting material
return GetItemIdString(itemLink)
else
-- Other oddball items that might have level info in them
local itemType, specializedItemType = GetItemLinkItemType(itemLink)
if (itemType == ITEMTYPE_TOOL and specializedItemType == SPECIALIZED_ITEMTYPE_TOOL) or
(itemType == ITEMTYPE_CONTAINER and specializedItemType == SPECIALIZED_ITEMTYPE_CONTAINER) or -- 4-6-19 AM - runeboxes appear to have level info in them
itemType == ITEMTYPE_LOCKPICK and specializedItemType == SPECIALIZED_ITEMTYPE_LOCKPICK or -- 11-19-24 Sharlikran - added because Lockpicks are no longer Tools
itemType == ITEMTYPE_SOUL_GEM and specializedItemType == SPECIALIZED_ITEMTYPE_SOUL_GEM or -- 11-19-24 Sharlikran - added because soul gems have level info
itemType == ITEMTYPE_RACIAL_STYLE_MOTIF or -- 9-12-16 AM - added because motifs now appear to have level info in them
itemType == ITEMTYPE_TROPHY or -- 11-19-24 Sharlikran - added because trophies can have level info
--[[ 12-15-24 Sharlikran - added because tabards have the guild ID as part of the itemLink
which causes there to be multiple copies. You cannot use the guild ID from the itemLink
to look up the guild name if you are not a member of the guild.
]]--
itemType == ITEMTYPE_TABARD or
itemType == ITEMTYPE_RECIPE then
return GetItemIdString(itemLink)
end
end
return itemLink
end
--@Baertram:
-- Added for other addons like FCOItemSaver to get the item instance or the unique ID
-->Returns itemInstance or uniqueId as 1st return value
-->Returns a boolean value as 2nd retun value: true if the bagId should build an itemInstance or unique ID / false if not
local function getItemInstanceOrUniqueId(bagId, slotIndex, itemLink)
local itemInstanceOrUniqueId = 0
local isBagToBuildItemInstanceOrUniqueId = false
if FCOIS == nil or FCOIS.getItemInstanceOrUniqueId == nil then return 0, false end
--Call function within addon FCOItemSaver, file FCOIS_OtherAddons.lua -> IIfA section
itemInstanceOrUniqueId, isBagToBuildItemInstanceOrUniqueId = FCOIS.getItemInstanceOrUniqueId(bagId, slotIndex, itemLink)
return itemInstanceOrUniqueId, isBagToBuildItemInstanceOrUniqueId
end
function IIfA:GetBagItemDetails(bagId, slotIndex)
local hasNoBagInfo = not bagId or not slotIndex
local hasNoActiveCompanion = bagId == BAG_COMPANION_WORN and not HasActiveCompanion()
if hasNoBagInfo or hasNoActiveCompanion then return end
-- Attempt to get the itemLink from the bag and slot
local itemLinkFromBag = GetItemLink(bagId, slotIndex, LINK_STYLE_BRACKETS)
local itemLink, itemKey = itemLinkFromBag, nil
-- Fetch item count from the bag and slot
local itemInfo = { GetItemInfo(bagId, slotIndex) }
local itemCount = itemInfo[2] or 0 -- meaning itemCount
-- Determine the itemKey based on the itemLink
itemKey = IIfA:GetItemKey(itemLinkFromBag)
-- "[GetBagItemDetails] - [First] itemLinkFromBag: '<<1>>', itemKey: '<<2>>', itemCount: <<3>>", itemLinkFromBag, itemKey, itemCount)
-- Check if bag slot info exists and update itemKey if necessary
local hasBagSlotInfo = bagId and slotIndex and IIfA.BagSlotInfo[bagId] ~= nil and IIfA.BagSlotInfo[bagId][slotIndex]
if #itemKey == 0 and hasBagSlotInfo then
itemKey = IIfA.BagSlotInfo[bagId][slotIndex]
end
-- IIfA:dm("Debug", "[GetBagItemDetails] - [Second] itemLinkFromBag: '<<1>>', itemKey: '<<2>>'", itemLinkFromBag, itemKey)
-- Check if the database has an itemLink for the itemKey and update itemLink
local DBv3 = IIFA_DATABASE[IIfA.currentAccount].servers[IIfA.currentServerType].DBv3 -- Adjusted to reference DBv3
local hasDatabaseItemLink = IIfA:isItemKey(itemKey) and DBv3[itemKey] and DBv3[itemKey].itemLink
if #itemLinkFromBag == 0 and hasDatabaseItemLink then
itemLink = DBv3[itemKey].itemLink
end
-- IIfA:dm("Debug", "[GetBagItemDetails] - [Third] itemLink: '<<1>>', itemKey: '<<2>>', itemLinkFromBag: '<<3>>'", itemLink, itemKey, itemLinkFromBag)
-- Fall back to using itemKey as itemLink if it qualifies
if itemLink ~= nil and #itemLink == 0 and IIfA:isItemLink(itemKey) then
itemLink = itemKey
end
-- Final debug output before returning results
-- IIfA:dm("Debug", "[GetBagItemDetails] - [Final] itemLink: '<<1>>', itemKey: '<<2>>', itemLinkFromBag: '<<3>>', itemCount: <<4>>", itemLink, itemKey, itemLinkFromBag, itemCount)
-- Return all computed values
return itemLink, itemKey, itemLinkFromBag, itemCount
end
local function cleanupItemLocation(DBitem, location, bagId, slotId)
local locationsData = DBitem and DBitem.locations and DBitem.locations[location]
if not locationsData then
DBitem.locations = DBitem.locations or {}
DBitem.locations[location] = DBitem.locations[location] or { bagID = bagId, bagSlot = {} }
end
-- Clean up DBitem locations first
if DBitem.locations[location] and DBitem.locations[location].bagSlot then
DBitem.locations[location].bagSlot[slotId] = nil
-- Remove location if bagSlot becomes empty
if next(DBitem.locations[location].bagSlot) == nil then
DBitem.locations[location] = nil
end
end
IIfA:ClearBagSlotInfo(bagId, slotId)
-- Ensure DBitem is saved back after cleanup, so changes are reflected
return DBitem
end
local function handleStaleDataCleanup(DBv3, storedKey, location, bagId, slotId, itemLinkSlotInfo)
-- Cleanup stale data
local oldItemData = DBv3[storedKey] or {}
local updatedData = cleanupItemLocation(oldItemData, location, bagId, slotId) -- clean up previous itemData
DBv3[storedKey] = updatedData -- the updated itemData keeping existing data if any
local itemKey = IIfA:GetItemKey(itemLinkSlotInfo)
local filterType = GetItemFilterTypeInfo(bagId, slotId) or 0
local itemQuality = GetItemLinkDisplayQuality(itemLinkSlotInfo)
local itemName = getItemName(bagId, slotId, itemLinkSlotInfo)
local itemSlotCount = getItemCount(bagId, slotId)
-- Initialize DBitem with the new information using the new itemKey and location
local newItemData = DBv3[itemKey] or {}
newItemData.filterType = filterType
newItemData.itemQuality = itemQuality
newItemData.itemName = itemName
newItemData.locations = newItemData.locations or {}
newItemData.locations[location] = newItemData.locations[location] or { bagID = bagId, bagSlot = {} }
newItemData.locations[location].bagSlot[slotId] = itemSlotCount or 0
IIfA.BagSlotInfo[bagId][slotId] = itemKey
return newItemData, itemKey -- Return the updated DBitem
end
local function ItemAttributesChanged(storedItemKey, currentItemLink)
-- Ensure storedKey is valid and is an item link
if not storedItemKey or not IIfA:isItemLink(storedItemKey) then
return false -- No stale data if storedKey is not an item link
end
-- If the stored key matches the current item link, no update needed
if storedItemKey == currentItemLink then
return false
end
-- Compare attributes of the stored and current item links
if GetItemLinkItemId(storedItemKey) ~= GetItemLinkItemId(currentItemLink) then return true end
if GetItemLinkDisplayQuality(storedItemKey) ~= GetItemLinkDisplayQuality(currentItemLink) then return true end
if GetItemLinkTraitType(storedItemKey) ~= GetItemLinkTraitType(currentItemLink) then return true end
if GetItemLinkRequiredLevel(storedItemKey) ~= GetItemLinkRequiredLevel(currentItemLink) then return true end
if GetItemLinkRequiredChampionPoints(storedItemKey) ~= GetItemLinkRequiredChampionPoints(currentItemLink) then return true end
if GetItemLinkTraitType(storedItemKey) ~= GetItemLinkTraitType(currentItemLink) then return true end
if GetItemLinkAppliedEnchantId(storedItemKey) ~= GetItemLinkAppliedEnchantId(currentItemLink) then return true end
return false -- No stale data detected
end
function IIfA:EvalBagItem(bagId, slotId)
-- Early exit if bagId is not tracked
if not IIfA.trackedBags[bagId] then return end
-- Ensure database is initialized
local DBv3 = IIFA_DATABASE[IIfA.currentAccount].servers[IIfA.currentServerType].DBv3
local itemSlotCount = getItemCount(bagId, slotId)
local storedKey = IIfA:GetBagSlotInfo(bagId, slotId)
-- Get the item's location
local location = getDatabaseItemLocation(bagId)
if location == IIfA.EMPTY_STRING or location == nil then
storedKey = storedKey or "[Empty String or Nil for storedKey]"
location = location or "[Empty String or Nil for location]"
IIfA:dm("Warn", "[EvalBagItem] Error: location: '<<1>>' is not valid! bagId: <<2>>, slotId: <<3>>, storedKey: '<<4>>'", location, bagId, slotId, storedKey)
return
end
-- Ensure itemLink is valid
local itemLink = GetItemLink(bagId, slotId, LINK_STYLE_BRACKETS)
local hasNoBagSlotData = (not itemLink or itemLink == "") and itemSlotCount <= 0
local shouldClearDatabaseLocations = storedKey and hasNoBagSlotData and (IIfA:isItemKey(storedKey) or IIfA:isItemLink(storedKey))
if DBv3 and DBv3[storedKey] and shouldClearDatabaseLocations then
DBv3[storedKey] = cleanupItemLocation(DBv3[storedKey], location, bagId, slotId)
IIfA:dm("Warn", "[EvalBagItem] Invalid data for bagId <<1>>, slotId <<2>>, clearing stored info for: '<<3>>', itemLink '<<4>>', itemSlotCount <<5>>, location '<<6>>'.", bagId, slotId, storedKey, itemLink, itemSlotCount, location)
return
end
if not itemLink or #itemLink == 0 then
IIfA:dm("Warn", "[EvalBagItem] itemLink not defined! storedKey '<<1>>', itemLink '<<2>>', itemSlotCount <<3>>, location '<<4>>', bag <<5>>, slot <<6>>", storedKey or "[Empty String or Nil for storedKey]", itemLink, itemSlotCount, location or "[Empty String or Nil for location]", bagId, slotId)
return
end -- Exit if invalid
-- Get or determine the item name
local itemName = getItemName(bagId, slotId, itemLink)
-- Ensure itemKey is valid
local itemKey = IIfA:GetItemKey(itemLink)
if not itemKey or #itemKey == 0 then
if storedKey then itemKey = IIfA.BagSlotInfo[bagId][slotId] end
if not itemKey or #itemKey == 0 then
IIfA:dm("Warn", "[EvalBagItem] itemKey not defined! storedKey '<<1>>', itemLink '<<2>>', itemSlotCount <<3>>, location '<<4>>', bag <<5>>, slot <<6>>", storedKey or "[Empty String or Nil for storedKey]", itemLink, itemSlotCount, location or "[Empty String or Nil for location]", bagId, slotId)
return
end -- Exit if still invalid
end
IIfA:SetBagSlotInfo(bagId, slotId, itemKey)
--[[ We are simply updating the current DBitem or DBv3[itemKey]
For that reason a helper function is not needed because ultimately
we are only updating the count. The rest of the data will most likely
be set already. ]]--
local DBitem = DBv3[itemKey] or {}
DBitem.filterType = DBitem.filterType or GetItemFilterTypeInfo(bagId, slotId) or 0
DBitem.itemQuality = DBitem.itemQuality or GetItemLinkDisplayQuality(itemLink)
DBitem.itemName = DBitem.itemName or itemName
DBitem.locations = DBitem.locations or {}