From 01af487dc85b1b581f211ee4eb2d0e7a55558747 Mon Sep 17 00:00:00 2001 From: pschifferer Date: Sat, 28 Mar 2009 03:00:28 +0000 Subject: [PATCH] Fixed the potential count function to only consider inventory items instead of all, and to use a more reliable algorithm for determining the count. --- CauldronUtil.lua | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) 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"); -- 1.7.9.5