forked from Auctionator/Auctionator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AuctionatorScan.lua
executable file
·1593 lines (1091 loc) · 38.2 KB
/
AuctionatorScan.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local addonName, addonTable = ...
local ZT = addonTable.ztt.ZT;
local zc = addonTable.zc
local zz = zc.md
local _
local ItemUpgradeInfo = LibStub( 'LibItemUpgradeInfo-1.0' )
local gAllScans = {};
local BIGNUM = 999999999999;
gScanHistDayZero = time({year=2010, month=11, day=15, hour=0}); -- never ever change
local gNumNilItemLinks
-----------------------------------------
AtrScan = {};
AtrScan.__index = AtrScan;
-----------------------------------------
AtrSearch = {};
AtrSearch.__index = AtrSearch;
-----------------------------------------
function Atr_GetExactMatchText (searchText)
local emtext = nil;
if (zc.IsTextQuoted (searchText)) then
emtext = string.sub (searchText, 2, searchText:len()-1);
end
return emtext;
end
-----------------------------------------
function Atr_NewSearch (itemName, IDstring, itemLink, rescanThreshold)
local srch = {};
setmetatable (srch, AtrSearch);
srch:Init (itemName, IDstring, itemLink, rescanThreshold);
return srch;
end
-----------------------------------------
function AtrSearch:Init (searchText, IDstring, itemLink, rescanThreshold)
Auctionator.Debug.Message( 'AtrSearch:Init', searchText, IDstring, itemLink, rescanThreshold )
if (searchText == nil) then
searchText = ""
end
self.origSearchText = searchText
self.exactMatchText = nil;
self.searchText = searchText
if (IDstring == nil) then
self.exactMatchText = Atr_GetExactMatchText(searchText)
if (self.exactMatchText) then
self.searchText = self.exactMatchText
end
end
self.IDstring = IDstring
self.processing_state = Auctionator.Constants.SearchStates.NULL
self.current_page = -1
self.items = {}
self.query = Atr_NewQuery()
self.sortedScans = nil
self.sortHow = Auctionator.Constants.Sort.PRICE_ASCENDING
self.shopListIndex = 1
self.shplist = Atr_GetShoppingListFromSearchText (self.searchText)
if Atr_IsCompoundSearch( self.searchText ) then
_, _, _, _, self.minItemLevel, self.maxItemLevel = Atr_ParseCompoundSearch( self.searchText )
end
Auctionator.Util.Print( self, 'AtrSearch:Init' )
if (IDstring) then
if (rescanThreshold and rescanThreshold > 0) then
local scan = Atr_FindScan (IDstring, searchText);
if (scan and (time() - scan.whenScanned) <= rescanThreshold) then
self.items[IDstring] = scan;
self.items[IDstring]:UpdateItemLink (itemLink);
end
end
if (not self.items[IDstring]) then
self.items[IDstring] = Atr_FindScanAndInit (IDstring, searchText);
self.items[IDstring]:UpdateItemLink (itemLink);
end
end
end
-----------------------------------------
function Atr_FindScanAndInit (IDstring, itemName)
Auctionator.Debug.Message( 'Atr_FindScanAndInit', IDstring, itemName )
return Atr_FindScan (IDstring, itemName, true);
end
-----------------------------------------
function Atr_FindScan (IDstring, itemName, init)
Auctionator.Debug.Message( 'Atr_FindScan', IDstring, itemName, init )
if (IDstring == nil or IDstring == "" or IDstring == "0") then
IDstring = "0";
itemName = "nil";
end
if (gAllScans[IDstring] == nil and itemName ~= nil) then -- if no itemName provided then we can't create
local scn = {};
setmetatable (scn, AtrScan);
gAllScans[IDstring] = scn;
init = true;
end
if (init and gAllScans[IDstring] ~= nil) then
gAllScans[IDstring]:Init (IDstring, itemName);
end
return gAllScans[IDstring];
end
-----------------------------------------
function Atr_ClearScanCache ()
for a,v in pairs (gAllScans) do
if (a ~= "0") then
gAllScans[a] = nil;
end
end
end
-----------------------------------------
function AtrScan:Init (IDstring, itemName)
self.IDstring = IDstring;
if (itemName) then
self.itemName = itemName;
end
self.itemLink = nil;
self.scanData = {};
self.sortedData = {};
self.whenScanned = 0;
self.lowprice = BIGNUM;
self.absoluteBest = nil;
self.itemClass = 0;
self.itemSubclass = 0;
self.itemLevel = 0;
self.yourBestPrice = nil;
self.yourWorstPrice = nil;
self.itemTextColor = { 1.0, 1.0, 1.0 };
self.searchText = nil;
end
-----------------------------------------
function AtrScan:UpdateItemLink (itemLink)
Auctionator.Debug.Message( itemLink )
if (itemLink and self.itemLink == nil) then
self.itemLink = itemLink;
local _, quality, iLevel, sType, sSubType;
if (zc.IsBattlePetLink (itemLink)) then
local speciesID, level, breedQuality = zc.ParseBattlePetLink (itemLink)
iLevel = level;
quality = breedQuality;
self.itemClass = LE_ITEM_CLASS_BATTLEPET;
self.itemSubclass = 0;
else
Auctionator.Util.Print( { GetItemInfo( itemLink ) }, 'GET ITEM INFO' .. itemLink )
-- TODO: Capture this knowledge somewhere
-- 1: name
-- 2: itemLink
-- 3: quality
-- 4: iLevel
-- 5: required Level
-- 6: itemClass String
-- 7: subClass String
-- 8: ? (int)
-- 9: WTF String
-- 10: big int
-- 11: big int
-- 12: itemClass int
-- 13: subClass int
_, _, quality, _, _, sType, sSubType, _, _, _, _, itemClass, itemSubClass = GetItemInfo(itemLink);
iLevel = ItemUpgradeInfo:GetUpgradedItemLevel( itemLink )
self.itemClass = itemClass
self.itemSubclass = itemSubClass
end
self.itemQuality = quality;
self.itemLevel = iLevel;
self.itemTextColor = { 0.75, 0.75, 0.75 };
if (quality == 0) then self.itemTextColor = { 0.6, 0.6, 0.6 }; end
if (quality == 1) then self.itemTextColor = { 1.0, 1.0, 1.0 }; end
if (quality == 2) then self.itemTextColor = { 0.2, 1.0, 0.0 }; end
if (quality == 3) then self.itemTextColor = { 0.0, 0.5, 1.0 }; end
if (quality == 4) then self.itemTextColor = { 0.7, 0.3, 1.0 }; end
end
end
-----------------------------------------
function AtrSearch:NumScans()
if (self.sortedScans) then
return #self.sortedScans;
end
local idstr,scn;
local count = 0;
for idstr,scn in pairs (self.items) do
count = count + 1;
end
return count;
end
-----------------------------------------
function AtrSearch:NumSortedScans()
if (self.sortedScans) then
return #self.sortedScans;
end
return 0;
end
-----------------------------------------
function AtrSearch:GetFirstScan()
if (self.sortedScans) then
return self.sortedScans[1];
end
local idstr,scn;
for idstr,scn in pairs (self.items) do
return scn;
end
return nil
end
-----------------------------------------
function AtrSearch:Start ()
Auctionator.Debug.Message( 'AtrSearch:Start' )
Auctionator.Util.Print( self, 'AtrSearch:Start' )
if self.searchText == "" then
return
end
if Atr_IsCompoundSearch( self.searchText ) then
self.sortHow = Auctionator.Constants.Sort.PRICE_DESCENDING
end
-- make sure all the matches in the scan db are in memory
local numpulled = 0;
if (self.exactMatchtext == nil and not self.IDstring and not Atr_IsCompoundSearch (self.searchText) and string.len(self.searchText) > 2) then
local name, info, itemLink;
for name, info in pairs(gAtr_ScanDB) do
if (zc.StringContains (name, self.searchText)) then
if (type(info) == "table" and info.id) then
local itemID, suffixID = strsplit(":", info.id);
if (suffixID == nil) then -- for now; seems problematic for many green "of the" items
itemLink = zc.PullItemIntoMemory (itemID, suffixID);
numpulled = numpulled + 1;
end
end
end
end
end
-- make sure all the items in the shopping list are in memory
if (self.shplist) then
local n
for n = 1,self.shplist:GetNumItems() do
local itemname = zc.TrimQuotes(self.shplist:GetNthItemName (n))
local dbInfo = gAtr_ScanDB[itemname]
if (dbInfo and dbInfo.id) then
zc.PullItemIntoMemory (dbInfo.id);
numpulled = numpulled + 1;
end
end
end
gNumNilItemLinks = 0
self.processing_state = Auctionator.Constants.SearchStates.SETTING_SORT;
if (Atr_ILevelHist_Init) then
Atr_ILevelHist_Init()
end
SortAuctionClearSort ("list");
-- not necessary but nice when user switches to Browse tab
local displayText = Atr_ParseCompoundSearch( self.searchText )
BrowseName:SetText( displayText )
self.current_page = 0;
self.processing_state = Auctionator.Constants.SearchStates.PRE_QUERY;
self:Continue();
end
-----------------------------------------
function AtrSearch:Abort ()
if (self.processing_state == Auctionator.Constants.SearchStates.NULL) then
return;
end
self.processing_state = Auctionator.Constants.SearchStates.NULL;
self:Init();
end
-----------------------------------------
function AtrSearch:CapturePageInfo ()
self.query:CapturePageInfo(self.current_page)
end
-----------------------------------------
function AtrSearch:CheckForDuplicatePage ()
local isDup = self.query:CheckForDuplicatePage(self.current_page);
if (isDup) then
self.current_page = self.current_page - 1; -- requery the page
self.processing_state = Auctionator.Constants.SearchStates.PRE_QUERY;
end
return isDup;
end
-----------------------------------------
function AtrSearch:ShouldAnalyze()
-- hopefully this will never happen but need check to avoid looping
if self.query.numDupPages > 50 then
return false
end
-- give Blizz servers a break (200 pages)
if self.current_page == 1 and self.query.totalAuctions > 10000 then
Atr_Error_Display( ZT( "Too many results\n\nPlease narrow your search" ))
return false
end
return true
end
function AtrSearch:SetScanningMessage()
local shoppingListItemName = Atr_GetShoppingListItem( self )
local message = nil
if shoppingListItemName then
local pageText = ""
if self.current_page > 1 then
pageText = string.format( ZT( ": page %d" ), self.current_page)
else
pageText = " "
end
message = string.format( ZT("Scanning auctions for %s%s"), shoppingListItemName, pageText )
elseif self.query.totalAuctions >= 50 then
message = string.format(
ZT("Scanning auctions: page %d of %d"), self.current_page,
ceil( self.query.totalAuctions / NUM_AUCTION_ITEMS_PER_PAGE
)
)
end
if message then
Atr_SetMessage( message )
end
end
function AtrSearch:AnalyzeResultsPage()
Auctionator.Debug.Message( 'AnalyzeResultsPage:', self.query.totalAuctions )
self.processing_state = Auctionator.Constants.SearchStates.ANALYZING;
if not self:ShouldAnalyze() then
return true
end
self:SetScanningMessage()
-- analyze
local numNilOwners = 0
if self.query.curPageInfo.numOnPage > 0 then
for x = 1, self.query.curPageInfo.numOnPage do
local item = self.query.curPageInfo.auctionInfo[ x ]
if item.itemLink then
local item_link = Auctionator.ItemLink:new({ item_link = item.itemLink })
if Atr_ILevelHist_Update then
Atr_ILevelHist_Update( item.itemLink )
end
if zc.IsBattlePetLink( item.itemLink ) then
Auctionator.Debug.Message( 'AtrSearch:AnalyzeResultsPage isBattlePet ', item_link:IdString() )
Auctionator.Util.Print( item_link, 'Battle Pet Item Link')
ATR_AddToBattlePetIconCache( item.itemLink, item.texture )
end
local OKitemLevel = true
if self.minItemLevel or self.maxItemLevel then
local iLevel = ItemUpgradeInfo:GetUpgradedItemLevel( item.itemLink )
OKitemLevel = not (
( self.minItemLevel and iLevel < self.minItemLevel ) or
( self.maxItemLevel and iLevel > self.maxItemLevel )
)
end
if OKitemLevel and owner == nil then
numNilOwners = numNilOwners + 1
end
if OKitemLevel and ( self.exactMatchText == nil or zc.StringSame( item.name, self.exactMatchText )) then
if self.items[ item_link:IdString() ] == nil then
self.items[ item_link:IdString() ] = Atr_FindScanAndInit( item_link:IdString(), item.name )
end
local scn = self.items[ item_link:IdString() ]
if scn then
local curpage = tonumber( self.current_page ) - 1
scn:AddScanItem( item.count, item.buyoutPrice, item.owner, 1, curpage )
scn:UpdateItemLink( item.itemLink )
end
end
else
gNumNilItemLinks = gNumNilItemLinks + 1
end
end
end
local done = self.query.curPageInfo.numOnPage < 50
if done and self.shplist then
self.shopListIndex = self.shopListIndex + 1
local nextSearchItem = Atr_GetShoppingListItem( self )
if nextSearchItem then
self.current_page = 0
self.exactMatchText = nil
done = false
end
end
if not done then
self.processing_state = Auctionator.Constants.SearchStates.PRE_QUERY
end
return done
end
-----------------------------------------
function AtrScan:AddScanItem (stackSize, buyoutPrice, owner, numAuctions, curpage)
local sd = {};
local i;
if (numAuctions == nil) then
numAuctions = 1;
end
for i = 1, numAuctions do
sd["stackSize"] = stackSize;
sd["buyoutPrice"] = buyoutPrice;
sd["owner"] = owner;
sd["pagenum"] = curpage;
tinsert (self.scanData, sd);
if (buyoutPrice and buyoutPrice > 0) then
local itemPrice = math.floor (buyoutPrice / stackSize);
self.lowprice = math.min (self.lowprice, itemPrice);
end
end
end
-----------------------------------------
function AtrScan:SubtractScanItem (stackSize, buyoutPrice)
local sd;
local i;
for i,sd in ipairs (self.scanData) do
if (sd.stackSize == stackSize and sd.buyoutPrice == buyoutPrice) then
tremove (self.scanData, i);
return;
end
end
end
-----------------------------------------
function Atr_IsShoppingListSearch (searchString)
if (searchString == nil) then
return false;
end
return zc.StringStartsWith (searchString, "{ ") and zc.StringEndsWith (searchString, " }");
end
-----------------------------------------
function Atr_GetShoppingListFromSearchText (searchString)
if (Atr_IsShoppingListSearch (searchString)) then
local len = string.len(searchString);
local shoppingListName = string.sub (searchString, 3, len-2);
return Atr_SList.FindByName (shoppingListName);
end
return nil
end
-----------------------------------------
function Atr_GetShoppingListItem (search)
if (search.shplist) then
return search.shplist:GetNthItemName (search.shopListIndex);
end
return nil;
end
-----------------------------------------
function Atr_IsCompoundSearch (searchString)
Auctionator.Debug.Message( 'Atr_IsCompoundSearch', searchString )
if (searchString == nil) then
return false;
end
Auctionator.Debug.Message( 'Atr_IsCompoundSearch', zc.StringContains (searchString, ">") or zc.StringContains (searchString, Auctionator.Constants.AdvancedSearchDivider) )
return zc.StringContains (searchString, ">") or zc.StringContains (searchString, Auctionator.Constants.AdvancedSearchDivider);
end
-----------------------------------------
local function toItemLevel (s) -- returns nil if not of the form i72 or i277, etc
if (string.len(s) > 1 and string.sub(s,1,1) == "i") then
return tonumber (string.sub(s,2))
end
return nil
end
-----------------------------------------
function Atr_ParseCompoundSearch( searchString )
local delimiter = Auctionator.Constants.AdvancedSearchDivider
if zc.StringContains( searchString, ">" ) then
delimiter = ">"
end
local queryString, filterKey, minLevel, maxLevel, minItemLevel, maxItemLevel =
strsplit( delimiter, searchString )
local filter = Auctionator.FilterLookup[ filterKey ]
-- TODO: Make this into an object when this works (sort of is as query, but needs a lot of work
-- to incorporate everywhere)
minLevel = tonumber( minLevel )
maxLevel = tonumber( maxLevel )
minItemLevel = tonumber( minItemLevel )
maxItemLevel = tonumber( maxItemLevel )
if minLevel == 0 then
minLevel = nil
end
if maxLevel == 0 then
maxLevel = nil
end
if minItemLevel == 0 then
minItemLevel = nil
end
if maxItemLevel == 0 then
maxItemLevel = nil
end
return queryString, filter, minLevel, maxLevel, minItemLevel, maxItemLevel
end
-----------------------------------------
function AtrSearch:Continue()
local canQuery = CanSendAuctionQuery()
Auctionator.Debug.Message( 'AtrSearch:Continue', canQuery )
if canQuery then
self.processing_state = KM_IN_QUERY;
local queryString;
local filterData = nil
local minLevel = nil;
local maxLevel = nil;
if (Atr_IsCompoundSearch(self.searchText)) then
queryString, filterData, minLevel, maxLevel = Atr_ParseCompoundSearch (self.searchText);
elseif (self.shplist) then
queryString = Atr_GetShoppingListItem (self)
self.exactMatchText = Atr_GetExactMatchText(queryString)
if (self.exactMatchText) then
queryString = self.exactMatchText
end
-- skip nested shopping lists or compound searches
while (Atr_IsShoppingListSearch(queryString) or Atr_IsCompoundSearch(queryString)) do
zc.md ("Skipping ", queryString);
self.shopListIndex = self.shopListIndex + 1
queryString = Atr_GetShoppingListItem (self)
if (queryString == nil) then
break
end
end
if (queryString == nil) then
queryString = "?????";
end
else
queryString = self.searchText;
end
local exactMatch = (self.exactMatchText ~= nil or self.IDstring ~= nil)
local filter = nil
if filterData ~= nil then
filter = filterData.filter
end
queryString = Auctionator.Util.UTF8_Truncate( queryString ) -- attempting to reduce number of disconnects
Auctionator.Util.Print( filter )
Auctionator.Util.Print(
{ queryString, minLevel, maxLevel, self.current_page, nil, nil, false, exactMatch, filter },
'QUERY AUCTION ITEMS PARAMS'
)
QueryAuctionItems (queryString, minLevel, maxLevel, self.current_page, nil, nil, false, exactMatch, filter )
self.query_sent_when = gAtr_ptime;
self.processing_state = Auctionator.Constants.SearchStates.POST_QUERY;
self.current_page = self.current_page + 1;
end
end
-----------------------------------------
local gSortScansBy;
-----------------------------------------
local function Atr_SortScans (x, y)
if (gSortScansBy == Auctionator.Constants.Sort.NAME_ASCENDING) then return string.lower (x.itemName) < string.lower (y.itemName); end
if (gSortScansBy == Auctionator.Constants.Sort.NAME_DESCENDING) then return string.lower (x.itemName) > string.lower (y.itemName); end
local xprice = 0;
local yprice = 0;
if (x.absoluteBest) then xprice = zc.round(x.absoluteBest.buyoutPrice/x.absoluteBest.stackSize); end;
if (y.absoluteBest) then yprice = zc.round(y.absoluteBest.buyoutPrice/y.absoluteBest.stackSize); end;
if (gSortScansBy == Auctionator.Constants.Sort.PRICE_ASCENDING) then return xprice < yprice; end
if (gSortScansBy == Auctionator.Constants.Sort.PRICE_DESCENDING) then return xprice > yprice; end
end
-----------------------------------------
function AtrSearch:Finish()
local finishTime = time();
self.processing_state = Auctionator.Constants.SearchStates.NULL;
self.current_page = -1;
self.query_sent_when = nil;
-- add scans for items that weren't found (at least for items that are in the scan db)
if (self.exactMatchText == nil and not self.IDstring) then
if (not Atr_IsCompoundSearch (self.searchText)) then
local name, info;
for name, info in pairs(gAtr_ScanDB) do
if (zc.StringContains (name, self.searchText)) then
if (info.id and self.items[info.id] == nil) then
local itemID, suffixID = strsplit(":", info.id);
if (suffixID == nil) then -- for now; seems problematic for many green "of the" items
self.items[info.id] = Atr_FindScanAndInit (info.id, name);
local itemLink = zc.LinkFromItemID (itemID, suffixID);
if (itemLink) then
self.items[info.id]:UpdateItemLink (itemLink)
end
end
end
end
end
end
end
-- add scans for items in the shopping list that weren't found
if (self.shplist) then
local n
for n = 1,self.shplist:GetNumItems() do
local itemname = zc.TrimQuotes(self.shplist:GetNthItemName (n))
local dbInfo = gAtr_ScanDB[itemname]
if (dbInfo and dbInfo.id) then
local IDstring = dbInfo.id
if (self.items[IDstring] == nil) then
self.items[IDstring] = Atr_FindScanAndInit (IDstring, itemname)
local itemLink = zc.LinkFromItemID (IDstring);
if (itemLink) then
self.items[IDstring]:UpdateItemLink (itemLink)
end
end
else -- not in scandb
local IDstring = "***"..itemname
self.items[IDstring] = Atr_FindScanAndInit (IDstring, itemname)
end
end
end
-- create an empty scan if there were no matches
self.sortedScans = nil;
if (self:NumScans() == 0) then
local dbInfo = gAtr_ScanDB[self.searchText]
if (dbInfo and dbInfo.id) then -- so that we see the history tab, etc.
local IDstring = dbInfo.id;
self.items[IDstring] = Atr_FindScan (IDstring, self.searchText, true);
else
self.items["0"] = Atr_FindScan (nil);
end
end
-- process the scans
local broadcastInfo = {};
local x = 1;
self.sortedScans = {};
for IDstring,scn in pairs (self.items) do
self.sortedScans[x] = scn;
x = x + 1;
scn.whenScanned = finishTime;
scn.searchText = self.searchText;
scn:CondenseAndSort ();
-- update the fullscan DB
if (scn.lowprice < BIGNUM) then
if scn.itemQuality == nil then
Auctionator.Debug.Message( 'Error: scn.itemQuality == nil, scn.itemName: ' .. scn.itemName )
end
if (scn.itemQuality ~= nil and (scn.itemQuality + 1 >= AUCTIONATOR_SCAN_MINLEVEL or scn.quality == -1)) then -- battle pets can be UNKNOWN (-1) quality
Atr_UpdateScanDBprice (scn.itemName, scn.lowprice);
Atr_UpdateScanDBclassInfo (scn.itemName, scn.itemClass, scn.itemSubclass);
Atr_UpdateScanDBitemID (scn.itemName, scn.itemLink);
table.insert (broadcastInfo, {i=scn.IDstring, p=scn.lowprice});
end
end
end
if (gNumNilItemLinks > 0) then
zc.msg_anm ("Number of nil links found during scan: ", gNumNilItemLinks)
end
Atr_Broadcast_DBupdated (#broadcastInfo, "partialscan", broadcastInfo);
if (Atr_ILevelHist_Print) then
Atr_ILevelHist_Print()
end
gSortScansBy = self.sortHow;
table.sort (self.sortedScans, Atr_SortScans);
end
-----------------------------------------
function AtrSearch:ClickPriceCol()
if (self.sortHow == Auctionator.Constants.Sort.PRICE_ASCENDING) then
self.sortHow = Auctionator.Constants.Sort.PRICE_DESCENDING;
else
self.sortHow = Auctionator.Constants.Sort.PRICE_ASCENDING;
end
gSortScansBy = self.sortHow;
table.sort (self.sortedScans, Atr_SortScans);
end
-----------------------------------------
function AtrSearch:ClickNameCol()
if (self.sortHow == Auctionator.Constants.Sort.NAME_ASCENDING) then
self.sortHow = Auctionator.Constants.Sort.NAME_DESCENDING;
else
self.sortHow = Auctionator.Constants.Sort.NAME_ASCENDING;
end
gSortScansBy = self.sortHow;
table.sort (self.sortedScans, Atr_SortScans);
end
-----------------------------------------
function AtrSearch:UpdateArrows()
Atr_Col1_Heading_ButtonArrow:Hide();
Atr_Col3_Heading_ButtonArrow:Hide();
if (self.sortHow == Auctionator.Constants.Sort.PRICE_ASCENDING) then
Atr_Col1_Heading_ButtonArrow:Show();
Atr_Col1_Heading_ButtonArrow:SetTexCoord(0, 0.5625, 0, 1.0);
elseif (self.sortHow == Auctionator.Constants.Sort.PRICE_DESCENDING) then
Atr_Col1_Heading_ButtonArrow:Show();
Atr_Col1_Heading_ButtonArrow:SetTexCoord(0, 0.5625, 1.0, 0);
elseif (self.sortHow == Auctionator.Constants.Sort.NAME_ASCENDING) then
Atr_Col3_Heading_ButtonArrow:Show();
Atr_Col3_Heading_ButtonArrow:SetTexCoord(0, 0.5625, 0, 1.0);
elseif (self.sortHow == Auctionator.Constants.Sort.NAME_DESCENDING) then
Atr_Col3_Heading_ButtonArrow:Show();
Atr_Col3_Heading_ButtonArrow:SetTexCoord(0, 0.5625, 1.0, 0);
end
end
-----------------------------------------
function Atr_ClearBrowseListings()
if (CanSendAuctionQuery()) then
QueryAuctionItems("xyzzy", 43, 43, 0, 7, 0);
zz ("Atr_ClearBrowseListings succeeded");
end
end
-----------------------------------------
function Atr_SortAuctionData (x, y)
return x.itemPrice < y.itemPrice;
end
-----------------------------------------
function AtrScan:CondenseAndSort ()
----- Condense the scan data into a table that has only a single entry per stacksize/price combo
self.sortedData = {};
local i,sd;
local conddata = {};
for i,sd in ipairs (self.scanData) do
local ownerCode = "x";
local dataType = "n"; -- normal
if (sd.owner == UnitName("player")) then
ownerCode = "y";
-- elseif (Atr_IsMyToon (sd.owner)) then
-- ownerCode = sd.owner;
end
local key = "_"..sd.stackSize.."_"..sd.buyoutPrice.."_"..ownerCode..dataType;
if (conddata[key]) then
conddata[key].count = conddata[key].count + 1;
else
local data = {};
data.stackSize = sd.stackSize;
data.buyoutPrice = sd.buyoutPrice;
data.itemPrice = sd.buyoutPrice / sd.stackSize;
data.count = 1;
data.type = dataType;
data.yours = (ownerCode == "y");
if (ownerCode ~= "x" and ownerCode ~= "y") then
data.altname = ownerCode;