forked from domzae/EavesDrop
-
Notifications
You must be signed in to change notification settings - Fork 1
/
EavesDrop.lua
1180 lines (1069 loc) · 41.2 KB
/
EavesDrop.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--[[
****************************************************************
EavesDrop
Author: Grayhoof. Original idea by Bant. Coding help/samples
from Andalia`s SideCombatLog and CombatChat.
Notes: Code comments coming at a later time.
****************************************************************]]
EavesDrop = LibStub("AceAddon-3.0"):NewAddon("EavesDrop", "AceEvent-3.0", "AceConsole-3.0", "AceTimer-3.0")
-- local EavesDrop = EavesDrop
local db
local L = LibStub("AceLocale-3.0"):GetLocale("EavesDrop", true)
local media = LibStub("LibSharedMedia-3.0")
local OUTGOING = 1
local INCOMING = -1
local MISC = 3
local critchar = "*"
local deathchar = "†"
local crushchar = "^"
local glancechar = "~"
local newhigh = "|cffffff00!|r"
local arrEventData = {}
local arrEventFrames = {}
local frameSize = 21
local arrSize = 10
local arrDisplaySize = 20
local arrMaxSize = 128
local scroll = 0
local allShown = false
local totDamageIn = 0
local totDamageOut = 0
local totHealingIn = 0
local totHealingOut = 0
local timeStart = 0
local curTime = 0
local lastTime = 0
-- LUA calls
local _G = _G
local tonumber = tonumber
local strsub = strsub
local string_format = string.format
local string_match = string.match
local gsub = gsub
local tremove = tremove
local tinsert = tinsert
local function string_nil(val)
if val then
return val
else
return UNKNOWN
end
end
-- API calls
local UnitName = UnitName
local UnitXP = UnitXP
local GetTime = GetTime
local InCombatLockdown = InCombatLockdown
-- local GetSpellInfo = GetSpellInfo $# Removed in War Within
local GetSpellInfo = GetSpellInfo or function(spellID)
if not spellID then
return nil;
end
local spellInfo = C_Spell.GetSpellInfo(spellID);
if spellInfo then
return spellInfo.name, nil, spellInfo.iconID, spellInfo.castTime, spellInfo.minRange, spellInfo.maxRange, spellInfo.spellID, spellInfo.originalIconID;
end
end
-- Combat log locals
local pxp = UnitXP("player")
local skillmsg = gsub(gsub(gsub(SKILL_RANK_UP, '%d%$', ''), '%%s', '(.+)'),
'%%d', '(%%d+)')
local CombatLog_Object_IsA = CombatLog_Object_IsA
local Blizzard_CombatLog_CurrentSettings
local COMBATLOG_OBJECT_NONE = COMBATLOG_OBJECT_NONE
local COMBATLOG_FILTER_MINE = COMBATLOG_FILTER_MINE
local COMBATLOG_FILTER_MY_PET = COMBATLOG_FILTER_MY_PET
local COMBATLOG_FILTER_HOSTILE = bit.bor(COMBATLOG_FILTER_HOSTILE_PLAYERS,
COMBATLOG_FILTER_HOSTILE_UNITS)
local COMBAT_EVENTS = {
["SWING_DAMAGE"] = "DAMAGE",
["RANGE_DAMAGE"] = "DAMAGE",
["SPELL_DAMAGE"] = "DAMAGE",
["SPELL_PERIODIC_DAMAGE"] = "DAMAGE",
["ENVIRONMENTAL_DAMAGE"] = "DAMAGE",
["DAMAGE_SHIELD"] = "DAMAGE",
["DAMAGE_SPLIT"] = "DAMAGE",
["SPELL_HEAL"] = "HEAL",
["SPELL_PERIODIC_HEAL"] = "HEAL",
["SWING_MISSED"] = "MISS",
["RANGE_MISSED"] = "MISS",
["SPELL_MISSED"] = "MISS",
["SPELL_PERIODIC_MISSED"] = "MISS",
["DAMAGE_SHIELD_MISSED"] = "MISS",
["SPELL_DRAIN"] = "DRAIN",
["SPELL_LEECH"] = "DRAIN",
["SPELL_PERIODIC_DRAIN"] = "DRAIN",
["SPELL_PERIODIC_LEECH"] = "DRAIN",
["SPELL_ENERGIZE"] = "POWER",
["SPELL_PERIODIC_ENERGIZE"] = "POWER",
["PARTY_KILL"] = "DEATH",
["UNIT_DIED"] = "DEATH",
["UNIT_DESTROYED"] = "DEATH"
}
local SCHOOL_STRINGS = {
[STRING_SCHOOL_PHYSICAL] = SPELL_SCHOOL0_CAP,
[STRING_SCHOOL_HOLY] = SPELL_SCHOOL1_CAP,
[STRING_SCHOOL_FIRE] = SPELL_SCHOOL2_CAP,
[STRING_SCHOOL_NATURE] = SPELL_SCHOOL3_CAP,
[STRING_SCHOOL_FROST] = SPELL_SCHOOL4_CAP,
[STRING_SCHOOL_SHADOW] = SPELL_SCHOOL5_CAP,
[STRING_SCHOOL_ARCANE] = SPELL_SCHOOL6_CAP
}
--[[local POWER_STRINGS = {
[SPELL_POWER_MANA] = MANA,
[SPELL_POWER_RAGE] = RAGE,
[SPELL_POWER_FOCUS] = FOCUS,
[SPELL_POWER_ENERGY] = ENERGY,
[SPELL_POWER_RUNES] = RUNES,
[SPELL_POWER_RUNIC_POWER] = RUNIC_POWER,
[SPELL_POWER_SOUL_SHARDS] = SHARDS,
[SPELL_POWER_LUNAR_POWER] = LUNAR_POWER,
[SPELL_POWER_HOLY_POWER] = HOLY_POWER,
[SPELL_POWER_ALTERNATE_POWER] = ALTERNATE_RESOURCE_TEXT,
[SPELL_POWER_MAELSTROM] = MAELSTROM_POWER,
[SPELL_POWER_CHI] = CHI_POWER,
[SPELL_POWER_INSANITY] = INSANITY_POWER,
--[SPELL_POWER_OBSOLETE] = 14;
--[SPELL_POWER_OBSOLETE2] = 15;
[SPELL_POWER_ARCANE_CHARGES] = ARCANE_CHARGES_POWER,
[SPELL_POWER_FURY] = FURY,
[SPELL_POWER_PAIN] = PAIN,
}]]
-- set table default size sense table.insert no longer does
for i = 1, arrMaxSize do arrEventData[i] = {} end
local function convertRGBtoHEXString(color, text)
return string_format("|cFF%02x%02x%02x%s|r", ceil(color.r * 255),
ceil(color.g * 255), ceil(color.b * 255), text)
end
local function shortenValue(value)
if value >= 10000000 then
value = string_format("%.1fm", value / 1000000)
elseif value >= 1000000 then
value = string_format("%.2fm", value / 1000000)
elseif value >= 100000 then
value = string_format("%.0fk", value / 1000)
elseif value >= 10000 then
value = string_format("%.1fk", value / 1000)
end
return value
end
local function round(num, idp)
return tonumber(string_format("%." .. (idp or 0) .. "f", num))
end
local function cleanstring(s)
s = gsub(s, "|r", "")
s = gsub(s, "|c........", "")
s = gsub(s, "|Hunit:%a+%-[^|]+|h", "")
s = gsub(s, "|Haction:([%w_*]*)|h", "")
s = gsub(s, "|Hitem:(%d+)|h", "")
s = gsub(s, "|Hicon:%d+:dest|h", "")
s = gsub(s, "|Hicon:%d+:source|h", "")
s = gsub(s, "|Hspell:%d+:%d+:([%w_*]*)|h", "")
s =
gsub(s, "|TInterface.TargetingFrame.UI.RaidTargetingIcon.%d.blp:0|t", "")
s = gsub(s, "|h", "")
s = gsub(s, "\n", ", ")
s = gsub(s, "\124", "\124\124")
s = s:gsub("[\r\n]+", " ")
return s
end
local function clearSummary()
totDamageIn = 0
totDamageOut = 0
totHealingIn = 0
totHealingOut = 0
end
-- Main Functions
function EavesDrop:OnInitialize()
-- setup table for display frame objects
for i = 1, arrDisplaySize do
arrEventFrames[i] = {}
arrEventFrames[i].frame = _G[string_format("EavesDropEvent%d", i)]
arrEventFrames[i].text =_G[string_format("EavesDropEvent%dEventText", i)]
arrEventFrames[i].intexture = _G[string_format("EavesDropEvent%dIncomingTexture", i)]
arrEventFrames[i].intextureframe = _G[string_format("EavesDropEvent%dIncoming", i)]
arrEventFrames[i].outtexture = _G[string_format("EavesDropEvent%dOutgoingTexture", i)]
arrEventFrames[i].outtextureframe = _G[string_format("EavesDropEvent%dOutgoing", i)]
end
self.db = LibStub("AceDB-3.0"):New("EavesDropDB", self:GetDefaultConfig())
self.chardb = LibStub("AceDB-3.0"):New("EavesDropStatsDB", {
profile = {[OUTGOING] = {}, [INCOMING] = {}}
})
self:SetupOptions()
-- callbacks for profile changes
self.db.RegisterCallback(self, "OnProfileChanged", "UpdateFrame")
self.db.RegisterCallback(self, "OnProfileCopied", "UpdateFrame")
self.db.RegisterCallback(self, "OnProfileReset", "UpdateFrame")
-- local the profile table
db = self.db.profile
self:PerformDisplayOptions()
self:RegisterEvent("ADDON_LOADED", self.SetFonts)
end
function EavesDrop:OnEnable()
self:RegisterEvent("PLAYER_DEAD")
self:UpdateExpEvents()
self:UpdateRepHonorEvents()
self:UpdateCombatEvents()
self:UpdateBuffEvents()
self:UpdateBuffFadeEvents()
self:UpdateSkillEvents()
self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED", "CombatEvent")
-- show frame
EavesDropFrame:Show()
if (db["FADEFRAME"]) then self:HideFrame() end
end
function EavesDrop:OnDisable()
self:UnregisterAllEvents()
EavesDropFrame:Hide()
end
function EavesDrop:UpdateCombatEvents()
if (db["COMBAT"] == true) then
self:RegisterEvent("PLAYER_REGEN_DISABLED")
self:RegisterEvent("PLAYER_REGEN_ENABLED")
else
self:UnregisterEvent("PLAYER_REGEN_DISABLED")
self:UnregisterEvent("PLAYER_REGEN_ENABLED")
end
end
function EavesDrop:UpdateExpEvents()
if (db["EXP"] == true) then
self:RegisterEvent("PLAYER_XP_UPDATE")
else
self:UnregisterEvent("PLAYER_XP_UPDATE")
end
end
function EavesDrop:UpdateRepHonorEvents()
if (db["REP"] or db["HONOR"]) then
self:RegisterEvent("COMBAT_TEXT_UPDATE")
else
self:UnregisterEvent("COMBAT_TEXT_UPDATE")
end
end
function EavesDrop:UpdateBuffEvents()
if (db["DEBUFF"] == true or db["BUFF"] == true) then
COMBAT_EVENTS["SPELL_AURA_APPLIED"] = "BUFF"
COMBAT_EVENTS["SPELL_PERIODIC_AURA_APPLIED"] = "BUFF"
COMBAT_EVENTS["SPELL_AURA_APPLIED_DOSE"] = "BUFF"
COMBAT_EVENTS["SPELL_PERIODIC_AURA_APPLIED_DOSE"] = "BUFF"
COMBAT_EVENTS["ENCHANT_APPLIED"] = "ENCHANT_APPLIED"
else
COMBAT_EVENTS["SPELL_AURA_APPLIED"] = nil
COMBAT_EVENTS["SPELL_PERIODIC_AURA_APPLIED"] = nil
COMBAT_EVENTS["SPELL_AURA_APPLIED_DOSE"] = nil
COMBAT_EVENTS["SPELL_PERIODIC_AURA_APPLIED_DOSE"] = nil
COMBAT_EVENTS["ENCHANT_APPLIED"] = nil
end
end
function EavesDrop:UpdateBuffFadeEvents()
if (db["DEBUFFFADE"] == true or db["BUFFFADE"] == true) then
COMBAT_EVENTS["SPELL_AURA_REMOVED"] = "FADE"
COMBAT_EVENTS["SPELL_PERIODIC_AURA_REMOVED"] = "FADE"
COMBAT_EVENTS["SPELL_AURA_REMOVED_DOSE"] = "FADE"
COMBAT_EVENTS["SPELL_PERIODIC_AURA_REMOVED_DOSE"] = "FADE"
COMBAT_EVENTS["ENCHANT_REMOVED"] = "ENCHANT_REMOVED"
else
COMBAT_EVENTS["SPELL_AURA_REMOVED"] = nil
COMBAT_EVENTS["SPELL_PERIODIC_AURA_REMOVED"] = nil
COMBAT_EVENTS["SPELL_AURA_REMOVED_DOSE"] = nil
COMBAT_EVENTS["SPELL_PERIODIC_AURA_REMOVED_DOSE"] = nil
COMBAT_EVENTS["ENCHANT_REMOVED"] = nil
end
end
function EavesDrop:UpdateSkillEvents()
if (db["SKILL"] == true) then
self:RegisterEvent("CHAT_MSG_SKILL")
else
self:UnregisterEvent("CHAT_MSG_SKILL")
end
end
----------------------
-- Reset everything to default
function EavesDrop:UpdateFrame()
-- local the profile table
db = self.db.profile
self:UpdateExpEvents()
self:UpdateRepHonorEvents()
self:UpdateCombatEvents()
self:UpdateBuffEvents()
self:UpdateBuffFadeEvents()
self:UpdateSkillEvents()
self:PerformDisplayOptions()
self:UpdateEvents()
end
function EavesDrop:PerformDisplayOptions()
-- set size
arrSize = db["NUMLINES"]
frameSize = db["LINEHEIGHT"] + 1
local totalh = (frameSize * arrSize) + 50
local totalw = (db["LINEHEIGHT"] * 2) + db["LINEWIDTH"]
-- FRAME SIZING
EavesDropFrame:SetHeight(totalh)
EavesDropFrame:SetWidth(totalw)
-- BACKGROUND APPEARANCE
local color = db["FRAME"]
local r, g, b, a = color.r, color.g, color.b, color.a
EavesDropBackground:SetHeight(totalh)
EavesDropBackground:SetWidth(totalw)
-- TODO?
local frameColor = CreateColor(r, g, b, a)
EavesDropBackground:SetGradient("VERTICAL", frameColor, frameColor)
-- BORDER CONFIG
color = db["BORDER"]
r, g, b, a = color.r, color.g, color.b, color.a
EavesDropTopBar:SetWidth(totalw)
EavesDropBottomBar:SetWidth(totalw)
-- TODO?
local outerColor = CreateColor(r * .1, g * .1, b * .1, 0)
local innerColor = CreateColor(r * .2, g * .2, b * .2, a)
EavesDropTopBar:SetGradient("VERTICAL", outerColor, innerColor)
EavesDropBottomBar:SetGradient("VERTICAL", innerColor, outerColor)
EavesDropFrame:EnableMouse(not db["LOCKED"])
-- tooltips
EavesDropTab.tooltipText = L["TabTip"]
if (db["SCROLLBUTTON"]) then
EavesDropFrameDownButton:Hide()
EavesDropFrameUpButton:Hide()
else
EavesDropFrameDownButton.tooltipText = L["DownTip"]
EavesDropFrameUpButton.tooltipText = L["UpTip"]
self:UpdateScrollButtons()
end
self.ToolTipAnchor = "ANCHOR_" .. strupper(db["TOOLTIPSANCHOR"])
-- labels
r, g, b, a = db["LABELC"].r, db["LABELC"].g, db["LABELC"].b, db["LABELC"].a
if (db["FLIP"] == true) then
EavesDropFramePlayerText:SetText(L["TargetLabel"])
EavesDropFrameTargetText:SetText(L["PlayerLabel"])
else
EavesDropFramePlayerText:SetText(L["PlayerLabel"])
EavesDropFrameTargetText:SetText(L["TargetLabel"])
end
EavesDropFramePlayerText:SetTextColor(r, g, b, a)
EavesDropFrameTargetText:SetTextColor(r, g, b, a)
-- fonts
self:SetFonts()
-- tab
if (db["HIDETAB"] == true) then
EavesDropTab:Hide()
else
EavesDropTab:Show()
end
-- position frame (have to schedule cause UI scale is still 1 for some reason during init)
self:ScheduleTimer("PlaceFrame", .1, self)
self:ResetEvents()
self:SetupHistory()
if (db["FADEFRAME"]) then
self:HideFrame()
else
self:ShowFrame()
end
end
function EavesDrop:SetFonts()
local requestedFont = media:Fetch("font", db["FONT"])
-- -- TODO
-- EavesDropFontNormal:SetFont(requestedFont, db["TEXTSIZE"])
-- EavesDropFontNormalSmall:SetFont(requestedFont, db["TEXTSIZE"])
end
function EavesDrop:PlaceFrame()
local frame, x, y = EavesDropFrame, db.x, db.y
frame:ClearAllPoints()
if x == 0 and y == 0 then
frame:SetPoint("CENTER", UIParent, "CENTER")
else
local es = frame:GetEffectiveScale()
frame:SetPoint("TOPLEFT", UIParent, "CENTER", x / es, y / es)
end
end
function EavesDrop:HideFrame() EavesDropFrame:SetAlpha(0) end
function EavesDrop:ShowFrame()
EavesDropFrame:SetAlpha(1)
EavesDropTab:SetAlpha(0)
end
function EavesDrop:CombatEvent()
local timestamp, event, hideCaster, sourceGUID, sourceName, sourceFlags,
sourceFlags2, destGUID, destName, destFlags, destFlags2, a1, a2, a3,
a4, a5, a6, a7, a8, a9, a10, a11, a12 = CombatLogGetCurrentEventInfo()
local etype = COMBAT_EVENTS[event]
if not etype then return end
if not Blizzard_CombatLog_CurrentSettings then
Blizzard_CombatLog_CurrentSettings =
Blizzard_CombatLog_Filters.filters[Blizzard_CombatLog_Filters.currentFilter]
end
-- check for reflect damage
if event == "SPELL_DAMAGE" and sourceName == destName and
CombatLog_Object_IsA(destFlags, COMBATLOG_FILTER_HOSTILE) then
self:ParseReflect(timestamp, event, hideCaster, sourceGUID, sourceName,
sourceFlags, sourceFlags2, destGUID, destName,
destFlags, destFlags2, a1, a2, a3, a4, a5, a6, a7, a8,
a9, a10, a11, a12)
return
end
local toPlayer, fromPlayer, toPet, fromPet
if (sourceName and
not CombatLog_Object_IsA(sourceFlags, COMBATLOG_OBJECT_NONE)) then
fromPlayer = CombatLog_Object_IsA(sourceFlags, COMBATLOG_FILTER_MINE)
fromPet = CombatLog_Object_IsA(sourceFlags, COMBATLOG_FILTER_MY_PET)
end
if (destName and not CombatLog_Object_IsA(destFlags, COMBATLOG_OBJECT_NONE)) then
toPlayer = CombatLog_Object_IsA(destFlags, COMBATLOG_FILTER_MINE)
toPet = CombatLog_Object_IsA(destFlags, COMBATLOG_FILTER_MY_PET)
end
if not fromPlayer and not toPlayer and not fromPet and not toPet then
return
end
if (not fromPlayer and not toPlayer) and (toPet or fromPet) and
not db["PET"] then return end
local amount, overDamage, school, resisted, blocked, absorbed, critical,
glancing, crushing
local spellId, spellName, spellSchool, missType, powerType, extraAmount,
environmentalType, overHeal
local text, texture, message, inout, color
-- defaults
if toPet or fromPet then texture = "pet" end
if toPlayer or toPet then inout = INCOMING end
if fromPlayer or fromPet then inout = OUTGOING end
if toPet then color = db["PETI"] end
if fromPet then color = db["PETO"] end
-- get combat log message (for tooltip)
message = CombatLog_OnEvent(Blizzard_CombatLog_CurrentSettings, timestamp,
event, hideCaster, sourceGUID, sourceName,
sourceFlags, sourceFlags2, destGUID, destName,
destFlags, destFlags2, a1, a2, a3, a4, a5, a6,
a7, a8, a9, a10, a11, a12)
------------damage----------------
if etype == "DAMAGE" then
local intype, outtype
if event == "SWING_DAMAGE" then
amount, overDamage, school, resisted, blocked, absorbed, critical, glancing, crushing =
a1, a2, a3, a4, a5, a6, a7, a8, a9
if school == SCHOOL_MASK_PHYSICAL then
outtype, intype = "TMELEE", "PHIT"
else
outtype, intype = "TSPELL", "PSPELL"
end
elseif event == "RANGE_DAMAGE" then
spellId, spellName, spellSchool, amount, overDamage, school, resisted, blocked, absorbed, critical, glancing, crushing =
a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12
if school == SCHOOL_MASK_PHYSICAL then
outtype, intype = "TMELEE", "PHIT"
else
outtype, intype = "TSPELL", "PSPELL"
end
elseif event == "ENVIRONMENTAL_DAMAGE" then
environmentalType, amount, overDamage, school, resisted, blocked, absorbed, critical, glancing, crushing =
a1, a2, a3, a4, a5, a6, a7, a8, a9, a10
outtype, intype = "TSPELL", "PSPELL"
else
spellId, spellName, spellSchool, amount, overDamage, school, resisted, blocked, absorbed, critical, glancing, crushing =
a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12
texture = select(3, GetSpellInfo(spellId))
outtype, intype = "TSPELL", "PSPELL"
end
text = tostring(shortenValue(amount))
if (critical) then text = critchar .. text .. critchar end
if (crushing) then text = crushchar .. text .. crushchar end
if (glancing) then text = glancechar .. text .. glancechar end
if (resisted) then
text = string_format("%s (%d)", text, shortenValue(resisted))
end
if (blocked) then
text = string_format("%s (%d)", text, shortenValue(blocked))
end
if (absorbed) then
text = string_format("%s (%d)", text, shortenValue(absorbed))
end
if fromPlayer then
if (self:TrackStat(inout, "hit", spellName, texture, SCHOOL_STRINGS[school], amount, critical, message)) then
text = newhigh .. text .. newhigh
end
-- fix colors for self physical
if school == SCHOOL_MASK_PHYSICAL then school = 0 end
color = self:SpellColor(db[outtype], SCHOOL_STRINGS[school])
totDamageOut = totDamageOut + amount
elseif toPlayer then
if (self:TrackStat(inout, "hit", spellName, texture, SCHOOL_STRINGS[school], amount, critical, message)) then
text = newhigh .. text .. newhigh
end
color = self:SpellColor(db[intype], SCHOOL_STRINGS[school])
text = "-" .. text
totDamageIn = totDamageIn + amount
elseif toPet then
text = "-" .. text
end
self:DisplayEvent(inout, text, texture, color, message, spellName)
------------buff/debuff gain----------------
elseif etype == "BUFF" then
spellId, spellName, spellSchool, auraType, amount = a1, a2, a3, a4, a5
texture = select(3, GetSpellInfo(spellId))
if toPlayer and db[auraType] then
self:DisplayEvent(INCOMING, self:ShortenString(spellName) .. " " ..
L["Gained"], texture, db["P" .. auraType],
message, spellName)
else
return
end
------------buff/debuff lose----------------
elseif etype == "FADE" then
spellId, spellName, spellSchool, auraType, amount = a1, a2, a3, a4, a5
texture = select(3, GetSpellInfo(spellId))
if toPlayer and db[auraType .. "FADE"] then
self:DisplayEvent(INCOMING, self:ShortenString(spellName) .. " " ..
L["Fades"], texture, db["P" .. auraType],
message, spellName)
else
return
end
------------heals----------------
elseif etype == "HEAL" then
spellId, spellName, spellSchool, amount, overHeal, absorbed, critical =
a1, a2, a3, a4, a5, a6, a7
text = tostring(shortenValue(amount))
texture = select(3, GetSpellInfo(spellId))
if toPlayer then
totHealingIn = totHealingIn + amount
if (amount < db["HFILTER"]) then return end
if (db["OVERHEAL"]) and overHeal > 0 then
text = string_format("%d {%d}", shortenValue(amount - overHeal), shortenValue(overHeal))
end
if (critical) then text = critchar .. text .. critchar end
if (db["HEALERID"] == true and not fromPlayer) then
text = text .. " (" .. sourceName .. ")"
end
color = db["PHEAL"]
if (self:TrackStat(inout, "heal", spellName, texture, SCHOOL_STRINGS[spellSchool], amount, critical, message)) then
text = newhigh .. text .. newhigh
end
text = "+" .. text
elseif fromPlayer then
totHealingOut = totHealingOut + amount
if (amount < db["HFILTER"]) then return end
if (db["OVERHEAL"]) and overHeal > 0 then
text = string_format("%d {%d}", shortenValue(amount - overHeal), shortenValue(overHeal))
end
if (critical) then text = critchar .. text .. critchar end
color = db["THEAL"]
if (self:TrackStat(inout, "heal", spellName, texture, SCHOOL_STRINGS[spellSchool], amount, critical, message)) then
text = newhigh .. text .. newhigh
end
text = "+" .. text
if (db["HEALERID"] == true) then
text = destName .. ": " .. text
end
end
self:DisplayEvent(inout, text, texture, color, message, spellName)
------------misses----------------
elseif etype == "MISS" then
local tcolor
if event == "SWING_MISSED" or event == "RANGE_MISSED" then
missType = a1
tcolor = "TMELEE"
else
spellId, spellName, spellSchool, missType = a1, a2, a3, a4
texture = select(3, GetSpellInfo(spellId))
tcolor = "TSPELL"
end
text = _G[missType]
if fromPlayer then
color = db[tcolor]
elseif toPlayer then
if missType == "REFLECT" then
self:SetReflect(sourceName, spellName)
end
color = db["PMISS"]
end
self:DisplayEvent(inout, text, texture, color, message, spellName)
------------leech and drains----------------
elseif etype == "DRAIN" then
if (db["GAINS"]) then
spellId, spellName, spellSchool, amount, powerType, extraAmount =
a1, a2, a3, a4, a5, a6
texture = select(3, GetSpellInfo(spellId))
if toPlayer then
text = string_format("-%d %s", amount, string_nil(""))
color = db["PGAIN"]
elseif fromPlayer and extraAmount then
if (extraAmount < db["MFILTER"]) then return end
text = string_format("+%d %s", extraAmount, string_nil(""))
color = db["PGAIN"]
elseif fromPlayer then
return
-- for showing your drain damage
-- text = string_format("%d %s", amount, string_nil(""))
-- color = db["TSPELL"]
end
self:DisplayEvent(inout, text, texture, color, message, spellName)
end
------------power gains----------------
elseif etype == "POWER" then
if (db["GAINS"]) then
spellId, spellName, spellSchool, amount, powerType = a1, a2, a3, a4,
a5
texture = select(3, GetSpellInfo(spellId))
if toPlayer then
if (amount < db["MFILTER"]) then return end
color = db["PGAIN"]
elseif not toPet then
return
end
text = string_format("+%d %s", amount, string_nil(""))
self:DisplayEvent(inout, text, texture, color, message, spellName)
end
------------deaths----------------
elseif etype == "DEATH" then
if fromPlayer then
text = deathchar .. destName .. deathchar
self:DisplayEvent(MISC, text, texture, db["DEATH"], message,
spellName)
else
return
end
------------enchants----------------
elseif etype == "ENCHANT_APPLIED" then
spellName = a1
self:DisplayEvent(INCOMING, self:ShortenString(spellName), texture,
db["PBUFF"], message, spellName)
elseif etype == "ENCHANT_REMOVED" then
spellName = a1
self:DisplayEvent(INCOMING,
self:ShortenString(spellName) .. " " .. L["Fades"],
texture, db["PBUFF"], message, spellName)
-------------anything else-------------
-- else
-- self:Print(event, sourceName, destName)
end
end
function EavesDrop:PLAYER_XP_UPDATE()
local xp = UnitXP("player")
local xpgained = xp - pxp
self:DisplayEvent(MISC,
string_format("+%d (%s)", shortenValue(xpgained), XP),
nil, db["EXPC"], nil)
pxp = xp
end
function EavesDrop:COMBAT_TEXT_UPDATE(event, larg1, larg2, larg3)
if larg1 == "FACTION" then
local sign = "+"
if larg2 == nil then larg2 = 0 end
if larg3 == nil then
larg3 = 0
sign = ""
end
if (tonumber(larg3) < 0) then sign = "" end
self:DisplayEvent(MISC, string_format("%s%d (%s)", sign, larg3, larg2),
nil, db["REPC"], nil)
elseif larg1 == "HONOR_GAINED" then
self:DisplayEvent(MISC, string_format("+%d (%s)", larg2, HONOR), nil,
db["HONORC"], nil)
end
end
function EavesDrop:PLAYER_REGEN_DISABLED()
pxp = UnitXP("player")
timeStart = GetTime()
clearSummary()
self:DisplayEvent(MISC, L["StartCombat"], nil, db["MISC"])
-- stop on update, since in combat
self:StopOnUpdate()
-- show frame, if its hidden
self:ShowFrame()
-- flag all as being shown, so buttons appear
allShown = true
end
function EavesDrop:PLAYER_REGEN_ENABLED()
self:DisplayEvent(MISC, L["EndCombat"], nil, db["MISC"])
if (db["SUMMARY"] == true) then
local duration = round(GetTime() - timeStart, 1)
local DPS = round(totDamageOut / duration, 1) or 0
local HPS = round(totHealingOut / duration, 1) or 0
local IDPS = round(totDamageIn / duration, 1) or 0
local IHPS = round(totHealingIn / duration, 1) or 0
local strSummary = convertRGBtoHEXString(db["MISC"], duration .. " " ..
L["IncombatSummary"]) ..
"\n" ..
convertRGBtoHEXString(db["PHIT"],
L["IncomingDamge"] .. ": " ..
totDamageIn .. " (" ..
IDPS .. ")") .. "\n" ..
convertRGBtoHEXString(db["PHEAL"],
L["IncomingHeals"] .. ": " ..
totHealingIn .. " (" ..
IHPS .. ")") .. "\n" ..
convertRGBtoHEXString(db["THEAL"],
L["OutgoingHeals"] .. ": " ..
totHealingOut .. " (" ..
HPS .. ")") .. "\n" ..
convertRGBtoHEXString(db["TSPELL"],
L["OutgoingDamage"] .. ": " ..
totDamageOut .. " (" ..
DPS .. ")")
self:DisplayEvent(MISC,
convertRGBtoHEXString(db["PHIT"],
shortenValue(totDamageIn)) ..
" | " ..
convertRGBtoHEXString(db["PHEAL"],
shortenValue(totHealingIn)) ..
" | " ..
convertRGBtoHEXString(db["THEAL"],
shortenValue(totHealingOut)) ..
" | " ..
convertRGBtoHEXString(db["TSPELL"],
shortenValue(totDamageOut)),
nil, db["MISC"], strSummary)
end
clearSummary()
-- since out of combat, try and start onupdate to count down frames
self:StartOnUpdate()
end
function EavesDrop:PLAYER_DEAD()
self:DisplayEvent(MISC, deathchar .. UnitName("player") .. deathchar, nil,
db["DEATH"])
end
function EavesDrop:CHAT_MSG_SKILL(event, larg1)
local skill, rank = string_match(larg1, skillmsg)
if skill then
self:DisplayEvent(MISC, string_format("%s: %d", skill, rank), nil,
db["SKILLC"], larg1)
end
end
local tempcolor = {r = 1, g = 1, b = 1}
function EavesDrop:DisplayEvent(type, text, texture, color, message, spellname)
-- remove oldest table and create new display event
local pEvent = tremove(arrEventData, 1)
local tooltiptext = message
if (db["FLIP"] == true) then type = type * -1 end
pEvent.type = type
pEvent.text = text
pEvent.texture = texture
pEvent.color = color or tempcolor
-- Messages probably already have a timestamp, so let's clear that up
if (db["TIMESTAMP"] == true and message) then
-- Check if we have a timestamp here and remove to use our own
local timecutoff = string.find(message, '> ')
-- If we did, skip those two characters "> "
if timecutoff then message = strsub(message, timecutoff + 2) end
pEvent.tooltipText = string_format('|cffffffff%s\n%s', date('%I:%M:%S'),
message)
elseif (db["TIMESTAMP"] == true and text) then
pEvent.tooltipText = string_format('|cffffffff%s|r\n%s',
date('%I:%M:%S'), text)
elseif (db["TIMESTAMP"] == true) then
pEvent.tooltipText = string_format('|cffffffff%s|r\n%s',
date('%I:%M:%S'), tooltiptext or '')
elseif spellname then
pEvent.tooltipText = spellname
else
pEvent.tooltipText = tooltiptext
end
tinsert(arrEventData, arrMaxSize, pEvent)
self:UpdateEvents()
end
function EavesDrop:UpdateEvents()
local key, value
local frame, text, intexture, outexture
local start, finish
local delay = db["FADETIME"] + (4 * arrSize)
start = arrMaxSize - scroll
finish = arrMaxSize - arrSize + 1 - scroll
for i = start, finish, -1 do
value = arrEventData[i]
key = i - (arrMaxSize - arrSize) + scroll
frame = arrEventFrames[key].frame
text = arrEventFrames[key].text
intexture = arrEventFrames[key].intexture
outtexture = arrEventFrames[key].outtexture
if (not value.text) then
text:SetText(nil)
intexture:SetTexture(nil)
outtexture:SetTexture(nil)
frame.delay = 0
frame.alpha = 0
frame.tooltipText = nil
frame:Hide()
else
if (value.type == INCOMING) then
text:SetJustifyH("LEFT")
text:SetWidth(db["LINEWIDTH"] - 20)
text:SetPoint("LEFT", intexture, "RIGHT", 5, 0)
intexture:SetTexCoord(.1, .9, .1, .9)
outtexture:SetTexture(nil)
if value.texture == "pet" then
SetPortraitTexture(intexture, value.texture)
else
intexture:SetTexture(value.texture)
end
elseif (value.type == OUTGOING) then
text:SetJustifyH("RIGHT")
text:SetWidth(db["LINEWIDTH"] - 20)
text:SetPoint("LEFT", intexture, "RIGHT", 5, 0)
intexture:SetTexture(nil)
outtexture:SetTexCoord(.1, .9, .1, .9)
if value.texture == "pet" then
SetPortraitTexture(outtexture, value.texture)
else
outtexture:SetTexture(value.texture)
end
else
text:SetJustifyH("CENTER")
text:SetWidth((db["LINEHEIGHT"] * 2) + (db["LINEWIDTH"] - 10))
text:SetPoint("LEFT", intexture, "LEFT", 0, 0)
intexture:SetTexture(nil)
outtexture:SetTexture(nil)
end
text:SetText(value.text)
text:SetTextColor(value.color.r, value.color.g, value.color.b)
frame.delay = delay
frame.alpha = 1
if (db["TOOLTIPS"] == true) then
frame.tooltipText = value.tooltipText
else
frame.tooltipText = nil
end
frame:Show()
frame:SetAlpha(frame.alpha)
end
delay = delay - 4
-- set clickthru
if (frame.tooltipText) then
frame:EnableMouse(true)
else
frame:EnableMouse(false)
end
end
-- Update scrolls
self:UpdateScrollButtons()
-- try to start up onUpdate. if in combat it won't start.
self:StartOnUpdate()
end
function EavesDrop:StartOnUpdate()
-- only start on update if not in combat, and not already started.
if not InCombatLockdown() and not self.OnUpdateStarted then
lastTime = GetTime()
self.OnUpdateStarted = self:ScheduleRepeatingTimer("OnUpdate", .2, self)
end
end
function EavesDrop:StopOnUpdate()
self:CancelTimer(self.OnUpdateStarted, true)
self.OnUpdateStarted = nil
end
function EavesDrop:ResetEvents()
local frame, text, intexture, outexture
for i = 1, arrDisplaySize do
frame = arrEventFrames[i].frame
text = arrEventFrames[i].text
intexture = arrEventFrames[i].intextureframe
outtexture = arrEventFrames[i].outtextureframe
frame.delay = 0
frame.alpha = 0
frame.tooltipText = nil
frame:SetHeight(db["LINEHEIGHT"] + 1)
frame:SetWidth((db["LINEHEIGHT"] * 2) + db["LINEWIDTH"])
frame:Hide()
text:SetHeight(db["LINEHEIGHT"])
intexture:SetHeight(db["LINEHEIGHT"])
intexture:SetWidth(db["LINEHEIGHT"])
intexture:SetPoint("LEFT", frame, "RIGHT", 5, 0)
outtexture:SetHeight(db["LINEHEIGHT"])
outtexture:SetWidth(db["LINEHEIGHT"])
end
end
function EavesDrop:OnUpdate()
local frame
local count = 0
curTime = GetTime()
elapsed = curTime - lastTime
lastTime = curTime
for i = 1, arrSize do
frame = arrEventFrames[i].frame
if (frame:IsShown()) then
count = count + 1
frame.delay = frame.delay - elapsed
if frame.delay <= 0 then
frame.alpha = frame.alpha - .2
-- frame:SetAlpha(frame.alpha)
end
if (frame.alpha <= 0) then
frame:Hide()
EavesDropFrameUpButton:Hide()
count = count - 1
end
end
end
if (count == arrSize) then
allShown = true
else
allShown = false
end
-- if none are active, stop onUpdate
if (count == 0) then self:StopOnUpdate() end
-- hide frame when none active
if (db["FADEFRAME"]) then
if ((count == 0) and (scroll == 0)) then
self:HideFrame()
else
self:ShowFrame()
end
end
end