vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1  
2  
3 --[[------------------------------ Development stuff start ----------------------
4 You schould NOT mess with this stuff you can totally kill the mod here if you don't
5 know what your doing, and there is NOTHING to be gained
6 ]]--
7  
8 --I do a lot (most) of development outside of WOW so here is a switch
9 SW_DEV_INWOW = true;
10  
11 -- a util to create junk msgs to test against
12 SW_DEV_CREATE_JUNK_STRINGS = true;
13 -- just handy to have
14 if SW_DEV_INWOW then
15 SW_DEV_CREATE_JUNK_STRINGS = false;
16 end
17 -- amount of junk do produce per regex
18 SW_DEV_ITEMS_PER_REGEX = 1;
19  
20 -- dummy event all registered regEx will be here
21 SW_DEV_EVENTDUMMY = "EVENTDUMMY";
22 SW_DECURSEDUMMY = "DECURSEDUMMY";
23 --SW_DECEV = {};
24  
25 SW_SpellIDLookUp = {};
26  
27 -- if outside of wow add stuff here to be loaded
28 if not SW_DEV_INWOW then
29 function GetLocale()
30 return "deDE";
31 end
32 dofile("GlobToUseDs.lua"); -- this is not distributet with the mod (its a stripped down GlobalStrings.lua from bliz)
33 --dofile("GlobalStrings-CH-xx.lua"); -- just a chinese version (core seems to work but not 100% sure)
34 dofile("SW_DefaultMap.lua");
35 SW_Map = SW_DefaultMap;
36 dofile("console.lua");
37 dofile("neutral.lua");
38 --dofile("localization.DE.lua");
39 dofile("init.lua");
40  
41  
42 SW_DEV_FINDMATCH = {};
43 SW_DEV_FINDCOLL = {};
44 if SW_DEV_CREATE_JUNK_STRINGS then
45 math.randomseed(os.time());
46 SW_DEV_JUNK_STRINGS ={};
47 end
48 arg1="";
49  
50 end
51 --added 1.4
52 --used to skip code while in "dev mode" this should always be true in a release
53 SW_LIVE_MODE = true;
54  
55 -------------------------------- Development stuff END ----------------------
56  
57 -- table to look up localized class names (lookup built automtically)
58  
59 SW_ClassNames = {
60 ["DRUID"] = "",
61 ["HUNTER"] = "",
62 ["MAGE"] = "",
63 ["PALADIN"] = "",
64 ["PRIEST"] = "",
65 ["ROGUE"] = "",
66 ["SHAMAN"] = "",
67 ["WARLOCK"] = "",
68 ["WARRIOR"] = "",
69 };
70  
71  
72 -- the lookup table with regex generated from Blizzards global vars
73 -- for adding vars add them in init.lua SW_CreateRegexFromGlobals()
74 SW_RegEx_Lookup = {};
75  
76 -- this maps events to regular expressions
77 -- to chage this mapping see init.lua SW_CreateEventRegexMap()
78 SW_EventRegexMap ={};
79  
80 -- similar to SW_EventRegexMap but only with VSENVIRONMENTALDAMAGE_XXX
81 -- this is only checked if nothing "fit" SW_EventRegexMap
82 SW_EventRegexMapEnviro = {};
83  
84 -- info with stuff that happened at startup
85 -- if in the end all was ok it will be nil
86 -- else it has some info to track down problems
87 SW_StartupLog = {};
88  
89 -- this tracks events we lsten to but dont have a regex for
90 SW_NA_Msgs = {};
91  
92 -- this is used to block the Fallback feature
93 -- if no regex was found for an event, the event is blocked from updating itself
94 -- else it would always go through all events in the event dummy
95 SW_Fallback_Block = {};
96  
97 -- resist stuff disabled
98 SW_CheckForAbsorbs = true; -- does etra check for ending (123 resisted) or (234 absorbed)etc
99 SW_OnlyResists = false; --if previeous is true it only does this check for resist (most interesting)
100  
101 --v 0.95 added SW_S_* to saved vars
102 -- table with infos
103 SW_S_Details = {};
104 -- table with heal map (who/who) info
105 SW_S_Healed = {};
106  
107 --1.3.0 Table with spell and mana info this person casted
108 SW_S_SpellInfo = {};
109 --1.3.0 Table with mana info dmg, heal and total mana used
110 SW_S_ManaUsage = {};
111  
112 -- "Friends" Table either self, group or raid
113 -- used to sperate any recorded info from people "in group"
114 SW_Friends = {};
115  
116 -- pet to owner lookup
117 --SW_Pets = {}; removed 1.5 old pet mech
118  
119 -- 1.5 extended pet info
120 SW_PetInfo = {};
121 SW_PetInfo["OWNER_PET"] = {};
122 SW_PetInfo["PET_OWNER"] = {};
123  
124 --1.3.1 holds time info for DPS
125 --1.3.2 had to change this again time and DPS dmg are not saved anymore across sessions
126 SW_CombatTime = 0;
127 SW_CombatTimeInfo = {};
128 SW_DPS_Dmg =0;
129  
130 SW_CombatTimeCounter =0;
131  
132 --settings Table
133 SW_Settings = {};
134  
135 -- its the player name we would look it up a LOT
136 SW_SELF_STRING= "";
137  
138 -- the "Event Channel" - we need it a LOT
139 SW_Event_Channel =nil;
140  
141 SW_EI_ALLOFF = false;
142  
143 -- 1.5.3 used for colors of the title bars and buttons in them
144 SW_Registerd_BF_Titles = {};
145 SW_Registered_BF_TitleButtons = {};
146 SW_DummyColor = {1,1,1,1};
147  
148 function SW_CreateSpellIDLookup()
149 --SW_SpellIDLookUp = {};
150 for i,v in ipairs(SW_Spellnames) do
151 SW_SpellIDLookUp[v] = i;
152 end
153 end
154 --------------------- START section GETINFO ---------------------------
155  
156 local function SW_g1(doMe, withInfo)
157 _,_,v1 = string.find(doMe, withInfo["r"])
158 if v1 == nil then return nil; end
159 return {v1};
160 end
161 local function SW_g2(doMe, withInfo)
162 _,_,v1, v2 = string.find(doMe, withInfo["r"])
163 if v2 == nil then return nil; end
164 return {v1, v2};
165 end
166 local function SW_g3(doMe, withInfo)
167 _,_,v1, v2, v3 = string.find(doMe, withInfo["r"])
168 if v3 == nil then return nil; end
169 return {v1, v2, v3};
170 end
171 local function SW_g4(doMe, withInfo)
172 _,_,v1, v2, v3, v4 = string.find(doMe, withInfo["r"])
173 if v4 == nil then return nil; end
174 return {v1, v2, v3, v4};
175 end
176 local function SW_g5(doMe, withInfo)
177 _,_,v1, v2, v3, v4, v5 = string.find(doMe, withInfo["r"])
178 if v5 == nil then return nil; end
179 return {v1, v2, v3, v4, v5};
180 end
181 local function SW_g6(doMe, withInfo)
182 _,_,v1, v2, v3, v4, v5, v6 = string.find(doMe, withInfo["r"])
183 if v6 == nil then return nil; end
184 return {v1, v2, v3, v4, v5, v6};
185 end
186 local function SW_g7(doMe, withInfo)
187 _,_,v1, v2, v3, v4, v5, v6, v7 = string.find(doMe, withInfo["r"])
188 if v7 == nil then return nil; end
189 return {v1, v2, v3, v4, v5, v6, v7};
190 end
191 function SW_g8(doMe, withInfo)
192 _,_,v1, v2, v3, v4, v5, v6, v7, v8 = string.find(doMe, withInfo["r"])
193 if v8 == nil then return nil; end
194 return {v1, v2, v3, v4, v5, v6, v7, v8};
195 end
196 local function SW_g9(doMe, withInfo)
197 _,_,v1, v2, v3, v4, v5, v6, v7, v8, v9 = string.find(doMe, withInfo["r"])
198 if v9 == nil then return nil; end
199 return {v1, v2, v3, v4, v5, v6, v7, v8, v9};
200 end
201  
202 -- here we resort the values via the mapping that was created during the init
203 local function SW_sortVals(vals, withInfo)
204 if vals == nil then return nil; end
205 local ret = {};
206 for k,v in pairs(withInfo["p"]) do
207 ret[v] = vals[k];
208 end
209 return ret;
210 end
211  
212 local SW_MAX_ARGS = 9;
213 -- a functionLookup mapping # returned arguments to a specific function
214 local SW_Func_Lookup = {SW_g1,SW_g2,SW_g3,SW_g4,SW_g5,SW_g6,SW_g7,SW_g8,SW_g9};
215 -- this actually performs the search on a string
216 function SW_getInfo(doMe, withInfo )
217 -- if we don't have a function or # of captures is invlid return nil
218 if withInfo["r"] == nil or withInfo["i"] > SW_MAX_ARGS or withInfo["i"] < 1 then return nil; end
219  
220  
221 -- resort if we have to
222 if withInfo["p"] == nil then
223 return SW_Func_Lookup[withInfo["i"]](doMe, withInfo);
224  
225 --return SW_Func_Lookup[withInfo["i"]](doMe, withInfo);
226 else
227 return SW_sortVals(SW_Func_Lookup[withInfo["i"]](doMe, withInfo), withInfo);
228 end
229 end
230  
231 -- at the end of dmg messages there can be blocked absobed etc messages
232 --this returns the globalVarName, the value absorbed
233 -- TODO this isnt correct.. there can be multiple endings
234 function getEndingInfo(strIn)
235 --even do the check ?
236 --if not SW_CheckForAbsorbs then return nil; end --add this on a outer level
237  
238 -- assumption here, abosrbs etc end with a ")" (seems to be true)
239 if string.sub(strIn,-1)~=")" then return nil; end
240  
241 s,e = string.find(strIn, SW_RegEx_Lookup["RESIST_TRAILER"]["r"])
242 if s ~= nil then return "RESIST_TRAILER", SW_getInfo(strIn, SW_RegEx_Lookup["RESIST_TRAILER"])[1]; end
243  
244 if SW_OnlyResists then return nil; end
245  
246 s,e = string.find(strIn, SW_RegEx_Lookup["ABSORB_TRAILER"]["r"])
247 if s ~= nil then return "ABSORB_TRAILER", SW_getInfo(strIn, SW_RegEx_Lookup["ABSORB_TRAILER"])[1]; end
248 s,e = string.find(strIn, SW_RegEx_Lookup["BLOCK_TRAILER"]["r"])
249 if s ~= nil then return "BLOCK_TRAILER", SW_getInfo(strIn, SW_RegEx_Lookup["BLOCK_TRAILER"])[1]; end
250 s,e = string.find(strIn, SW_RegEx_Lookup["VULNERABLE_TRAILER"]["r"])
251 if s ~= nil then return "VULNERABLE_TRAILER", SW_getInfo(strIn, SW_RegEx_Lookup["VULNERABLE_TRAILER"])[1]; end
252  
253 return nil;
254 end
255 --------------------- END section GETINFO ---------------------------
256  
257 function SW_Stats_OnLoad()
258 SW_SL_Add(SW_SL["START"]);
259  
260 SlashCmdList["SW_STATS"] = function(msg)
261 SW_SlashCommand(msg);
262 end
263 SLASH_SW_STATS1 = SW_RootSlashes[1];
264 SLASH_SW_STATS2 = SW_RootSlashes[2];
265  
266 SW_CreateRegexFromGlobals();
267 SW_RegisterEvents();
268 end
269  
270 local function SW_handleMatch(event, regExName, caps)
271 local re = SW_RegEx_Lookup[regExName];
272 local reBI= re["basicInfo"];
273 local from = reBI[1];
274 local to = reBI[2];
275 local what = reBI[5];
276 local school = reBI[6];
277 local tmp;
278 local pFrom, pFromTotal, pFromWhat, pFromSchool;
279 local pTo, pToWhat, pToSchool, pToRec;
280 local isCrit = (re["isCrit"] ~= nil);
281  
282 local scrapDmg = false;
283  
284 --[[ START SETUP
285 setup all vars from to etc
286 make sure the vars are initialized
287 --]]
288 if from == nil then
289 from = SW_PRINT_ITEM_WORLD;
290 else
291 if from == -1 then from = SW_SELF_STRING; else from = caps[from]; end
292 if from == nil then from = "??"; end
293 end
294 if to == nil then
295 to = SW_PRINT_ITEM_WORLD;
296 else
297 if to == -1 then to = SW_SELF_STRING; else to = caps[to] end
298 if to == nil then to = "??"; end
299 end
300 -- 1.1.0 dont count dmg from self to self
301 if reBI[3] then
302 if from == to then
303 scrapDmg = true;
304 end
305 --1.3.1 start dps timer
306 if SW_CombatTimeInfo.awaitingStart and from == SW_SELF_STRING then
307 SW_CombatTimeInfo.awaitingStart = false;
308 SW_CombatTimeInfo.awaitingEnd = true;
309 end
310 end
311 if what == nil then
312 what = SW_PRINT_ITEM_NORMAL;
313 else
314 what = caps[ reBI[5] ];
315 if what == nil then what = "??"; end
316 end
317 --[[ usefull for finding wrong captures
318 if string.find (what, "'s") then
319 SW_printStr("--START--");
320 SW_printStr(what);
321 SW_printStr(arg1);
322 SW_printStr(regExName);
323 SW_printStr(re[r]);
324 SW_DumpTable(caps);
325 SW_printStr("--END--");
326 end
327 --]]
328 if school == nil then
329 school = SW_PRINT_ITEM_NON_SCHOOL;
330 else
331 school = caps[school];
332 if school == nil then school = "??"; end
333 end
334  
335 pFrom = SW_S_Details[from];
336 if pFrom == nil then
337 SW_S_Details[from] ={};
338 pFrom = SW_S_Details[from];
339 pFrom[SW_PRINT_ITEM_TOTAL_DONE] = {0,0}; --first = dmg; sec = heal
340 pFrom[SW_PRINT_ITEM_RECIEVED] = {0,0}; --first = dmg; sec = heal
341 pFrom[SW_PRINT_ITEM_TYPE] = {}; -- school info
342 end
343  
344 pFromTotal = pFrom[SW_PRINT_ITEM_TOTAL_DONE];
345  
346 pTo= SW_S_Details[to];
347 if pTo == nil then
348 SW_S_Details[to] = {};
349 pTo = SW_S_Details[to];
350 pTo[SW_PRINT_ITEM_TOTAL_DONE] = {0,0}; --first = dmg; sec = heal
351 pTo[SW_PRINT_ITEM_RECIEVED] = {0,0}; --first = dmg; sec = heal
352 pTo[SW_PRINT_ITEM_TYPE] = {}; -- school info
353 end
354  
355 pToRec = pTo[SW_PRINT_ITEM_RECIEVED];
356  
357 pFromWhat = pFrom[what];
358 if pFromWhat == nil then
359 pFrom[what] ={0,0,0,0,0,0,0}; --dmg, heal, maxDmg, usedcount (or tick count with dots) - 1.4.1beta2 added ,maxHeal, critcountDmg, critcountHeal
360 pFromWhat = pFrom[what];
361 end
362  
363 -- this can happen now because of the sync channel
364 if pFrom[SW_PRINT_ITEM_TYPE] == nil then
365 pFrom[SW_PRINT_ITEM_TYPE] = {};
366 end
367 pFromSchool = pFrom[SW_PRINT_ITEM_TYPE][school];
368 if pFromSchool == nil then
369 pFrom[SW_PRINT_ITEM_TYPE][school] ={0,0,0,0,0,0}; --dmgDone, Donemax, usedCount, dmgRecieved, recivedMax, recievedCount
370 pFromSchool = pFrom[SW_PRINT_ITEM_TYPE][school];
371 end
372  
373 -- this can happen now because of the sync channel
374 if pTo[SW_PRINT_ITEM_TYPE] == nil then
375 pTo[SW_PRINT_ITEM_TYPE] = {};
376 end
377 pToSchool = pTo[SW_PRINT_ITEM_TYPE][school];
378 if pToSchool == nil then
379 pTo[SW_PRINT_ITEM_TYPE][school] ={0,0,0,0,0,0}; --dmgDone, Donemax, usedCount, dmgRecieved, recivedMax, recievedCount
380 pToSchool = pTo[SW_PRINT_ITEM_TYPE][school];
381 end
382  
383 -- END SETUP
384  
385  
386 -- count usage up by 1
387 pFromWhat[4] = pFromWhat[4] + 1;
388  
389 -- dmg or heal ?
390 if reBI[3] then
391  
392 local dmg = tonumber(caps[ reBI[3] ]);
393  
394 if not scrapDmg and (SW_Friends[from] ~= nil or SW_PetInfo["PET_OWNER"][from] ~= nil) then
395 SW_RPS:validEvent();
396 end
397 if not scrapDmg then
398  
399 -- added 1.5 is this a pet?
400 if SW_PetInfo["PET_OWNER"][from] ~= nil then
401 SW_HandlePetEvent(from, true, dmg, 0);
402 end
403 --1.3.2 added extra counter for dps dmg
404 if from == SW_SELF_STRING then
405 SW_DPS_Dmg = SW_DPS_Dmg + dmg;
406 end
407 pFromTotal[1] = pFromTotal[1] + dmg;
408 pFromWhat[1] = pFromWhat[1] + dmg;
409 if dmg > pFromWhat[3] then
410 pFromWhat[3] = dmg;
411 end
412  
413 --1.4.1 beta 2 added
414 if isCrit then
415 pFromWhat[6] = pFromWhat[6] + 1;
416 end
417 end
418 -- added 1.5 is this a pet?
419 if SW_PetInfo["PET_OWNER"][to] ~= nil then
420 SW_HandlePetEvent(to, false, dmg, 0);
421 end
422 pToRec[1] = pToRec[1] + dmg;
423  
424 if not scrapDmg then
425 pFromSchool[1] = pFromSchool[1] +dmg;
426 if dmg > pFromSchool[2] then
427 pFromSchool[2] = dmg;
428 end
429 pFromSchool[3] = pFromSchool[3] + 1;
430 end
431  
432 pToSchool[4] = pToSchool[4] + dmg;
433 if dmg > pToSchool[5] then
434 pToSchool[5] = dmg;
435 end
436 pToSchool[6] = pToSchool[6] + 1;
437  
438 elseif reBI[4] then
439 local heal = tonumber(caps[ reBI[4] ]);
440 -- added 1.5 is this a pet?
441 if SW_PetInfo["PET_OWNER"][from] ~= nil then
442 SW_HandlePetEvent(from, true, 0, heal);
443 end
444 if SW_PetInfo["PET_OWNER"][to] ~= nil then
445 SW_HandlePetEvent(to, false, 0, heal);
446 end
447 if SW_Friends[to] ~= nil then
448 --1.4.1 added nil check is this the cause of the rare error ?
449 -- TODO (low prio) noticed while working on 1.5 no OH count from pets as target
450 local info = SW_Friends[to]["UnitID"];
451 if info == nil then
452 SW_RebuildFriendList();
453 if SW_Friends[to] == nil or SW_Friends[to]["UnitID"] == nil then
454 SW_printStr("UnitHealthMax(nil) - SW FriendList rebuilt-- didn't help");
455 return;
456 end
457 SW_printStr("UnitHealthMax(nil) - SW FriendList rebuilt - OK");
458  
459 end
460 info = SW_Friends[to]["UnitID"];
461 local num = UnitHealthMax(info) - UnitHealth(info) - heal;
462 if num < 0 then
463 num = num * (-1);
464  
465 if SW_S_Healed[from] == nil then
466 SW_S_Healed[from] = {};
467 end
468  
469 if SW_S_Healed[from][SW_OVERHEAL] == nil then
470 SW_S_Healed[from][SW_OVERHEAL] = 0;
471 end
472  
473 SW_S_Healed[from][SW_OVERHEAL] = SW_S_Healed[from][SW_OVERHEAL] + num;
474 --SW_printStr("Over Heal in cast from "..from.." to "..to.." "..num);
475 end
476 end
477 pFromTotal[2] = pFromTotal[2] + heal;
478 pFromWhat[2] = pFromWhat[2] + heal;
479  
480 if heal > pFromWhat[5] then
481 pFromWhat[5] = heal;
482 end
483 --1.4.1 beta 2 added
484 if isCrit then
485 pFromWhat[7] = pFromWhat[7] + 1;
486 end
487  
488 pToRec[2] = pToRec[2] + heal;
489  
490 -- heal map
491  
492 if SW_S_Healed[from] == nil then
493 SW_S_Healed[from] = {};
494 SW_S_Healed[from][to] = 0;
495 else
496 if SW_S_Healed[from][to] == nil then
497 SW_S_Healed[from][to] = 0;
498 end
499 end
500 SW_S_Healed[from][to] = SW_S_Healed[from][to] + heal;
501 end
502  
503 if SW_EI_ALLOFF then return; end
504 --[[ --]]
505 if SW_Settings["EI_ShowEvent"] then
506 SW_Event_Channel:AddMessage(GREEN_FONT_COLOR_CODE..event.."->"..regExName);
507 end
508 if SW_Settings["EI_ShowRegEx"] then
509 SW_Event_Channel:AddMessage(LIGHTYELLOW_FONT_COLOR_CODE..SW_RegEx_Lookup[regExName]["r"]);
510 end
511 if SW_Settings["EI_ShowOrigStr"] then
512 SW_Event_Channel:AddMessage(arg1);
513 end
514  
515  
516 if SW_Settings["EI_ShowMatch"] then
517 if from == nil then
518 from = "?";
519 end
520 if to == nil then
521 to="?";
522 end
523 local sOut = string.format(SW_PRINT_INFO_FROMTO, from, to);
524  
525 if reBI[3] then
526 if caps[ reBI[3] ] == nil then
527 caps[ reBI[3] ] = "??";
528 end
529 if scrapDmg then
530 sOut = sOut..string.format(SW_PRINT_ITEM, SW_PRINT_ITEM_DMG, caps[ reBI[3] ]).." ("..SW_PRINT_ITEM_IGNORED..")";
531 else
532 sOut = sOut..string.format(SW_PRINT_ITEM, SW_PRINT_ITEM_DMG, caps[ reBI[3] ]);
533 end
534 end
535 if reBI[4] then
536 if caps[ reBI[4] ] == nil then
537 caps[ reBI[4] ] = "??";
538 end
539 sOut = sOut..string.format(SW_PRINT_ITEM, SW_PRINT_ITEM_HEAL, caps[ reBI[4] ]);
540 end
541 if reBI[5] then
542 if caps[ reBI[5] ] == nil then
543 caps[ reBI[5] ] = "??";
544 end
545 sOut = sOut..string.format(SW_PRINT_ITEM, SW_PRINT_ITEM_THROUGH, caps[ reBI[5] ]);
546 end
547 if reBI[6] then
548 if caps[ reBI[6] ] == nil then
549 caps[ reBI[6] ] = "??";
550 end
551 sOut = sOut..string.format(SW_PRINT_ITEM, SW_PRINT_ITEM_TYPE, caps[ reBI[6] ]);
552 end
553 if isCrit then
554 sOut = sOut..SW_PRINT_ITEM_CRIT;
555 end
556 SW_Event_Channel:AddMessage(sOut);
557 end
558  
559  
560 end
561  
562 --1.5.1 Decurse Counting
563 local function SW_CheckDecurse(event)
564 local re;
565 local reBI;
566 local from;
567 local to;
568 local what;
569 local spellID;
570 local r;
571  
572 for _,v in ipairs(SW_EventRegexMap[SW_DECURSEDUMMY]) do
573 r = SW_getInfo(arg1, SW_RegEx_Lookup[v]);
574 if r~=nil then
575 re = SW_RegEx_Lookup[v];
576 reBI= re["basicInfo"];
577 from = reBI[1];
578 to = reBI[2];
579 what = reBI[5];
580  
581 if what == nil then
582 what = SW_PRINT_ITEM_NORMAL;
583 else
584 what = r[what];
585 if what == nil then what = "??"; end
586 end
587  
588 -- this isn't perfect "what" can still be a number of false captures
589 -- the lookup makes it safe though
590 spellID = SW_SpellIDLookUp[what];
591 if spellID ~= nil then
592 if from == nil then
593 from = SW_PRINT_ITEM_WORLD;
594 else
595 if from == -1 then from = SW_SELF_STRING; else from = r[from]; end
596 if from == nil then from = "??"; end
597 end
598 if to == nil then
599 to = SW_PRINT_ITEM_WORLD;
600 else
601 if to == -1 then to = SW_SELF_STRING; else to = r[to] end
602 if to == nil then to = "??"; end
603 end
604  
605 if SW_S_SpellInfo[from] == nil then
606 SW_S_SpellInfo[from] = {};
607 end
608 if SW_S_SpellInfo[from][SW_DECURSEDUMMY] == nil then
609 SW_S_SpellInfo[from][SW_DECURSEDUMMY] = {};
610 end
611 if SW_S_SpellInfo[from][SW_DECURSEDUMMY]["total"] == nil then
612 SW_S_SpellInfo[from][SW_DECURSEDUMMY]["total"] = 1;
613 else
614 SW_S_SpellInfo[from][SW_DECURSEDUMMY]["total"] = SW_S_SpellInfo[from][SW_DECURSEDUMMY]["total"] + 1;
615 end
616 if SW_S_SpellInfo[from][SW_DECURSEDUMMY][what] == nil then
617 SW_S_SpellInfo[from][SW_DECURSEDUMMY][what] = 1;
618 else
619 SW_S_SpellInfo[from][SW_DECURSEDUMMY][what] = SW_S_SpellInfo[from][SW_DECURSEDUMMY][what] + 1;
620 end
621 --[[
622 if SW_DECEV[event] == nil then
623 SW_DECEV[event] = {};
624 end
625 table.insert(SW_DECEV[event], {from .. "; to '" .. to .. "'; " .. what, SW_RegEx_Lookup[v][r], arg1} );
626 --]]
627 return true;
628 end
629  
630 end
631 end
632 return false;
633 end
634 local function findEventMatch(event)
635 -- only interested in stuff with numbers
636 -- V0.92 Changed this regex
637 --V 1.1.0 Added () -- fix for french crit vals
638 -- 1.4.2 made regex a var to be localized see neutral.lua
639 if not string.find (arg1, SW_PRE_REGEX) then
640 SW_CheckDecurse(event);
641 return false, "NUMBER";
642 end
643  
644  
645 --[[SW_TmpMap
646 if you change this change SW_CreateEventRegexMap
647 Its a map of regex to check first, point is if we find the
648 default map had erros we put these here first to enable transition
649 to a new default map, why here?.. becaue here we add messages that would be handeld by other regexp
650  
651 if SW_TmpMap ~= nil then
652 for _,v in ipairs(SW_TmpMap) do
653 r = SW_getInfo(arg1, SW_RegEx_Lookup[v]);
654 if r~=nil then
655 SW_lateAdd(event, v, SW_EventRegexMap, SW_Map, true);
656 end
657 end
658 end
659 --]]
660 local r;
661 if SW_EventRegexMap[event] ~= nil then
662 for _,v in ipairs(SW_EventRegexMap[event]) do
663 r = SW_getInfo(arg1, SW_RegEx_Lookup[v]);
664 if r~=nil then
665 SW_handleMatch(event, v, r);
666 return true;
667 end
668 end
669 else
670 SW_printStr(RED_FONT_COLOR_CODE..SW_EMPTY_EVENT..event, 1);
671 end
672 local r;
673 -- if we get here see if it was env dmg
674 if SW_EventRegexMapEnviro[event] ~= nil then
675 for _,v in ipairs(SW_EventRegexMapEnviro[event]) do
676 r = SW_getInfo(arg1, SW_RegEx_Lookup[v]);
677 if r~=nil then
678 SW_handleMatch(event, v, r);
679 return true;
680 end
681 end
682 end
683 return false, "NF";
684  
685 end
686 local function doFallback(event)
687 -- we didn't find a regex that fits
688 -- the SW_DEV_EVENTDUMMY has all defined that we are "listening" to
689 local r;
690 for _,v in ipairs(SW_EventRegexMap[SW_DEV_EVENTDUMMY]) do
691 r = SW_getInfo(arg1, SW_RegEx_Lookup[v]);
692 if r~=nil then
693 if string.sub(v,1,string.len("VSENVIRONMENTALDAMAGE"))=="VSENVIRONMENTALDAMAGE" then
694 SW_lateAdd(event, v, SW_EventRegexMapEnviro, SW_EnviroMap);
695 else
696 SW_lateAdd(event, v, SW_EventRegexMap, SW_Map);
697 end
698 SW_handleMatch(event, v, r);
699 return true;
700 end
701 end
702 return false;
703 end
704 function SW_DoEvent(event)
705 if arg1 == nil then
706 SW_printStr("arg1 NIL For:"..event);
707 return;
708 end
709 local isOk, reason = findEventMatch(event);
710  
711 if not isOk and reason == "NF" then
712 SW_printStr(RED_FONT_COLOR_CODE..event, 2);
713 SW_printStr(RED_FONT_COLOR_CODE.." "..arg1, 2);
714  
715 if SW_Fallback_Block[event] == nil then
716  
717 if doFallback(event) then
718 SW_printStr(GREEN_FONT_COLOR_CODE.." "..SW_CONSOLE_FALLBACK, 2);
719 else
720 SW_printStr(RED_FONT_COLOR_CODE.." "..SW_CONSOLE_NOREGEX, 2);
721 SW_Fallback_Block[event] = arg1;
722 end
723 else
724 SW_printStr(RED_FONT_COLOR_CODE.." "..SW_FALLBACK_BLOCK_INFO, 2);
725 SW_printStr(RED_FONT_COLOR_CODE.." "..SW_CONSOLE_NOREGEX, 2);
726 SW_printStr(RED_FONT_COLOR_CODE.." "..SW_Fallback_Block[event], 2);
727 end
728  
729 end
730  
731 end
732 function SW_Test(subMap)
733  
734 if subMap == nil then
735 for k,v in pairs(SW_EventRegexMap) do
736 SW_printStr (k);
737 for _,x in ipairs(v) do
738 SW_printStr(" "..x.." ---- "..SW_RegEx_Lookup[x]["r"]);
739 end
740 end
741 else
742 SW_printStr (subMap);
743 for _,x in ipairs(SW_EventRegexMap[subMap]) do
744 SW_printStr(" "..x.." ---- "..SW_RegEx_Lookup[x]["r"]);
745 end
746 end
747 end
748  
749 -- 1.5 new pet mechanics
750 function SW_PetHasOwner(petName)
751 local petInfo = SW_PetInfo["PET_OWNER"][petName];
752 if petInfo ~= nil and petInfo["currentOwners"] ~= nil then
753 for k, v in pairs(petInfo["currentOwners"]) do
754 return true;
755 end
756 end
757 return false;
758 end
759 -- resets current petownership to nothing
760 function SW_PetsResetOwners()
761 for k, v in pairs(SW_PetInfo["OWNER_PET"]) do
762 v["currentPet"] = nil;
763 end
764 for k, v in pairs(SW_PetInfo["PET_OWNER"]) do
765 v["currentOwners"] = {};
766 end
767 end
768 function SW_HandlePetEvent(petName, petsAction, dmg, heal)
769 local petInfo = SW_PetInfo["PET_OWNER"][petName];
770 local tmpInfo = nil;
771 local oneOwner = nil;
772 local hadOwner = false;
773  
774 if petInfo == nil then return; end
775 if petInfo["currentOwners"] == nil then return; end
776  
777 for k, v in pairs(petInfo["currentOwners"]) do
778 hadOwner = true;
779 oneOwner = SW_PetInfo["OWNER_PET"][k];
780 if oneOwner ~= nil then
781  
782 if oneOwner["currentPet"] == petName then -- through setup should always be true
783  
784 if petsAction then
785 tmpInfo = oneOwner["pets"][petName][SW_PRINT_ITEM_TOTAL_DONE];
786 else
787 tmpInfo = oneOwner["pets"][petName][SW_PRINT_ITEM_RECIEVED];
788 end
789 tmpInfo[1] = tmpInfo[1] + dmg;
790 tmpInfo[2] = tmpInfo[2] + heal;
791 if petsAction then
792 tmpInfo = oneOwner[SW_PRINT_ITEM_TOTAL_DONE];
793 else
794 tmpInfo = oneOwner[SW_PRINT_ITEM_RECIEVED];
795 end
796 tmpInfo[1] = tmpInfo[1] + dmg;
797 tmpInfo[2] = tmpInfo[2] + heal;
798 end
799 end
800 end
801  
802 if hadOwner then
803 if petsAction then
804 tmpInfo = petInfo[SW_PRINT_ITEM_TOTAL_DONE];
805 else
806 tmpInfo = petInfo[SW_PRINT_ITEM_RECIEVED];
807 end
808 tmpInfo[1] = tmpInfo[1] + dmg;
809 tmpInfo[2] = tmpInfo[2] + heal;
810 end
811 end
812 function SW_UpdatePet(ownerID)
813 local ownerName = UnitName(ownerID);
814 local unitPetName = nil;
815 local unitPetID = nil;
816 local localizedClass, englishClass;
817  
818 if ownerName == nil then return; end
819  
820 -- translate target to raid/ group id
821 -- cant seem to get the pet of a "target" id
822 if ownerID == "target" then
823 if SW_Friends[ownerName] ~= nil then
824 -- should always be true just an extra check
825 if UnitIsUnit(SW_Friends[ownerName]["UnitID"], "target") then
826 ownerID = SW_Friends[ownerName]["UnitID"];
827 else
828 ownerID = nil;
829 end
830 else
831 ownerID = nil;
832 end
833 end
834 if (ownerID == nil) then return; end
835  
836 -- here we have an id we can really use
837 if ownerID == "player" then
838 unitPetID = "pet";
839 elseif string.find(ownerID, "party") then
840 unitPetID = string.gsub(ownerID, "party", "partypet");
841 elseif string.find(ownerID, "raid") then
842 unitPetID = string.gsub(ownerID, "raid", "raidpet");
843 else
844 SW_printStr("SW_UpdatePet error ownerID is:"..ownerID);
845 return;
846 end
847  
848 unitPetName = UnitName(unitPetID);
849  
850 -- this tends to happen when logging in
851 -- once inside the game zoning and reloadui shouldn't trigger this
852 if unitPetName == UNKNOWNOBJECT then
853 --SW_printStr("Started UNKNOWNOBJECT timer");
854 SW_Timed_Calls.retryUnknownObject = true;
855 return;
856 end
857  
858 -- no pet
859 if unitPetName == nil then
860 -- remove the owner
861 for k,v in pairs(SW_PetInfo["PET_OWNER"]) do
862 if v["currentOwners"] ~= nil then
863 v["currentOwners"][ownerName] = nil;
864 end
865 end
866 if SW_PetInfo["OWNER_PET"][ownerName] ~= nil then
867 SW_PetInfo["OWNER_PET"][ownerName]["currentPet"] = nil;
868 end
869 end
870 if unitPetName ~= nil and unitPetName ~= UNKNOWNOBJECT then
871 -- setup pet owner
872 if SW_PetInfo["PET_OWNER"][unitPetName] == nil then
873 SW_PetInfo["PET_OWNER"][unitPetName] = {};
874 SW_PetInfo["PET_OWNER"][unitPetName][SW_PRINT_ITEM_TOTAL_DONE] = {0,0};
875 SW_PetInfo["PET_OWNER"][unitPetName][SW_PRINT_ITEM_RECIEVED] = {0,0};
876 SW_PetInfo["PET_OWNER"][unitPetName]["currentOwners"] = {};
877 SW_PetInfo["PET_OWNER"][unitPetName]["currentOwners"][ownerName] = true;
878 localizedClass, englishClass = UnitClass(unitPetID);
879 if englishClass ~= nil and localizedClass ~= nil then
880 SW_ClassNames[englishClass] = localizedClass;
881 end
882 -- englishClass might be nill but thats fine
883 SW_PetInfo["PET_OWNER"][unitPetName]["CLASSE"] = englishClass;
884 else
885 -- need this check because of sync channel
886 if SW_PetInfo["PET_OWNER"][unitPetName]["currentOwners"] == nil then
887 SW_PetInfo["PET_OWNER"][unitPetName]["currentOwners"] = {};
888 end
889 SW_PetInfo["PET_OWNER"][unitPetName]["currentOwners"][ownerName] = true;
890 -- sometimes class info doesn't carry over (pet is to far away)
891 -- so recheck it
892 if SW_PetInfo["PET_OWNER"][unitPetName]["CLASSE"] == nil then
893 localizedClass, englishClass = UnitClass(unitPetID);
894 if englishClass ~= nil and localizedClass ~= nil then
895 SW_ClassNames[englishClass] = localizedClass;
896 end
897 SW_PetInfo["PET_OWNER"][unitPetName]["CLASSE"] = englishClass;
898 end
899 end
900 -- setup owner pet
901 if SW_PetInfo["OWNER_PET"][ownerName] == nil then
902 SW_PetInfo["OWNER_PET"][ownerName] = {};
903 SW_PetInfo["OWNER_PET"][ownerName]["pets"] = {};
904 SW_PetInfo["OWNER_PET"][ownerName][SW_PRINT_ITEM_TOTAL_DONE] = {0,0};
905 SW_PetInfo["OWNER_PET"][ownerName][SW_PRINT_ITEM_RECIEVED] = {0,0};
906 end
907 -- very odd had a report so added this, why would this be needed?
908 -- ah ok if its inited through the sync channel this is needed.
909 if SW_PetInfo["OWNER_PET"][ownerName]["pets"] == nil then
910 SW_PetInfo["OWNER_PET"][ownerName]["pets"] = {};
911 end
912  
913 if SW_PetInfo["OWNER_PET"][ownerName]["pets"][unitPetName] == nil then
914 SW_PetInfo["OWNER_PET"][ownerName]["pets"][unitPetName] = {};
915 SW_PetInfo["OWNER_PET"][ownerName]["pets"][unitPetName][SW_PRINT_ITEM_TOTAL_DONE] = {0,0};
916 SW_PetInfo["OWNER_PET"][ownerName]["pets"][unitPetName][SW_PRINT_ITEM_RECIEVED] = {0,0};
917 end
918 SW_PetInfo["OWNER_PET"][ownerName]["currentPet"] = unitPetName;
919  
920 --SW_Pets[unitPetName] = ownerName;
921 if SW_Friends[ownerName] == nil then
922 SW_Friends[ownerName] = {};
923 SW_Friends[ownerName]["PETS"] = {};
924 elseif SW_Friends[ownerName]["PETS"] == nil then
925 SW_Friends[ownerName]["PETS"] = {};
926 end
927 SW_Friends[ownerName]["PETS"][unitPetName] = 1;
928 end
929 end
930 -- creats the "friends" list
931 -- self, group members, or raid members
932 function SW_Make_Friends(gType)
933 local name, rank,sg,lev;
934 local namePet;
935 local playerClass, englishClass = UnitClass("player");
936 SW_ClassNames[englishClass] = playerClass;
937  
938 SW_Friends = {[SW_SELF_STRING]=
939 {["CLASS"] = playerClass, ["CLASSE"] = englishClass, ["UnitID"]="player", ["L"] = UnitLevel("player")},
940 };
941 --1.4.2 add rank info when we are alone will be overwritten if in raid/group
942 SW_Friends[SW_SELF_STRING]["Rank"] = 0;
943  
944 --update pet info
945 SW_PetsResetOwners();
946 SW_UpdatePet("player");
947  
948 --[[
949 1.4.2 Changed to GetRaidRosterInfo need rank info now
950 probably could use class and fileName instead of UnitClass(...)
951 --]]
952 if gType == "RAID" then
953 for i=1, GetNumRaidMembers() do
954 --name =UnitName("raid"..i);
955 --name, rank, subgroup, level, class, fileName, zone, online, isDead = GetRaidRosterInfo(i)
956 name, rank,sg,lev = GetRaidRosterInfo(i);
957 if name ~= nil then
958 playerClass, englishClass = UnitClass("raid"..i);
959 if englishClass ~= nil and playerClass ~= nil then
960 SW_ClassNames[englishClass] = playerClass;
961 SW_Friends[name] = {["CLASS"] = playerClass, ["CLASSE"] = englishClass, ["UnitID"]="raid"..i, ["Rank"]=rank, ["L"] = lev };
962 end
963  
964 SW_UpdatePet("raid"..i);
965 end
966  
967 end
968 return;
969 end
970  
971 if gType == "GROUP" then
972 for i=1, GetNumPartyMembers() do
973 name =UnitName("party"..i);
974 if name ~= nil then
975 playerClass, englishClass = UnitClass("party"..i);
976 if UnitIsPartyLeader("party"..i) then
977 rank = 2;
978 else
979 rank = 0;
980 end
981 if englishClass ~= nil and playerClass ~= nil then
982 SW_ClassNames[englishClass] = playerClass;
983 SW_Friends[name] = {["CLASS"] = playerClass, ["CLASSE"] = englishClass, ["UnitID"]="party"..i, ["Rank"]=rank, ["L"] = UnitLevel("party"..i)};
984 end
985  
986 SW_UpdatePet("party"..i);
987 end
988 end
989 --1.4.2 check self as party leader
990 if IsPartyLeader() then
991 SW_Friends[SW_SELF_STRING]["Rank"] = 2;
992 end
993 return;
994 end
995  
996 end
997  
998 --[[
999 SW_TestState = {
1000 _memberVar,
1001 Test = function (self, test)
1002 self._memberVar = test;
1003 x=0;
1004 for i=1, 1000000 do
1005 x=x+1;
1006  
1007 end
1008 if self._memberVar == test then
1009 SW_printStr(test.." OK");
1010 else
1011 SW_printStr(test.." FAILED");
1012 end
1013 end,
1014 }
1015 --]]
1016  
1017 SW_Timed_Calls = {
1018  
1019 deltaPending = 0.5, -- 1.4 beta 5 increased + 0.1
1020 passedPendig =0,
1021 pendingActive = false,
1022  
1023 deltaResize = 0.5,
1024 passedResize = 0,
1025  
1026 deltaSySend = 1.1, -- + 0.1 in 1.2.4 a few more checks going on
1027 passedSySend = 0,
1028  
1029 deltaSyDo = 5,
1030 passedSyDo = 0,
1031  
1032 deltaSyLI = 100, -- lowerd to 100
1033 passedSyLI = 0,
1034  
1035 retryUnknownObject = false, -- added in 1.5 pet mechanics using SyDo timer
1036 pendingJoin = false, -- added in 1.5 for sync joining, using SySend timer
1037 checkJoin = false, -- added in 1.5 for checking if we REALLY are in the chan, using SySend timer
1038  
1039 OnUpdate = function (self, elapsed)
1040 self.passedResize = self.passedResize + elapsed;
1041 self.passedSySend = self.passedSySend + elapsed;
1042 self.passedSyDo = self.passedSyDo + elapsed;
1043 self.passedSyLI = self.passedSyLI + elapsed;
1044  
1045 if (SW_CombatTimeInfo.awaitingEnd) then
1046 SW_CombatTime = SW_CombatTime + elapsed;
1047 end
1048 if self.pendingActive then
1049 self.passedPendig = self.passedPendig + elapsed;
1050 if self.passedPendig > self.deltaPending then
1051 self.pendingActive = false;
1052 self.passedPendig = 0;
1053 SW_AcceptPendingCast();
1054 end
1055 end
1056 if self.passedResize > self.deltaResize then
1057 if SW_SomethingResizing then
1058 SW_BarLayoutRegisterdOnResize();
1059 end
1060 self.passedResize = 0;
1061 end
1062 if self.passedSySend > self.deltaSySend then
1063  
1064 -- added 1.5.3 for raid per second info
1065 SW_RPS:updateInfo();
1066  
1067 -- added in 1.5 joining a chan is now on a short timer
1068 -- to allow exit of old sync chan first
1069 if self.checkJoin then
1070 self.checkJoin = false;
1071 SW_SyncJoinedCheck();
1072 end
1073 if self.pendingJoin then
1074 self.pendingJoin = false;
1075 SW_SyncJoinPending();
1076 end
1077  
1078 SW_SyncSend();
1079 -- added 1.5.beta.1 for voting system
1080 SW_UpdateVoteTimers(self.deltaSySend);
1081  
1082  
1083 if not SW_SomethingResizing then
1084 SW_UpdateBars();
1085 end
1086 self.passedSySend = 0;
1087 end
1088 if self.passedSyDo > self.deltaSyDo then
1089 -- added in 1.5 this should only happen when logging in
1090 if self.retryUnknownObject then
1091 self.retryUnknownObject = false;
1092 --SW_printStr("UNKNOWNOBJECT timer fired");
1093 SW_RebuildFriendList();
1094 end
1095 SW_SyncDo();
1096 self.passedSyDo = 0;
1097 end
1098 if self.passedSyLI > self.deltaSyLI then
1099 SW_SyncCheckAlive();
1100 self.passedSyLI = 0;
1101 end
1102 end,
1103  
1104 StopPending = function (self)
1105 self.pendingActive = false;
1106 self.passedPendig = 0;
1107 end,
1108 StartPending = function (self)
1109 self.pendingActive = true;
1110 end,
1111  
1112 StartJoinChanPending = function (self)
1113 self.passedSySend = 0;
1114 self.pendingJoin = true;
1115 end,
1116 StopJoinChanPending = function (self)
1117 self.pendingJoin = false;
1118 end,
1119 StartCheckChan = function (self)
1120 self.passedSySend = 0;
1121 self.checkJoin = true;
1122 end,
1123 StopCheckChan = function (self)
1124 self.checkJoin = false;
1125 end,
1126 };
1127 -- this doesnt work like intended, eg talking to nef starts this oO
1128 --[[
1129 function SW_RaidInfightUpdate()
1130 local indi = getglobal("SW_BarFrame1_Title_InFight");
1131 for k,v in pairs(SW_Friends) do
1132 if v["UnitID"] ~= nil then
1133 if UnitAffectingCombat(v["UnitID"]) then
1134 indi.NormalT:SetVertexColor(0,1,0,1);
1135 return;
1136 end
1137 end
1138 end
1139 indi.NormalT:SetVertexColor(1,0,0,1);
1140 end
1141 --]]
1142 function SW_AddDeath(name)
1143 if name == nil then return; end
1144  
1145 if SW_S_Details[name] == nil then
1146 SW_S_Details[name] = {};
1147 SW_S_Details[name][SW_PRINT_ITEM_TOTAL_DONE] = {0,0};
1148 SW_S_Details[name][SW_PRINT_ITEM_RECIEVED] = {0,0};
1149 SW_S_Details[name][SW_PRINT_ITEM_TYPE] = {};
1150 end
1151 if SW_S_Details[name][SW_PRINT_ITEM_DEATHS] == nil then
1152 SW_S_Details[name][SW_PRINT_ITEM_DEATHS] = 1;
1153 else
1154 SW_S_Details[name][SW_PRINT_ITEM_DEATHS] = SW_S_Details[name][SW_PRINT_ITEM_DEATHS] + 1;
1155 end
1156 end
1157 function SW_HandleDeath(msg)
1158 if msg == nil then return; end
1159  
1160 if msg == UNITDIESSELF then
1161 SW_AddDeath(SW_SELF_STRING);
1162 else
1163 local _,_, deadGuy = string.find(msg, SW_DeathRegEx);
1164 SW_AddDeath(deadGuy);
1165 end
1166 end
1167  
1168  
1169 --[[
1170 Note to self, add HPS aswell
1171 --]]
1172 SW_C_RPS ={
1173 filters = {["SF"] = "SW_Filter_EverGroup", ["PF"] = "SW_PF_VPR"},
1174  
1175 new = function (self, o)
1176 local doResetInit = true;
1177 if o then
1178 doResetInit = false;
1179 else
1180 o = {};
1181 end
1182 setmetatable(o, self);
1183 self.__index = self;
1184  
1185 o.baseTimer = SW_C_Timer:new(o.baseTimer);
1186 o.startTimer = SW_C_Timer:new(o.startTimer);
1187  
1188 if doResetInit then
1189 o:resetDPS();
1190 end
1191 return o;
1192 end,
1193 resetDPS = function(self)
1194 self.isRunning = false;
1195 self.allowLastFightUpdate = false;
1196 self.currentSecs = 0;
1197 self.totalSecs = 0;
1198 self.lastFightSecs = 0;
1199 self.startDmg = 0;
1200 self.maxDPS = 0;
1201 self.lastFightDmg = 0;
1202 self.uglyTruthStarted = false;
1203 self.resetPoint = self:getDmg();
1204 SW_BarFrame1_Title_SyncIcon:UpdateColor(SW_Settings["Colors"]["Heal"]);
1205 end,
1206  
1207 validEvent = function (self)
1208 self.lastEvent = self.baseTimer:now();
1209  
1210 -- even with the ugly truth time be so nice to wait for first dmg
1211 if not self.uglyTruthStarted then
1212 self.uglyTruthStarted = true;
1213 self.baseTimer:setToNow();
1214 end
1215 if not self.isRunning then
1216 self.startTimer:setToNow();
1217 self.allowLastFightUpdate = false;
1218 self.startDmg = self:getDmg();
1219 self.isRunning = true;
1220 SW_BarFrame1_Title_SyncIcon:UpdateColor(SW_Settings["Colors"]["Damage"]);
1221 end
1222 end,
1223 updateInfo = function (self)
1224 if not self.isRunning then return; end
1225 local deltaT = self.startTimer:now() - self.lastEvent;
1226 if deltaT > 6 then -- a buffer to keep you "in fight" 1.5.3.beta.1 changed from 5 to 6 (late sync msgs)
1227 self.isRunning = false;
1228 self.currentSecs = 0;
1229 deltaT = self.lastEvent - self.startTimer;
1230 if deltaT < 1 then deltaT = 1; end -- 1 sec minimum fight time
1231 self.totalSecs = self.totalSecs + deltaT;
1232 self.lastFightSecs = deltaT;
1233 self.allowLastFightUpdate = true;
1234 SW_BarFrame1_Title_SyncIcon:UpdateColor(SW_Settings["Colors"]["Heal"]);
1235 else
1236 self.currentSecs = self.startTimer:elapsed();
1237 SW_BarFrame1_Title_SyncIcon:UpdateColor(SW_Settings["Colors"]["Damage"]);
1238 end
1239 end,
1240  
1241 getDmg = function(self)
1242 local snap = SW_GetDmgInfo("SW_Filter_EverGroup", nil, "SW_PF_VPR", self.filters);
1243 local total = 0;
1244 for i,v in ipairs(snap) do
1245 total = total + v[2];
1246 end
1247 return total;
1248 end,
1249  
1250 getVals = function (self)
1251 local ret = {};
1252 local currDmg = self:getDmg();
1253 local currDelta = currDmg - self.startDmg;
1254  
1255 if self.currentSecs == 0 then
1256 ret[1] = 0;
1257 else
1258 if self.currentSecs < 1 then
1259 ret[1] = math.floor(currDelta *100 + 0.5)/100;
1260 else
1261 ret[1] = math.floor((currDelta / self.currentSecs) *100 + 0.5)/100;
1262 end
1263 end
1264  
1265 if self.totalSecs == 0 and self.currentSecs == 0 then
1266 ret[2] = 0;
1267 else
1268 --SW_printStr((currDmg - self.resetPoint)..".."..(self.totalSecs + self.currentSecs));
1269 ret[2] = math.floor(((currDmg - self.resetPoint) / (self.totalSecs + self.currentSecs)) *100 + 0.5)/100;
1270 end
1271  
1272 if self.lastFightSecs == 0 then
1273 ret[3] = 0;
1274 else
1275 if self.allowLastFightUpdate then
1276 -- only point of this is to accept late sync messages
1277 -- in testing this made (almost) no difference
1278 self.lastFightDmg = currDelta;
1279 end
1280 ret[3] = math.floor((self.lastFightDmg / self.lastFightSecs) *100 + 0.5)/100;
1281 end
1282  
1283 if self.uglyTruthStarted then
1284 ret[4] = math.floor(((currDmg - self.resetPoint) / self.baseTimer:elapsed()) *100 + 0.5)/100;
1285 end
1286  
1287 if not self.isRunning or self.currentSecs > 5 then
1288 for i,v in ipairs(ret) do
1289 if v > self.maxDPS then
1290 self.maxDPS = v;
1291 end
1292 end
1293 end
1294 return ret;
1295 end,
1296  
1297  
1298 dump = function (self)
1299 SW_DumpTable(self);
1300 end,
1301 }
1302  
1303 function SW_Stats_OnEvent()
1304 if (event == "VARIABLES_LOADED") then
1305 -- init code will go here considering saved vars
1306 -- 1.5 Current pet ownership reset, will be updated through other events on login
1307 SW_PetsResetOwners();
1308  
1309 -- 1.5.1 decurseing, could be used for more
1310 SW_CreateSpellIDLookup();
1311 -- 1.5 added pausing, default to running for old versions and new installs
1312 if SW_Settings["IsRunning"] == nil then
1313 SW_Settings["IsRunning"] = true;
1314 end
1315 if SW_Settings["IsRunning"] then
1316 SW_UnpauseEvents();
1317 end
1318  
1319 if SW_Map == nil then
1320 SW_Map = SW_DefaultMap;
1321 else
1322 if SW_Settings["LAST_V_RUN"] == nil then
1323 SW_Map = SW_DefaultMap;
1324 SW_Fallback_Block = {};
1325 else
1326 if SW_Settings["LAST_V_RUN"] ~= SW_VERSION then
1327 SW_Map = SW_DefaultMap;
1328 SW_Fallback_Block = {};
1329 SW_ResetInfo();
1330 end
1331 end
1332 end
1333  
1334 SW_DefaultMap = nil;
1335 if SW_EnviroMap == nil then
1336 SW_EnviroMap ={};
1337 end
1338 SW_CreateEventRegexMap();
1339 SW_SL_Finalize();
1340 SW_SELF_STRING = UnitName("player");
1341  
1342 if SW_Settings["SyncBCTarget"] == nil then
1343 SW_Settings["SyncBCTarget"] = "SW_BarSyncFrame_OptRaid";
1344 end
1345 -- sets the checkboxes to saved values
1346 SW_SetChkStates();
1347 SW_Event_Channel = getglobal("SW_FrameConsole_Text2_MsgFrame");
1348 SW_EI_ALLOFF = not (SW_Settings["EI_ShowRegEx"] or SW_Settings["EI_ShowMatch"]
1349 or SW_Settings["EI_ShowEvent"] or SW_Settings["EI_ShowOrigStr"]);
1350  
1351 SW_Settings["LAST_V_RUN"] = SW_VERSION;
1352 if SW_Settings["QuickOptCount"] == nil then
1353 SW_Settings["QuickOptCount"] = 5;
1354 end
1355 SW_UpdateOptVis();
1356  
1357 -- wow what a headache, an addon called sweep overwrites this with a number oO
1358 -- causing all sorts of problems
1359 -- it's not great just to skip it but we can get along without seeding the generator
1360 if type(math.randomseed) == "function" then
1361 math.randomseed( time() );
1362 else
1363 SW_printStr("math.randomseed is not a funtion... it should be");
1364 end
1365 -- localize gui
1366 for k,v in pairs(SW_GUI) do
1367 --if its not a table the key is a direct map to the string
1368 if type(v) ~= "table" then
1369 getglobal(k):SetText(v);
1370 else
1371 --[[v["f"] is the function
1372 k is the identifier for the function
1373 v["s"] is the string
1374 ]]--
1375 v["f"](k,v["s"]);
1376 end
1377  
1378 end
1379 -- done localizing gui.. drop table
1380 SW_GUI = nil;
1381 -- do layout of items
1382 SW_DoLayout();
1383 SW_SyncInit();
1384 if SW_Settings["ReportAmount"] == nil then
1385 SW_Settings["ReportAmount"] = 5;
1386 end
1387 if SW_Settings["Colors"] == nil then
1388 SW_Settings["Colors"] = {};
1389 end
1390 for k,v in pairs(SW_Default_Colors) do
1391 if SW_Settings["Colors"][k] == nil then
1392 SW_Settings["Colors"][k] = v;
1393 end
1394 end
1395  
1396  
1397 if ButtonHole then
1398 ButtonHole.application.RegisterMod({id="SW_STATS_BH_HOOK",
1399 name="SW Stats",
1400 tooltip="SW Stats",
1401 buttonFrame="SW_IconFrame",
1402 updateFunction="SW_UpdateIconPos"});
1403 else
1404 SW_UpdateIconPos();
1405 end
1406  
1407 --1.5.3 default color mechaniks changed
1408 if SW_Settings["Colors"]["TitleBars"] == nil then
1409 SW_Settings["Colors"]["TitleBars"] = {1,0,0,1};
1410 end
1411 SW_UpdateTitleColor(SW_Settings["Colors"]["TitleBars"]);
1412 if SW_Settings["Colors"]["TitleBarsFont"] == nil then
1413 SW_Settings["Colors"]["TitleBarsFont"] = {1,1,1,1};
1414 end
1415 SW_UpdateTitleTextColor(SW_Settings["Colors"]["TitleBarsFont"]);
1416 if SW_Settings["Colors"]["Backdrops"] == nil then
1417 SW_Settings["Colors"]["Backdrops"] = {SW_COLOR_ACT["r"],SW_COLOR_ACT["g"],SW_COLOR_ACT["b"],1};
1418 end
1419 SW_UpdateFrameBackdrops(SW_Settings["Colors"]["Backdrops"]);
1420 if SW_Settings["Colors"]["MainWinBack"] == nil then
1421 SW_Settings["Colors"]["MainWinBack"] = {0,0,0,0.6};
1422 end
1423 SW_UpdateMainWinBack(SW_Settings["Colors"]["MainWinBack"])
1424  
1425 -- 1.5.3 Sync Icon
1426 if SW_Settings["SYNCLastChan"] ~= nil then
1427 SW_BarFrame1_Title_SyncIcon:Show();
1428 SW_BarFrame1_Title_SyncIcon:UpdateColor(SW_Settings["Colors"]["Heal"]);
1429 end
1430 --1.5.3 retaining vis of the main window
1431 if SW_Settings["SHOWMAIN"] then
1432 SW_BarFrame1:Show();
1433 end
1434 -- 1.5.3.beta.1 locking frames
1435 SW_LockFrames(SW_Settings["BFLocked"]);
1436  
1437 -- 1.5.3 Raid dps info
1438 SW_RPS = SW_C_RPS:new(SW_RPS);
1439 --SW_ToggleConsole();
1440 elseif (event == "PLAYER_TARGET_CHANGED") then
1441 local unitName = UnitName("target");
1442 if unitName == nil then return; end
1443 local localizedClass, englishClass = UnitClass("target");
1444 --1.0.2 added this, could happen with far away pets
1445 if localizedClass == nil or englishClass == nil then return; end
1446  
1447 SW_ClassNames[englishClass] = localizedClass;
1448  
1449 -- ignore if we dont have info
1450 if SW_S_Details[unitName] == nil then return; end
1451  
1452 SW_S_Details[unitName]["CLASSE"] = englishClass;
1453  
1454 --1.5 added GPC and GPET
1455 if UnitPlayerControlled("target") then
1456 if SW_Friends[unitName] ~= nil then
1457 SW_S_Details[unitName]["UTYPE"] = "GPC";
1458 elseif SW_PetInfo["PET_OWNER"][from] ~= nil then
1459 -- don't mark MC'd mobs as gpet
1460 if SW_S_Details[unitName]["UTYPE"] ~= "NPC" then
1461 SW_S_Details[unitName]["UTYPE"] = "GPET";
1462 end
1463 else
1464 SW_S_Details[unitName]["UTYPE"] = "PC";
1465 end
1466 else
1467 SW_S_Details[unitName]["UTYPE"] = "NPC";
1468 end
1469 --[[
1470 if UnitIsEnemy("player", "target") then
1471 SW_printStr("ENEMY");
1472 else
1473 SW_printStr("Friend");
1474 end
1475 --]]
1476 elseif (event == "SPELLS_CHANGED") then
1477 -- update if we learn new spells
1478 if arg1 == nil then
1479 SW_UpdateCastByNameLookup();
1480 end
1481 elseif (event == "SPELLCAST_CHANNEL_START") then
1482 --SW_printStr("-CHANNELSTART-");
1483 SW_AcceptSelectedCast();
1484 --[[elseif (event == "SPELLCAST_START") then
1485 SW_printStr("-START-"); ]]--
1486 elseif (event == "SPELLCAST_STOP") then
1487 --SW_printStr("-SPELLCAST_STOP- :");
1488 --SW_printStr(SW_SelectedSpell[1]);
1489 if SW_SelectedSpell[1] ~= nil then
1490 --SW_printStr("-SPELLCAST_STOP:"..SW_SelectedSpell[1]);
1491 -- is this an instant ?
1492 if SW_SelectedSpell[3] then
1493 SW_AcceptSelectedCast();
1494 else
1495 SW_PendingCast[1] = SW_SelectedSpell[1];
1496 SW_PendingCast[2] = SW_SelectedSpell[2];
1497 SW_SelectedSpell = {};
1498 --SW_printStr("-STOP NP-"..SW_PendingCast[1]);
1499 SW_Timed_Calls:StartPending();
1500 end
1501 end
1502 elseif event == "SPELLCAST_FAILED" or event == "SPELLCAST_INTERRUPTED" then
1503 --SW_printStr("-SPELLCAST_FAIL-");
1504 SW_Timed_Calls:StopPending();
1505 SW_SelectedSpell = {};
1506 SW_PendingCast = {};
1507 elseif (event == "CHAT_MSG_GUILD") then
1508 SW_SyncCheckMsgForChan(arg1,arg2);
1509 elseif (event == "CHAT_MSG_OFFICER") then
1510 SW_SyncCheckMsgForChan(arg1,arg2);
1511 elseif (event == "CHAT_MSG_PARTY") then
1512 SW_SyncCheckMsgForChan(arg1,arg2);
1513 elseif (event == "CHAT_MSG_RAID") then
1514 SW_SyncCheckMsgForChan(arg1,arg2);
1515 elseif (event == "CHAT_MSG_RAID_LEADER") then
1516 SW_SyncCheckMsgForChan(arg1,arg2);
1517 elseif (event == "CHAT_MSG_CHANNEL") then
1518 if arg8 == SW_SyncChanID then
1519 SW_SyncHandleMsg(arg1, arg2);
1520 end
1521 --elseif (event == "CHAT_MSG_SAY") then
1522 -- SW_SyncCheckMsgForChan(arg1,arg2);
1523  
1524 elseif (event == "PLAYER_ENTERING_WORLD") then
1525 --bar layout needs to go here, only then the "saved (layout-cache.txt)" layout is loaded already
1526 SW_BarLayoutRegisterd();
1527 if GetNumRaidMembers() > 0 then
1528 SW_Make_Friends("RAID");
1529 elseif GetNumPartyMembers() > 0 then
1530 SW_Make_Friends("GROUP");
1531 else
1532 SW_Make_Friends();
1533 end
1534 SW_UpdateCastByNameLookup();
1535  
1536 elseif (event == "UNIT_PET") then
1537 --SW_printStr("UNIT_PET "..arg1);
1538 SW_UpdatePet(arg1);
1539 elseif (event == "PARTY_MEMBERS_CHANGED") or (event == "PARTY_LEADER_CHANGED") then
1540 --SW_printStr("PARTY_MEMBERS_CHANGED ");
1541 if UnitInRaid("player") then
1542 return;
1543 end
1544 SW_Make_Friends("GROUP");
1545 elseif (event == "RAID_ROSTER_UPDATE") then
1546 SW_Make_Friends("RAID");
1547 local sf = getglobal("SW_BarSyncFrame");
1548 if sf:IsVisible() then
1549 sf:UpdateARPVis();
1550 end
1551 elseif (event == "CHAT_MSG_COMBAT_FRIENDLY_DEATH") then
1552 SW_HandleDeath(arg1);
1553 elseif (event == "CHAT_MSG_COMBAT_HOSTILE_DEATH") then
1554 SW_HandleDeath(arg1);
1555 elseif (event == "PLAYER_REGEN_DISABLED") then
1556 SW_CombatTimeInfo.awaitingStart = true;
1557 elseif (event == "PLAYER_REGEN_ENABLED") then
1558 SW_CombatTimeInfo.awaitingStart = false;
1559 SW_CombatTimeInfo.awaitingEnd = false;
1560 else
1561 SW_DoEvent(event);
1562 end
1563 end
1564 if not SW_DEV_INWOW then
1565 SW_SL_Add(SW_SL["START"]);
1566 SW_CreateRegexFromGlobals();
1567 SW_CreateEventRegexMap();
1568 SW_SL_Finalize();
1569 SW_Test();
1570 end