Mercurial > wow > inventory
diff Modules/Mover.lua @ 119:dc6f405c1a5d
Now resizing the mover frame based on text size.
addon.Locations table now uses location names as value, rather than random numbers.
Added proper Merchant restocking support. Please note this currently doesn?t take the bonus queue nor the min crafting queue options into account.
author | Zerotorescue |
---|---|
date | Sat, 15 Jan 2011 17:03:05 +0100 |
parents | 239e25a058c7 |
children | 00cf4fc1697f |
line wrap: on
line diff
--- a/Modules/Mover.lua Sat Jan 15 16:24:39 2011 +0100 +++ b/Modules/Mover.lua Sat Jan 15 17:03:05 2011 +0100 @@ -7,10 +7,11 @@ local movesSource; addon.Locations = { - Bag = 0, - Bank = 1, - Guild = 2, - Mailbox = 3, + ["Bag"] = "Bag", + ["Bank"] = "Bank", + ["Guild"] = "Guild", + ["Mailbox"] = "Mailbox", + ["Merchant"] = "Merchant", }; local ContainerFunctions = { @@ -50,14 +51,27 @@ Synchronous = true, -- wait after every single move Event = "BAG_UPDATE", }, + [addon.Locations.Merchant] = { + GetItemId = function(_, merchantIndex) + return addon:GetItemId(GetMerchantItemLink(merchantIndex)); + end, + PickupItem = function(_, merchantIndex, num) + return BuyMerchantItem(merchantIndex, num); + end, + IsLocked = function() return false; end, + DoNotDrop = true, -- BuyMerchantItem does not support picking up + Burst = true, -- spam buy items, the source can take it + Event = "BAG_UPDATE", + }, }; -function mod:AddMove(itemId, amount, numMissing, numAvailable) +function mod:AddMove(itemId, amount, numMissing, numAvailable, cost) table.insert(queuedMoves, { ["itemId"] = itemId, ["num"] = amount, -- can not be unlimited ["missing"] = numMissing, ["available"] = numAvailable, + ["cost"] = cost, }); end @@ -149,12 +163,42 @@ else -- We want to move the smallest stacks first to keep stuff pretty (and minimize space usage, splitting a stack takes 2 slots, moving something only 1) table.sort(sourceItem.locations, function(a, b) + -- -1 indicates unlimited, this is always more than an actual amount + if a.count == -1 then + return false; + elseif b.count == -1 then + return true; + end + return a.count < b.count; end); for _, itemLocation in pairs(sourceItem.locations) do -- if this location has more items than we need, only move what we need, otherwise move everything in this stack - local movingNum = ((itemLocation.count > singleMove.num and singleMove.num) or itemLocation.count); + -- -1 items indicates unlimited amount, in that case we must cap at missing items + local movingNum = (((itemLocation.count == -1 or itemLocation.count > singleMove.num) and singleMove.num) or itemLocation.count); + + if itemLocation.count == -1 then + -- If the source has an unlimited quantity, makes moves based on the max stacksize + + local stackSize = select(8, GetItemInfo(singleMove.itemId)); -- 8 = stacksize + + if stackSize then + while movingNum > stackSize do + -- Move a single stack size while the amount remaining to be moved is above the stack size num + + table.insert(outgoingMoves, { + ["itemId"] = singleMove.itemId, + ["num"] = stackSize, + ["container"] = itemLocation.container, + ["slot"] = itemLocation.slot, + }); + + movingNum = (movingNum - stackSize); + singleMove.num = (singleMove.num - stackSize); + end + end + end table.insert(outgoingMoves, { ["itemId"] = singleMove.itemId,