Mercurial > wow > inventory
comparison 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 |
comparison
equal
deleted
inserted
replaced
118:de18ef96983b | 119:dc6f405c1a5d |
---|---|
5 local queuedMoves = {}; -- table storing all queued moves before BeginMove is called | 5 local queuedMoves = {}; -- table storing all queued moves before BeginMove is called |
6 local combinedMoves = {}; -- table storing all combined moves (with source and target) that is to be processed by the actual mover in the order of the index (1 to #) | 6 local combinedMoves = {}; -- table storing all combined moves (with source and target) that is to be processed by the actual mover in the order of the index (1 to #) |
7 local movesSource; | 7 local movesSource; |
8 | 8 |
9 addon.Locations = { | 9 addon.Locations = { |
10 Bag = 0, | 10 ["Bag"] = "Bag", |
11 Bank = 1, | 11 ["Bank"] = "Bank", |
12 Guild = 2, | 12 ["Guild"] = "Guild", |
13 Mailbox = 3, | 13 ["Mailbox"] = "Mailbox", |
14 ["Merchant"] = "Merchant", | |
14 }; | 15 }; |
15 | 16 |
16 local ContainerFunctions = { | 17 local ContainerFunctions = { |
17 [addon.Locations.Bag] = { | 18 [addon.Locations.Bag] = { |
18 GetItemId = GetContainerItemID, | 19 GetItemId = GetContainerItemID, |
48 IsLocked = function() return false; end, | 49 IsLocked = function() return false; end, |
49 DoNotDrop = true, -- TakeInboxItem does not support picking up | 50 DoNotDrop = true, -- TakeInboxItem does not support picking up |
50 Synchronous = true, -- wait after every single move | 51 Synchronous = true, -- wait after every single move |
51 Event = "BAG_UPDATE", | 52 Event = "BAG_UPDATE", |
52 }, | 53 }, |
54 [addon.Locations.Merchant] = { | |
55 GetItemId = function(_, merchantIndex) | |
56 return addon:GetItemId(GetMerchantItemLink(merchantIndex)); | |
57 end, | |
58 PickupItem = function(_, merchantIndex, num) | |
59 return BuyMerchantItem(merchantIndex, num); | |
60 end, | |
61 IsLocked = function() return false; end, | |
62 DoNotDrop = true, -- BuyMerchantItem does not support picking up | |
63 Burst = true, -- spam buy items, the source can take it | |
64 Event = "BAG_UPDATE", | |
65 }, | |
53 }; | 66 }; |
54 | 67 |
55 function mod:AddMove(itemId, amount, numMissing, numAvailable) | 68 function mod:AddMove(itemId, amount, numMissing, numAvailable, cost) |
56 table.insert(queuedMoves, { | 69 table.insert(queuedMoves, { |
57 ["itemId"] = itemId, | 70 ["itemId"] = itemId, |
58 ["num"] = amount, -- can not be unlimited | 71 ["num"] = amount, -- can not be unlimited |
59 ["missing"] = numMissing, | 72 ["missing"] = numMissing, |
60 ["available"] = numAvailable, | 73 ["available"] = numAvailable, |
74 ["cost"] = cost, | |
61 }); | 75 }); |
62 end | 76 end |
63 | 77 |
64 function mod:HasMoves() | 78 function mod:HasMoves() |
65 return (#queuedMoves ~= 0); | 79 return (#queuedMoves ~= 0); |
147 if not sourceItem then | 161 if not sourceItem then |
148 addon:Print(("Can't move %s, this doesn't exist in the source."):format(IdToItemLink(singleMove.itemId)), addon.Colors.Red); | 162 addon:Print(("Can't move %s, this doesn't exist in the source."):format(IdToItemLink(singleMove.itemId)), addon.Colors.Red); |
149 else | 163 else |
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) | 164 -- 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) |
151 table.sort(sourceItem.locations, function(a, b) | 165 table.sort(sourceItem.locations, function(a, b) |
166 -- -1 indicates unlimited, this is always more than an actual amount | |
167 if a.count == -1 then | |
168 return false; | |
169 elseif b.count == -1 then | |
170 return true; | |
171 end | |
172 | |
152 return a.count < b.count; | 173 return a.count < b.count; |
153 end); | 174 end); |
154 | 175 |
155 for _, itemLocation in pairs(sourceItem.locations) do | 176 for _, itemLocation in pairs(sourceItem.locations) do |
156 -- if this location has more items than we need, only move what we need, otherwise move everything in this stack | 177 -- if this location has more items than we need, only move what we need, otherwise move everything in this stack |
157 local movingNum = ((itemLocation.count > singleMove.num and singleMove.num) or itemLocation.count); | 178 -- -1 items indicates unlimited amount, in that case we must cap at missing items |
179 local movingNum = (((itemLocation.count == -1 or itemLocation.count > singleMove.num) and singleMove.num) or itemLocation.count); | |
180 | |
181 if itemLocation.count == -1 then | |
182 -- If the source has an unlimited quantity, makes moves based on the max stacksize | |
183 | |
184 local stackSize = select(8, GetItemInfo(singleMove.itemId)); -- 8 = stacksize | |
185 | |
186 if stackSize then | |
187 while movingNum > stackSize do | |
188 -- Move a single stack size while the amount remaining to be moved is above the stack size num | |
189 | |
190 table.insert(outgoingMoves, { | |
191 ["itemId"] = singleMove.itemId, | |
192 ["num"] = stackSize, | |
193 ["container"] = itemLocation.container, | |
194 ["slot"] = itemLocation.slot, | |
195 }); | |
196 | |
197 movingNum = (movingNum - stackSize); | |
198 singleMove.num = (singleMove.num - stackSize); | |
199 end | |
200 end | |
201 end | |
158 | 202 |
159 table.insert(outgoingMoves, { | 203 table.insert(outgoingMoves, { |
160 ["itemId"] = singleMove.itemId, | 204 ["itemId"] = singleMove.itemId, |
161 ["num"] = movingNum, | 205 ["num"] = movingNum, |
162 ["container"] = itemLocation.container, | 206 ["container"] = itemLocation.container, |