vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 Auctioneer Addon for World of Warcraft(tm).
3 Version: 3.9.0.1000 (Kangaroo)
4 Revision: $Id: AucScanner.lua 980 2006-08-31 05:29:48Z mentalpower $
5  
6 Auctioneer scanning functions
7 Functions to handle the auction scan procedure
8  
9 License:
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License
12 as published by the Free Software Foundation; either version 2
13 of the License, or (at your option) any later version.
14  
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19  
20 You should have received a copy of the GNU General Public License
21 along with this program(see GPL.txt); if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 ]]
24  
25 --Local function prototypes
26 local processLink, invalidateAHSnapshot, auctionStartHook, finishedAuctionScanHook, auctionEntryHook, startAuction, placeAuctionBid, relevel, configureAH, insertAHTab, auctionFrameFiltersUpdateClasses, rememberPrice, auctionsClear, auctionsSetWarn, auctionsSetLine, newAuction, auctHouseShow, auctHouseClose, auctHouseUpdate, filterButtonSetType, onChangeAuctionDuration, setAuctionDuration
27  
28 -- Hook into this function if you want notification when we find a link.
29 function processLink(link)
30 if (ItemsMatrix_ProcessLinks ~= nil) then
31 ItemsMatrix_ProcessLinks( link, -- itemLink
32 nil, -- not used atm
33 nil, -- vendorprice - not calculatable in AH
34 nil -- event - TODO: dunno, maybe only for chatevents?
35 )
36 end
37 if (LootLink_ProcessLinks ~= nil) then
38 LootLink_ProcessLinks( link, -- itemLink
39 true -- TODO: uncertain? - ah is a trustable source?
40 );
41 end
42 if (Itemizer and Itemizer.ProcessLinks) then
43 Itemizer.ProcessLinks( link, -- itemLink
44 true -- The Link comes from the API, which means it doesn't have to be split up
45 );
46 end
47 end
48  
49  
50 -- This function sets the dirty flag to true for all the auctions in the snapshot
51 -- This is done to indicate that the snapshot is out of date.
52 function invalidateAHSnapshot()
53 -- Invalidate the snapshot
54 local auctKey = Auctioneer.Util.GetAuctionKey();
55 if (not AuctionConfig.snap) then
56 AuctionConfig.snap = {};
57 end
58 if (not AuctionConfig.snap[auctKey]) then
59 AuctionConfig.snap[auctKey] = {};
60 end
61 for cat,cData in pairs(AuctionConfig.snap[auctKey]) do
62 -- Only invalidate the class group if we will be scanning it.
63 if (Auctioneer.Command.GetFilter("scan-class"..cat)) then
64 for iKey, iData in pairs(cData) do
65 -- The first char is the dirty flag (purposely)
66 AuctionConfig.snap[auctKey][cat][iKey] = "1" .. string.sub(iData,2);
67 end
68 end
69 end
70 end
71  
72 -- Called when the auction scan starts
73 function auctionStartHook() --Auctioneer_AuctionStart_Hook
74 Auction_DoneItems = {};
75 Auctioneer.Core.Variables.SnapshotItemPrices = {};
76 invalidateAHSnapshot();
77  
78 -- Make sure AuctionConfig.data is initialized
79 local serverFaction = Auctioneer.Util.GetAuctionKey();
80 if (AuctionConfig.data == nil) then AuctionConfig.data = {}; end
81 if (AuctionConfig.data[serverFaction] == nil) then
82 AuctionConfig.data[serverFaction] = {};
83 end
84  
85 -- Reset scan audit counters
86 Auctioneer.Core.Variables.TotalAuctionsScannedCount = 0;
87 Auctioneer.Core.Variables.NewAuctionsCount = 0;
88 Auctioneer.Core.Variables.OldAuctionsCount = 0;
89 Auctioneer.Core.Variables.DefunctAuctionsCount = 0;
90  
91 -- Record the auction start time
92 Auctioneer.Core.Variables.AuctionScanStart = time()
93  
94 -- Protect AuctionFrame if we should
95 if (Auctioneer.Command.GetFilterVal('protect-window') == 1) then
96 Auctioneer.Util.ProtectAuctionFrame(true);
97 end
98 end
99  
100 -- This is called when an auction scan finishes and is used for clean up
101 function finishedAuctionScanHook() --Auctioneer_FinishedAuctionScan_Hook
102 -- Only remove defunct auctions from snapshot if there was a good amount of auctions scanned.
103 local auctKey = Auctioneer.Util.GetAuctionKey();
104  
105 if (not AuctionConfig.sbuy) then AuctionConfig.sbuy = {}; end
106 if (not AuctionConfig.sbuy[auctKey]) then AuctionConfig.sbuy[auctKey] = {}; end
107  
108 if Auctioneer.Core.Variables.TotalAuctionsScannedCount >= 50 then
109 local snap, id, rprop, enchant, sig;
110  
111 if (AuctionConfig and AuctionConfig.snap and AuctionConfig.snap[auctKey]) then
112 for cat,cData in pairs(AuctionConfig.snap[auctKey]) do
113 for iKey, iData in pairs(cData) do
114 snap = Auctioneer.Core.GetSnapshotFromData(iData);
115 if (snap.dirty == "1") then
116 id, rprop, enchant = Auctioneer.Core.GetItemSignature(iKey);
117  
118 -- Clear defunct auctions
119 if (id and rprop and enchant) then
120 sig = id..":"..rprop..":"..enchant;
121 AuctionConfig.sbuy[auctKey][sig] = nil;
122 Auctioneer.Storage.SetSnapMed(auctKey, sig, nil);
123 end
124 AuctionConfig.snap[auctKey][cat][iKey] = nil;
125 Auctioneer.Core.Variables.DefunctAuctionsCount = Auctioneer.Core.Variables.DefunctAuctionsCount + 1;
126 end
127 end
128 end
129 end
130 end
131  
132 -- Copy the item prices into the Saved item prices table
133 if (Auctioneer.Core.Variables.SnapshotItemPrices) then
134 for sig, iData in pairs(Auctioneer.Core.Variables.SnapshotItemPrices) do
135 AuctionConfig.sbuy[auctKey][sig] = Auctioneer.Core.StoreMedianList(iData.buyoutPrices);
136 Auctioneer.Storage.SetSnapMed(auctKey, sig, Auctioneer.Statistic.GetMedian(iData.buyoutPrices));
137 Auctioneer.Core.Variables.SnapshotItemPrices[sig] = nil;
138 end
139 end
140  
141 local lDiscrepencyCount = Auctioneer.Core.Variables.TotalAuctionsScannedCount - (Auctioneer.Core.Variables.NewAuctionsCount + Auctioneer.Core.Variables.OldAuctionsCount);
142  
143 local totalAuctionsMessage = string.format(_AUCT('AuctionTotalAucts'), Auctioneer.Util.ColorTextWhite(Auctioneer.Core.Variables.TotalAuctionsScannedCount))
144 local newAuctionsMessage = string.format(_AUCT('AuctionNewAucts'), Auctioneer.Util.ColorTextWhite(Auctioneer.Core.Variables.NewAuctionsCount))
145 local oldAuctionsMessage = string.format(_AUCT('AuctionOldAucts'), Auctioneer.Util.ColorTextWhite(Auctioneer.Core.Variables.OldAuctionsCount))
146 local defunctAuctionsMessage = string.format(_AUCT('AuctionDefunctAucts'), Auctioneer.Util.ColorTextWhite(Auctioneer.Core.Variables.DefunctAuctionsCount))
147 local discrepanciesMessage
148  
149 Auctioneer.Util.ChatPrint(totalAuctionsMessage);
150 Auctioneer.Util.ChatPrint(newAuctionsMessage);
151 Auctioneer.Util.ChatPrint(oldAuctionsMessage);
152 Auctioneer.Util.ChatPrint(defunctAuctionsMessage);
153  
154 if (Auctioneer.Util.NullSafe(lDiscrepencyCount) > 0) then
155 discrepanciesMessage = string.format(_AUCT('AuctionDiscrepancies'), Auctioneer.Util.ColorTextWhite(lDiscrepencyCount))
156 Auctioneer.Util.ChatPrint(discrepanciesMessage);
157 end
158  
159 --Add the preceding information to the AH frame too
160 BrowseNoResultsText:SetText(totalAuctionsMessage.."\n"..newAuctionsMessage.."\n"..oldAuctionsMessage.."\n"..defunctAuctionsMessage.."\n"..(discrepanciesMessage or ""))
161  
162 --Record the auction stop time
163 Auctioneer.Core.Variables.AuctionScanStop = time()
164  
165 --Populate our scan statistics
166 Auctioneer.Statistic.SetScanLength(Auctioneer.Core.Variables.AuctionScanStart, Auctioneer.Core.Variables.AuctionScanStop)
167 Auctioneer.Statistic.SetScanAge(Auctioneer.Core.Variables.AuctionScanStop)
168  
169 --The followng was added by MentalPower to implement the "/auc finish-sound" command
170 if (Auctioneer.Command.GetFilter("finish-sound")) then
171 PlaySoundFile("Interface\\AddOns\\Auctioneer\\Sounds\\ScanComplete.ogg")
172 end
173  
174 --The followng was added by MentalPower to implement the "/auc finish" command
175 local finish = Auctioneer.Command.GetFilterVal('finish');
176  
177 if (finish == 1) then
178 Logout();
179  
180 elseif (finish == 2) then
181 Quit();
182 end
183  
184 --Cleaning up after oneself is always a good idea.
185 collectgarbage()
186 end
187  
188 -- Called by scanning hook when an auction item is scanned from the Auction house
189 -- we save the aution item to our tables, increment our counts etc
190 function auctionEntryHook(funcVars, retVal, page, index, category, nonScan) --Auctioneer_AuctionEntry_Hook
191 EnhTooltip.DebugPrint("Processing page", page, "item", index);
192 if (not nonScan) then
193 local auctionDoneKey;
194 if (not page or not index or not category) then
195 return;
196 else
197 auctionDoneKey = category.."-"..page.."-"..index;
198 end
199 if (not Auction_DoneItems[auctionDoneKey]) then
200 Auction_DoneItems[auctionDoneKey] = true;
201 else
202 return;
203 end
204 end
205  
206 Auctioneer.Core.Variables.TotalAuctionsScannedCount = Auctioneer.Core.Variables.TotalAuctionsScannedCount + 1;
207  
208 local aiName, aiTexture, aiCount, aiQuality, aiCanUse, aiLevel, aiMinBid, aiMinIncrement, aiBuyoutPrice, aiBidAmount, aiHighBidder, aiOwner = GetAuctionItemInfo("list", index);
209 if (aiOwner == nil) then aiOwner = "unknown"; end
210  
211 -- do some validation of the auction data that was returned
212 if (aiName == nil or tonumber(aiBuyoutPrice) > Auctioneer.Core.Constants.MaxAllowedFormatInt or tonumber(aiMinBid) > Auctioneer.Core.Constants.MaxAllowedFormatInt) then return; end
213 if (aiCount < 1) then aiCount = 1; end
214  
215 -- get other auctiondata
216 local aiTimeLeft = GetAuctionItemTimeLeft("list", index);
217 local aiLink = GetAuctionItemLink("list", index);
218  
219 -- Call some interested iteminfo addons
220 Auctioneer.Scanner.ProcessLink(aiLink);
221  
222 local aiItemID, aiRandomProp, aiEnchant, aiUniqID = EnhTooltip.BreakLink(aiLink);
223 local aiKey = aiItemID..":"..aiRandomProp..":"..aiEnchant;
224 local hyperlink = string.format("item:%d:%d:%d:%d", aiItemID, aiEnchant, aiRandomProp, aiUniqID);
225  
226 -- Get all item data
227 local iName, iLink, iQuality, iLevel, iClass, iSubClass, iCount, iMaxStack = GetItemInfo(hyperlink);
228 local itemCat = Auctioneer.Util.GetCatNumberByName(iClass);
229  
230 -- construct the unique auction signature for this aution
231 local lAuctionSignature = string.format("%d:%d:%d:%s:%d:%d:%d:%d", aiItemID, aiRandomProp, aiEnchant, Auctioneer.Util.NilSafeString(aiName), Auctioneer.Util.NullSafe(aiCount), Auctioneer.Util.NullSafe(aiMinBid), Auctioneer.Util.NullSafe(aiBuyoutPrice), aiUniqID);
232  
233 -- add this item's buyout price to the buyout price history for this item in the snapshot
234 if aiBuyoutPrice > 0 then
235 local buyoutPriceForOne = Auctioneer.Util.PriceForOne(aiBuyoutPrice, aiCount);
236 if (not Auctioneer.Core.Variables.SnapshotItemPrices[aiKey]) then
237 Auctioneer.Core.Variables.SnapshotItemPrices[aiKey] = {buyoutPrices={buyoutPriceForOne}, name=aiName};
238 else
239 table.insert(Auctioneer.Core.Variables.SnapshotItemPrices[aiKey].buyoutPrices, buyoutPriceForOne);
240 table.sort(Auctioneer.Core.Variables.SnapshotItemPrices[aiKey].buyoutPrices);
241 end
242 end
243  
244  
245 -- if this auction is not in the snapshot add it
246 local auctKey = Auctioneer.Util.GetAuctionKey();
247 local snap = Auctioneer.Core.GetSnapshot(auctKey, itemCat, lAuctionSignature);
248  
249 -- If we haven't seen this item (its not in the old snapshot)
250 if (not snap) then
251 EnhTooltip.DebugPrint("No snap");
252 Auctioneer.Core.Variables.NewAuctionsCount = Auctioneer.Core.Variables.NewAuctionsCount + 1;
253  
254 -- now build the list of buyout prices seen for this auction to use to get the median
255 local newBuyoutPricesList = Auctioneer.BalancedList.NewBalancedList(Auctioneer.Core.Constants.MaxBuyoutHistorySize);
256  
257 local auctionPriceItem = Auctioneer.Core.GetAuctionPriceItem(aiKey, auctKey);
258 if (not auctionPriceItem) then auctionPriceItem = {} end
259  
260 local seenCount,minCount,minPrice,bidCount,bidPrice,buyCount,buyPrice = Auctioneer.Core.GetAuctionPrices(auctionPriceItem.data);
261 seenCount = seenCount + 1;
262 minCount = minCount + 1;
263 minPrice = minPrice + Auctioneer.Util.PriceForOne(aiMinBid, aiCount);
264 if (Auctioneer.Util.NullSafe(aiBidAmount) > 0) then
265 bidCount = bidCount + 1;
266 bidPrice = bidPrice + Auctioneer.Util.PriceForOne(aiBidAmount, aiCount);
267 end
268 if (Auctioneer.Util.NullSafe(aiBuyoutPrice) > 0) then
269 buyCount = buyCount + 1;
270 buyPrice = buyPrice + Auctioneer.Util.PriceForOne(aiBuyoutPrice, aiCount);
271 end
272 auctionPriceItem.data = string.format("%d:%d:%d:%d:%d:%d:%d", seenCount,minCount,minPrice,bidCount,bidPrice,buyCount,buyPrice);
273  
274 local bph = auctionPriceItem.buyoutPricesHistoryList;
275 if (bph and table.getn(bph) > 0) then
276 newBuyoutPricesList.setList(bph);
277 end
278 if (Auctioneer.Util.NullSafe(aiBuyoutPrice) > 0) then
279 newBuyoutPricesList.insert(Auctioneer.Util.PriceForOne(aiBuyoutPrice, aiCount));
280 end
281  
282 auctionPriceItem.buyoutPricesHistoryList = newBuyoutPricesList.getList();
283 auctionPriceItem.name = aiName;
284 auctionPriceItem.category = itemCat;
285 Auctioneer.Core.SaveAuctionPriceItem(auctKey, aiKey, auctionPriceItem);
286  
287 -- finaly add the auction to the snapshot
288 if (aiOwner == nil) then aiOwner = "unknown"; end
289 local initialTimeSeen = time();
290  
291 snap = {
292 initialSeenTime=initialTimeSeen,
293 lastSeenTime=initialTimeSeen,
294 itemLink=aiLink,
295 quality=Auctioneer.Util.NullSafe(aiQuality),
296 level=Auctioneer.Util.NullSafe(aiLevel),
297 bidamount=Auctioneer.Util.NullSafe(aiBidAmount),
298 highBidder=aiHighBidder,
299 owner=aiOwner,
300 timeLeft=Auctioneer.Util.NullSafe(aiTimeLeft),
301 category=itemCat,
302 dirty=0
303 };
304  
305 else
306 EnhTooltip.DebugPrint("Snap!");
307 Auctioneer.Core.Variables.OldAuctionsCount = Auctioneer.Core.Variables.OldAuctionsCount + 1;
308 --this is an auction that was already in the snapshot from a previous scan and is still in the auction house
309 snap.dirty = 0; --set its dirty flag to false so we know to keep it in the snapshot
310 snap.lastSeenTime = time(); --set the time we saw it last
311 snap.timeLeft = Auctioneer.Util.NullSafe(aiTimeLeft); --update the time left
312 snap.bidamount = Auctioneer.Util.NullSafe(aiBidAmount); --update the current bid amount
313 snap.highBidder = aiHighBidder; --update the high bidder
314 end
315  
316 -- Commit the snapshot back to the table.
317 Auctioneer.Core.SaveSnapshot(auctKey, itemCat, lAuctionSignature, snap);
318 end
319  
320 -- hook into the auction starting process
321 function startAuction(funcArgs, retVal, start, buy, duration)
322 if (AuctPriceRememberCheck:GetChecked()) then
323 Auctioneer.Storage.SetFixedPrice(Auctioneer_CurAuctionItem, start, buy, duration, Auctioneer_CurAuctionCount)
324 end
325 Auctioneer_CurAuctionItem = nil
326 Auctioneer_CurAuctionCount = nil
327 AuctPriceRememberCheck:SetChecked(false)
328 end
329  
330 -- hook to capture data about an auction that was boughtout
331 function placeAuctionBid(funcVars, retVal, itemtype, itemindex, bidamount)
332 -- get the info for this auction
333 local aiLink = GetAuctionItemLink(itemtype, itemindex);
334 local aiItemID, aiRandomProp, aiEnchant, aiUniqID = EnhTooltip.BreakLink(aiLink);
335 local aiKey = aiItemID..":"..aiRandomProp..":"..aiEnchant;
336 local aiName, aiTexture, aiCount, aiQuality, aiCanUse, aiLevel, aiMinBid, aiMinIncrement, aiBuyout, aiBidAmount, aiHighBidder, aiOwner = GetAuctionItemInfo(itemtype, itemindex);
337  
338 local auctionSignature = string.format("%d:%d:%d:%s:%d:%d:%d:%d", aiItemID, aiRandomProp, aiEnchant, Auctioneer.Util.NilSafeString(aiName), Auctioneer.Util.NullSafe(aiCount), Auctioneer.Util.NullSafe(aiMinBid), Auctioneer.Util.NullSafe(aiBuyout), aiUniqID);
339  
340 local playerName = UnitName("player");
341 local eventTime = "e"..time();
342 if (not AuctionConfig.bids) then AuctionConfig.bids = {} end
343 if (not AuctionConfig.bids[playerName]) then
344 AuctionConfig.bids[playerName] = {};
345 end
346  
347 AuctionConfig.bids[playerName][eventTime] = string.format("%s|%s|%s|%s|%s", auctionSignature, bidamount, 0, aiOwner, aiHighBidder or "unknown");
348  
349 if bidamount == aiBuyout then -- only capture buyouts
350 local foundInSnapshot = false
351  
352 -- remove from snapshot
353 Auctioneer.Util.ChatPrint(string.format(_AUCT('FrmtActRemove'), auctionSignature));
354 local auctKey = Auctioneer.Util.GetAuctionKey();
355 local itemCat = Auctioneer.Util.GetCatForKey(aiKey);
356 if (itemCat and AuctionConfig and AuctionConfig.snap and AuctionConfig.snap[auctKey] and AuctionConfig.snap[auctKey][itemCat]) then
357 if (AuctionConfig.snap[auctKey][itemCat][auctionSignature]) then
358 foundInSnapshot = true;
359 AuctionConfig.snap[auctKey][itemCat][auctionSignature] = nil;
360 end
361 end
362 if (not AuctionConfig.bids) then AuctionConfig.bids = {} end
363 if (not AuctionConfig.bids[playerName]) then AuctionConfig.bids[playerName] = {} end
364 AuctionConfig.bids[playerName][eventTime] = string.format("%s|%s|%s|%s|%s", auctionSignature, bidamount, 1, aiOwner, aiHighBidder or "unknown");
365  
366 if (foundInSnapshot) then
367 if (Auctioneer_HSPCache and Auctioneer_HSPCache[auctKey]) then
368 Auctioneer_HSPCache[auctKey][aiKey] = nil;
369 end
370 Auctioneer_Lowests = nil;
371  
372 -- Remove from snapshot buyout list
373 local sbuy = Auctioneer.Core.GetSnapshotInfo(auctKey, aiKey)
374 if sbuy then
375 local price = Auctioneer.Util.PriceForOne(aiBuyout, aiCount);
376 -- Find price in buyout list
377 local found = table.foreachi(sbuy.buyoutPrices, function(k, v) if tonumber(v) == price then return k end end)
378 if found then
379 table.remove(sbuy.buyoutPrices, found)
380 Auctioneer.Core.SaveSnapshotInfo(auctKey, aiKey, sbuy)
381 end
382 end
383 end
384 end
385 end
386  
387 function relevel(frame) --Local
388 local myLevel = frame:GetFrameLevel() + 1
389 local children = { frame:GetChildren() }
390 for _,child in pairs(children) do
391 child:SetFrameLevel(myLevel)
392 relevel(child)
393 end
394 end
395  
396 local lAHConfigPending = true
397 function configureAH()
398 if (lAHConfigPending and IsAddOnLoaded("Blizzard_AuctionUI")) then
399 EnhTooltip.DebugPrint("Configuring AuctionUI");
400 AuctionsPriceText:ClearAllPoints();
401 AuctionsPriceText:SetPoint("TOPLEFT", "AuctionsItemText", "TOPLEFT", 0, -53);
402 AuctionsBuyoutText:ClearAllPoints();
403 AuctionsBuyoutText:SetPoint("TOPLEFT", "AuctionsPriceText", "TOPLEFT", 0, -33);
404 AuctionsBuyoutErrorText:ClearAllPoints();
405 AuctionsBuyoutErrorText:SetPoint("TOPLEFT", "AuctionsBuyoutText", "TOPLEFT", 0, -29);
406 AuctionsDurationText:ClearAllPoints();
407 AuctionsDurationText:SetPoint("TOPLEFT", "AuctionsBuyoutErrorText", "TOPLEFT", 0, -7);
408 AuctionsDepositText:ClearAllPoints();
409 AuctionsDepositText:SetPoint("TOPLEFT", "AuctionsDurationText", "TOPLEFT", 0, -31);
410 if (AuctionInfo ~= nil) then
411 AuctionInfo:ClearAllPoints();
412 AuctionInfo:SetPoint("TOPLEFT", "AuctionsDepositText", "TOPLEFT", -4, -33);
413 end
414  
415 AuctionsShortAuctionButtonText:SetText("2");
416 AuctionsMediumAuctionButton:SetPoint("TOPLEFT", "AuctionsDurationText", "BOTTOMLEFT", 3, 1);
417 AuctionsMediumAuctionButtonText:SetText("8");
418 AuctionsMediumAuctionButton:ClearAllPoints();
419 AuctionsMediumAuctionButton:SetPoint("BOTTOMLEFT", "AuctionsShortAuctionButton", "BOTTOMRIGHT", 20,0);
420 AuctionsLongAuctionButtonText:SetText("24 "..HOURS);
421 AuctionsLongAuctionButton:ClearAllPoints();
422 AuctionsLongAuctionButton:SetPoint("BOTTOMLEFT", "AuctionsMediumAuctionButton", "BOTTOMRIGHT", 20,0);
423  
424 -- set UI-texts
425 BrowseScanButton:SetText(_AUCT('TextScan'));
426 BrowseScanButton:SetParent("AuctionFrameBrowse");
427 BrowseScanButton:SetPoint("LEFT", "AuctionFrameMoneyFrame", "RIGHT", 5,0);
428 BrowseScanButton:Show();
429  
430 if (AuctionInfo) then
431 AuctionInfo:SetParent("AuctionFrameAuctions")
432 AuctionInfo:SetPoint("TOPLEFT", "AuctionsDepositText", "TOPLEFT", -4, -51)
433 AuctionInfo:Show()
434  
435 AuctPriceRemember:SetParent("AuctionFrameAuctions")
436 AuctPriceRemember:SetPoint("TOPLEFT", "AuctionsDepositText", "BOTTOMLEFT", 0, -6)
437 AuctPriceRemember:Show()
438 AuctPriceRememberText:SetText(_AUCT('GuiRememberText'))
439 AuctPriceRememberCheck:SetParent("AuctionFrameAuctions")
440 AuctPriceRememberCheck:SetPoint("TOPLEFT", "AuctionsDepositText", "BOTTOMLEFT", 0, -2)
441 AuctPriceRememberCheck:Show()
442 end
443  
444 -- Protect the auction frame from being closed.
445 -- This call is to ensure the window is protected even after you
446 -- manually load Auctioneer while already showing the AuctionFrame
447 if (Auctioneer.Command.GetFilterVal('protect-window') == 2) then
448 Auctioneer.Util.ProtectAuctionFrame(true);
449 end
450  
451 Auctioneer.Core.HookAuctionHouse()
452 AuctionFrameFilters_UpdateClasses()
453 lAHConfigPending = nil
454  
455 -- Count the number of auction house tabs
456 local tabCount = 0;
457 while (getglobal("AuctionFrameTab"..(tabCount + 1)) ~= nil) do
458 tabCount = tabCount + 1;
459 end
460  
461 -- Find the correct location to insert our Search Auctions and Post Auctions
462 -- tabs. We want to insert them at the end or before BeanCounter's
463 -- Transactions tab.
464 local tabIndex = 1;
465 while (getglobal("AuctionFrameTab"..(tabIndex)) ~= nil and
466 getglobal("AuctionFrameTab"..(tabIndex)):GetName() ~= "AuctionFrameTabTransactions") do
467 tabIndex = tabIndex + 1;
468 end
469 insertAHTab(tabIndex, AuctionFrameTabSearch, AuctionFrameSearch);
470 insertAHTab(tabIndex + 1, AuctionFrameTabPost, AuctionFramePost);
471  
472 if (not AuctionUI_Hooked) then
473 Stubby.RegisterFunctionHook("AuctionFrameTab_OnClick", 200, AuctioneerUI_AuctionFrameTab_OnClickHook)
474 AuctionUI_Hooked = true
475 end
476 end
477 end
478  
479 function insertAHTab(tabIndex, tabButton, tabFrame)
480 -- Count the number of auction house tabs (including the tab we are going
481 -- to insert).
482 local tabCount = 1;
483 while (getglobal("AuctionFrameTab"..(tabCount)) ~= nil) do
484 tabCount = tabCount + 1;
485 end
486  
487 -- Adjust the tabIndex to fit within the current tab count.
488 if (tabIndex < 1 or tabIndex > tabCount) then
489 tabIndex = tabCount;
490 end
491  
492 -- Make room for the tab, if needed.
493 for index = tabCount, tabIndex + 1, -1 do
494 setglobal("AuctionFrameTab"..(index), getglobal("AuctionFrameTab"..(index - 1)));
495 getglobal("AuctionFrameTab"..(index)):SetID(index);
496 end
497  
498 -- Configure the frame.
499 tabFrame:SetParent("AuctionFrame");
500 tabFrame:SetPoint("TOPLEFT", "AuctionFrame", "TOPLEFT", 0, 0);
501 relevel(tabFrame);
502  
503 -- Configure the tab button.
504 setglobal("AuctionFrameTab"..tabIndex, tabButton);
505 tabButton:SetParent("AuctionFrame");
506 tabButton:SetPoint("TOPLEFT", getglobal("AuctionFrameTab"..(tabIndex - 1)):GetName(), "TOPRIGHT", -8, 0);
507 tabButton:SetID(tabIndex);
508 tabButton:Show();
509  
510 -- If we inserted a tab in the middle, adjust the layout of the next tab button.
511 if (tabIndex < tabCount) then
512 nextTabButton = getglobal("AuctionFrameTab"..(tabIndex + 1));
513 nextTabButton:SetPoint("TOPLEFT", tabButton:GetName(), "TOPRIGHT", -8, 0);
514 end
515  
516 -- Update the tab count.
517 PanelTemplates_SetNumTabs(AuctionFrame, tabCount)
518 end
519  
520 function auctionFrameFiltersUpdateClasses() --Auctioneer_AuctionFrameFilters_UpdateClasses
521 local obj
522 for i=1, 15 do
523 obj = getglobal("AuctionFilterButton"..i.."Checkbox")
524 if (obj) then
525 obj:SetParent("AuctionFilterButton"..i)
526 obj:SetPoint("RIGHT", "AuctionFilterButton"..i, "RIGHT", -5,0)
527 end
528 end
529 end
530  
531 function rememberPrice()
532 if (not Auctioneer_CurAuctionItem) then
533 AuctPriceRememberCheck:SetChecked(false)
534 return
535 end
536  
537 if (not AuctPriceRememberCheck:GetChecked()) then
538 Auctioneer.Storage.DeleteFixedPrice(Auctioneer_CurAuctionItem)
539 else
540 local count = Auctioneer_CurAuctionCount
541 local start = MoneyInputFrame_GetCopper(StartPrice)
542 local buy = MoneyInputFrame_GetCopper(BuyoutPrice)
543 local dur = AuctionFrameAuctions.duration
544 Auctioneer.Storage.SetFixedPrice(Auctioneer_CurAuctionItem, start, buy, dur, count)
545 end
546 end
547  
548 function auctionsClear() --Auctioneer_Auctions_Clear
549 for i = 1, 5 do
550 getglobal("AuctionInfoText"..i):Hide();
551 getglobal("AuctionInfoMoney"..i):Hide();
552 end
553 AuctionInfoWarnText:Hide();
554 end
555  
556 function auctionsSetWarn(textStr) --Auctioneer_Auctions_SetWarn
557 if (AuctionInfoWarnText == nil) then EnhTooltip.DebugPrint("Error, no text for AuctionInfo line "..line); end
558 local cHex, cRed, cGreen, cBlue = Auctioneer.Util.GetWarnColor(textStr)
559 AuctionInfoWarnText:SetText(textStr);
560 AuctionInfoWarnText:SetTextColor(cRed, cGreen, cBlue);
561 AuctionInfoWarnText:Show();
562 end
563  
564 function auctionsSetLine(line, textStr, moneyAmount) --Auctioneer_Auctions_SetLine
565 local text = getglobal("AuctionInfoText"..line);
566 local money = getglobal("AuctionInfoMoney"..line);
567 if (text == nil) then EnhTooltip.DebugPrint("Error, no text for AuctionInfo line "..line); end
568 if (money == nil) then EnhTooltip.DebugPrint("Error, no money for AuctionInfo line "..line); end
569 text:SetText(textStr);
570 text:Show();
571 if (money ~= nil) then
572 MoneyFrame_Update("AuctionInfoMoney"..line, math.ceil(Auctioneer.Util.NullSafe(moneyAmount)));
573 getglobal("AuctionInfoMoney"..line.."SilverButtonText"):SetTextColor(1.0,1.0,1.0);
574 getglobal("AuctionInfoMoney"..line.."CopperButtonText"):SetTextColor(0.86,0.42,0.19);
575 money:Show();
576 else
577 money:Hide();
578 end
579 end
580  
581  
582 function newAuction()
583 local name, texture, count, quality, canUse, price = GetAuctionSellItemInfo()
584 local countFix = count
585 if countFix == 0 then
586 countFix = 1
587 end
588  
589 if (not name) then
590 Auctioneer.Scanner.AuctionsClear()
591 return
592 end
593  
594 local bag, slot, id, rprop, enchant, uniq = EnhTooltip.FindItemInBags(name);
595 if (bag == nil) then
596 -- is the item one of your bags?
597 local i
598 for i = 0, 4, 1 do
599 if name == GetBagName(i) then
600 id, rprop, enchant, uniq = breakLink(GetInventoryItemLink("player", ContainerIDToInventoryID(i)))
601 break
602 end
603 end
604 end
605  
606 -- still no corresponding item found?
607 if id == nil then
608 Auctioneer.Scanner.AuctionsClear()
609 return
610 end
611  
612 local startPrice, buyoutPrice, x;
613 local itemKey = id..":"..rprop..":"..enchant;
614 Auctioneer_CurAuctionItem = itemKey;
615 Auctioneer_CurAuctionCount = countFix;
616 local auctionPriceItem = Auctioneer.Core.GetAuctionPriceItem(itemKey);
617 local aCount,minCount,minPrice,bidCount,bidPrice,buyCount,buyPrice = Auctioneer.Core.GetAuctionPrices(auctionPriceItem.data);
618  
619 if (Auctioneer.Storage.GetFixedPrice(itemKey)) then
620 AuctPriceRememberCheck:SetChecked(true)
621 else
622 AuctPriceRememberCheck:SetChecked(false)
623 end
624  
625 -- Find the current lowest buyout for 1 of these in the current snapshot
626 local currentLowestBuyout = Auctioneer.Statistic.FindLowestAuctions(itemKey);
627 if currentLowestBuyout then
628 x,x,x,x,lowStackCount,x,currentLowestBuyout = Auctioneer.Core.GetItemSignature(currentLowestBuyout);
629 currentLowestBuyout = currentLowestBuyout / lowStackCount;
630 end
631  
632 local historicalMedian, historicalMedCount = Auctioneer.Statistic.GetItemHistoricalMedianBuyout(itemKey);
633 local snapshotMedian, snapshotMedCount = Auctioneer.Statistic.GetItemSnapshotMedianBuyout(itemKey);
634  
635 auctionsClear();
636 Auctioneer.Scanner.AuctionsSetLine(1, string.format(_AUCT('FrmtAuctinfoHist'), historicalMedCount), historicalMedian * count);
637 Auctioneer.Scanner.AuctionsSetLine(2, string.format(_AUCT('FrmtAuctinfoSnap'), snapshotMedCount), snapshotMedian * count);
638 if (snapshotMedCount and snapshotMedCount > 0 and currentLowestBuyout) then
639 Auctioneer.Scanner.AuctionsSetLine(3, _AUCT('FrmtAuctinfoLow'), currentLowestBuyout * count);
640 else
641 Auctioneer.Scanner.AuctionsSetLine(3, _AUCT('FrmtAuctinfoNolow'));
642 end
643 local blizPrice = MoneyInputFrame_GetCopper(StartPrice);
644  
645 local hsp, hspCount, mktPrice, warn = Auctioneer.Statistic.GetHSP(itemKey, Auctioneer.Util.GetAuctionKey());
646 if hsp == 0 and buyCount > 0 then
647 hsp = math.ceil(buyPrice / buyCount); -- use mean buyout if median not available
648 end
649 local discountBidPercent = tonumber(Auctioneer.Command.GetFilterVal('pct-bidmarkdown'));
650 local buyPrice = Auctioneer.Statistic.RoundDownTo95(Auctioneer.Util.NullSafe(hsp) * countFix);
651 local bidPrice = Auctioneer.Statistic.RoundDownTo95(Auctioneer.Statistic.SubtractPercent(buyPrice, discountBidPercent));
652  
653 if (Auctioneer.Storage.GetFixedPrice(itemKey)) then
654 local start, buy, dur = Auctioneer.Storage.GetFixedPrice(itemKey, countFix)
655 Auctioneer.Scanner.AuctionsSetLine(4, _AUCT('FrmtAuctinfoSugbid'), bidPrice);
656 Auctioneer.Scanner.AuctionsSetLine(5, _AUCT('FrmtAuctinfoSugbuy'), buyPrice);
657 auctionsSetWarn(_AUCT('FrmtWarnUser'));
658 MoneyInputFrame_SetCopper(StartPrice, start);
659 MoneyInputFrame_SetCopper(BuyoutPrice, buy);
660 setAuctionDuration(tonumber(dur));
661 elseif (Auctioneer.Command.GetFilter('autofill')) then
662 Auctioneer.Scanner.AuctionsSetLine(4, _AUCT('FrmtAuctinfoMktprice'), Auctioneer.Util.NullSafe(mktPrice)*countFix);
663 Auctioneer.Scanner.AuctionsSetLine(5, _AUCT('FrmtAuctinfoOrig'), blizPrice);
664 auctionsSetWarn(warn);
665 MoneyInputFrame_SetCopper(StartPrice, bidPrice);
666 MoneyInputFrame_SetCopper(BuyoutPrice, buyPrice);
667 else
668 Auctioneer.Scanner.AuctionsSetLine(4, _AUCT('FrmtAuctinfoSugbid'), bidPrice);
669 Auctioneer.Scanner.AuctionsSetLine(5, _AUCT('FrmtAuctinfoSugbuy'), buyPrice);
670 auctionsSetWarn(warn);
671 end
672 end
673  
674 function auctHouseShow()
675 -- Set the default auction duration
676 if (Auctioneer.Command.GetFilterVal('auction-duration') > 0) then
677 setAuctionDuration(Auctioneer.Command.GetFilterVal('auction-duration'))
678 else
679 setAuctionDuration(Auctioneer.Command.GetFilterVal('last-auction-duration'))
680 end
681  
682 -- Protect the auction frame from being closed if we should
683 if (Auctioneer.Command.GetFilterVal('protect-window') == 2) then
684 Auctioneer.Util.ProtectAuctionFrame(true);
685 end
686  
687 -- Start scanning if so requested
688 if Auctioneer.Scanning.IsScanningRequested then
689 Auctioneer.Scanning.StartAuctionScan();
690 end
691 end
692  
693  
694 function auctHouseClose()
695 if Auctioneer.Scanning.IsScanningRequested then
696 Auctioneer.Scanning.StopAuctionScan();
697 end
698  
699 -- Unprotect the auction frame
700 Auctioneer.Util.ProtectAuctionFrame(false);
701 end
702  
703 function auctHouseUpdate()
704 local completeScan = Auctioneer.Scanning.CheckCompleteScan()
705 local isScanningRequested = Auctioneer.Scanning.IsScanningRequested
706 EnhTooltip.DebugPrint("AuctionHouseUpdate()", "Is Scanning Requested", isScanningRequested, "Complete Scan", completeScan)
707  
708 if (isScanningRequested and completeScan) then
709 Auctioneer.Scanning.ScanAuction();
710  
711 elseif (completeScan) then
712 Auctioneer.Scanning.ScanAuction(true);
713 end
714 end
715  
716 function filterButtonSetType(funcVars, retVal, button, type, text, isLast) --Auctioneer_FilterButton_SetType
717 EnhTooltip.DebugPrint("Setting button", button:GetName(), type, text, isLast);
718  
719 local buttonName = button:GetName();
720 local i,j, buttonID = string.find(buttonName, "(%d+)$");
721 buttonID = tonumber(buttonID);
722  
723 local checkbox = getglobal(button:GetName().."Checkbox");
724 if checkbox then
725 if (type == "class") then
726 local classid, maxid = Auctioneer.Command.FindFilterClass(text);
727 if (classid > 0) then
728 Auctioneer.Command.FilterSetFilter(checkbox, "scan-class"..classid);
729 if (classid == maxid) and (buttonID < 15) then
730 for i=buttonID+1, 15 do
731 getglobal("AuctionFilterButton"..i):Hide();
732 end
733 end
734 else
735 checkbox:Hide();
736 end
737 else
738 checkbox:Hide();
739 end
740 end
741 end
742  
743 local ignoreAuctionDurationChange = nil
744 function onChangeAuctionDuration()
745 if (ignoreAuctionDurationChange) then
746 ignoreAuctionDurationChange = nil;
747 return
748 end
749 Auctioneer.Command.SetFilter('last-auction-duration', AuctionFrameAuctions.duration)
750 end
751  
752 function setAuctionDuration(duration, persist)
753 local durationIndex
754 if (duration >= 1 and duration <= 3) then
755 durationIndex = duration
756 elseif (duration == 120) then
757 durationIndex = 1
758 elseif (duration == 480) then
759 durationIndex = 2
760 elseif (duration == 1440) then
761 durationIndex = 3
762 else
763 EnhTooltip.DebugPrint("Auctioneer.Scanner.SetAuctionDuration(): invalid duration ", duration)
764 return
765 end
766  
767 if (not persist) then ignoreAuctionDurationChange = true; end
768 AuctionsRadioButton_OnClick(durationIndex);
769 end
770  
771 Auctioneer.Scanner = {
772 ProcessLink = processLink,
773 InvalidateAHSnapshot = invalidateAHSnapshot,
774 AuctionStartHook = auctionStartHook,
775 FinishedAuctionScanHook = finishedAuctionScanHook,
776 AuctionEntryHook = auctionEntryHook,
777 StartAuction = startAuction,
778 PlaceAuctionBid = placeAuctionBid,
779 ConfigureAH = configureAH,
780 AuctionFrameFiltersUpdateClasses = auctionFrameFiltersUpdateClasses,
781 RememberPrice = rememberPrice,
782 AuctionsClear = auctionsClear,
783 AuctionsSetWarn = auctionsSetWarn,
784 AuctionsSetLine = auctionsSetLine,
785 NewAuction = newAuction,
786 AuctHouseShow = auctHouseShow,
787 AuctHouseClose = auctHouseClose,
788 AuctHouseUpdate = auctHouseUpdate,
789 FilterButtonSetType = filterButtonSetType,
790 OnChangeAuctionDuration = onChangeAuctionDuration,
791 SetAuctionDuration = setAuctionDuration,
792 }