📄 aucscanner.lua
字号:
--[[ Auctioneer Addon for World of Warcraft(tm). Version: 3.5.0.0917 (Platypus) Revision: $Id: AucScanner.lua 890 2006-06-02 18:55:25Z mentalpower $ Auctioneer scanning functions Functions to handle the auction scan procedure License: This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program(see GPL.txt); if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.]]--Local function prototypeslocal processLink, invalidateAHSnapshot, auctionStartHook, finishedAuctionScanHook, auctionEntryHook, startAuction, placeAuctionBid, relevel, configureAH, insertAHTab, auctionFrameFiltersUpdateClasses, rememberPrice, auctionsClear, auctionsSetWarn, auctionsSetLine, newAuction, auctHouseShow, auctHouseClose, auctHouseUpdate, filterButtonSetType, onChangeAuctionDuration, setAuctionDuration-- Hook into this function if you want notification when we find a link.function processLink(link) if (ItemsMatrix_ProcessLinks ~= nil) then ItemsMatrix_ProcessLinks( link, -- itemlink nil, -- not used atm nil, -- vendorprice - TODO: not calculatable in AH? nil -- event - TODO: donno, maybe only for chatevents? ) end if (LootLink_ProcessLinks ~= nil) then LootLink_ProcessLinks( link, -- itemlink true -- TODO: uncertain? - ah is a trustable source? ); endend-- This function sets the dirty flag to true for all the auctions in the snapshot-- This is done to indicate that the snapshot is out of date.function invalidateAHSnapshot() -- Invalidate the snapshot local auctKey = Auctioneer.Util.GetAuctionKey(); if (not AuctionConfig.snap) then AuctionConfig.snap = {}; end if (not AuctionConfig.snap[auctKey]) then AuctionConfig.snap[auctKey] = {}; end for cat,cData in pairs(AuctionConfig.snap[auctKey]) do -- Only invalidate the class group if we will be scanning it. if (Auctioneer.Command.GetFilter("scan-class"..cat)) then for iKey, iData in pairs(cData) do -- The first char is the dirty flag (purposely) AuctionConfig.snap[auctKey][cat][iKey] = "1" .. string.sub(iData,2); end end endend-- Called when the auction scan startsfunction auctionStartHook() --Auctioneer_AuctionStart_Hook Auction_DoneItems = {}; Auctioneer.Core.Variables.SnapshotItemPrices = {}; invalidateAHSnapshot(); -- Make sure AuctionConfig.data is initialized local serverFaction = Auctioneer.Util.GetAuctionKey(); if (AuctionConfig.data == nil) then AuctionConfig.data = {}; end if (AuctionConfig.data[serverFaction] == nil) then AuctionConfig.data[serverFaction] = {}; end -- Reset scan audit counters Auctioneer.Core.Variables.TotalAuctionsScannedCount = 0; Auctioneer.Core.Variables.NewAuctionsCount = 0; Auctioneer.Core.Variables.OldAuctionsCount = 0; Auctioneer.Core.Variables.DefunctAuctionsCount = 0; -- Protect AuctionFrame if we should if (Auctioneer.Command.GetFilterVal('protect-window') == 1) then Auctioneer.Util.ProtectAuctionFrame(true); endend-- This is called when an auction scan finishes and is used for clean upfunction finishedAuctionScanHook() --Auctioneer_FinishedAuctionScan_Hook -- Only remove defunct auctions from snapshot if there was a good amount of auctions scanned. local auctKey = Auctioneer.Util.GetAuctionKey(); if (not AuctionConfig.sbuy) then AuctionConfig.sbuy = {}; end if (not AuctionConfig.sbuy[auctKey]) then AuctionConfig.sbuy[auctKey] = {}; end local endTime = time(); if Auctioneer.Core.Variables.TotalAuctionsScannedCount >= 50 then local dropCount, buyCount, bidCount, expCount; dropCount = 0; buyCount = 0; bidCount = 0; expCount = 0; local snap,lastSeen,expiredSeconds,itemKey,buyList,listStr,listSplit,buyout,hist; local id, rprop, enchant, name, count, min, buyout, sig; if (AuctionConfig and AuctionConfig.snap and AuctionConfig.snap[auctKey]) then for cat,cData in pairs(AuctionConfig.snap[auctKey]) do for iKey, iData in pairs(cData) do snap = Auctioneer.Core.GetSnapshotFromData(iData); if (snap.dirty == "1") then id, rprop, enchant, name, count, min, buyout = Auctioneer.Core.GetItemSignature(iKey); -- This item should have been seen, but wasn't. -- We need to work out if it expired before or after its time lastSeen = snap.lastSeenTime; expiredSeconds = endTime - lastSeen; if (snap.timeLeft == 1) and (snap.bidamount > 0) then bidCount = bidCount+1; -- This one expired at the final time interval, so its likely -- that this is the best bid value we'll get for it. itemKey = Auctioneer.Util.GetKeyFromSig(iKey); if (not AuctionConfig.success) then AuctionConfig.success = {} end if (not AuctionConfig.success.bid) then AuctionConfig.success.bid = {} end if (not AuctionConfig.success.bid[auctKey]) then AuctionConfig.success.bid[auctKey] = {} end bidList = Auctioneer.BalancedList.NewBalancedList(Auctioneer.Core.Constants.MaxBuyoutHistorySize); bidList.setList(Auctioneer.Core.LoadMedianList(AuctionConfig.success.bid[auctKey][itemKey])); bidList.insert(Auctioneer.Util.PriceForOne(snap.bidamount, count)); AuctionConfig.success.bid[auctKey][itemKey] = Auctioneer.Core.StoreMedianList (bidList.getList()); elseif (expiredSeconds < Auctioneer.Core.Constants.TimeLeft.Seconds[snap.timeLeft]) then -- Whoa! This item was bought out. itemKey = Auctioneer.Util.GetKeyFromSig(iKey); if (not AuctionConfig.success) then AuctionConfig.success = {} end if (buyout > 0) then buyCount = buyCount+1; if (not AuctionConfig.success.buy) then AuctionConfig.success.buy = {} end if (not AuctionConfig.success.buy[auctKey]) then AuctionConfig.success.buy[auctKey] = {} end buyList = Auctioneer.BalancedList.NewBalancedList(Auctioneer.Core.Constants.MaxBuyoutHistorySize); buyList.setList(Auctioneer.Core.LoadMedianList(AuctionConfig.success.buy[auctKey][itemKey])); buyList.insert(Auctioneer.Util.PriceForOne(buyout, count)); AuctionConfig.success.buy[auctKey][itemKey] = Auctioneer.Core.StoreMedianList(buyList.getList()); else if (not AuctionConfig.success.drop) then AuctionConfig.success.drop = {} end if (not AuctionConfig.success.drop[auctKey]) then AuctionConfig.success.drop[auctKey] = {} end local cancelCount = tonumber(AuctionConfig.success.drop[auctKey][itemKey]) or 0 AuctionConfig.success.drop[auctKey][itemKey] = cancelCount + 1; dropCount = dropCount + 1; end else expCount = expCount+1; end -- Clear defunct auctions if (id and rprop and enchant) then sig = id..":"..rprop..":"..enchant; AuctionConfig.sbuy[auctKey][sig] = nil; Auctioneer.Storage.SetSnapMed(auctKey, sig, nil); end AuctionConfig.snap[auctKey][cat][iKey] = nil; Auctioneer.Core.Variables.DefunctAuctionsCount = Auctioneer.Core.Variables.DefunctAuctionsCount + 1; end end end end EnhTooltip.DebugPrint("Final counts", dropCount, buyCount, bidCount, expCount); end -- Copy the item prices into the Saved item prices table if (Auctioneer.Core.Variables.SnapshotItemPrices) then for sig, iData in pairs(Auctioneer.Core.Variables.SnapshotItemPrices) do AuctionConfig.sbuy[auctKey][sig] = Auctioneer.Core.StoreMedianList(iData.buyoutPrices); Auctioneer.Storage.SetSnapMed(auctKey, sig, Auctioneer.Statistic.GetMedian(iData.buyoutPrices)); Auctioneer.Core.Variables.SnapshotItemPrices[sig] = nil; end end local lDiscrepencyCount = Auctioneer.Core.Variables.TotalAuctionsScannedCount - (Auctioneer.Core.Variables.NewAuctionsCount + Auctioneer.Core.Variables.OldAuctionsCount); local totalAuctionsMessage = string.format(_AUCT('AuctionTotalAucts'), Auctioneer.Util.ColorTextWhite(Auctioneer.Core.Variables.TotalAuctionsScannedCount)) local newAuctionsMessage = string.format(_AUCT('AuctionNewAucts'), Auctioneer.Util.ColorTextWhite(Auctioneer.Core.Variables.NewAuctionsCount)) local oldAuctionsMessage = string.format(_AUCT('AuctionOldAucts'), Auctioneer.Util.ColorTextWhite(Auctioneer.Core.Variables.OldAuctionsCount)) local defunctAuctionsMessage = string.format(_AUCT('AuctionDefunctAucts'), Auctioneer.Util.ColorTextWhite(Auctioneer.Core.Variables.DefunctAuctionsCount)) local discrepanciesMessage Auctioneer.Util.ChatPrint(totalAuctionsMessage); Auctioneer.Util.ChatPrint(newAuctionsMessage); Auctioneer.Util.ChatPrint(oldAuctionsMessage); Auctioneer.Util.ChatPrint(defunctAuctionsMessage); if (Auctioneer.Util.NullSafe(lDiscrepencyCount) > 0) then discrepanciesMessage = string.format(_AUCT('AuctionDiscrepancies'), Auctioneer.Util.ColorTextWhite(lDiscrepencyCount)) Auctioneer.Util.ChatPrint(discrepanciesMessage); end --Add the preceding information to the AH frame too BrowseNoResultsText:SetText(totalAuctionsMessage.."\n"..newAuctionsMessage.."\n"..oldAuctionsMessage.."\n"..defunctAuctionsMessage.."\n"..(discrepanciesMessage or "")) --The followng was added by MentalPower to implement the "/auc finish" command local finish = Auctioneer.Command.GetFilterVal('finish'); if (finish == 1) then Logout(); elseif (finish == 2) then Quit(); elseif (finish == 3) then if(ReloadUIHandler) then ReloadUIHandler("10"); else ReloadUI(); end end --Cleaning up after oneself is always a good idea. collectgarbage()end-- Called by scanning hook when an auction item is scanned from the Auction house-- we save the aution item to our tables, increment our counts etcfunction auctionEntryHook(funcVars, retVal, page, index, category) --Auctioneer_AuctionEntry_Hook EnhTooltip.DebugPrint("Processing page", page, "item", index); local auctionDoneKey; if (not page or not index or not category) then return; else auctionDoneKey = category.."-"..page.."-"..index; end if (not Auction_DoneItems[auctionDoneKey]) then Auction_DoneItems[auctionDoneKey] = true; else return; end Auctioneer.Core.Variables.TotalAuctionsScannedCount = Auctioneer.Core.Variables.TotalAuctionsScannedCount + 1; local aiName, aiTexture, aiCount, aiQuality, aiCanUse, aiLevel, aiMinBid, aiMinIncrement, aiBuyoutPrice, aiBidAmount, aiHighBidder, aiOwner = GetAuctionItemInfo("list", index); if (aiOwner == nil) then aiOwner = "unknown"; end -- do some validation of the auction data that was returned if (aiName == nil or tonumber(aiBuyoutPrice) > Auctioneer.Core.Constants.MaxAllowedFormatInt or tonumber(aiMinBid) > Auctioneer.Core.Constants.MaxAllowedFormatInt) then return; end if (aiCount < 1) then aiCount = 1; end -- get other auctiondata local aiTimeLeft = GetAuctionItemTimeLeft("list", index); local aiLink = GetAuctionItemLink("list", index); -- Call some interested iteminfo addons processLink(aiLink); local aiItemID, aiRandomProp, aiEnchant, aiUniqID = EnhTooltip.BreakLink(aiLink); local aiKey = aiItemID..":"..aiRandomProp..":"..aiEnchant; local hyperlink = string.format("item:%d:%d:%d:%d", aiItemID, aiEnchant, aiRandomProp, aiUniqID); -- Get all item data local iName, iLink, iQuality, iLevel, iClass, iSubClass, iCount, iMaxStack = GetItemInfo(hyperlink); local itemCat = Auctioneer.Util.GetCatNumberByName(iClass); -- construct the unique auction signature for this aution 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); -- add this item's buyout price to the buyout price history for this item in the snapshot if aiBuyoutPrice > 0 then local buyoutPriceForOne = Auctioneer.Util.PriceForOne(aiBuyoutPrice, aiCount); if (not Auctioneer.Core.Variables.SnapshotItemPrices[aiKey]) then Auctioneer.Core.Variables.SnapshotItemPrices[aiKey] = {buyoutPrices={buyoutPriceForOne}, name=aiName}; else table.insert(Auctioneer.Core.Variables.SnapshotItemPrices[aiKey].buyoutPrices, buyoutPriceForOne); table.sort(Auctioneer.Core.Variables.SnapshotItemPrices[aiKey].buyoutPrices);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -