-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore.lua
More file actions
4529 lines (4004 loc) · 153 KB
/
Copy pathCore.lua
File metadata and controls
4529 lines (4004 loc) · 153 KB
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 addonName, ns = ...
local GLOW_EDGE_OFFSET = 0
local OVERLAY_TILE_SIZE = 32
local GLOW_TEXTURE_WIDTH = 16
local healPredictionCalculator
local function GetAddonMetadata(field)
if C_AddOns and C_AddOns.GetAddOnMetadata then
return C_AddOns.GetAddOnMetadata(addonName, field)
end
if GetAddOnMetadata then
return GetAddOnMetadata(addonName, field)
end
end
ns.defaults = {
enabled = true,
overlayOpacity = 40,
overlayColor = { r = 1.0, g = 1.0, b = 1.0 },
showGlow = true,
glowOpacity = 60,
glowColor = { r = 0.45, g = 0.92, b = 1.0 },
}
ShieldFramesDB = ShieldFramesDB or {}
local function GetDB()
return ShieldFramesDB
end
local function MergeDefaults(db, defaults)
for key, value in pairs(defaults) do
if type(value) == "table" then
db[key] = db[key] or {}
MergeDefaults(db[key], value)
elseif db[key] == nil then
db[key] = value
end
end
end
function ns.GetDB()
return GetDB()
end
function ns.MergeDefaults()
MergeDefaults(GetDB(), ns.defaults)
end
local function MigrateOpacitySetting(db, key)
local value = db[key]
if type(value) ~= "number" then
return
end
if value > 0 and value <= 1 then
db[key] = math.floor(value * 100 + 0.5)
end
end
function ns.MigrateSavedSettings()
local db = GetDB()
MergeDefaults(db, ns.defaults)
MigrateOpacitySetting(db, "overlayOpacity")
MigrateOpacitySetting(db, "glowOpacity")
end
local function NormalizeOpacityPercent(value, default)
if type(value) ~= "number" then
return default
end
if value > 0 and value <= 1 then
return math.floor(value * 100 + 0.5)
end
return value
end
local function NormalizeColor(color, fallback)
if type(color) ~= "table" then
return fallback
end
return {
r = color.r or fallback.r,
g = color.g or fallback.g,
b = color.b or fallback.b,
}
end
local function IsSecret(value)
return issecretvalue and issecretvalue(value)
end
-- Reject nil/secret and non-finite numbers (NaN/Inf). NaN fails every comparison
-- (`nan > 0` is false), so unguarded width math can skip clamps and stretch overlays.
local function IsFiniteNumber(value)
return type(value) == "number" and value == value and value < math.huge and value > -math.huge
end
local function SafeNumber(value)
if value == nil or IsSecret(value) then
return nil
end
if not IsFiniteNumber(value) then
return nil
end
return value
end
local function IsPositiveFinite(value)
local n = SafeNumber(value)
return n ~= nil and n > 0
end
-- Midnight can mark StatusBar:GetWidth() secret even when the bar is laid out.
-- Prefer GetWidth, then GetRect, then parent/frame fallbacks.
local function SafeRegionWidth(region)
if not region then
return nil
end
local width = SafeNumber(region.GetWidth and region:GetWidth())
if IsPositiveFinite(width) then
return width
end
if region.GetRect then
local ok, _, _, rectWidth = pcall(region.GetRect, region)
if ok then
rectWidth = SafeNumber(rectWidth)
if IsPositiveFinite(rectWidth) then
return rectWidth
end
end
end
if region.GetScaledRect then
local ok, _, _, rectWidth = pcall(region.GetScaledRect, region)
if ok then
rectWidth = SafeNumber(rectWidth)
if IsPositiveFinite(rectWidth) then
return rectWidth
end
end
end
return nil
end
-- Midnight: never `if secretBool` / `and secretBool` — compare explicitly.
local function SafeBool(value)
if value == nil or IsSecret(value) then
return false
end
return value == true
end
local function SafeUnitIsUnit(unitA, unitB)
if unitA == nil or unitB == nil then
return false
end
if unitA == unitB then
return true
end
if type(UnitIsUnit) ~= "function" then
return false
end
local ok, result = pcall(UnitIsUnit, unitA, unitB)
if not ok then
return false
end
return SafeBool(result)
end
local function CanAccessValue(value)
if value == nil then
return false
end
if not IsSecret(value) then
return true
end
return canaccessvalue and canaccessvalue(value)
end
local function HasMidnightRenderAbsorb(absorbAmount, secretAbsorb)
if absorbAmount ~= nil and (CanAccessValue(absorbAmount) or IsSecret(absorbAmount)) then
return true
end
return secretAbsorb ~= nil
end
local function PickMidnightRenderAbsorb(absorbAmount, secretAbsorb)
if absorbAmount ~= nil and (CanAccessValue(absorbAmount) or IsSecret(absorbAmount)) then
return absorbAmount
end
return secretAbsorb
end
local function SafeAuraField(aura, field)
if not aura or not field then
return nil
end
local ok, value = pcall(function()
return aura[field]
end)
if not ok then
return nil
end
return value
end
local function SafeAuraSpellId(aura)
local spellId = SafeAuraField(aura, "spellId")
if spellId == nil or not CanAccessValue(spellId) then
return nil
end
return spellId
end
local function IsFrameForbidden(frame)
return frame and type(frame.IsForbidden) == "function" and frame:IsForbidden()
end
local function GetOverlayParentFrame(frame, healthBar)
if healthBar and not IsFrameForbidden(healthBar) then
return healthBar
end
return frame
end
local function GetOverlayAnchorFrame(frame, healthBar)
return healthBar or frame
end
local function SafeCompare(fn)
local ok, result = pcall(fn)
if not ok then
return nil
end
return result
end
local function SafeGreaterThan(value, threshold)
if not CanAccessValue(value) then
return nil
end
return SafeCompare(function()
return value > threshold
end)
end
local function SafeLessOrEqual(value, threshold)
if not CanAccessValue(value) then
return nil
end
return SafeCompare(function()
return value <= threshold
end)
end
local function SafeSubtractClampNonNegative(a, b)
if not CanAccessValue(a) or not CanAccessValue(b) then
return nil
end
return SafeCompare(function()
local amount = a - b
if amount < 0 then
amount = 0
end
return amount
end)
end
local function UsesHealPredictionCalculator()
return CreateUnitHealPredictionCalculator ~= nil and UnitGetDetailedHealPrediction ~= nil
end
local function EnsureHealPredictionCalculator()
if healPredictionCalculator then
return healPredictionCalculator
end
if not CreateUnitHealPredictionCalculator then
return nil
end
healPredictionCalculator = CreateUnitHealPredictionCalculator()
if healPredictionCalculator.SetToDefaults then
healPredictionCalculator:SetToDefaults()
end
if healPredictionCalculator.SetDamageAbsorbClampMode and Enum and Enum.UnitDamageAbsorbClampMode then
healPredictionCalculator:SetDamageAbsorbClampMode(Enum.UnitDamageAbsorbClampMode.MissingHealthWithoutIncomingHeals)
end
return healPredictionCalculator
end
local function UpdateHealPredictionCalculator(unit)
local calculator = EnsureHealPredictionCalculator()
if not calculator or not UnitGetDetailedHealPrediction then
return nil
end
if calculator.Reset then
calculator:Reset()
end
local ok = pcall(UnitGetDetailedHealPrediction, unit, "player", calculator)
if not ok then
ok = pcall(UnitGetDetailedHealPrediction, unit, calculator)
end
if not ok then
return nil
end
return calculator
end
local function GetCalculatorAbsorbValues(unit)
local calculator = UpdateHealPredictionCalculator(unit)
if not calculator then
return
end
-- Total absorb drives the reverse-fill bar; in-bar clamp reveals overshield via subtraction.
local totalAbsorb
if calculator.GetTotalDamageAbsorbs then
totalAbsorb = calculator:GetTotalDamageAbsorbs()
end
if totalAbsorb == nil and calculator.GetDamageAbsorbs then
totalAbsorb = calculator:GetDamageAbsorbs()
end
local inBarAbsorb
if calculator.GetDamageAbsorbs then
inBarAbsorb = calculator:GetDamageAbsorbs()
end
local maxHealth = calculator.GetMaximumHealth and calculator:GetMaximumHealth()
local overshieldAmount = SafeSubtractClampNonNegative(totalAbsorb, inBarAbsorb)
return totalAbsorb, overshieldAmount, maxHealth, calculator
end
local function IsPositiveAmount(value)
return SafeGreaterThan(value, 0)
end
local function FrameShowsOvershieldGlow(frame)
local glow = frame.overAbsorbGlow
if not glow or (type(glow.IsForbidden) == "function" and glow:IsForbidden()) then
return false
end
-- Use IsShown only. We may SetAlpha(0) to hide Blizzard's glow under our stripe;
-- that must not count as "no overshield" or we clear → restore → flicker.
return glow:IsShown()
end
local function FrameHasBlizzOvershieldGlow(frame)
local ok, active = pcall(FrameShowsOvershieldGlow, frame)
return ok and active
end
local function FrameHasRawOvershieldGlow(frame)
local glow = frame and frame.overAbsorbGlow
if not glow or IsFrameForbidden(glow) then
return false
end
return glow:IsShown()
end
local function HasSecretAbsorbValue(totalAbsorb, overshieldAmount)
if totalAbsorb ~= nil and not CanAccessValue(totalAbsorb) then
return true
end
if overshieldAmount ~= nil and not CanAccessValue(overshieldAmount) then
return true
end
return false
end
local function SetFrameOvershieldActive(frame, active)
frame.ShieldFramesOvershieldActive = active or nil
end
local function HideBlizzOvershieldGlow(frame, glow)
if not glow or (type(glow.IsForbidden) == "function" and glow:IsForbidden()) then
return
end
if frame then
frame.ShieldFramesBlizzGlowFaded = true
end
glow:SetAlpha(0)
end
local function RestoreBlizzOvershieldGlow(frame, glow)
if not glow or (type(glow.IsForbidden) == "function" and glow:IsForbidden()) then
return
end
if frame then
frame.ShieldFramesBlizzGlowFaded = nil
end
glow:SetAlpha(1)
glow:Hide()
end
local function GetUnitHealthValues(frame, unit)
local healthBar = frame and (frame.healthbar or frame.healthBar)
local curHealth
local maxHealth
if unit then
local rawCur = UnitHealth(unit)
local rawMax = UnitHealthMax(unit)
curHealth = rawCur ~= nil and CanAccessValue(rawCur) and SafeNumber(rawCur) or nil
maxHealth = rawMax ~= nil and CanAccessValue(rawMax) and SafeNumber(rawMax) or nil
end
-- Party/raid UnitHealthMax is often secret in Midnight. Prefer the StatusBar extents
-- when those values are still readable so absorb estimates can size a hatch.
if (not curHealth or not maxHealth) and healthBar and not IsFrameForbidden(healthBar) then
local ok, barCur, barMax = pcall(function()
return healthBar:GetValue(), select(2, healthBar:GetMinMaxValues())
end)
if ok then
if not curHealth and barCur ~= nil and CanAccessValue(barCur) then
curHealth = SafeNumber(barCur)
end
if not maxHealth and barMax ~= nil and CanAccessValue(barMax) then
maxHealth = SafeNumber(barMax)
end
end
end
return curHealth, maxHealth, healthBar
end
local function UnitHasReadableOvershield(unit, frame)
local curHealth, maxHealth = GetUnitHealthValues(frame, unit)
if not curHealth or not maxHealth or maxHealth <= 0 then
return false
end
local rawAbsorb = UnitGetTotalAbsorbs(unit)
if rawAbsorb == nil or not CanAccessValue(rawAbsorb) then
return nil
end
local totalAbsorb = SafeNumber(rawAbsorb) or 0
if totalAbsorb <= 0 then
return false
end
local missingHealth = maxHealth - curHealth
if missingHealth < 0 then
missingHealth = 0
end
return totalAbsorb > missingHealth
end
local function UnitHasReadableAbsorb(unit)
if not unit then
return nil
end
local rawAbsorb = UnitGetTotalAbsorbs(unit)
if rawAbsorb == nil or not CanAccessValue(rawAbsorb) then
return nil
end
return (SafeNumber(rawAbsorb) or 0) > 0
end
-- Seed list only — runtime detection learns every absorb spell ID we see via
-- UnitGetTotalAbsorbs correlation and SPELL_ABSORBED, stored in ShieldFramesDB.
local SEED_ABSORB_SPELL_IDS = {
[235313] = true, -- Blazing Barrier
[235450] = true, -- Prismatic Barrier
[11426] = true, -- Ice Barrier
[77535] = true, -- Blood Shield (Blood DK)
[193320] = true, -- Umbilicus Eternus absorb (after Vampiric Blood)
[391527] = true, -- Umbilicus Eternus absorb (current)
[48707] = true, -- Anti-Magic Shell
[17] = true, -- Power Word: Shield
[1253593] = true, -- Void Shield
[47753] = true, -- Divine Aegis (crit-heal absorb; Radiance / direct heals)
[152118] = true, -- Clarity of Will
[271466] = true, -- Luminous Barrier
[184662] = true, -- Shield of Vengeance
[108945] = true, -- Angelic Bulwark
}
-- Kept for sizing hints only (not for presence detection).
local MAGE_BARRIER_SPELL_IDS = {
[235313] = true,
[235450] = true,
[11426] = true,
}
-- Compat alias used by older call sites / comments.
local ABSORB_AURA_SPELL_IDS = SEED_ABSORB_SPELL_IDS
-- When absorb aura points are secret (common on party frames), size from max health
-- so PW:S / barriers still show instead of vanishing.
local GENERIC_ABSORB_HEALTH_FRACTION = 0.22
local MAGE_BARRIER_HEALTH_FRACTION = 0.25
local MIN_ABSORB_POINT = 100
-- Pixel hatch when Midnight only exposes Blizzard's overAbsorbGlow tip (Blood Shield
-- aura/amount secret) and we have no prior width to reuse.
local DEFAULT_BOOTSTRAP_OVERLAY_WIDTH = 48
local function GetLearnedAbsorbSpellIds()
local db = GetDB()
if type(db.learnedAbsorbSpellIds) ~= "table" then
db.learnedAbsorbSpellIds = {}
end
return db.learnedAbsorbSpellIds
end
local function LearnAbsorbSpellId(spellId)
spellId = SafeNumber(spellId)
if not spellId or spellId <= 0 then
return false
end
spellId = math.floor(spellId + 0.5)
if SEED_ABSORB_SPELL_IDS[spellId] then
return false
end
local learned = GetLearnedAbsorbSpellIds()
if learned[spellId] then
return false
end
learned[spellId] = true
return true
end
local function IsTrackedAbsorbSpellId(spellId)
spellId = SafeNumber(spellId)
if not spellId then
return false
end
spellId = math.floor(spellId + 0.5)
if SEED_ABSORB_SPELL_IDS[spellId] then
return true
end
local learned = GetDB().learnedAbsorbSpellIds
return type(learned) == "table" and learned[spellId] == true
end
local function SafeGetAuraBySpellID(unit, spellId)
if not unit or not spellId or not C_UnitAuras then
return nil
end
if unit == "player" and C_UnitAuras.GetPlayerAuraBySpellID then
local ok, aura = pcall(C_UnitAuras.GetPlayerAuraBySpellID, spellId)
if ok and aura then
return aura
end
end
if C_UnitAuras.GetAuraDataBySpellID then
local ok, aura = pcall(C_UnitAuras.GetAuraDataBySpellID, unit, spellId)
if ok and aura then
return aura
end
end
return nil
end
local function ForEachHelpfulAura(unit, callback)
if not unit or not callback or not C_UnitAuras or not C_UnitAuras.GetAuraDataByIndex then
return
end
-- Never break on a nil slot: Midnight can omit secret auras mid-list.
-- Callback may return false to stop early (presence checks).
for index = 1, 40 do
local ok, aura = pcall(C_UnitAuras.GetAuraDataByIndex, unit, index, "HELPFUL")
if ok and aura then
if callback(aura, index) == false then
return
end
end
end
end
local function GetBestAbsorbPointFromAura(aura)
if not aura then
return nil
end
local points = SafeAuraField(aura, "points")
if not points then
return nil
end
-- Absorb auras expose multiple points (absorb + dummy coefficients). Use the largest
-- readable positive point; tiny values (e.g. 20-30 dummy) are not absorb amounts.
local best
local sawReadableZero = false
for index = 1, 32 do
local point = SafeAuraField(points, index)
if point == nil then
break
end
if CanAccessValue(point) then
local amount = SafeNumber(point)
if amount and amount > 0 then
if not best or amount > best then
best = amount
end
elseif amount == 0 then
sawReadableZero = true
end
end
end
if best and best >= MIN_ABSORB_POINT then
return best
end
if sawReadableZero and not best then
return 0
end
return nil
end
-- When UnitGetTotalAbsorbs is readable, any helpful aura whose points look like an
-- absorb amount is learned automatically (covers every class/spec without a hand list).
local function TryLearnAbsorbSpellsFromUnit(unit)
if not unit then
return
end
local totalAbsorb
if UnitGetTotalAbsorbs and CanAccessValue then
local ok, value = pcall(UnitGetTotalAbsorbs, unit)
if ok then
totalAbsorb = SafeNumber(value)
end
end
if not IsPositiveFinite(totalAbsorb) or totalAbsorb < MIN_ABSORB_POINT then
return
end
ForEachHelpfulAura(unit, function(aura)
local spellId = SafeAuraSpellId(aura)
if not spellId or IsTrackedAbsorbSpellId(spellId) then
return
end
local point = GetBestAbsorbPointFromAura(aura)
if point and point >= MIN_ABSORB_POINT and point <= totalAbsorb * 1.05 then
LearnAbsorbSpellId(spellId)
end
end)
end
local function EstimateMageBarrierAbsorb(maxHealth)
local maxH = SafeNumber(maxHealth)
if not maxH or maxH <= 0 then
return nil
end
return maxH * MAGE_BARRIER_HEALTH_FRACTION
end
local function EstimateGenericAbsorb(maxHealth)
local maxH = SafeNumber(maxHealth)
if not maxH or maxH <= 0 then
return nil
end
return maxH * GENERIC_ABSORB_HEALTH_FRACTION
end
local function EstimateAbsorbForSpellId(spellId, maxHealth)
if MAGE_BARRIER_SPELL_IDS[spellId] then
return EstimateMageBarrierAbsorb(maxHealth)
end
if IsTrackedAbsorbSpellId(spellId) then
return EstimateGenericAbsorb(maxHealth)
end
return nil
end
local function SanitizeKnownAbsorbAmount(spellId, fromAura, maxHealth)
if fromAura == 0 then
return 0
end
if spellId and MAGE_BARRIER_SPELL_IDS[spellId] then
local estimate = EstimateMageBarrierAbsorb(maxHealth)
if estimate then
if fromAura and fromAura >= estimate * 0.05 then
return fromAura
end
return estimate
end
end
if fromAura and fromAura > 0 then
return fromAura
end
-- Secret / missing points on absorbs (common on party frames).
return EstimateAbsorbForSpellId(spellId, maxHealth)
end
local function GetAbsorbAmountFromAura(aura, maxHealth)
if not aura then
return nil
end
local spellId = SafeAuraSpellId(aura)
if not spellId or not IsTrackedAbsorbSpellId(spellId) then
return nil
end
local fromPoints = GetBestAbsorbPointFromAura(aura)
local sanitized = SanitizeKnownAbsorbAmount(spellId, fromPoints, maxHealth)
if sanitized ~= nil then
return sanitized
end
return EstimateAbsorbForSpellId(spellId, maxHealth)
end
local function GetAbsorbAmountForSpellId(unit, spellId, maxHealth)
local aura = SafeGetAuraBySpellID(unit, spellId)
if not aura then
return nil
end
return GetAbsorbAmountFromAura(aura, maxHealth)
end
-- Small proc absorbs (Divine Aegis) should not use the full generic fraction estimate
-- or they inflate the hatch and fight Blizzard's true width.
local SMALL_PROC_ABSORB_SPELL_IDS = {
[47753] = true, -- Divine Aegis
}
local ABSORB_SNAPSHOT_TTL = 0.2
local absorbSnapshots = {}
local function InvalidateAbsorbSnapshot(unit)
if unit then
absorbSnapshots[unit] = nil
end
end
local function ForEachTrackedAbsorbAura(unit, callback)
if not unit or not callback then
return
end
local seen = {}
local foundViaSpellId = false
local function consider(spellId, aura)
spellId = SafeNumber(spellId)
if not spellId or seen[spellId] then
return
end
if not aura then
aura = SafeGetAuraBySpellID(unit, spellId)
end
if not aura then
return
end
seen[spellId] = true
foundViaSpellId = true
callback(aura, spellId)
end
for spellId in pairs(SEED_ABSORB_SPELL_IDS) do
consider(spellId, nil)
end
local learned = GetDB().learnedAbsorbSpellIds
if type(learned) == "table" then
for spellId in pairs(learned) do
consider(spellId, nil)
end
end
-- Index scan is a fallback when spell-ID lookups miss; skip if we already found absorbs.
if not foundViaSpellId then
ForEachHelpfulAura(unit, function(aura)
local spellId = SafeAuraSpellId(aura)
if spellId and IsTrackedAbsorbSpellId(spellId) then
consider(spellId, aura)
end
end)
end
end
local function BuildAbsorbSnapshot(unit, maxHealth)
local snap = {
t = GetTime(),
maxHealth = SafeNumber(maxHealth),
hasKnown = false,
total = nil,
fraction = nil,
depleted = false,
count = 0,
}
local total = 0
local sawAura = false
local sawPositive = false
local sawZeroOnly = true
local fraction = 0
ForEachTrackedAbsorbAura(unit, function(aura, spellId)
sawAura = true
snap.count = snap.count + 1
snap.hasKnown = true
local amount = GetAbsorbAmountFromAura(aura, maxHealth)
if amount == nil and spellId then
amount = EstimateAbsorbForSpellId(spellId, maxHealth)
end
if amount and amount > 0 then
total = total + amount
sawPositive = true
sawZeroOnly = false
elseif amount == 0 then
-- depleted instance of this aura
else
sawZeroOnly = false
end
if SMALL_PROC_ABSORB_SPELL_IDS[spellId] then
fraction = fraction + 0.08
elseif MAGE_BARRIER_SPELL_IDS[spellId] then
fraction = fraction + MAGE_BARRIER_HEALTH_FRACTION
else
fraction = fraction + GENERIC_ABSORB_HEALTH_FRACTION
end
end)
if not sawAura then
snap.total = nil
snap.fraction = nil
snap.depleted = false
else
if sawPositive then
snap.total = total
snap.depleted = false
elseif sawZeroOnly then
snap.total = 0
snap.depleted = true
else
snap.total = nil
snap.depleted = false
end
if fraction > 0 then
if fraction > 0.85 then
snap.fraction = 0.85
else
snap.fraction = fraction
end
end
end
absorbSnapshots[unit] = snap
return snap
end
local function GetAbsorbSnapshot(unit, maxHealth)
if not unit then
return nil
end
maxHealth = SafeNumber(maxHealth)
local now = GetTime()
local snap = absorbSnapshots[unit]
if snap and (now - snap.t) <= ABSORB_SNAPSHOT_TTL then
if maxHealth == nil or snap.maxHealth == nil or snap.maxHealth == maxHealth then
return snap
end
end
return BuildAbsorbSnapshot(unit, maxHealth)
end
local function GetKnownAbsorbAuraData(unit)
if not unit or not C_UnitAuras then
return nil
end
-- Do NOT learn here — this runs from Blizzard FillBar/heal-prediction hooks.
-- Direct spell lookups first: party aura index scans often miss secret absorbs.
for spellId in pairs(SEED_ABSORB_SPELL_IDS) do
local aura = SafeGetAuraBySpellID(unit, spellId)
if aura then
return aura, spellId
end
end
local learned = GetDB().learnedAbsorbSpellIds
if type(learned) == "table" then
for spellId in pairs(learned) do
local aura = SafeGetAuraBySpellID(unit, spellId)
if aura then
return aura, spellId
end
end
end
local foundAura, foundSpellId
ForEachHelpfulAura(unit, function(aura)
local spellId = SafeAuraSpellId(aura)
if spellId and IsTrackedAbsorbSpellId(spellId) then
foundAura = aura
foundSpellId = spellId
return false
end
end)
if foundAura then
return foundAura, foundSpellId
end
return nil
end
local function UnitHasKnownAbsorbAura(unit)
local snap = GetAbsorbSnapshot(unit, nil)
return snap ~= nil and snap.hasKnown == true
end
local function UnitHasDamageBarrierAura(unit)
return UnitHasKnownAbsorbAura(unit)
end
-- When absolute absorb/max are secret, size the hatch as a fraction of bar width.
local function EstimateKnownAbsorbBarFraction(unit)
local snap = GetAbsorbSnapshot(unit, nil)
if not snap then
return nil
end
return snap.fraction
end
-- Sum every tracked absorb aura currently on the unit (seed + learned).
local function GetTotalKnownAbsorbAmount(unit, maxHealth)
local snap = GetAbsorbSnapshot(unit, maxHealth)
if not snap then
return nil
end
return snap.total
end
local function GetAbsorbFromKnownAura(unit)
return GetTotalKnownAbsorbAmount(unit, nil)
end
local function KnownAbsorbAuraIsDepleted(unit)
local snap = GetAbsorbSnapshot(unit, nil)
return snap ~= nil and snap.depleted == true
end
local function UnitHasKnownAbsorbCandidate(unit)
local snap = GetAbsorbSnapshot(unit, nil)
if not snap or not snap.hasKnown then
return false
end
return not snap.depleted
end
local function CountLearnedAbsorbSpellIds()
local learned = GetDB().learnedAbsorbSpellIds
if type(learned) ~= "table" then
return 0
end
local count = 0
for _ in pairs(learned) do
count = count + 1
end
return count
end
local function IsPlayerUnitToken(unit)
if not unit then
return false
end
return unit == "player" or SafeUnitIsUnit(unit, "player")
end
local function IsCompactUnitFrame(frame)
if type(frame) ~= "table" then
return false
end
if frame.optionTable ~= nil or frame.displayedUnit ~= nil then
return true
end
local name = frame.GetName and frame:GetName()
return type(name) == "string" and name:find("Compact", 1, true) ~= nil
end
local function RefreshKnownAbsorbAuraState(frame, unit)
if not frame or not unit then
return
end
if KnownAbsorbAuraIsDepleted(unit) then
frame.ShieldFramesKnownAbsorbAuraPresent = false
return
end
if UnitHasKnownAbsorbAura(unit) then