📄 aucbidmanager.lua
字号:
--[[ Auctioneer Addon for World of Warcraft(tm). Version: 3.5.0.0917 (Platypus) Revision: $Id: AucBidManager.lua 776 2006-03-31 06:06:23Z vindicator $ BidManager - manages bid requests in the AH 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.--]]--------------------------------------------------------------------------------- Data Members--------------------------------------------------------------------------------- Queue of bid requests to be worked onlocal LastRequest;local RequestQueue = {};local ProcessingRequestQueue = false;-- Bid queue actionslocal BID_AUCTION = "bid";local BUYOUT_AUCTION = "buyout";-- Parameters of QueryAuctionItems() last time it was called.local CurrentSearchParams ={ name = nil; minLevel = nil; maxLevel = nil; invTypeIndex = nil; classIndex = nil; subclassIndex = nil; page = nil; isUsable = nil; qualityIndex = nil; queryTime = nil; -- Time that the query was made or the last response was received queryResponse = true; -- Flag indicates if any response has been received queryComplete = true; -- Flag indicates if the entire response has been received targetCountForPage = nil; -- Number of items expected on the page (nil for unknown)};-- Queue of bids submitted to the server, but not yet accepted or rejectedlocal PendingBids = {};-- Function hooks that are used when processing requestslocal Original_CanSendAuctionQuery;local Original_AuctionFrameBrowse_OnEvent;local Original_AuctionFrameBrowse_Update;-- Result codes for bid requests.BidResultCodes = {}BidResultCodes["BidAccepted"] = 0;BidResultCodes["ItemNotFound"] = 1;BidResultCodes["NotEnoughMoney"] = 2;BidResultCodes["OwnAuction"] = 3;BidResultCodes["AlreadyHigherBid"] = 4;BidResultCodes["AlreadyHighBidder"] = 5;BidResultCodes["CurrentBidLower"] = 6;BidResultCodes["MaxBidsReached"] = 7;--------------------------------------------------------------------------------- Function Prototypes-------------------------------------------------------------------------------local addPlayerToAccount;local isPlayerOnAccount;local isBidInProgress;local addPendingBid;local removePendingBid;local placeAuctionBidHook;local onBidResponse;local isQueryInProgress;local queryAuctionItemsHook;local checkQueryComplete;local addRequestToQueue;local removeRequestFromQueue;local isProcessingRequest;local getRequestCount;local beginProcessingRequestQueue;local endProcessingRequestQueue;local processRequestQueue;local processPage;local nilSafe;local boolString;local chatPrint;local debugPrint;local bidAuction;local dumpState;--------------------------------------------------------------------------------------------------------------------------------------------------------------function AucBidManagerFrame_OnLoad() this:RegisterEvent("ADDON_LOADED"); this:RegisterEvent("AUCTION_ITEM_LIST_UPDATE"); this:RegisterEvent("AUCTION_HOUSE_CLOSED"); Stubby.RegisterFunctionHook("PlaceAuctionBid", -50, placeAuctionBidHook) Stubby.RegisterFunctionHook("QueryAuctionItems", -50, queryAuctionItemsHook)end--------------------------------------------------------------------------------------------------------------------------------------------------------------function AucBidManagerFrame_OnEvent(event) if (event == "ADDON_LOADED" and string.lower(arg1) == "auctioneer") then addPlayerToAccount(UnitName("player")); this:UnregisterEvent("ADDON_LOADED"); elseif (event == "AUCTION_ITEM_LIST_UPDATE") then debugPrint(event); checkQueryComplete(); elseif (event == "CHAT_MSG_SYSTEM" and arg1) then debugPrint(event); if (arg1) then debugPrint(" "..arg1) end; if (arg1 == ERR_AUCTION_BID_PLACED) then onBidResponse(BidResultCodes["BidAccepted"]); end elseif (event == "UI_ERROR_MESSAGE" and arg1) then debugPrint(event); if (arg1) then debugPrint(" "..arg1) end; if (arg1 == ERR_ITEM_NOT_FOUND) then onBidResponse(BidResultCodes["ItemNotFound"]); elseif (arg1 == ERR_NOT_ENOUGH_MONEY) then onBidResponse(BidResultCodes["NotEnoughMoney"]); elseif (arg1 == ERR_AUCTION_BID_OWN) then onBidResponse(BidResultCodes["OwnAuction"]); elseif (arg1 == ERR_AUCTION_HIGHER_BID) then onBidResponse(BidResultCodes["AlreadyHigherBid"]); end elseif (event == "AUCTION_HOUSE_CLOSED") then endProcessingRequestQueue(); endend--------------------------------------------------------------------------------------------------------------------------------------------------------------function AucBidManagerFrame_OnUpdate() processRequestQueue();end--------------------------------------------------------------------------------------------------------------------------------------------------------------function AucBidManager_CanSendAuctionQuery() -- Intentionally empty; don't allow the auction UI to update while we're processing requests return false;end--------------------------------------------------------------------------------------------------------------------------------------------------------------function AucBidManager_AuctionFrameBrowse_OnEvent() -- Intentionally empty; don't allow the auction UI to update while we're processing requestsend--------------------------------------------------------------------------------------------------------------------------------------------------------------function AucBidManager_AuctionFrameBrowse_Update() -- Intentionally empty; don't allow the auction UI to update while we're processing requestsend--------------------------------------------------------------------------------- Adds a player to the list of players on the current account.-------------------------------------------------------------------------------function addPlayerToAccount(player) -- List of players on the same account as the current player (including the -- current player). Auctions owned by these players cannot be bid on. if (not AuctionConfig.players) then AuctionConfig.players = {}; end if (not isPlayerOnAccount(player)) then table.insert(AuctionConfig.players, player); endend--------------------------------------------------------------------------------- Checks if a player is on the same account as the current player.-------------------------------------------------------------------------------function isPlayerOnAccount(player) if (not AuctionConfig.players) then AuctionConfig.players = {}; end for _, p in pairs(AuctionConfig.players) do if (p == player) then return true; end end return false;end--------------------------------------------------------------------------------- Returns true if a bid request is in flight to the server-------------------------------------------------------------------------------function isBidInProgress() return (table.getn(PendingBids) > 0);end--------------------------------------------------------------------------------- Adds a pending bid to the queue.-------------------------------------------------------------------------------function addPendingBid(name, count, bid, owner, request) -- Add a pending bid to the queue. local pendingBid = {}; pendingBid.name = name; pendingBid.count = count; pendingBid.bid = bid; pendingBid.owner = owner; pendingBid.request = request; table.insert(PendingBids, pendingBid); debugPrint("addPendingBid() - Added pending bid"); if (request) then debugPrint("addPendingBid() - Associated request with pending bid "..table.getn(PendingBids)); end -- Register for the response events if this is the first pending bid. if (table.getn(PendingBids) == 1) then debugPrint("addPendingBid() - Registering for CHAT_MSG_SYSTEM and UI_ERROR_MESSAGE"); AucBidManagerFrame:RegisterEvent("CHAT_MSG_SYSTEM"); AucBidManagerFrame:RegisterEvent("UI_ERROR_MESSAGE"); endend--------------------------------------------------------------------------------- Removes the pending bid from the queue.-------------------------------------------------------------------------------function removePendingBid() if (table.getn(PendingBids) > 0) then -- Remove the first pending bid. local bid = PendingBids[1]; table.remove(PendingBids, 1); debugPrint("removePendingBid() - Removed pending bid"); -- Unregister for the response events if this is the last pending bid. if (table.getn(PendingBids) == 0) then debugPrint("removePendingBid() - Unregistering for CHAT_MSG_SYSTEM and UI_ERROR_MESSAGE"); AucBidManagerFrame:UnregisterEvent("CHAT_MSG_SYSTEM"); AucBidManagerFrame:UnregisterEvent("UI_ERROR_MESSAGE"); end return bid; end -- No pending bid to remove! return nil;end--------------------------------------------------------------------------------- Called before PlaceAuctionBid()-------------------------------------------------------------------------------function placeAuctionBidHook(_, _, listType, index, bid, request) local name, texture, count, quality, canUse, level, minBid, minIncrement, buyoutPrice, bidAmount, highBidder, owner = GetAuctionItemInfo(listType, index); if (name and count and bid) then addPendingBid(name, count, bid, owner, request); return "setparams", {listType, index, bid}; else debugPrint("PlaceAuctionBid() - Ignoring bid"); return "abort"; endend--------------------------------------------------------------------------------- Called whenever a response to a bid is received-------------------------------------------------------------------------------function onBidResponse(result) if (table.getn(PendingBids) > 0) then -- We always assume the bid response is for the next bid in PendingBids. local bid = removePendingBid(); -- If there is an associated request, add our result to it. local request = bid.request; if (request) then debugPrint("Found request associated with bid"); if (result == BidResultCodes["BidAccepted"]) then table.insert(request.results, result); if (request.bid == request.buyout) then local output = string.format(_AUCT('FrmtBoughtAuction'), request.name, request.count); chatPrint(output); else local output = string.format(_AUCT('FrmtBidAuction'), request.name, request.count); chatPrint(output); end elseif (result == BidResultCodes["ItemNotFound"]) then -- nothing to do elseif (result == BidResultCodes["NotEnoughMoney"]) then table.insert(request.results, result); local output = string.format(_AUCT('FrmtNotEnoughMoney'), request.name, request.count); chatPrint(output); elseif (result == BidResultCodes["OwnAuction"]) then table.insert(request.results, result); local output = string.format(_AUCT('FrmtSkippedBiddingOnOwnAuction'), request.name, request.count); chatPrint(output); elseif (result == BidResultCodes["AlreadyHigherBid"]) then if (request.bid ~= request.buyout) then table.insert(request.results, result); local output = string.format(_AUCT('FrmtSkippedAuctionWithHigherBid'), request.name, request.count); chatPrint(output); else debugPrint("Attempted to buyout the same auction"); end end else debugPrint("Did not find request associated with bid"); end -- Process the bid result . if (result == BidResultCodes["BidAccepted"] and request) then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -