Skip to content

Commit cd1d28e

Browse files
LocalIdentityLocalIdentity
andauthored
Fix negative eHP and NaN Max hit values for some builds (#9772)
Some builds could show up having negative eHP values or nan max hit when they have single digit life values numHits could become negative which would make eHP show up as negative too Enemy damage conversion could also result in max hit becoming 0 in one part of the code and that would then display as NaN after it tries to divide by 0 Co-authored-by: LocalIdentity <localidentity2@gmail.com>
1 parent 27bdb39 commit cd1d28e

1 file changed

Lines changed: 22 additions & 7 deletions

File tree

src/Modules/CalcDefence.lua

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2701,7 +2701,10 @@ function calcs.buildDefenceEstimations(env, actor)
27012701
if poolTable.Life >= 0 and damageTotal >= maxDamage then -- If still living and the amount of damage exceeds maximum threshold we survived infinite number of hits.
27022702
return m_huge
27032703
end
2704-
return numHits
2704+
if numHits ~= numHits then
2705+
return 0
2706+
end
2707+
return m_max(numHits, 0)
27052708
end
27062709

27072710
if damageCategoryConfig ~= "DamageOverTime" then
@@ -3161,9 +3164,12 @@ function calcs.buildDefenceEstimations(env, actor)
31613164
local damageConvertedMulti = convertPercent / 100
31623165
local totalHitPool = output[damageConvertedType.."TotalHitPool"]
31633166
local totalTakenMulti = output[damageConvertedType.."AfterReductionTakenHitMulti"] * (1 - output["VaalArcticArmourMitigation"])
3164-
3165-
if effectiveAppliedArmour == 0 and convertPercent == 100 then -- use a simpler calculation for no armour DR
3166-
local drMulti = output[damageConvertedType.."ResistTakenHitMulti"] * (1 - output[damageConvertedType.."DamageReduction"] / 100)
3167+
if damageConvertedMulti <= 0 then
3168+
local takenWithoutIncoming = m_max(takenFlat, 0) * totalTakenMulti
3169+
hitTaken = takenWithoutIncoming >= totalHitPool and 0 or m_huge
3170+
elseif effectiveAppliedArmour == 0 and convertPercent == 100 then -- use a simpler calculation for no armour DR
3171+
local totalResistMult = output[damageConvertedType.."ResistTakenHitMulti"]
3172+
local drMulti = totalResistMult * (1 - output[damageConvertedType.."DamageReduction"] / 100)
31673173
hitTaken = m_max(totalHitPool / damageConvertedMulti / drMulti - takenFlat, 0) / totalTakenMulti
31683174
else
31693175
-- get relevant raw reductions and reduction modifiers
@@ -3194,7 +3200,7 @@ function calcs.buildDefenceEstimations(env, actor)
31943200
local b = ((enemyOverwhelmPercent / 100 - flatDR) * effectiveAppliedArmour * totalTakenMulti - 5 * (totalHitPool - takenFlat * totalTakenMulti)) * resistXConvert
31953201
local c = -effectiveAppliedArmour * (totalHitPool - takenFlat * totalTakenMulti)
31963202

3197-
local RAW = (m_sqrt(b * b - 4 * a * c) - b) / (2 * a)
3203+
local RAW = a ~= 0 and (m_sqrt(m_max(b * b - 4 * a * c, 0)) - b) / (2 * a) or m_huge
31983204

31993205
-- tack on some caps
32003206
local noDRMaxHit = totalHitPool / damageConvertedMulti / totalResistMult / totalTakenMulti * (1 - takenFlat * totalTakenMulti / totalHitPool)
@@ -3220,9 +3226,18 @@ function calcs.buildDefenceEstimations(env, actor)
32203226
local passOverkill = passPools.OverkillDamage - passPools.hitPoolRemaining
32213227
local passRatio = 0
32223228
for partType, _ in pairs(passDamages) do
3223-
passRatio = m_max(passRatio, (passOverkill + output[partType.."TotalHitPool"]) / output[partType.."TotalHitPool"])
3229+
local partPool = output[partType.."TotalHitPool"] or 0
3230+
if partPool > 0 then
3231+
passRatio = m_max(passRatio, (passOverkill + partPool) / partPool)
3232+
end
3233+
end
3234+
if passRatio <= 0 then
3235+
passRatio = 1
3236+
end
3237+
local stepSize = 1
3238+
if n > 1 and previousOverkill and previousOverkill ~= 0 and previousOverkill == previousOverkill then
3239+
stepSize = m_min(m_abs((passOverkill - previousOverkill) / previousOverkill), 2)
32243240
end
3225-
local stepSize = n > 1 and m_min(m_abs((passOverkill - previousOverkill) / previousOverkill), 2) or 1
32263241
local stepAdjust = stepSize > 1 and -passOverkill / stepSize or n > 1 and -passOverkill * stepSize or 0
32273242
previousOverkill = passOverkill
32283243
passIncomingDamage = (passIncomingDamage + stepAdjust) / m_sqrt(passRatio)

0 commit comments

Comments
 (0)