Mercurial > wow > inventory
comparison Modules/Mover.lua @ 89:a12d22ef3f39
AceSerializer has been enabled again as it?s used when exporting/importing groups. All other unused libraries are now really removed.
Adjusted debug function to format only when a debug channel is available.
Fixed moving from guild banks, checking if items are locked is different then with banks.
Now unregistering the item locking event so it doesn?t continue to try to move every time an item is switched after the automated cycle has finished. (geeezus, this description is a total overkill)
Fixed item queueing.
Queue all when there?s a group without any items inside no longer crashes.
Removing cached container data after closing a container.
author | Zerotorescue |
---|---|
date | Fri, 07 Jan 2011 22:19:03 +0100 |
parents | f1c035694545 |
children | 31493364b163 |
comparison
equal
deleted
inserted
replaced
88:f1c035694545 | 89:a12d22ef3f39 |
---|---|
42 -- Get a list of items in the source container | 42 -- Get a list of items in the source container |
43 local sourceContents = Scanner:CacheLocation(location, false); | 43 local sourceContents = Scanner:CacheLocation(location, false); |
44 | 44 |
45 local outgoingMoves = {}; | 45 local outgoingMoves = {}; |
46 | 46 |
47 addon:Debug(#queuedMoves .. " moves were queued."); | 47 addon:Debug("%d moves were queued.", #queuedMoves); |
48 | 48 |
49 for _, singleMove in pairs(queuedMoves) do | 49 for _, singleMove in pairs(queuedMoves) do |
50 local sourceItem = sourceContents[singleMove.id]; | 50 local sourceItem = sourceContents[singleMove.id]; |
51 if not sourceItem then | 51 if not sourceItem then |
52 print("Can't move " .. IdToItemLink(singleMove.id) .. ", non-existant in source"); | 52 print("Can't move " .. IdToItemLink(singleMove.id) .. ", non-existant in source"); |
75 end | 75 end |
76 end | 76 end |
77 end | 77 end |
78 end | 78 end |
79 | 79 |
80 addon:Debug(#outgoingMoves .. " outgoing moves are possible."); | 80 addon:Debug("%d outgoing moves are possible.", #outgoingMoves); |
81 | 81 |
82 -- No longer needed | 82 -- No longer needed |
83 table.wipe(queuedMoves); | 83 table.wipe(queuedMoves); |
84 | 84 |
85 -- Process every single outgoing move and find fitting targets | 85 -- Process every single outgoing move and find fitting targets |
107 }); | 107 }); |
108 end | 108 end |
109 end | 109 end |
110 end | 110 end |
111 | 111 |
112 addon:Debug(#emptySlots .. " empty slots are available."); | 112 addon:Debug("%d empty slots are available.", #emptySlots); |
113 | 113 |
114 -- Remember where we're moving from | 114 -- Remember where we're moving from |
115 movesSource = location; | 115 movesSource = location; |
116 | 116 |
117 local backup = 0; | 117 local backup = 0; |
228 | 228 |
229 -- Proceed with the next element (or previous considering we're going from last to first) | 229 -- Proceed with the next element (or previous considering we're going from last to first) |
230 numOutgoingMoves = (numOutgoingMoves - 1); | 230 numOutgoingMoves = (numOutgoingMoves - 1); |
231 end | 231 end |
232 | 232 |
233 addon:Debug(#outgoingMoves .. " moves remaining."); | 233 addon:Debug("%d moves remaining.", #outgoingMoves); |
234 | 234 |
235 backup = (backup + 1); | 235 backup = (backup + 1); |
236 if backup > 1000 then | 236 if backup > 1000 then |
237 dump(nil, outgoingMoves); | 237 dump(nil, outgoingMoves); |
238 table.wipe(outgoingMoves); | 238 table.wipe(outgoingMoves); |
243 end | 243 end |
244 | 244 |
245 -- Reverse table, we need to go through it from last to first because we'll be removing elements, but we don't want the actions to be executed in a different order | 245 -- Reverse table, we need to go through it from last to first because we'll be removing elements, but we don't want the actions to be executed in a different order |
246 combinedMoves = table.reverse(combinedMoves); | 246 combinedMoves = table.reverse(combinedMoves); |
247 | 247 |
248 addon:Debug(#combinedMoves .. " moves should be possible."); | 248 addon:Debug("%d moves should be possible.", #combinedMoves); |
249 | 249 |
250 -- No longer needed | 250 -- No longer needed |
251 table.wipe(emptySlots); | 251 table.wipe(emptySlots); |
252 | 252 |
253 self:ProcessMove(); | 253 self:ProcessMove(); |
280 local targetLocationsLocked = {}; | 280 local targetLocationsLocked = {}; |
281 | 281 |
282 local _GetContainerItemId = GetContainerItemID; | 282 local _GetContainerItemId = GetContainerItemID; |
283 if movesSource == addon.Locations.Guild then | 283 if movesSource == addon.Locations.Guild then |
284 _GetContainerItemId = function(tabId, slotId) return addon:GetItemID(GetGuildBankItemLink(tabId, slotId)); end; | 284 _GetContainerItemId = function(tabId, slotId) return addon:GetItemID(GetGuildBankItemLink(tabId, slotId)); end; |
285 end | |
286 local _GetContainerItemInfo = GetContainerItemInfo; | |
287 if movesSource == addon.Locations.Guild then | |
288 _GetContainerItemInfo = GetGuildBankItemInfo; | |
285 end | 289 end |
286 | 290 |
287 local combinedMovesOriginalLength = #combinedMoves; | 291 local combinedMovesOriginalLength = #combinedMoves; |
288 local numCurrentMove = combinedMovesOriginalLength; | 292 local numCurrentMove = combinedMovesOriginalLength; |
289 while numCurrentMove ~= 0 do | 293 while numCurrentMove ~= 0 do |
290 local move = combinedMoves[numCurrentMove]; | 294 local move = combinedMoves[numCurrentMove]; |
291 | 295 |
292 local isSourceLocked = ((sourceLocationsLocked[move.sourceContainer] and sourceLocationsLocked[move.sourceContainer][move.sourceSlot]) or select(3, GetContainerItemInfo(move.sourceContainer, move.sourceSlot))); | 296 local isSourceLocked = ((sourceLocationsLocked[move.sourceContainer] and sourceLocationsLocked[move.sourceContainer][move.sourceSlot]) or select(3, _GetContainerItemInfo(move.sourceContainer, move.sourceSlot))); |
293 local isTargetLocked = ((targetLocationsLocked[move.targetContainer] or targetLocationsLocked[move.targetContainer][move.targetSlot]) or select(3, GetContainerItemInfo(move.targetContainer, move.targetSlot))); | 297 local isTargetLocked = ((targetLocationsLocked[move.targetContainer] and targetLocationsLocked[move.targetContainer][move.targetSlot]) or select(3, GetContainerItemInfo(move.targetContainer, move.targetSlot))); |
294 | 298 |
295 -- sourceContainer, sourceSlot, targetContainer, targetSlot, itemId, num | 299 if move and not isSourceLocked and not isTargetLocked then |
296 if move and isSourceLocked and isTargetLocked then | |
297 | 300 |
298 print(("Moving %dx%s."):format(move.num, IdToItemLink(move.itemId))); | 301 print(("Moving %dx%s."):format(move.num, IdToItemLink(move.itemId))); |
299 | 302 |
300 addon:Debug(("Moving %dx%s from (%d,%d) to (%d,%d)"):format(move.num, IdToItemLink(move.itemId), move.sourceContainer, move.sourceSlot, move.targetContainer, move.targetSlot)); | 303 addon:Debug("Moving %dx%s from (%d,%d) to (%d,%d)", move.num, IdToItemLink(move.itemId), move.sourceContainer, move.sourceSlot, move.targetContainer, move.targetSlot); |
301 | 304 |
302 if _GetContainerItemId(move.sourceContainer, move.sourceSlot) ~= move.itemId then | 305 if _GetContainerItemId(move.sourceContainer, move.sourceSlot) ~= move.itemId then |
303 self:Abort("source changed", "Source (" .. move.sourceContainer .. "," .. move.sourceSlot .. ") is not " .. IdToItemLink(move.itemId)); | 306 self:Abort("source changed", "Source (" .. move.sourceContainer .. "," .. move.sourceSlot .. ") is not " .. IdToItemLink(move.itemId)); |
304 return; | 307 return; |
305 end | 308 end |
344 | 347 |
345 -- Proceed with the next element (or previous considering we're going from last to first) | 348 -- Proceed with the next element (or previous considering we're going from last to first) |
346 numCurrentMove = (numCurrentMove - 1); | 349 numCurrentMove = (numCurrentMove - 1); |
347 end | 350 end |
348 | 351 |
349 addon:Debug((combinedMovesOriginalLength - #combinedMoves) .. " moves processed. " .. #combinedMoves .. " moves remaining."); | 352 addon:Debug("%d moves processed. %d moves remaining.", (combinedMovesOriginalLength - #combinedMoves), #combinedMoves); |
350 | 353 |
351 if #combinedMoves == 0 then | 354 if #combinedMoves == 0 then |
352 print("Finished."); | 355 print("Finished."); |
353 | 356 |
354 self:Abort(); | 357 self:Abort(); |
358 end | 361 end |
359 | 362 |
360 local tmrProcessNext; | 363 local tmrProcessNext; |
361 function mod:ITEM_LOCK_CHANGED() | 364 function mod:ITEM_LOCK_CHANGED() |
362 self:CancelTimer(tmrProcessNext, true); -- silent | 365 self:CancelTimer(tmrProcessNext, true); -- silent |
363 tmrProcessNext = self:ScheduleTimer("ProcessMove", 0.5); | 366 tmrProcessNext = self:ScheduleTimer("ProcessMove", .5); |
364 end | 367 end |
365 | 368 |
366 function IdToItemLink(itemId) | 369 function IdToItemLink(itemId) |
367 local itemLink = select(2, GetItemInfo(itemId)); | 370 local itemLink = select(2, GetItemInfo(itemId)); |
368 itemLink = itemLink or "Unknown (" .. itemId .. ")"; | 371 itemLink = itemLink or "Unknown (" .. itemId .. ")"; |
375 end | 378 end |
376 end | 379 end |
377 | 380 |
378 function mod:Abort(simple, debugMsg) | 381 function mod:Abort(simple, debugMsg) |
379 if debugMsg then | 382 if debugMsg then |
380 addon:Debug("Aborting:" .. debugMsg); | 383 addon:Debug("Aborting:%s", debugMsg); |
381 end | 384 end |
382 if simple then | 385 if simple then |
383 print("|cffff0000Aborting: " .. simple .. ".|r"); | 386 print("|cffff0000Aborting: " .. simple .. ".|r"); |
384 end | 387 end |
385 table.wipe(combinedMoves); | 388 table.wipe(combinedMoves); |
386 movesSource = nil; | 389 movesSource = nil; |
387 | 390 |
388 -- Stop timer | 391 -- Stop timer |
389 self:UnregisterEvent("BAG_UPDATE"); | 392 self:UnregisterEvent("ITEM_LOCK_CHANGED"); |
390 self:CancelTimer(tmrProcessNext, true); -- silent | 393 self:CancelTimer(tmrProcessNext, true); -- silent |
391 | 394 |
392 self:UnregisterEvent("UI_ERROR_MESSAGE"); | 395 self:UnregisterEvent("UI_ERROR_MESSAGE"); |
393 end | 396 end |
394 | 397 |