vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 Healers Assist by Kiki of European Cho'gall (Alliance)
3 Regexpr functions
4 Taken from SWStats by Artack - Thanks !
5 ]]
6  
7 --------------- Constantes ---------------
8  
9 --------------- Shared variables ---------------
10  
11 HA_RegEx_Lookup = {};
12  
13 --------------- Local variables ---------------
14  
15 local HA_SL_RegExCreate = 0;
16 local HA_SL_RegExAdded = 0;
17 local HA_MAX_ARGS = 4;
18  
19 HA_DefaultMap= {
20 ["CHAT_MSG_SPELL_SELF_BUFF"] = {
21 [1] = "HEALEDCRITSELFSELF",
22 [2] = "HEALEDCRITSELFOTHER",
23 [3] = "HEALEDSELFSELF",
24 [4] = "HEALEDSELFOTHER",
25 },
26 ["CHAT_MSG_SPELL_PARTY_BUFF"] = {
27 [1] = "HEALEDCRITOTHERSELF",
28 [2] = "HEALEDCRITOTHEROTHER",
29 [3] = "HEALEDOTHERSELF",
30 [4] = "HEALEDOTHEROTHER",
31 },
32 ["CHAT_MSG_SPELL_FRIENDLYPLAYER_BUFF"] = {
33 [1] = "HEALEDCRITOTHERSELF",
34 [2] = "HEALEDCRITOTHEROTHER",
35 [3] = "HEALEDOTHERSELF",
36 [4] = "HEALEDOTHEROTHER",
37 },
38 ["CHAT_MSG_SPELL_HOSTILEPLAYER_BUFF"] = {
39 [1] = "HEALEDCRITOTHERSELF",
40 [2] = "HEALEDCRITOTHEROTHER",
41 [3] = "HEALEDOTHERSELF",
42 [4] = "HEALEDOTHEROTHER",
43 },
44 ["CHAT_MSG_SPELL_PERIODIC_SELF_BUFFS"] = {
45 [1] = "PERIODICAURAHEALSELFSELF",
46 },
47 ["CHAT_MSG_SPELL_PERIODIC_PARTY_BUFFS"] = {
48 [1] = "PERIODICAURAHEALSELFOTHER",
49 },
50 ["CHAT_MSG_SPELL_PERIODIC_FRIENDLYPLAYER_BUFFS"] = {
51 [1] = "PERIODICAURAHEALSELFOTHER",
52 },
53 };
54  
55 --------------- Internal functions ---------------
56  
57 local function HA_g1(doMe, withInfo)
58 _,_,v1 = string.find(doMe, withInfo["r"])
59 if v1 == nil then return nil; end
60 return {v1};
61 end
62 local function HA_g2(doMe, withInfo)
63 _,_,v1, v2 = string.find(doMe, withInfo["r"])
64 if v2 == nil then return nil; end
65 return {v1, v2};
66 end
67 local function HA_g3(doMe, withInfo)
68 _,_,v1, v2, v3 = string.find(doMe, withInfo["r"])
69 if v3 == nil then return nil; end
70 return {v1, v2, v3};
71 end
72 local function HA_g4(doMe, withInfo)
73 _,_,v1, v2, v3, v4 = string.find(doMe, withInfo["r"])
74 if v4 == nil then return nil; end
75 return {v1, v2, v3, v4};
76 end
77  
78 local HA_Func_Lookup = {HA_g1,HA_g2,HA_g3,HA_g4}; -- Must be declared after functions
79  
80 -- here we resort the values via the mapping that was created during the init
81 local function HA_sortVals(vals, withInfo)
82 if vals == nil then return nil; end
83 local ret = {};
84 for k,v in pairs(withInfo["p"]) do
85 ret[v] = vals[k];
86 end
87 return ret;
88 end
89  
90 function HA_getInfo(doMe, withInfo )
91 -- if we don't have a function or # of captures is invlid return nil
92 if withInfo["r"] == nil or withInfo["i"] > HA_MAX_ARGS or withInfo["i"] < 1 then return nil; end
93  
94 -- resort if we have to
95 if withInfo["p"] == nil then
96 return HA_Func_Lookup[withInfo["i"]](doMe, withInfo);
97 else
98 return HA_sortVals(HA_Func_Lookup[withInfo["i"]](doMe, withInfo), withInfo);
99 end
100 end
101  
102 local function _HA_InitVar(varName,types,fromSelf,toSelf,isCrit)
103 local str = getglobal(varName);
104 if str == nil then return end;
105 if types == nil then return end;
106  
107 --fixes ambiguous strings
108 -- fix log strings is a localized function
109 local strTmp = HA_FixLogStrings(str);
110 if(str ~= strTmp)
111 then
112 setglobal(varName, strTmp);
113 str = strTmp;
114 end
115  
116 HA_SL_RegExCreate = HA_SL_RegExCreate +1;
117 HA_RegEx_Lookup[varName] ={};
118  
119 -- "p" stands for positions maps found for numbered vals (e.g. %3$s)
120 -- in a different langugage these might be used in a different order
121 HA_RegEx_Lookup[varName]["p"] ={};
122  
123 HA_RegEx_Lookup[varName]["types"] = types;
124 if(fromSelf)
125 then
126 HA_RegEx_Lookup[varName]["fromSelf"] = 1;
127 end
128 if(toSelf)
129 then
130 HA_RegEx_Lookup[varName]["toSelf"] = 1;
131 end
132 if(isCrit)
133 then
134 HA_RegEx_Lookup[varName]["isCrit"] = 1;
135 end
136  
137 local index=0;
138 local needPosLookup = false;
139 -- first we have to "sanitze" the string ^()%.[]*+-? are special chars in a regex (dont escape the $ and %)
140 -- so we are escaping these with %
141 str = string.gsub(str, "([%.%(%)%+%-%?%[%]%^])", "%%%1");
142  
143 -- the inner function actually does the work
144 str = string.gsub(str,'(%%(%d?)$?([sd]))',
145 function(all,num,type) -- e.g. %3$s all = %3$s num=3 type=s
146 index = index+1;
147 --1.0.2 , fixed the french version bug through "tonumber .. omg DOH .. oh well
148 -- this will help all non english versions
149 HA_RegEx_Lookup[varName]["p"][index] = tonumber(num);
150 if(num ~= "")
151 then
152 -- if num is "" then the string e.g. only used %s and not %1$s
153 -- and we dont need a lookup - its already in order
154 needPosLookup = true;
155 end
156  
157 --this is the actual replacement that makes the regex
158 -- use non greedy for strings
159 if(type == 's')
160 then
161 return ('(.-)');
162 else
163 return ('(%d+)');
164 end
165 end
166 );
167  
168 -- saves how many captures to expect later using this regex
169 HA_RegEx_Lookup[varName]["i"] = index;
170  
171 --generate maps for heal dmg etc info
172 if(index == getn(types))
173 then
174 local playerName = "";
175 local mm = {};
176 local medm = {};
177 local i;
178 local max = getn(types);
179  
180 --1 = target
181 --2 = caster/attacker/initiator
182 --3 = someString (normally spell names, or item names)
183 -- 51 = dmg 52 = heal
184 --{from,to,dmg,heal, what}
185 for i, val in ipairs(types)
186 do
187 if(val == 2)
188 then
189 mm[1] = i;
190 medm[1] = i;
191 elseif(val == 1)
192 then
193 mm[2] = i;
194 medm[2] = i;
195 elseif(val == 51)
196 then
197 mm[3] = i;
198 medm[3] = i;
199 elseif(val == 52)
200 then
201 mm[4] = i;
202 medm[4] = i;
203 elseif(val == 3)
204 then
205 mm[5] = i;
206 medm[5] = i;
207 elseif(val == 7)
208 then
209 mm[6] = i;
210 medm[6] = i;
211 end
212 end
213  
214 if(fromSelf)
215 then
216 mm[1]= -1;
217 end
218 if(toSelf)
219 then
220 mm[2]= -1;
221 end
222 HA_RegEx_Lookup[varName]["basicInfo"] = mm;
223 else
224 HA_ChatWarning("_HA_InitVar "..varName.." "..index.."~="..getn(types).." caputerN~=TypeN");
225 end
226  
227 if (needPosLookup)
228 then
229 -- check if we really do need it
230 -- could be in order anyways
231 needPosLookup = false;
232 for k, v in pairs(HA_RegEx_Lookup[varName]["p"])
233 do
234 -- make k, v numbers, so they will compare
235 -- k,v are of different types so this wouldn't work otherwise
236 k = k+0;
237 v = v+0;
238 if(k ~= v)
239 then
240 needPosLookup = true;
241 break;
242 end
243 end
244 end
245 -- now we are sure if we need it or not
246 if(not needPosLookup)
247 then
248 -- %s %d etc. used info is "in order"
249 -- or %1$s %2$d etc. was used but all in correct order
250 -- just junk it
251 HA_RegEx_Lookup[varName]["p"] = nil;
252 end
253  
254 HA_RegEx_Lookup[varName]["r"] = "^"..str; -- the regex
255 end
256  
257 --------------- Shared functions ---------------
258  
259 function HA_findEventMatch(event,callback)
260 -- only interested in stuff with numbers
261 -- V0.92 Changed this regex
262 --V 1.1.0 Added () -- fix for french crit vals
263 if (not arg1 or not string.find (arg1, "[%s%.%:%(]%d+[%s%.%)]")) then
264 return;
265 end
266  
267 if(HA_DefaultMap[event] ~= nil)
268 then
269 for _,v in ipairs(HA_DefaultMap[event])
270 do
271 r = HA_getInfo(arg1,HA_RegEx_Lookup[v]);
272 if(r ~= nil)
273 then
274 local re = HA_RegEx_Lookup[v];
275 local reBI= re["basicInfo"];
276 local from = reBI[1];
277 local to = reBI[2];
278 local what = reBI[5];
279 local school = reBI[6];
280 local heal = tonumber(r[reBI[4]]);
281 local crit = false;
282 if from == -1 then from = HA_PlayerName; else from = r[from]; end
283 if to == -1 then to = HA_PlayerName; else to = r[to] end
284 if(re["isCrit"] == 1) then crit = true; end
285 if(what) then what = r[what]; end
286 callback(event, from, to, what, heal, crit);
287 return;
288 end
289 end
290 end
291 end
292  
293 function HA_CreateRegexFromGlobals()
294 HA_RegEx_Lookup = {};
295 HA_SL_RegExCreate = 0;
296 HA_SL_RegExAdded = 0;
297  
298 --1 = target
299 --2 = caster/attacker/initiator
300 --3 = someString (normally spell names, or item names)
301 -- 51 = dmg 52 = heal
302 --{from,to,dmg,heal, what}
303 _HA_InitVar("HEALEDSELFSELF",{3,52},true,true,nil);
304 _HA_InitVar("HEALEDSELFOTHER",{3,1,52},true,nil,nil);
305 _HA_InitVar("HEALEDCRITSELFSELF",{3,52},true,true,true);
306 _HA_InitVar("HEALEDCRITSELFOTHER",{3,1,52},true,nil,true);
307 _HA_InitVar("HEALEDOTHERSELF",{2,3,52},nil,true,nil);
308 _HA_InitVar("HEALEDOTHEROTHER",{2,3,1,52},nil,nil,nil);
309 _HA_InitVar("HEALEDCRITOTHERSELF",{2,3,52},nil,true,true);
310 _HA_InitVar("HEALEDCRITOTHEROTHER",{2,3,1,52},nil,nil,true);
311 -- Hots
312 _HA_InitVar("PERIODICAURAHEALSELFSELF",{52,3},true,true,nil);
313 _HA_InitVar("PERIODICAURAHEALSELFOTHER",{1,52,3},true,nil,nil);
314  
315 --SPELLFAILCASTSELF
316 end
317