implemented auto stack and multi post, auctions can now be cancelled with right click, posting an auction now adds it to the list without refresh necessary and selects it, charges not working yet
This commit is contained in:
@@ -1,106 +1,83 @@
|
||||
local target_size
|
||||
local slot
|
||||
Aux.post = {}
|
||||
|
||||
local state
|
||||
|
||||
-- iterator for inventory
|
||||
function inventory()
|
||||
local inventory = {}
|
||||
for bag = 0, 4 do
|
||||
if GetBagName(bag) then
|
||||
for bagSlot = 1, GetContainerNumSlots(bag) do
|
||||
tinsert(inventory, { bag = bag, bagSlot = bagSlot })
|
||||
local post_auction
|
||||
|
||||
function Aux.post.onupdate()
|
||||
if state then
|
||||
if state.auctioning then
|
||||
if not GetContainerItemInfo(state.auctioning.bag, state.auctioning.bag_slot) then
|
||||
state.auctioning = nil
|
||||
state.posted = state.posted + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local i = 0
|
||||
local n = getn(inventory)
|
||||
return function()
|
||||
i = i + 1
|
||||
if i <= n then
|
||||
return inventory[i]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function findEmptySlot()
|
||||
for slot in inventory() do
|
||||
if not GetContainerItemInfo(slot.bag, slot.bagSlot) then
|
||||
return slot
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function findItem(name)
|
||||
local slots = {}
|
||||
for slot in inventory() do
|
||||
if itemName(slot) == name then
|
||||
tinsert(slots, slot)
|
||||
end
|
||||
end
|
||||
return slots
|
||||
end
|
||||
|
||||
function sameSlot(slot1, slot2)
|
||||
return slot1.bag == slot2.bag and slot1.bagSlot == slot2.bagSlot
|
||||
end
|
||||
|
||||
function moveItem(fromSlot, toSlot, amount)
|
||||
ClearCursor()
|
||||
SplitContainerItem(fromSlot.bag, fromSlot.bagSlot, amount)
|
||||
PickupContainerItem(toSlot.bag, toSlot.bagSlot)
|
||||
ClearCursor()
|
||||
end
|
||||
|
||||
function itemName(slot)
|
||||
local itemLink = GetContainerItemLink(slot.bag, slot.bagSlot)
|
||||
if itemLink then
|
||||
return string.gsub(itemLink, "^.-%[(.*)%].*", "%1")
|
||||
end
|
||||
end
|
||||
|
||||
function stackSize(slot)
|
||||
local _, itemCount = GetContainerItemInfo(slot.bag, slot.bagSlot)
|
||||
return itemCount
|
||||
end
|
||||
|
||||
function postAuction(slot)
|
||||
ClearCursor()
|
||||
pickupContainerItem(slot.bag, slot.bagSlot)
|
||||
ClickAuctionSellItemButton()
|
||||
ClearCursor()
|
||||
Aux.orig.AuctionsCreateAuctionButton_OnClick()
|
||||
-- StartAuction(request.bid, request.buyout, request.duration);
|
||||
end
|
||||
|
||||
function createStack(name, size)
|
||||
ClearCursor()
|
||||
ClickAuctionSellItemButton()
|
||||
ClearCursor()
|
||||
|
||||
local slots = findItem(name)
|
||||
local stackSlot = slots[1]
|
||||
tremove(slots, 1)
|
||||
|
||||
for _, slot in ipairs(slots) do
|
||||
if stackSize(stackSlot) < size then
|
||||
moveItem(slot, stackSlot, size - stackSize(stackSlot))
|
||||
elseif stackSize(stackSlot) > size then
|
||||
moveItem(stackSlot, slot, stackSize(stackSlot) - size)
|
||||
if state.posted < state.count then
|
||||
if not state.stacking and not state.auctioning then
|
||||
state.stacking = true
|
||||
Aux.stack.start(
|
||||
state.name,
|
||||
state.stack_size,
|
||||
function(slot)
|
||||
if slot then
|
||||
post_auction(slot)
|
||||
else
|
||||
Aux.post.stop()
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
else
|
||||
return stackSlot
|
||||
end
|
||||
end
|
||||
|
||||
if stackSize(stackSlot) > size then
|
||||
local emptySlot = findEmptySlot()
|
||||
Aux_Log(stackSize(stackSlot) .. ' : ' .. emptySlot.bag .. ' ' .. emptySlot.bagSlot)
|
||||
moveItem(stackSlot, emptySlot, stackSize(stackSlot) - size)
|
||||
Aux_Log(stackSize(stackSlot) .. ' : ' .. emptySlot.bag .. ' ' .. emptySlot.bagSlot)
|
||||
if stackSize(stackSlot) == size then
|
||||
return stackSlot
|
||||
Aux.post.stop()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- /script createStack('Dried King Bolete', 3)
|
||||
function Aux.post.stop()
|
||||
if state then
|
||||
local callback = state.callback
|
||||
local posted = state.posted
|
||||
|
||||
state = nil
|
||||
PickupContainerItem = Aux.stack.orig.PickupContainerItem
|
||||
SplitContainerItem = Aux.stack.orig.SplitContainerItem
|
||||
|
||||
if callback then
|
||||
callback(posted)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function post_auction(slot)
|
||||
ClearCursor()
|
||||
ClickAuctionSellItemButton()
|
||||
ClearCursor()
|
||||
PickupContainerItem(slot.bag, slot.bag_slot)
|
||||
ClickAuctionSellItemButton()
|
||||
ClearCursor()
|
||||
StartAuction(state.bid, state.buyout, state.duration)
|
||||
state.auctioning = slot
|
||||
state.stacking = false
|
||||
end
|
||||
|
||||
function Aux.post.start(name, stack_size, duration, bid, buyout, count, callback)
|
||||
Aux.post.stop()
|
||||
|
||||
ClearCursor()
|
||||
ClickAuctionSellItemButton()
|
||||
ClearCursor()
|
||||
|
||||
PickupContainerItem = function() end
|
||||
SplitContainerItem = function() end
|
||||
|
||||
state = {
|
||||
name = name,
|
||||
stack_size = stack_size,
|
||||
duration = duration,
|
||||
bid = bid,
|
||||
buyout = buyout,
|
||||
count = count,
|
||||
posted = 0,
|
||||
callback = callback,
|
||||
}
|
||||
end
|
||||
Reference in New Issue
Block a user