diff ReagentMaker.lua @ 46:40d6886d1966

Correct the number of items to craft (the formulae was wrong and has to take the number of item crafted into account)
author contrebasse
date Sat, 30 Apr 2011 01:31:19 +0200
parents 00c2282f073a
children 512660b07eda
line wrap: on
line diff
--- 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]