Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 142 additions & 0 deletions spec/System/TestAilments_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,148 @@ describe("TestAilments", function()
assert.are.near(1.3, build.calcsTab.mainOutput.ShockEffectMod, 10 ^ -9)
end)

local function setupArcInversion()
build.skillsTab:PasteSocketGroup("Arc 20/0 1\n")
build.characterLevel = 90
build.characterLevelAutoMode = false
build.configTab.input.enemyIsBoss = "Pinnacle"
end

local function calcsShock(mode, chance, element, extraMods)
build.configTab.input.ailmentMode = mode
local mods = "Adds 50000 to 50000 Lightning Damage to Spells\n100% chance to Shock"
if chance > 0 then
mods = mods .. string.format("\nHits have %d%% chance to treat Enemy Monster %s Resistance values as inverted", chance, element)
end
build.configTab.input.customMods = mods .. (extraMods or "")
build.buildFlag = true
rebuild()
return build.calcsTab.calcsEnv.player
end

-- Shock effect, in percent, in the breakdown row for the configured boss
local function pinnacleShock(player)
for _, row in ipairs(player.breakdown.ShockDPS.rowList) do
if row.thresh:find("(Pinnacle)", 1, true) then
return tonumber(row.effect:match("^[%d.]+"))
end
end
end

-- Stats that Calcs shows for a non-damaging ailment, read from the sidebar and Calcs calculations
local function ailmentStats(env, ailment)
local output = env.player.output
return { env.player.mainSkill.skillFlags[ailment:lower()] or false, output[ailment.."Chance"] or 0, output[ailment.."Duration"] or 0, output[ailment.."EffectMod"] or 0, output.FreezeDurationMod or 0 }
end

it("shows Shock from inverted hits while preserving weighted hit DPS", function()
setupArcInversion()
local average = calcsShock("AVERAGE", 50, "Elemental")
local inverted = calcsShock("INVERTED", 50, "Elemental")
local certainInversion = calcsShock("AVERAGE", 100, "Elemental")
local invertedShock = pinnacleShock(inverted)
-- The boss has positive Lightning Resistance, so a hit that inverts it Shocks harder than the average hit
assert.is_true(build.calcsTab.calcsEnv.enemyDB:Sum("BASE", nil, "LightningResist") > 0)
assert.is_true(pinnacleShock(average) < invertedShock)
assert.are.equal(pinnacleShock(certainInversion), invertedShock)
assert.is_true(average.output.LightningHitAverage < certainInversion.output.LightningHitAverage)
assert.are.equal(average.output.LightningHitAverage, inverted.output.LightningHitAverage)
assert.are.equal(average.output.TotalDPS, inverted.output.TotalDPS)
assert.matches("Inverted Hits", inverted.breakdown.ShockEffectMod[1], 1, true)
assert.is_nil(inverted.breakdown.ShockEffectMod[2])

calcsShock("INVERTED", 50, "Elemental")
loadBuildFromXML(build:SaveDB("code"))
assert.are.equal("INVERTED", build.configTab.input.ailmentMode)
assert.are.equal(invertedShock, pinnacleShock(build.calcsTab.calcsEnv.player))
end)

it("gives the sidebar and Calcs the same ailment stats in Inverted Hits mode", function()
setupArcInversion()
calcsShock("INVERTED", 50, "Elemental")
assert.is_true(build.calcsTab.mainEnv.player.mainSkill.skillFlags.shock)
assert.is_true(build.calcsTab.mainOutput.ShockDuration > 0)
assert.are.same(ailmentStats(build.calcsTab.calcsEnv, "Shock"), ailmentStats(build.calcsTab.mainEnv, "Shock"))
-- An inverted hit against a capped inverted resistance deals no Lightning Damage
build.configTab.input.enemyLightningResist = -150
calcsShock("INVERTED", 50, "Lightning")
assert.are.same(ailmentStats(build.calcsTab.calcsEnv, "Shock"), ailmentStats(build.calcsTab.mainEnv, "Shock"))
end)

