diff --git a/oregen-manager.lua b/oregen-manager.lua index fedb8fc..9a74d32 100644 --- a/oregen-manager.lua +++ b/oregen-manager.lua @@ -251,11 +251,19 @@ function getNumCraftable (ingredients, current_stock) return result end -function craftRecipe (ticker, recipe, count) - if count == nil then count = 1 end +function adjustStock (current_stock, recipe, count) + for _, ingredient in ipairs(recipe.ingredients) do + item, i_count = ingredient[1], ingredient[2] + current_stock[item] = current_stock[item] - (i_count * count) + end +end + +function craftRecipe (ticker, recipe, current_stock) + local count = getNumCraftable(recipe.ingredients, current_stock) if recipe.limit ~= nil then count = math.min(count, recipe.limit) end + adjustStock(current_stock, recipe, count) local createRequest createRequest = function (recipe, i) if i == nil then i = 1 end @@ -297,8 +305,7 @@ function run (ticker, export_storage, current_modes) if mode[1] == "recipe" then -- make as many recipes as you can with current stock local recipe = RECIPES[item] - local count = getNumCraftable(recipe.ingredients, stock_amounts) - craftRecipe(ticker, recipe, count) + craftRecipe(ticker, recipe, stock_amounts) elseif mode[1] == "export" then local export_amt = export_amounts[item] if export_amt == nil then export_amt = 0 end