vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | local locals = KC_ITEMS_LOCALS.modules.auction |
2 | |||
3 | KC_Auction = KC_ItemsModule:new({ |
||
4 | type = "auction", |
||
5 | name = locals.name, |
||
6 | desc = locals.description, |
||
7 | cmdOptions = locals.chat, |
||
8 | dependencies = {"common"}, |
||
9 | optPath = {"options"}, |
||
10 | db = AceDatabase:new("KC_AuctionDB") |
||
11 | |||
12 | }) |
||
13 | |||
14 | KC_Items:Register(KC_Auction) |
||
15 | |||
16 | function KC_Auction:Enable() |
||
17 | if (not self:GetOpt({"options"}, "filters") ) then |
||
18 | self:SetOpt({"options"}, "filters", "1,1,1,1,1,1,1,1,1,1") |
||
19 | end |
||
20 | self:RegisterEvent("AUCTION_HOUSE_SHOW") |
||
21 | self.classes = {GetAuctionItemClasses()} |
||
22 | if (self.app.tooltip) then |
||
23 | self.app.tooltip:RegisterFunc(self, "Tooltip") |
||
24 | end |
||
25 | end |
||
26 | |||
27 | function KC_Auction:Disable() |
||
28 | KC_ItemsModule.Disable(self) |
||
29 | if (self.app.tooltip) then |
||
30 | self.app.tooltip:UnregisterFunc(self, "Tooltip") |
||
31 | end |
||
32 | end |
||
33 | |||
34 | function KC_Auction:AUCTION_HOUSE_SHOW() |
||
35 | self.gui.frame:SetParents(); |
||
36 | self.gui.frame:Initialize(self, self.gui.config) |
||
37 | self.gui.frame:OnLoad() |
||
38 | self:UnregisterEvent("AUCTION_HOUSE_SHOW"); |
||
39 | end |
||
40 | |||
41 | -- Auction Scanning Code. |
||
42 | function KC_Auction:Scan() |
||
43 | |||
44 | if(not AuctionFrame:IsVisible()) then |
||
45 | self:ScanCleanup(true) |
||
46 | self:Msg(locals.auction.cantscan) |
||
47 | return |
||
48 | end |
||
49 | |||
50 | local targets = self:GetOpt({"options"}, "filters") |
||
51 | |||
52 | BrowseNoResultsText:Show() |
||
53 | BrowseNoResultsText:SetText("") |
||
54 | |||
55 | for i=1, NUM_BROWSE_TO_DISPLAY do |
||
56 | button = getglobal("BrowseButton"..i) |
||
57 | button:Hide() |
||
58 | end |
||
59 | |||
60 | if (strfind(targets, "1")) then |
||
61 | self.scanning = true |
||
62 | self.done = false |
||
63 | self.targets = {} |
||
64 | |||
65 | for i,v in {self.common:Explode(targets, ",")} do |
||
66 | _ = ((v == 1) and tinsert(self.targets, i)) |
||
67 | end |
||
68 | |||
69 | for i = 0, 15 do |
||
70 | local chk = self.gui.frame["FilterChk" .. i] |
||
71 | chk:Disable() |
||
72 | end |
||
73 | |||
74 | self:Hook("CanSendAuctionQuery", function () if (self.Hooks.CanSendAuctionQuery.orig()) then self:NextPage() end end) |
||
75 | self:Hook("AuctionFrameBrowse_OnEvent", function () end) |
||
76 | |||
77 | self:RegisterEvent("AUCTION_ITEM_LIST_UPDATE" , "AuctionUpdate") |
||
78 | self:RegisterEvent("AUCTION_HOUSE_CLOSED" , "ScanCanceled") |
||
79 | |||
80 | else |
||
81 | self:ScanCleanup(true) |
||
82 | BrowseNoResultsText:SetText(locals.auction.notargets) |
||
83 | end |
||
84 | end |
||
85 | |||
86 | function KC_Auction:NextPage() |
||
87 | local maxPages |
||
88 | if (self.page) then |
||
89 | local numBatchAuctions, totalAuctions = GetNumAuctionItems("list") |
||
90 | maxPages= floor(totalAuctions / NUM_AUCTION_ITEMS_PER_PAGE) |
||
91 | |||
92 | if (totalAuctions == 0 or self.done) then |
||
93 | self:ScanDone() |
||
94 | return; |
||
95 | end |
||
96 | |||
97 | BrowseNoResultsText:SetText(format(locals.auction.scanning, self.page + 1, (maxPages or 0) + 1, self.classes[self.target])) |
||
98 | |||
99 | if (self.page < maxPages) then |
||
100 | self.page = self.page + 1 |
||
101 | else |
||
102 | if (getn(self.targets) > 0) then |
||
103 | self.target = tremove(self.targets, 1) |
||
104 | self.page = 0 |
||
105 | else |
||
106 | self.done = true |
||
107 | self.page = self.page +1 |
||
108 | end |
||
109 | end |
||
110 | else |
||
111 | self.page = 0 |
||
112 | self.target = tremove(self.targets, 1) |
||
113 | BrowseNoResultsText:SetText(locals.auction.settingup) |
||
114 | end |
||
115 | self.needScan = true |
||
116 | |||
117 | QueryAuctionItems("", "", "", nil, self.target, nil, self.page, nil, nil) |
||
118 | |||
119 | end |
||
120 | |||
121 | function KC_Auction:AuctionUpdate() |
||
122 | if (not self.needScan) then return end |
||
123 | |||
124 | for id = 1, GetNumAuctionItems("list") do |
||
125 | local link = GetAuctionItemLink("list", id) |
||
126 | local _, _, count, _, _, _, minBid, _, buyoutPrice, bidAmount, _, _ = GetAuctionItemInfo("list", id) |
||
127 | self:ProcessItem(link, count, minBid, bidAmount, buyoutPrice) |
||
128 | end |
||
129 | |||
130 | self.needScan = false |
||
131 | end |
||
132 | |||
133 | function KC_Auction:ScanDone() |
||
134 | BrowseNoResultsText:SetText(locals.auction.done) |
||
135 | self:ScanCleanup() |
||
136 | end |
||
137 | |||
138 | function KC_Auction:ScanCanceled() |
||
139 | BrowseNoResultsText:SetText(locals.auction.canceled) |
||
140 | self:ScanCleanup() |
||
141 | end |
||
142 | |||
143 | function KC_Auction:ScanCleanup(lite) |
||
144 | |||
145 | if (not lite) then |
||
146 | self:Unhook("CanSendAuctionQuery") |
||
147 | self:Unhook("AuctionFrameBrowse_OnEvent") |
||
148 | |||
149 | self:UnregisterEvent("AUCTION_ITEM_LIST_UPDATE") |
||
150 | self:UnregisterEvent("AUCTION_HOUSE_CLOSED") |
||
151 | |||
152 | self:ProcessSnapshot() |
||
153 | end |
||
154 | |||
155 | for i = 0, 15 do |
||
156 | local chk = self.gui.frame["FilterChk" .. i] |
||
157 | chk:Enable() |
||
158 | end |
||
159 | |||
160 | self.gui.frame.ScanButton:SetValue(locals.labels.scan) |
||
161 | |||
162 | self.snapshot = (self.snapshot and self.persistent) and self.snapshot or nil |
||
163 | |||
164 | self.page = nil |
||
165 | self.needScan = false |
||
166 | self.target = nil |
||
167 | self.targets = nil |
||
168 | self.done = false |
||
169 | self.scanning = nil |
||
170 | self.gui.frame.scanning = nil |
||
171 | |||
172 | end |
||
173 | |||
174 | function KC_Auction:ProcessItem(link, count, min, bid, buy) |
||
175 | local code = self.common:GetCode(link, true); |
||
176 | |||
177 | self.snapshot = self.snapshot or {} |
||
178 | self.snapshot[code] = self.snapshot[code] or {} |
||
179 | self.snapshot[code].buys = (buy > 0) and ((self.snapshot[code].buys or "") .. self.common:Round(buy/count,3) .. ",") or self.snapshot[code].buys |
||
180 | self.snapshot[code].buycount= (buy > 0) and (self.snapshot[code].buycount or 0) + 1 or self.snapshot[code].buycount |
||
181 | self.snapshot[code].bids = (bid > 0) and ((self.snapshot[code].bids or "") .. self.common:Round(bid/count,3) .. ",") or self.snapshot[code].bids |
||
182 | self.snapshot[code].bidcount= (bid > 0) and (self.snapshot[code].bidcount or 0) + 1 or self.snapshot[code].bidcount |
||
183 | self.snapshot[code].mins = (self.snapshot[code].mins or "") .. self.common:Round(min/count,3) .. "," |
||
184 | self.snapshot[code].stacks = (self.snapshot[code].stacks or "") .. count .. "," |
||
185 | self.snapshot[code].seen = (self.snapshot[code].seen or 0) + 1 |
||
186 | end |
||
187 | |||
188 | function KC_Auction:ProcessSnapshot() |
||
189 | if (not self.snapshot) then return end |
||
190 | |||
191 | local realmFactionID = self.common:GetRealmFactionID() |
||
192 | local nWeight = .65 |
||
193 | local sWeight = .35 |
||
194 | |||
195 | for item in self.snapshot do |
||
196 | local sSeen, sAvgStack, sMin, sBidcount, sBid, sBuycount, sBuy = self:GetItemData(item) |
||
197 | |||
198 | local buys = {self.common:Explode(self.snapshot[item].buys, ",")} |
||
199 | local bids = {self.common:Explode(self.snapshot[item].bids, ",")} |
||
200 | local mins = {self.common:Explode(self.snapshot[item].mins, ",")} |
||
201 | local stacks = {self.common:Explode(self.snapshot[item].stacks, ",")} |
||
202 | |||
203 | buys = getn(buys) > 0 and buys or nil |
||
204 | bids = getn(bids) > 0 and bids or nil |
||
205 | mins = getn(mins) > 0 and mins or nil |
||
206 | stacks = getn(stacks) > 0 and stacks or nil |
||
207 | |||
208 | local nMin = mins and self.common:BellCurve(mins) or 0 |
||
209 | local nBid = bids and self.common:BellCurve(bids) or 0 |
||
210 | local nBuy = buys and self.common:BellCurve(buys) or 0 |
||
211 | |||
212 | local nAvgStack = stacks and self.common:Avg(stacks) or 0 |
||
213 | |||
214 | nMin = (sMin and sMin > 0) and self.common:WeightedAvg(nMin, sMin, nWeight, sWeight) or nMin |
||
215 | nBid = (sBid and sBid > 0) and self.common:WeightedAvg(nBid, sBid, nWeight, sWeight) or nBid |
||
216 | nBuy = (sMin and sMin > 0) and self.common:WeightedAvg(nBuy, sMin, nWeight, sWeight) or nBuy |
||
217 | |||
218 | nAvgStack = (sAvgStack and sAvgStack > 0) and self.common:WeightedAvg(nAvgStack, sAvgStack, nWeight, sWeight) or nAvgStack |
||
219 | |||
220 | local nSeen = self.snapshot[item].seen + (sSeen or 0) |
||
221 | local nBidcount = (self.snapshot[item].bidcount or 0) + (sBidcount or 0) |
||
222 | local nBuycount = (self.snapshot[item].buycount or 0) + (sBuycount or 0) |
||
223 | |||
224 | self.db:set({realmFactionID}, item, format("%s:%s:%s:%s:%s:%s:%s", nSeen, nAvgStack, nMin, nBidcount, nBid, nBuycount, nBuy)) |
||
225 | end |
||
226 | end |
||
227 | |||
228 | function KC_Auction:GetItemData(code) |
||
229 | return self.common:Explode(self.db:get({self.common:GetRealmFactionID()}, code) or "0", ":"); |
||
230 | end |
||
231 | |||
232 | function KC_Auction:EnablePersistence() |
||
233 | self.persistent = true; |
||
234 | end |
||
235 | |||
236 | function KC_Auction:Tooltip(tooltip, code, lcode, qty, hooker) |
||
237 | local sSeen, sAvgStack, sMin, sBidcount, sBid, sBuycount, sBuy = self:GetItemData(lcode) |
||
238 | |||
239 | if (sSeen == 0) then return end |
||
240 | |||
241 | local short = self:GetOpt(self.optPath, "short") |
||
242 | local single = self:GetOpt(self.optPath, "single") |
||
243 | local stats = self:GetOpt(self.optPath, "showstats") |
||
244 | local showbid = self:GetOpt(self.optPath, "showbid") |
||
245 | |||
246 | local mLabel = format(short and locals.labels.min.short or locals.labels.min.long, qty) |
||
247 | local bLabel = format(short and locals.labels.buy.short or locals.labels.buy.long, qty) |
||
248 | local iLabel = format(short and locals.labels.bid.short or locals.labels.bid.long, qty) |
||
249 | local hLabel = format(locals.labels.header, qty) |
||
250 | local sLabel = format(locals.labels.stats, sSeen, self.common:Round(sAvgStack, 2)) |
||
251 | |||
252 | _ = (not short) and hooker:AddTextLine( tooltip, hLabel) |
||
253 | _ = (sMin and sMin > 0) and hooker:AddPriceLine(tooltip, sMin * qty, mLabel, locals.sep, locals.sepcolor) |
||
254 | _ = (sBuy and sBuy > 0) and hooker:AddPriceLine(tooltip, sBuy * qty, bLabel, locals.sep, locals.sepcolor) |
||
255 | _ = (showbid and tonumber(sBid) and sBid > 0) and hooker:AddPriceLine(tooltip, sBid * qty, iLabel, locals.sep, locals.sepcolor) |
||
256 | _ = (stats) and hooker:AddTextLine( tooltip, sLabel) |
||
257 | end |