Mercurial > wow > reagentmaker
comparison 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 |
comparison
equal
deleted
inserted
replaced
45:4e6492b19f4c | 46:40d6886d1966 |
---|---|
111 | 111 |
112 -- Index of the reagent in the recipe, taken from the button name | 112 -- Index of the reagent in the recipe, taken from the button name |
113 local reagentRecipeIndex = A.buttonNumber(btn) | 113 local reagentRecipeIndex = A.buttonNumber(btn) |
114 | 114 |
115 -- ID of the reagent we want to craft | 115 -- ID of the reagent we want to craft |
116 local reagentID = A.link2ID(GetTradeSkillReagentItemLink(GetTradeSkillSelectionIndex(), reagentRecipeIndex)) | 116 local recipeIndex = GetTradeSkillSelectionIndex() |
117 local reagentID = A.link2ID(GetTradeSkillReagentItemLink(recipeIndex, reagentRecipeIndex)) | |
117 | 118 |
118 -- Continue only if the reagent is known | 119 -- Continue only if the reagent is known |
119 if not reagentID or not A.data[reagentID] then return end | 120 if not reagentID or not A.data[reagentID] then return end |
120 | 121 |
121 -- If only one recipe is known for the reagent, use it | 122 -- If only one recipe is known for the reagent, use it |
124 if not numMakable then | 125 if not numMakable then |
125 A.Error("The recipe to make the reagent seems to be hidden, it is not makable.") | 126 A.Error("The recipe to make the reagent seems to be hidden, it is not makable.") |
126 return | 127 return |
127 end | 128 end |
128 if numMakable>0 then | 129 if numMakable>0 then |
129 A.craft(reagentID,reagentRecipeIndex,reagentIndex,numMakable,chooseNumberToCraft) | 130 A.craft(recipeIndex,reagentRecipeIndex,reagentIndex,numMakable,chooseNumberToCraft) |
130 return | 131 return |
131 end | 132 end |
132 | 133 |
133 -- If we can make the item needed to make the reagent, open a window to make it | 134 -- If we can make the item needed to make the reagent, open a window to make it |
134 -- one step recursion, enables to mill to create an ink | 135 -- one step recursion, enables to mill to create an ink |
153 DoTradeSkill(owner.ReagentMaker_reagentIndex,tonumber(split)) | 154 DoTradeSkill(owner.ReagentMaker_reagentIndex,tonumber(split)) |
154 owner.ReagentMaker_reagentIndex = nil | 155 owner.ReagentMaker_reagentIndex = nil |
155 end | 156 end |
156 | 157 |
157 -- Craft the reagent of an item, given it's position in the recipe | 158 -- Craft the reagent of an item, given it's position in the recipe |
158 function A.craft(reagentID,reagentRecipeIndex,reagentIndex,numReagentMakable,chooseNumber) | 159 function A.craft(recipeIndex,reagentRecipeIndex,reagentIndex,numReagentMakable,chooseNumber) |
159 -- Look at how many we need to make one item for the selected recipe | 160 -- Look at how many we need to make one item for the selected recipe |
160 local numToMake = 1 | 161 local numToMake = 1 |
161 local selectedIndex = GetTradeSkillSelectionIndex() | 162 local _, _, reagentCount, playerReagentCount = GetTradeSkillReagentInfo(recipeIndex, reagentRecipeIndex) |
162 local skillName, skillType, numAvailable, isExpanded, serviceType, numSkillUps = GetTradeSkillInfo(selectedIndex) | |
163 local reagentName, reagentTexture, reagentCount, playerReagentCount = GetTradeSkillReagentInfo(selectedIndex, reagentRecipeIndex) | |
164 -- make enough reagents to craft one more item | 163 -- make enough reagents to craft one more item |
165 numToMake = math.min(reagentCount*(1+numAvailable) - playerReagentCount,numReagentMakable) | 164 numToMake = math.min(math.floor(playerReagentCount/reagentCount+1)*reagentCount-playerReagentCount,numReagentMakable) |
166 | 165 |
166 -- take into account that some recipe craft more than one item | |
167 -- use the mean between min and max, but make at least one... | |
168 local minMade, maxMade = GetTradeSkillNumMade(reagentIndex) | |
169 numToMake = math.max(math.floor(2*numToMake/(maxMade+minMade)),1) | |
170 | |
167 -- Choose number or craft directly | 171 -- Choose number or craft directly |
168 if chooseNumber and numReagentMakable>1 then | 172 if chooseNumber then |
169 -- the dialog window is linked to the reagent button | 173 -- the dialog window is linked to the reagent button |
170 local btn = _G["TradeSkillReagent"..reagentRecipeIndex] | 174 local btn = _G["TradeSkillReagent"..reagentRecipeIndex] |
171 | 175 |
172 -- Store info to be able to run the function later | 176 -- Store info to be able to run the function later |
173 btn.ReagentMaker_reagentIndex = reagentIndex | 177 btn.ReagentMaker_reagentIndex = reagentIndex |