Mercurial > wow > reagentmaker
comparison 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 |
comparison
equal
deleted
inserted
replaced
109:b5fd4a61ee64 | 110:d60d6b4cab0c |
---|---|
40 -- Wow functions | 40 -- Wow functions |
41 local GetTradeSkillInfo = GetTradeSkillInfo | 41 local GetTradeSkillInfo = GetTradeSkillInfo |
42 local GetNumTradeSkills = GetNumTradeSkills | 42 local GetNumTradeSkills = GetNumTradeSkills |
43 local GetTradeSkillItemLink = GetTradeSkillItemLink | 43 local GetTradeSkillItemLink = GetTradeSkillItemLink |
44 | 44 |
45 function A.numRecipeMakable(reagentIDIfUnique,reagents) | |
46 if reagentIDIfUnique then -- only one reagent | |
47 itemCount = GetItemCount(reagentIDIfUnique) | |
48 if not itemCount then return end | |
49 return math.floor(itemCount/reagents) | |
50 else -- many reagents | |
51 local m | |
52 for _,reagent in pairs(reagents) do | |
53 itemCount = GetItemCount(reagent[1]) | |
54 if not itemCount then return end | |
55 if not m then | |
56 m = math.floor(itemCount/reagent[2]) | |
57 else | |
58 m = math.min(m,math.floor(itemCount/reagent[2])) | |
59 end | |
60 if m==0 then break end | |
61 end | |
62 return m | |
63 end -- if | |
64 end | |
65 | |
45 -- Gives the number of craftable objects | 66 -- Gives the number of craftable objects |
46 --[[ | |
47 function A.numMakable(reagentID) | |
48 -- Look for the recipe to make the item | |
49 local reagentIndex = A.findSkillIndex(reagentID) | |
50 if not reagentIndex then return end | |
51 | |
52 -- Check how many items we can craft | |
53 local skillName, skillType, numReagentMakable, isExpanded, serviceType, numSkillUps = GetTradeSkillInfo(reagentIndex) | |
54 return numReagentMakable, reagentIndex | |
55 end | |
56 --]] | |
57 function A.numMakable(reagentID) | 67 function A.numMakable(reagentID) |
58 -- No recipe | 68 -- No recipe |
59 if not A.data[reagentID] then return 0 end | 69 if not A.data[reagentID] then return 0 end |
60 | 70 |
61 -- Many recipes | 71 -- Many recipes |
62 local n = 0 | 72 local n = 0 |
63 local itemCount | 73 local itemCount |
64 for _,recipe in pairs(A.data[reagentID]) do | 74 for _,recipe in pairs(A.data[reagentID]) do |
65 if recipe[1] then -- only one reagent | 75 n = n + A.numRecipeMakable(recipe[1],recipe[2]) |
66 itemCount = GetItemCount(recipe[1]) | |
67 if not itemCount then return end | |
68 n = n + math.floor(itemCount/recipe[2]) | |
69 else -- many reagents | |
70 local m | |
71 for _,reagent in pairs(recipe[2]) do | |
72 itemCount = GetItemCount(reagent[1]) | |
73 if not itemCount then return end | |
74 if not m then | |
75 m = math.floor(itemCount/reagent[2]) | |
76 else | |
77 m = math.min(m,math.floor(itemCount/reagent[2])) | |
78 end | |
79 if m==0 then break end | |
80 end | |
81 n = n + m | |
82 end -- if | |
83 end -- for | 76 end -- for |
84 return n | 77 return n |
85 end -- function | 78 end -- function |
86 | 79 |
87 -- Find the first tradeskill index of the recipe to make an item | 80 -- Find the first tradeskill index of the recipe to make an item |
88 function A.findSkillIndex(itemID) | 81 function A.findSkillIndex(itemID) |
82 if not itemID then return end | |
89 for i = 1,GetNumTradeSkills() do | 83 for i = 1,GetNumTradeSkills() do |
90 local _, skillType = GetTradeSkillInfo(i) | 84 if select(2,GetTradeSkillInfo(i)) ~= "header" and A.link2ID(GetTradeSkillItemLink(i)) == itemID then |
91 if skillType == "header" then | 85 return i |
92 else | 86 end -- if |
93 local ID = A.link2ID(GetTradeSkillItemLink(i)) | 87 end -- for |
94 if ID and ID == itemID then | 88 end -- function |
95 return i | 89 |
96 end -- if | 90 -- Find the exact tradeskill index of the recipe to make an item |
91 function A.findExactSkillIndex(itemID,recipeName) | |
92 if not itemID or not recipeName then return end | |
93 for i = 1,GetNumTradeSkills() do | |
94 local skillName, skillType = GetTradeSkillInfo(i) | |
95 if skillType ~= "header" and skillName==recipeName and A.link2ID(GetTradeSkillItemLink(i)) == itemID then | |
96 return i | |
97 end -- if | 97 end -- if |
98 end -- for | 98 end -- for |
99 end -- function | 99 end -- function |
100 end -- do | 100 end -- do |
101 | 101 |
102 | 102 |
103 -- Taken from Datastore_Crafts | 103 -- Bypass filters and collpsed headers |
104 -- *** Scanning functions *** | |
105 do | 104 do |
106 local selectedTradeSkillIndex | 105 local selectedTradeSkillIndex |
107 local stateSaved | 106 local stateSaved |
108 local filtersState = {} | 107 local filtersState = {} |
109 local headersState = {} | 108 local headersState = {} |
209 return unique | 208 return unique |
210 end | 209 end |
211 | 210 |
212 --[[ | 211 --[[ |
213 function A.isTradeskillUnique(itemData) | 212 function A.isTradeskillUnique(itemData) |
214 local spellName = itemData[1].spellName | 213 local tradeskillName = itemData[1].tradeskillName |
215 | 214 |
216 -- Check if the item is made by only one recipe. If not, return | 215 -- Check if the item is made by only one recipe. If not, return |
217 if #itemData>1 then | 216 if #itemData>1 then |
218 for _,v in ipairs(itemData) do | 217 for _,v in ipairs(itemData) do |
219 if v.spellName ~= spellName then | 218 if v.tradeskillName ~= tradeskillName then |
220 spellName = nil | 219 tradeskillName = nil |
221 break | 220 break |
222 end | 221 end |
223 end | 222 end |
224 end | 223 end |
225 | 224 |
226 return spellName | 225 return tradeskillName |
227 end | 226 end |
228 --]] | 227 --]] |