Mercurial > wow > inventory
comparison Modules/Mover.lua @ 109:3bbad0429d87
Now only giving the ?bags are full? message once per item rather then for every queued move.
Neater coding for the container functions and prepared mailbox support (although this is not currently planned to be further developed for the moment).
Updated todo list to include mailbox support.
author | Zerotorescue |
---|---|
date | Wed, 12 Jan 2011 22:48:25 +0100 |
parents | 6ae44d372360 |
children | 67bd5057ecb7 |
comparison
equal
deleted
inserted
replaced
108:3688fdd14fef | 109:3bbad0429d87 |
---|---|
143 | 143 |
144 if not firstAvailableSlot then | 144 if not firstAvailableSlot then |
145 addon:Print(("Bags are full. Skipping %s."):format(IdToItemLink(outgoingMove.itemId)), addon.Colors.Orange); | 145 addon:Print(("Bags are full. Skipping %s."):format(IdToItemLink(outgoingMove.itemId)), addon.Colors.Orange); |
146 | 146 |
147 outgoingMove.itemId = nil; -- remove this record from the outgoingMoves-table | 147 outgoingMove.itemId = nil; -- remove this record from the outgoingMoves-table |
148 | |
149 -- Not a single item with this item id can be moved, since we only want the bags are full announcement once, we remove all other moves with this item id | |
150 for _, otherMove in pairs(outgoingMoves) do | |
151 if otherMove.itemId and otherMove.itemId == outgoingMove.itemId then | |
152 otherMove.itemId = nil; | |
153 end | |
154 end | |
148 else | 155 else |
149 table.insert(combinedMoves, { | 156 table.insert(combinedMoves, { |
150 itemId = outgoingMove.itemId, | 157 itemId = outgoingMove.itemId, |
151 num = outgoingMove.num, | 158 num = outgoingMove.num, |
152 sourceContainer = outgoingMove.container, | 159 sourceContainer = outgoingMove.container, |
264 | 271 |
265 -- Even though we aren't completely done yet, allow requeueing | 272 -- Even though we aren't completely done yet, allow requeueing |
266 onFinish(); | 273 onFinish(); |
267 end | 274 end |
268 | 275 |
276 local ContainerFunctions = { | |
277 [addon.Locations.Bag] = { | |
278 GetItemId = GetContainerItemID, | |
279 PickupItem = SplitContainerItem, | |
280 IsLocked = function(sourceContainer, sourceSlot) | |
281 return select(3, GetContainerItemInfo(sourceContainer, sourceSlot); | |
282 end, | |
283 }, | |
284 [addon.Locations.Bank] = { | |
285 GetItemId = GetContainerItemID, | |
286 PickupItem = SplitContainerItem, | |
287 IsLocked = function(sourceContainer, sourceSlot) | |
288 return select(3, GetContainerItemInfo(sourceContainer, sourceSlot); | |
289 end, | |
290 }, | |
291 [addon.Locations.Guild] = { | |
292 GetItemId = function(tabId, slotId) | |
293 return addon:GetItemId(GetGuildBankItemLink(tabId, slotId)); | |
294 end, | |
295 PickupItem = SplitGuildBankItem, | |
296 IsLocked = function(sourceContainer, sourceSlot) | |
297 return select(3, GetGuildBankItemInfo(sourceContainer, sourceSlot); | |
298 end, | |
299 }, | |
300 --[[ Even though support is possible, it will require a little more work than just this and there are currently higher priorities | |
301 [addon.Locations.Mailbox] = { | |
302 GetItemId = function(mailIndex, attachmentId) | |
303 return addon:GetItemId(GetInboxItemLink(mailIndex, attachmentId)); | |
304 end, | |
305 PickupItem = TakeInboxItem, | |
306 IsLocked = function() return false; end, | |
307 DoNotDrop = true, | |
308 },]] | |
309 }; | |
310 | |
269 function mod:ProcessMove() | 311 function mod:ProcessMove() |
270 addon:Debug("ProcessMove"); | 312 addon:Debug("ProcessMove"); |
271 | 313 |
272 if #combinedMoves == 0 then | 314 if #combinedMoves == 0 then |
273 addon:Print("Nothing to move."); | 315 addon:Print("Nothing to move."); |
289 -- repeat every few seconds until we're completely done | 331 -- repeat every few seconds until we're completely done |
290 | 332 |
291 local sourceLocationsLocked = {}; | 333 local sourceLocationsLocked = {}; |
292 local targetLocationsLocked = {}; | 334 local targetLocationsLocked = {}; |
293 | 335 |
294 local _GetContainerItemId = GetContainerItemID; | |
295 if movesSource == addon.Locations.Guild then | |
296 _GetContainerItemId = function(tabId, slotId) return addon:GetItemId(GetGuildBankItemLink(tabId, slotId)); end; | |
297 end | |
298 local _GetContainerItemInfo = GetContainerItemInfo; | |
299 if movesSource == addon.Locations.Guild then | |
300 _GetContainerItemInfo = GetGuildBankItemInfo; | |
301 end | |
302 | |
303 local combinedMovesOriginalLength = #combinedMoves; | 336 local combinedMovesOriginalLength = #combinedMoves; |
304 local numCurrentMove = combinedMovesOriginalLength; | 337 local numCurrentMove = combinedMovesOriginalLength; |
305 while numCurrentMove ~= 0 do | 338 while numCurrentMove ~= 0 do |
306 local move = combinedMoves[numCurrentMove]; | 339 local move = combinedMoves[numCurrentMove]; |
307 | 340 |
308 local isSourceLocked = ((sourceLocationsLocked[move.sourceContainer] and sourceLocationsLocked[move.sourceContainer][move.sourceSlot]) or select(3, _GetContainerItemInfo(move.sourceContainer, move.sourceSlot))); | 341 local isSourceLocked = ((sourceLocationsLocked[move.sourceContainer] and sourceLocationsLocked[move.sourceContainer][move.sourceSlot]) or ContainerFunctions[movesSource].IsLocked(move.sourceContainer, move.sourceSlot)); |
309 local isTargetLocked = ((targetLocationsLocked[move.targetContainer] and targetLocationsLocked[move.targetContainer][move.targetSlot]) or select(3, GetContainerItemInfo(move.targetContainer, move.targetSlot))); | 342 -- Target are always the local bags |
343 local isTargetLocked = ((targetLocationsLocked[move.targetContainer] and targetLocationsLocked[move.targetContainer][move.targetSlot]) or ContainerFunctions[addon.Locations.Bag].IsLocked(move.targetContainer, move.targetSlot)); | |
310 | 344 |
311 if move and not isSourceLocked and not isTargetLocked then | 345 if move and not isSourceLocked and not isTargetLocked then |
312 | |
313 addon:Print(("Moving %dx%s."):format(move.num, IdToItemLink(move.itemId))); | 346 addon:Print(("Moving %dx%s."):format(move.num, IdToItemLink(move.itemId))); |
314 | 347 |
315 addon:Debug("Moving %dx%s from (%d,%d) to (%d,%d)", move.num, IdToItemLink(move.itemId), move.sourceContainer, move.sourceSlot, move.targetContainer, move.targetSlot); | 348 addon:Debug("Moving %dx%s from (%d,%d) to (%d,%d)", move.num, IdToItemLink(move.itemId), move.sourceContainer, move.sourceSlot, move.targetContainer, move.targetSlot); |
316 | 349 |
317 if _GetContainerItemId(move.sourceContainer, move.sourceSlot) ~= move.itemId then | 350 if ContainerFunctions[movesSource].GetItemId(move.sourceContainer, move.sourceSlot) ~= move.itemId then |
318 self:Abort("source changed", "Source (" .. move.sourceContainer .. "," .. move.sourceSlot .. ") is not " .. IdToItemLink(move.itemId)); | 351 self:Abort("source changed", "Source (" .. move.sourceContainer .. "," .. move.sourceSlot .. ") is not " .. IdToItemLink(move.itemId)); |
319 return; | 352 return; |
320 end | 353 end |
321 | 354 |
322 -- Pickup stack | 355 -- Pickup stack |
323 if movesSource == addon.Locations.Bank then | 356 ContainerFunctions[movesSource].PickupItem(move.sourceContainer, move.sourceSlot, move.num); |
324 SplitContainerItem(move.sourceContainer, move.sourceSlot, move.num); | |
325 elseif movesSource == addon.Locations.Guild then | |
326 SplitGuildBankItem(move.sourceContainer, move.sourceSlot, move.num); | |
327 end | |
328 | 357 |
329 -- Remember we picked this item up and thus it is now locked | 358 -- Remember we picked this item up and thus it is now locked |
330 if not sourceLocationsLocked[move.sourceContainer] then | 359 if not sourceLocationsLocked[move.sourceContainer] then |
331 sourceLocationsLocked[move.sourceContainer] = {}; | 360 sourceLocationsLocked[move.sourceContainer] = {}; |
332 end | 361 end |
333 sourceLocationsLocked[move.sourceContainer][move.sourceSlot] = true; | 362 sourceLocationsLocked[move.sourceContainer][move.sourceSlot] = true; |
334 | 363 |
335 if movesSource == addon.Locations.Guild or CursorHasItem() then -- CursorHasItem is always false if source is a guild tab | 364 if movesSource ~= addon.Locations.Bank or CursorHasItem() then -- CursorHasItem only works when moving outside of the bank |
336 -- We are moving into our local bags, so the below must check normal | 365 -- We are moving into our local bags, so the below must check normal |
337 local targetItemId = GetContainerItemID(move.targetContainer, move.targetSlot); | 366 local targetItemId = ContainerFunctions[movesSource].get(move.targetContainer, move.targetSlot); |
338 if targetItemId and targetItemId ~= move.itemId then | 367 if targetItemId and targetItemId ~= move.itemId then |
339 self:Abort("target changed", "Target (" .. move.targetContainer .. "," .. move.targetSlot .. ") is not " .. IdToItemLink(move.itemId) .. " nor empty"); | 368 self:Abort("target changed", "Target (" .. move.targetContainer .. "," .. move.targetSlot .. ") is not " .. IdToItemLink(move.itemId) .. " nor empty"); |
340 return; | 369 return; |
341 end | 370 end |
342 | 371 |