-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscanner.lua
144 lines (113 loc) · 4.31 KB
/
scanner.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
local myname, ns = ...
local INFLATION_LIMIT = 2.5 -- Maximum markup we'll allow over manually set prices
local maxes, counts, lastseen = {}, {}, {}
local allscaninprogress, touched
local mins = tekauc_data and tekauc_data.GetTable() or {}
tekauc.mins, tekauc.maxes, tekauc.counts = mins, maxes, counts
local butt = LibStub("tekKonfig-Button").new(BrowseSearchButton, "RIGHT", BrowseSearchButton, "LEFT", -10, 0)
butt:SetText("Scan All")
local function IsValidPrice(id, price)
if not tekauc.manualprices[id] then return true end
if (tekauc.manualprices[id] * INFLATION_LIMIT) >= price then return true end
end
local function ScanBlock(startindex, endindex)
for i=startindex,endindex do
local name, texture, count, quality, canUse, level, levelColHeader, minBid,
minIncrement, buyoutPrice, bidAmount, highBidder, bidderFullName, owner,
ownerFullName, saleStatus, id, hasAllInfo = GetAuctionItemInfo("list", i)
if not allscaninprogress and not touched[id] then
-- Wipe these results if it's a short scan
touched[id], mins[id], maxes[id], counts[id] = true
end
buyoutPrice = buyoutPrice / count
if buyoutPrice > 0 and IsValidPrice(id, buyoutPrice) then
if (mins[id] or 9999999999) > buyoutPrice then mins[id] = buyoutPrice end
if (maxes[id] or 0) < buyoutPrice then maxes[id] = buyoutPrice end
counts[id] = (counts[id] or 0) + count
end
end
end
local enabled = true
local TICKLENGTH = 0.1
local totalresults, nextblock, nexttick, throttle
local default_ui_was_registered
butt:SetScript("OnUpdate", function(self, elap)
-- check if we need to process a block of results
if allscaninprogress and nexttick <= GetTime() then
local endindex = nextblock + ns.block_size
if endindex > totalresults then endindex = totalresults end
ns.SendMessage("SCAN_PROGRESS", nextblock, totalresults)
local t = GetTime()
ScanBlock(nextblock, endindex)
if endindex == totalresults then
for _,sellbutt in pairs(ns.sellbutts) do sellbutt:Enable() end
ns.SendMessage("SCAN_COMPLETE", totalresults)
ns.scannedall = true
allscaninprogress = false
totalresults, nextblock = nil
if default_ui_was_registered then
AuctionFrameBrowse:RegisterEvent("AUCTION_ITEM_LIST_UPDATE")
end
else
nextblock = endindex + 1
nexttick = GetTime() + TICKLENGTH
end
end
local _, scanable = CanSendAuctionQuery("list")
if allscaninprogress or (enabled and not scanable) then self:Disable()
elseif not enabled and scanable then
self:Enable()
for _,sellbutt in pairs(ns.sellbutts) do sellbutt:Disable() end
end
enabled = scanable
end)
local allscanpending
butt:SetScript("OnClick", function(self)
mins, maxes, counts = {}, {}, {}
tekauc.mins, tekauc.maxes, tekauc.counts = mins, maxes, counts
if tekauc_data then tekauc_data.SetTable(mins) end
allscanpending = true
default_ui_was_registered = AuctionFrameBrowse:IsEventRegistered("AUCTION_ITEM_LIST_UPDATE")
AuctionFrameBrowse:UnregisterEvent("AUCTION_ITEM_LIST_UPDATE")
SortAuctionClearSort("list")
QueryAuctionItems(nil, nil, nil, nil, nil, nil, true)
end)
local function ShouldAllScan()
local num, total = GetNumAuctionItems("list")
if allscanpending and num == total then return true end
end
local function ShouldPartialScan()
if allscanpending or allscaninprogress then return false end
if GetNumAuctionItems("list") > 5000 then return false end
if AuctionFrameBrowse.page ~= 0 then return false end
local column, reverse = GetAuctionSort("list", 1)
if column == "unitprice" and not reverse then return true end
end
local function BeginAllScan()
allscanpending = false
allscaninprogress = true
touched = {}
totalresults = GetNumAuctionItems("list")
nextblock = 1
nexttick = GetTime()
ns.SendMessage("SCAN_STARTING")
end
local function BeginPartialScan()
local num = GetNumAuctionItems("list")
touched = {}
ScanBlock(1, num)
end
butt:RegisterEvent("AUCTION_ITEM_LIST_UPDATE")
butt:SetScript("OnEvent", function(self)
if ShouldAllScan() then return BeginAllScan() end
if ShouldPartialScan() then BeginPartialScan() end
end)
-- Global API for any addon to query prices
local orig = GetAuctionBuyout
function GetAuctionBuyout(item)
local id = ns.ids[item]
if id and mins[id] then return mins[id] end
if id and tekauc.manualprices[id] then return tekauc.manualprices[id] end
if orig then return orig(item) end
end
tekauc.GetAuctionBuyout = GetAuctionBuyout