-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBankManager.lua
2864 lines (2332 loc) · 110 KB
/
BankManager.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
--[[
-------------------------------------------------------------------------------
-- BankManager, by Ayantir
-------------------------------------------------------------------------------
This software is under : CreativeCommons CC BY-NC-SA 4.0
Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)
You are free to:
Share — copy and redistribute the material in any medium or format
Adapt — remix, transform, and build upon the material
The licensor cannot revoke these freedoms as long as you follow the license terms.
Under the following terms:
Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
NonCommercial — You may not use the material for commercial purposes.
ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.
No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.
Please read full licence at :
http://creativecommons.org/licenses/by-nc-sa/4.0/legalcode
]]
-- Global Vars
local LAM2 = LibAddonMenu2
local db = { }
local ADDON_NAME = "BankManagerRevived"
local displayName = "|c3366FFBank|r Manager |c990000Revived|r |cF4EE42(Jewelry Crafting fix)|r"
local ADDON_AUTHOR = "|cFF9B15Sharlikran|r, Lexynide, SnowmanDK, Ayantir, Eldrni, Todo"
local ADDON_VERSION = "1.70"
local ADDON_WEBSITE = "https://www.esoui.com/downloads/info2249-BankManagerRevivedJewelryCraftingfix.html"
local activeBankBag = 0
local isBanking = false
local actualProfile = 1
local inProgress = false
local panel
local guildList
local checkingGBank
local currentGBank
local currentGBankName
local restartFromAtGBank
local hasAnyPullToDo
local hasAnySpecialPullToDo
local qtyMovedToGBank = 0
local countMovedToGBank = 0
local dataSorted
local isESOPlusSubscriber
local ACTION_NOTSET = 1
local ACTION_PUSH = 2
local ACTION_PULL = 3
local ACTION_PUSH_GBANK = 4
local ACTION_PUSH_BOTH = 5
local function GetActionName(action)
local actionTable = {
[ACTION_NOTSET] = "ACTION_NOTSET",
[ACTION_PUSH] = "ACTION_PUSH",
[ACTION_PULL] = "ACTION_PULL",
[ACTION_PUSH_GBANK] = "ACTION_PUSH_GBANK",
[ACTION_PUSH_BOTH] = "ACTION_PUSH_BOTH",
}
return actionTable[action]
end
--[[TODO Optional Keyword, Returns true when keywordCondition.acceptedKeyword[arg1] is true ]]--
local BMR_RULEWRITER_VALUE_OPTIONAL_KEYWORD = 1
--[[TODO With Operator, Returns true when keywordCondition.acceptedKeyword[arg1] is true ]]--
--[[TODO Why is only "With Operator" used for GetRuleWriterCondition ]]--
local BMR_RULEWRITER_VALUE_WITH_OPERATOR = 2
--[[TODO Without Operator, second argument is converted to a number. Returns true if number is between 1 and 10000]]--
local BMR_RULEWRITER_VALUE_WITHOUT_OPERATOR = 3
--[[TODO Nothing, added because it wasn't defined. Requires 2 arguments and returns true if both false]]--
local BMR_RULEWRITER_VALUE_NOTHING = 4
local BMR_ITEMLINK = 1
local BMR_BAG_AND_SLOT = 2
local BMR_ITEMTYPE = 3
local BMR_ITEMTYPE_SPECIALIZED = 4
--local startTimeInMs = 0
--[[
BAG_BACKPACK 1
BAG_BANK 2
BAG_GUILDBANK 3
BAG_SUBSCRIBER_BANK 6
BAG_HOUSE_BANK_ONE 7
BAG_HOUSE_BANK_TWO 8
BAG_HOUSE_BANK_THREE 9
BAG_HOUSE_BANK_FOUR 10
BAG_HOUSE_BANK_FIVE 11
BAG_HOUSE_BANK_SIX 12
BAG_HOUSE_BANK_SEVEN 13
BAG_HOUSE_BANK_EIGHT 14
BAG_HOUSE_BANK_NINE 15
BAG_HOUSE_BANK_TEN 16
* IsBankOpen()
** _Returns:_ *bool* _isBankOpen_
* GetBankingBag()
** _Returns:_ *[Bag|#Bag]* _bankingBag_
* IsGuildBankOpen()
** _Returns:_ *bool* _isGuildBankOpen_
]]--
-- Array of queues for moving items to handle bag/bank capacity limits
BankManagerRevived = {}
BankManagerRevived.a_test = {} -- for testing and not spamming to chat
local pushQueue = {}
local pullQueue = {}
local movedItems = {
[BAG_BACKPACK] = {},
[BAG_BANK] = {},
[BAG_GUILDBANK] = {},
[BAG_SUBSCRIBER_BANK] = {},
[BAG_HOUSE_BANK_ONE] = {},
[BAG_HOUSE_BANK_TWO] = {},
[BAG_HOUSE_BANK_THREE] = {},
[BAG_HOUSE_BANK_FOUR] = {},
[BAG_HOUSE_BANK_FIVE] = {},
[BAG_HOUSE_BANK_SIX] = {},
[BAG_HOUSE_BANK_SEVEN] = {},
[BAG_HOUSE_BANK_EIGHT] = {},
[BAG_HOUSE_BANK_NINE] = {},
[BAG_HOUSE_BANK_TEN] = {},
}
-- Defaults structure for SV
-- memory is a bit wasted here, still need to try to find how to dynamically build defaults after the SV pull from file
local BMR_MAX_PROFILES = 9 -- Adjust as needed
local defaults = {
worldname = GetWorldName(),
actualProfile = {},
globalAddonProfile = 1,
gui_x = -600,
gui_y = -400,
profiles = {} -- Start with an empty table
}
-- Populate the profiles table with default values using a loop
do
for i = 1, BMR_MAX_PROFILES do
defaults.profiles[i] = {
name = "",
defined = (i == 1), -- First profile is defined, others are not
autoTransfert = true,
detailledDisplay = true,
summary = true,
protected = true,
moved = true,
detailledNotMoved = true,
initialWaitInSecs = 2,
overfill = 0,
pauseInMs = 0,
userRules = "",
userRulesAfter = false,
}
end
end
-------------------------------------------------
----- Logger Function -----
-------------------------------------------------
BankManagerRevived.show_log = false
if LibDebugLogger then
BankManagerRevived.logger = LibDebugLogger.Create(ADDON_NAME)
end
local logger
local viewer
if DebugLogViewer then viewer = true else viewer = false end
if LibDebugLogger then logger = true else logger = false end
local function create_log(log_type, log_content)
if not viewer and log_type == "Info" then
CHAT_ROUTER:AddSystemMessage(log_content)
return
end
if not BankManagerRevived.show_log then return end
if logger and log_type == "Debug" then
BankManagerRevived.logger:Debug(log_content)
end
if logger and log_type == "Info" then
BankManagerRevived.logger:Info(log_content)
end
if logger and log_type == "Verbose" then
BankManagerRevived.logger:Verbose(log_content)
end
if logger and log_type == "Warn" then
BankManagerRevived.logger:Warn(log_content)
end
end
local function emit_message(log_type, text)
if (text == "") then
text = "[Empty String]"
end
create_log(log_type, text)
end
local function emit_table(log_type, t, indent, table_history)
indent = indent or "."
table_history = table_history or {}
if not t then
emit_message(log_type, indent .. "[Nil Table]")
return
end
if next(t) == nil then
emit_message(log_type, indent .. "[Empty Table]")
return
end
for k, v in pairs(t) do
local vType = type(v)
emit_message(log_type, indent .. "(" .. vType .. "): " .. tostring(k) .. " = " .. tostring(v))
if (vType == "table") then
if (table_history[v]) then
emit_message(log_type, indent .. "Avoiding cycle on table...")
else
table_history[v] = true
emit_table(log_type, v, indent .. " ", table_history)
end
end
end
end
local function emit_userdata(log_type, udata)
local function_limit = 5 -- Limit the number of functions displayed
local total_limit = 10 -- Total number of entries to display (functions + non-functions)
local function_count = 0 -- Counter for functions
local entry_count = 0 -- Counter for total entries displayed
emit_message(log_type, "Userdata: " .. tostring(udata))
local meta = getmetatable(udata)
if meta and meta.__index then
for k, v in pairs(meta.__index) do
-- Show function name for functions
if type(v) == "function" then
if function_count < function_limit then
emit_message(log_type, " Function: " .. tostring(k)) -- Function name
function_count = function_count + 1
entry_count = entry_count + 1
end
elseif type(v) ~= "function" then
-- For non-function entries (like tables or variables), show them
emit_message(log_type, " " .. tostring(k) .. ": " .. tostring(v))
entry_count = entry_count + 1
end
-- Stop when we've reached the total limit
if entry_count >= total_limit then
emit_message(log_type, " ... (output truncated due to limit)")
break
end
end
else
emit_message(log_type, " (No detailed metadata available)")
end
end
local function contains_placeholders(str)
return type(str) == "string" and str:find("<<%d+>>")
end
function BankManagerRevived:dm(log_type, ...)
local num_args = select("#", ...)
local first_arg = select(1, ...) -- The first argument is always the message string
-- Check if the first argument is a string with placeholders
if type(first_arg) == "string" and contains_placeholders(first_arg) then
-- Extract any remaining arguments for zo_strformat (after the message string)
local remaining_args = { select(2, ...) }
-- Format the string with the remaining arguments
local formatted_value = ZO_CachedStrFormat(first_arg, unpack(remaining_args))
-- Emit the formatted message
emit_message(log_type, formatted_value)
else
-- Process other argument types (userdata, tables, etc.)
for i = 1, num_args do
local value = select(i, ...)
if type(value) == "userdata" then
emit_userdata(log_type, value)
elseif type(value) == "table" then
emit_table(log_type, value)
else
emit_message(log_type, tostring(value))
end
end
end
end
-- BMR code
-- Display a movement
local function PrintItemsToBag(itemLink, itemIcon, bagIdTo, qty, currentGBankName)
CHAT_ROUTER:AddSystemMessage(zo_strformat(BMR_ACTION_ITEMS_MOVED, zo_strformat(SI_TOOLTIP_ITEM_NAME, itemLink), itemIcon, qty, GetString("BMR_ACTION_ITEMS_MOVED_TO", bagIdTo), currentGBankName))
end
local function PrintItemsNotMovedToBag(itemLink, itemIcon, bagIdTo, qty, currentGBankName)
CHAT_ROUTER:AddSystemMessage(zo_strformat(BMR_ACTION_ITEMS_NOT_MOVED, zo_strformat(SI_TOOLTIP_ITEM_NAME, itemLink), itemIcon, qty, GetString("BMR_ACTION_ITEMS_MOVED_TO", bagIdTo), currentGBankName))
end
-- Display movement summary
local function PrintSummaryToBag(bagIdTo, countMoved, qtyMoved, currentGBankName)
CHAT_ROUTER:AddSystemMessage(zo_strformat(BMR_ACTION_ITEMS_SUMMARY, countMoved, qtyMoved, GetString("BMR_ACTION_ITEMS_MOVED_TO", bagIdTo), currentGBankName))
end
-- Display currency movement
local function PrintCurrencyToBank(currencyType, qtyMoved)
CHAT_ROUTER:AddSystemMessage(zo_strformat(BMR_ACTION_CURRENCY_SUMMARY, ZO_CurrencyControl_FormatCurrencyAndAppendIcon(qtyMoved, true, currencyType), GetString(BMR_ACTION_ITEMS_MOVED_TO2)))
end
-- Display currency movement
local function PrintCurrencyToBag(currencyType, qtyMoved)
CHAT_ROUTER:AddSystemMessage(zo_strformat(BMR_ACTION_CURRENCY_SUMMARY, ZO_CurrencyControl_FormatCurrencyAndAppendIcon(qtyMoved, true, currencyType), GetString(BMR_ACTION_ITEMS_MOVED_TO1)))
end
local function Sanitize(value)
return value:gsub("[-*+?^$().[%]%%]", "%%%0") -- escape meta characters
end
local function BuildWritsItems()
local shouldBeWatched
BankManagerRules.static.special.writsQuests = {}
BankManagerRules.static.special.writsQuestsGlyphs = {} -- Bit dirty, see how to improve - BankManagerRules.lua#271
BankManagerRules.static.special.writsQuestsPots = {}
for journalQuestIndex = 1, GetNumJournalQuests() do
if GetJournalQuestType(journalQuestIndex) == QUEST_TYPE_CRAFTING then
if GetJournalQuestNumSteps(journalQuestIndex) == QUEST_MAIN_STEP_INDEX then
for numConditions = 1, GetJournalQuestNumConditions(journalQuestIndex, QUEST_MAIN_STEP_INDEX) do
local conditionText, current, max, _, isComplete = GetJournalQuestConditionInfo(journalQuestIndex, QUEST_MAIN_STEP_INDEX, numConditions)
if conditionText ~= "" and current < max then
conditionText = string.gsub(conditionText, " ", " ") -- First is a NO-BREAK SPACE, 2nd a SPACE, found somes.
conditionText = Sanitize(conditionText)
table.insert(BankManagerRules.static.special.writsQuests, { text = conditionText, qtyToMove = max })
table.insert(BankManagerRules.static.special.writsQuestsGlyphs, { text = conditionText, qtyToMove = max })
table.insert(BankManagerRules.static.special.writsQuestsPots, { text = conditionText, qtyToMove = max })
shouldBeWatched = true
end
end
end
end
end
if not shouldBeWatched then
hasAnySpecialPullToDo = false
end
end
-- Reset all vars when finishing a GBank move
local function OnCloseProcessAtGBank()
restartFromAtGBank = nil
qtyMovedToGBank = 0
countMovedToGBank = 0
inProgress = false
pushQueue = {}
EVENT_MANAGER:UnregisterForEvent(ADDON_NAME, EVENT_GUILD_BANK_TRANSFER_ERROR)
EVENT_MANAGER:UnregisterForEvent(ADDON_NAME, EVENT_GUILD_BANK_ITEM_ADDED)
end
-- Build the push/pull array
local function queueAction(ruleName, bagId, slotId)
-- if activeBankBag ~= BAG_BACKPACK or activeBankBag ~= BAG_BANK or activeBankBag ~= BAG_GUILDBANK or activeBankBag ~= BAG_SUBSCRIBER_BANK then return end
local whichAction = db.profiles[actualProfile].rules[ruleName].action
if (whichAction == ACTION_PUSH or whichAction == ACTION_PUSH_GBANK or whichAction == ACTION_PUSH_BOTH) and bagId == BAG_BACKPACK then
-- Push item to bank
--BankManagerRevived:dm("Debug", string.format("BY ACTION: whichAction : %s ; ruleName: %s ; bagId: %s ; slotId: %s ; activeBankBag: %s", whichAction, ruleName, bagId, slotId, activeBankBag))
--d("ACTION " .. whichAction .. " " .. ruleName .. " " .. bagId .. " " .. slotId)
table.insert(pushQueue, { ruleName = ruleName, bagId = bagId, slotId = slotId, itemLink = GetItemLink(bagId, slotId), itemIcon = GetItemLinkInfo(GetItemLink(bagId, slotId)) })
elseif whichAction == ACTION_PULL and (bagId == BAG_BANK or bagId == BAG_SUBSCRIBER_BANK) then
-- Pull item to bank
--BankManagerRevived:dm("Debug", string.format("ACTION_PULL: whichAction : %s ; ruleName: %s ; bagId: %s ; slotId: %s ; activeBankBag: %s", whichAction, ruleName, bagId, slotId, activeBankBag))
--d("ACTION_PULL " .. ruleName .. " " .. bagId .. " " .. slotId)
table.insert(pullQueue, { ruleName = ruleName, bagId = bagId, slotId = slotId, itemLink = GetItemLink(bagId, slotId), itemIcon = GetItemLinkInfo(GetItemLink(bagId, slotId)) })
end
end
-- return true if item is protected
local function IsItemProtected(bagId, slotId)
-- ESOUI
if IsItemPlayerLocked(bagId, slotId) then
return true
end
--Item Saver support
if ItemSaver_IsItemSaved and ItemSaver_IsItemSaved(bagId, slotId) then
return true
end
--FCO ItemSaver support
if FCOIS and FCOIS.IsLocked then
return FCOIS.IsLocked(bagId, slotId)
end
--FilterIt support
if FilterIt and FilterIt.AccountSavedVariables and FilterIt.AccountSavedVariables.FilteredItems then
local sUniqueId = Id64ToString(GetItemUniqueId(bagId, slotId))
if FilterIt.AccountSavedVariables.FilteredItems[sUniqueId] then
return FilterIt.AccountSavedVariables.FilteredItems[sUniqueId] ~= FILTERIT_VENDOR
end
end
return false
end
-- To sort array
local function sortByKeyAndPosition(array)
local arrayTemp = {}
for key, data in pairs(array) do table.insert(arrayTemp, { key = key, data = data }) end
local function sortByPosition(a, b)
if not a.data.position and not b.data.position then return a.data.ruleName < b.data.ruleName end
if not a.data.position and b.data.position then return true end
if a.data.position and not b.data.position then return false end
if a.data.position and b.data.position then
return a.data.position < b.data.position
end
end
table.sort(arrayTemp, sortByPosition)
return arrayTemp
end
local function pairsByKeysAndPosition(array)
local i = 0
local iter = function()
i = i + 1
if array and array[i] then
return array[i].key, array[i].data
else
return
end
end
return iter
end
-- Check if slotId match a rule
local function prepareItem(bagId, slotId, checkingGBank)
local itemLinkMoveRestricted = false
local itemLink = GetItemLink(bagId, slotId)
-- Inits
if IsItemStolen(bagId, slotId) then itemLinkMoveRestricted = true end
if db.profiles[actualProfile].protected and IsItemProtected(bagId, slotId) then itemLinkMoveRestricted = true end
-- Cannot be moved to bank
if bagId == BAG_BACKPACK and GetItemLinkBindType(itemLink) == BIND_TYPE_ON_PICKUP_BACKPACK then itemLinkMoveRestricted = true end
-- Cannot be moved to GBank
if checkingGBank and GetItemLinkBindType(itemLink) == BIND_TYPE_ON_PICKUP then itemLinkMoveRestricted = true end
-- Might be BOE but item is Bound
if checkingGBank and IsItemLinkBound(itemLink) then itemLinkMoveRestricted = true end
-- Might be Unique and you can't store that in the Guild Bank
if checkingGBank and IsItemLinkUnique(itemLink) then itemLinkMoveRestricted = true end
if itemLinkMoveRestricted then return end
local itemMatch = false
local ruleMatch
-- For each item in bag, look all rules
for ruleName, ruleData in pairsByKeysAndPosition(dataSorted) do
local action = db.profiles[actualProfile].rules[ruleName].action or ACTION_NOTSET
local associatedGuild = db.profiles[actualProfile].rules[ruleName].associatedGuild
local actionAssigned = action ~= ACTION_NOTSET
local guildMatch = currentGBankName == associatedGuild
-- table.insert(BankManagerRevived.a_test, string.format(tostring(ruleName) .. ":" .. GetItemLinkName(itemLink) .. " : currentGBankName: %s : associatedGuild: %s", tostring(currentGBankName), tostring(associatedGuild)))
local actionPullValid = action == ACTION_PULL and (bagId == BAG_BANK or bagId == BAG_SUBSCRIBER_BANK)
local actionPushValid = action == ACTION_PUSH and bagId == BAG_BACKPACK
local actionPushGBankValid = guildMatch and action == ACTION_PUSH_GBANK and bagId == BAG_BACKPACK
local actionPushBothValid = action == ACTION_PUSH_BOTH and ((guildMatch and IsGuildBankOpen()) or IsBankOpen()) and bagId == BAG_BACKPACK
-- table.insert(BankManagerRevived.a_test, string.format(tostring(ruleName) .. ":" .. GetItemLinkName(itemLink) .. " : actionAssigned: %s : guildMatch: %s : actionPullValid: %s", tostring(actionAssigned), tostring(guildMatch), tostring(actionPullValid)))
-- table.insert(BankManagerRevived.a_test, string.format(tostring(ruleName) .. ":" .. GetItemLinkName(itemLink) .. " : actionPushValid: %s : actionPushGBankValid: %s : actionPushBothValid: %s", tostring(actionPushValid), tostring(actionPushGBankValid), tostring(actionPushBothValid)))
-- Check first if item didn't matched a previous rule
if not itemMatch then
local shouldMove = false
if action == ACTION_PULL then
if db.profiles[actualProfile].rules[ruleName].specialEnabled then
hasAnySpecialPullToDo = true
else
hasAnyPullToDo = true
end
end
if actionAssigned and (actionPullValid or actionPushValid or actionPushGBankValid or actionPushBothValid) then shouldMove = true end
-- If rule is well writen and set to do something
-- table.insert(BankManagerRevived.a_test, string.format(tostring(ruleName) .. ":" .. GetItemLinkName(itemLink) .. " : shouldMove: %s : action: %s", tostring(shouldMove), GetActionName(action)))
if ruleData.params and shouldMove then
for ruleParamIndex, ruleParamData in ipairs(ruleData.params) do
local funcToUse = ruleParamData.func -- Our fonction stored
local itemMatchValue
if funcToUse then
if ruleParamData.funcArgs == BMR_ITEMLINK then
-- Is item matching values ?
for funcChoices, funcMatches in ipairs(ruleParamData.values) do
if funcToUse(itemLink) == funcMatches then
itemMatchValue = true
end
end
elseif ruleParamData.funcArgs == BMR_ITEMTYPE then
for funcChoices, funcMatches in ipairs(ruleParamData.values) do
local itemType = funcToUse(itemLink)
if itemType == funcMatches then
itemMatchValue = true
end
end
elseif ruleParamData.funcArgs == BMR_ITEMTYPE_SPECIALIZED then
for funcChoices, funcMatches in ipairs(ruleParamData.values) do
local _, specializedItemType = funcToUse(itemLink)
if specializedItemType == funcMatches then
itemMatchValue = true
end
end
elseif ruleParamData.funcArgs == BMR_BAG_AND_SLOT then
for funcChoices, funcMatches in ipairs(ruleParamData.values) do
if funcToUse(bagId, slotId) == funcMatches then
itemMatchValue = true
end
end
end
end
-- The item didn't match our filter, don't try other params, go to next rule
if not itemMatchValue then
itemMatch = false
ruleMatch = nil
break
else
-- The item match our filter .. for now
itemMatch = true
ruleMatch = ruleName
--BankManagerRevived:dm("Debug", string.format("ITEM MATCH VALUE: itemLink : %s ; ( bagId: %s ; slotId: %s ) ; ruleMatch: %s ; ruleName / #: (%s , %s) activeBankBag: %s", itemLink, bagId, slotId, ruleMatch, ruleName, ruleParamIndex, activeBankBag))
--d(itemLink .. " (" .. bagId .. " " .. slotId.. ") ruleMatch:" .. ruleName .. " #" .. ruleParamIndex)
end
end -- end params loop
end
else
break
end
end
if itemMatch and ruleMatch ~= nil then
-- table.insert(BankManagerRevived.a_test, string.format(tostring(ruleMatch) .. ":" .. GetItemLinkName(itemLink) .. " itemMatch: %s", tostring(itemMatch)))
queueAction(ruleMatch, bagId, slotId)
end
end
-- Move all items defined in push/pull arrays
local function moveItems(errorReasonAtGBank)
BankManagerRevived:dm("Debug", "moveItems")
local atGuildBank = IsGuildBankOpen()
local atBank = IsBankOpen()
local bagIdOpen = GetBankingBag()
-- Our bagcache, because game don't have it in realtime
local tinyBagCache = {
[BAG_BACKPACK] = {},
[BAG_BANK] = {},
[BAG_GUILDBANK] = {},
[BAG_SUBSCRIBER_BANK] = {},
[BAG_HOUSE_BANK_ONE] = {},
[BAG_HOUSE_BANK_TWO] = {},
[BAG_HOUSE_BANK_THREE] = {},
[BAG_HOUSE_BANK_FOUR] = {},
[BAG_HOUSE_BANK_FIVE] = {},
[BAG_HOUSE_BANK_SIX] = {},
[BAG_HOUSE_BANK_SEVEN] = {},
[BAG_HOUSE_BANK_EIGHT] = {},
[BAG_HOUSE_BANK_NINE] = {},
[BAG_HOUSE_BANK_TEN] = {},
}
-- Our bagcache for qty, because game don't have it in realtime
local qtyBagCache = {}
-- Avoid checking first 230 slots if we already did it.
local tinyBagCacheFirstSlot = {
[BAG_BACKPACK] = 0,
[BAG_BANK] = 0,
[BAG_GUILDBANK] = 0,
[BAG_SUBSCRIBER_BANK] = 0,
[BAG_HOUSE_BANK_ONE] = 0,
[BAG_HOUSE_BANK_TWO] = 0,
[BAG_HOUSE_BANK_THREE] = 0,
[BAG_HOUSE_BANK_FOUR] = 0,
[BAG_HOUSE_BANK_FIVE] = 0,
[BAG_HOUSE_BANK_SIX] = 0,
[BAG_HOUSE_BANK_SEVEN] = 0,
[BAG_HOUSE_BANK_EIGHT] = 0,
[BAG_HOUSE_BANK_NINE] = 0,
[BAG_HOUSE_BANK_TEN] = 0,
}
local freeSlots = {
[BAG_BACKPACK] = 0,
[BAG_BANK] = 0,
[BAG_GUILDBANK] = 0,
[BAG_SUBSCRIBER_BANK] = 0,
[BAG_HOUSE_BANK_ONE] = 0,
[BAG_HOUSE_BANK_TWO] = 0,
[BAG_HOUSE_BANK_THREE] = 0,
[BAG_HOUSE_BANK_FOUR] = 0,
[BAG_HOUSE_BANK_FIVE] = 0,
[BAG_HOUSE_BANK_SIX] = 0,
[BAG_HOUSE_BANK_SEVEN] = 0,
[BAG_HOUSE_BANK_EIGHT] = 0,
[BAG_HOUSE_BANK_NINE] = 0,
[BAG_HOUSE_BANK_TEN] = 0,
}
-- Items moved in psuh + pull actions
local itemsMoved = 0
local qtyMoved = 0
local countMoved = 0
local pushInProgress = true
-- Thanks Merlight & circonian, FindFirstEmptySlotInBag don't refresh in realtime.
local function FindEmptySlotInBag(bagId)
BankManagerRevived:dm("Debug", "FindEmptySlotInBag")
if isESOPlusSubscriber and bagId == BAG_BANK and freeSlots[bagId] == 0 then
bagId = BAG_SUBSCRIBER_BANK
end
--d("FindEmptySlotInBag (" .. bagId .. ")" .. " ; isESOPlusSubscriber=" .. tostring(isESOPlusSubscriber))
if atGuildBank or (bagId == BAG_BANK and not isESOPlusSubscriber and freeSlots[bagId] > db.profiles[actualProfile].overfill) or (isESOPlusSubscriber and (bagId == BAG_BANK or bagId == BAG_SUBSCRIBER_BANK) and freeSlots[BAG_SUBSCRIBER_BANK] > db.profiles[actualProfile].overfill) or (bagId == BAG_BACKPACK and freeSlots[bagId] > db.profiles[actualProfile].overfill) then
for slotIndex = tinyBagCacheFirstSlot[bagId], (GetBagSize(bagId) - 1) do
if not SHARED_INVENTORY.bagCache[bagId][slotIndex] and not tinyBagCache[bagId][slotIndex] then
--d("tinyBagCache -> " .. bagId .. " " .. slotIndex)
tinyBagCache[bagId][slotIndex] = true
tinyBagCacheFirstSlot[bagId] = slotIndex + 1
freeSlots[bagId] = freeSlots[bagId] - 1
return bagId, slotIndex
end
end
end
return bagId
end
-- Return the slotIndex if the stack is not fulfilled or a newslot
local function FindItemInBag(bagIdTo, bagIdFrom, slotIdFrom, maxStack)
BankManagerRevived:dm("Debug", "FindItemInBag")
--d("FindItemInBag")
local itemInstanceId = SHARED_INVENTORY.bagCache[bagIdFrom][slotIdFrom].itemInstanceId
for slotId, data in pairs(SHARED_INVENTORY.bagCache[bagIdTo]) do
if data.itemInstanceId == itemInstanceId and data.stackCount < maxStack then
return bagIdTo, data.slotIndex
end
end
if bagIdTo == BAG_BANK then
for slotId, data in pairs(SHARED_INVENTORY.bagCache[BAG_SUBSCRIBER_BANK]) do
if data.itemInstanceId == itemInstanceId and data.stackCount < maxStack then
return BAG_SUBSCRIBER_BANK, data.slotIndex
end
end
end
-- Not found or all stack are full
return FindEmptySlotInBag(bagIdTo)
end
local function FindDestSlotInBag(stackCountTo, bagIdTo, bagIdFrom, slotIdFrom, maxStack)
BankManagerRevived:dm("Debug", "FindDestSlotInBag")
--d("FindDestSlotInBag " .. bagIdFrom .. " " .. slotIdFrom)
if stackCountTo > 0 then
return FindItemInBag(bagIdTo, bagIdFrom, slotIdFrom, maxStack)
else
return FindEmptySlotInBag(bagIdTo)
end
end
local function moveItemInSlot(bagIdFrom, slotIdFrom, bagIdTo, slotIdTo, qtyToMove, itemLink)
BankManagerRevived:dm("Debug", "moveItemInSlot")
if IsProtectedFunction("RequestMoveItem") then
CallSecureProtected("RequestMoveItem", bagIdFrom, slotIdFrom, bagIdTo, slotIdTo, qtyToMove)
else
RequestMoveItem(bagIdFrom, slotIdFrom, bagIdTo, slotIdTo, qtyToMove)
end
-- qtyBagCache[itemLink] is always set, because set just before.
qtyBagCache[itemLink][bagIdTo] = qtyBagCache[itemLink][bagIdTo] + qtyToMove
qtyBagCache[itemLink][bagIdFrom] = qtyBagCache[itemLink][bagIdFrom] - qtyToMove
-- to check
return true
end
-- Move a slot or a partial slot to GBank
local function moveItemInGBank(bagIdFrom, slotIdFrom, qtyToMove, itemLink)
BankManagerRevived:dm("Debug", "moveItemInGBank")
--d("moveItemInGBank")
if qtyToMove then
--Partial slot, we need an empty slot
local emptySlot = FindEmptySlotInBag(bagIdFrom)
-- Local bag can be full
if emptySlot then
moveItemInSlot(bagIdFrom, slotIdFrom, bagIdFrom, emptySlot, qtyToMove, itemLink)
TransferToGuildBank(bagIdFrom, emptySlot)
end
else
TransferToGuildBank(bagIdFrom, slotIdFrom)
end
-- Temporary
return true
end
local function StackInfoInBag(bagToCheck, slotIdFrom, bagIdFrom, itemLink)
BankManagerRevived:dm("Debug", "StackInfoInBag")
local stackCountBackpack, stackCountBank
if not qtyBagCache[itemLink] then
stackCountBackpack, stackCountBank = GetItemLinkStacks(itemLink) -- Not updated in realtime
qtyBagCache[itemLink] = {}
qtyBagCache[itemLink][BAG_BACKPACK] = stackCountBackpack
qtyBagCache[itemLink][BAG_BANK] = stackCountBank
qtyBagCache[itemLink][BAG_SUBSCRIBER_BANK] = stackCountBank
else
stackCountBackpack = qtyBagCache[itemLink][BAG_BACKPACK]
stackCountBank = qtyBagCache[itemLink][BAG_BANK] + qtyBagCache[itemLink][BAG_SUBSCRIBER_BANK]
end
local stackSize, maxStack = GetSlotStackSize(bagIdFrom, slotIdFrom)
if bagToCheck == BAG_BACKPACK then
return stackCountBackpack >= maxStack, stackSize, maxStack, stackCountBackpack, stackCountBank
elseif bagToCheck == BAG_BANK or bagToCheck == BAG_SUBSCRIBER_BANK then
return stackCountBank >= maxStack, stackSize, maxStack, stackCountBackpack, stackCountBank
end
end
local function RestackBags()
BankManagerRevived:dm("Debug", "RestackBags")
-- Sometimes needed (2 stacks, first 79, 2nd 200, but limit is 200 -> will push 79 , then 121, resulting 2 stacks), maybe need to optimize tinyBagCache
StackBag(BAG_BANK)
StackBag(BAG_SUBSCRIBER_BANK)
StackBag(BAG_BACKPACK)
end
local function FinishBankMoves()
BankManagerRevived:dm("Debug", "FinishBankMoves")
hasAnyPullToDo = nil
pushQueue = {}
pullQueue = {}
movedItems = {
[BAG_BACKPACK] = {},
[BAG_BANK] = {},
[BAG_GUILDBANK] = {},
[BAG_SUBSCRIBER_BANK] = {},
[BAG_HOUSE_BANK_ONE] = {},
[BAG_HOUSE_BANK_TWO] = {},
[BAG_HOUSE_BANK_THREE] = {},
[BAG_HOUSE_BANK_FOUR] = {},
[BAG_HOUSE_BANK_FIVE] = {},
[BAG_HOUSE_BANK_SIX] = {},
[BAG_HOUSE_BANK_SEVEN] = {},
[BAG_HOUSE_BANK_EIGHT] = {},
[BAG_HOUSE_BANK_NINE] = {},
[BAG_HOUSE_BANK_TEN] = {},
}
inProgress = false
end
local function tryMoveSlots(data, bagIdTo, restartAt)
BankManagerRevived:dm("Debug", "tryMoveSlots")
-- Need to push/pull?
if not restartAt then restartAt = 1 end
local moveData = data[restartAt]
if moveData then
-- Should not exceed 100 in a move or game will kick you
if db.profiles[actualProfile].pauseInMs >= 100 or (itemsMoved < 98 and db.profiles[actualProfile].pauseInMs < 100) then
--d(moveData.ruleName .. " will check qty and if, move " .. GetItemName(moveData.bagId, moveData.slotId))
-- Is slot at max size in bank ?
local isFullStack, stackSize, maxStack, stackCountBackpack, stackCountBank = StackInfoInBag(bagIdTo, moveData.slotId, moveData.bagId, moveData.itemLink)
local itemMoved = false
local qtyToMove, destSlot
if BankManagerRules.data[moveData.ruleName].isSpecial then
if bagIdTo == BAG_BACKPACK then
qtyToMove = BankManagerRules.static.special[moveData.ruleName][moveData.itemLink]
bagIdTo, destSlot = FindDestSlotInBag(stackCountBackpack, bagIdTo, moveData.bagId, moveData.slotId, maxStack)
end
--d("qtyToMove " .. qtyToMove .. " destSlot " .. tostring(destSlot))
if destSlot then
--d(moveData.ruleName .. " is moving " .. GetItemName(moveData.bagId, moveData.slotId) .. " (not full stack)")
itemMoved = moveItemInSlot(moveData.bagId, moveData.slotId, bagIdTo, destSlot, qtyToMove, moveData.itemLink)
elseif db.profiles[actualProfile].detailledNotMoved then
PrintItemsNotMovedToBag(moveData.itemLink, moveData.itemIcon, bagIdTo, qtyToMove)
end
elseif not isFullStack and db.profiles[actualProfile].rules[moveData.ruleName].onlyIfNotFullStack then
if bagIdTo == BAG_BACKPACK then
qtyToMove = math.min(stackSize, (maxStack - stackCountBackpack))
bagIdTo, destSlot = FindDestSlotInBag(stackCountBackpack, bagIdTo, moveData.bagId, moveData.slotId, maxStack)
elseif bagIdTo == BAG_BANK or bagIdTo == BAG_SUBSCRIBER_BANK then
qtyToMove = math.min(stackSize, (maxStack - stackCountBank))
bagIdTo, destSlot = FindDestSlotInBag(stackCountBank, bagIdTo, moveData.bagId, moveData.slotId, maxStack) -- bagIdTo can change because of BAG_SUBSCRIBER_BANK
end
--d("qtyToMove " .. tostring(qtyToMove) .. " destSlot " .. tostring(bagIdTo) .. "/" .. tostring(destSlot))
if destSlot then
--d(moveData.ruleName .. " is moving " .. GetItemName(moveData.bagId, moveData.slotId) .. " (not full stack)")
itemMoved = moveItemInSlot(moveData.bagId, moveData.slotId, bagIdTo, destSlot, qtyToMove, moveData.itemLink)
elseif db.profiles[actualProfile].detailledNotMoved then
PrintItemsNotMovedToBag(moveData.itemLink, moveData.itemIcon, bagIdTo, qtyToMove)
end
elseif not db.profiles[actualProfile].rules[moveData.ruleName].onlyIfNotFullStack then
-- Still don't know why.
if type(db.profiles[actualProfile].rules[moveData.ruleName].onlyStacks) == "boolean" then
db.profiles[actualProfile].rules[moveData.ruleName].onlyStacks = 1
end
local stackCountInBag
-- got 80 to push, bank got 350, stack is 200, 1st stack will receive 50, 2nd stack: 30 if maxStack = 3, or 50 and 0 because of maxStack = 2
if bagIdTo == BAG_BACKPACK then
stackCountInBag = stackCountBackpack
elseif bagIdTo == BAG_BANK or bagIdTo == BAG_SUBSCRIBER_BANK then
stackCountInBag = stackCountBank
end
local maxQtyAuthorized = db.profiles[actualProfile].rules[moveData.ruleName].onlyStacks * maxStack
qtyToMove = math.min(stackSize, maxStack - (stackCountInBag % maxStack))
if qtyToMove + stackCountInBag <= maxQtyAuthorized then
bagIdTo, destSlot = FindDestSlotInBag(stackCountInBag, bagIdTo, moveData.bagId, moveData.slotId, maxStack)
--d("maxQtyAuthorized: " .. maxQtyAuthorized .. " stackCountInBag: " .. stackCountInBag)
if qtyToMove == stackSize or (qtyToMove < stackSize and qtyToMove + stackCountInBag == maxQtyAuthorized) then
-- 1 push to do
--d("1 push to do")
--d("qtyToMove " .. qtyToMove .. " destSlot " .. tostring(destSlot))
if stackCountInBag + qtyToMove <= maxQtyAuthorized then
if destSlot then
itemMoved = moveItemInSlot(moveData.bagId, moveData.slotId, bagIdTo, destSlot, qtyToMove, moveData.itemLink)
elseif db.profiles[actualProfile].detailledNotMoved then
PrintItemsNotMovedToBag(moveData.itemLink, moveData.itemIcon, bagIdTo, qtyToMove)
end
end
else
--d("2 push to do?")
--d("qtyToMove " .. qtyToMove .. " destSlot " .. tostring(destSlot))
-- 2 push to do, first will fulfil, 2nd will take the modulo
if stackCountInBag + qtyToMove <= maxQtyAuthorized then
--Already too late!
if destSlot then
--d("2 push to do -> destSlot1:" .. destSlot)
itemMoved = moveItemInSlot(moveData.bagId, moveData.slotId, bagIdTo, destSlot, qtyToMove, moveData.itemLink)
elseif db.profiles[actualProfile].detailledNotMoved then
PrintItemsNotMovedToBag(moveData.itemLink, moveData.itemIcon, bagIdTo, qtyToMove)
end
-- Maybe move1 hit the limit?
if stackCountInBag + qtyToMove < db.profiles[actualProfile].rules[moveData.ruleName].onlyStacks * maxStack then
destSlot = FindEmptySlotInBag(bagIdTo)
if destSlot then
--d("2 push to do -> destSlot2:" .. destSlot)
itemMoved = moveItemInSlot(moveData.bagId, moveData.slotId, bagIdTo, destSlot, stackSize - qtyToMove, moveData.itemLink)
qtyToMove = stackSize -- to Display the correct value
elseif db.profiles[actualProfile].detailledNotMoved then
PrintItemsNotMovedToBag(moveData.itemLink, moveData.itemIcon, bagIdTo, qtyToMove)
end
end
end
end
end
end
if itemMoved then
qtyMoved = qtyMoved + qtyToMove
countMoved = countMoved + 1
itemsMoved = itemsMoved + 1
if db.profiles[actualProfile].detailledDisplay then
PrintItemsToBag(moveData.itemLink, moveData.itemIcon, bagIdTo, qtyToMove)
end
end
zo_callLater(function() tryMoveSlots(data, bagIdTo, restartAt + 1) end, db.profiles[actualProfile].pauseInMs)
else
CHAT_ROUTER:AddSystemMessage(GetString(BMR_ZOS_LIMITATIONS))
pushInProgress = false -- Don't do pull
-- End of moves
if qtyMoved > 0 then
if db.profiles[actualProfile].summary then
PrintSummaryToBag(bagIdTo, countMoved, qtyMoved)
end
RestackBags()
end
FinishBankMoves()
return
end
elseif pushInProgress then
-- End of push
pushInProgress = false
if qtyMoved > 0 then
if db.profiles[actualProfile].summary then
PrintSummaryToBag(bagIdTo, countMoved, qtyMoved)
end
end
qtyMoved = 0
countMoved = 0
freeSlots[BAG_BACKPACK] = GetNumBagFreeSlots(BAG_BACKPACK)
zo_callLater(function() tryMoveSlots(pullQueue, BAG_BACKPACK) end, db.profiles[actualProfile].pauseInMs)
else
-- End of pull
if qtyMoved > 0 then
if db.profiles[actualProfile].summary then
PrintSummaryToBag(bagIdTo, countMoved, qtyMoved)
end
RestackBags()
end
FinishBankMoves()
end
end
local function doSingleMove(moveData)
BankManagerRevived:dm("Debug", "doSingleMove")
local associatedGuild = db.profiles[actualProfile].rules[moveData.ruleName].associatedGuild
local action = db.profiles[actualProfile].rules[moveData.ruleName].action
local onlyIfNotFullStack = db.profiles[actualProfile].rules[moveData.ruleName].onlyIfNotFullStack
local onlyStacksValue
if type(db.profiles[actualProfile].rules[moveData.ruleName].onlyStacks) == 'boolean' then onlyStacksValue = 1