# HG changeset patch # User Zerotorescue # Date 1295044272 -3600 # Node ID 41f0689dfda198759b6b36b734217165ce5ea37f # Parent 67bd5057ecb7190ac0d39756370e29d7d60a176f This implementation of vendor buying did not work well. Too many customizations were needed that made the code hard to read and understand and eventually it was found that vendor buying should be based on refill target, not local stock. The mover/refiller is not meant for this, we should just do this somewhere else. diff -r 67bd5057ecb7 -r 41f0689dfda1 Classes/ContainerItem.class.lua --- a/Classes/ContainerItem.class.lua Fri Jan 14 23:25:05 2011 +0100 +++ b/Classes/ContainerItem.class.lua Fri Jan 14 23:31:12 2011 +0100 @@ -19,12 +19,11 @@ return self; end -function addon.ContainerItem:AddLocation(container, slot, count, price) +function addon.ContainerItem:AddLocation(container, slot, count) table.insert(self.locations, { ["container"] = container, ["slot"] = slot, ["count"] = count, - ["price"] = price, }); -- -1 indicates unlimited supply @@ -38,11 +37,3 @@ return true; end - -function addon.ContainerItem:GetVendorPrice() - for _, loc in pairs(self.locations) do - if loc.price then - return loc.price; - end - end -end diff -r 67bd5057ecb7 -r 41f0689dfda1 Modules/Mover.lua --- a/Modules/Mover.lua Fri Jan 14 23:25:05 2011 +0100 +++ b/Modules/Mover.lua Fri Jan 14 23:31:12 2011 +0100 @@ -11,7 +11,6 @@ Bank = 1, Guild = 2, Mailbox = 3, - Merchant = 4, }; local ContainerFunctions = { @@ -51,37 +50,14 @@ 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) - -- The below behavior was changed in patch 4.0.1, it now acts as expected; quantity requested equals exact quantity bought, even with increased batchsize - - -- Some merchant items are sold in batches (e.g. of 5) - -- In that case BuyMerchantItem wants the num stacks, rather than the quantity to be bought - --local batchSize = select(4, GetMerchantItemInfo(merchantIndex)); - - --local batches = math.ceil(num / batchSize); - - --BuyMerchantItem(merchantIndex, batches); - - 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, price) +function mod:AddMove(itemId, amount, numMissing, numAvailable) table.insert(queuedMoves, { ["itemId"] = itemId, ["num"] = amount, -- can not be unlimited ["missing"] = numMissing, ["available"] = numAvailable, - ["price"] = price, }); end @@ -173,40 +149,12 @@ 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 == -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); - end - end - end + local movingNum = ((itemLocation.count > singleMove.num and singleMove.num) or itemLocation.count); table.insert(outgoingMoves, { ["itemId"] = singleMove.itemId, diff -r 67bd5057ecb7 -r 41f0689dfda1 Modules/Scanner.lua --- a/Modules/Scanner.lua Fri Jan 14 23:25:05 2011 +0100 +++ b/Modules/Scanner.lua Fri Jan 14 23:31:12 2011 +0100 @@ -18,7 +18,7 @@ InventoriumItemMover:Hide(); end -local function UseStorageRefillST(withPrices) +local function UseStorageRefillST() local frame = InventoriumItemMover; -- both for speed as code-consistency -- Scrolling table with a list of items to be moved @@ -26,7 +26,7 @@ local headers = { { ["name"] = "Item", - ["width"] = (scrollTableWidth * ((withPrices and .5) or .60)), + ["width"] = (scrollTableWidth * .60), ["defaultsort"] = "asc", ["comparesort"] = function(this, aRow, bRow, column) local aName, _, aRarity = GetItemInfo(this:GetRow(aRow).rowData.itemId); @@ -56,7 +56,7 @@ }, { ["name"] = "Available", - ["width"] = (scrollTableWidth * ((withPrices and .2) or .25)), + ["width"] = (scrollTableWidth * .25), ["align"] = "RIGHT", ["defaultsort"] = "dsc", ["sortnext"] = 1, @@ -74,17 +74,6 @@ ["tooltip"] = (not addon.db.profile.defaults.hideHelp and "Click to sort the list by the availibility percentage."), }, }; - if withPrices then - table.insert(headers, { - ["name"] = "Price", - ["width"] = (scrollTableWidth * .15), - ["align"] = "RIGHT", - ["defaultsort"] = "dsc", - ["sortnext"] = 1, - ["tooltipTitle"] = (not addon.db.profile.defaults.hideHelp and "Price"), - ["tooltip"] = (not addon.db.profile.defaults.hideHelp and "Click to sort the list by the price of this item at this vendor."), - }); - end local proceedButton = { text = "Move Items", @@ -211,28 +200,6 @@ end end end - elseif location == addon.Locations.Merchant then - for itemIndex = 1, GetMerchantNumItems() do - -- All merchant items - - local itemLink = GetMerchantItemLink(itemIndex); - local itemId = itemLink and addon:GetItemId(itemLink); - local _, _, vendorValue, _, numAvailable, _, extendedCost = GetMerchantItemInfo(index); - - if itemLink and itemId and numAvailable ~= 0 and not extendedCost then - local itemMove; - if not itemCache[itemId] then - -- If this is the first time we see this item, make a new object - itemMove = addon.ContainerItem:New(); - itemCache[itemId] = itemMove; - else - -- If we had this item in another slot too - itemMove = itemCache[itemId]; - end - - itemMove:AddLocation(1, itemIndex, numAvailable, vendorValue); - end - end else error("Invalid location provided for CacheLocation. Must be Bank or Guild."); end @@ -282,12 +249,12 @@ -- Check how many are available local availableItems = ((itemCache[itemId] and itemCache[itemId].totalCount) or 0); -- Calculate how many we'll be moving (less missing than available? use missing, otherwise use available) - local moving = (((availableItems == -1 or missingItems <= availableItems) and missingItems) or availableItems); + local moving = ((missingItems <= availableItems and missingItems) or availableItems); - if availableItems ~= 0 then - addon:Debug("Insufficient %s but this location has %s (moving %d)", IdToItemLink(itemId), ((availableItems == -1 and "unlimited") or availableItems), moving); + if availableItems > 0 then + addon:Debug("Insufficient %s but this location has %d (moving %d)", IdToItemLink(itemId), availableItems, moving); - Mover:AddMove(itemId, moving, missingItems, availableItems, itemCache[itemId]:GetVendorPrice()); + Mover:AddMove(itemId, moving, missingItems, availableItems); end end end @@ -300,7 +267,7 @@ if addon.db.profile.defaults.autoRefillSkipConfirm then OnMoveAccept(); else - UseStorageRefillST((location == addon.Locations.Merchant)); + UseStorageRefillST(); -- This table is never copied, just referenced. It is the same for every row. local columns = { @@ -323,13 +290,6 @@ end, }, -- missing / available }; - if location == addon.Locations.Merchant then - table.insert(columns, { - ["value"] = function(data, cols, realrow, column, table) - return GetCoinTextureString(data[realrow].rowData.price * data[realrow].rowData.num); - end, - }); - end -- Store the list with rows in this local data = {}; @@ -426,25 +386,6 @@ self:RegisterEvent("GUILDBANKBAGSLOTS_CHANGED"); end -function mod:MERCHANT_SHOW() - addon:Debug("Scanner:MERCHANT_SHOW"); - - self:RegisterEvent("MERCHANT_CLOSED"); - - self:Scan(addon.Locations.Merchant); -end - -function mod:MERCHANT_CLOSED() - addon:Debug("Scanner:MERCHANT_CLOSED"); - - self:ClearCache(); - - self:UnregisterEvent("MERCHANT_CLOSED"); - - InventoriumItemMover:Hide(); - Mover:ResetQueue(); -end - --local previousMailCount; --function mod:MAIL_SHOW() -- addon:Debug("Scanner:MAIL_SHOW"); @@ -498,7 +439,6 @@ self:RegisterEvent("BANKFRAME_OPENED"); self:RegisterEvent("GUILDBANKFRAME_OPENED"); -- self:RegisterEvent("MAIL_SHOW"); - self:RegisterEvent("MERCHANT_SHOW"); Mover = addon:GetModule("Mover");