changeset 82:f885805da5d6

Added options to toggle the automatic refilling. This defaults to true. Normalized property amount names; a move has a ?num? that must be moved and a location has a ?count? indicating the amount of items at that slot. Target/source item verification should now be working properly for guilds. When ?bank? is included in the local item count, we will skip trying to auto refill from this.
author Zerotorescue
date Thu, 06 Jan 2011 10:48:56 +0100
parents 58617c7827fa
children 6b60f7a1410c
files Config.lua Core.lua Mover.lua Scanner.lua
diffstat 4 files changed, 69 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/Config.lua	Thu Jan 06 01:01:25 2011 +0100
+++ b/Config.lua	Thu Jan 06 10:48:56 2011 +0100
@@ -512,6 +512,20 @@
 							desc = "Show an alert when an item in this group gets below the local minimum stock threshold.",
 							arg = "overrideAlertBelowLocalMinimum",
 						},
+						overrideAutoRefill = {
+							order = 17,
+							type = "toggle",
+							name = "Override auto refill",
+							desc = "Allows you to override wether you want to automatically refill items when below the minimum local stock.",
+							arg = "autoRefill",
+						},
+						autoRefill = {
+							order = 18,
+							type = "toggle",
+							name = "Auto refill from (guild) bank",
+							desc = "Automatically refill items from the bank (unless this is included in the local count) or guild bank when below the minimum local stock.",
+							arg = "overrideAutoRefill",
+						},
 						
 						overrideMinGlobalStock = {
 							order = 20,
@@ -1463,6 +1477,14 @@
 						get = function() return addon.db.profile.defaults.alertBelowLocalMinimum; end,
 						set = function(i, v) addon.db.profile.defaults.alertBelowLocalMinimum = v; end,
 					},
+					autoRefill = {
+						order = 12,
+						type = "toggle",
+						name = "Auto refill from (guild) bank",
+						desc = "Automatically refill items from the bank (unless this is included in the local count) or guild bank when below the minimum local stock.",
+						get = function() return addon.db.profile.defaults.autoRefill; end,
+						set = function(i, v) addon.db.profile.defaults.autoRefill = v; end,
+					},
 					minGlobalStock = {
 						order = 20,
 						type = "range",
--- a/Core.lua	Thu Jan 06 01:01:25 2011 +0100
+++ b/Core.lua	Thu Jan 06 10:48:56 2011 +0100
@@ -34,6 +34,7 @@
 				craftingAddon = "AdvancedTradeSkillWindow",
 				minLocalStock = 20,
 				alertBelowLocalMinimum = true,
+				autoRefill = true,
 				minGlobalStock = 60,
 				alertBelowGlobalMinimum = true,
 				summaryThresholdShow = 10,
--- a/Mover.lua	Thu Jan 06 01:01:25 2011 +0100
+++ b/Mover.lua	Thu Jan 06 10:48:56 2011 +0100
@@ -28,12 +28,14 @@
 	
 	local outgoingMoves = {};
 
+	addon:Debug(#queuedMoves .. " moves were queued.");
+	
 	for _, singleMove in pairs(queuedMoves) do
 		local sourceItem = sourceContents[singleMove.id];
 		if not sourceItem then
 			print("Can't move " .. IdToItemLink(singleMove.id) .. ", non-existant in source");
 		else
-			-- We want to move the smallest stacks first to keep stuff pretty
+			-- 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)
 				return a.count < b.count;
 			end);
@@ -44,9 +46,9 @@
 				
 				table.insert(outgoingMoves, {
 					itemId = singleMove.id,
+					num = movingNum,
 					container = itemLocation.container,
 					slot = itemLocation.slot,
-					count = movingNum,
 				});
 				
 				singleMove.num = (singleMove.num - movingNum);
@@ -58,6 +60,8 @@
 			end
 		end
 	end
