📄 aucbidmanager.lua
字号:
-- Check if there is a corresponding request and upate it to -- reflect the successful bid. if (request) then request.bidCount = request.bidCount + 1; -- Increment the request's current index if the auction was not bought out. if (request.bid ~= request.buyout) then request.currentIndex = request.currentIndex + 1; debugPrint("Incrementing the request's currentIndex to "..request.currentIndex); end end elseif (result ~= BidResultCodes["BidAccepted"]) then -- We were expecting the list to update after our bid/buyout, but -- our bid/buyout failed so we won't be getting an update. CurrentSearchParams.queryComplete = true; CurrentSearchParams.queryResponse = true; CurrentSearchParams.targetCountForPage = nil; -- Skip over the auction we failed to bid on. if (request) then request.currentIndex = request.currentIndex + 1; debugPrint("Incrementing the request's currentIndex to "..request.currentIndex); end if (result == BidResultCodes["OwnAuction"] and bid.owner) then -- We tried bidding on our own auction! Blizzard doesn't -- allow bids from any player on the account that posted -- the auction. Therefore we keep a dynamic list of all -- of these failures so we can avoid these auctions in the -- future. addPlayerToAccount(bid.owner); end end else -- We got out of sync somehow... this indicates a bug in how we determine -- the results of bid requests. chatPrint(_AUCT('FrmtBidQueueOutOfSync')); endend--------------------------------------------------------------------------------- Returns true if a query is in progress-------------------------------------------------------------------------------function isQueryInProgress() return (not CurrentSearchParams.queryComplete);end--------------------------------------------------------------------------------- Wrapper around CanSendAuctionQuery() that always calls the Blizzard version.-------------------------------------------------------------------------------function canSendAuctionQuery() if (Original_CanSendAuctionQuery) then return Original_CanSendAuctionQuery(); end return CanSendAuctionQuery();end--------------------------------------------------------------------------------- Called before QueryAuctionItems()-------------------------------------------------------------------------------function queryAuctionItemsHook(_, _, name, minLevel, maxLevel, invTypeIndex, classIndex, subclassIndex, page, isUsable, qualityIndex) if (not Auctioneer.Scanning.IsScanningRequested and canSendAuctionQuery()) then CurrentSearchParams.name = name; CurrentSearchParams.minLevel = minLevel; CurrentSearchParams.maxLevel = maxLevel; CurrentSearchParams.invTypeIndex = invTypeIndex; CurrentSearchParams.classIndex = classIndex; CurrentSearchParams.subclassIndex = subclassIndex; CurrentSearchParams.page = page; CurrentSearchParams.isUsable = isUsable; CurrentSearchParams.qualityIndex = qualityIndex; CurrentSearchParams.queryTime = time(); CurrentSearchParams.queryResponse = false; CurrentSearchParams.queryComplete = false; CurrentSearchParams.targetCountForPage = nil; debugPrint("queryAuctionItemsHook()"); else CurrentSearchParams.name = nil; CurrentSearchParams.minLevel = nil; CurrentSearchParams.maxLevel = nil; CurrentSearchParams.invTypeIndex = nil; CurrentSearchParams.classIndex = nil; CurrentSearchParams.subclassIndex = nil; CurrentSearchParams.page = nil; CurrentSearchParams.isUsable = nil; CurrentSearchParams.qualityIndex = nil; CurrentSearchParams.queryTime = time(); CurrentSearchParams.queryResponse = true; CurrentSearchParams.queryComplete = true; CurrentSearchParams.targetCountForPage = nil; debugPrint("queryAuctionItemsHook() - ignoring"); end -- Toss the information about the last request processed. LastRequest = nil;end--------------------------------------------------------------------------------- Checks a query to see if its complete. Often times the owner information-- of auctions are missing at first. Asking for it triggers another update-- of the auction list.-------------------------------------------------------------------------------function checkQueryComplete() if (not CurrentSearchParams.queryComplete) then -- Get the number of auctions on the page. local lastIndexOnPage, totalAuctions = GetNumAuctionItems("list"); debugPrint("LastIndexOnPage = "..lastIndexOnPage); debugPrint("TotalAuctions = "..totalAuctions); if (CurrentSearchParams.targetCountForPage == nil or CurrentSearchParams.targetCountForPage == lastIndexOnPage) then -- Assume true until otherwise proven false. CurrentSearchParams.queryTime = time(); CurrentSearchParams.queryResponse = true; CurrentSearchParams.queryComplete = true; for indexOnPage = 1, lastIndexOnPage do local name, texture, count, quality, canUse, level, minBid, minIncrement, buyoutPrice, bidAmount, highBidder, owner = GetAuctionItemInfo("list", indexOnPage); if (owner == nil) then -- No dice... there are more updates coming... CurrentSearchParams.queryComplete = false; break; end end if (CurrentSearchParams.queryComplete) then debugPrint("checkQueryComplete() - true"); else debugPrint("checkQueryComplete() - false (waiting for owner information on auctions)"); end else debugPrint("checkQueryComplete() - false (waiting for "..CurrentSearchParams.targetCountForPage.." auctions on page)"); end endend--------------------------------------------------------------------------------- Adds a request to the queue.-------------------------------------------------------------------------------function addRequestToQueue(request) -- Add the request state information request.bidAttempts = 0; request.bidCount = 0; request.currentPage = 0; request.currentIndex = 1; request.continuation = false; request.results = {}; -- Check if the previous request is the same as this request. If so we -- want to pickup where the last request left off. if (table.getn(RequestQueue) == 0 and LastRequest ~= nil and LastRequest.id == request.id and LastRequest.rprop == request.rprop and LastRequest.enchant == request.enchant and LastRequest.name == request.name and LastRequest.count == request.count and LastRequest.min == request.min and LastRequest.buyout == request.buyout and LastRequest.unique == request.unique and LastRequest.bid == request.bid) then request.currentPage = LastRequest.currentPage; request.currentIndex = LastRequest.currentIndex; request.continuation = true; end -- Add the request to the queue. table.insert(RequestQueue, request); debugPrint("Added request to queue: "..request.name..", "..request.count..", "..nilSafe(request.buyout)..", "..nilSafe(request.bid));end--------------------------------------------------------------------------------- Removes a request at the head of the queue.-------------------------------------------------------------------------------function removeRequestFromQueue() if (table.getn(RequestQueue) > 0) then -- Remove the request from the queue. local request = RequestQueue[1]; table.remove(RequestQueue, 1); debugPrint("Removed request from queue: "..request.name..", "..request.count..", "..nilSafe(request.buyout)..", "..nilSafe(request.bid)); -- Make the callback, if requested. local callback = request.callback; if (callback and callback.func) then callback.func(callback.param, request); end -- Inform the user if no auctions were found. if (table.getn(request.results) == 0) then if (request.continuation) then local output = string.format(_AUCT('FrmtNoMoreAuctionsFound'), request.name, request.count); chatPrint(output); else local output = string.format(_AUCT('FrmtNoAuctionsFound'), request.name, request.count); chatPrint(output); end end -- Check if the next request is the same as the previous. If so we -- want to pickup where the last request left off. if (LastRequest ~= nil and table.getn(RequestQueue) > 0) then local nextRequest = RequestQueue[1]; if (LastRequest.id == nextRequest.id and LastRequest.rprop == nextRequest.rprop and LastRequest.enchant == nextRequest.enchant and LastRequest.name == nextRequest.name and LastRequest.count == nextRequest.count and LastRequest.min == nextRequest.min and LastRequest.buyout == nextRequest.buyout and LastRequest.unique == nextRequest.unique and LastRequest.bid == nextRequest.bid) then nextRequest.currentPage = LastRequest.currentPage; nextRequest.currentIndex = LastRequest.currentIndex; nextRequest.continuation = true; end end endend--------------------------------------------------------------------------------- Checks if the BidManager is currently working on a request.-------------------------------------------------------------------------------function isProcessingRequest() return ProcessingRequestQueue;end--------------------------------------------------------------------------------- Gets the number of pending requests.-------------------------------------------------------------------------------function getRequestCount() return table.getn(RequestQueue);end--------------------------------------------------------------------------------- Starts processing the request queue if possible. Returns true if started.-------------------------------------------------------------------------------function beginProcessingRequestQueue() if (not ProcessingRequestQueue and AuctionFrame and AuctionFrame:IsVisible() and table.getn(RequestQueue) > 0 and not Auctioneer.Scanning.IsScanningRequested and not isQueryInProgress() and not isBidInProgress()) then ProcessingRequestQueue = true; AucBidManagerFrame:Show(); debugPrint("Begin processing the bid queue"); -- Hook the functions to disable the Browse UI if (not Original_CanSendAuctionQuery) then Original_CanSendAuctionQuery = CanSendAuctionQuery; CanSendAuctionQuery = AucBidManager_CanSendAuctionQuery; end if (not Original_AuctionFrameBrowse_OnEvent) then Original_AuctionFrameBrowse_OnEvent = AuctionFrameBrowse_OnEvent; AuctionFrameBrowse_OnEvent = AucBidManager_AuctionFrameBrowse_OnEvent; end if (not Original_AuctionFrameBrowse_Update) then Original_AuctionFrameBrowse_Update = AuctionFrameBrowse_Update; AuctionFrameBrowse_Update = AucBidManager_AuctionFrameBrowse_Update; end -- Hide the UI from any current results, show the no results text so we can use it BrowseNoResultsText:Show(); BrowseNoResultsText:SetText(_AUCT('UiProcessingBidRequests')); for iButton = 1, NUM_BROWSE_TO_DISPLAY do button = getglobal("BrowseButton"..iButton); button:Hide(); end BrowsePrevPageButton:Hide(); BrowseNextPageButton:Hide(); BrowseSearchCountText:Hide(); BrowseBidButton:Disable(); BrowseBuyoutButton:Disable(); end return ProcessingRequestQueue;end--------------------------------------------------------------------------------- Ends processing the request queue-------------------------------------------------------------------------------function endProcessingRequestQueue() if (ProcessingRequestQueue) then ProcessingRequestQueue = false; AucBidManagerFrame:Hide(); debugPrint("End processing the bid queue"); -- Unhook the functions if( Original_CanSendAuctionQuery ) then CanSendAuctionQuery = Original_CanSendAuctionQuery; Original_CanSendAuctionQuery = nil; end if( Original_AuctionFrameBrowse_OnEvent ) then AuctionFrameBrowse_OnEvent = Original_AuctionFrameBrowse_OnEvent; Original_AuctionFrameBrowse_OnEvent = nil; end if( Original_AuctionFrameBrowse_Update ) then AuctionFrameBrowse_Update = Original_AuctionFrameBrowse_Update; Original_AuctionFrameBrowse_Update = nil; end -- Update the Browse UI. BrowseNoResultsText:Hide(); BrowseNoResultsText:SetText(""); AuctionFrameBrowse_Update(); endend--------------------------------------------------------------------------------- Attempt to process the request queue. Based on the current state, this-- method performs the next action needed to process the queue.-------------------------------------------------------------------------------function processRequestQueue() -- Check if we should toss the results of the last query. Sometimes
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -