forked from fenneh/DeathStrikePredictor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeathStrikePredictor.lua
More file actions
424 lines (367 loc) · 14.2 KB
/
DeathStrikePredictor.lua
File metadata and controls
424 lines (367 loc) · 14.2 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
local addonName, DSP = ...
-- Check if player is a Death Knight
local _, class = UnitClass("player")
if class ~= "DEATHKNIGHT" then return end
-- Initialize variables
DSP.damagePool = 0
DSP.baseHealing = 0.25
DSP.minHealing = 0.07
DSP.mod = 1
DSP.versMod = 1
DSP.inCombat = false
DSP.updateThrottle = 0.1
DSP.timeSinceLastUpdate = 0
DSP.healAbsorbEnabled = true
DSP.trackHealing = false
DSP.debugMode = false -- Add debug mode flag
local damageQueue = {}
local DEATH_STRIKE_SPELL_ID = 49998
local DAMAGE_BATCH_INTERVAL = 0.1 -- Process damage every 0.1 seconds
local damageUpdateTimer = 0
-----------------------------------------------------------------------------
-- Helper: Detect (or pretend to detect) Rune of Sanguination
-----------------------------------------------------------------------------
function DSP.HasRuneOfSanguination()
-- TODO: Replace this with real detection code or a user toggle.
-- For now, we'll just return true to *always* apply the bonus.
return true
end
-----------------------------------------------------------------------------
-- Forward declare all functions that are used by other functions
-----------------------------------------------------------------------------
local UpdatePrediction
local FindPlayerHealthBar
local CreatePredictionOverlay
local ProcessDamageQueue
local CleanupFrames
local GetPredictedHealing
-----------------------------------------------------------------------------
-- 1. Get current predicted healing
-----------------------------------------------------------------------------
GetPredictedHealing = function()
local maxHealth = UnitHealthMax("player")
-- 1) Check Coagulating Blood aura (463730). If active, use that stored damage
local cbAura = C_UnitAuras.GetPlayerAuraBySpellID(463730)
local damagePoolToUse = DSP.damagePool
if cbAura and cbAura.points and cbAura.points[1] then
damagePoolToUse = cbAura.points[1]
end
-- 2) Calculate both potential healing sources
local damagePortion = damagePoolToUse * DSP.baseHealing -- 25% of "effective" damage
local healthPortion = maxHealth * DSP.minHealing -- 7% of max health
-- 3) Take the maximum of damage portion and health portion
local healing = math.max(damagePortion, healthPortion)
-- 4) Voracious (15%)
if IsPlayerSpell(273953) then
healing = healing * 1.15
end
-- 5) Hemostasis (8% per stack, up to 5 stacks)
do
local name, _, hemoCount = AuraUtil.FindAuraByName("Hemostasis", "player")
if hemoCount and hemoCount > 0 then
-- +8% per stack => multiplier = 1 + (stacks * 0.08)
healing = healing * (1 + (hemoCount * 0.08))
end
end
-- 6) Vampiric Blood (30% + 5% per Improved VB stack)
local vbAura = C_UnitAuras.GetPlayerAuraBySpellID(55233)
if vbAura then
local _, _, vbCount = AuraUtil.FindAuraByName("Improved Vampiric Blood", "player")
local stacks = vbCount or 0
healing = healing * (1.3 + stacks * 0.05)
end
-- 7) Improved Death Strike (5% for Blood)
if GetSpecialization() == 1 and IsPlayerSpell(374277) then
healing = healing * 1.05
end
-- 8) Sanguine Ground (5%)
if C_UnitAuras.GetPlayerAuraBySpellID(391459) then
healing = healing * 1.05
end
-- 9) **Rune of Sanguination** (+up to 48% based on missing HP)
if DSP.HasRuneOfSanguination() then
local curHP = UnitHealth("player")
local missingHPpct = 1 - (curHP / maxHealth)
-- clamp so it doesn't exceed 1.0 if the game does something odd:
if missingHPpct < 0 then missingHPpct = 0 end
if missingHPpct > 1 then missingHPpct = 1 end
-- up to +48% if completely missing HP
local rosBonusMax = 0.48 -- 48%
local rosMultiplier = 1 + (rosBonusMax * missingHPpct)
healing = healing * rosMultiplier
end
-- 10) Apply versatility
healing = healing * DSP.versMod
-- 11) Dark Succor bonus if active (+10% max HP as a flat addition)
if AuraUtil.FindAuraByName("Dark Succor", "player") then
healing = healing + (maxHealth * 0.1)
end
return healing
end
-----------------------------------------------------------------------------
-- 2. Find the player's health bar
-----------------------------------------------------------------------------
FindPlayerHealthBar = function()
-- Try to find SUF health bar by exact name from frame stack
local healthBar = _G["SUFUnitplayer.healthBar"]
if healthBar then
return healthBar
end
-- Try alternative SUF frame paths
local sufPlayer = _G["SUFUnitplayer"]
if sufPlayer then
healthBar = sufPlayer.healthBar or sufPlayer:GetChildren()
if healthBar then
return healthBar
end
end
-- Fallback to default PlayerFrame
return PlayerFrame.healthbar
end
-----------------------------------------------------------------------------
-- Helper functions
-----------------------------------------------------------------------------
local function UpdateColors()
if DSP.overlay and DSP.db and DSP.db.profile then
local oc = DSP.db.profile.overlayColor
DSP.overlay:SetColorTexture(oc.r, oc.g, oc.b, oc.a)
end
if DSP.line and DSP.db and DSP.db.profile then
local lc = DSP.db.profile.lineColor
DSP.line:SetColorTexture(lc.r, lc.g, lc.b, lc.a)
end
end
-----------------------------------------------------------------------------
-- 3. Create the prediction overlay
-----------------------------------------------------------------------------
CreatePredictionOverlay = function(healthBar)
-- Clean up any existing frames first
CleanupFrames()
local container = CreateFrame("Frame", "DSPContainer", healthBar)
container:SetFrameStrata("BACKGROUND")
container:SetAllPoints(healthBar)
container:SetFrameLevel(healthBar:GetFrameLevel() + 2)
local overlay = container:CreateTexture("DSPOverlay", "ARTWORK", nil, 1)
overlay:SetBlendMode("ADD")
overlay:SetHeight(healthBar:GetHeight())
local line = container:CreateTexture("DSPLine", "ARTWORK", nil, 2)
line:SetHeight(healthBar:GetHeight())
line:SetWidth(1)
line:SetBlendMode("ADD")
-- Store the container reference
DSP.container = container
DSP.overlay = overlay
DSP.line = line
-- Set initial colors
UpdateColors()
-- Hide everything initially
container:Hide()
overlay:Hide()
line:Hide()
return overlay, line
end
-----------------------------------------------------------------------------
-- 4. Update the prediction display
-----------------------------------------------------------------------------
UpdatePrediction = function()
if not DSP.healthBar then
DSP.healthBar = FindPlayerHealthBar()
if not DSP.healthBar then
return
end
end
if not DSP.overlay or not DSP.line then
if DSP.healthBar then
DSP.overlay, DSP.line = CreatePredictionOverlay(DSP.healthBar)
end
if not DSP.overlay or not DSP.line then
return
end
end
-- Hide predictions if not in combat
if not DSP.inCombat then
if DSP.container then
DSP.container:Hide()
end
if DSP.overlay then
DSP.overlay:Hide()
end
if DSP.line then
DSP.line:Hide()
end
return
end
-- Show container if we're in combat
if DSP.container then
DSP.container:Show()
end
local maxHealth = UnitHealthMax("player")
local healing = GetPredictedHealing()
-- Sanity check and cap the healing prediction
local maxAllowedHealing = maxHealth * 1.5 -- Cap at 150% of max health
if healing > maxAllowedHealing then
if DSP.debugMode then
print(string.format("WARNING: Excessive healing prediction: %.0f (%.0f%% of max health)", healing, (healing / maxHealth) * 100))
print(string.format("Capping at: %.0f (150%% of max health)", maxAllowedHealing))
end
healing = maxAllowedHealing
end
-- Hide prediction if no valid healing amount
if not healing or healing <= 0 then
DSP.overlay:Hide()
DSP.line:Hide()
return
end
local healthBar = DSP.healthBar
local width = healthBar:GetWidth()
local health = UnitHealth("player")
-- Handle heal absorbs
if DSP.healAbsorbEnabled then
health = math.max(0, health - UnitGetTotalHealAbsorbs("player"))
end
local startPos = (health / maxHealth) * width
local endPos = ((health + healing) / maxHealth) * width
-- Cap the endPos to the width of the health bar
endPos = math.min(endPos, width)
-- Update overlay position
DSP.overlay:ClearAllPoints()
DSP.overlay:SetPoint("TOPLEFT", healthBar, "TOPLEFT", startPos, 0)
DSP.overlay:SetWidth(math.max(1, endPos - startPos))
DSP.overlay:Show()
-- Update line position
DSP.line:ClearAllPoints()
DSP.line:SetPoint("TOPLEFT", healthBar, "TOPLEFT", endPos - 1, 0)
DSP.line:Show()
end
-----------------------------------------------------------------------------
-- 5. Cleanup frames
-----------------------------------------------------------------------------
CleanupFrames = function()
local oldContainer = _G["DSPContainer"]
if oldContainer then
oldContainer:Hide()
oldContainer:SetParent(nil)
end
local oldOverlay = _G["DSPOverlay"]
if oldOverlay then
oldOverlay:Hide()
oldOverlay:SetParent(nil)
end
local oldLine = _G["DSPLine"]
if oldLine then
oldLine:Hide()
oldLine:SetParent(nil)
end
if DSP.container then
DSP.container:Hide()
DSP.container = nil
end
DSP.overlay = nil
DSP.line = nil
DSP.healthBar = nil
end
-----------------------------------------------------------------------------
-- 6. Process damage queue (rolling 5-sec damage)
-----------------------------------------------------------------------------
ProcessDamageQueue = function()
local totalDamage = 0
for _, damage in ipairs(damageQueue) do
totalDamage = totalDamage + damage
end
if totalDamage > 0 then
DSP.damagePool = DSP.damagePool + totalDamage
UpdatePrediction()
end
wipe(damageQueue)
end
-----------------------------------------------------------------------------
-- 7. Talents for debug printing
-----------------------------------------------------------------------------
DSP.talentMods = {
[273953] = 0.15, -- Voracious (+15%)
[374277] = function()
return GetSpecialization() == 1 and 0.05 or 0.6
end, -- Improved Death Strike (+5% Blood, +60% Frost/Unholy)
[454835] = 0.15, -- Osmosis: Anti-Magic Shell => +15% healing
[273946] = function() -- Hemostasis (debug display)
local name, _, count = AuraUtil.FindAuraByName("Hemostasis", "player")
return count and (count * 0.08) or 0
end
}
-----------------------------------------------------------------------------
-- 8. Auras for debug printing
-----------------------------------------------------------------------------
DSP.auraMods = {
[391459] = 0.05, -- Sanguine Ground (+5%)
[64844] = 0.04, -- Divine Hymn (+4%)
[47788] = 0.60, -- Guardian Spirit (+60%)
[72221] = 0.05, -- Luck of the Draw (+5%)
[139068] = 0.05, -- Determination (+5%)
}
-----------------------------------------------------------------------------
-- 9. Main frame and event handling
-----------------------------------------------------------------------------
local frame = CreateFrame("Frame")
frame:RegisterEvent("PLAYER_REGEN_ENABLED")
frame:RegisterEvent("PLAYER_REGEN_DISABLED")
frame:RegisterEvent("PLAYER_LOGIN")
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
frame:RegisterEvent("UNIT_MAXHEALTH")
frame:RegisterEvent("UNIT_HEALTH")
frame:RegisterEvent("UNIT_HEAL_ABSORB_AMOUNT_CHANGED")
frame:SetScript("OnEvent", function(self, event, ...)
if event == "PLAYER_LOGIN" then
DSP.healthBar = FindPlayerHealthBar()
if DSP.healthBar then
DSP.overlay, DSP.line = CreatePredictionOverlay(DSP.healthBar)
end
elseif event == "PLAYER_ENTERING_WORLD" then
DSP.healthBar = FindPlayerHealthBar()
if DSP.healthBar then
DSP.overlay, DSP.line = CreatePredictionOverlay(DSP.healthBar)
end
elseif event == "PLAYER_REGEN_ENABLED" then
DSP.inCombat = false
UpdatePrediction()
elseif event == "PLAYER_REGEN_DISABLED" then
DSP.inCombat = true
DSP.damagePool = 0
wipe(damageQueue)
UpdatePrediction()
elseif event == "COMBAT_LOG_EVENT_UNFILTERED" then
local timestamp, subevent, _, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags, spellId, spellName, _, amount = CombatLogGetCurrentEventInfo()
if destGUID == UnitGUID("player") and subevent == "SWING_DAMAGE" then
amount = spellId -- In swing events, the damage is in the spellId parameter
table.insert(damageQueue, amount)
elseif destGUID == UnitGUID("player") and (subevent == "SPELL_DAMAGE" or subevent == "RANGE_DAMAGE") then
table.insert(damageQueue, amount)
end
elseif event == "UNIT_MAXHEALTH" or event == "UNIT_HEALTH" or event == "UNIT_HEAL_ABSORB_AMOUNT_CHANGED" then
local unit = ...
if unit == "player" then
UpdatePrediction()
end
end
end)
-- Update the damage pool every DAMAGE_BATCH_INTERVAL seconds
frame:SetScript("OnUpdate", function(self, elapsed)
DSP.timeSinceLastUpdate = (DSP.timeSinceLastUpdate or 0) + elapsed
if DSP.timeSinceLastUpdate >= DAMAGE_BATCH_INTERVAL then
ProcessDamageQueue()
DSP.timeSinceLastUpdate = 0
end
end)
-- Register slash command
SLASH_DSP1 = "/dsp"
SlashCmdList["DSP"] = function(msg)
if msg == "debug" then
DSP.debugMode = not DSP.debugMode
print("Death Strike Predictor debug mode:", DSP.debugMode and "ON" or "OFF")
end
end
-- Initialize core variables
DSP.damagePool = 0
DSP.inCombat = false
DSP.timeSinceLastUpdate = 0
DSP.healAbsorbEnabled = true