Mercurial > wow > reagentmaker
comparison utils.lua @ 3:ed0582126cae
The base features semms to work.
| author | contrebasse |
|---|---|
| date | Sat, 02 Apr 2011 01:49:39 +0200 |
| parents | eba26c900e99 |
| children | 250d01156e21 |
comparison
equal
deleted
inserted
replaced
| 2:04c5b817eead | 3:ed0582126cae |
|---|---|
| 1 local addonName, A = ... | 1 local addonName, A = ... |
| 2 | 2 |
| 3 do | 3 -- DEBUG Print |
| 4 -- WoW frames | 4 function A.DEBUG(msg) |
| 5 local DEFAULT_CHAT_FRAME = DEFAULT_CHAT_FRAME | 5 DEFAULT_CHAT_FRAME:AddMessage(msg or "nil",1,0,0) |
| 6 end -- function | |
| 6 | 7 |
| 7 function A.DEBUG(msg) | 8 -- Returns the item ID from its link |
| 8 DEFAULT_CHAT_FRAME:AddMessage(msg or "nil",1,0,0) | 9 function A.link2ID(link) |
| 9 end -- function | 10 return tonumber(select(3,string.find(link or "", "-*:(%d+)[:|].*")) or "") |
| 11 end -- function | |
| 12 | |
| 13 -- Returns the button number for the reagents buttons | |
| 14 function A.buttonNumber(btn) | |
| 15 -- "TradeSkillReagentN" | |
| 16 return tonumber(btn:GetName():sub(-1)) | |
| 10 end | 17 end |
| 11 | 18 |
| 12 do | 19 -- Gives the number of craftable objects |
| 13 -- Lua functions | 20 function A.numMakable(reagentID) |
| 14 local select = select | 21 -- Look for the recipe to make the item |
| 15 local tonumber = tonumber | 22 local reagentIndex = A.findSkillIndex(reagentID) |
| 16 local sfind = string.find | 23 if not reagentIndex then return 0 end |
| 17 | 24 |
| 18 function A.link2ID(link) | 25 -- Check how many items we can craft |
| 19 return tonumber(select(3,sfind(link or "", "-*:(%d+)[:|].*")) or "") | 26 local skillName, skillType, numReagentMakable, isExpanded, serviceType, numSkillUps = GetTradeSkillInfo(reagentIndex) |
| 20 end -- function | 27 return numReagentMakable or 0, reagentIndex |
| 21 end -- do | 28 end |
| 29 | |
| 30 -- Find the first tradeskill index of the recipe to make an item | |
| 31 function A.findSkillIndex(itemID) | |
| 32 for i = 1,GetNumTradeSkills() do | |
| 33 local skillName, skillType, numAvailable, isExpanded, serviceType, numSkillUps = GetTradeSkillInfo(i) | |
| 34 if skillType == "header" then | |
| 35 else | |
| 36 if skillName then | |
| 37 local ID = A.link2ID(GetTradeSkillItemLink(i)) | |
| 38 if ID and ID == itemID then | |
| 39 return i | |
| 40 end -- if | |
| 41 end -- if | |
| 42 end -- if | |
| 43 end -- for | |
| 44 A.DEBUG("Tradeskill not found for "..itemID) | |
| 45 end -- function |
