Mercurial > wow > reagentmaker
comparison data.lua @ 117:e6bb47c6d8d6
Hopefuly fixed ticket #1
author | contrebasse |
---|---|
date | Sun, 19 Jun 2011 13:04:37 +0200 |
parents | d60d6b4cab0c |
children | c32d6bf6cfc1 |
comparison
equal
deleted
inserted
replaced
116:7ce304c296b0 | 117:e6bb47c6d8d6 |
---|---|
1 local addonName, A = ... | 1 local addonName, A = ... |
2 | |
3 -- @todo: enchants, elementals, prospecting | |
4 -- @todo improve scanning | |
5 | 2 |
6 A.data = A.CommonData | 3 A.data = A.CommonData |
7 | 4 |
8 do | 5 do |
9 -- lua functions | 6 -- lua functions |
30 -- the function who scans the tradeskill | 27 -- the function who scans the tradeskill |
31 function A:ScanSimpleRecipes() | 28 function A:ScanSimpleRecipes() |
32 -- Do not scan while we modify the tradeskill display | 29 -- Do not scan while we modify the tradeskill display |
33 if A.blockScan then return end | 30 if A.blockScan then return end |
34 | 31 |
35 | |
36 -- Check if the tradeskill is loaded | 32 -- Check if the tradeskill is loaded |
37 -- Has to have recipes and begin with a header | 33 -- Has to have recipes and begin with a header |
38 local NRecipes = GetNumTradeSkills() | 34 local NRecipes = GetNumTradeSkills() |
39 if NRecipes==0 or select(2,GetTradeSkillInfo(1))~="header" then | 35 if NRecipes==0 or select(2,GetTradeSkillInfo(1))~="header" then |
40 return | 36 return |
58 A.MillingDataLoaded = true | 54 A.MillingDataLoaded = true |
59 end | 55 end |
60 end | 56 end |
61 | 57 |
62 local lastHeader | 58 local lastHeader |
59 local isScanCorrect = true | |
63 for i = 1,NRecipes do | 60 for i = 1,NRecipes do |
64 -- skillName, skillType, numAvailable, isExpanded, serviceType, numSkillUps = GetTradeSkillInfo(index) | 61 -- skillName, skillType, numAvailable, isExpanded, serviceType, numSkillUps = GetTradeSkillInfo(index) |
65 -- serviceType is nil if the recipe creates an item | 62 -- serviceType is nil if the recipe creates an item |
66 local skillName, skillType, _, _, serviceType = GetTradeSkillInfo(i) | 63 local skillName, skillType, _, _, serviceType = GetTradeSkillInfo(i) |
64 if not skillName then return end | |
65 | |
66 -- Save the name of the header | |
67 if skillType and skillType == "header" then | 67 if skillType and skillType == "header" then |
68 lastHeader = skillName | 68 lastHeader = skillName |
69 | 69 |
70 -- Analyse recipe | |
70 elseif skillType and skillType ~= "header" and serviceType==nil then | 71 elseif skillType and skillType ~= "header" and serviceType==nil then |
72 local isRecipeCorrect = true | |
73 | |
71 -- item ID | 74 -- item ID |
72 local itemID = A.link2ID(GetTradeSkillItemLink(i)) | 75 local itemID = A.link2ID(GetTradeSkillItemLink(i)) |
76 if not itemID then isRecipeCorrect = false; end | |
73 | 77 |
74 local numReagents = GetTradeSkillNumReagents(i) | 78 local numReagents = GetTradeSkillNumReagents(i) |
79 if not numReagents then isRecipeCorrect = false; end | |
80 | |
75 local reagentID, reagentCount | 81 local reagentID, reagentCount |
76 if numReagents==1 then | 82 if numReagents==1 then |
77 -- reagent ID | 83 -- reagent ID |
78 reagentID = A.link2ID(GetTradeSkillReagentItemLink(i, 1)) | 84 reagentID = A.link2ID(GetTradeSkillReagentItemLink(i, 1)) |
85 if not reagentID then isRecipeCorrect = false; end | |
79 | 86 |
80 -- reagent number needed | 87 -- reagent number needed |
81 reagentCount = select(3,GetTradeSkillReagentInfo(i, 1)) | 88 reagentCount = select(3,GetTradeSkillReagentInfo(i, 1)) |
89 if not reagentCount then isRecipeCorrect = false; end | |
82 else | 90 else |
83 -- no reagentID | 91 -- no reagentID (is already nil) |
92 --reagentID = nil | |
84 | 93 |
85 -- contains data for the whole reagents | 94 -- contains data for the whole reagents |
86 reagentCount = {} | 95 reagentCount = {} |
87 for j = 1,numReagents do | 96 for j = 1,numReagents do |
88 tinsert(reagentCount,{A.link2ID(GetTradeSkillReagentItemLink(i, j)), select(3,GetTradeSkillReagentInfo(i, j))}) | 97 local id = A.link2ID(GetTradeSkillReagentItemLink(i, j)) |
98 local num = select(3,GetTradeSkillReagentInfo(i, j)) | |
99 if not id or not num then isRecipeCorrect = false; break; end | |
100 tinsert(reagentCount,{id, num}) | |
89 end | 101 end |
90 end | 102 end |
91 | 103 |
92 -- number of reagent created by the recipe | 104 -- number of reagent created by the recipe |
93 local minMade, maxMade = GetTradeSkillNumMade(i) | 105 local minMade, maxMade = GetTradeSkillNumMade(i) |
106 if not minMade or not maxMade then isRecipeCorrect = false; end | |
94 | 107 |
95 -- recipe link (for tooltips) | 108 -- recipe link (for tooltips) |
96 local recipeLink = GetTradeSkillRecipeLink(i) | 109 local recipeLink = GetTradeSkillRecipeLink(i) |
110 if not recipeLink then isRecipeCorrect = false; end | |
97 | 111 |
112 if not isRecipeCorrect then | |
113 print("Recette incorrecte") | |
114 isScanCorrect = false | |
115 end | |
98 -- error checking | 116 -- error checking |
99 if itemID and (numReagents ~= 1 or (reagentID and reagentCount)) and minMade and maxMade and recipeLink then | 117 if isRecipeCorrect then |
100 -- remove unneeded minMade/maxMade | 118 -- remove unneeded minMade/maxMade |
101 if maxMade==minMade then | 119 if maxMade==minMade then |
102 maxMade = nil | 120 maxMade = nil |
103 if minMade==1 then | 121 if minMade==1 then |
104 minMade = nil | 122 minMade = nil |
129 end | 147 end |
130 end -- if | 148 end -- if |
131 end -- if | 149 end -- if |
132 end -- for | 150 end -- for |
133 -- the scanning is complete | 151 -- the scanning is complete |
134 return true | 152 if not isScanCorrect then |
153 print("Erreur dans le scan") | |
154 end | |
155 return isScanCorrect | |
135 end -- function | 156 end -- function |
136 end -- do | 157 end -- do |