comparison Modules/Mover.lua @ 111:41f0689dfda1

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.
author Zerotorescue
date Fri, 14 Jan 2011 23:31:12 +0100
parents 67bd5057ecb7
children 239e25a058c7
comparison
equal deleted inserted replaced
110:67bd5057ecb7 111:41f0689dfda1
9 addon.Locations = { 9 addon.Locations = {
10 Bag = 0, 10 Bag = 0,
11 Bank = 1, 11 Bank = 1,
12 Guild = 2, 12 Guild = 2,
13 Mailbox = 3, 13 Mailbox = 3,
14 Merchant = 4,
15 }; 14 };
16 15
17 local ContainerFunctions = { 16 local ContainerFunctions = {
18 [addon.Locations.Bag] = { 17 [addon.Locations.Bag] = {
19 GetItemId = GetContainerItemID, 18 GetItemId = GetContainerItemID,
49 IsLocked = function() return false; end, 48 IsLocked = function() return false; end,
50 DoNotDrop = true, -- TakeInboxItem does not support picking up 49 DoNotDrop = true, -- TakeInboxItem does not support picking up
51 Synchronous = true, -- wait after every single move 50 Synchronous = true, -- wait after every single move
52 Event = "BAG_UPDATE", 51 Event = "BAG_UPDATE",
53 }, 52 },
54 [addon.Locations.Merchant] = {
55 GetItemId = function(_, merchantIndex)
56 return addon:GetItemId(GetMerchantItemLink(merchantIndex));
57 end,
58 PickupItem = function(_, merchantIndex, num)
59 -- 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
60
61 -- Some merchant items are sold in batches (e.g. of 5)
62 -- In that case BuyMerchantItem wants the num stacks, rather than the quantity to be bought
63 --local batchSize = select(4, GetMerchantItemInfo(merchantIndex));
64
65 --local batches = math.ceil(num / batchSize);
66
67 --BuyMerchantItem(merchantIndex, batches);
68
69 return BuyMerchantItem(merchantIndex, num);
70 end,
71 IsLocked = function() return false; end,
72 DoNotDrop = true, -- BuyMerchantItem does not support picking up
73 Burst = true, -- spam buy items, the source can take it
74 Event = "BAG_UPDATE",
75 },
76 }; 53 };
77 54
78 function mod:AddMove(itemId, amount, numMissing, numAvailable, price) 55 function mod:AddMove(itemId, amount, numMissing, numAvailable)
79 table.insert(queuedMoves, { 56 table.insert(queuedMoves, {
80 ["itemId"] = itemId, 57 ["itemId"] = itemId,
81 ["num"] = amount, -- can not be unlimited 58 ["num"] = amount, -- can not be unlimited
82 ["missing"] = numMissing, 59 ["missing"] = numMissing,
83 ["available"] = numAvailable, 60 ["available"] = numAvailable,
84 ["price"] = price,
85 }); 61 });
86 end 62 end
87 63
88 function mod:HasMoves() 64 function mod:HasMoves()
89 return (#queuedMoves ~= 0); 65 return (#queuedMoves ~= 0);
171 if not sourceItem then 147 if not sourceItem then
172 addon:Print(("Can't move %s, this doesn't exist in the source."):format(IdToItemLink(singleMove.itemId)), addon.Colors.Red); 148 addon:Print(("Can't move %s, this doesn't exist in the source."):format(IdToItemLink(singleMove.itemId)), addon.Colors.Red);
173 else 149 else
174 -- 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) 150 -- 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)
175 table.sort(sourceItem.locations, function(a, b) 151 table.sort(sourceItem.locations, function(a, b)
176 -- -1 indicates unlimited, this is always more than an actual amount
177 if a.count == -1 then
178 return false;
179 elseif b.count == -1 then
180 return true;
181 end
182
183 return a.count < b.count; 152 return a.count < b.count;
184 end); 153 end);
185 154
186 for _, itemLocation in pairs(sourceItem.locations) do 155 for _, itemLocation in pairs(sourceItem.locations) do
187 -- if this location has more items than we need, only move what we need, otherwise move everything in this stack 156 -- if this location has more items than we need, only move what we need, otherwise move everything in this stack
188 local movingNum = (((itemLocation.count == -1 or itemLocation.count > singleMove.num) and singleMove.num) or itemLocation.count); 157 local movingNum = ((itemLocation.count > singleMove.num and singleMove.num) or itemLocation.count);
189
190 if itemLocation.count == -1 then
191 -- If the source has an unlimited quantity, makes moves based on the max stacksize
192
193 local stackSize = select(8, GetItemInfo(singleMove.itemId)); -- 8 = stacksize
194
195 if stackSize then
196 while movingNum > stackSize do
197 -- Move a single stack size while the amount remaining to be moved is above the stack size num
198
199 table.insert(outgoingMoves, {
200 ["itemId"] = singleMove.itemId,
201 ["num"] = stackSize,
202 ["container"] = itemLocation.container,
203 ["slot"] = itemLocation.slot,
204 });
205
206 movingNum = (movingNum - stackSize);
207 end
208 end
209 end
210 158
211 table.insert(outgoingMoves, { 159 table.insert(outgoingMoves, {
212 ["itemId"] = singleMove.itemId, 160 ["itemId"] = singleMove.itemId,
213 ["num"] = movingNum, 161 ["num"] = movingNum,
214 ["container"] = itemLocation.container, 162 ["container"] = itemLocation.container,