-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathLibHealComm-4.0.lua
executable file
·3415 lines (2900 loc) · 134 KB
/
LibHealComm-4.0.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 major = "LibHealComm-4.0"
local minor = 110
assert(LibStub, format("%s requires LibStub.", major))
local HealComm = LibStub:NewLibrary(major, minor)
if( not HealComm ) then return end
local COMM_PREFIX = "LHC40"
C_ChatInfo.RegisterAddonMessagePrefix(COMM_PREFIX)
local bit = bit
local ceil = ceil
local error = error
local floor = floor
local format = format
local gsub = gsub
local max = max
local min = min
local pairs = pairs
local ipairs = ipairs
local rawset = rawset
local select = select
local setmetatable = setmetatable
local strlen = strlen
local strmatch = strmatch
local strsplit = strsplit
local strsub = strsub
local tinsert = tinsert
local tonumber = tonumber
local tremove = tremove
local type = type
local unpack = unpack
local wipe = wipe
local Ambiguate = Ambiguate
local CastingInfo = CastingInfo
local ChannelInfo = ChannelInfo
local CreateFrame = CreateFrame
local GetInventoryItemLink = GetInventoryItemLink
local GetInventorySlotInfo = GetInventorySlotInfo
local GetNumGroupMembers = GetNumGroupMembers
local GetNumTalents = GetNumTalents
local GetNumTalentTabs = GetNumTalentTabs
local GetRaidRosterInfo = GetRaidRosterInfo
local GetSpellBonusHealing = GetSpellBonusHealing
local GetSpellCritChance = GetSpellCritChance
local GetSpellInfo = GetSpellInfo
local GetTalentInfo = GetTalentInfo
local GetTime = GetTime
local GetZonePVPInfo = GetZonePVPInfo
local hooksecurefunc = hooksecurefunc
local InCombatLockdown = InCombatLockdown
local IsEquippedItem = IsEquippedItem
local IsInGroup = IsInGroup
local IsInInstance = IsInInstance
local IsInRaid = IsInRaid
local IsLoggedIn = IsLoggedIn
local IsSpellInRange = IsSpellInRange
local SpellIsTargeting = SpellIsTargeting
local UnitAura = UnitAura
local UnitCanAssist = UnitCanAssist
local UnitExists = UnitExists
local UnitBuff = UnitBuff
local UnitGUID = UnitGUID
local UnitIsCharmed = UnitIsCharmed
local UnitIsVisible = UnitIsVisible
local UnitInRaid = UnitInRaid
local UnitLevel = UnitLevel
local UnitName = UnitName
local UnitPlayerControlled = UnitPlayerControlled
local CheckInteractDistance = CheckInteractDistance
local CombatLogGetCurrentEventInfo = CombatLogGetCurrentEventInfo
local UnitHasVehicleUI = UnitHasVehicleUI or function() end
local GetGlyphSocketInfo = GetGlyphSocketInfo or function() end
local GetNumGlyphSockets = GetNumGlyphSockets or function() return 0 end
local MAX_RAID_MEMBERS = MAX_RAID_MEMBERS
local MAX_PARTY_MEMBERS = MAX_PARTY_MEMBERS
local COMBATLOG_OBJECT_AFFILIATION_MINE = COMBATLOG_OBJECT_AFFILIATION_MINE
local build = floor(select(4,GetBuildInfo())/10000)
local isTBC = build == 2
local isWrath = build == 3
local spellRankTableData = {
[1] = { 774, 8936, 5185, 740, 635, 19750, 139, 2060, 596, 2061, 2054, 2050, 1064, 331, 8004, 136, 755, 689, 746, 33763, 32546, 37563, 48438, 61295, 51945, 50464, 47757 },
[2] = { 1058, 8938, 5186, 8918, 639, 19939, 6074, 10963, 996, 9472, 2055, 2052, 10622, 332, 8008, 3111, 3698, 699, 1159, 53248, 61299, 51990, 48450, 52986, 48119 },
[3] = { 1430, 8939, 5187, 9862, 647, 19940, 6075, 10964, 10960, 9473, 6063, 2053, 10623, 547, 8010, 3661, 3699, 709, 3267, 53249, 61300, 51997, 48451, 52987, 48120 },
[4] = { 2090, 8940, 5188, 9863, 1026, 19941, 6076, 10965, 10961, 9474, 6064, 913, 10466, 3662, 3700, 7651, 3268, 25422, 53251, 61301, 51998, 52988 },
[5] = { 2091, 8941, 5189, 1042, 19942, 6077, 22009, 25314, 25316, 10915, 939, 10467, 13542, 11693, 11699, 7926, 25423, 26983, 51999 },
[6] = { 3627, 9750, 6778, 3472, 19943, 6078, 10916, 959, 10468, 13543, 11694, 11700, 7927, 23569, 24412, 25210, 25308, 52000, 55458, 48446 },
[7] = { 8910, 9856, 8903, 10328, 10927, 10917, 8005, 13544, 11695, 10838, 27137, 25213, 25420, 27219, 55459, 48447, 48072 },
[8] = { 9839, 9857, 9758, 10329, 10928, 10395, 10839, 23568, 24413, 25233, 27259, 27220, 27046, 48784, 49275, 48062 },
[9] = { 9840, 9858, 9888, 25292, 10929, 10396, 18608, 25235, 48785, 49276, 48063, 48989, 47856, 47857 },
[10] = { 9841, 9889, 25315, 25357, 18610, 23567, 24414, 26980, 27135, 48070, 48990 },
[11] = { 25299, 25297, 30020, 27136, 25221, 25391, 27030, 48442, 48071 },
[12] = { 26981, 26978, 25222, 25396, 27031, 48781, 48443 },
[13] = { 26982, 26979, 48782, 49272, 48067, 45543 },
[14] = { 49273, 48377, 48440, 48068, 51827 },
[15] = { 48378, 48441, 45544 },
[16] = { 51803 },
}
local SpellIDToRank = {}
for rankIndex, spellIDTable in pairs(spellRankTableData) do
for _, spellID in pairs(spellIDTable) do
SpellIDToRank[spellID] = rankIndex
end
end
-- API CONSTANTS
local ALL_DATA = 0x0f
local DIRECT_HEALS = 0x01
local CHANNEL_HEALS = 0x02
local HOT_HEALS = 0x04
local ABSORB_SHIELDS = 0x08
local BOMB_HEALS = 0x10
local ALL_HEALS = bit.bor(DIRECT_HEALS, CHANNEL_HEALS, HOT_HEALS, BOMB_HEALS)
local CASTED_HEALS = bit.bor(DIRECT_HEALS, CHANNEL_HEALS)
local OVERTIME_HEALS = bit.bor(HOT_HEALS, CHANNEL_HEALS)
local OVERTIME_AND_BOMB_HEALS = bit.bor(HOT_HEALS, CHANNEL_HEALS, BOMB_HEALS)
HealComm.ALL_HEALS, HealComm.OVERTIME_HEALS, HealComm.OVERTIME_AND_BOMB_HEALS, HealComm.CHANNEL_HEALS, HealComm.DIRECT_HEALS, HealComm.HOT_HEALS, HealComm.CASTED_HEALS, HealComm.ABSORB_SHIELDS, HealComm.ALL_DATA, HealComm.BOMB_HEALS = ALL_HEALS, OVERTIME_HEALS, OVERTIME_AND_BOMB_HEALS, CHANNEL_HEALS, DIRECT_HEALS, HOT_HEALS, CASTED_HEALS, ABSORB_SHIELDS, ALL_DATA, BOMB_HEALS
local playerGUID, playerName, playerLevel
local playerHealModifier = 1
HealComm.callbacks = HealComm.callbacks or LibStub:GetLibrary("CallbackHandler-1.0"):New(HealComm)
HealComm.activeHots = HealComm.activeHots or {}
HealComm.activePets = HealComm.activePets or {}
HealComm.equippedSetCache = HealComm.equippedSetCache or {}
HealComm.guidToGroup = HealComm.guidToGroup or {}
HealComm.guidToUnit = HealComm.guidToUnit or {}
HealComm.hotData = HealComm.hotData or {}
HealComm.itemSetsData = HealComm.itemSetsData or {}
HealComm.pendingHeals = HealComm.pendingHeals or {}
HealComm.pendingHots = HealComm.pendingHots or {}
HealComm.spellData = HealComm.spellData or {}
HealComm.talentData = HealComm.talentData or {}
HealComm.tempPlayerList = HealComm.tempPlayerList or {}
HealComm.glyphCache = HealComm.glyphCache or {}
if( not HealComm.unitToPet ) then
HealComm.unitToPet = {["player"] = "pet"}
for i = 1, MAX_PARTY_MEMBERS do HealComm.unitToPet["party" .. i] = "partypet" .. i end
for i = 1, MAX_RAID_MEMBERS do HealComm.unitToPet["raid" .. i] = "raidpet" .. i end
end
local spellData, hotData, tempPlayerList, pendingHeals, pendingHots = HealComm.spellData, HealComm.hotData, HealComm.tempPlayerList, HealComm.pendingHeals, HealComm.pendingHots
local equippedSetCache, itemSetsData, talentData = HealComm.equippedSetCache, HealComm.itemSetsData, HealComm.talentData
local activeHots, activePets = HealComm.activeHots, HealComm.activePets
-- Figure out what they are now since a few things change based off of this
local playerClass = select(2, UnitClass("player"))
if( not HealComm.compressGUID ) then
HealComm.compressGUID = setmetatable({}, {
__index = function(tbl, guid)
local str
if strsub(guid,1,6) ~= "Player" then
for unit,pguid in pairs(activePets) do
if pguid == guid and UnitExists(unit) then
str = "p-" .. strmatch(UnitGUID(unit), "^%w*-([-%w]*)$")
end
end
if not str then
--assert(str, "Could not encode: "..guid)
return nil
end
else
str = strmatch(guid, "^%w*-([-%w]*)$")
end
rawset(tbl, guid, str)
return str
end})
HealComm.decompressGUID = setmetatable({}, {
__index = function(tbl, str)
if( not str ) then return nil end
local guid
if strsub(str,1,2) == "p-" then
local unit = HealComm.guidToUnit["Player-"..strsub(str,3)]
if not unit then
return nil
end
guid = activePets[unit]
else
guid = "Player-"..str
end
rawset(tbl, str, guid)
return guid
end})
end
local compressGUID, decompressGUID = HealComm.compressGUID, HealComm.decompressGUID
-- Handles caching of tables for variable tick spells, like Wild Growth
if( not HealComm.tableCache ) then
HealComm.tableCache = setmetatable({}, {__mode = "k"})
function HealComm:RetrieveTable()
return tremove(HealComm.tableCache, 1) or {}
end
function HealComm:DeleteTable(tbl)
wipe(tbl)
tinsert(HealComm.tableCache, tbl)
end
end
-- Validation for passed arguments
if( not HealComm.tooltip ) then
local tooltip = CreateFrame("GameTooltip")
tooltip:SetOwner(UIParent, "ANCHOR_NONE")
tooltip.TextLeft1 = tooltip:CreateFontString()
tooltip.TextRight1 = tooltip:CreateFontString()
tooltip:AddFontStrings(tooltip.TextLeft1, tooltip.TextRight1)
HealComm.tooltip = tooltip
end
-- Record management, because this is getting more complicted to deal with
local function updateRecord(pending, guid, amount, stack, endTime, ticksLeft)
if( pending[guid] ) then
local id = pending[guid]
pending[id] = guid
pending[id + 1] = amount
pending[id + 2] = stack
pending[id + 3] = endTime or 0
pending[id + 4] = ticksLeft or 0
else
pending[guid] = #(pending) + 1
tinsert(pending, guid)
tinsert(pending, amount)
tinsert(pending, stack)
tinsert(pending, endTime or 0)
tinsert(pending, ticksLeft or 0)
if( pending.bitType == HOT_HEALS ) then
activeHots[guid] = (activeHots[guid] or 0) + 1
HealComm.hotMonitor:Show()
end
end
end
local function getRecord(pending, guid)
local id = pending[guid]
if( not id ) then return nil end
-- amount, stack, endTime, ticksLeft
return pending[id + 1], pending[id + 2], pending[id + 3], pending[id + 4]
end
local function removeRecord(pending, guid)
local id = pending[guid]
if( not id ) then return nil end
-- ticksLeft, endTime, stack, amount, guid
tremove(pending, id + 4)
tremove(pending, id + 3)
tremove(pending, id + 2)
local amount = tremove(pending, id + 1)
tremove(pending, id)
pending[guid] = nil
-- Release the table
if( type(amount) == "table" ) then HealComm:DeleteTable(amount) end
if( pending.bitType == HOT_HEALS and activeHots[guid] ) then
activeHots[guid] = activeHots[guid] - 1
activeHots[guid] = activeHots[guid] > 0 and activeHots[guid] or nil
end
-- Shift any records after this ones index down 5 to account for the removal
for i=1, #(pending), 5 do
local guid = pending[i]
if( pending[guid] > id ) then
pending[guid] = pending[guid] - 5
end
end
end
local function removeRecordList(pending, inc, comp, ...)
for i=1, select("#", ...), inc do
local guid = select(i, ...)
guid = comp and decompressGUID[guid] or guid
if guid then
local id = pending[guid]
-- ticksLeft, endTime, stack, amount, guid
tremove(pending, id + 4)
tremove(pending, id + 3)
tremove(pending, id + 2)
local amount = tremove(pending, id + 1)
tremove(pending, id)
pending[guid] = nil
-- Release the table
if( type(amount) == "table" ) then HealComm:DeleteTable(amount) end
end
end
-- Redo all the id maps
for i=1, #(pending), 5 do
pending[pending[i]] = i
end
end
-- Removes every mention to the given GUID
local function removeAllRecords(guid)
local changed
for _, tbl in pairs({pendingHeals, pendingHots}) do
for _, spells in pairs(tbl) do
for _, pending in pairs(spells) do
if( pending.bitType and pending[guid] ) then
local id = pending[guid]
-- ticksLeft, endTime, stack, amount, guid
tremove(pending, id + 4)
tremove(pending, id + 3)
tremove(pending, id + 2)
local amount = tremove(pending, id + 1)
tremove(pending, id)
pending[guid] = nil
-- Release the table
if( type(amount) == "table" ) then HealComm:DeleteTable(amount) end
-- Shift everything back
if( #(pending) > 0 ) then
for i=1, #(pending), 5 do
local guid = pending[i]
if( pending[guid] > id ) then
pending[guid] = pending[guid] - 5
end
end
else
wipe(pending)
end
changed = true
end
end
end
end
activeHots[guid] = nil
if( changed ) then
HealComm.callbacks:Fire("HealComm_GUIDDisappeared", guid)
end
end
-- These are not public APIs and are purely for the wrapper to use
HealComm.removeRecordList = removeRecordList
HealComm.removeRecord = removeRecord
HealComm.getRecord = getRecord
HealComm.updateRecord = updateRecord
-- Removes all pending heals, if it's a group that is causing the clear then we won't remove the players heals on themselves
local function clearPendingHeals()
for _, tbl in pairs({pendingHeals, pendingHots}) do
for casterGUID, spells in pairs(tbl) do
for _, pending in pairs(spells) do
if( pending.bitType ) then
wipe(tempPlayerList)
for i=#(pending), 1, -5 do tinsert(tempPlayerList, pending[i - 4]) end
if( #(tempPlayerList) > 0 ) then
local spellID, bitType = pending.spellID, pending.bitType
wipe(pending)
HealComm.callbacks:Fire("HealComm_HealStopped", casterGUID, spellID, bitType, true, unpack(tempPlayerList))
end
end
end
end
end
end
-- APIs
-- Returns the players current heaing modifier
function HealComm:GetPlayerHealingMod()
return playerHealModifier or 1
end
-- Returns the current healing modifier for the GUID
function HealComm:GetHealModifier(guid)
return HealComm.currentModifiers[guid] or 1
end
-- Returns whether or not the GUID has casted a heal
function HealComm:GUIDHasHealed(guid)
return (pendingHeals[guid] or pendingHots[guid]) and true or nil
end
-- Returns the guid to unit table
function HealComm:GetGUIDUnitMapTable()
if( not HealComm.protectedMap ) then
HealComm.protectedMap = setmetatable({}, {
__index = function(tbl, key) return HealComm.guidToUnit[key] end,
__newindex = function() error("This is a read only table and cannot be modified.", 2) end,
__metatable = false
})
end
return HealComm.protectedMap
end
-- Gets the next heal landing on someone using the passed filters
function HealComm:GetNextHealAmount(guid, bitFlag, time, ignoreGUID, srcGUID)
local healTime, healAmount, healFrom
local currentTime = GetTime()
for _, tbl in pairs({pendingHeals, pendingHots}) do
for casterGUID, spells in pairs(tbl) do
if( not ignoreGUID or ignoreGUID ~= casterGUID ) and (not srcGUID or srcGUID == casterGUID) then
for _, pending in pairs(spells) do
if( pending.bitType and bit.band(pending.bitType, bitFlag) > 0 ) then
for i=1, #(pending), 5 do
local targetGUID = pending[i]
if(not guid or targetGUID == guid) then
local amount = pending[i + 1]
local stack = pending[i + 2]
local endTime = pending[i + 3]
endTime = endTime > 0 and endTime or pending.endTime
-- Direct heals are easy, if they match the filter then return them
if( ( pending.bitType == DIRECT_HEALS or pending.bitType == BOMB_HEALS ) and ( not time or endTime <= time ) ) then
if( not healTime or endTime < healTime ) then
healTime = endTime
healAmount = amount * stack
healFrom = casterGUID
end
-- Channeled heals and hots, have to figure out how many times it'll tick within the given time band
elseif( ( pending.bitType == CHANNEL_HEALS or pending.bitType == HOT_HEALS ) ) then
local secondsLeft = time and time - currentTime or endTime - currentTime
local nextTick = currentTime + (secondsLeft % pending.tickInterval)
if( not healTime or nextTick < healTime ) then
healTime = nextTick
if pending.hasVariableTicks then
healAmount = amount[pending.totalTicks - pending[i + 4] + 1]
else
healAmount = amount * stack
end
healFrom = casterGUID
end
end
end
end
end
end
end
end
end
return healTime, healFrom, healAmount
end
-- Get the healing amount that matches the passed filters
local function filterData(spells, filterGUID, bitFlag, time, ignoreGUID)
local healAmount = 0
local currentTime = GetTime()
if spells then
for _, pending in pairs(spells) do
if( pending.bitType and bit.band(pending.bitType, bitFlag) > 0 ) then
for i = 1, #(pending), 5 do
local guid = pending[i]
if( guid == filterGUID or ignoreGUID ) then
local amount = pending[i + 1]
local stack = pending[i + 2]
local endTime = pending[i + 3]
endTime = endTime > 0 and endTime or pending.endTime
if( ( pending.bitType == DIRECT_HEALS or pending.bitType == BOMB_HEALS ) and ( not time or endTime <= time ) ) then
healAmount = healAmount + amount * stack
elseif( ( pending.bitType == CHANNEL_HEALS or pending.bitType == HOT_HEALS ) and endTime > currentTime ) then
local ticksLeft = pending[i + 4]
if( not time or time >= endTime ) then
if( not pending.hasVariableTicks ) then
healAmount = healAmount + (amount * stack) * ticksLeft
else
local ticksPassed = pending.totalTicks - ticksLeft
for numTick, heal in pairs(amount) do
if numTick > ticksPassed then
healAmount = healAmount + (heal * stack)
end
end
end
else
local secondsLeft = endTime - currentTime
local bandSeconds = time - currentTime
local ticks = floor(min(bandSeconds, secondsLeft) / pending.tickInterval)
local nextTickIn = secondsLeft % pending.tickInterval
local fractionalBand = bandSeconds % pending.tickInterval
if( nextTickIn > 0 and nextTickIn < fractionalBand ) then
ticks = ticks + 1
end
if( not pending.hasVariableTicks ) then
healAmount = healAmount + (amount * stack) * min(ticks, ticksLeft)
else
local ticksPassed = pending.totalTicks - ticksLeft
for numTick, heal in ipairs(amount) do
if numTick > ticksPassed then
healAmount = healAmount + (heal * stack)
end
end
end
end
end
end
end
end
end
end
return healAmount
end
-- Gets healing amount using the passed filters
function HealComm:GetHealAmount(guid, bitFlag, time, casterGUID)
local amount = 0
if( casterGUID and (pendingHeals[casterGUID] or pendingHots[casterGUID]) ) then
amount = filterData(pendingHeals[casterGUID], guid, bitFlag, time) + filterData(pendingHots[casterGUID], guid, bitFlag, time)
elseif( not casterGUID ) then
for _, tbl in pairs({pendingHeals, pendingHots}) do
for _, spells in pairs(tbl) do
amount = amount + filterData(spells, guid, bitFlag, time)
end
end
end
return amount > 0 and amount or nil
end
-- Gets healing amounts for everyone except the player using the passed filters
function HealComm:GetOthersHealAmount(guid, bitFlag, time)
local amount = 0
for _, tbl in pairs({pendingHeals, pendingHots}) do
for casterGUID, spells in pairs(tbl) do
if( casterGUID ~= playerGUID ) then
amount = amount + filterData(spells, guid, bitFlag, time)
end
end
end
return amount > 0 and amount or nil
end
function HealComm:GetCasterHealAmount(guid, bitFlag, time)
local amount = pendingHeals[guid] and filterData(pendingHeals[guid], nil, bitFlag, time, true) or 0
amount = amount + (pendingHots[guid] and filterData(pendingHots[guid], nil, bitFlag, time, true) or 0)
return amount > 0 and amount or nil
end
function HealComm:GetHealAmountEx(dstGUID, dstBitFlag, dstTime, srcGUID, srcBitFlag, srcTime)
local dstAmount1 = 0
local dstAmount2 = 0
local srcAmount1 = 0
local srcAmount2 = 0
local currTime = GetTime()
dstBitFlag = dstBitFlag or ALL_HEALS
srcBitFlag = srcBitFlag or ALL_HEALS
for _, tbl in ipairs({pendingHeals, pendingHots}) do
for casterGUID, spells in pairs(tbl) do
local time
if casterGUID ~= srcGUID then
time = dstTime
else
time = srcTime
end
if spells then
for _, pending in pairs(spells) do
local bitType = pending.bitType or 0
if casterGUID ~= srcGUID then
bitType = bit.band(bitType, dstBitFlag)
else
bitType = bit.band(bitType, srcBitFlag)
end
if bitType > 0 then
for i = 1, #pending, 5 do
local targetGUID = pending[i]
if targetGUID == dstGUID then
local amount = 0
if not pending.hasVariableTicks then
amount = pending[i + 1]
end
local stack = pending[i + 2]
local endTime = pending[i + 3]
endTime = endTime > 0 and endTime or pending.endTime
if endTime > currTime then
amount = amount * stack
local amount1 = 0
local amount2 = 0
if bitType == DIRECT_HEALS or bitType == BOMB_HEALS then
if not time or endTime <= time then
amount1 = amount
end
amount2 = amount
elseif bitType == HOT_HEALS or bitType == CHANNEL_HEALS then
local ticksLeft = pending[i + 4]
local ticks
if not time then
ticks = 1
elseif time >= endTime then
ticks = ticksLeft
else
local tickInterval = pending.tickInterval
local secondsLeft = endTime - currTime
local bandSeconds = max(time - currTime, 0)
ticks = floor(min(bandSeconds, secondsLeft) / tickInterval)
local nextTickIn = secondsLeft % tickInterval
local fractionalBand = bandSeconds % tickInterval
if nextTickIn > 0 and nextTickIn < fractionalBand then
ticks = ticks + 1
end
end
if ticks > ticksLeft then
ticks = ticksLeft
end
if not pending.hasVariableTicks then
amount1 = amount * ticks
amount2 = amount * ticksLeft
else
amount = pending[i + 1]
amount1 = amount[pending.totalTicks - pending[i + 4] + 1] or 0
local ticksPassed = pending.totalTicks - ticksLeft
for numTick, heal in ipairs(amount) do
if numTick > ticksPassed then
amount2 = amount2 + (heal * stack)
end
end
end
end
if casterGUID ~= srcGUID then
dstAmount1 = dstAmount1 + amount1
dstAmount2 = dstAmount2 + amount2
else
srcAmount1 = srcAmount1 + amount1
srcAmount2 = srcAmount2 + amount2
end
end
end
end
end
end
end
end
end
dstAmount2 = dstAmount2 - dstAmount1
srcAmount2 = srcAmount2 - srcAmount1
dstAmount1 = dstAmount1 > 0 and dstAmount1 or nil
dstAmount2 = dstAmount2 > 0 and dstAmount2 or nil
srcAmount1 = srcAmount1 > 0 and srcAmount1 or nil
srcAmount2 = srcAmount2 > 0 and srcAmount2 or nil
return dstAmount1, dstAmount2, srcAmount1, srcAmount2
end
-- Get the number of direct heals on a target
function HealComm:GetNumHeals(filterGUID, time)
local numHeals = 0
for _, spells in pairs(pendingHeals) do
if spells then
for _, pending in pairs(spells) do
for i = 1, #(pending), 5 do
local guid = pending[i]
if( guid == filterGUID ) then
local endTime = pending[i + 3]
endTime = endTime > 0 and endTime or pending.endTime
if( pending.bitType == DIRECT_HEALS and ( not time or endTime <= time ) ) then
numHeals = numHeals + 1
end
end
end
end
end
end
return numHeals
end
-- Healing class data
-- Thanks to Gagorian (DrDamage) for letting me steal his formulas and such
local playerCurrentRelic
local guidToUnit, guidToGroup, glyphCache = HealComm.guidToUnit, HealComm.guidToGroup, HealComm.glyphCache
local unitHasAura
do
local findAura = AuraUtil.FindAura
local findAuraByName = AuraUtil.FindAuraByName
local function spellIdPredicate(spellIdToFind, _, _, _, _, _, _, _, _, _, _, _, spellId)
return spellIdToFind == spellId
end
local function findAuraBySpellId(spellId, unit, filter)
return findAura(spellIdPredicate, unit, filter, spellId)
end
function unitHasAura(unit, name)
if type(name) == "number" then
return findAuraBySpellId(name, unit)
else
return findAuraByName(name, unit)
end
end
end
-- Note because I always forget on the order:
-- Talents that effective the coeffiency of spell power to healing are first and are tacked directly onto the coeffiency (Empowered Rejuvenation)
-- Penalty modifiers (downranking/spell level too low) are applied directly to the spell power
-- Spell power modifiers are then applied to the spell power
-- Heal modifiers are applied after all of that
-- Crit modifiers are applied after
-- Any other modifiers such as Mortal Strike or Avenging Wrath are applied after everything else
local function calculateGeneralAmount(level, amount, spellPower, spModifier, healModifier)
local penalty = level > 20 and 1 or (1 - ((20 - level) * 0.0375))
if isWrath then
--https://wowwiki-archive.fandom.com/wiki/Downranking
penalty = min(1,max(0,(22+(level+5)-playerLevel)/20))
elseif isTBC then
-- TBC added another downrank penalty
penalty = penalty * min(1, (level + 11) / playerLevel)
end
spellPower = spellPower * penalty
return healModifier * (amount + (spellPower * spModifier))
end
local function DirectCoefficient(castTime)
return castTime / 3.5
end
local function HotCoefficient(duration)
return duration / 15
end
local function avg(a, b)
return (a + b) / 2
end
--[[
What the different callbacks do:
AuraHandler: Specific aura tracking needed for this class, who has Beacon up on them and such
ResetChargeData: Due to spell "queuing" you can't always rely on aura data for buffs that last one or two casts, for example Divine Favor (+100% crit, one spell)
if you cast Holy Light and queue Flash of Light the library would still see they have Divine Favor and give them crits on both spells. The reset means that the flag that indicates
they have the aura can be killed and if they interrupt the cast then it will call this and let you reset the flags.
What happens in terms of what the client thinks and what actually is, is something like this:
UNIT_SPELLCAST_START, Holy Light -> Divine Favor up
UNIT_SPELLCAST_SUCCEEDED, Holy Light -> Divine Favor up (But it was really used)
UNIT_SPELLCAST_START, Flash of Light -> Divine Favor up (It's not actually up but auras didn't update)
UNIT_AURA -> Divine Favor up (Split second where it still thinks it's up)
UNIT_AURA -> Divine Favor faded (Client catches up and realizes it's down)
CalculateHealing: Calculates the healing value, does all the formula calculations talent modifiers and such
CalculateHotHealing: Used specifically for calculating the heals of hots
GetHealTargets: Who the heal is going to hit, used for setting extra targets for Beacon of Light + Paladin heal or Prayer of Healing.
The returns should either be:
"compressedGUID1,compressedGUID2,compressedGUID3,compressedGUID4", healthAmount
Or if you need to set specific healing values for one GUID it should be
"compressedGUID1,healthAmount1,compressedGUID2,healAmount2,compressedGUID3,healAmount3", -1
The latter is for cases like Glyph of Healing Wave where you need a heal for 1,000 on A and a heal for 200 on the player for B without sending 2 events.
The -1 tells the library to look in the GUId list for the heal amounts
**NOTE** Any GUID returned from GetHealTargets must be compressed through a call to compressGUID[guid]
]]
local CalculateHealing, GetHealTargets, AuraHandler, CalculateHotHealing, ResetChargeData, LoadClassData
local function getBaseHealAmount(spellData, spellName, spellID, spellRank)
if spellID == 37563 then
spellData = spellData["37563"]
else
spellData = spellData[spellName]
end
local average = spellData.averages[spellRank]
if type(average) == "number" then
return average
end
local requiresLevel = spellData.levels[spellRank]
return average[min(playerLevel - requiresLevel + 1, #average)]
end
if( playerClass == "DRUID" ) then
LoadClassData = function()
local GiftofNature = GetSpellInfo(17104)
local HealingTouch = GetSpellInfo(5185)
local ImprovedRejuv = GetSpellInfo(17111)
local MarkoftheWild = GetSpellInfo(1126)
local Regrowth = GetSpellInfo(8936)
local Rejuvenation = GetSpellInfo(774)
local Tranquility = GetSpellInfo(740)
local Lifebloom = GetSpellInfo(33763) or "Lifebloom"
local EmpoweredRejuv = GetSpellInfo(33886) or "Empowered Rejuv"
local EmpoweredTouch = GetSpellInfo(33879) or "Empowered Touch"
local WildGrowth = GetSpellInfo(48438) or "Wild Growth"
local Nourish = GetSpellInfo(50464) or "Nourish"
local MasterShapeshifter = GetSpellInfo(48411) or "Master Shapeshifter"
local Genesis = GetSpellInfo(57810) or "Genesis"
local NaturesSplendor = GetSpellInfo(57865) or "Natures Splendor"
local TreeofLife = GetSpellInfo(33891) or "Tree of Life"
hotData[Regrowth] = { interval = 3, ticks = 7, coeff = (isTBC or isWrath) and 0.7 or 0.5, levels = { 12, 18, 24, 30, 36, 42, 48, 54, 60, 65, 71, 77 }, averages = { 98, 175, 259, 343, 427, 546, 686, 861, 1064, 1274, 1792, 2345 }}
if isWrath then
hotData[Rejuvenation] = { interval = 3, levels = { 4, 10, 16, 22, 28, 34, 40, 46, 52, 58, 60, 63, 69, 75, 80 }, averages = { 40, 70, 145, 225, 305, 380, 485, 610, 760, 945, 1110, 1165, 1325, 1490, 1690 }}
hotData[Lifebloom] = {interval = 1, ticks = 7, coeff = 0.66626, dhCoeff = 0.517928287, levels = {64, 72, 80}, averages = {224, 287, 371}, bomb = {480, 616, 776}}
hotData[WildGrowth] = {interval = 1, ticks = 7, coeff = 0.8056, levels = {60, 70, 75, 80}, averages = {686, 861, 1239, 1442}}
else
hotData[Rejuvenation] = { interval = 3, levels = { 4, 10, 16, 22, 28, 34, 40, 46, 52, 58, 60, 63, 69 }, averages = { 32, 56, 116, 180, 244, 304, 388, 488, 608, 756, 888, 932, 1060 }}
hotData[Lifebloom] = {interval = 1, ticks = 7, coeff = 0.52, dhCoeff = 0.34335, levels = {64}, averages = {273}, bomb = {600}}
end
if isWrath then
spellData[HealingTouch] = { levels = {1, 8, 14, 20, 26, 32, 38, 44, 50, 56, 60, 62, 69, 74, 79}, averages = {
{avg(37, 51), avg(37, 52), avg(38, 53), avg(39, 54), avg(40, 55)},
{avg(88, 112), avg(89, 114), avg(90, 115), avg(91, 116), avg(93, 118), avg(94, 119)},
{avg(195, 243), avg(196, 245), avg(198, 247), avg(200, 249), avg(202, 251), avg(204, 253)},
{avg(363, 445), avg(365, 448), avg(368, 451), avg(371, 454), avg(373, 456), avg(376, 459)},
{avg(490, 594), avg(493, 597), avg(496, 600), avg(499, 603), avg(502, 606), avg(505, 609)},
{avg(636, 766), avg(639, 770), avg(642, 773), avg(646, 777), avg(649, 780), avg(653, 783)},
{avg(802, 960), avg(805, 964), avg(809, 968), avg(813, 972), avg(817, 976), avg(821, 980)},
{avg(1199, 1427), avg(1203, 1432), avg(1208, 1436), avg(1212, 1441), avg(1217, 1445), avg(1221, 1450)},
{avg(1299, 1539), avg(1304, 1545), avg(1309, 1550), avg(1314, 1555), avg(1319, 1560), avg(1324, 1565)},
{avg(1620, 1912), avg(1625, 1918), avg(1631, 1924), avg(1637, 1930), avg(1642, 1935), avg(1648, 1941)},
{avg(1944, 2294), avg(1950, 2301), avg(1956, 2307), avg(1962, 2313), avg(1968, 2319), avg(1975, 2325)},
{avg(2026, 2392), avg(2032, 2399), avg(2038, 2405), avg(2044, 2411), avg(2051, 2418), avg(2057, 2424)},
{avg(2321, 2739), avg(2328, 2746), avg(2335, 2753), avg(2342, 2760), avg(2349, 2767)},
{avg(3223, 3805), avg(3232, 3815), avg(3242, 3825), avg(3252, 3835), avg(3262, 3845)},
{avg(3750, 4428), avg(3761, 4440)} }}
else
spellData[HealingTouch] = { levels = {1, 8, 14, 20, 26, 32, 38, 44, 50, 56, 60, 62, 69}, averages = {
{avg(37, 51), avg(37, 52), avg(38, 53), avg(39, 54), avg(40, 55)},
{avg(88, 112), avg(89, 114), avg(90, 115), avg(91, 116), avg(93, 118), avg(94, 119)},
{avg(195, 243), avg(196, 245), avg(198, 247), avg(200, 249), avg(202, 251), avg(204, 253)},
{avg(363, 445), avg(365, 448), avg(368, 451), avg(371, 454), avg(373, 456), avg(376, 459)},
{avg(572, 694), avg(575, 698), avg(579, 701), avg(582, 705), avg(586, 708), avg(589, 712)},
{avg(742, 894), avg(746, 898), avg(750, 902), avg(754, 906), avg(758, 910), avg(762, 914)},
{avg(936, 1120), avg(940, 1125), avg(945, 1129), avg(949, 1134), avg(954, 1138), avg(958, 1143)},
{avg(1199, 1427), avg(1204, 1433), avg(1209, 1438), avg(1214, 1443), avg(1219, 1448), avg(1225, 1453)},
{avg(1516, 1796), avg(1521, 1802), avg(1527, 1808), avg(1533, 1814), avg(1539, 1820), avg(1545, 1826)},
{avg(1890, 2230), avg(1896, 2237), avg(1903, 2244), avg(1909, 2250), avg(1916, 2257), avg(1923, 2263)},
{avg(2267, 2677), avg(2274, 2685), avg(2281, 2692), avg(2288, 2699), avg(2296, 2707), avg(2303, 2714)},
{avg(2364, 2790), avg(2371, 2798), avg(2378, 2805), avg(2386, 2813), avg(2393, 2820), avg(2401, 2827)},
{avg(2707, 3197), avg(2715, 3206)} }}
end
spellData[Regrowth] = {coeff = (isWrath and 0.6 or 0.5) * (2 / 3.5) , levels = hotData[Regrowth].levels, averages = {
{avg(84, 98), avg(85, 100), avg(87, 102), avg(89, 104), avg(91, 106), avg(93, 107)},
{avg(164, 188), avg(166, 191), avg(169, 193), avg(171, 196), avg(174, 198), avg(176, 201)},
{avg(240, 274), avg(243, 278), avg(246, 281), avg(249, 284), avg(252, 287), avg(255, 290)},
{avg(318, 360), avg(321, 364), avg(325, 368), avg(328, 371), avg(332, 375), avg(336, 378)},
{avg(405, 457), avg(409, 462), avg(413, 466), avg(417, 470), avg(421, 474), avg(425, 478)},
{avg(511, 575), avg(515, 580), avg(520, 585), avg(525, 590), avg(529, 594), avg(534, 599)},
{avg(646, 724), avg(651, 730), avg(656, 735), avg(661, 740), avg(667, 746), avg(672, 751)},
{avg(809, 905), avg(815, 911), avg(821, 917), avg(827, 923), avg(833, 929), avg(839, 935)},
{avg(1003, 1119), avg(1009, 1126), avg(1016, 1133), avg(1023, 1140), avg(1030, 1147), avg(1037, 1153)},
{avg(1215, 1355), avg(1222, 1363), avg(1230, 1371), avg(1238, 1379), avg(1245, 1386), avg(1253, 1394)},
{avg(1710, 1908), avg(1720, 1919), avg(1731, 1930), avg(1742, 1941), avg(1753, 1952), avg(1764, 1962)},
{avg(2234, 2494), avg(2241, 2502), avg(2249, 2510), avg(2257, 2518)} }}
if isTBC or isWrath then
spellData[Tranquility] = {_isChanneled = true, coeff = 1.145, ticks = 4, interval = 2, levels = {30, 40, 50, 60, 70, 75, 80}, averages = {
{351 * 4, 354 * 4, 356 * 4, 358 * 4, 360 * 4, 362 * 4, 365 * 4},
{515 * 4, 518 * 4, 521 * 4, 523 * 4, 526 * 4, 528 * 4, 531 * 4},
{765 * 4, 769 * 4, 772 * 4, 776 * 4, 779 * 4, 782 * 4, 786 * 4},
{1097 * 4, 1101 * 4, 1105 * 4, 1109 * 4, 1112 * 4, 1116 * 4, 1120 * 4},
{1518 * 4, 1523 * 4, 1527 * 4, 1532 * 4, 1536 * 4},
{2598 * 4, 2606 * 4, 2614 * 4, 2622 * 4, 2629 * 4},
{3035 * 4} }}
else
spellData[Tranquility] = {_isChanneled = true, coeff = 1/3, ticks = 5, interval = 2, levels = {30, 40, 50, 60}, averages = {
{94 * 5, 95 * 5, 96 * 5, 96 * 5, 97 * 5, 97 * 5, 98 * 5},
{138 * 5, 139 * 5, 140 * 5, 141 * 5, 141 * 5, 142 * 5, 143 * 5},
{205 * 5, 206 * 5, 207 * 5, 208 * 5, 209 * 5, 210 * 5, 211 * 5},
{294 * 5} }}
end
spellData[Nourish] = {coeff = 0.358005, levels = {80}, averages = {avg(1883, 2187)}}
talentData[GiftofNature] = {mod = 0.02, current = 0}
talentData[ImprovedRejuv] = {mod = 0.05, current = 0}
talentData[EmpoweredRejuv] = {mod = 0.04, current = 0}
talentData[EmpoweredTouch] = {mod = 0.1, current = 0}
talentData[Genesis] = {mod = 0.01, current = 0}
talentData[NaturesSplendor] = {mod = 1, current = 0}
talentData[MasterShapeshifter] = {mod = 0.02, current = 0}
itemSetsData["Stormrage"] = {16903, 16898, 16904, 16897, 16900, 16899, 16901, 16902}
itemSetsData["Nordrassil"] = {30216, 30217, 30219, 30220, 30221}
itemSetsData["Thunderheart"] = {31041, 31032, 31037, 31045, 31047, 34571, 34445, 34554}
itemSetsData["Dreamwalker"] = {40460, 40461, 40462, 40463, 40465, 39531, 39538, 39539, 39542, 39543}
itemSetsData["Lasherweave"] = {50106, 50107, 50108, 50109, 50113, 51139, 51138, 51137, 51136, 51135, 51300, 51301, 51302, 51303, 51304}
local bloomBombIdols = {[28355] = 87, [33076] = 105, [33841] = 116, [35021] = 131, [42576] = 188, [42577] = 217, [42578] = 246, [42579] = 294, [42580] = 376, [51423] = 448}
local rejuIdols = {[186054] = 15, [22398] = 50, [25643] = 86, [38366] = 33}
local bloomIdols = {[40711] = 125, [27886] = 47}
local hotTotals, hasRegrowth = {}, {}
AuraHandler = function(unit, guid)
hotTotals[guid] = 0
if( unitHasAura(unit, Rejuvenation) ) then hotTotals[guid] = hotTotals[guid] + 1 end
if( unitHasAura(unit, Lifebloom) ) then hotTotals[guid] = hotTotals[guid] + 1 end
if( unitHasAura(unit, WildGrowth) ) then hotTotals[guid] = hotTotals[guid] + 1 end
if( unitHasAura(unit, Regrowth) ) then
hasRegrowth[guid] = true
hotTotals[guid] = hotTotals[guid] + 1
else
hasRegrowth[guid] = nil
end
end
GetHealTargets = function(bitType, guid, spellID)
-- Tranquility pulses on everyone within 30 yards, if they are in range of Mark of the Wild they'll get Tranquility
local spellName = GetSpellInfo(spellID)
if( spellName == Tranquility ) then
local targets = compressGUID[playerGUID]
local playerGroup = guidToGroup[playerGUID]
for groupGUID, id in pairs(guidToGroup) do
if( id == playerGroup and playerGUID ~= groupGUID and not UnitHasVehicleUI(guidToUnit[groupID]) and IsSpellInRange(MarkoftheWild, guidToUnit[groupGUID]) == 1 ) then
targets = targets .. "," .. compressGUID[groupGUID]
end
end
return targets
end
return compressGUID[guid]
end
-- Calculate hot heals
local wgTicks = {}
CalculateHotHealing = function(guid, spellID)
local spellName, spellRank = GetSpellInfo(spellID), SpellIDToRank[spellID]
local healAmount = getBaseHealAmount(hotData, spellName, spellID, spellRank)
local spellPower = GetSpellBonusHealing()
local healModifier, spModifier = playerHealModifier, 1
local bombAmount, totalTicks
-- Gift of Nature
if isTBC or isWrath then
healModifier = healModifier * (1 + talentData[GiftofNature].current)
else
-- Gift of Nature does only apply to base values in classic
healAmount = healAmount + talentData[GiftofNature].current
end
if( unitHasAura("player", TreeofLife) ) then
-- 32387 - Idol of the Raven Godess, +44 SP while in TOL
if( playerCurrentRelic == 32387 ) then
spellPower = spellPower + 44
end
end
-- Rejuvenation
if( spellName == Rejuvenation ) then
if isTBC or isWrath then
healModifier = healModifier + talentData[ImprovedRejuv].current
else
-- Improved Rejuvenation only applies to base values in classic
healAmount = healAmount * (1 + talentData[ImprovedRejuv].current)
end
if( playerCurrentRelic and rejuIdols[playerCurrentRelic] ) then
spellPower = spellPower + rejuIdols[playerCurrentRelic]
end