-
Notifications
You must be signed in to change notification settings - Fork 1
/
LilVendor.lua
1236 lines (1023 loc) · 44.9 KB
/
LilVendor.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
-----------------------------------------------------------------------------------------------
-- Client Lua Script
-- Copyright (c) NCsoft. All rights reserved
-----------------------------------------------------------------------------------------------
require "Window"
require "string"
require "math"
require "Sound"
require "Item"
require "Money"
require "GameLib"
local LilVendor = {}
local kstrTabBuy = "VendorTab0"
local kstrTabSell = "VendorTab1"
local kstrTabBuyback = "VendorTab2"
local kstrTabRepair = "VendorTab3"
local knMaxGuildLimit = 2000000000 -- 2000 plat
local knConfirmTreshold = 200000 -- 20 gold
local knHeaderContainerMinHeight = 32
local ktVendorRespondEvent =
{
-- Stackable items send the StackSplit reason when they are being sold
[Item.CodeEnumItemUpdateReason.StackSplit] = Apollo.GetString("Vendor_Bought"),
[Item.CodeEnumItemUpdateReason.Vendor] = Apollo.GetString("Vendor_Bought"),
[Item.CodeEnumItemUpdateReason.Buyback] = Apollo.GetString("Vendor_BoughtBack"),
}
function LilVendor:new(o)
o = o or {}
setmetatable(o, self)
self.__index = self
o.tFactoryCache = {}
o.idOpenedGroup = nil
return o
end
function LilVendor:Init()
Apollo.RegisterAddon(self, false, "", {"Util"})
end
function LilVendor:OnLoad()
self.xmlDoc = XmlDoc.CreateFromFile("LilVendor.xml")
self.xmlDoc:RegisterCallback("OnDocumentReady", self)
end
function LilVendor:OnDocumentReady()
if self.xmlDoc == nil then
return
end
Apollo.RegisterEventHandler("WindowManagementReady", "OnWindowManagementReady", self)
Apollo.RegisterEventHandler("UpdateInventory", "OnUpdateInventory", self)
Apollo.RegisterEventHandler("VendorItemsUpdated", "OnVendorItemsUpdated", self)
Apollo.RegisterEventHandler("BuybackItemsUpdated", "OnBuybackItemsUpdated", self)
Apollo.RegisterEventHandler("CloseVendorWindow", "OnCloseVendorWindow", self)
Apollo.RegisterEventHandler("InvokeVendorWindow", "OnInvokeVendorWindow", self)
Apollo.RegisterEventHandler("PlayerCurrencyChanged", "OnPlayerCurrencyChanged", self)
-- Return events for buy/sell/repair
Apollo.RegisterEventHandler("GenericError", "OnGenericError", self)
Apollo.RegisterEventHandler("ItemDurabilityUpdate", "OnItemDurabilityUpdate", self)
Apollo.RegisterEventHandler("ItemAdded", "OnItemAdded", self)
Apollo.RegisterEventHandler("ItemRemoved", "OnItemRemoved", self)
-- Guild events
Apollo.RegisterEventHandler("GuildChange", "OnGuildChange", self)
Apollo.RegisterEventHandler("GuildBankWithdraw", "OnGuildChange", self)
Apollo.RegisterEventHandler("GuildWarCoinsChanged", "OnPlayerCurrencyChanged", self)
Apollo.RegisterTimerHandler("AlertMessageTimer", "OnAlertMessageTimer", self)
Apollo.CreateTimer("AlertMessageTimer", 4.0, false)
Apollo.StopTimer("AlertMessageTimer")
self.wndLilVendor = Apollo.LoadForm(self.xmlDoc, "VendorWindow", nil, self)
self.wndLilVendor:FindChild(kstrTabBuy):SetCheck(true)
self.wndLilVendor:FindChild("GuildRepairBtn"):Enable(false)
self.wndLilVendor:Show(false, true)
self.wndItemContainer = self.wndLilVendor:FindChild("LeftSideContainer:ItemsList")
self.wndBagWindow = self.wndLilVendor:FindChild("BagWindow")
self.tAltCurrency = nil
self.tDefaultSelectedItem = nil
self.tVendorItems = {}
self.tItemWndList = {}
self.tBuybackItems = {}
self.tRepairableItems = {}
end
function LilVendor:OnWindowManagementReady()
Event_FireGenericEvent("WindowManagementAdd", {wnd = self.wndLilVendor, strName = "LilVendor"})
end
-----------------------------------------------------------------------------------------------
function LilVendor:OnInvokeVendorWindow(unitArg) -- REFACTOR
Event_FireGenericEvent("VendorInvokedWindow")
local bIsRepairLilVendor = IsRepairVendor(unitArg)
self.wndLilVendor:Show(true)
self.wndLilVendor:SetData(unitArg)
self.wndLilVendor:FindChild("VendorName"):SetText(unitArg:GetName())
self.wndLilVendor:FindChild(kstrTabBuy):SetCheck(true)
self.wndLilVendor:FindChild(kstrTabSell):SetCheck(false)
self.wndLilVendor:FindChild(kstrTabBuyback):SetCheck(false)
self.wndLilVendor:FindChild(kstrTabRepair):SetCheck(false)
self.wndLilVendor:FindChild(kstrTabRepair):Enable(bIsRepairLilVendor)
if bIsRepairLilVendor then
self:RefreshRepairTab()
end
self:RedrawFully()
end
function LilVendor:OnUpdateInventory()
self:Redraw()
end
function LilVendor:OnVendorItemsUpdated()
self:Redraw()
end
function LilVendor:OnBuybackItemsUpdated()
self:RefreshBuyBackTab()
self:Redraw()
end
function LilVendor:OnPlayerCurrencyChanged()
self.wndLilVendor:FindChild("Cash"):SetAmount(GameLib.GetPlayerCurrency(), false)
if self.wndLilVendor:FindChild("AltCurrency"):IsShown() and self.tAltCurrency then
self.wndLilVendor:FindChild("AltCurrency"):SetAmount(GameLib.GetPlayerCurrency(self.tAltCurrency.eMoneyType, self.tAltCurrency.eAltType), false)
end
self:Redraw()
end
---------------------------------------------------------------------------------------------------
-- Main Update Method
---------------------------------------------------------------------------------------------------
function LilVendor:RedrawFully()
if not self.wndLilVendor or not self.wndLilVendor:IsShown() then
return
end
local nVScrollPos = self.wndItemContainer:GetVScrollPos()
self.wndItemContainer:DestroyChildren()
self:DisableBuyButton()
self:Redraw()
self:RefreshBuyBackTab()
self.wndItemContainer:SetVScrollPos(nVScrollPos)
self:OnPlayerCurrencyChanged()
if not self.tDefaultSelectedItem then
return
end
for key, wndHeader in pairs(self.wndItemContainer:GetChildren()) do
for key2, wndItem in pairs(wndHeader:FindChild("VendorHeaderContainer"):GetChildren()) do
local tData = wndItem:GetData()
if tData ~= nil and tData.idUnique == self.tDefaultSelectedItem.idUnique then -- GOTCHA: We can't == compare item objects, but we can compare .id
wndItem:FindChild("VendorListItemBtn"):SetCheck(true)
self:FocusOnVendorListItem(wndItem:GetData())
break
end
end
end
end
function LilVendor:Redraw()
if not self.wndLilVendor or not self.wndLilVendor:IsShown() then
return
end
local tUpdateInfo = nil
if self.wndLilVendor:FindChild(kstrTabBuy):IsChecked() then
tUpdateInfo = self:UpdateVendorItems()
elseif self.wndLilVendor:FindChild(kstrTabSell):IsChecked() then
tUpdateInfo = self:UpdateSellItems()
elseif self.wndLilVendor:FindChild(kstrTabBuyback):IsChecked() then
tUpdateInfo = self:UpdateBuybackItems()
elseif self.wndLilVendor:FindChild(kstrTabRepair):IsChecked() then
tUpdateInfo = self:UpdateRepairableItems()
end
--[[local tInvItems = GameLib.GetPlayerUnit():GetInventoryItems()
local jCount = 0
for _, val in pairs(tInvItems) do
if val.itemInBag:GetItemCategory() == 94 then --Junk ID
jCount = jCount + 1
end
end
self.wndLilVendor:FindChild("SellJunkBtn"):SetText("Sell Junk (" .. jCount ..")")
if self.wndLilVendor:FindChild(kstrTabSell):IsChecked() and jCount > 0 then
self.wndLilVendor:FindChild("SellJunkBtn"):Show(true)
self.wndLilVendor:FindChild("SellJunkBtn"):Enable(true)
elseif self.wndLilVendor:FindChild(kstrTabSell):IsChecked() and jCount <= 0 then
self.wndLilVendor:FindChild("SellJunkBtn"):Show(true)
self.wndLilVendor:FindChild("SellJunkBtn"):Enable(false)
else
self.wndLilVendor:FindChild("SellJunkBtn"):Show(false)
end]]--
local bFullRedraw = tUpdateInfo and tUpdateInfo.tUpdatedItems and (tUpdateInfo.bChanged or tUpdateInfo.bItemCountChanged or tUpdateInfo.bGroupCountChanged)
if bFullRedraw then
local nVScrollPos = self.wndItemContainer:GetVScrollPos()
self.wndItemContainer:DestroyChildren()
self:DisableBuyButton()
self:DrawHeaderAndItems(tUpdateInfo.tUpdatedItems, tUpdateInfo.bChanged)
self.wndItemContainer:SetVScrollPos(nVScrollPos)
else
self:DrawHeaderAndItems(tUpdateInfo.tUpdatedItems, tUpdateInfo.bChanged)
end
self:OnGuildChange() -- Also check Guild Repair
end
function LilVendor:DrawHeaderAndItems(tVendorList, bChanged)
for idHeader, tHeaderValue in pairs(tVendorList) do
local wndCurr = self:FactoryCacheProduce(self.wndItemContainer, "VendorHeaderItem", "H"..idHeader)
wndCurr:SetData(tHeaderValue)
if self.idOpenedGroup == nil then
self.idOpenedGroup = tHeaderValue.idGroup
end
wndCurr:FindChild("VendorHeaderBtn"):SetCheck(self.idOpenedGroup == tHeaderValue.idGroup)
wndCurr:FindChild("VendorHeaderName"):SetText(tHeaderValue.strName)
if wndCurr:FindChild("VendorHeaderBtn"):IsChecked() then
self:DrawListItems(wndCurr:FindChild("VendorHeaderContainer"), tHeaderValue.tItems)
end
self:SizeHeader(wndCurr)
end
self.wndItemContainer:ArrangeChildrenVert(0)
-- TODO: Advanced item info in frame
-- TODO: Destroy advanced item info if nothing is selected
end
function LilVendor:SizeHeader(wndHeader)
local wndVendorHeaderContainer = wndHeader:FindChild("VendorHeaderContainer")
-- Children, if checked
local nOnGoingHeight = math.max(knHeaderContainerMinHeight, wndVendorHeaderContainer:ArrangeChildrenVert(0))
-- Resize
local nLeft, nTop, nRight, nBottom = wndVendorHeaderContainer:GetAnchorOffsets()
wndVendorHeaderContainer:SetAnchorOffsets(nLeft, nTop, nRight, nTop + nOnGoingHeight)
local nLeft2, nTop2, nRight2, nBottom2 = wndHeader:GetAnchorOffsets()
wndHeader:SetAnchorOffsets(nLeft2, nTop2, nRight2, nTop2 + nOnGoingHeight + 36) -- Padding to the container and below it -- TODO Hardcoded formatting
end
function LilVendor:DrawListItems(wndParent, tItems)
for key, tCurrItem in pairs(tItems) do
if not tCurrItem.bFutureStock then
local wndCurr = self:FactoryCacheProduce(wndParent, "VendorListItem", "I"..tCurrItem.idUnique)
wndCurr:FindChild("VendorListItemBtn"):SetData(tCurrItem)
wndCurr:FindChild("VendorListItemTitle"):SetText(tCurrItem.strName)
if tCurrItem.itemData then wndCurr:FindChild("VendorListItemCategory"):SetText(tCurrItem.itemData:GetItemCategoryName() ~= "" and tCurrItem.itemData:GetItemCategoryName() or tCurrItem.itemData:GetItemTypeName()) end
wndCurr:FindChild("VendorListItemCantUse"):Show(self:HelperPrereqFailed(tCurrItem))
if tCurrItem.eType == Item.CodeEnumLootItemType.StaticItem then
wndCurr:FindChild("VendorListItemIcon"):GetWindowSubclass():SetItem(tCurrItem.itemData)
else
wndCurr:FindChild("VendorListItemIcon"):SetSprite(tCurrItem.strIcon)
end
local monPrice = nil
if tCurrItem.itemData then
local itemData = tCurrItem.itemData
if self.wndLilVendor:FindChild(kstrTabSell):IsChecked() or self.wndLilVendor:FindChild(kstrTabBuyback):IsChecked()then
monPrice = itemData:GetSellPrice():Multiply(tCurrItem.nStackSize)
elseif self.wndLilVendor:FindChild(kstrTabBuy):IsChecked() then
monPrice = itemData:GetBuyPrice():Multiply(tCurrItem.nStackSize)
elseif self.wndLilVendor:FindChild(kstrTabRepair):IsChecked() then
monPrice = Money.new(Money.CodeEnumCurrencyType.Credits)
monPrice:SetAmount(itemData:GetRepairCost())
end
elseif tCurrItem.splData then
monPrice = Money.new(tCurrItem.tPriceInfo.eCurrencyType1)
monPrice:SetAmount(tCurrItem.tPriceInfo.nAmount1)
monPrice:Multiply(tCurrItem.nStackSize)
if tCurrItem.tPriceInfo.eAltType1 then
monPrice:SetAltType(tCurrItem.tPriceInfo.eAltType1)
end
end
if tCurrItem.nStackSize > 1 then
wndCurr:FindChild("VendorListItemIcon"):SetText(tCurrItem.nStackSize)
elseif tCurrItem.nStockCount > 0 and self.wndLilVendor:FindChild(kstrTabBuy):IsChecked() then
wndCurr:FindChild("VendorListItemIcon"):SetText(String_GetWeaselString(Apollo.GetString("Vendor_LimitedItemCount"), tCurrItem.nStockCount))
end
-- Costs
if monPrice and monPrice:GetMoneyType() ~= Money.CodeEnumCurrencyType.Credits then
self.tAltCurrency = {}
self.tAltCurrency.eMoneyType = monPrice:GetMoneyType()
self.tAltCurrency.eAltType = monPrice:GetAltType()
end
local wndCash = wndCurr:FindChild("VendorListItemCashWindow")
if monPrice then
wndCash:SetAmount(monPrice, true)
else
wndCash:SetMoneySystem(Money.CodeEnumCurrencyType.Credits)
wndCash:SetAmount(0, true)
end
if self:HelperRecipeAlreadyKnown(tCurrItem) then
wndCurr:FindChild("VendorListItemTitle"):SetText(String_GetWeaselString(Apollo.GetString("Vendor_KnownRecipe"), wndCurr:FindChild("VendorListItemTitle"):GetText()))
end
local bTextColorRed = self:HelperIsTooExpensive(tCurrItem) or self:HelperPrereqBuyFailed(tCurrItem)
wndCurr:FindChild("VendorListItemTitle"):SetTextColor(bTextColorRed and "UI_WindowTextRed" or "UI_TextHoloBody")
wndCurr:FindChild("VendorListItemCashWindow"):SetTextColor(bTextColorRed and "UI_WindowTextRed" or "white")
end
end
-- After iterating
if self.tAltCurrency then
self.wndLilVendor:FindChild("AltCurrency"):SetAmount(GameLib.GetPlayerCurrency(self.tAltCurrency.eMoneyType, self.tAltCurrency.eAltType))
self.wndLilVendor:FindChild("AltCurrency"):Show(true, true)
self.wndLilVendor:FindChild("CashBagBG"):ArrangeChildrenVert(0)
else
self.wndLilVendor:FindChild("AltCurrency"):Show(false)
self.wndLilVendor:FindChild("CashBagBG"):ArrangeChildrenVert(0)
end
local nHeight = wndParent:ArrangeChildrenVert(0)
return nHeight
end
function LilVendor:EnableBuyButton(tData)
self:HideRestockingFee()
self.wndLilVendor:FindChild("Buy"):Enable(true)
self.wndLilVendor:FindChild("Buy"):SetData(tData)
end
function LilVendor:DisableBuyButton(bDontClear)
self:HideRestockingFee()
if self.wndLilVendor:FindChild(kstrTabRepair):IsChecked() then
local nRepairAllCost = GameLib.GetRepairAllCost()
self.wndLilVendor:FindChild("Buy"):Enable(nRepairAllCost > 0 and nRepairAllCost <= GameLib.GetPlayerCurrency():GetAmount())
elseif bDontClear or self.tDefaultSelectedItem == nil then
self.wndLilVendor:FindChild("Buy"):Enable(false)
end
if not bDontClear then
self.wndLilVendor:FindChild("Buy"):SetData(nil)
end
self:SetBuyButtonText()
end
function LilVendor:OnVendorListItemCheck(wndHandler, wndControl) -- TODO REFACTOR
if not wndHandler or not wndHandler:GetData() then
return
end
local tItemData = wndHandler:GetData()
self.tDefaultSelectedItem = nil -- Erase the default selection now
self:FocusOnVendorListItem(tItemData)
end
function LilVendor:OnVendorListItemUncheck(wndHandler, wndControl) -- TODO REFACTOR
if not wndHandler or not wndHandler:GetData() then
return
end
self.tDefaultSelectedItem = nil -- Erase the default selection now
self:DisableBuyButton()
self:OnGuildChange()
end
function LilVendor:OnVendorListItemMouseDown(wndHandler, wndControl, eMouseButton, nPosX, nPosY, bDoubleClick)
if (eMouseButton == GameLib.CodeEnumInputMouse.Left and bDoubleClick) or eMouseButton == GameLib.CodeEnumInputMouse.Right then -- left double click or right click
if not Apollo.IsControlKeyDown() then
self:OnVendorListItemCheck(wndHandler, wndControl)
if self.wndLilVendor:FindChild("Buy"):IsEnabled() then
self:OnBuy(self.wndLilVendor:FindChild("Buy"), self.wndLilVendor:FindChild("Buy")) -- hackish, simulate a buy button click
self.tDefaultSelectedItem = nil
end
else
-- item preview
-- Check if this item is a decor item
if not wndHandler or not wndHandler:GetData() then return end
local tItemPreview = wndHandler:GetData()
if tItemPreview and tItemPreview.itemData then
local itemCurr = tItemPreview.itemData
if itemCurr:GetHousingDecorInfoId() ~= nil and itemCurr:GetHousingDecorInfoId() ~= 0 then
Event_FireGenericEvent("DecorPreviewOpen", itemCurr:GetHousingDecorInfoId())
else
Event_FireGenericEvent("ShowItemInDressingRoom", itemCurr)
end
end
end
return true
end
end
function LilVendor:SelectNextItemInLine(tItem)
--[[ No longer desired functionality, the entire stack sells on the click
-- If there's more in the stack, use the same item still
if tItem.stackSize > 1 then
self.tDefaultSelectedItem = tItem
return
end
]]--
-- Look for the item's window in the list
local wndPrev = nil
for key, wndHeader in pairs(self.wndItemContainer:GetChildren()) do
wndPrev = wndHeader:FindChild("VendorHeaderContainer"):FindChildByUserData(tItem)
if wndPrev then
break
end
end
if not wndPrev then
return
end
-- Now that we found the window, find the next sibling in the list
local nNextItem = -1
for nCurr, wndCurr in pairs(wndPrev:GetParent():GetChildren()) do -- TODO HACKish, though GetParent():GetChildren() might be safe
if nNextItem == nCurr then
self.tDefaultSelectedItem = wndCurr:GetData() -- We'll let the redraw re-select the item for us
elseif wndCurr == wndPrev then
nNextItem = nCurr + 1
end
end
end
function LilVendor:FocusOnVendorListItem(tVendorItem)
local nMostCanBuy = 100
if tVendorItem.nStackSize == 1 then
nMostCanBuy = 1
elseif tVendorItem.nStockCount ~= 0 then
nMostCanBuy = tVendorItem.nStockCount
end
self:EnableBuyButton(tVendorItem)
-- TODO: Take second currency into account
local nPrice = 0
if tVendorItem.tPriceInfo then
nPrice = tVendorItem.tPriceInfo.nAmount1 * tVendorItem.nStackSize
end
if self.wndLilVendor:FindChild(kstrTabBuy):IsChecked() and nPrice > 0 then
local nPlayerAmount = GameLib.GetPlayerCurrency(tVendorItem.tPriceInfo.eCurrencyType1, tVendorItem.tPriceInfo.eAltType1):GetAmount()
nMostCanBuy = math.min(nMostCanBuy, math.floor(nPlayerAmount / nPrice))
if nMostCanBuy == 0 then
self:DisableBuyButton(true)
end
end
if self.wndLilVendor:FindChild(kstrTabBuyback):IsChecked() or self.wndLilVendor:FindChild(kstrTabRepair):IsChecked() then
local nPlayerAmount = GameLib.GetPlayerCurrency(tVendorItem.tPriceInfo.eCurrencyType1, tVendorItem.tPriceInfo.eAltType1):GetAmount()
if nPrice > nPlayerAmount then
self:DisableBuyButton(true)
end
elseif tVendorItem.bFutureStock or not tVendorItem.bMeetsPreq then
self:DisableBuyButton(true)
end
local strStack = ""
if self.wndLilVendor:FindChild(kstrTabBuy):IsChecked() and tVendorItem.nStackSize > 1 then
strStack = String_GetWeaselString(Apollo.GetString("Vendor_ItemCount"), tVendorItem.nStackSize)
end
self:SetBuyButtonText(strStack)
end
---------------------------------------------------------------------------------------------------
-- Alert Message Handlers
---------------------------------------------------------------------------------------------------
function LilVendor:OnItemAdded(itemBought, nCount, eReason)
if self.wndLilVendor and self.wndLilVendor:IsShown() and ktVendorRespondEvent[eReason] then
local strItem = nCount > 1 and String_GetWeaselString(Apollo.GetString("CombatLog_MultiItem"), nCount, itemBought:GetName()) or itemBought:GetName()
self:ShowAlertMessageContainer(String_GetWeaselString(ktVendorRespondEvent[eReason] or Apollo.GetString("Vendor_Bought"), strItem), false)
Sound.Play(Sound.PlayUIVendorBuy)
end
end
function LilVendor:OnItemRemoved(itemSold, nCount, eReason)
if self.wndLilVendor and self.wndLilVendor:IsShown() and ktVendorRespondEvent[eReason] then
local strMessage = nCount > 1 and String_GetWeaselString(Apollo.GetString("CombatLog_MultiItem"), nCount, itemSold:GetName()) or itemSold:GetName()
self:ShowAlertMessageContainer(String_GetWeaselString(Apollo.GetString("Vendor_Sold"), strMessage), false)
Sound.Play(Sound.PlayUIVendorSell)
end
end
function LilVendor:OnGenericError(eError, strMessage)
local tPurchaseFailEvent = -- index is enums to respond to, value is optional (UNLOCALIZED) replacement string (otherwise the passed string is used)
{
[GameLib.CodeEnumGenericError.DbFailure] = "",
[GameLib.CodeEnumGenericError.Item_BadId] = "",
[GameLib.CodeEnumGenericError.Vendor_StackSize] = "",
[GameLib.CodeEnumGenericError.Vendor_SoldOut] = "",
[GameLib.CodeEnumGenericError.Vendor_UnknownItem] = "",
[GameLib.CodeEnumGenericError.Vendor_FailedPreReq] = "",
[GameLib.CodeEnumGenericError.Vendor_NotAVendor] = "",
[GameLib.CodeEnumGenericError.Vendor_TooFar] = "",
[GameLib.CodeEnumGenericError.Vendor_BadItemRec] = "",
[GameLib.CodeEnumGenericError.Vendor_NotEnoughToFillQuantity] = "",
[GameLib.CodeEnumGenericError.Vendor_NotEnoughCash] = "",
[GameLib.CodeEnumGenericError.Vendor_UniqueConstraint] = "",
[GameLib.CodeEnumGenericError.Vendor_ItemLocked] = "",
[GameLib.CodeEnumGenericError.Vendor_IWontBuyThat] = "",
[GameLib.CodeEnumGenericError.Vendor_NoQuantity] = "",
[GameLib.CodeEnumGenericError.Vendor_BagIsNotEmpty] = "",
[GameLib.CodeEnumGenericError.Vendor_CuratorOnlyBuysRelics] = "",
[GameLib.CodeEnumGenericError.Vendor_CannotBuyRelics] = "",
[GameLib.CodeEnumGenericError.Vendor_NoBuyer] = "",
[GameLib.CodeEnumGenericError.Vendor_NoVendor] = "",
[GameLib.CodeEnumGenericError.Vendor_Buyer_NoActionCC] = "",
[GameLib.CodeEnumGenericError.Vendor_Vendor_NoActionCC] = "",
[GameLib.CodeEnumGenericError.Vendor_Vendor_Disposition] = "",
[GameLib.CodeEnumGenericError.Item_InventoryFull] = "",
[GameLib.CodeEnumGenericError.Item_UnknownItem] = "",
[GameLib.CodeEnumGenericError.Item_QuestViolation] = "",
[GameLib.CodeEnumGenericError.Item_Unique] = "",
[GameLib.CodeEnumGenericError.Faction_NotEnoughRep] = "",
}
if self.wndLilVendor and self.wndLilVendor:IsShown() and tPurchaseFailEvent[eError] then
if tPurchaseFailEvent[eError] ~= "" then
strMessage = tPurchaseFailEvent[eError]
end
self:ShowAlertMessageContainer(strMessage, true)
end
end
function LilVendor:OnItemDurabilityUpdate(itemCurr, nOldValue)
local nNewValue = itemCurr:GetDurability()
if self.wndLilVendor and self.wndLilVendor:IsShown() and nNewValue > nOldValue then
self:DisableBuyButton()
self.tRepairableItems = nil
self:Redraw()
self:ShowAlertMessageContainer(Apollo.GetString("Vendor_RepairsComplete"), false)
end
end
function LilVendor:ShowAlertMessageContainer(strMessage, bFailed)
self.wndLilVendor:FindChild("AlertMessageText"):SetText(strMessage)
self.wndLilVendor:FindChild("AlertMessageTitleSucceed"):Show(not bFailed)
self.wndLilVendor:FindChild("AlertMessageTitleFail"):Show(bFailed)
self.wndLilVendor:FindChild("AlertMessageContainer"):Show(false, true)
self.wndLilVendor:FindChild("AlertMessageContainer"):Show(true)
Apollo.StopTimer("AlertMessageTimer")
Apollo.StartTimer("AlertMessageTimer")
end
function LilVendor:HideRestockingFee()
local strMessage = Apollo.GetString("Vendor_RestockAlert")
if self.wndLilVendor:FindChild("AlertMessageText"):GetText() == strMessage then
self.wndLilVendor:FindChild("AlertMessageContainer"):Show(false)
end
end
function LilVendor:ProcessingRestockingFee(tItemData)
if not tItemData or not tItemData.itemData or not tItemData.itemData:HasRestockingFee() then
return false
end
local strMessage = Apollo.GetString("Vendor_RestockAlert")
local wndAlertMessageText = self.wndLilVendor:FindChild("AlertMessageText")
if wndAlertMessageText:GetText() == strMessage and wndAlertMessageText:IsVisible() then
return false
end
wndAlertMessageText:SetText(strMessage)
self.wndLilVendor:FindChild("AlertMessageTitleSucceed"):Show(false)
self.wndLilVendor:FindChild("AlertMessageTitleFail"):Show(false)
self.wndLilVendor:FindChild("AlertMessageContainer"):Show(false, true)
self.wndLilVendor:FindChild("AlertMessageContainer"):Show(true)
return true
end
function LilVendor:OnAlertMessageTimer()
Apollo.StopTimer("AlertMessageTimer")
self.wndLilVendor:FindChild("AlertMessageContainer"):Show(false)
end
function LilVendor:RefreshBuyBackTab()
local tNewBuybackItems = self.wndLilVendor:GetData():GetBuybackItems()
local nCount = 0
if tNewBuybackItems ~= nil then
nCount = #tNewBuybackItems
end
if nCount == 0 then
self.wndLilVendor:FindChild(kstrTabBuyback):SetText(Apollo.GetString("CRB_Buyback"))
else
self.wndLilVendor:FindChild(kstrTabBuyback):SetText(String_GetWeaselString(Apollo.GetString("Vendor_TabLabelMultiple"), Apollo.GetString("CRB_Buyback"), nCount))
end
end
function LilVendor:RefreshRepairTab()
local tNewRepairableItems = {}
if IsRepairVendor(self.wndLilVendor:GetData()) then
tNewRepairableItems = self.wndLilVendor:GetData():GetRepairableItems()
for idx, tItem in pairs(tNewRepairableItems or {}) do
tItem.idUnique = tItem.idLocation
end
end
local nCount = tNewRepairableItems and #tNewRepairableItems or 0
if nCount == 0 then
self.wndLilVendor:FindChild(kstrTabRepair):SetText(Apollo.GetString("CRB_Repair"))
else
self.wndLilVendor:FindChild(kstrTabRepair):SetText(String_GetWeaselString(Apollo.GetString("Vendor_TabLabelMultiple"), Apollo.GetString("CRB_Repair"), nCount))
end
end
---------------------------------------------------------------------------------------------------
-- Old Buy vs Sell vs Etc. Update Methods
-- TODO: Refactor this entire thing
---------------------------------------------------------------------------------------------------
function LilVendor:UpdateVendorItems() -- TODO: Old code
if not self.wndLilVendor:GetData() then -- Get Data should be the LilVendor Unit
return
end
local tVendorGroups = self.wndLilVendor:GetData():GetVendorGroups()
local tNewVendorItems = self.wndLilVendor:GetData():GetVendorItems()
local tNewVendorItemsByGroup = self:ArrangeGroups(tNewVendorItems, tVendorGroups)
local bChanged = false
local bItemCountChanged = false
local bGroupCountChanged = false
if self.tVendorItemsByGroup == nil or not self:TableEquals(tNewVendorItemsByGroup, self.tVendorItemsByGroup) then
bChanged = true
bItemCountChanged = #tNewVendorItems ~= (self.tVendorItems ~= nil and #self.tVendorItems or 0)
bGroupCountChanged = #tNewVendorItemsByGroup ~= (self.tVendorItemsByGroup ~= nil and #self.tVendorItemsByGroup or 0)
self.tVendorItems = tNewVendorItems
self.tVendorItemsByGroup = tNewVendorItemsByGroup
end
local tReturn = {}
tReturn.bChanged = bChanged
tReturn.bItemCountChanged = bItemCountChanged
tReturn.bGroupCountChanged = bGroupCountChanged
tReturn.tUpdatedItems = self.tVendorItemsByGroup
return tReturn
end
---------------------------------------------------------------------------------------------------
function LilVendor:UpdateSellItems()
if not self.wndLilVendor:GetData() then -- Get Data should be the LilVendor Unit
return
end
local tInvItems = GameLib.GetPlayerUnit():GetInventoryItems()
local tNewSellItems = {}
for key, tItemData in ipairs(tInvItems) do
local itemCurr = self:ItemToVendorSellItem(tItemData.itemInBag, 1)
if itemCurr then
table.insert(tNewSellItems, itemCurr)
end
end
local tSellGroups = {{idGroup = 1, strName = "Backpack"}}
local tNewSellItemsByGroup = self:ArrangeGroups(tNewSellItems, tSellGroups)
local bChanged = false
local bItemCountChanged = false
local bGroupCountChanged = false
if self.tSellItemsByGroup == nil or not self:TableEquals(tNewSellItemsByGroup, self.tSellItemsByGroup) then
bChanged = true
bItemCountChanged = #tNewSellItems ~= (self.tSellItems ~= nil and #self.tSellItems or 0)
bGroupCountChanged = #tNewSellItemsByGroup ~= (self.tSellItemsByGroup ~= nil and #self.tSellItemsByGroup or 0)
self.tSellItems = tNewSellItems
self.tSellItemsByGroup = tNewSellItemsByGroup
end
local tReturn = {}
tReturn.bChanged = bChanged
tReturn.bItemCountChanged = bItemCountChanged
tReturn.bGroupCountChanged = bGroupCountChanged
tReturn.tUpdatedItems = self.tSellItemsByGroup
return tReturn
end
---------------------------------------------------------------------------------------------------
function LilVendor:UpdateBuybackItems()
if not self.wndLilVendor:GetData() then -- Get Data should be the LilVendor Unit
return
end
local tNewBuybackItems = self.wndLilVendor:GetData():GetBuybackItems()
local tNewBuybackItemsByGroup = self:ArrangeGroups(tNewBuybackItems)
self:RefreshBuyBackTab()
local bChanged = false
local bItemCountChanged = false
local bGroupCountChanged = false
if self.tBuybackItemsByGroup == nil or not self:TableEquals(tNewBuybackItemsByGroup, self.tBuybackItemsByGroup) then
bChanged = true
bItemCountChanged = #tNewBuybackItems ~= (self.tBuybackItems ~= nil and #self.tBuybackItems or 0)
bGroupCountChanged = #tNewBuybackItemsByGroup ~= (self.tBuybackItemsByGroup ~= nil and #self.tBuybackItemsByGroup or 0)
self.tBuybackItems = tNewBuybackItems
self.tBuybackItemsByGroup = tNewBuybackItemsByGroup
end
local tReturn = {}
tReturn.bChanged = bChanged
tReturn.bItemCountChanged = bItemCountChanged
tReturn.bGroupCountChanged = bGroupCountChanged
tReturn.tUpdatedItems = self.tBuybackItemsByGroup
return tReturn
end
---------------------------------------------------------------------------------------------------
function LilVendor:UpdateRepairableItems()
if not self.wndLilVendor:GetData() then -- Get Data should be the LilVendor Unit
return
end
local tNewRepairableItems = {}
if IsRepairVendor(self.wndLilVendor:GetData()) then
tNewRepairableItems = self.wndLilVendor:GetData():GetRepairableItems()
for idx, tItem in pairs(tNewRepairableItems or {}) do
tItem.idUnique = tItem.idLocation
end
end
local tNewRepairableItemsByGroup = self:ArrangeGroups(tNewRepairableItems)
self:RefreshRepairTab()
local bChanged = false
local bItemCountChanged = false
local bGroupCountChanged = false
if self.tRepairableItemsByGroup == nil or not self:TableEquals(tNewRepairableItemsByGroup, self.tRepairableItemsByGroup) then
bChanged = true
bItemCountChanged = #tNewRepairableItems ~= (self.tRepairableItems ~= nil and #self.tRepairableItems or 0)
bGroupCountChanged = #tNewRepairableItemsByGroup ~= (self.tRepairableItemsByGroup ~= nil and #self.tRepairableItemsByGroup or 0)
self.tRepairableItems = tNewRepairableItems
self.tRepairableItemsByGroup = tNewRepairableItemsByGroup
end
local tReturn = {}
tReturn.bChanged = bChanged
tReturn.bItemCountChanged = bItemCountChanged
tReturn.bGroupCountChanged = bGroupCountChanged
tReturn.tUpdatedItems = self.tRepairableItemsByGroup
return tReturn
end
---------------------------------------------------------------------------------------------------
-- Simple UI Methods
---------------------------------------------------------------------------------------------------
function LilVendor:OnWindowClosed()
Event_CancelVending()
end
function LilVendor:OnCloseBtn()
self.wndLilVendor:Close()
end
function LilVendor:OnCloseVendorWindow()
self.wndLilVendor:Close()
end
-----------------------------------------------------------------------------------------------
-- Guild
-----------------------------------------------------------------------------------------------
function LilVendor:OnGuildChange() -- Catch All method to validate Guild Repair
if not self.wndLilVendor or not self.wndLilVendor:IsValid() or not self.wndLilVendor:IsVisible() then
return
end
local tMyGuild = nil
for idx, tGuild in pairs(GuildLib.GetGuilds()) do
if tGuild:GetType() == GuildLib.GuildType_Guild then
tMyGuild = tGuild
break
end
end
local bIsRepairing = self.wndLilVendor:FindChild(kstrTabRepair):IsChecked()
-- The following code allows for tMyGuild to be nil
local nLeft, nTop, nRight, nBottom = self.wndLilVendor:FindChild("LeftSideContainer"):GetAnchorOffsets()
self.wndLilVendor:FindChild("LeftSideContainer"):SetAnchorOffsets(nLeft, nTop, nRight, (tMyGuild and bIsRepairing) and -40 or -40) -- TODO HACKY: Hardcoded formatting
self.wndLilVendor:FindChild("GuildRepairContainer"):Show(tMyGuild and bIsRepairing)
self.wndLilVendor:FindChild("AltCurrency"):Show(not (tMyGuild and bIsRepairing))
if tMyGuild then -- If not valid, it won't be shown anyways
local tMyRankData = tMyGuild:GetRanks()[tMyGuild:GetMyRank()]
local nAvailableFunds
local nRepairRemainingToday = math.min(knMaxGuildLimit, tMyRankData.monBankRepairLimit:GetAmount()) - tMyGuild:GetBankMoneyRepairToday():GetAmount()
if tMyGuild:GetMoney():GetAmount() <= nRepairRemainingToday then
nAvailableFunds = tMyGuild:GetMoney():GetAmount()
else
nAvailableFunds = nRepairRemainingToday
end
self.wndLilVendor:FindChild("GuildRepairFundsCashWindow"):SetAmount(math.max(0, nAvailableFunds))
local repairableItems = self.wndLilVendor:GetData():GetRepairableItems()
local bHaveItemsToRepair = #repairableItems > 0
-- Check if you have enough and text color accordingly
local nRepairAllCost = 0
for key, tCurrItem in pairs(repairableItems) do
local tCurrPrice = math.max(tCurrItem.tPriceInfo.nAmount1, tCurrItem.tPriceInfo.nAmount2) * tCurrItem.nStackSize
nRepairAllCost = nRepairAllCost + tCurrPrice
end
local bSufficientFunds = nRepairAllCost <= nAvailableFunds
-- Enable / Disable button
local tCurrItem = self.wndLilVendor:FindChild("Buy"):GetData()
if tCurrItem and tCurrItem.tPriceInfo then
local tCurrPrice = math.max(tCurrItem.tPriceInfo.nAmount1, tCurrItem.tPriceInfo.nAmount2) * tCurrItem.nStackSize
bSufficientFunds = tCurrPrice <= nAvailableFunds
end
self.wndLilVendor:FindChild("GuildRepairBtn"):Enable(nRepairRemainingToday > 0 and bHaveItemsToRepair and bSufficientFunds)
self.wndLilVendor:FindChild("GuildRepairFundsCashWindow"):SetTextColor(bSufficientFunds and ApolloColor.new("UI_TextMetalBodyHighlight") or ApolloColor.new("red"))
self.wndLilVendor:FindChild("GuildRepairBtn"):SetData(tMyGuild)
end
end
function LilVendor:OnGuildRepairBtn(wndHandler, wndControl)
local tMyGuild = wndHandler:GetData()
local tItemData = self.wndLilVendor:FindChild("Buy"):GetData()
if tMyGuild and tItemData and tItemData.idLocation then
tMyGuild:RepairItemVendor(tItemData.idLocation)
local eRepairCurrency = tItemData.tPriceInfo.eCurrencyType1
local nRepairAmount = tItemData.tPriceInfo.nAmount1
self.wndLilVendor:FindChild("AlertCost"):SetMoneySystem(eRepairCurrency)
self.wndLilVendor:FindChild("AlertCost"):SetAmount(nRepairAmount)
elseif tMyGuild then
tMyGuild:RepairAllItemsVendor()
local monRepairAllCost = GameLib.GetRepairAllCost()
self.wndLilVendor:FindChild("AlertCost"):SetMoneySystem(Money.CodeEnumCurrencyType.Credits)
self.wndLilVendor:FindChild("AlertCost"):SetAmount(monRepairAllCost)
end
Sound.Play(Sound.PlayUIVendorRepair)
end
function LilVendor:OnBuy(wndHandler, wndControl)
if not wndHandler or not self.wndLilVendor:GetData() then
return
end
local tItemData = wndHandler:GetData()
if not self:ProcessingRestockingFee(tItemData) then
self:FinalizeBuy(tItemData)
end
end
function LilVendor:FinalizeBuy(tItemData)
local idItem = tItemData and tItemData.idUnique or nil
if tItemData and self.wndLilVendor:FindChild(kstrTabBuy):IsChecked() then
BuyItemFromVendor(idItem, 1) -- TODO: quantity chooser
self.tDefaultSelectedItem = tItemData
self:ShowAlertMessageContainer(String_GetWeaselString(Apollo.GetString("Vendor_Bought"), tItemData.strName), false) -- TODO: This shouldn't be needed
local monBuyPrice = tItemData.itemData:GetBuyPrice()
self.wndLilVendor:FindChild("AlertCost"):SetAmount(monBuyPrice)
elseif tItemData and self.wndLilVendor:FindChild(kstrTabSell):IsChecked() then
SellItemToVendorById(idItem, tItemData.nStackSize)
self:SelectNextItemInLine(tItemData)
self:Redraw()
local monSellPrice = tItemData.itemData:GetSellPrice():Multiply(tItemData.nStackSize)
self.wndLilVendor:FindChild("AlertCost"):SetAmount(monSellPrice)
elseif tItemData and self.wndLilVendor:FindChild(kstrTabBuyback):IsChecked() then
BuybackItemFromVendor(idItem)
self:SelectNextItemInLine(tItemData)
local monBuyBackPrice = tItemData.itemData:GetSellPrice():Multiply(tItemData.nStackSize)
self.wndLilVendor:FindChild("AlertCost"):SetAmount(monBuyBackPrice)
elseif self.wndLilVendor:FindChild(kstrTabRepair):IsChecked() then
local idLocation = tItemData and tItemData.idLocation or nil
if idLocation then
RepairItemVendor(idLocation)
local eRepairCurrency = tItemData.tPriceInfo.eCurrencyType1
local nRepairAmount = tItemData.tPriceInfo.nAmount1
self.wndLilVendor:FindChild("AlertCost"):SetMoneySystem(eRepairCurrency)
self.wndLilVendor:FindChild("AlertCost"):SetAmount(nRepairAmount)
else
self:RepairAllHelper()
end
Sound.Play(Sound.PlayUIVendorRepair)
elseif self.wndVendor:FindChild(kstrTabRepair):IsChecked() then
self:RepairAllHelper()
Sound.Play(Sound.PlayUIVendorRepair)
else
return
end
self.wndLilVendor:FindChild("VendorFlash"):SetSprite("CRB_WindowAnimationSprites:sprWinAnim_BirthSmallTemp")
end
function LilVendor:RepairAllHelper()
RepairAllItemsVendor()
local monRepairAllCost = GameLib.GetRepairAllCost()
self.wndLilVendor:FindChild("AlertCost"):SetMoneySystem(Money.CodeEnumCurrencyType.Credits)
self.wndLilVendor:FindChild("AlertCost"):SetAmount(monRepairAllCost)
end
function LilVendor:OnTabBtn(wndHandler, wndControl)
if not wndHandler then return end
self.wndItemContainer:DestroyChildren()
self.tDefaultSelectedItem = nil
self.idOpenedGroup = nil
self:DisableBuyButton()
self:Redraw()
end
function LilVendor:SetBuyButtonText(strAppend)
if not strAppend then
strAppend = ""
end
local strCaption = "" -- TODO REFACTOR
if self.wndLilVendor:FindChild(kstrTabBuy):IsChecked() then
strCaption = Apollo.GetString("Vendor_Purchase")
elseif self.wndLilVendor:FindChild(kstrTabSell):IsChecked() then
strCaption = Apollo.GetString("Vendor_Sell")
elseif self.wndLilVendor:FindChild(kstrTabBuyback):IsChecked() then
strCaption = Apollo.GetString("Vendor_Purchase")
elseif self.wndLilVendor:FindChild(kstrTabRepair):IsChecked() then
strCaption = Apollo.GetString(self.wndLilVendor:FindChild("Buy"):GetData() and "Vendor_Repair" or "Vendor_RepairAll")
else
strCaption = Apollo.GetString("Vendor_Purchase")
end
self.wndLilVendor:FindChild("Buy"):SetText(String_GetWeaselString(strCaption, strAppend))
self.wndLilVendor:FindChild("GuildRepairBtn"):SetText(Apollo.GetString(self.wndLilVendor:FindChild("Buy"):GetData() and "Vendor_GuildRepair" or "Vendor_GuildRepairAll"))
end
---------------------------------------------------------------------------------------------------
-- Old code
---------------------------------------------------------------------------------------------------
function LilVendor:ArrangeGroups(tItemList, tGroups)
local tNewList = {
tOther =
{
strName = Apollo.GetString("ChallengeTypeGeneral"),
tItems = {}
}
} --, specials = {}, future = {} } }
if not tGroups then
tNewList.tOther.tItems = tItemList
return tNewList
end
for idx, value in ipairs(tGroups) do
if value.strName and string.len(value.strName) > 0 then
tNewList[value.idGroup] = { strName = value.strName, tItems = {}, idGroup = value.idGroup } --, specials = {}, future = {} }
end
end
for idx, value in ipairs(tItemList) do
local tGroup = tNewList[value.idGroup] or tNewList.tOther
table.insert(tGroup.tItems, value)
end
for key, value in pairs(tNewList) do