+
+	addon:Debug(#outgoingMoves .. " outgoing moves are possible.");
 	
 	-- No longer needed
 	table.wipe(queuedMoves);
@@ -78,7 +82,7 @@
 	for bagId = start, stop do
 		-- Go through all our slots
 		for slotId = 1, GetContainerNumSlots(bagId) do
-			local itemId = GetContainerItemID(bagId, slotId);
+			local itemId = GetContainerItemID(bagId, slotId); -- we're scanning our local bags here, so no need to get messy with guild bank support
 			
 			if not itemId then
 				table.insert(emptySlots, {
@@ -88,6 +92,8 @@
 			end
 		end
 	end
+
+	addon:Debug(#emptySlots .. " empty slots are available.");
 	
 	-- Remember where we're moving from
 	movesSource = location;
@@ -110,26 +116,26 @@
 					if not firstAvailableSlot then
 						print("Bags are full. Skipping " .. IdToItemLink(outgoingMove.itemId) .. ".");
 						
-						outgoingMove.itemId = nil;
+						outgoingMove.itemId = nil; -- remove this record from the outgoingMoves-table
 					else
 						table.insert(combinedMoves, {
+							itemId = outgoingMove.itemId,
+							num = outgoingMove.num,
 							sourceContainer = outgoingMove.container,
 							sourceSlot = outgoingMove.slot,
 							targetContainer = firstAvailableSlot.container,
 							targetSlot = firstAvailableSlot.slot,
-							itemId = outgoingMove.itemId,
-							num = outgoingMove.count,
 						});
 						
 						-- We filled an empty slot so the target contents now has one more item,
 						-- make a new instance of the ItemMove class so any additional items with this id can be stacked on top of it
 						local itemMove = addon.ContainerItem:New();
-						itemMove:AddLocation(firstAvailableSlot.container, firstAvailableSlot.slot, outgoingMove.count);
+						itemMove:AddLocation(firstAvailableSlot.container, firstAvailableSlot.slot, outgoingMove.num);
 						targetContents[outgoingMove.itemId] = itemMove;
 						
 						table.remove(emptySlots, 1); -- no longer empty
 						
-						outgoingMove.count = 0; -- nothing remaining - sanity check
+						outgoingMove.num = 0; -- nothing remaining - sanity check
 						outgoingMove.itemId = nil; -- remove this record from the outgoingMoves-table
 					end
 				else
@@ -142,24 +148,24 @@
 					end);
 					
 					for _, itemLocation in pairs(targetItem.locations) do
-						if itemLocation.count < itemStackCount and outgoingMove.count > 0 then
+						if itemLocation.count < itemStackCount and outgoingMove.num > 0 then
 							-- Check if this stack isn't already full (and we still need to move this item)
 							
 							local remainingSpace = (itemStackCount - itemLocation.count);
-							if remainingSpace > outgoingMove.count then
+							if remainingSpace > outgoingMove.num then
 								-- Enough room to move this entire stack
 								-- Deposit this item and then forget this outgoing move as everything in it was processed
 								
 								table.insert(combinedMoves, {
+									itemId = outgoingMove.itemId,
+									num = outgoingMove.num,
 									sourceContainer = outgoingMove.container,
 									sourceSlot = outgoingMove.slot,
 									targetContainer = itemLocation.container,
 									targetSlot = itemLocation.slot,
-									itemId = outgoingMove.itemId,
-									num = outgoingMove.count,
 								});
 								
-								itemLocation.count = (itemLocation.count + outgoingMove.count);
+								itemLocation.count = (itemLocation.count + outgoingMove.num);
 								outgoingMove.count = 0; -- nothing remaining
 								outgoingMove.itemId = nil; -- remove this record from the outgoingMoves-table
 								break; -- stop the locations-loop
@@ -167,22 +173,22 @@
 								-- Deposit this item but don't remove the outgoing move as there are some items left to move
 								
 								table.insert(combinedMoves, {
+									itemId = outgoingMove.itemId,
+									num = outgoingMove.num,
 									sourceContainer = outgoingMove.container,
 									sourceSlot = outgoingMove.slot,
 									targetContainer = itemLocation.container,
 									targetSlot = itemLocation.slot,
-									itemId = outgoingMove.itemId,
-									num = outgoingMove.count,
 								});
 								
 								-- The target will be full when we complete, but the source will still have remaining items left to be moved
 								itemLocation.count = itemStackCount;
-								outgoingMove.count = (outgoingMove.count - remainingSpace);
+								outgoingMove.num = (outgoingMove.num - remainingSpace);
 							end
 						end
 					end
 					
-					if outgoingMove.count > 0 then
+					if outgoingMove.num > 0 then
 						-- We went through all matching items and checked their stack sizes if we could move this there, no room available
 						-- So forget about the target item (even though it may just have full locations, these are useless anyway) and the next loop move it onto an empty slot
 						targetItem = nil;
@@ -206,14 +212,15 @@
 			numOutgoingMoves = (numOutgoingMoves - 1);
 		end
 	end
+
+	addon:Debug(#combinedMoves .. " moves should be possible.");
 	
 	-- No longer needed
 	table.wipe(emptySlots);
 	
 	self:ProcessMove();
 	
-	self:RegisterEvent("BAG_UPDATE");
-	
+	-- Even though we aren't completely done yet, allow requeueing
 	onFinish();
 end
 
@@ -251,6 +258,7 @@
 		return;
 	end
 	
+	self:RegisterEvent("BAG_UPDATE");
 	self:RegisterEvent("UI_ERROR_MESSAGE");
 	
 	-- combinedMoves now has all moves in it (source -> target)
@@ -262,9 +270,17 @@
 	local targetLocationsLocked = {};
 	
 	-- 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
-    combinedMoves = table.reverse(combinedMoves);
+	combinedMoves = table.reverse(combinedMoves);
 	
-	local numCurrentMove = #combinedMoves;
+	local GetContainerItemID;
+	if movesSource == addon.Locations.Guild then
+		GetContainerItemID = GetGuildBankItemLink;
+	else
+		GetContainerItemID = GetContainerItemID;
+	end
+    
+	local combinedMovesOriginalLength = #combinedMoves;
+	local numCurrentMove = combinedMovesOriginalLength;
 	while numCurrentMove ~= 0 do
 		local move = combinedMoves[numCurrentMove];
 		
@@ -278,7 +294,6 @@
 			
 			if GetContainerItemID(move.sourceContainer, move.sourceSlot) ~= move.itemId then
 				self:Abort("source changed", "Source (" .. move.sourceContainer .. "," .. move.sourceSlot .. ") is not " .. IdToItemLink(move.itemId));
-				
 				return;
 			end
 			
@@ -301,7 +316,7 @@
 					return;
 				end
 				
-				-- And drop it
+				-- And drop it (this is always a local bag so no need to do any guild-checks)
 				PickupContainerItem(move.targetContainer, move.targetSlot);
 				
 				-- Remember we dropped an item here and thus this is now locked
@@ -322,6 +337,8 @@
 		numCurrentMove = (numCurrentMove - 1);
 	end
 	
+	addon:Debug((combinedMovesOriginalLength - #combinedMoves) .. " moves processed. " .. #combinedMoves .. " moves remaining.");
+	
 	if #combinedMoves == 0 then
 		print("Finished.");
 		
--- a/Scanner.lua	Thu Jan 06 01:01:25 2011 +0100
+++ b/Scanner.lua	Thu Jan 06 10:48:56 2011 +0100
@@ -78,7 +78,7 @@
 				-- If there is actually an item in this slot
 				
 			local itemLink = GetGuildBankItemLink(tabId, slotId);
-			local itemId = itemLink and GetItemId(itemLink);
+			local itemId = itemLink and GetItemID(itemLink);
 			local itemCount = itemLink and select(2, GetGuildBankItemInfo(tabId, slotId));
 				
 			if itemLink and itemId and itemCount and itemCount > 0 then
@@ -99,7 +99,7 @@
 			slotId = (slotId - 1);
 		end
 	else
-		error("Invalid location provided for the local _GetItemCount. Must be Bank or Guild.");
+		error("Invalid location provided for CacheLocation. Must be Bank or Guild.");
 	end
 	
 	if not remember then
@@ -125,8 +125,9 @@
 	-- Go through all groups
 	for groupName, values in pairs(addon.db.profile.groups) do
 		local trackAt = addon:GetOptionByKey(groupName, "trackAtCharacters");
+		local localItemData = self:GetOptionByKey(groupName, "localItemData");
 		
-		if values.items and trackAt[playerName] then
+		if values.items and trackAt[playerName] and addon:GetOptionByKey(groupName, "autoRefill") and (location ~= addon.Locations.Bank or not localItemData or not localItemData["Bank"]) then
 			-- Is this character interested in this data?
 			
 			local minLocalStock = addon:GetOptionByKey(groupName, "minLocalStock");
@@ -167,6 +168,8 @@
 			timeout = 0,
 			whileDead = 1,
 			hideOnEscape = 1,
+			exclusive = 1,
+			enterClicksFirstButton = 1,
 		};
 		StaticPopup_Show("InventoriumRefill");
 	end