# HG changeset patch # User contrebasse # Date 1304119879 -7200 # Node ID 40d6886d19665e403a86a46ee398a5c1f16720e0 # Parent 4e6492b19f4c3ab28d5c9dd4526e205b519f55a9 Correct the number of items to craft (the formulae was wrong and has to take the number of item crafted into account) diff -r 4e6492b19f4c -r 40d6886d1966 ReagentMaker.lua --- a/ReagentMaker.lua Sat Apr 30 00:53:03 2011 +0200 +++ b/ReagentMaker.lua Sat Apr 30 01:31:19 2011 +0200 @@ -113,7 +113,8 @@ local reagentRecipeIndex = A.buttonNumber(btn) -- ID of the reagent we want to craft - local reagentID = A.link2ID(GetTradeSkillReagentItemLink(GetTradeSkillSelectionIndex(), reagentRecipeIndex)) + local recipeIndex = GetTradeSkillSelectionIndex() + local reagentID = A.link2ID(GetTradeSkillReagentItemLink(recipeIndex, reagentRecipeIndex)) -- Continue only if the reagent is known if not reagentID or not A.data[reagentID] then return end @@ -126,7 +127,7 @@ return end if numMakable>0 then - A.craft(reagentID,reagentRecipeIndex,reagentIndex,numMakable,chooseNumberToCraft) + A.craft(recipeIndex,reagentRecipeIndex,reagentIndex,numMakable,chooseNumberToCraft) return end @@ -155,17 +156,20 @@ end -- Craft the reagent of an item, given it's position in the recipe -function A.craft(reagentID,reagentRecipeIndex,reagentIndex,numReagentMakable,chooseNumber) +function A.craft(recipeIndex,reagentRecipeIndex,reagentIndex,numReagentMakable,chooseNumber) -- Look at how many we need to make one item for the selected recipe local numToMake = 1 - local selectedIndex = GetTradeSkillSelectionIndex() - local skillName, skillType, numAvailable, isExpanded, serviceType, numSkillUps = GetTradeSkillInfo(selectedIndex) - local reagentName, reagentTexture, reagentCount, playerReagentCount = GetTradeSkillReagentInfo(selectedIndex, reagentRecipeIndex) + local _, _, reagentCount, playerReagentCount = GetTradeSkillReagentInfo(recipeIndex, reagentRecipeIndex) -- make enough reagents to craft one more item - numToMake = math.min(reagentCount*(1+numAvailable) - playerReagentCount,numReagentMakable) + numToMake = math.min(math.floor(playerReagentCount/reagentCount+1)*reagentCount-playerReagentCount,numReagentMakable) + -- take into account that some recipe craft more than one item + -- use the mean between min and max, but make at least one... + local minMade, maxMade = GetTradeSkillNumMade(reagentIndex) + numToMake = math.max(math.floor(2*numToMake/(maxMade+minMade)),1) + -- Choose number or craft directly - if chooseNumber and numReagentMakable>1 then + if chooseNumber then -- the dialog window is linked to the reagent button local btn = _G["TradeSkillReagent"..reagentRecipeIndex]