Quantcast

Fixed the potential count function to only consider inventory items instead of all, and to use a more

pschifferer [03-28-09 - 03:00]
Fixed the potential count function to only consider inventory items instead of all, and to use a more
reliable algorithm for determining the count.
Filename
CauldronUtil.lua
diff --git a/CauldronUtil.lua b/CauldronUtil.lua
index 15c0129..1c345f8 100644
--- a/CauldronUtil.lua
+++ b/CauldronUtil.lua
@@ -28,28 +28,45 @@ end
 function Cauldron:GetPotentialCraftCount(skillInfo)
 	self:debug("GetPotentialCraftCount enter");

-	local count = 999999;
+	local count = 0;
+
+	-- a place to store count values
+	local c = {};

 	-- iterate over the reagent list and find out how many can be made for each reagent count;
 	-- the lowest value is the potential amount craftable; only count a skill if it has more
-	-- than one reagent
+	-- than one reagent, and is a key reagent
 	if #skillInfo.reagents > 1 then
 		for i,rinfo in ipairs(skillInfo.reagents) do
 			-- only count "key" reagents
 			if rinfo.key then
 				local counts = Cauldron:ReagentCount(rinfo.name);
-				local makeable = math.floor(counts.total / rinfo.numRequired);
+				local makeable = math.floor(counts.has / rinfo.numRequired);
+
+				table.insert(c, makeable);

+				--[[
 				if (makeable > 0) and (count > 0) and (makeable < count) then
 					count = makeable;
 				end
+				--]]
 			end
 		end
+
+		-- sort the table
+		table.sort(c);
+
+		-- if there are any results, get the first, because it will be the lowest number
+		if #c > 0 then
+			count = c[1];
+		end
 	end

+	--[[
 	if count == 999999 then
 		count = 0;
 	end
+	--]]

 	self:debug("GetPotentialCraftCount exit");