Mercurial > wow > reagentmaker
view data.lua @ 111:af23986010ef v1.1beta0
Rewrote the main part to clarify things, should have removed some hidden nasty bugs.
author | contrebasse |
---|---|
date | Thu, 02 Jun 2011 23:07:23 +0200 |
parents | d60d6b4cab0c |
children | e6bb47c6d8d6 |
line wrap: on
line source
local addonName, A = ... -- @todo: enchants, elementals, prospecting -- @todo improve scanning A.data = A.CommonData do -- lua functions local print = print local ipairs = ipairs local pairs = pairs local tinsert = tinsert local select = select -- Wow functions local GetNumTradeSkills = GetNumTradeSkills local GetTradeSkillInfo = GetTradeSkillInfo local GetTradeSkillNumReagents = GetTradeSkillNumReagents local GetTradeSkillItemLink = GetTradeSkillItemLink local GetTradeSkillRecipeLink = GetTradeSkillRecipeLink local GetTradeSkillReagentItemLink = GetTradeSkillReagentItemLink local GetTradeSkillReagentInfo = GetTradeSkillReagentInfo local GetTradeSkillNumMade = GetTradeSkillNumMade local GetSpellInfo = GetSpellInfo -- Wow objects local GetTradeSkillLine = GetTradeSkillLine -- the function who scans the tradeskill function A:ScanSimpleRecipes() -- Do not scan while we modify the tradeskill display if A.blockScan then return end -- Check if the tradeskill is loaded -- Has to have recipes and begin with a header local NRecipes = GetNumTradeSkills() if NRecipes==0 or select(2,GetTradeSkillInfo(1))~="header" then return end local tradeskillName = GetTradeSkillLine() -- Check if the pseudo tradeskills have to be added if tradeskillName == GetSpellInfo(25229) then -- Jewelcrafting if not A.ProspectingDataLoaded then for itemID,data in pairs(A.ProspectingData) do A.data[itemID] = data end A.ProspectingDataLoaded = true end elseif tradeskillName == GetSpellInfo(45357) then -- Inscription if not A.MillingDataLoaded then for itemID,data in pairs(A.MillingData) do A.data[itemID] = data end A.MillingDataLoaded = true end end local lastHeader for i = 1,NRecipes do -- skillName, skillType, numAvailable, isExpanded, serviceType, numSkillUps = GetTradeSkillInfo(index) -- serviceType is nil if the recipe creates an item local skillName, skillType, _, _, serviceType = GetTradeSkillInfo(i) if skillType and skillType == "header" then lastHeader = skillName elseif skillType and skillType ~= "header" and serviceType==nil then -- item ID local itemID = A.link2ID(GetTradeSkillItemLink(i)) local numReagents = GetTradeSkillNumReagents(i) local reagentID, reagentCount if numReagents==1 then -- reagent ID reagentID = A.link2ID(GetTradeSkillReagentItemLink(i, 1)) -- reagent number needed reagentCount = select(3,GetTradeSkillReagentInfo(i, 1)) else -- no reagentID -- contains data for the whole reagents reagentCount = {} for j = 1,numReagents do tinsert(reagentCount,{A.link2ID(GetTradeSkillReagentItemLink(i, j)), select(3,GetTradeSkillReagentInfo(i, j))}) end end -- number of reagent created by the recipe local minMade, maxMade = GetTradeSkillNumMade(i) -- recipe link (for tooltips) local recipeLink = GetTradeSkillRecipeLink(i) -- error checking if itemID and (numReagents ~= 1 or (reagentID and reagentCount)) and minMade and maxMade and recipeLink then -- remove unneeded minMade/maxMade if maxMade==minMade then maxMade = nil if minMade==1 then minMade = nil end -- if end -- if -- As we scan multiple times, check if this recipe is already stored local addSpell = true if not A.data[itemID] then A.data[itemID] = {} else for _,v in ipairs(A.data[itemID]) do if v.spellLink==recipeLink then addSpell = nil break end -- if end -- for end -- if -- Cache the data if addSpell then local spell = {reagentID,reagentCount,minMade,maxMade} spell.skillName = skillName spell.tradeskillName = tradeskillName spell.spellLink = recipeLink spell.header = lastHeader tinsert(A.data[itemID],spell) end end -- if end -- if end -- for -- the scanning is complete return true end -- function end -- do