⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aucpostmanager.lua

📁 时间太紧了
💻 LUA
📖 第 1 页 / 共 2 页
字号:
--[[	Auctioneer Addon for World of Warcraft(tm).	Version: 3.5.0.0917 (Platypus)	Revision: $Id: AucPostManager.lua 884 2006-06-01 06:28:42Z vindicator $	AucPostManager - manages posting auctions 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-------------------------------------------------------------------------------local RequestQueue = {};local ProcessingRequestQueue = false;--------------------------------------------------------------------------------- State machine states for a request.-------------------------------------------------------------------------------local READY_STATE = "Ready";local COMBINING_STACK_STATE = "CombiningStacks";local SPLITTING_STACK_STATE = "SplittingStack";local SPLITTING_AND_COMBINING_STACK_STATE = "SplittingAndCombiningStacks";local AUCTIONING_STACK_STATE = "AuctioningStack";--------------------------------------------------------------------------------- Function hooks that are used when processing requests-------------------------------------------------------------------------------local Original_PickupContainerItem;local Original_SplitContainerItem;--------------------------------------------------------------------------------- Function Prototypes-------------------------------------------------------------------------------local postAuction;local addRequestToQueue;local removeRequestFromQueue;local processRequestQueue;local run;local onEvent;local setState;local findEmptySlot;local findStackByName;local findStackById;local getItemName;local getItemId;local clearAuctionItem;local findAuctionItem;local getItemQuantity;local printBag;--------------------------------------------------------------------------------------------------------------------------------------------------------------function AucPostManagerFrame_OnLoad()	this:RegisterEvent("AUCTION_HOUSE_CLOSED");end--------------------------------------------------------------------------------------------------------------------------------------------------------------function AucPostManagerFrame_OnEvent(event)	-- Toss all the pending requests when the AH closes.	if (event == "AUCTION_HOUSE_CLOSED") then		while (table.getn(RequestQueue) > 0) do			removeRequestFromQueue();		end	-- Hand off the event to the current request	elseif (table.getn(RequestQueue) > 0) then		local request = RequestQueue[1];		if (request.state ~= READY_STATE) then			onEvent(request, event);			processRequestQueue();		end	endend--------------------------------------------------------------------------------------------------------------------------------------------------------------function AucPostManager_PickupContainerItem(bag, slot)	-- Intentionally empty; don't allow items to be picked up while posting	-- auctions.	debugPrint("Prevented call to PickupContainerItem()");end--------------------------------------------------------------------------------------------------------------------------------------------------------------function AucPostManager_SplitContainerItem(bag, slot, count)	-- Intentionally empty; don't allow items to be picked up while posting	-- auctions.	debugPrint("Prevented call to SplitContainerItem()");end--------------------------------------------------------------------------------- Wrapper around PickupContainerItem() that always calls the Blizzard version.-------------------------------------------------------------------------------function pickupContainerItem(bag, slot)	if (Original_PickupContainerItem) then		return Original_PickupContainerItem(bag, slot);	end	return PickupContainerItem(bag, slot);end--------------------------------------------------------------------------------- Wrapper around SplitContainerItem() that always calls the Blizzard version.-------------------------------------------------------------------------------function splitContainerItem(bag, slot, count)	if (Original_SplitContainerItem) then		return Original_SplitContainerItem(bag, slot, count);	end	return SplitContainerItem(bag, slot, count);end--------------------------------------------------------------------------------- Start an auction.-------------------------------------------------------------------------------function postAuction(id, stackSize, stackCount, bid, buyout, duration, callbackFunc, callbackParam)	-- Problems can occur if the Auctions tab hasn't been shown at least once.	if (not AuctionFrameAuctions:IsVisible()) then		AuctionFrameAuctions:Show();		AuctionFrameAuctions:Hide();	end	-- Add the request to the queue.	local request = {};	request.id = id;	request.name = GetItemInfo(id);	request.stackSize = stackSize;	request.stackCount = stackCount;	request.bid = bid;	request.buyout = buyout;	request.duration = duration;	request.callback = { func = callbackFunc, param = callbackParam };	addRequestToQueue(request);	processRequestQueue();end--------------------------------------------------------------------------------- Adds a request to the queue.-------------------------------------------------------------------------------function addRequestToQueue(request)	request.state = READY_STATE;	request.stackPostCount = 0;	request.lockEventsInCurrentState = 0;	request.stack = nil;	table.insert(RequestQueue, request);end--------------------------------------------------------------------------------- Removes a request at the head of the queue.-------------------------------------------------------------------------------function removeRequestFromQueue()	if (table.getn(RequestQueue) > 0) then		local request = RequestQueue[1];		-- Make absolutely sure we are back in the READY_STATE so that we		-- correctly unregister for events.		setState(request, READY_STATE);		-- Perform the callback		local callback = request.callback;		if (callback and callback.func) then			callback.func(callback.param, request);		end		-- Report the auctions posted		if (request.stackPostCount == 1) then			local output = string.format(_AUCT('FrmtPostedAuction'), request.name, request.stackSize);			chatPrint(output);		else			local output = string.format(_AUCT('FrmtPostedAuctions'), request.stackPostCount, request.name, request.stackSize);			chatPrint(output);		end		table.remove(RequestQueue, 1);		-- If this was the last request, end processing the queue.		if (table.getn(RequestQueue) == 0) then			endProcessingRequestQueue()		end	endend--------------------------------------------------------------------------------- Executes the request at the head of the queue.-------------------------------------------------------------------------------function processRequestQueue()	if (beginProcessingRequestQueue()) then		run(RequestQueue[1]);	endend--------------------------------------------------------------------------------- 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) then		ProcessingRequestQueue = true;		debugPrint("Begin processing the post queue");		-- Hook the functions to disable picking up items. This prevents		-- spurious ITEM_LOCK_CHANGED events from confusing us.		if (not Original_PickupContainerItem) then			Original_PickupContainerItem = PickupContainerItem;			PickupContainerItem = AucPostManager_PickupContainerItem;		end		if (not Original_SplitContainerItem) then			Original_SplitContainerItem = SplitContainerItem;			SplitContainerItem = AucPostManager_SplitContainerItem;		end	end	return ProcessingRequestQueue;end--------------------------------------------------------------------------------- Ends processing the request queue-------------------------------------------------------------------------------function endProcessingRequestQueue()	if (ProcessingRequestQueue) then		-- Unhook the functions.		if (Original_PickupContainerItem) then			PickupContainerItem = Original_PickupContainerItem;			Original_PickupContainerItem = nil;		end		if (Original_SplitContainerItem) then			SplitContainerItem = Original_SplitContainerItem;			Original_SplitContainerItem = nil;		end		debugPrint("End processing the post queue");		ProcessingRequestQueue = false;	endend--------------------------------------------------------------------------------- Performs the next step in fulfilling the request.-------------------------------------------------------------------------------function run(request)	if (request.state == READY_STATE) then		-- Locate a stack of the items. If the request has a stack associated		-- with it, that's a hint to try and use it. Otherwise we'll search		-- for a stack of the exact size. Failing that, we'll start with the		-- first stack we find.		local stack1 = nil;		if (request.stack and request.id == getItemId(request.stack.bag, request.stack.slot)) then			-- Use the stack hint.			stack1 = request.stack;		else			-- Find the first stack.			stack1 = findStackById(request.id);			-- Now look for a stack of the exact size to use instead.			if (stack1) then				local stack2 = { bag = stack1.bag, slot = stack1.slot };				local _, stack2Size = GetContainerItemInfo(stack2.bag, stack2.slot);				while (stack2 and stack2Size ~= request.stackSize) do					stack2 = findStackById(request.id, stack2.bag, stack2.slot + 1);					if (stack2) then						_, stack2Size = GetContainerItemInfo(stack2.bag, stack2.slot);					end				end				if (stack2) then					stack1 = stack2;				end			end		end		-- If we have found a stack, figure out what we should do with it.		if (stack1) then			local _, stack1Size = GetContainerItemInfo(stack1.bag, stack1.slot);			if (stack1Size == request.stackSize) then				-- We've done it! Now move the stack to the auction house.				request.stack = stack1;				setState(request, AUCTIONING_STACK_STATE);				pickupContainerItem(stack1.bag, stack1.slot);				ClickAuctionSellItemButton();				-- Start the auction if requested.				if (request.bid and request.buyout and request.duration) then					StartAuction(request.bid, request.buyout, request.duration);				else					removeRequestFromQueue();				end			elseif (stack1Size < request.stackSize) then				-- The stack we have is less than needed. Locate more of the item.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -