Skip to content

Commit 9906ace

Browse files
github-actions[bot]LocalIdentityLocalIdentity
authored
[pob1-port] Fix negative eHP and NaN Max hit values for some builds (#1799)
* Apply changes from PathOfBuildingCommunity/PathOfBuilding#9772 * Fix merge conflict --------- Co-authored-by: LocalIdentity <LocalIdentity@users.noreply.github.com> Co-authored-by: LocalIdentity <localidentity2@gmail.com>
1 parent 69b69e2 commit 9906ace

1 file changed

Lines changed: 23 additions & 7 deletions

File tree

src/Modules/CalcDefence.lua

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ local ipairs = ipairs
1010
local t_insert = table.insert
1111
local m_min = math.min
1212
local m_max = math.max
13+
local m_abs = math.abs
1314
local m_floor = math.floor
1415
local m_ceil = math.ceil
1516
local m_sqrt = math.sqrt
@@ -3112,7 +3113,10 @@ function calcs.buildDefenceEstimations(env, actor)
31123113
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.
31133114
return m_huge
31143115
end
3115-
return numHits
3116+
if numHits ~= numHits then
3117+
return 0
3118+
end
3119+
return m_max(numHits, 0)
31163120
end
31173121

31183122
if damageCategoryConfig ~= "DamageOverTime" then
@@ -3578,9 +3582,12 @@ function calcs.buildDefenceEstimations(env, actor)
35783582
local damageConvertedMulti = convertPercent / 100
35793583
local totalHitPool = output[damageConvertedType.."TotalHitPool"]
35803584
local totalTakenMulti = output[damageConvertedType.."AfterReductionTakenHitMulti"] * (1 - output["VaalArcticArmourMitigation"])
3581-
3582-
if effectiveAppliedArmour == 0 and convertPercent == 100 then -- use a simpler calculation for no armour DR
3583-
local drMulti = output[damageConvertedType.."ResistTakenHitMulti"] * (1 - output[damageConvertedType.."DamageReduction"] / 100)
3585+
if damageConvertedMulti <= 0 then
3586+
local takenWithoutIncoming = m_max(takenFlat, 0) * totalTakenMulti
3587+
hitTaken = takenWithoutIncoming >= totalHitPool and 0 or m_huge
3588+
elseif effectiveAppliedArmour == 0 and convertPercent == 100 then -- use a simpler calculation for no armour DR
3589+
local totalResistMult = output[damageConvertedType.."ResistTakenHitMulti"]
3590+
local drMulti = totalResistMult * (1 - output[damageConvertedType.."DamageReduction"] / 100)
35843591
hitTaken = m_max(totalHitPool / damageConvertedMulti / drMulti - takenFlat, 0) / totalTakenMulti
35853592
else
35863593
-- get relevant raw reductions and reduction modifiers
@@ -3614,7 +3621,7 @@ function calcs.buildDefenceEstimations(env, actor)
36143621
local b = (effectiveAppliedArmour * oneMinusFlatPlusOverwhelm - effectiveAppliedArmour - HP_tTM_tF_DCM_tRM * data.misc.ArmourRatio * damageConvertedMulti)
36153622
local c = -HP_tTM_tF_DCM_tRM * effectiveAppliedArmour
36163623

3617-
local RAW = (m_sqrt(b * b - 4 * a * c) - b) / (2 * a)
3624+
local RAW = a ~= 0 and (m_sqrt(m_max(b * b - 4 * a * c, 0)) - b) / (2 * a) or m_huge
36183625

36193626
-- tack on some caps
36203627
local noDRMaxHit = totalHitPool / damageConvertedMulti / totalResistMult / totalTakenMulti * (1 - takenFlat * totalTakenMulti / totalHitPool)
@@ -3640,9 +3647,18 @@ function calcs.buildDefenceEstimations(env, actor)
36403647
local passOverkill = passPools.OverkillDamage - passPools.hitPoolRemaining
36413648
local passRatio = 0
36423649
for partType, _ in pairs(passDamages) do
3643-
passRatio = m_max(passRatio, (passOverkill + output[partType.."TotalHitPool"]) / output[partType.."TotalHitPool"])
3650+
local partPool = output[partType.."TotalHitPool"] or 0
3651+
if partPool > 0 then
3652+
passRatio = m_max(passRatio, (passOverkill + partPool) / partPool)
3653+
end
3654+
end
3655+
if passRatio <= 0 then
3656+
passRatio = 1
3657+
end
3658+
local stepSize = 1
3659+
if n > 1 and previousOverkill and previousOverkill ~= 0 and previousOverkill == previousOverkill then
3660+
stepSize = m_min(m_abs((passOverkill - previousOverkill) / previousOverkill), 2)
36443661
end
3645-
local stepSize = n > 1 and m_min(math.abs((passOverkill - previousOverkill) / previousOverkill), 2) or 1
36463662
local stepAdjust = stepSize > 1 and -passOverkill / stepSize or n > 1 and -passOverkill * stepSize or 0
36473663
previousOverkill = passOverkill
36483664
passIncomingDamage = (passIncomingDamage + stepAdjust) / m_sqrt(passRatio)

0 commit comments

Comments
 (0)