vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 local dewdrop = AceLibrary("Dewdrop-2.0")
2 local tablet = AceLibrary("Tablet-2.0")
3 local parser = ParserLib:GetInstance('1.1')
4 local compost = AceLibrary("Compost-2.0")
5  
6 local L = AceLibrary("AceLocale-2.0"):new("FuBar_DPS")
7  
8 FuBar_DPS = AceLibrary("AceAddon-2.0"):new("FuBarPlugin-2.0", "AceEvent-2.0", "AceConsole-2.0", "AceDB-2.0", "Metrognome-2.0" )
9  
10 FuBar_DPS:RegisterDB("FuBar_DPS_DB")
11 FuBar_DPS:RegisterDefaults('profile', {
12 myDmgDone = true,
13 myDmgTaken = true
14 })
15  
16 local _, isPetClass = UnitClass('player')
17 if not (isPetClass == "WARLOCK" or isPetClass == "HUNTER" ) then
18 isPetClass = nil
19 end
20  
21 local OnCombatEvent = function(event, info)
22 FuBar_DPS:OnCombatEvent(event, info);
23 end
24  
25 local optionsTable = {
26 type = 'group',
27 args = {
28 player = {
29 order = 1,
30 type = 'group',
31 name = L["MENU_PLAYER"],
32 desc = L["TOOLTIP_PLAYER"],
33 args = {
34 dps = {
35 order = 1,
36 type = 'toggle',
37 name = L["myDmgDone"],
38 desc = L["myDmgDone"],
39 set = 'SetMyDmgDone',
40 get = 'IsMyDmgDone',
41 },
42 dtps = {
43 order = 2,
44 type = 'toggle',
45 name = L["myDmgTaken"],
46 desc = L["myDmgTaken"],
47 set = 'SetMyDmgTaken',
48 get = 'IsMyDmgTaken',
49 },
50 hps = {
51 order = 3,
52 type = 'toggle',
53 name = L["myHealDone"],
54 desc = L["myHealDone"],
55 set = 'SetMyHealDone',
56 get = 'IsMyHealDone',
57 },
58 htps = {
59 order = 4,
60 type = 'toggle',
61 name = L["myHealTaken"],
62 desc = L["myHealTaken"],
63 set = 'SetMyHealTaken',
64 get = 'IsMyHealTaken',
65 },
66 },
67 },
68 hideLabel = {
69 order = 5,
70 type = 'toggle',
71 name = L["MENU_HIDE_LABEL"],
72 desc = L["MENU_HIDE_LABEL"],
73 set = 'SetHideLabel',
74 get = "IsHideLabel",
75 },
76 reset = {
77 order = 7,
78 type = 'execute',
79 name = L["MENU_RESET"],
80 desc = L["MENU_RESET"],
81 func = 'ResetSession',
82 }
83  
84 }
85 }
86  
87 FuBar_DPS.eventList = {
88 "CHAT_MSG_COMBAT_CREATURE_VS_SELF_HITS",
89 "CHAT_MSG_COMBAT_HOSTILEPLAYER_HITS",
90 "CHAT_MSG_COMBAT_SELF_HITS",
91 "CHAT_MSG_SPELL_CREATURE_VS_SELF_BUFF",
92 "CHAT_MSG_SPELL_CREATURE_VS_SELF_DAMAGE",
93 "CHAT_MSG_SPELL_DAMAGESHIELDS_ON_OTHERS",
94 "CHAT_MSG_SPELL_DAMAGESHIELDS_ON_SELF",
95 "CHAT_MSG_SPELL_FRIENDLYPLAYER_BUFF",
96 -- "CHAT_MSG_SPELL_FRIENDLYPLAYER_DAMAGE",
97 "CHAT_MSG_SPELL_HOSTILEPLAYER_BUFF",
98 -- "CHAT_MSG_SPELL_HOSTILEPLAYER_DAMAGE",
99 "CHAT_MSG_SPELL_PARTY_BUFF",
100 -- "CHAT_MSG_SPELL_PARTY_DAMAGE",
101 "CHAT_MSG_SPELL_PERIODIC_CREATURE_BUFFS",
102 "CHAT_MSG_SPELL_PERIODIC_CREATURE_DAMAGE",
103 "CHAT_MSG_SPELL_PERIODIC_FRIENDLYPLAYER_BUFFS",
104 "CHAT_MSG_SPELL_PERIODIC_FRIENDLYPLAYER_DAMAGE",
105 "CHAT_MSG_SPELL_PERIODIC_HOSTILEPLAYER_BUFFS",
106 "CHAT_MSG_SPELL_PERIODIC_HOSTILEPLAYER_DAMAGE",
107 "CHAT_MSG_SPELL_PERIODIC_PARTY_BUFFS",
108 "CHAT_MSG_SPELL_PERIODIC_PARTY_DAMAGE",
109 "CHAT_MSG_SPELL_PERIODIC_SELF_BUFFS",
110 "CHAT_MSG_SPELL_PERIODIC_SELF_DAMAGE",
111 "CHAT_MSG_SPELL_SELF_BUFF",
112 "CHAT_MSG_SPELL_SELF_DAMAGE",
113 "CHAT_MSG_COMBAT_PET_HITS",
114 "CHAT_MSG_SPELL_PET_BUFF",
115 "CHAT_MSG_SPELL_PET_DAMAGE",
116 }
117  
118 FuBar_DPS.myDPS = { "myDmgDone", "myDmgTaken", "myHealDone", "myHealTaken" }
119 FuBar_DPS.petDPS = {}
120 FuBar_DPS.colors = {
121 myDmgDone = "ff0000",
122 myDmgTaken = "ff7f00",
123 myHealDone = "00ff00",
124 myHealTaken = "2020ff",
125 petDmgDone = "ff3030",
126 petDmgTaken = "ff7f30",
127 petHealDone = "30ff30",
128 petHealTaken = "5050ff",
129 }
130  
131 FuBar_DPS.stats = {
132 session = {
133 myDmgDone = 0,
134 myDmgTaken = 0,
135 myHealDone = 0,
136 myHealTaken = 0,
137 duration = 0,
138 },
139 last = {
140 myDmgDone = 0,
141 myDmgTaken = 0,
142 myHealDone = 0,
143 myHealTaken = 0,
144 duration = 0,
145 },
146 }
147  
148 FuBar_DPS.vars = {
149 inCombat = false
150 }
151  
152  
153  
154 function FuBar_DPS:OnInitialize()
155  
156 self:RegisterEvent("PLAYER_REGEN_DISABLED")
157 self:RegisterEvent("PLAYER_REGEN_ENABLED")
158 self:RegisterMetro(self.name, self.TickCombat, 1, self)
159  
160 if isPetClass then
161 self:InitializePetClass()
162 end
163  
164 end
165  
166 function FuBar_DPS:OnEnable()
167 for i, event in self.eventList do
168 parser:RegisterEvent(self.name, event, OnCombatEvent)
169 end
170 end
171  
172 function FuBar_DPS:OnDisable()
173 parser:UnregisterAllEvents(self.name)
174 end
175  
176 function FuBar_DPS:PLAYER_REGEN_DISABLED()
177 for i in self.stats.last do
178 self.stats.last[i] = 0
179 end
180 self.vars.inCombat = true;
181 self:StartMetro(self.name)
182 end
183  
184 function FuBar_DPS:PLAYER_REGEN_ENABLED()
185 self:StopMetro(self.name)
186 for i, v in self.stats.last do
187 self.stats.session[i] = self.stats.session[i] + v
188 end
189 self.vars.inCombat = false
190 end
191  
192 function FuBar_DPS:OnCombatEvent(event, info)
193  
194 if self.vars.inCombat then
195  
196 if info.type == "hit" then
197  
198 if info.source == ParserLib_SELF then
199 self.stats.last.myDmgDone = self.stats.last.myDmgDone + tonumber(info.amount);
200 elseif isPetClass and info.source == UnitName("pet") then
201 self.stats.last.petDmgDone = self.stats.last.petDmgDone + tonumber(info.amount);
202 end
203  
204 if info.victim == ParserLib_SELF then
205 self.stats.last.myDmgTaken = self.stats.last.myDmgTaken + tonumber(info.amount);
206 elseif isPetClass and info.victim == UnitName("pet") then
207 self.stats.last.petDmgTaken = self.stats.last.petDmgTaken + tonumber(info.amount);
208 end
209  
210 elseif info.type == "heal" then
211  
212 if info.source == ParserLib_SELF then
213 self.stats.last.myHealDone = self.stats.last.myHealDone + tonumber(info.amount);
214 elseif isPetClass and info.source == UnitName("pet") then
215 self.stats.last.petHealDone = self.stats.last.petHealDone + tonumber(info.amount);
216 end
217  
218 if info.victim == ParserLib_SELF then
219 self.stats.last.myHealTaken = self.stats.last.myHealTaken + tonumber(info.amount);
220 elseif isPetClass and info.victim == UnitName("pet") then
221 self.stats.last.petHealTaken = self.stats.last.petHealTaken + tonumber(info.amount);
222 end
223  
224 end
225  
226 end
227  
228  
229 end
230  
231  
232  
233 function FuBar_DPS:TickCombat(difference)
234 self.stats.last.duration = self.stats.last.duration + difference
235 self:Update()
236 end
237  
238 function FuBar_DPS:GetDPS(category, field)
239 local duration = self.stats[category].duration
240 if duration < 1 then duration = 1 end
241 return string.format("|cff%s%.1f|r", self.colors[field], self.stats[category][field] / duration)
242 end
243  
244  
245  
246 function FuBar_DPS:ResetSession()
247 for i in self.stats.session do
248 self.stats.session[i] = 0
249 end
250 end
251  
252 function FuBar_DPS:OnTextUpdate()
253  
254 local label, text, petLabel, petText
255  
256 if not self.db.profile.hideLabel then
257 label = L.LABEL_DPS
258 petLabel = L.LABEL_PET
259 end
260  
261 if isPetClass and self.db.profile.mergeDPS then
262 self:SetAddedStats();
263 end
264  
265 text = ""
266 for i, v in self.myDPS do
267 if self.db.profile[v] then text = text .. "/" .. self:GetDPS("last", v) end
268 end
269 if string.sub(text, 1, 1) == "/" then text = string.sub(text, 2) end
270 if text == "" then label = "" end
271  
272 if isPetClass and self.db.profile.mergeDPS then
273 self:UnsetAddedStats();
274 end
275  
276 petText = ""
277 for i, v in self.petDPS do
278 if self.db.profile[v] then petText = petText .. "/" .. self:GetDPS("last", v) end
279 end
280 if string.sub(petText, 1, 1) == "/" then petText = string.sub(petText, 2) end
281 if petText == "" then petLabel = nil end
282  
283 -- Do not turn everything off!
284 if text == "" and not label and petText == "" and not petLabel then
285 label = L.LABEL_DPS
286 end
287  
288 local t = compost:Acquire()
289 if label then table.insert(t, label) end
290 if text ~= "" then table.insert(t, text) end
291 if petLabel then table.insert(t, petLabel) end
292 if petText ~= "" then table.insert(t, petText) end
293 self:SetText( table.concat(t, " ") )
294 compost:Reclaim(t)
295  
296 end
297  
298 function FuBar_DPS:OnTooltipUpdate()
299  
300 if not self.statsCats then
301 self.statsCats = { 'session', 'last' }
302 end
303  
304 for i, statsCat in self.statsCats do
305  
306 local cat = tablet:AddCategory(
307 'columns', 3,
308 'text', L[statsCat],
309 'text2', string.format("%ds", self.stats[statsCat].duration),
310 'text3', L.TOTAL,
311 'child_textR', 1,
312 'child_textG', 1,
313 'child_textB', 0
314 );
315  
316 if isPetClass and self.db.profile.showPetTooltip then
317 cat:AddLine(
318 'text', string.format("|cffeda55f%s|r", L.MENU_PLAYER)
319 )
320 end
321  
322 for i, statsType in self.myDPS do
323 cat:AddLine(
324 'text', L[statsType],
325 'text2', self:GetDPS(statsCat, statsType),
326 'text3', self.stats[statsCat][statsType]
327 );
328 end
329  
330 if isPetClass and self.db.profile.showPetTooltip then
331 cat:AddLine(
332 'text', string.format("|cffeda55f%s|r", L.MENU_PET)
333 )
334 for i, statsType in self.petDPS do
335 cat:AddLine(
336 'text', L[statsType],
337 'text2', self:GetDPS(statsCat, statsType),
338 'text3', self.stats[statsCat][statsType]
339 );
340 end
341 end
342 end
343  
344 end
345  
346  
347  
348 -- Set()s and Get()S
349 function FuBar_DPS:SetHideLabel(v)
350 self.db.profile.hideLabel = v
351 self:Update()
352 end
353  
354 function FuBar_DPS:SetMyDmgDone(v)
355 self.db.profile.myDmgDone = v
356 self:Update()
357 end
358  
359 function FuBar_DPS:SetMyDmgTaken(v)
360 self.db.profile.myDmgTaken = v
361 self:Update()
362 end
363  
364 function FuBar_DPS:SetMyHealDone(v)
365 self.db.profile.myHealDone = v
366 self:Update()
367 end
368  
369 function FuBar_DPS:SetMyHealTaken(v)
370 self.db.profile.myHealTaken = v
371 self:Update()
372 end
373  
374 function FuBar_DPS:IsHideLabel()
375 return self.db.profile.hideLabel
376 end
377  
378 function FuBar_DPS:IsMyDmgDone()
379 return self.db.profile.myDmgDone
380 end
381  
382 function FuBar_DPS:IsMyDmgTaken()
383 return self.db.profile.myDmgTaken
384 end
385  
386 function FuBar_DPS:IsMyHealDone()
387 return self.db.profile.myHealDone
388 end
389  
390 function FuBar_DPS:IsMyHealTaken()
391 return self.db.profile.myHealTaken
392 end
393  
394  
395 if isPetClass then
396 function FuBar_DPS:SetMergeDPS(v)
397 self.db.profile.mergeDPS = v
398 self:Update()
399 end
400  
401 function FuBar_DPS:SetShowPetTooltip(v)
402 self.db.profile.showPetTooltip = v
403 self:Update()
404 end
405  
406 function FuBar_DPS:IsMergeDPS()
407 return self.db.profile.mergeDPS
408 end
409  
410 function FuBar_DPS:IsShowPetTooltip()
411 return self.db.profile.showPetTooltip
412 end
413  
414 function FuBar_DPS:SetPetDmgDone(v)
415 self.db.profile.petDmgDone = v
416 self:Update()
417 end
418  
419 function FuBar_DPS:SetPetDmgTaken(v)
420 self.db.profile.petDmgTaken = v
421 self:Update()
422 end
423  
424 function FuBar_DPS:SetPetHealDone(v)
425 self.db.profile.petHealDone = v
426 self:Update()
427 end
428  
429 function FuBar_DPS:SetPetHealTaken(v)
430 self.db.profile.petHealTaken = v
431 self:Update()
432 end
433  
434 function FuBar_DPS:IsPetDmgDone()
435 return self.db.profile.petDmgDone
436 end
437  
438 function FuBar_DPS:IsPetDmgTaken()
439 return self.db.profile.petDmgTaken
440 end
441  
442 function FuBar_DPS:IsPetHealDone()
443 return self.db.profile.petHealDone
444 end
445  
446 function FuBar_DPS:IsPetHealTaken()
447 return self.db.profile.petHealTaken
448 end
449  
450  
451 function FuBar_DPS:SetAddedStats()
452 if not self.stats.oldLast then self.stats.oldLast = {} end
453  
454 -- Switch stats to oldStats.
455 local tmp = self.stats.oldLast
456 self.stats.oldLast = self.stats.last
457 self.stats.last = tmp
458  
459 local stats = self.stats.last
460 local oldStats = self.stats.oldLast
461  
462 stats.myDmgDone = oldStats.myDmgDone + oldStats.petDmgDone
463 stats.myDmgTaken = oldStats.myDmgTaken + oldStats.petDmgTaken
464 stats.myHealDone = oldStats.myHealDone + oldStats.petHealDone
465 stats.myHealTaken = oldStats.myHealTaken + oldStats.petHealTaken
466 stats.duration = oldStats.duration
467 end
468  
469 function FuBar_DPS:UnsetAddedStats()
470 -- Switch back.
471 local tmp = self.stats.last
472 self.stats.last = self.stats.oldLast
473 self.stats.oldLast = tmp
474 end
475  
476  
477 function FuBar_DPS:InitializePetClass()
478 self.stats.session.petDmgDone = 0
479 self.stats.session.petDmgTaken = 0
480 self.stats.session.petHealDone = 0
481 self.stats.session.petHealTaken = 0
482 self.stats.last.petDmgDone = 0
483 self.stats.last.petDmgTaken = 0
484 self.stats.last.petHealDone = 0
485 self.stats.last.petHealTaken = 0
486 self.petDPS = { "petDmgDone", "petDmgTaken", "petHealDone", "petHealTaken" }
487 end
488  
489 optionsTable.args.mergeDPS = {
490 order = 3,
491 type = 'toggle',
492 name = L["MENU_MERGE_DPS"],
493 desc = L["MENU_MERGE_DPS"],
494 set = 'SetMergeDPS',
495 get = "IsMergeDPS",
496 }
497  
498 optionsTable.args.showPetTooltip = {
499 order = 4,
500 type = 'toggle',
501 name = L["MENU_SHOW_PET_TOOLTIP"],
502 desc = L["MENU_SHOW_PET_TOOLTIP"],
503 set = 'SetShowPetTooltip',
504 get = "IsShowPetTooltip",
505 }
506  
507 optionsTable.args.pet = {
508 order = 2,
509 type = 'group',
510 name = L["MENU_PET"],
511 desc = L["TOOLTIP_PET"],
512 args = {
513 petDmgDone = {
514 order = 1,
515 type = 'toggle',
516 name = L["petDmgDone"],
517 desc = L["petDmgDone"],
518 set = 'SetPetDmgDone',
519 get = 'IsPetDmgDone',
520 },
521 petDmgTaken = {
522 order = 2,
523 type = 'toggle',
524 name = L["petDmgTaken"],
525 desc = L["petDmgTaken"],
526 set = 'SetPetDmgTaken',
527 get = 'IsPetDmgTaken',
528 },
529 petHealDone = {
530 order = 3,
531 type = 'toggle',
532 name = L["petHealDone"],
533 desc = L["petHealDone"],
534 set = 'SetPetHealDone',
535 get = 'IsPetHealDone',
536 },
537 petHealTaken = {
538 order = 4,
539 type = 'toggle',
540 name = L["petHealTaken"],
541 desc = L["petHealTaken"],
542 set = 'SetPetHealTaken',
543 get = 'IsPetHealTaken',
544 },
545 },
546 }
547  
548 end
549  
550 FuBar_DPS.OnMenuRequest = optionsTable
551 FuBar_DPS:RegisterChatCommand( { "/fbdps" }, optionsTable )