diff Modules/Scanner.lua @ 123:ee4672f21586

Restocking from a merchant now considers bonus queue and min crafting queue settings.
author Zerotorescue
date Sun, 16 Jan 2011 00:41:02 +0100
parents 6724bc8eface
children 8460855e3d90
line wrap: on
line diff
--- a/Modules/Scanner.lua	Sat Jan 15 18:52:01 2011 +0100
+++ b/Modules/Scanner.lua	Sun Jan 16 00:41:02 2011 +0100
@@ -342,13 +342,20 @@
 		-- Settings
 		local trackAt = addon:GetOptionByKey(groupName, "trackAtCharacters");
 		local localItemData = addon:GetOptionByKey(groupName, "localItemData");
-		local isRefillEnabled = addon:GetOptionByKey(groupName, "autoRefill");
-		local requiredItems = ((isRestock and addon:GetOptionByKey(groupName, "restockTarget")) or addon:GetOptionByKey(groupName, "minLocalStock"));
+		local requiredItems, bonusQueue, minCraftingQueue, isRefillEnabled;
+		if isRestock then
+			requiredItems = addon:GetOptionByKey(groupName, "restockTarget");
+			bonusQueue = addon:GetOptionByKey(groupName, "bonusQueue");
+			minCraftingQueue = floor( addon:GetOptionByKey(groupName, "minCraftingQueue") * requiredItems ); -- If the minCraftingQueue is 5% and restockTarget is 60, this will result in 3
+		else
+			isRefillEnabled = addon:GetOptionByKey(groupName, "autoRefill");
+			requiredItems = addon:GetOptionByKey(groupName, "minLocalStock");
+		end
 		
 		local isTracked = (trackAt and trackAt[playerName]); -- Is this character interested in this data?
 		local isConsideredLocal = (localItemData and localItemData[location]); -- if this location was checked as local storage, don't refill from it
 		
-		if values.items and isTracked and (isRefillEnabled or isRestock) and not isConsideredLocal then
+		if values.items and isTracked and (isRestock or isRefillEnabled) and not isConsideredLocal then
 			addon:Debug("Scanning |cff00ff00%s|r", groupName);
 			
 			for itemId, _ in pairs(values.items) do
@@ -364,7 +371,13 @@
 					-- Check if we have enough items local (but only do so if this location also has enough available)
 					local missingItems = (requiredItems - currentItemCount);
 					
-					if missingItems > 0 then
+					if isRestock and currentItemCount == 0 and bonusQueue and bonusQueue > 0 then
+						-- If we have none left and the bonus queue is enabled, modify the amount to  be queued
+						
+						missingItems = floor( ( missingItems * ( bonusQueue + 1 ) ) + .5 ); -- round
+					end
+					
+					if missingItems > 0 and (not isRestock or missingItems >= minCraftingQueue) then
 						-- Check how many are available
 						local availableItems = ((containerItem.totalCount) or 0);
 						-- Calculate how many we'll be moving (less missing than available? use missing, otherwise use available)