vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 BonusScanner_bonuses = {};
2 BonusScanner_currentset = "";
3 BonusScanner_sets = {};
4  
5  
6 function BonusScanner_ScanAll()
7  
8 local slotNames = {
9 "Head",
10 "Neck",
11 "Shoulder",
12 "Shirt",
13 "Chest",
14 "Waist",
15 "Legs",
16 "Feet",
17 "Wrist",
18 "Hands",
19 "Finger0",
20 "Finger1",
21 "Trinket0",
22 "Trinket1",
23 "Back",
24 "MainHand",
25 "SecondaryHand",
26 "Ranged",
27 "Tabard",
28 };
29  
30 local i, slotName
31 local id, hasItem;
32 local itemName, tmpText, tmpStr, tmpSet, val, lines, set;
33  
34 BonusScanner_bonuses = {};
35 BonusScanner_sets = {};
36 BonusScanner_currentset = "";
37  
38 for i, slotName in slotNames do
39 id, _ = GetInventorySlotInfo(slotName.. "Slot");
40 TPIBonTooltip:Hide()
41 TPIBonTooltip:SetOwner(this, "ANCHOR_LEFT");
42 hasItem = TPIBonTooltip:SetInventoryItem("player", id);
43  
44 if ( not hasItem ) then
45 TPIBonTooltip:ClearLines()
46 else
47 itemName = TPIBonTooltipTextLeft1:GetText();
48 lines = TPIBonTooltip:NumLines();
49  
50 for i=2, lines, 1 do
51 tmpText = getglobal("TPIBonTooltipTextLeft"..i);
52 val = nil;
53 if (tmpText:GetText()) then
54 tmpStr = tmpText:GetText();
55 BonusScanner_ScanLine(tmpStr);
56 end
57 end
58 -- if set item, mark set as already scanned
59 if(BonusScanner_currentset ~= "") then
60 BonusScanner_sets[BonusScanner_currentset] = 1;
61 end;
62 end
63 end
64 TPIBonTooltip:Hide()
65 end
66  
67 function BonusScanner_AddValue(effect, value)
68 local i,e;
69 if(type(effect) == "string") then
70 if(BonusScanner_bonuses[effect]) then
71 BonusScanner_bonuses[effect] = BonusScanner_bonuses[effect] + value;
72 else
73 BonusScanner_bonuses[effect] = value;
74 end
75 else
76 -- list of effects
77 for i,e in effect do
78 if(BonusScanner_bonuses[e]) then
79 BonusScanner_bonuses[e] = BonusScanner_bonuses[e] + value;
80 else
81 BonusScanner_bonuses[e] = value;
82 end
83 end
84 end
85 end;
86  
87 function BonusScanner_ScanLine(line)
88 local tmpStr, found;
89  
90 -- Check for "Equip: "
91 if(string.sub(line,0,string.len(TITAN_ITEMBONUSES_EQUIP_PREFIX)) == TITAN_ITEMBONUSES_EQUIP_PREFIX) then
92  
93 tmpStr = string.sub(line,string.len(TITAN_ITEMBONUSES_EQUIP_PREFIX)+1);
94 BonusScanner_ScanPassive(tmpStr);
95  
96 -- Check for "Set: "
97 elseif(string.sub(line,0,string.len(TITAN_ITEMBONUSES_SET_PREFIX)) == TITAN_ITEMBONUSES_SET_PREFIX
98 and BonusScanner_currentset ~= ""
99 and not BonusScanner_sets[BonusScanner_currentset]) then
100  
101 tmpStr = string.sub(line,string.len(TITAN_ITEMBONUSES_SET_PREFIX)+1);
102 BonusScanner_ScanPassive(tmpStr);
103  
104 -- any other line (standard stats, enchantment, set name, etc.)
105 else
106 -- Check for set name
107 _, _, tmpStr = string.find(line, TITAN_ITEMBONUSES_SETNAME_PATTERN);
108 if(tmpStr) then
109 BonusScanner_currentset = tmpStr;
110 else
111 found = BonusScanner_ScanGeneric(line);
112 if(not found) then
113 BonusScanner_ScanOther(line);
114 end;
115 end
116 end
117 end;
118  
119  
120 -- Scans passive bonuses like "Set: " and "Equip: "
121 function BonusScanner_ScanPassive(line)
122 local i, p, value, found;
123  
124 found = nil;
125 for i,p in TITAN_ITEMBONUSES_EQUIP_PATTERNS do
126 _, _, value = string.find(line, "^" .. p.pattern);
127 if(value) then
128 BonusScanner_AddValue(p.effect, value)
129 found = 1;
130 end
131 end
132 if(not found) then
133 BonusScanner_ScanGeneric(line);
134 end
135 end
136  
137  
138 -- Scans generic bonuses like "+3 Intellect" or "Arcane Resistance +4"
139 function BonusScanner_ScanGeneric(line)
140 local value, token, pos, tmpStr, found;
141  
142 -- split line at "/" for enchants with multiple effects
143 found = false;
144 while(string.len(line) > 0) do
145 pos = string.find(line, "/", 1, true);
146 if(pos) then
147 tmpStr = string.sub(line,1,pos-1);
148 line = string.sub(line,pos+1);
149 else
150 tmpStr = line;
151 line = "";
152 end
153  
154 -- trim line
155 tmpStr = string.gsub( tmpStr, "^%s+", "" );
156 tmpStr = string.gsub( tmpStr, "%s+$", "" );
157 tmpStr = string.gsub( tmpStr, "%.$", "" );
158  
159 _, _, value, token = string.find(tmpStr, TITAN_ITEMBONUSES_PREFIX_PATTERN);
160 if(not value) then
161 _, _, token, value = string.find(tmpStr, TITAN_ITEMBONUSES_SUFFIX_PATTERN);
162 end
163 if(token and value) then
164 -- trim token
165 token = string.gsub( token, "^%s+", "" );
166 token = string.gsub( token, "%s+$", "" );
167  
168 if(BonusScanner_ScanToken(token,value)) then
169 found = true;
170 end
171 end
172 end
173 return found;
174 end
175  
176  
177 -- Identifies simple tokens like "Intellect" and composite tokens like "Fire damage" and
178 -- add the value to the respective bonus.
179 function BonusScanner_ScanToken(token, value)
180 local i, p, s1, s2;
181  
182 if(TITAN_ITEMBONUSES_TOKEN_EFFECT[token]) then
183 BonusScanner_AddValue(TITAN_ITEMBONUSES_TOKEN_EFFECT[token], value);
184 return true;
185 else
186 s1 = nil;
187 s2 = nil;
188 for i,p in TITAN_ITEMBONUSES_S1 do
189 if(string.find(token,p.pattern,1,1)) then
190 s1 = p.effect;
191 end
192 end
193 for i,p in TITAN_ITEMBONUSES_S2 do
194 if(string.find(token,p.pattern,1,1)) then
195 s2 = p.effect;
196 end
197 end
198 if(s1 and s2) then
199 BonusScanner_AddValue(s1..s2, value);
200 return true;
201 end
202 end
203 return false;
204 end
205  
206 -- Scans last fallback for not generic enchants, like "Mana Regen x per 5 sec."
207 function BonusScanner_ScanOther(line)
208 local i, p, value, start, found;
209  
210 found = nil;
211 for i,p in TITAN_ITEMBONUSES_OTHER_PATTERNS do
212 start, _, value = string.find(line, "^" .. p.pattern);
213 if(start) then
214 if(p.value) then
215 BonusScanner_AddValue(p.effect, p.value)
216 elseif(value) then
217 BonusScanner_AddValue(p.effect, value)
218 end
219 end
220 end
221 end