it("leaves damaging ailments unchanged in Inverted Hits mode", function()
build.skillsTab:PasteSocketGroup("Fireball 20/0 1\n")
build.configTab.input.enemyIsBoss = "Pinnacle"
local function damagingAilments(mode)
build.configTab.input.ailmentMode = mode
build.configTab.input.customMods = "Adds 1000 to 1000 Chaos Damage to Spells\n100% chance to Ignite\n100% chance to Poison on Hit\nHits have 50% chance to treat Enemy Monster Elemental Resistance values as inverted"
build.buildFlag = true
rebuild()
return build.calcsTab.calcsEnv.player
end
local average = damagingAilments("AVERAGE")
local inverted = damagingAilments("INVERTED")
assert.is_true(average.output.IgniteDPS > 0)
assert.is_true(average.output.PoisonDPS > 0)
assert.are.equal(average.output.IgniteDPS, inverted.output.IgniteDPS)
assert.are.equal(average.output.PoisonDPS, inverted.output.PoisonDPS)
assert.are.equal(average.output.PoisonDPS, build.calcsTab.mainOutput.PoisonDPS)
assert.is_nil(table.concat(average.breakdown.PoisonDPS, " "):find("Inverted Hits", 1, true))
assert.matches("Average Damage", inverted.breakdown.PoisonDPS[1], 1, true)
assert.matches("Inverted Hits changes nothing here", inverted.breakdown.PoisonDPS[2], 1, true)
end)

it("uses ordinary ailment damage for types without inversion and in Crits Only mode", function()
setupArcInversion()
local withoutInversion = calcsShock("AVERAGE", 0, "Elemental")
local coldOnly = calcsShock("INVERTED", 50, "Cold")
assert.is_nil(withoutInversion.breakdown.ShockEffectMod[2])
assert.are.equal(pinnacleShock(withoutInversion), pinnacleShock(coldOnly))
assert.matches("Average Damage", coldOnly.breakdown.ShockEffectMod[1], 1, true)
assert.matches("Inverted Hits changes nothing here", coldOnly.breakdown.ShockEffectMod[2], 1, true)
local crits = calcsShock("CRIT", 50, "Lightning")
assert.are.equal(0, crits.output.ShockChanceOnHit)
assert.matches("Crits Only", crits.breakdown.ShockEffectMod[1], 1, true)
assert.is_nil(crits.breakdown.ShockEffectMod[2])
end)

it("uses penetration after element-specific inversion and reports immunity at the hit cap", function()
setupArcInversion()
local penetration = "\nDamage Penetrates 20% of Enemy Lightning Resistance"
local inverted = calcsShock("INVERTED", 50, "Lightning", penetration)
local certainInversion = calcsShock("AVERAGE", 100, "Lightning", penetration)
assert.are.equal(pinnacleShock(certainInversion), pinnacleShock(inverted))
build.configTab.input.enemyLightningResist = -150
local capped = calcsShock("INVERTED", 50, "Lightning")
assert.is_true(capped.output.LightningHitAverage > 0)
assert.are.equal("Inverted hits deal no damage that can inflict Shock.", capped.breakdown.ShockDPS[1])
-- The Shock rows stay visible for the note, so they must carry the stats an ordinary hit would show
local ordinary = calcsShock("AVERAGE", 50, "Lightning")
assert.is_true(ordinary.output.ShockDuration > 0)
assert.is_true(capped.mainSkill.skillFlags.shock)
assert.are.equal(ordinary.output.ShockDuration, capped.output.ShockDuration)
assert.are.equal(ordinary.output.ShockEffectMod, capped.output.ShockEffectMod)
assert.are.equal(ordinary.output.ShockChance, capped.output.ShockChance)
end)

it("shows the Freeze threshold of an inverted hit", function()
build.skillsTab:PasteSocketGroup("Freezing Pulse 20/0 1\n")
build.configTab.input.enemyIsBoss = "Pinnacle"
local function freezeThreshold(mode, chance)
build.configTab.input.ailmentMode = mode
build.configTab.input.customMods = string.format("100%% chance to Freeze\nHits have %d%% chance to treat Enemy Monster Cold Resistance values as inverted", chance)
build.buildFlag = true
rebuild()
for _, line in ipairs(build.calcsTab.calcsEnv.player.breakdown.FreezeDPS) do
local threshold = line:match("no more than (%d+) Ailment Threshold")
if threshold then return tonumber(threshold) end
end
end
local average = freezeThreshold("AVERAGE", 50)
local inverted = freezeThreshold("INVERTED", 50)
assert.is_true(inverted > average)
assert.are.equal(freezeThreshold("AVERAGE", 100), inverted)
end)

