forked from jvh-addons-wildstar/CommodityStats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommodityStats.lua
1301 lines (1167 loc) · 58.4 KB
/
CommodityStats.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
-- Got questions/comments? contact me at [email protected] or send me a message through Curse
require "Window"
local PixiePlot, GeminiLogging, glog, GeminiLocale, L
local CommodityStats = {}
local secondsInDay = 86400
local secondsInHour = 3600
local clrSellTop1 = {a=1,r=1,g=0,b=0}
local clrSellTop10 = {a=1,r=1,g=0.5,b=0.5}
local clrSellTop50 = {a=1,r=1,g=0.8,b=0.8}
local clrBuyTop1 = {a=1,r=0,g=1,b=0}
local clrBuyTop10 = {a=1,r=0.5,g=1,b=0.5}
local clrBuyTop50 = {a=1,r=0.8,g=1,b=0.8}
local CREDDid = "999999"
local transactionListItems = {}
-- OrderTypes
CommodityStats.OrderType = {
BOTH = 0,
BUY = 1,
SELL = 2
}
-- Transaction results
CommodityStats.Result = {
BUYSUCCESS = 0,
SELLSUCCESS = 1,
BUYEXPIRED = 2,
SELLEXPIRED = 3
}
-- DateTime formats
CommodityStats.DateFormat = {
DDMM = "%d/%m %H:%M",
MMDD = "%m/%d %H:%M"
}
-- categories
CommodityStats.Category = {
SELLORDER = "HeaderSellOrderBtn",
BUYORDER = "HeaderBuyOrderBtn",
SELLNOW = "HeaderSellNowBtn",
BUYNOW = "HeaderBuyNowBtn"
}
-- Price Undercut/Increase strategies
CommodityStats.Strategy = {
MATCH = 0,
FIXED = 1,
PERCENTAGE = 2
}
-- Price groups
CommodityStats.Pricegroup = {
TOP1 = 1,
TOP10 = 2,
TOP50 = 3
}
function CommodityStats:new(o)
o = o or {}
setmetatable(o, self)
self.__index = self
self.categoryQueue = {}
self.statistics = {}
self.transactions = {}
self.settings = {}
self.currentItemID = 0
self.queueSize = 0
self.lastAverageRun = 0
self.isScanning = false
-- default values
self.settings = {
daysToKeep = 60,
daysUntilAverage = 7,
dateFormatString = CommodityStats.DateFormat.DDMM,
orderType = CommodityStats.OrderType.BOTH,
baseSellPrice = CommodityStats.Pricegroup.TOP1,
sellStrategy = CommodityStats.Strategy.MATCH,
sellUndercutPercentage = 5,
sellUndercutFixed = 100,
baseBuyPrice = CommodityStats.Pricegroup.TOP1,
buyStrategy = CommodityStats.Strategy.MATCH,
buyIncreasePercentage = 5,
buyIncreaseFixed = 100,
lastSelectedTab = nil
}
return o
end
function CommodityStats:Init()
Apollo.RegisterAddon(self, true, "CommodityStats", {"MarketplaceCommodity", "MarketplaceCREDD", "Gemini:Logging-1.2", "Gemini:Locale-1.0"})
Apollo.RegisterEventHandler("MailBoxActivate", "OnMailboxOpen", self)
Apollo.RegisterEventHandler("ToggleMailWindow", "OnMailboxOpen", self)
Apollo.RegisterEventHandler("CommodityInfoResults", "OnCommodityInfoResults", self)
Apollo.RegisterEventHandler("CREDDExchangeInfoResults", "OnCREDDExchangeInfoResults", self)
Apollo.RegisterSlashCommand("commoditystats", "OnConfigure", self)
Apollo.RegisterSlashCommand("cs", "OnConfigure", self)
end
function CommodityStats:OnLoad()
PixiePlot = Apollo.GetPackage("Drafto:Lib:PixiePlot-1.4").tPackage
GeminiLogging = Apollo.GetPackage("Gemini:Logging-1.2").tPackage
glog = GeminiLogging:GetLogger({
level = GeminiLogging.WARN,
pattern = "%d %n %c %l - %m",
appender = "GeminiConsole"
})
GeminiLocale = Apollo.GetPackage("Gemini:Locale-1.0").tPackage
L = GeminiLocale:GetLocale("CommodityStats", false)
self.Xml = XmlDoc.CreateFromFile("CommodityStats.xml")
self.wndMain = Apollo.LoadForm(self.Xml, "MainContainer", nil, self)
GeminiLocale:TranslateWindow(L, self.wndMain)
self.MarketplaceCommodity = Apollo.GetAddon("MarketplaceCommodity")
self.MarketplaceCREDD = Apollo.GetAddon("MarketplaceCREDD")
self:InitializeHooks()
end
function CommodityStats:InitializeHooks()
local fnOldCREDDinitialize = self.MarketplaceCREDD.Initialize
-- Add statistics button to CREDD Exchange
self.MarketplaceCREDD.Initialize = function(tMarketPlaceCREDD)
fnOldCREDDinitialize(tMarketPlaceCREDD)
if self.CREDDStatButton ~= nil then self.CREDDStatButton:Destroy() end
self.CREDDStatButton = Apollo.LoadForm(self.Xml, "CREDDStatButton", tMarketPlaceCREDD.wndMain:FindChild("ActLater"), self)
self.CREDDStatButton:SetTooltip(L["Show price/transaction history"])
end
local fnOldInitialize = self.MarketplaceCommodity.Initialize
-- Add scanbutton to Commodity Exchange
self.MarketplaceCommodity.Initialize = function(tMarketPlaceCommodity)
fnOldInitialize(tMarketPlaceCommodity)
if self.ScanButton ~= nil then self.ScanButton:Destroy() end
self.ScanButton = Apollo.LoadForm(self.Xml, "ScanButton", tMarketPlaceCommodity.wndMain, self)
self.ScanButton:SetText(L["Scan all data"])
-- restore previous window position (which it really should do out of the box imo)
if self.commPosition ~= nil then
tMarketPlaceCommodity.wndMain:Move(self.commPosition.left, self.commPosition.top, tMarketPlaceCommodity.wndMain:GetWidth(), tMarketPlaceCommodity.wndMain:GetHeight())
end
-- Get CREDD info separately since it's not part of the CX, but we want the history on it.
CREDDExchangeLib.RequestExchangeInfo()
end
-- Add statistics button to every listed commodity item
local fnOldHeaderBtnToggle = self.MarketplaceCommodity.OnHeaderBtnToggle
self.MarketplaceCommodity.OnHeaderBtnToggle = function(tMarketPlaceCommodity)
fnOldHeaderBtnToggle(tMarketPlaceCommodity)
local children = tMarketPlaceCommodity.wndMain:FindChild("MainScrollContainer"):GetChildren()
for i, child in ipairs(children) do
if child:GetText() == "" then
local stat = Apollo.LoadForm(self.Xml, "StatButton", child, self)
stat:SetTooltip(L["Show price/transaction history"])
end
end
end
-- Fill in the best available price for buy/sell orders
local fnOldOnCommodityInfoResults = self.MarketplaceCommodity.OnCommodityInfoResults
self.MarketplaceCommodity.OnCommodityInfoResults = function(tMarketPlaceCommodity, nItemId, tStats, tOrders)
fnOldOnCommodityInfoResults(tMarketPlaceCommodity, nItemId, tStats, tOrders)
local scrollContainer = tMarketPlaceCommodity.wndMain:FindChild("MainScrollContainer")
if not scrollContainer then return end
local wndMatch = scrollContainer:FindChild(nItemId)
if not wndMatch or not wndMatch:IsValid() then
return
end
local price = 0
local hasPreviousQuantity
local selectedCategory = self:GetSelectedCategory(tMarketPlaceCommodity);
if self[selectedCategory] ~= nil then -- do we have previously saved prices/quantities?
scrollContainer:SetVScrollPos(self[selectedCategory].lastScrollPos)
if self[selectedCategory].lastItemID == nItemId then
price = self[selectedCategory].lastPricePerUnit:GetAmount()
wndMatch:FindChild("ListInputNumber"):SetText(self[selectedCategory].lastQuantity)
hasPreviousQuantity = true
end
end
if price == 0 then
price = self:GetPrice(nItemId, tStats, selectedCategory)
end
local listSubmitBtn = wndMatch:FindChild("ListSubmitBtn")
wndMatch:FindChild("ListInputPrice"):SetAmount(price)
listSubmitBtn:Enable(price > 0)
if self.settings.autoQuantity and not hasPreviousQuantity and (selectedCategory == CommodityStats.Category.SELLORDER or selectedCategory == CommodityStats.Category.SELLNOW) then
local maxOrder = MarketplaceLib.kMaxCommodityOrder
local sellQuantity = wndMatch:FindChild("ListCount"):GetData() or 0
if sellQuantity > maxOrder then sellQuantity = maxOrder end
wndMatch:FindChild("ListInputNumber"):SetText(sellQuantity)
tMarketPlaceCommodity:OnListInputNumberHelper(wndMatch, sellQuantity)
end
-- Add an extra invisible window to the Submit button so that we can intercept the click event on an otherwise protected ActionConfirmButton
Apollo.LoadForm(self.Xml, "ListSubmitButtonOverlay", listSubmitBtn, self)
end
-- Use a non-blocking infobox to display the transaction result info (no more waiting 4 seconds between every buy/sell attempt)
self.MarketplaceCommodity.OnPostCustomMessage = function(tMarketPlaceCommodity, strMessage, bResultOK, nDuration)
local tParameters= { iWindowType = GameLib.CodeEnumStoryPanel.Center, tLines = { strMessage }, nDisplayLength = nDuration }
MessageManagerLib.DisplayStoryPanel(tParameters)
end
-- Fix the error that occurs when you empty the quantity box
local fnOldOnListInputNumberHelper = self.MarketplaceCommodity.OnListInputNumberHelper
self.MarketplaceCommodity.OnListInputNumberHelper = function(tMarketPlaceCommodity, wndParent, nNewValue)
fnOldOnListInputNumberHelper(tMarketPlaceCommodity, wndParent, nNewValue or 0)
end
end
function CommodityStats:OnListSubmitBtn( wndHandler, wndControl, eMouseButton, nLastRelativeMouseX, nLastRelativeMouseY )
-- Save the last used params and scrollposition
local containername = self:GetSelectedCategory(self.MarketplaceCommodity)
wndHandler = wndHandler:GetParent()
if containername ~= nil then
local tCurrItem = wndHandler:GetData()[1]
local wndParent = wndHandler:GetData()[2]
self[containername] = {}
self[containername].lastItemID = tCurrItem:GetItemId()
self[containername].lastPricePerUnit = wndParent:FindChild("ListInputPrice"):GetCurrency()
self[containername].lastQuantity = wndParent:FindChild("ListInputNumber"):GetText()
self[containername].lastScrollPos = self.MarketplaceCommodity.wndMain:FindChild("MainScrollContainer"):GetVScrollPos()
end
end
function CommodityStats:SaveLastUsedParams(tMarketPlaceCommodity, wndHandler)
local containername = self:GetSelectedCategory(tMarketPlaceCommodity)
if containername ~= nil then
local tCurrItem = wndHandler:GetData()[1]
local wndParent = wndHandler:GetData()[2]
self[containername] = {}
self[containername].lastItemID = tCurrItem:GetItemId()
self[containername].lastPricePerUnit = wndParent:FindChild("ListInputPrice"):GetCurrency()
self[containername].lastQuantity = wndParent:FindChild("ListInputNumber"):GetText()
self[containername].lastScrollPos = tMarketPlaceCommodity.wndMain:FindChild("MainScrollContainer"):GetVScrollPos()
end
end
function CommodityStats:GetSelectedCategory(tMarketPlaceCommodity)
if tMarketPlaceCommodity.wndMain:FindChild("HeaderSellOrderBtn"):IsChecked() then return CommodityStats.Category.SELLORDER end
if tMarketPlaceCommodity.wndMain:FindChild("HeaderBuyOrderBtn"):IsChecked() then return CommodityStats.Category.BUYORDER end
if tMarketPlaceCommodity.wndMain:FindChild("HeaderSellNowBtn"):IsChecked() then return CommodityStats.Category.SELLNOW end
if tMarketPlaceCommodity.wndMain:FindChild("HeaderBuyNowBtn"):IsChecked() then return CommodityStats.Category.BUYNOW end
return nil
end
function CommodityStats:GetPrice(nItemId, tStats, selectedCategory)
local price = 0
if selectedCategory == CommodityStats.Category.SELLORDER or selectedCategory == CommodityStats.Category.BUYNOW then
local sellPriceGroup = self.settings.baseSellPrice or CommodityStats.Pricegroup.TOP10
local strategy = self.settings.sellStrategy or CommodityStats.Strategy.MATCH
if selectedCategory == CommodityStats.Category.BUYNOW then
sellPriceGroup = CommodityStats.Pricegroup.TOP1
strategy = CommodityStats.Strategy.MATCH
end
price = tStats.arSellOrderPrices[sellPriceGroup].monPrice:GetAmount()
if strategy == CommodityStats.Strategy.FIXED then
price = price - self.settings.sellUndercutFixed or 0
if price < 1 then price = 1 end
end
if strategy == CommodityStats.Strategy.PERCENTAGE then
price = math.floor(price - (price / 100 * self.settings.sellUndercutPercentage or 0))
end
else
local buyPriceGroup = self.settings.baseBuyPrice or CommodityStats.Pricegroup.TOP10
local strategy = self.settings.buyStrategy or CommodityStats.Strategy.MATCH
if selectedCategory == CommodityStats.Category.SELLNOW then
buyPriceGroup = CommodityStats.Pricegroup.TOP1
strategy = CommodityStats.Strategy.MATCH
end
price = tStats.arBuyOrderPrices[buyPriceGroup].monPrice:GetAmount()
if strategy == CommodityStats.Strategy.FIXED then
price = price + self.settings.buyIncreaseFixed or 0
end
if strategy == CommodityStats.Strategy.PERCENTAGE then
price = math.floor(price + (price / 100 * self.settings.buyIncreasePercentage or 0))
end
end
return price
end
function CommodityStats:OnCommodityInfoResults(nItemId, tStats, tOrders)
glog:debug("Commodity info received for item ID " .. tostring(nItemId) .. ".")
local stat = self:CreateCommodityStat(tStats)
if stat.buyOrderCount ~= 0 or stat.sellOrderCount ~= 0 then
if self.statistics[nItemId] == nil then
self.statistics[nItemId] = {}
end
local timestamp = GetTime()
stat.time = timestamp
if self.statistics[nItemId][timestamp] == nil then
self.statistics[nItemId][timestamp] = stat
end
end
if self.isScanning then
self.queueSize = self.queueSize - 1
if self.queueSize == 0 then
self.ScanButton:SetText(L["Finished!"])
self.ScanButton:Enable(true)
self.isScanning = false
end
end
end
function CommodityStats:OnCREDDExchangeInfoResults(arMarketStats, arOrders)
glog:debug("Received CREDD info")
local stat = self:CreateCommodityStat(arMarketStats)
if stat.buyOrderCount ~= 0 or stat.sellOrderCount ~= 0 then
if self.statistics[CREDDid] == nil then
self.statistics[CREDDid] = {}
end
local timestamp = GetTime()
stat.time = timestamp
if self.statistics[CREDDid][timestamp] == nil then
self.statistics[CREDDid][timestamp] = stat
end
end
end
function CommodityStats:CreateCommodityStat(tStats)
local stat = {}
stat.buyOrderCount = tStats.nBuyOrderCount
stat.sellOrderCount = tStats.nSellOrderCount
stat.buyPrices = {}
stat.buyPrices.top1 = tStats.arBuyOrderPrices[CommodityStats.Pricegroup.TOP1].monPrice:GetAmount()
stat.buyPrices.top10 = tStats.arBuyOrderPrices[CommodityStats.Pricegroup.TOP10].monPrice:GetAmount()
stat.buyPrices.top50 = tStats.arBuyOrderPrices[CommodityStats.Pricegroup.TOP50].monPrice:GetAmount()
stat.sellPrices = {}
stat.sellPrices.top1 = tStats.arSellOrderPrices[CommodityStats.Pricegroup.TOP1].monPrice:GetAmount()
stat.sellPrices.top10 = tStats.arSellOrderPrices[CommodityStats.Pricegroup.TOP10].monPrice:GetAmount()
stat.sellPrices.top50 = tStats.arSellOrderPrices[CommodityStats.Pricegroup.TOP50].monPrice:GetAmount()
return stat
end
function CommodityStats:OnSave(eLevel)
if eLevel ~= GameLib.CodeEnumAddonSaveLevel.Realm then
return nil
end
local save = {
statistics = self.statistics,
transactions = self.transactions,
settings = self.settings,
lastAverageRun = self.lastAverageRun
}
-- save window positions
local mainPosLeft, mainPosTop = self.wndMain:GetPos()
local commPosLeft, commPosTop = self.MarketplaceCommodity.wndMain:GetPos()
save.mainPosition = { left = mainPosLeft, top = mainPosTop }
save.commPosition = { left = commPosLeft, top = commPosTop }
return save
end
function CommodityStats:OnRestore(eLevel, tData)
self.transactions = tData.transactions or {}
self.statistics = tData.statistics or {}
self.lastAverageRun = tData.lastAverageRun or 0
if tData.settings ~= nil then
self.settings = tData.settings
self:PurgeExpiredStats()
self:AverageStatistics()
end
-- restore window positions
if tData.mainPosition ~= nil then
self.wndMain:Move(tData.mainPosition.left, tData.mainPosition.top, self.wndMain:GetWidth(), self.wndMain:GetHeight())
end
if tData.commPosition ~= nil then self.commPosition = tData.commPosition end
end
function CommodityStats:DrawColorNotes()
DrawLine(self.wndStatistics:FindChild("PixieBuytop1"), 3, clrBuyTop1)
DrawLine(self.wndStatistics:FindChild("PixieBuytop10"), 3, clrBuyTop10)
DrawLine(self.wndStatistics:FindChild("PixieBuytop50"), 3, clrBuyTop50)
DrawLine(self.wndStatistics:FindChild("PixieSelltop1"), 3, clrSellTop1)
DrawLine(self.wndStatistics:FindChild("PixieSelltop10"), 3, clrSellTop10)
DrawLine(self.wndStatistics:FindChild("PixieSelltop50"), 3, clrSellTop50)
end
function CommodityStats:LoadStatisticsForm()
if self.wndStatistics ~= nil then
self.wndStatistics:Destroy()
end
self.wndStatistics = Apollo.LoadForm(self.Xml, "StatisticsForm", self.wndMain:FindChild("MainForm"), self)
GeminiLocale:TranslateWindow(L, self.wndStatistics)
self:DrawColorNotes()
self:SetOrderTypeSelection()
self.plot = PixiePlot:New(self.wndStatistics:FindChild("Plot"))
self.plot:RemoveAllDataSets()
local stats = self.statistics[self.currentItemID]
if stats == nil then
local monTopBuy = self.wndStatistics:FindChild("monTopBuyPrice"):Show(false)
local monTopSell = self.wndStatistics:FindChild("monTopSellPrice"):Show(false)
local monPotentialProfit = self.wndStatistics:FindChild("monPotentialProfit"):Show(false)
glog:debug("No statistics, showing an empty plot")
-- show an empty plot
self.plot:Redraw()
return
end
local dsSellTop1 = { xStart = 0, values = {} }
local dsSellTop10 = { xStart = 0, values = {} }
local dsSellTop50 = { xStart = 0, values = {} }
local dsBuyTop1 = { xStart = 0, values = {} }
local dsBuyTop10 = { xStart = 0, values = {} }
local dsBuyTop50 = { xStart = 0, values = {} }
local earliest, minPrice, maxPrice = self:GetValueBoundaries(stats)
local current = earliest
local now = GetTime()
self.plot:SetXMin(earliest)
self.plot:SetXMax(now)
self.plot:SetYMin(minPrice)
self.plot:SetYMax(maxPrice)
while current <= now do
local stat = stats[current]
if stat ~= nil then
if self.settings.orderType == CommodityStats.OrderType.SELL or self.settings.orderType == CommodityStats.OrderType.BOTH then
if stat.sellPrices.top1 ~= 0 then table.insert(dsSellTop1.values, { x = current, y = stat.sellPrices.top1 }) end
if stat.sellPrices.top10 ~= 0 then table.insert(dsSellTop10.values, { x = current, y = stat.sellPrices.top10 }) end
if stat.sellPrices.top50 ~= 0 then table.insert(dsSellTop50.values, { x = current, y = stat.sellPrices.top50 }) end
end
if self.settings.orderType == CommodityStats.OrderType.BUY or self.settings.orderType == CommodityStats.OrderType.BOTH then
if stat.buyPrices.top1 ~= 0 then table.insert(dsBuyTop1.values, { x = current, y = stat.buyPrices.top1 }) end
if stat.buyPrices.top10 ~= 0 then table.insert(dsBuyTop10.values, { x = current, y = stat.buyPrices.top10 }) end
if stat.buyPrices.top50 ~= 0 then table.insert(dsBuyTop50.values, { x = current, y = stat.buyPrices.top50 }) end
end
end
current = current + secondsInHour
end
self:EstimateProfits(stats[now])
self.plot:SetXInterval(3600)
self.plot:SetOption("ePlotStyle", PixiePlot.SCATTER)
self.plot:SetOption("eCoordinateSystem", PixiePlot.CARTESIAN)
self.plot:SetOption("bScatterLine", true)
self.plot:SetOption("fLineWidth", 2)
self.plot:SetOption("bDrawSymbol", true)
self.plot:SetOption("fSymbolSize", 4)
self.plot:SetOption("bDrawYValueLabels", true)
self.plot:SetOption("bDrawXValueLabels", true)
self.plot:SetOption("nLabelDecimals", 0)
self.plot:SetOption("bDrawXGridLines", true)
self.plot:SetOption("bDrawYGridLines", true)
self.plot:SetOption("fXLabelMargin", 50)
self.plot:SetOption("fYLabelMargin", 75)
self.plot:SetOption("fPlotMargin", 15)
self.plot:SetOption("nXValueLabels", 5)
self.plot:SetOption("nYValueLabels", 5)
self.plot:SetOption("xValueFormatter", function(value) return os.date(self.settings.dateFormatString, value) end)
self.plot:SetOption("yValueFormatter", function(value) return FormatMoney(value) end)
self.plot:SetOption("fXValueLabelTilt", 45)
self.plot:SetOption("fYValueLabelTilt", 60)
self.plot:SetOption("bWndOverlays", true)
self.plot:SetOption("fWndOverlaySize", 15)
self.plot:SetOption("wndOverlayLoadCallback", function(tData, wnd)
local wndTooltip = wnd:LoadTooltipForm("CommodityStats.xml", "TooltipForm", self)
GeminiLocale:TranslateWindow(L, wndTooltip)
wndTooltip:FindChild("txtTime"):SetText(os.date(self.settings.dateFormatString, tData.x))
wndTooltip:FindChild("monPrice"):SetAmount(tData.y)
wnd:SetTooltipForm(wndTooltip)
end)
self.plot:SetOption("aPlotColors", self:GetPlotColors(self.settings.orderType))
self.plot:SetOption("wndOverlayMouseEventCallback", function(tData, eType)
glog:debug("Mouse event " .. eType)
glog:debug(tData)
end)
if self.settings.orderType == CommodityStats.OrderType.SELL or self.settings.orderType == CommodityStats.OrderType.BOTH then
self.plot:AddDataSet(dsSellTop1)
self.plot:AddDataSet(dsSellTop10)
self.plot:AddDataSet(dsSellTop50)
end
if self.settings.orderType == CommodityStats.OrderType.BUY or self.settings.orderType == CommodityStats.OrderType.BOTH then
self.plot:AddDataSet(dsBuyTop1)
self.plot:AddDataSet(dsBuyTop10)
self.plot:AddDataSet(dsBuyTop50)
end
self.plot:Redraw()
end
function CommodityStats:GetPlotColors(nOrderType)
if nOrderType == CommodityStats.OrderType.BOTH then
return {clrSellTop1, clrSellTop10, clrSellTop50, clrBuyTop1, clrBuyTop10, clrBuyTop50 }
end
if nOrderType == CommodityStats.OrderType.SELL then
return {clrSellTop1, clrSellTop10, clrSellTop50 }
end
if nOrderType == CommodityStats.OrderType.BUY then
return {clrBuyTop1, clrBuyTop10, clrBuyTop50 }
end
end
function CommodityStats:EstimateProfits(prices)
local monTopBuy = self.wndStatistics:FindChild("monTopBuyPrice")
local monTopSell = self.wndStatistics:FindChild("monTopSellPrice")
local monPotentialProfit = self.wndStatistics:FindChild("monPotentialProfit")
monTopBuy:Show(false)
monTopSell:Show(false)
monPotentialProfit:Show(false)
if prices ~= nil then
if prices.buyPrices.top1 > 0 then
self.wndStatistics:FindChild("txtTopBuyPrice"):Show(false)
monTopBuy:Show(true)
monTopBuy:SetAmount(prices.buyPrices.top1)
end
if prices.sellPrices.top1 > 0 then
self.wndStatistics:FindChild("txtTopSellPrice"):Show(false)
monTopSell:Show(true)
monTopSell:SetAmount(prices.sellPrices.top1)
end
if prices.buyPrices.top1 > 0 and prices.sellPrices.top1 > 0 then
local estimatedProfit = prices.sellPrices.top1 - prices.buyPrices.top1
if estimatedProfit > 0 then
self.wndStatistics:FindChild("txtPotentialProfit"):Show(false)
monPotentialProfit:Show(true)
monPotentialProfit:SetAmount(estimatedProfit)
end
end
end
end
function CommodityStats:SetOrderTypeSelection()
if self.settings.orderType == CommodityStats.OrderType.BUY then self.wndStatistics:FindChild("btnBuy"):SetCheck(true) end
if self.settings.orderType == CommodityStats.OrderType.SELL then self.wndStatistics:FindChild("btnSell"):SetCheck(true) end
if self.settings.orderType == CommodityStats.OrderType.BOTH then self.wndStatistics:FindChild("btnBoth"):SetCheck(true) end
end
function CommodityStats:GetValueBoundaries(t)
local earliest = -1
local minPrice = -1
local maxPrice = -1
for i, data in pairs(t) do
local timestamp = tonumber(i)
if timestamp ~= nil then
if earliest == -1 or earliest > timestamp then
earliest = timestamp
end
if self.settings.orderType == CommodityStats.OrderType.SELL or self.settings.orderType == CommodityStats.OrderType.BOTH then
if data.sellPrices.top1 > maxPrice then maxPrice = data.sellPrices.top1 end
if data.sellPrices.top10 > maxPrice then maxPrice = data.sellPrices.top10 end
if data.sellPrices.top50 > maxPrice then maxPrice = data.sellPrices.top50 end
end
if self.settings.orderType == CommodityStats.OrderType.BUY or self.settings.orderType == CommodityStats.OrderType.BOTH then
if data.buyPrices.top1 > maxPrice then maxPrice = data.buyPrices.top1 end
if data.buyPrices.top10 > maxPrice then maxPrice = data.buyPrices.top10 end
if data.buyPrices.top50 > maxPrice then maxPrice = data.buyPrices.top50 end
end
minPrice = maxPrice
if self.settings.orderType == CommodityStats.OrderType.SELL or self.settings.orderType == CommodityStats.OrderType.BOTH then
if data.sellPrices.top1 < minPrice and data.sellPrices.top1 ~= 0 then minPrice = data.sellPrices.top1 end
if data.sellPrices.top10 < minPrice and data.sellPrices.top10 ~= 0 then minPrice = data.sellPrices.top10 end
if data.sellPrices.top50 < minPrice and data.sellPrices.top50 ~= 0 then minPrice = data.sellPrices.top50 end
end
if self.settings.orderType == CommodityStats.OrderType.BUY or self.settings.orderType == CommodityStats.OrderType.BOTH then
if data.buyPrices.top1 < minPrice and data.buyPrices.top1 ~= 0 then minPrice = data.buyPrices.top1 end
if data.buyPrices.top10 < minPrice and data.buyPrices.top10 ~= 0 then minPrice = data.buyPrices.top10 end
if data.buyPrices.top50 < minPrice and data.buyPrices.top50 ~= 0 then minPrice = data.buyPrices.top50 end
end
end
end
return earliest, minPrice, maxPrice
end
function CommodityStats:PurgeExpiredStats()
if self.settings.daysToKeep > 0 then
local counter = 0
local minimumTime = GetTime() - (self.settings.daysToKeep * secondsInDay)
for index, item in pairs(self.statistics) do
if type(index) == 'number' then
for timestamp, stat in pairs(item) do
if type(timestamp) == 'number' then
if timestamp <= minimumTime then
item[timestamp] = nil
counter = counter + 1
end
end
end
end
end
if counter > 0 then
glog:debug("Removed " .. tostring(counter) .. " statistics that were older than " .. tostring(self.settings.daysToKeep) .. ".")
end
end
end
function CommodityStats:AverageStatistics()
if self.settings.daysUntilAverage > 0 and (os.time() - self.lastAverageRun) > secondsInDay then
local treshold = GetTime() - (secondsInDay * self.settings.daysUntilAverage)
for itemid, stats in pairs(self.statistics) do
if type(itemid) == 'number' then
if stats.earliest == nil then
local earliest, minPrice, maxPrice = self:GetValueBoundaries(stats)
stats.earliest = earliest
end
while stats.earliest < treshold do
local firstStat = stats.earliest
local newStats = {}
while stats.earliest < firstStat + secondsInDay and stats.earliest < treshold do
local stat = stats[stats.earliest]
if stat ~= nil then
table.insert(newStats, stat)
stats[stats.earliest] = nil
end
stats.earliest = stats.earliest + secondsInHour
end
if #newStats > 0 then
stats[firstStat] = AverageStats(newStats)
end
end
end
self.lastAverageRun = os.time()
end
end
end
function CommodityStats:LoadTransactionsForm()
if self.wndTransactions ~= nil then
self.wndTransactions:Destroy()
end
self.wndTransactions = Apollo.LoadForm(self.Xml, "TransactionsForm", self.wndMain:FindChild("MainForm"), self)
GeminiLocale:TranslateWindow(L, self.wndTransactions)
self:DisplayTransactions(self.currentItemID)
end
function CommodityStats:LoadConfigForm()
if self.wndConfig ~= nil then
self.wndConfig:Destroy()
end
self.wndConfig = Apollo.LoadForm(self.Xml, "ConfigForm", self.wndMain:FindChild("MainForm"), self)
GeminiLocale:TranslateWindow(L, self.wndConfig)
-- history settings
self.wndConfig:FindChild("txtStatisticsAge"):SetText(tostring(self.settings.daysToKeep))
self.wndConfig:FindChild("txtStatisticsAverage"):SetText(tostring(self.settings.daysUntilAverage))
-- date format settings
self.wndConfig:FindChild("txtCustomDateTime"):SetText(self.settings.dateFormatString)
if self.settings.dateFormatString == CommodityStats.DateFormat.DDMM then
self.wndConfig:FindChild("chkddmmyyyy"):SetCheck(true)
elseif self.settings.dateFormatString == CommodityStats.DateFormat.MMDD then
self.wndConfig:FindChild("chkmmddyyyy"):SetCheck(true)
else
self.wndConfig:FindChild("chkCustom"):SetCheck(true)
self.wndConfig:FindChild("CustomDateTimeContainer"):Show(true)
end
-- sellorder pricing
self:SetSelectedBaseSellPrice()
self:SetSelectedSellStrategy()
self.wndConfig:FindChild("txtUndercutPercentage"):SetText(tostring(self.settings.sellUndercutPercentage or 0))
self.wndConfig:FindChild("monSellUndercutFixed"):SetAmount(self.settings.sellUndercutFixed or 0)
self.wndConfig:FindChild("chkAutoQuantity"):SetCheck(self.settings.autoQuantity)
-- buyorder pricing
self:SetSelectedBaseBuyPrice()
self:SetSelectedBuyStrategy()
self.wndConfig:FindChild("txtIncreasePercentage"):SetText(tostring(self.settings.buyIncreasePercentage or 0))
self.wndConfig:FindChild("monBuyIncreaseFixed"):SetAmount(self.settings.buyIncreaseFixed or 0)
self.wndConfig:Show(true)
end
function FormatMoney(nAmount)
-- careful with negative amounts when calculating modulo
local isNegative = nAmount < 0
if isNegative then nAmount = nAmount * -1 end
local platinum = math.floor(nAmount / 1000000)
nAmount = nAmount % 1000000
local gold = math.floor(nAmount / 10000)
nAmount = nAmount % 10000
local silver = math.floor(nAmount / 100)
local copper = nAmount % 100
local output = ""
if platinum > 0 then output = output .. tostring(platinum) .. "p " end
if gold > 0 then output = output .. tostring(gold) .. "g " end
if silver > 0 then output = output .. tostring(silver) .. "s " end
output = output .. tostring(math.floor(copper)) .. "c"
if isNegative then output = "-" .. output end
return output
end
function AverageStats(tCollection)
-- we have to make sure we don't take '0' values (no defined price) along in our averaging.
-- that means each stat can have a different collection size.
-- The exception is buy/sell order count
local buyOrderCountCollection = {}
local sellOrderCountCollection = {}
local buyTop1Collection = {}
local buyTop10Collection = {}
local buyTop50Collection = {}
local sellTop1Collection = {}
local sellTop10Collection = {}
local sellTop50Collection = {}
for i, item in ipairs(tCollection) do
if tonumber(i) then
table.insert(buyOrderCountCollection, item.buyOrderCount)
table.insert(sellOrderCountCollection, item.sellOrderCount)
if item.buyPrices.top1 > 0 then table.insert(buyTop1Collection, item.buyPrices.top1) end
if item.buyPrices.top10 > 0 then table.insert(buyTop10Collection, item.buyPrices.top10) end
if item.buyPrices.top50 > 0 then table.insert(buyTop50Collection, item.buyPrices.top50) end
if item.sellPrices.top1 > 0 then table.insert(sellTop1Collection, item.sellPrices.top1) end
if item.sellPrices.top10 > 0 then table.insert(sellTop10Collection, item.sellPrices.top10) end
if item.sellPrices.top50 > 0 then table.insert(sellTop50Collection, item.sellPrices.top50) end
end
end
return { buyOrderCount = AverageNumbers(buyOrderCountCollection), sellOrderCount = AverageNumbers(sellOrderCountCollection),
sellPrices = { top1 = AverageNumbers(sellTop1Collection), top10 = AverageNumbers(sellTop10Collection), top50 = AverageNumbers(sellTop50Collection)},
buyPrices = { top1 = AverageNumbers(buyTop1Collection), top10 = AverageNumbers(buyTop10Collection), top50 = AverageNumbers(buyTop50Collection)}
}
end
function AverageNumbers(tCollection)
if #tCollection == 0 then return 0 end
local total = 0
for i, val in ipairs(tCollection) do
total = total + val
end
return math.floor(total / #tCollection)
end
function CommodityStats:CleanItemDatabase()
-- needed to clean zero values when I mess up
for id, stats in pairs(self.statistics) do
local highest = 0
for time, stat in pairs(stats) do
if stat.buyOrderCount == nil then stat.buyOrderCount = 0 end
if stat.sellOrderCount == nil then stat.sellOrderCount = 0 end
if stat.buyOrderCount > highest then highest = stat.buyOrderCount end
if stat.sellOrderCount > highest then highest = stat.sellOrderCount end
end
if highest == 0 then
glog:debug("Deleting item ID " .. tostring(id))
self.statistics[id] = nil
end
end
end
function DrawLine(wndTarget, height, color)
local width = wndTarget:GetWidth()
local center = math.floor(wndTarget:GetHeight() / 2)
wndTarget:AddPixie({
bLine = true,
fWidth = height,
cr = color,
loc = {
fPoints = {0,0,0,0},
nOffsets = {
0,
center,
width,
center
}
},
})
end
function GetTime()
-- this function returns unix epoch time. We do some extra trickery to round the time to hours, since we don't need stats as detailed as every minute/second
local time = GameLib.GetLocalTime()
timeargs = {}
timeargs.year = time.nYear
timeargs.month = time.nMonth
timeargs.day = time.nDay
timeargs.hour = time.nHour
timeargs.min = 0
timeargs.sec = 0
return os.time(timeargs)
end
function CommodityStats:OnMailboxOpen()
-- Disabling it for non-US locales for now
if L["Locale"] == "enUS" then
local mails = MailSystemLib.GetInbox()
for i, mail in pairs(mails) do
local info = mail:GetMessageInfo()
local itemID, transaction
if info.eSenderType == MailSystemLib.EmailType_CommodityAuction and info.bIsRead == false then
if info.strBody:lower():find("seller has been found") then
itemID, transaction = processTransaction(info, CommodityStats.Result.BUYSUCCESS)
elseif info.strBody:lower():find("buyer has been found") then
itemID, transaction = processTransaction(info, CommodityStats.Result.SELLSUCCESS)
elseif info.strBody:lower():find("buy order") then
itemID, transaction = processTransaction(info, CommodityStats.Result.BUYEXPIRED)
elseif info.strBody:lower():find("sell order") then
itemID, transaction = processTransaction(info, CommodityStats.Result.SELLEXPIRED)
end
if transaction ~= nil and itemID ~= nil then
if self.transactions[itemID] == nil then self.transactions[itemID] = {} end
table.insert(self.transactions[itemID], transaction)
end
mail:MarkAsRead()
end
end
end
end
function CommodityStats:DisplayTransactions(itemID)
for i, listitem in ipairs(transactionListItems) do
listitem:Destroy()
end
transactionListItems = {}
local buyTotal = 0
local sellTotal = 0
local buyQuantity = 0
local sellQuantity = 0
local wndItems = self.wndTransactions:FindChild("ItemList")
if itemID == nil then
for id, transactions in pairs(self.transactions) do
for i, transaction in ipairs(self.transactions[id]) do
table.insert(transactionListItems, self:AddTransactionItem(wndItems, id, transaction))
end
end
else
if self.transactions[itemID] ~= nil then
for i, transaction in ipairs(self.transactions[itemID]) do
if transaction.result == CommodityStats.Result.BUYSUCCESS then
buyQuantity = buyQuantity + transaction.quantity
buyTotal = buyTotal + (transaction.quantity * transaction.price)
end
if transaction.result == CommodityStats.Result.SELLSUCCESS then
sellQuantity = sellQuantity + transaction.quantity
sellTotal = sellTotal + (transaction.quantity * transaction.price)
end
table.insert(transactionListItems, self:AddTransactionItem(wndItems, id, transaction))
end
end
end
self.wndTransactions:FindChild("txtTotalBuyAmount"):SetText(tostring(buyQuantity))
self.wndTransactions:FindChild("monTotalBuyPrice"):SetAmount(buyTotal)
self.wndTransactions:FindChild("txtTotalSellAmount"):SetText(tostring(sellQuantity))
self.wndTransactions:FindChild("monTotalSellPrice"):SetAmount(sellTotal)
local totalprofit = sellTotal - buyTotal
local profitColor = "green"
if totalprofit < 0 then
totalprofit = totalprofit * -1
profitColor = "red"
self.wndTransactions:FindChild("txtTotalProfit"):SetText(L["Total loss:"])
end
self.wndTransactions:FindChild("monProfit"):SetTextColor(profitColor)
self.wndTransactions:FindChild("monProfit"):SetAmount(totalprofit)
wndItems:ArrangeChildrenVert()
self.wndTransactions:Show(true)
self.wndTransactions:ToFront()
end
function CommodityStats:AddTransactionItem(wndTarget, itemID, transaction)
local result = ""
if transaction.result == CommodityStats.Result.BUYSUCCESS then result = L["Buy success"] end
if transaction.result == CommodityStats.Result.SELLSUCCESS then result = L["Sell success"] end
if transaction.result == CommodityStats.Result.BUYEXPIRED then result = L["Buy expired"] end
if transaction.result == CommodityStats.Result.SELLEXPIRED then result = L["Sell expired"] end
local wndTransaction = Apollo.LoadForm(self.Xml, "TransactionItem", wndTarget, self)
wndTransaction:FindChild("txtDate"):SetText(os.date(self.settings.dateFormatString, transaction.timestamp))
wndTransaction:FindChild("txtQuantity"):SetText(tostring(transaction.quantity))
wndTransaction:FindChild("monPrice"):SetAmount(transaction.price)
wndTransaction:FindChild("txtResult"):SetText(result)
return wndTransaction
end
function processTransaction(info, transactionresult)
glog:info("Processing mail with subject '" .. info.strSubject .."'. Transactionresult: " .. tostring(transactionresult) .. ".")
local transaction = { result = transactionresult }
local quantity, name, price, unit
if transactionresult == CommodityStats.Result.BUYSUCCESS or transactionresult == CommodityStats.Result.SELLSUCCESS then
quantity, name, price, unit = string.match(info.strBody, '(%d+)[^%s](.-)%.?\n?\r?\n.-(%d+)(.-)\r?\n')
else
quantity, name, price = string.match(info.strBody, 'for (%d+)[^%s](.-)at%s(%d+)')
end
if quantity == nil or name == nil or price == nil then
glog:warn("Couldn't parse mail with subject '" .. info.strSubject .. "'.")
return nil, nil
end
transaction.quantity = tonumber(trim(quantity))
transaction.price = tonumber(trim(price))
transaction.timestamp = getMailTime(info)
local item = getItemByName(singularize(trim(name)))
if item == nil then
glog:warn("Couldn't find item ID for " .. name .. ". Transaction not saved.")
return nil, nil
end
return item.nId, transaction
end
function getItemByName(name)
local results = MarketplaceLib.SearchCommodityItems(name)
local returnVal = nil
for i, result in pairs(results) do
if result.strName:lower() == name:lower() then
returnVal = result
break
end
end
return returnVal
end
function getMailTime(mailinfo)
-- mails don't have info on when the mail was sent, only the time until it expires, represented by a float between 0 and 30
local elapsedSeconds = math.floor((30 - mailinfo.fExpirationTime) * secondsInDay)
return os.time() - elapsedSeconds
end
function singularize(s)
-- Auction mails pluralize certain item names if multiple items were bought/sold.
-- We need the singular form in order to actually find the item ID.
-- This is mostly guesswork. If anyone knows a better way to handle this, please let me know.
local words = { "rune", "bar", "bone", "core", "fragment", "scrap", "sign", "pelt", "chunk", "leather", "dye", "charge", "injector", "pummelgranate", "roast", "breast",
"boost", "stimulant", "potion", "cloth", "grenade", "juice", "serum", "extract", "leave", "disruptor", "emitter", "focuser", "spirovine", "root",
"transformer", "acceleron", "ingot", "bladeleave", "coralscale", "zephyrite", "sample", "faerybloom", "sapphire", "yellowbell", "sample"}
s = s:lower()
for i, word in pairs(words) do
s = s:gsub(word .. "s", word)
end
return s
end
function trim(s)
return s:find'^%s*$' and '' or s:match'^%s*(.*%S)'
end
---------------------------------------------------------------------------------------------------
-- Button Functions
---------------------------------------------------------------------------------------------------
function CommodityStats:OnConfigure(sCommand, sArgs)
if sArgs ~= nil then
if sArgs:lower() == "rover" then
Event_FireGenericEvent("SendVarToRover", "Commodity Prices", self.statistics)
Event_FireGenericEvent("SendVarToRover", "Commodity Transactions", self.transactions)
glog:info("Sent statistics to Rover")
return
end
if sArgs:lower() == "forceaverage" then
glog:info("Resetting the last average time of each scan to zero and invoking scan. This could timeout with large collections")
for itemid, stats in pairs(self.statistics) do
stats.earliest = nil
end
self:AverageStatistics()
return
end
if sArgs:lower() == "log" then
self:DisplayTransactions()
return
end
end
self.wndMain:Show(true)
self:OnTabSelected(nil, nil, nil, true)
end
function CommodityStats:OnSettingsSave(wndHandler, wndControl, eMouseButton)
self.settings.daysToKeep = tonumber(self.wndConfig:FindChild("txtStatisticsAge"):GetText())
self.settings.daysUntilAverage = tonumber(self.wndConfig:FindChild("txtStatisticsAverage"):GetText())
wndControl:SetText(L["Saved!"])
end
function CommodityStats:OnCancel()
self.wndMain:Show(false)
end
function CommodityStats:OnScanData( wndHandler, wndControl, eMouseButton )
self.ScanButton:SetText(L["Scanning..."])
self.ScanButton:Enable(false)
local queue = {}
for idx, tTopCategory in ipairs(MarketplaceLib.GetCommodityFamilies()) do
for idx2, tMidCategory in ipairs(MarketplaceLib.GetCommodityCategories(tTopCategory.nId)) do
for idx3, tBotCategory in pairs(MarketplaceLib.GetCommodityTypes(tMidCategory.nId)) do
for idx4, tItem in pairs(MarketplaceLib.GetCommodityItems(tBotCategory.nId)) do
table.insert(queue, tItem.nId)
end
end
end
end
self.queueSize = #queue
glog:info("Requesting price info on " .. tostring(self.queueSize) .. " items.")
self.isScanning = true
for i, id in ipairs(queue) do
MarketplaceLib.RequestCommodityInfo(id)
end