Mercurial > wow > reagentmaker
diff utils.lua @ 110:d60d6b4cab0c
Tradeskill in external window should now be functional
author | contrebasse |
---|---|
date | Thu, 02 Jun 2011 18:23:42 +0200 |
parents | 618163a6d970 |
children | af23986010ef |
line wrap: on
line diff
--- a/utils.lua Thu Jun 02 14:12:49 2011 +0200 +++ b/utils.lua Thu Jun 02 18:23:42 2011 +0200 @@ -42,18 +42,28 @@ local GetNumTradeSkills = GetNumTradeSkills local GetTradeSkillItemLink = GetTradeSkillItemLink + function A.numRecipeMakable(reagentIDIfUnique,reagents) + if reagentIDIfUnique then -- only one reagent + itemCount = GetItemCount(reagentIDIfUnique) + if not itemCount then return end + return math.floor(itemCount/reagents) + else -- many reagents + local m + for _,reagent in pairs(reagents) do + itemCount = GetItemCount(reagent[1]) + if not itemCount then return end + if not m then + m = math.floor(itemCount/reagent[2]) + else + m = math.min(m,math.floor(itemCount/reagent[2])) + end + if m==0 then break end + end + return m + end -- if + end + -- Gives the number of craftable objects - --[[ - function A.numMakable(reagentID) - -- Look for the recipe to make the item - local reagentIndex = A.findSkillIndex(reagentID) - if not reagentIndex then return end - - -- Check how many items we can craft - local skillName, skillType, numReagentMakable, isExpanded, serviceType, numSkillUps = GetTradeSkillInfo(reagentIndex) - return numReagentMakable, reagentIndex - end - --]] function A.numMakable(reagentID) -- No recipe if not A.data[reagentID] then return 0 end @@ -62,46 +72,35 @@ local n = 0 local itemCount for _,recipe in pairs(A.data[reagentID]) do - if recipe[1] then -- only one reagent - itemCount = GetItemCount(recipe[1]) - if not itemCount then return end - n = n + math.floor(itemCount/recipe[2]) - else -- many reagents - local m - for _,reagent in pairs(recipe[2]) do - itemCount = GetItemCount(reagent[1]) - if not itemCount then return end - if not m then - m = math.floor(itemCount/reagent[2]) - else - m = math.min(m,math.floor(itemCount/reagent[2])) - end - if m==0 then break end - end - n = n + m - end -- if + n = n + A.numRecipeMakable(recipe[1],recipe[2]) end -- for return n end -- function -- Find the first tradeskill index of the recipe to make an item function A.findSkillIndex(itemID) + if not itemID then return end for i = 1,GetNumTradeSkills() do - local _, skillType = GetTradeSkillInfo(i) - if skillType == "header" then - else - local ID = A.link2ID(GetTradeSkillItemLink(i)) - if ID and ID == itemID then - return i - end -- if + if select(2,GetTradeSkillInfo(i)) ~= "header" and A.link2ID(GetTradeSkillItemLink(i)) == itemID then + return i + end -- if + end -- for + end -- function + + -- Find the exact tradeskill index of the recipe to make an item + function A.findExactSkillIndex(itemID,recipeName) + if not itemID or not recipeName then return end + for i = 1,GetNumTradeSkills() do + local skillName, skillType = GetTradeSkillInfo(i) + if skillType ~= "header" and skillName==recipeName and A.link2ID(GetTradeSkillItemLink(i)) == itemID then + return i end -- if end -- for end -- function end -- do --- Taken from Datastore_Crafts --- *** Scanning functions *** +-- Bypass filters and collpsed headers do local selectedTradeSkillIndex local stateSaved @@ -211,18 +210,18 @@ --[[ function A.isTradeskillUnique(itemData) - local spellName = itemData[1].spellName + local tradeskillName = itemData[1].tradeskillName -- Check if the item is made by only one recipe. If not, return if #itemData>1 then for _,v in ipairs(itemData) do - if v.spellName ~= spellName then - spellName = nil + if v.tradeskillName ~= tradeskillName then + tradeskillName = nil break end end end - return spellName + return tradeskillName end --]]