-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Core.lua
1243 lines (1057 loc) · 32.3 KB
/
Core.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
local Libra = LibStub("Libra")
local Critline, addonName = Libra:NewAddon(...)
_G.Critline = Critline
Libra:EmbedWidgets(Critline)
Critline.L = LibStub("AceLocale-3.0"):GetLocale(addonName)
local L = Critline.L
local LSM = LibStub("LibSharedMedia-3.0")
local _, playerClass = UnitClass("player")
local spellMappings, tooltipMappings, spellNameOverrides, spellIconOverrides
local debugging
-- debugging = true
-- local references to commonly used functions and variables for faster access
local floor, band, tonumber, format = floor, bit.band, tonumber, format
local CombatLogGetCurrentEventInfo = CombatLogGetCurrentEventInfo
local CombatLog_Object_IsA = CombatLog_Object_IsA
local HasPetUI = HasPetUI
local GetSpellName = C_Spell.GetSpellName
local GetSpellLink = C_Spell.GetSpellLink
local IsPlayerSpell = IsPlayerSpell
local COMBATLOG_FILTER_MINE = COMBATLOG_FILTER_MINE
local COMBATLOG_FILTER_MY_PET = COMBATLOG_FILTER_MY_PET
local COMBATLOG_OBJECT_REACTION_FRIENDLY = COMBATLOG_OBJECT_REACTION_FRIENDLY
local COMBATLOG_OBJECT_REACTION_HOSTILE = COMBATLOG_OBJECT_REACTION_HOSTILE
local COMBATLOG_OBJECT_CONTROL_PLAYER = COMBATLOG_OBJECT_CONTROL_PLAYER
local COMBATLOG_OBJECT_TYPE_GUARDIAN = COMBATLOG_OBJECT_TYPE_GUARDIAN
-- auto attack spell
local AUTO_ATTACK_ID = 6603
local AUTO_ATTACK = GetSpellName(AUTO_ATTACK_ID)
local trees = {
dmg = {
title = L["Damage"],
label = L["damage"],
icon = [[Interface\Icons\Ability_SteelMelee]],
},
heal = {
title = L["Healing"],
label = L["healing"],
icon = [[Interface\Icons\Spell_Holy_FlashHeal]],
},
pet = {
title = L["Pet"],
label = L["pet"],
icon = [[Interface\Icons\Ability_Hunter_Pet_Bear]],
},
}
Critline.trees = trees
Critline.treeIndex = {
"dmg",
"heal",
"pet",
}
local RAID_BOSS_LEVELS = {
[469] = 63, -- Blackwing Lair
[409] = 63, -- Molten Core
[509] = 63, -- Ruins of Ahn'Qiraj
[531] = 63, -- Temple of Ahn'Qiraj
[564] = 73, -- Black Temple
[565] = 73, -- Gruul's Lair
[534] = 73, -- Hyjal Summit
[532] = 73, -- Karazhan
[544] = 73, -- Magtheridon's Lair
[548] = 73, -- Serpentshrine Cavern
[580] = 73, -- Sunwell Plateau
[550] = 73, -- The Eye
[631] = 83, -- Icecrown Citadel
[533] = 83, -- Naxxramas
[249] = 83, -- Onyxia's Lair
[616] = 83, -- The Eye of Eternity
[615] = 83, -- The Obsidian Sanctum
[724] = 83, -- The Ruby Sanctum
[649] = 83, -- Trial of the Crusader
[603] = 83, -- Ulduar
[624] = 83, -- Vault of Archavon
[757] = 88, -- Baradin Hold
[669] = 88, -- Blackwing Descent
[967] = 88, -- Dragon Soul
[720] = 88, -- Firelands
[671] = 88, -- The Bastion of Twilight
[754] = 88, -- Throne of the Four Winds
[1009] = 93, -- Heart of Fear
[1008] = 93, -- Mogu'shan Vaults
[1136] = 93, -- Siege of Orgrimmar
[996] = 93, -- Terrace of Endless Spring
[1098] = 93, -- Throne of Thunder
[1228] = 103, -- Highmaul
[1205] = 103, -- Blackrock Foundry
[1448] = 103, -- Hellfire Citadel
[1520] = 113, -- The Emerald Nightmare
[1648] = 113, -- Trial of Valor
[1530] = 113, -- The Nighthold
[1676] = 113, -- Tomb of Sargeras
[1712] = 113, -- Antorus, the Burning Throne
}
local bossLevel
-- guardian type pets whose damage we may want to register
local classPets = {
[89] = true, -- Infernal
[11859] = true, -- Doomguard
[15438] = true, -- Greater Fire Elemental
[27829] = true, -- Ebon Gargoyle
[29264] = true, -- Spirit Wolf
}
local spellIDCache = {}
-- cache of spell ID -> spell name
local spellNameCache = {}
-- cache of spell textures
local spellTextureCache = {
-- use a static icon for auto attack (otherwise uses your weapon's icon)
[AUTO_ATTACK_ID] = [[Interface\Icons\INV_Sword_04]],
[5019] = [[Interface\Icons\Ability_ShootWand]], -- Shoot (wand)
}
local swingDamage = function(amount, _, school, resisted, _, _, critical)
return AUTO_ATTACK_ID, AUTO_ATTACK, amount, resisted, critical
end
local spellDamage = function(spellID, spellName, _, amount, _, school, resisted, _, _, critical)
return spellID, spellName, amount, resisted, critical
end
local healing = function(spellID, spellName, _, amount, _, _, critical)
return spellID, spellName, amount, 0, critical
end
local absorb = function(spellID, spellName, _, _, amount)
return spellID, spellName, amount, 0, critical
end
local combatEvents = {
SWING_DAMAGE = swingDamage,
RANGE_DAMAGE = spellDamage,
SPELL_DAMAGE = spellDamage,
SPELL_PERIODIC_DAMAGE = spellDamage,
SPELL_HEAL = healing,
SPELL_PERIODIC_HEAL = healing,
SPELL_AURA_APPLIED = absorb,
SPELL_AURA_REFRESH = absorb,
}
-- alpha: sort by name
local alpha = function(a, b)
if a == b then return end
if a.name == b.name then
if a.id == b.id then
-- sort DoT entries after non DoT
return a.periodic < b.periodic
else
return a.id < b.id
end
else
return a.name < b.name
end
end
-- normal: sort by normal > crit > name
local normal = function(a, b)
if a == b then return end
local normalA, normalB = (a.normal and a.normal.amount or 0), (b.normal and b.normal.amount or 0)
if normalA == normalB then
-- equal normal amounts, sort by crit amount instead
local critA, critB = (a.crit and a.crit.amount or 0), (b.crit and b.crit.amount or 0)
if critA == critB then
-- equal crit amounts too, sort by name instead
return alpha(a, b)
else
return critA > critB
end
else
return normalA > normalB
end
end
-- crit: sort by crit > normal > name
local crit = function(a, b)
if a == b then return end
local critA, critB = (a.crit and a.crit.amount or 0), (b.crit and b.crit.amount or 0)
if critA == critB then
return normal(a, b)
else
return critA > critB
end
end
local recordSorters = {
alpha = alpha,
normal = normal,
crit = crit,
}
local callbacks = LibStub("CallbackHandler-1.0"):New(Critline)
Critline.callbacks = callbacks
-- this will hold the text for the summary tooltip
local tooltips = {dmg = {}, heal = {}, pet = {}}
-- indicates whether a given tree will need to have its tooltip updated before next use
local doTooltipUpdate = {}
-- overall record for each tree
local topRecords = {
dmg = {normal = 0, crit = 0},
heal = {normal = 0, crit = 0},
pet = {normal = 0, crit = 0},
}
-- sortable spell tables
local spellArrays = {dmg = {}, heal = {}, pet = {}}
LSM:Register("sound", "Level up", 567431) -- Sound\Interface\LevelUp.ogg
Critline.SlashCmdHandlers = {
debug = function() Critline:ToggleDebug() end,
}
SlashCmdList.CRITLINE = function(msg)
msg = msg:trim():lower()
local slashCmdHandler = Critline.SlashCmdHandlers[msg]
if slashCmdHandler then
slashCmdHandler()
else
Critline:OpenConfig()
end
end
SLASH_CRITLINE1 = "/critline"
SLASH_CRITLINE2 = "/cl"
AddonCompartmentFrame:RegisterAddon({
text = "Critline",
icon = Critline.trees.dmg.icon,
notCheckable = true,
func = function()
Critline:OpenConfig()
end,
})
local config = Critline:CreateOptionsFrame(addonName)
Critline.config = config
do
local function set(self, value)
Critline.percharDB.profile[self.key] = value
end
local function get(self)
return Critline.percharDB.profile[self.key]
end
local function toggleTree(self, checked)
callbacks:Fire("OnTreeStateChanged", self.key, checked)
end
-- summary sort dropdown
local menu = {
{
text = L["Spell name"],
value = "alpha",
},
{
text = L["Normal record"],
value = "normal",
},
{
text = L["Crit record"],
value = "crit",
},
}
local options = {
{
type = "CheckButton",
text = L["Record damage"],
tooltip = L["Check to enable damage events to be recorded."],
key = "dmg",
set = set,
get = get,
func = toggleTree,
},
{
type = "CheckButton",
text = L["Record healing"],
tooltip = L["Check to enable healing events to be recorded."],
key = "heal",
func = toggleTree,
set = set,
get = get,
},
{
type = "CheckButton",
text = L["Record pet damage"],
tooltip = L["Check to enable pet damage events to be recorded."],
key = "pet",
func = toggleTree,
set = set,
get = get,
},
{
type = "CheckButton",
text = L["Record PvE"],
tooltip = L["Disable to ignore records where the target is an NPC."],
key = "PvE",
padding = 8,
},
{
type = "CheckButton",
text = L["Record PvP"],
tooltip = L["Disable to ignore records where the target is a player."],
key = "PvP",
},
{
type = "CheckButton",
text = L["Ignore vulnerability"],
tooltip = L["Enable to ignore additional damage due to vulnerability."],
key = "ignoreVulnerability",
},
{
newColumn = true,
type = "CheckButton",
text = L["Shorten records"],
tooltip = L["Use shorter format for record numbers."],
key = "shortFormat",
func = function(self, checked)
callbacks:Fire("FormatChanged")
Critline:UpdateTooltips()
end,
},
{
type = "CheckButton",
text = L["Records in spell tooltips"],
tooltip = L["Include (unfiltered) records in spell tooltips."],
key = "spellTooltips",
},
{
type = "CheckButton",
text = L["Detailed tooltip"],
tooltip = L["Use detailed format in the summary tooltip."],
key = "detailedTooltip",
func = "UpdateTooltips",
},
{
type = "Dropdown",
text = L["Sort tooltips by:"],
key = "tooltipSort",
width = 160,
func = "UpdateTooltips",
menuList = {
"alpha",
"normal",
"crit",
},
properties = {
text = {
alpha = L["Spell name"],
normal = L["Normal record"],
crit = L["Crit record"],
},
},
},
{
type = "CheckButton",
text = L["Include old record"],
tooltip = L["Includes previous record along with \"New record\" messages."],
key = "oldRecord",
},
{
type = "CheckButton",
text = L["Chat output"],
tooltip = L["Prints new record notifications to the chat frame."],
key = "chatOutput",
},
{
type = "CheckButton",
text = L["Screenshot"],
tooltip = L["Saves a screenshot on a new record."],
key = "screenshot",
},
{
type = "Dropdown",
text = L["Sound effect"],
key = "sound",
func = function(self, value)
-- hack not to play the sound when settings are loaded from a triggered event
if not GetMouseButtonClicked() then return end
PlaySoundFile(LSM:Fetch("sound", value))
end,
width = 160,
menuList = function() return LSM:List("sound") end,
},
}
config:CreateOptions(options)
end
local defaults = {
profile = {
PvE = true,
PvP = true,
ignoreVulnerability = true,
shortFormat = false,
spellTooltips = true,
detailedTooltip = false,
tooltipSort = "normal",
oldRecord = false,
chatOutput = false,
screenshot = false,
sound = "None",
},
global = {
spellMappings = {},
tooltipMappings = {},
spellNameOverrides = {
-- pre-add form name to hybrid druid abilities, so the user can tell which is cat and which is bear
-- [33878] = format("%s (%s)", GetSpellName(33878), GetSpellName(5487)), -- Mangle (Bear Form)
-- [33876] = format("%s (%s)", GetSpellName(33876), GetSpellName(768)), -- Mangle (Cat Form)
-- [779] = format("%s (%s)", GetSpellName(779), GetSpellName(5487)), -- Swipe (Bear Form)
-- [62078] = format("%s (%s)", GetSpellName(62078), GetSpellName(768)), -- Swipe (Cat Form)
},
spellIconOverrides = {},
},
}
-- which trees are enabled by default for a given class
-- if not specified; defaults to only damage enabled
local treeDefaults = {
DRUID = {heal = true},
HUNTER = {pet = true},
MONK = {heal = true},
PALADIN = {heal = true},
PRIEST = {heal = true},
SHAMAN = {heal = true},
WARLOCK = {pet = true},
}
function Critline:OnInitialize()
local AceDB = LibStub("AceDB-3.0")
local db = AceDB:New("CritlineDB", defaults, nil)
self.db = db
config:SetDatabase(self.db, true)
config:SetHandler(self)
local percharDefaults = {
profile = treeDefaults[playerClass] or {},
}
-- everyone wants damage!
percharDefaults.profile.dmg = true
-- set these to false rather than nil if disabled, for consistency
percharDefaults.profile.heal = percharDefaults.profile.heal or false
percharDefaults.profile.pet = percharDefaults.profile.pet or false
percharDefaults.profile.spells = {
dmg = {},
heal = {},
pet = {},
}
local percharDB = AceDB:New("CritlinePerCharDB", percharDefaults)
self.percharDB = percharDB
-- dual spec support
local LibDualSpec = LibStub("LibDualSpec-1.0")
LibDualSpec:EnhanceDatabase(self.db, addonName)
LibDualSpec:EnhanceDatabase(self.percharDB, addonName)
db.RegisterCallback(self, "OnProfileChanged", "LoadSettings")
db.RegisterCallback(self, "OnProfileCopied", "LoadSettings")
db.RegisterCallback(self, "OnProfileReset", "LoadSettings")
percharDB.RegisterCallback(self, "OnProfileChanged", "LoadPerCharSettings")
percharDB.RegisterCallback(self, "OnProfileCopied", "LoadPerCharSettings")
percharDB.RegisterCallback(self, "OnProfileReset", "LoadPerCharSettings")
self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
self:RegisterEvent("PLAYER_ENTERING_WORLD")
spellMappings = db.global.spellMappings
tooltipMappings = db.global.tooltipMappings
spellNameOverrides = db.global.spellNameOverrides
spellIconOverrides = db.global.spellIconOverrides
-- purge invalid spell mappings
for k, v in pairs(spellMappings) do
if not GetSpellLink(v) then
spellMappings[k] = nil
end
end
self:LoadSettings()
self:LoadPerCharSettings()
end
function Critline:LoadSettings()
callbacks:Fire("SettingsLoaded")
config:SetupControls()
end
function Critline:LoadPerCharSettings()
self:FixSpells()
self:BuildSpellArray()
callbacks:Fire("PerCharSettingsLoaded")
self:UpdateTopRecords()
self:UpdateTooltips()
config:SetupControls()
end
function Critline:FixSpells()
for k, tree in pairs(self.percharDB.profile.spells) do
for spellID, spell in pairs(tree) do
-- merge any spell remnants that has gotten new mappings, into their new spell ID
local spellMapping = spellMappings[spellID]
if spellMapping and spellMapping ~= spellID then
local map = tree[spellMapping] or spell
for i = 1, 2 do
map[i] = map[i] or spell[i]
end
tree[spellID] = nil
end
-- remove spells that have been taken out of the game
if not GetSpellLink(spellID) then
tree[spellID] = nil
end
end
end
end
local healEvents = {
SPELL_HEAL = true,
SPELL_PERIODIC_HEAL = true,
SPELL_AURA_APPLIED = true,
SPELL_AURA_REFRESH = true,
}
function Critline:COMBAT_LOG_EVENT_UNFILTERED()
local timestamp, eventType, hideCaster, sourceGUID, sourceName, sourceFlags, sourceFlags2, destGUID, destName, destFlags, destFlags2,
arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21 = CombatLogGetCurrentEventInfo()
local isPet
-- if sourceGUID is not us or our pet, we leave
if not CombatLog_Object_IsA(sourceFlags, COMBATLOG_FILTER_MINE) then
-- only register if it's a real pet, or a guardian tree pet that's included in the filter
if self:IsMyPet(sourceFlags, sourceGUID) then
isPet = true
-- self:Debug(format("This is my pet (%s)", sourceName))
else
-- self:Debug("This is not me, my trap or my pet; return.")
return
end
else
-- self:Debug(format("This is me or my trap (%s)", sourceName))
end
local isPeriodic
local periodic = 1
local isHeal = healEvents[eventType]
-- we don't care about healing done by the pet
if isHeal and isPet then
self:Debug("Pet healing. Return.")
return
end
if eventType == "SPELL_PERIODIC_DAMAGE" or eventType == "SPELL_PERIODIC_HEAL" then
isPeriodic = true
periodic = 2
end
local combatEvent = combatEvents[eventType]
if not combatEvent then
return
end
-- get the relevants arguments
local spellID, spellName, amount, resisted, critical = combatEvent(arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21)
local rawID = spellID
local cachedID = spellIDCache[spellID]
if cachedID then
spellID = cachedID
elseif not IsPlayerSpell(spellID) then
local spellLink = GetSpellLink(spellName)
if spellLink then
local id = tonumber(spellLink:match("spell:(%d+)"))
if id and IsPlayerSpell(id) then
spellIDCache[spellID] = id
spellID = id
end
end
else
-- cache either way so we don't have to check with IsPlayerSpell when we know that it is
spellIDCache[spellID] = spellID
end
-- if we don't have a destName (who we hit or healed) and we don't have a sourceName (us or our pets) then we leave
if not destName then
self:Debug(format("No target info for %s (%d).", spellName, spellID))
return
end
-- return if the event has no amount (non-absorbing aura applied)
if not amount then
return
end
local spellMapping = spellMappings[spellID]
if spellMapping then
spellID = spellMapping
end
-- some absorb effects seem to have a floating point amount
amount = floor(amount)
if amount <= 0 then
self:Debug(format("Amount <= 0. (%s) Return.", self:GetFullSpellName(spellName, periodic)))
return
end
local tree = "dmg"
if isPet then
tree = "pet"
elseif isHeal then
tree = "heal"
end
-- exit if not recording tree dmg
if not self.percharDB.profile[tree] then
self:Debug(format("Not recording %s spells. Return.", tree))
return
end
local targetLevel = self:GetLevelFromGUID(destGUID)
local passed, isFiltered
if self.filters then
passed, isFiltered = self.filters:SpellPassesFilters(tree, spellName, spellID, isPeriodic, destGUID, destName, targetLevel, rawID)
if not passed then
return
end
end
local isPvPTarget = band(destFlags, COMBATLOG_OBJECT_CONTROL_PLAYER) ~= 0
local friendlyFire = band(destFlags, COMBATLOG_OBJECT_REACTION_FRIENDLY) ~= 0
local hostileTarget = band(destFlags, COMBATLOG_OBJECT_REACTION_HOSTILE) ~= 0
if not (isPvPTarget or self.db.profile.PvE or isHeal) then
self:Debug(format("%s is an NPC and PvE damage is not registered.", destName))
return
end
if isPvPTarget and not (self.db.profile.PvP or isHeal or friendlyFire) then
self:Debug(format("%s is a player and PvP damage is not registered.", destName))
return
end
-- ignore damage done to friendly targets
if friendlyFire and not isHeal then
self:Debug(format("Skipped %s @ %s. Friendly fire.", GetSpellLink(rawID), destName))
return
end
-- ignore healing done to hostile targets
if hostileTarget and isHeal then
self:Debug(format("Skipped %s @ %s. Healing hostile target", GetSpellLink(rawID), destName))
return
end
-- ignore vulnerability damage if necessary
if self.db.profile.ignoreVulnerability and resisted and resisted < 0 then
amount = amount + resisted
self:Debug(format("%d vulnerability damage ignored for a real value of %d.", abs(resisted), amount))
end
local hitType = critical and "crit" or "normal"
local data = self:GetSpellInfo(tree, spellID, periodic)
local arrayData
spellName = self:GetSpellName(spellID)
-- create spell database entries as required
if not data then
self:Debug(format("Creating data for %s (%s)", self:GetFullSpellName(spellName, periodic), tree))
data, arrayData = self:AddSpell(tree, spellID, periodic, spellName, isFiltered)
self:UpdateSpells(tree)
end
if not data[hitType] then
data[hitType] = {amount = 0}
(arrayData or self:GetSpellArrayEntry(tree, spellID, periodic))[hitType] = data[hitType]
end
data = data[hitType]
-- if new amount is larger than the stored amount we'll want to store it
if amount > data.amount then
self:NewRecord(tree, spellID, spellName, periodic, amount, critical, data, isFiltered)
if not isFiltered then
-- update the highest record if needed
local topRecords = topRecords[tree]
if amount > topRecords[hitType] then
topRecords[hitType] = amount
callbacks:Fire("OnNewTopRecord", tree)
end
end
data.amount = amount
data.target = destName
data.targetLevel = targetLevel
data.isPvPTarget = isPvPTarget
self:UpdateRecords(tree, isFiltered)
end
end
function Critline:PLAYER_ENTERING_WORLD()
local name, instanceType, difficultyID, difficultyName, maxPlayers, dynamicDifficulty, isDynamic, instanceMapID = GetInstanceInfo()
bossLevel = RAID_BOSS_LEVELS[instanceMapID] or -1
end
function Critline:IsMyPet(flags, guid)
local _, _, _, _, _, npcID = strsplit("-", guid)
local isMyPet = CombatLog_Object_IsA(flags, COMBATLOG_FILTER_MY_PET)
local isGuardian = band(flags, COMBATLOG_OBJECT_TYPE_GUARDIAN) ~= 0
return isMyPet and ((not isGuardian and HasPetUI()) or classPets[npcID])
end
local levelCache = {}
local levelStrings = {
TOOLTIP_UNIT_LEVEL:format("(%d+)"),
TOOLTIP_UNIT_LEVEL_RACE:format("(%d+)", ".+"),
TOOLTIP_UNIT_LEVEL_RACE_TYPE:format("(%d+)", ".+", ".+"),
TOOLTIP_UNIT_LEVEL_TYPE:format("(%d+)", ".+"),
}
function Critline:GetLevelFromGUID(destGUID)
if levelCache[destGUID] then
return levelCache[destGUID]
end
local tooltipData = C_TooltipInfo.GetHyperlink("unit:"..destGUID)
local level = bossLevel
for i, line in ipairs(tooltipData.lines) do
local text = line.leftText
for i, v in ipairs(levelStrings) do
local level = text and text:match(v)
if level then
level = tonumber(level) or bossLevel
levelCache[destGUID] = level
return level
end
end
end
return level
end
function Critline:Message(...)
print("|cffffff00Critline:|r", ...)
end
function Critline:Debug(...)
if debugging then
print("|cff56a3ffCritlineDebug:|r", ...)
end
end
function Critline:ToggleDebug()
debugging = not debugging
self:Message("Debugging "..(debugging and "enabled" or "disabled"))
end
function Critline:OpenConfig()
config:Open()
end
function Critline:NewRecord(tree, spellID, spellName, periodic, amount, critical, prevRecord, isFiltered)
callbacks:Fire("NewRecord", tree, spellID, spellName, periodic, amount, critical, prevRecord, isFiltered)
if isFiltered then
return
end
amount = self:ShortenNumber(amount)
if self.db.profile.oldRecord and prevRecord.amount > 0 then
amount = format("%s (%s)", amount, self:ShortenNumber(prevRecord.amount))
end
if self.db.profile.chatOutput then
self:Message(format(L["New %s%s record - %s"], critical and "|cffff0000"..L["critical "].."|r" or "", self:GetFullSpellName(spellName, periodic, true), amount))
end
if self.db.profile.screenshot then
Screenshot()
end
PlaySoundFile(LSM:Fetch("sound", self.db.profile.sound))
end
local FIRST_NUMBER_CAP = FIRST_NUMBER_CAP:lower()
function Critline:ShortenNumber(amount)
if tonumber(amount) and self.db.profile.shortFormat then
if amount >= 1e7 then
amount = (floor(amount / 1e5) / 10)..SECOND_NUMBER_CAP
elseif amount >= 1e6 then
amount = (floor(amount / 1e4) / 100)..SECOND_NUMBER_CAP
elseif amount >= 1e4 then
amount = (floor(amount / 100) / 10)..FIRST_NUMBER_CAP
end
end
return amount
end
function Critline:BuildSpellArray(tree)
if not tree then
for tree in pairs(trees) do
self:BuildSpellArray(tree)
end
return
end
local array = spellArrays[tree]
wipe(array)
for spellID, spell in pairs(self.percharDB.profile.spells[tree]) do
for i, v in pairs(spell) do
array[#array + 1] = {
id = spellID,
name = self:GetSpellName(spellID) or tostring(spellID),
filtered = v.filtered,
periodic = i,
normal = v.normal,
crit = v.crit,
}
end
end
end
function Critline:GetSpellArrayEntry(tree, spellID, periodic)
for i, spell in ipairs(spellArrays[tree]) do
if spell.id == spellID and spell.periodic == periodic then
return spell
end
end
end
-- local previousTree
-- local previousSort
function Critline:GetSpellArray(tree, useProfileSort)
local array = spellArrays[tree]
if useProfileSort ~= false then
local sortMethod = useProfileSort and self.db.profile.tooltipSort or "alpha"
-- no need to sort if it's already sorted the way we want it
-- if sortMethod ~= previousSort or tree ~= previousTree then
sort(array, recordSorters[sortMethod])
-- previousTree = tree
-- previousSort = sortMethod
-- end
end
return array
end
-- return spell table from database, given tree, spell name and isPeriodic value
function Critline:GetSpellInfo(tree, spellID, periodic)
local spell = self.percharDB.profile.spells[tree][spellID]
return spell and spell[periodic]
end
function Critline:GetSpellName(spellID, raw)
local spellName = spellNameCache[spellID] or GetSpellName(spellID)
spellNameCache[spellID] = spellName
return (not raw and spellNameOverrides[spellID]) or spellName
end
function Critline:GetSpellTexture(spellID)
local spellTexture = spellIconOverrides[spellID] or spellTextureCache[spellID] or C_Spell.GetSpellTexture(spellID)
spellTextureCache[spellID] = spellTexture
return spellTexture
end
function Critline:GetFullSpellName(spellName, periodic, verbose)
if periodic == 2 then
spellName = format("%s (%s)", spellName, verbose and L["tick"] or "*")
end
return spellName
end
function Critline:GetFullTargetName(spell)
local suffix = ""
if spell.isPvPTarget then
suffix = format(" (%s)", PVP)
end
return format("%s%s", spell.target, suffix)
end
-- retrieves the top, non filtered record amounts and spell names for a given tree
function Critline:UpdateTopRecords(tree)
if not tree then
for tree in pairs(topRecords) do
self:UpdateTopRecords(tree)
end
return
end
local normalRecord, critRecord = 0, 0
for spellID, spell in pairs(self.percharDB.profile.spells[tree]) do
for i, v in pairs(spell) do
if not (self.filters and v.filtered) then
local normal = v.normal
if normal then
normalRecord = max(normal.amount, normalRecord)
end
local crit = v.crit
if crit then
critRecord = max(crit.amount, critRecord)
end
end
end
end
local topRecords = topRecords[tree]
topRecords.normal = normalRecord
topRecords.crit = critRecord
callbacks:Fire("OnNewTopRecord", tree)
end
-- retrieves the top, non filtered record amounts and spell names for a given tree
function Critline:GetHighest(tree)
local topRecords = topRecords[tree]
return topRecords.normal, topRecords.crit
end
function Critline:AddSpell(tree, spellID, periodic, spellName, filtered)
local spells = self.percharDB.profile.spells[tree]
local spell = spells[spellID] or {}
spells[spellID] = spell
spell[periodic] = {filtered = filtered}
local spellArray = spellArrays[tree]
local arrayData = {
id = spellID,
name = spellName,
filtered = filtered,
periodic = periodic,
}
spellArray[#spellArray + 1] = arrayData
return spell[periodic], arrayData
end
function Critline:DeleteSpell(tree, spellID, periodic)
do
local tree = self.percharDB.profile.spells[tree]
local spell = tree[spellID]
spell[periodic] = nil
-- remove this entire spell entry if neither direct nor tick entries remain
if not spell[3 - periodic] then
tree[spellID] = nil
end
end
for i, v in ipairs(spellArrays[tree]) do
if v.id == spellID and v.periodic == periodic then
tremove(spellArrays[tree], i)
self:Message(format(L["Reset %s (%s) records."], self:GetFullSpellName(v.name, v.periodic), trees[tree].label))
break
end
end