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

📄 aucpostmanager.lua

📁 时间太紧了
💻 LUA
📖 第 1 页 / 共 2 页
字号:
				local stack2 = findStackById(request.id, stack1.bag, stack1.slot + 1);				if (stack2) then					local _, stack2Size = GetContainerItemInfo(stack2.bag, stack2.slot);					if (stack1Size + stack2Size <= request.stackSize) then						-- Combine all of stack2 with stack1.						setState(request, COMBINING_STACK_STATE);						pickupContainerItem(stack2.bag, stack2.slot);						pickupContainerItem(stack1.bag, stack1.slot);						request.stack = stack1;					else						-- Combine part of stack2 with stack1.						setState(request, SPLITTING_AND_COMBINING_STACK_STATE);						splitContainerItem(stack2.bag, stack2.slot, request.stackSize - stack1Size);						pickupContainerItem(stack1.bag, stack1.slot);						request.stack = stack1;					end				else					-- Not enough of the item found!					chatPrint(_AUCT('FrmtNoEmptyPackSpace'));					removeRequestFromQueue();				end			else				-- The stack we have is more than needed. Locate an empty slot.				local stack2 = findEmptySlot();				if (stack2) then					setState(request, SPLITTING_STACK_STATE);					splitContainerItem(stack1.bag, stack1.slot, request.stackSize);					pickupContainerItem(stack2.bag, stack2.slot);					request.stack = stack2;				else					-- Not enough of the item!					local output = string.format(_AUCT('FrmtNotEnoughOfItem'), request.name);					chatPrint(output);					removeRequestFromQueue();				end			end		else			-- Item not found!			local output = string.format(_AUCT('FrmtNotEnoughOfItem'), request.name);			chatPrint(output);			removeRequestFromQueue();		end	endend--------------------------------------------------------------------------------- Processes the event.-------------------------------------------------------------------------------function onEvent(request, event)	debugPrint("Received event "..event.. " in state "..request.state);	-- Process the event.	if (event == "ITEM_LOCK_CHANGED") then		-- Check if we are waiting for a stack to be complete.		request.lockEventsInCurrentState = request.lockEventsInCurrentState + 1;		if (request.lockEventsInCurrentState == 3 and			(request.state == SPLITTING_STACK_STATE or			 request.state == COMBINING_STACK_STATE or			 request.state == SPLITTING_AND_COMBINING_STACK_STATE)) then			-- Ready to move onto the next step.			setState(request, READY_STATE);		end	elseif (event == "BAG_UPDATE") then		-- Check if we are waiting for StartAuction() to complete. If so, check		-- if the stack we are trying to auction is now gone.		if (request.state == AUCTIONING_STACK_STATE and GetContainerItemInfo(request.stack.bag, request.stack.slot) == nil) then			-- Ready to move onto the next step.			setState(request, READY_STATE);			-- Decrement the auction target count.			request.stackPostCount = request.stackPostCount + 1;			if (request.stackPostCount == request.stackCount) then				removeRequestFromQueue();			end		end	endend--------------------------------------------------------------------------------- Changes the request state.-------------------------------------------------------------------------------function setState(request, newState)	if (request.state ~= newState) then		debugPrint("Entered state: "..newState);		-- Unregister for events needed in the old state.		if (request.state == SPLITTING_STACK_STATE or			request.state == COMBINING_STACK_STATE or			request.state == SPLITTING_AND_COMBINING_STACK_STATE) then			debugPrint("Unregistering for ITEM_LOCK_CHANGED");			AucPostManagerFrame:UnregisterEvent("ITEM_LOCK_CHANGED");		elseif (request.state == AUCTIONING_STACK_STATE) then			debugPrint("Unregistering for BAG_UPDATE");			AucPostManagerFrame:UnregisterEvent("BAG_UPDATE");		end		-- Update the request's state.		request.state = newState;		request.lockEventsInCurrentState = 0;		-- Register for events needed in the new state.		if (request.state == SPLITTING_STACK_STATE or			request.state == COMBINING_STACK_STATE or			request.state == SPLITTING_AND_COMBINING_STACK_STATE) then			debugPrint("Registering for ITEM_LOCK_CHANGED");			AucPostManagerFrame:RegisterEvent("ITEM_LOCK_CHANGED");		elseif (request.state == AUCTIONING_STACK_STATE) then			debugPrint("Registering for BAG_UPDATE");			AucPostManagerFrame:RegisterEvent("BAG_UPDATE");		end	endend--------------------------------------------------------------------------------- Finds an empty slot in the player's containers.---- TODO: Correctly handle containers like ammo packs-------------------------------------------------------------------------------function findEmptySlot()	for bag = 0, 4, 1 do		if (GetBagName(bag)) then			for item = GetContainerNumSlots(bag), 1, -1 do				if (not GetContainerItemInfo(bag, item)) then					return { bag=bag, slot=item };				end			end		end	end	return nil;end--------------------------------------------------------------------------------- Finds the specified item by name---- TODO: Correctly handle containers like ammo packs-------------------------------------------------------------------------------function findStackByName(name, startingBag, startingSlot)	if (startingBag == nil) then		startingBag = 0;	end	if (startingSlot == nil) then		startingSlot = 1;	end	for bag = startingBag, 4, 1 do		if (GetBagName(bag)) then			local numItems = GetContainerNumSlots(bag);			if (startingSlot <= numItems) then				for slot = startingSlot, GetContainerNumSlots(bag), 1 do					local itemName = getItemName(bag, slot);					if (name == itemName) then						return { bag=bag, slot=slot };					end				end			end			startingSlot = 1;		end	end	return nil;end--------------------------------------------------------------------------------- Finds the specified item by id---- TODO: Correctly handle containers like ammo packs-------------------------------------------------------------------------------function findStackById(id, startingBag, startingSlot)	if (startingBag == nil) then		startingBag = 0;	end	if (startingSlot == nil) then		startingSlot = 1;	end	for bag = startingBag, 4, 1 do		if (GetBagName(bag)) then			local numItems = GetContainerNumSlots(bag);			if (startingSlot <= numItems) then				for slot = startingSlot, GetContainerNumSlots(bag), 1 do					local itemId = getItemId(bag, slot);					if (id == itemId) then						return { bag=bag, slot=slot };					end				end			end			startingSlot = 1;		end	end	return nil;end--------------------------------------------------------------------------------- Gets the name of the specified-------------------------------------------------------------------------------function getItemName(bag, slot)	local link = GetContainerItemLink(bag, slot);	if (link) then		local _, _, _, _, name = EnhTooltip.BreakLink(link);		return name;	endend--------------------------------------------------------------------------------- Gets the id of the specified-------------------------------------------------------------------------------function getItemId(bag, slot)	local link = GetContainerItemLink(bag, slot);	if (link) then		local id = EnhTooltip.BreakLink(link);		return id;	endend--------------------------------------------------------------------------------- Clears the current auction item, if any.-------------------------------------------------------------------------------function clearAuctionItem()	local bag, item = findAuctionItem();	if (bag and item) then		ClickAuctionSellItemButton();		pickupContainerItem(bag, item);	endend--------------------------------------------------------------------------------- Finds the bag and slot for the current auction item.---- TODO: Correctly handle containers like ammo packs-------------------------------------------------------------------------------function findAuctionItem()	local auctionName, _, auctionCount = GetAuctionSellItemInfo();	--debugPrint("Searching for "..auctionName.." in a stack of "..auctionCount);	if (auctionName and auctionCount) then		for bag = 0, 4, 1 do			if (GetBagName(bag)) then				for item = GetContainerNumSlots(bag), 1, -1 do					--debugPrint("Checking "..bag..", "..item);					local _, itemCount, itemLocked = GetContainerItemInfo(bag, item);					if (itemLocked and itemCount == auctionCount) then						local itemName = getItemName(bag, item);						--debugPrint("Item "..itemName.." locked");						if (itemName == auctionName) then							return bag, item;						end					end				end			end		end	endend--------------------------------------------------------------------------------- Gets the quanity of the specified item---- TODO: Correctly handle containers like ammo packs-------------------------------------------------------------------------------function getItemQuantity(id)	local quantity = 0;	for bag = 0, 4, 1 do		if (GetBagName(bag)) then			for item = GetContainerNumSlots(bag), 1, -1 do				local itemId = getItemId(bag, item);				if (id == itemId) then					local _, itemCount = GetContainerItemInfo(bag, item);					quantity = quantity + itemCount;				end			end		end	end	return quantity;end--------------------------------------------------------------------------------------------------------------------------------------------------------------function nilSafe(string)	if (string) then		return string;	end	return "<nil>";end--------------------------------------------------------------------------------------------------------------------------------------------------------------chatPrint = Auctioneer.Util.ChatPrint;--------------------------------------------------------------------------------------------------------------------------------------------------------------debugPrint = EnhTooltip.DebugPrint;--------------------------------------------------------------------------------- Public API-------------------------------------------------------------------------------AucPostManager ={	-- Exported functions	PostAuction = postAuction;	GetItemQuantity = getItemQuantity;};

⌨️ 快捷键说明

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