it("scales minion ailment duration with Barnacles", function()
build.skillsTab:PasteSocketGroup("Slot: Weapon 1\nSummon Ice Golem 20/0 1\n")
build.configTab.input.customMods = "Inflict Barnacles on nearby Enemies every second\nMinions gain 100% of Physical Damage as Extra Cold Damage"
Expand Down
79 changes: 55 additions & 24 deletions src/Modules/CalcOffence.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3385,6 +3385,11 @@ function calcs.offence(env, actor, activeSkill)
end
end

-- Inverted Hits ailment mode: track the damage of a hit that inverts each resistance it can, per crit pass.
-- Hit damage itself keeps its chance weighting.
local invertedHits = env.configInput.ailmentMode == "INVERTED" and { { }, { } }
pass.invertedHits = invertedHits

-- Calculate base hit damage
for _, damageType in ipairs(dmgTypeList) do
local damageTypeMin = damageType.."Min"
Expand Down Expand Up @@ -3626,11 +3631,13 @@ function calcs.offence(env, actor, activeSkill)
if skillFlags.trap or skillFlags.mine then
takenInc = takenInc + enemyDB:Sum("INC", nil, "TrapMineDamageTaken")
end
local effMult = (1 + takenInc / 100) * takenMore
local takenMult = (1 + takenInc / 100) * takenMore
local effMult = takenMult
local useResChance = useThisResist(damageType)
local useRes = useResChance > 0
local cannotPenIgnore = skillModList:Flag(cfg, isElemental[damageType] and "CannotElePenIgnore" or nil)
local effectiveResist = resist
if skillModList:Flag(cfg, isElemental[damageType] and "CannotElePenIgnore" or nil) then
if cannotPenIgnore then
effectiveResist = invertChance > 0 and (resist * (1 - invertChance) + invertedResist * invertChance) or resist
effMult = effMult * (1 - effectiveResist / 100)
elseif useRes then
Expand All @@ -3641,13 +3648,17 @@ function calcs.offence(env, actor, activeSkill)
end
effMult = effMult * (1 - effectiveResist / 100)
end
if invertedHits and invertChance > 0 and (cannotPenIgnore or useRes) then
local effectiveInvertedResist = cannotPenIgnore and invertedResist or (invertedResist - pen) * useResChance
invertedHits[pass][damageType] = damageTypeHitAvg * takenMult * (1 - effectiveInvertedResist / 100)
end
damageTypeHitMin = damageTypeHitMin * effMult
damageTypeHitMax = damageTypeHitMax * effMult
damageTypeHitAvg = damageTypeHitAvg * effMult
if env.mode == "CALCS" then
output[damageType.."EffMult"] = effMult
end
if pass == 2 and breakdown and (effMult ~= 1 or sourceRes ~= damageType or invertChance > 0) and skillModList:Flag(cfg, isElemental[damageType] and "CannotElePenIgnore" or nil) then
if pass == 2 and breakdown and (effMult ~= 1 or sourceRes ~= damageType or invertChance > 0) and cannotPenIgnore then
t_insert(breakdown[damageType], s_format("x %.3f ^8(effective DPS modifier)", effMult))
breakdown[damageType.."EffMult"] = breakdown.effMult(damageType, resist, 0, takenInc, effMult, takenMore, sourceRes, useRes, invertChance, effectiveResist, invertedResist)
elseif pass == 2 and breakdown and (effMult ~= 1 or sourceRes ~= damageType or invertChance > 0) then
Expand Down Expand Up @@ -4337,6 +4348,7 @@ function calcs.offence(env, actor, activeSkill)
end

local ailmentMode = env.configInput.ailmentMode or "AVERAGE"
local ordinaryAilmentMode = ailmentMode == "CRIT" and "Crits Only" or "Average Damage"
if ailmentMode == "CRIT" or modDB:Flag(nil, "AilmentsOnlyFromCrit") then
for _, ailment in ipairs(ailmentTypeList) do
output[ailment.."ChanceOnHit"] = 0
Expand All @@ -4359,11 +4371,13 @@ function calcs.offence(env, actor, activeSkill)
targetCfg.flags = bor(targetCfg.flags, band(cfg.flags, ModFlag.Weapon1H))
end

local invertedHits = pass.invertedHits
---Calculates normal and crit damage to be used in non-damaging ailment calculations
---@param ailment string
---@return number, number @average hit damage, average crit damage
---@return number, number, boolean @average hit damage, average crit damage, whether inversion was used
local function calcAverageSourceDamage(ailment)
local sourceHitDmg, sourceCritDmg = 0, 0
local usesInversion = false
for _, type in ipairs(dmgTypeList) do
if canDeal[type] and (function()
if type == ailmentData[ailment].associatedType then
Expand All @@ -4372,11 +4386,22 @@ function calcs.offence(env, actor, activeSkill)
return skillModList:Flag(cfg, type.."Can"..ailment)
end
end)() then
sourceHitDmg = sourceHitDmg + output[type.."HitAverage"]
sourceCritDmg = sourceCritDmg + output[type.."CritAverage"]
local invertedHit = invertedHits and invertedHits[2][type]
local invertedCrit = invertedHits and invertedHits[1][type]
if invertedHit or invertedCrit then usesInversion = true end
sourceHitDmg = sourceHitDmg + (invertedHit or output[type.."HitAverage"])
sourceCritDmg = sourceCritDmg + (invertedCrit or output[type.."CritAverage"])
end
end
return sourceHitDmg, sourceCritDmg
return sourceHitDmg, sourceCritDmg, usesInversion
end

---Describes the ailment mode a non-damaging ailment actually used
local function ailmentModeBreakdown(usesInversion)
return {
s_format("Ailment mode: %s ^8(can be changed in the Configuration tab)", usesInversion and "Inverted Hits" or ordinaryAilmentMode),
ailmentMode == "INVERTED" and not usesInversion and "^8(Inverted Hits changes nothing here: no damage that can inflict this ailment has a chance to invert resistance)" or nil,
}
end

-- Calculate the inflict chance and base damage of a secondary effect (bleed/poison/ignite/shock/freeze)
Expand Down Expand Up @@ -4887,7 +4912,8 @@ function calcs.offence(env, actor, activeSkill)
end
if globalBreakdown then
globalBreakdown.PoisonDPS = {
s_format("Ailment mode: %s ^8(can be changed in the Configuration tab)", ailmentMode == "CRIT" and "Crits Only" or "Average Damage")
s_format("Ailment mode: %s ^8(can be changed in the Configuration tab)", ordinaryAilmentMode),
ailmentMode == "INVERTED" and "^8(Inverted Hits changes nothing here: damaging ailments are based on damage before enemy resistances)" or nil,
}
end
local baseMinVal = calcAilmentDamage("Poison", output.CritChance, sourceMinHitDmg, 0, true) * data.misc.PoisonPercentBase
Expand Down Expand Up @@ -5448,46 +5474,51 @@ function calcs.offence(env, actor, activeSkill)
end
-- Crit ailments are done differently for Freeze
if (output.FreezeChanceOnHit + output.FreezeChanceOnCrit) > 0 then
local hitDamage, critDamage, usesInversion = calcAverageSourceDamage("Freeze")
if globalBreakdown then
globalBreakdown.FreezeDurationMod = {
s_format("Ailment mode: %s ^8(can be changed in the Configuration tab)", ailmentMode == "CRIT" and "Crits Only" or "Average Damage")
}
globalBreakdown.FreezeDurationMod = ailmentModeBreakdown(usesInversion)
end
local baseVal = calcAilmentDamage("Freeze", output.CritChance, calcAverageSourceDamage("Freeze")) * skillModList:More(cfg, "FreezeAsThoughDealing")
if baseVal > 0 then
local baseVal = calcAilmentDamage("Freeze", output.CritChance, hitDamage, critDamage) * skillModList:More(cfg, "FreezeAsThoughDealing")
if baseVal > 0 or usesInversion then
skillFlags.freeze = true
output.FreezeDurationMod = 1 + skillModList:Sum("INC", cfg, "EnemyFreezeDuration", "EnemyAilmentDuration", "EnemyElementalAilmentDuration") / 100 + enemyDB:Sum("INC", nil, "SelfFreezeDuration", "SelfElementalAilmentDuration", "SelfAilmentDuration", "HoarfrostFreezeDuration") / 100
if breakdown then
t_insert(breakdown.FreezeDPS, s_format("For freeze to apply for the minimum of 0.3 seconds, target must have no more than %.0f Ailment Threshold.", baseVal * 20 * output.FreezeDurationMod))
t_insert(breakdown.FreezeDPS, s_format("^8(Ailment Threshold is about equal to Life except on bosses where it is about half of their life)"))
if baseVal > 0 then
t_insert(breakdown.FreezeDPS, s_format("For freeze to apply for the minimum of 0.3 seconds, target must have no more than %.0f Ailment Threshold.", baseVal * 20 * output.FreezeDurationMod))
t_insert(breakdown.FreezeDPS, "^8(Ailment Threshold is about equal to Life except on bosses where it is about half of their life)")
else
breakdown.FreezeDPS = { "Inverted hits deal no damage that can Freeze." }
end
end
end
end
-- Cycle through all non-damage ailments here, modifying them if needed
for ailment, val in pairs(ailments) do
if (output[ailment.."ChanceOnHit"] + output[ailment.."ChanceOnCrit"]) > 0 then
if globalBreakdown then
globalBreakdown[ailment.."EffectMod"] = {
s_format("Ailment mode: %s ^8(can be changed in the Configuration tab)", ailmentMode == "CRIT" and "Crits Only" or "Average Damage")
}
end
-- Sets the crit strike condition to match ailment mode.
if ailmentMode == "CRIT" and (not modDB:Flag(nil, "AilmentsAreNeverFromCrit")) then
cfg.skillCond["CriticalStrike"] = true
else
cfg.skillCond["CriticalStrike"] = false
end

local damage = calcAilmentDamage(ailment, output.CritChance, calcAverageSourceDamage(ailment)) * skillModList:More(cfg, ailment.."AsThoughDealing")
-- We check if there is a damage instance above 0 since if you deal 0 damage, you don't apply anything.
if damage > 0 then
local hitDamage, critDamage, usesInversion = calcAverageSourceDamage(ailment)
if globalBreakdown then
globalBreakdown[ailment.."EffectMod"] = ailmentModeBreakdown(usesInversion)
end
local damage = calcAilmentDamage(ailment, output.CritChance, hitDamage, critDamage) * skillModList:More(cfg, ailment.."AsThoughDealing")
-- If you deal 0 damage, you don't apply anything. Inverted Hits still shows the ailment's stats with a note,
-- since ordinary hits of the same skill may inflict it.
if damage > 0 or usesInversion then
skillFlags[string.lower(ailment)] = true
local incDur = skillModList:Sum("INC", cfg, "Enemy"..ailment.."Duration", "EnemyElementalAilmentDuration", "EnemyAilmentDuration") + enemyDB:Sum("INC", nil, "Self"..ailment.."Duration", "SelfElementalAilmentDuration", "SelfAilmentDuration")
local moreDur = skillModList:More(cfg, "Enemy"..ailment.."Duration", "EnemyElementalAilmentDuration", "EnemyAilmentDuration") * enemyDB:More(nil, "Self"..ailment.."Duration", "SelfElementalAilmentDuration", "SelfAilmentDuration")
output[ailment.."Duration"] = ailmentData[ailment].duration * (1 + incDur / 100) * moreDur * debuffDurationMult
-- Line Controls Crit Conditional for Crit Mastery
output[ailment.."EffectMod"] = calcLib.mod(skillModList, cfg, "Enemy"..ailment.."Effect") * calcLib.mod(enemyDB, nil, "Self"..ailment.."Effect")
if breakdown then
if breakdown and damage <= 0 then
breakdown[ailment.."DPS"] = { "Inverted hits deal no damage that can inflict "..ailment.."." }
elseif breakdown then
local maximum = globalOutput["Maximum"..ailment] or ailmentData[ailment].max
local current = m_max(m_min(globalOutput["Current"..ailment] or 0, maximum), 0)
local desired = m_max(m_min(enemyDB:Sum("BASE", nil, "Desired"..ailment.."Val"), maximum), 0)
Expand Down
Loading