Skip to content

Commit ad84c4c

Browse files
author
David Medgyesy
committed
Apply Inverted Hits ailment mode in every calculation
The mode was limited to the Calcs environment, so the sidebar calculation could disagree with Calcs about whether a skill Shocks or Freezes. It now applies wherever ailments are calculated; hit damage keeps its chance weighting. When an inverted hit deals no damage that can inflict an ailment, the rows stay visible for the note and now carry the duration and effect an ordinary hit shows, instead of a 0s duration. Breakdowns state the mode that was actually used: Poison and non-damaging ailments the skill cannot invert say Average Damage with a note, and the config tooltip explains that Ignite, Bleed and Poison are based on damage before resistances. Tests compare against the certain-inversion case instead of fixed percentages.
1 parent 205d444 commit ad84c4c

3 files changed

Lines changed: 82 additions & 21 deletions

File tree

‎spec/System/TestAilments_spec.lua‎

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,41 +95,89 @@ describe("TestAilments", function()
9595
return build.calcsTab.calcsEnv.player
9696
end
9797

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

107+
-- Stats that Calcs shows for a non-damaging ailment, read from the sidebar and Calcs calculations
108+
local function ailmentStats(env, ailment)
109+
local output = env.player.output
110+
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 }
111+
end
112+
106113
it("shows Shock from inverted hits while preserving weighted hit DPS", function()
107114
setupArcInversion()
108115
local average = calcsShock("AVERAGE", 50, "Elemental")
109116
local inverted = calcsShock("INVERTED", 50, "Elemental")
110117
local certainInversion = calcsShock("AVERAGE", 100, "Elemental")
111-
assert.are.equal("10%", pinnacleShock(average))
112-
assert.are.equal("12%", pinnacleShock(certainInversion))
113-
assert.are.equal(pinnacleShock(certainInversion), pinnacleShock(inverted))
118+
local invertedShock = pinnacleShock(inverted)
119+
-- The boss has positive Lightning Resistance, so a hit that inverts it Shocks harder than the average hit
120+
assert.is_true(build.calcsTab.calcsEnv.enemyDB:Sum("BASE", nil, "LightningResist") > 0)
121+
assert.is_true(pinnacleShock(average) < invertedShock)
122+
assert.are.equal(pinnacleShock(certainInversion), invertedShock)
123+
assert.is_true(average.output.LightningHitAverage < certainInversion.output.LightningHitAverage)
114124
assert.are.equal(average.output.LightningHitAverage, inverted.output.LightningHitAverage)
115125
assert.are.equal(average.output.TotalDPS, inverted.output.TotalDPS)
116126
assert.matches("Inverted Hits", inverted.breakdown.ShockEffectMod[1], 1, true)
127+
assert.is_nil(inverted.breakdown.ShockEffectMod[2])
117128

118129
calcsShock("INVERTED", 50, "Elemental")
119130
loadBuildFromXML(build:SaveDB("code"))
120131
assert.are.equal("INVERTED", build.configTab.input.ailmentMode)
121-
assert.are.equal("12%", pinnacleShock(build.calcsTab.calcsEnv.player))
132+
assert.are.equal(invertedShock, pinnacleShock(build.calcsTab.calcsEnv.player))
133+
end)
134+
135+
it("gives the sidebar and Calcs the same ailment stats in Inverted Hits mode", function()
136+
setupArcInversion()
137+
calcsShock("INVERTED", 50, "Elemental")
138+
assert.is_true(build.calcsTab.mainEnv.player.mainSkill.skillFlags.shock)
139+
assert.is_true(build.calcsTab.mainOutput.ShockDuration > 0)
140+
assert.are.same(ailmentStats(build.calcsTab.calcsEnv, "Shock"), ailmentStats(build.calcsTab.mainEnv, "Shock"))
141+
-- An inverted hit against a capped inverted resistance deals no Lightning Damage
142+
build.configTab.input.enemyLightningResist = -150
143+
calcsShock("INVERTED", 50, "Lightning")
144+
assert.are.same(ailmentStats(build.calcsTab.calcsEnv, "Shock"), ailmentStats(build.calcsTab.mainEnv, "Shock"))
145+
end)
146+
147+
it("leaves damaging ailments unchanged in Inverted Hits mode", function()
148+
build.skillsTab:PasteSocketGroup("Fireball 20/0 1\n")
149+
build.configTab.input.enemyIsBoss = "Pinnacle"
150+
local function damagingAilments(mode)
151+
build.configTab.input.ailmentMode = mode
152+
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"
153+
build.buildFlag = true
154+
rebuild()
155+
return build.calcsTab.calcsEnv.player
156+
end
157+
local average = damagingAilments("AVERAGE")
158+
local inverted = damagingAilments("INVERTED")
159+
assert.is_true(average.output.IgniteDPS > 0)
160+
assert.is_true(average.output.PoisonDPS > 0)
161+
assert.are.equal(average.output.IgniteDPS, inverted.output.IgniteDPS)
162+
assert.are.equal(average.output.PoisonDPS, inverted.output.PoisonDPS)
163+
assert.are.equal(average.output.PoisonDPS, build.calcsTab.mainOutput.PoisonDPS)
164+
assert.is_nil(table.concat(average.breakdown.PoisonDPS, " "):find("Inverted Hits", 1, true))
165+
assert.matches("Average Damage", inverted.breakdown.PoisonDPS[1], 1, true)
166+
assert.matches("Inverted Hits changes nothing here", inverted.breakdown.PoisonDPS[2], 1, true)
122167
end)
123168

124169
it("uses ordinary ailment damage for types without inversion and in Crits Only mode", function()
125170
setupArcInversion()
126171
local withoutInversion = calcsShock("AVERAGE", 0, "Elemental")
127172
local coldOnly = calcsShock("INVERTED", 50, "Cold")
173+
assert.is_nil(withoutInversion.breakdown.ShockEffectMod[2])
128174
assert.are.equal(pinnacleShock(withoutInversion), pinnacleShock(coldOnly))
129175
assert.matches("Average Damage", coldOnly.breakdown.ShockEffectMod[1], 1, true)
176+
assert.matches("Inverted Hits changes nothing here", coldOnly.breakdown.ShockEffectMod[2], 1, true)
130177
local crits = calcsShock("CRIT", 50, "Lightning")
131178
assert.are.equal(0, crits.output.ShockChanceOnHit)
132179
assert.matches("Crits Only", crits.breakdown.ShockEffectMod[1], 1, true)
180+
assert.is_nil(crits.breakdown.ShockEffectMod[2])
133181
end)
134182

135183
it("uses penetration after element-specific inversion and reports immunity at the hit cap", function()
@@ -142,6 +190,13 @@ describe("TestAilments", function()
142190
local capped = calcsShock("INVERTED", 50, "Lightning")
143191
assert.is_true(capped.output.LightningHitAverage > 0)
144192
assert.are.equal("Inverted hits deal no damage that can inflict Shock.", capped.breakdown.ShockDPS[1])
193+
-- The Shock rows stay visible for the note, so they must carry the stats an ordinary hit would show
194+
local ordinary = calcsShock("AVERAGE", 50, "Lightning")
195+
assert.is_true(ordinary.output.ShockDuration > 0)
196+
assert.is_true(capped.mainSkill.skillFlags.shock)
197+
assert.are.equal(ordinary.output.ShockDuration, capped.output.ShockDuration)
198+
assert.are.equal(ordinary.output.ShockEffectMod, capped.output.ShockEffectMod)
199+
assert.are.equal(ordinary.output.ShockChance, capped.output.ShockChance)
145200
end)
146201

147202
it("shows the Freeze threshold of an inverted hit", function()

‎src/Modules/CalcOffence.lua‎

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3385,8 +3385,9 @@ function calcs.offence(env, actor, activeSkill)
33853385
end
33863386
end
33873387

3388-
-- Keep conditional damage for the Calcs ailment breakdown only.
3389-
local invertedHits = env.mode == "CALCS" and env.configInput.ailmentMode == "INVERTED" and { { }, { } }
3388+
-- Inverted Hits ailment mode: track the damage of a hit that inverts each resistance it can, per crit pass.
3389+
-- Hit damage itself keeps its chance weighting.
3390+
local invertedHits = env.configInput.ailmentMode == "INVERTED" and { { }, { } }
33903391
pass.invertedHits = invertedHits
33913392

33923393
-- Calculate base hit damage
@@ -4395,6 +4396,14 @@ function calcs.offence(env, actor, activeSkill)
43954396
return sourceHitDmg, sourceCritDmg, usesInversion
43964397
end
43974398

4399+
---Describes the ailment mode a non-damaging ailment actually used
4400+
local function ailmentModeBreakdown(usesInversion)
4401+
return {
4402+
s_format("Ailment mode: %s ^8(can be changed in the Configuration tab)", usesInversion and "Inverted Hits" or ordinaryAilmentMode),
4403+
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,
4404+
}
4405+
end
4406+
43984407
-- Calculate the inflict chance and base damage of a secondary effect (bleed/poison/ignite/shock/freeze)
43994408
local function calcAilmentDamage(type, sourceCritChance, sourceHitDmg, sourceCritDmg, hideFromBreakdown)
44004409
local chanceOnHit, chanceOnCrit = output[type.."ChanceOnHit"], output[type.."ChanceOnCrit"]
@@ -4903,7 +4912,8 @@ function calcs.offence(env, actor, activeSkill)
49034912
end
49044913
if globalBreakdown then
49054914
globalBreakdown.PoisonDPS = {
4906-
s_format("Ailment mode: %s ^8(can be changed in the Configuration tab)", ailmentMode == "CRIT" and "Crits Only" or "Average Damage")
4915+
s_format("Ailment mode: %s ^8(can be changed in the Configuration tab)", ordinaryAilmentMode),
4916+
ailmentMode == "INVERTED" and "^8(Inverted Hits changes nothing here: damaging ailments are based on damage before enemy resistances)" or nil,
49074917
}
49084918
end
49094919
local baseMinVal = calcAilmentDamage("Poison", output.CritChance, sourceMinHitDmg, 0, true) * data.misc.PoisonPercentBase
@@ -5466,9 +5476,7 @@ function calcs.offence(env, actor, activeSkill)
54665476
if (output.FreezeChanceOnHit + output.FreezeChanceOnCrit) > 0 then
54675477
local hitDamage, critDamage, usesInversion = calcAverageSourceDamage("Freeze")
54685478
if globalBreakdown then
5469-
globalBreakdown.FreezeDurationMod = {
5470-
s_format("Ailment mode: %s ^8(can be changed in the Configuration tab)", usesInversion and "Inverted Hits" or ordinaryAilmentMode)
5471-
}
5479+
globalBreakdown.FreezeDurationMod = ailmentModeBreakdown(usesInversion)
54725480
end
54735481
local baseVal = calcAilmentDamage("Freeze", output.CritChance, hitDamage, critDamage) * skillModList:More(cfg, "FreezeAsThoughDealing")
54745482
if baseVal > 0 or usesInversion then
@@ -5496,19 +5504,21 @@ function calcs.offence(env, actor, activeSkill)
54965504

54975505
local hitDamage, critDamage, usesInversion = calcAverageSourceDamage(ailment)
54985506
if globalBreakdown then
5499-
globalBreakdown[ailment.."EffectMod"] = {
5500-
s_format("Ailment mode: %s ^8(can be changed in the Configuration tab)", usesInversion and "Inverted Hits" or ordinaryAilmentMode)
5501-
}
5507+
globalBreakdown[ailment.."EffectMod"] = ailmentModeBreakdown(usesInversion)
55025508
end
55035509
local damage = calcAilmentDamage(ailment, output.CritChance, hitDamage, critDamage) * skillModList:More(cfg, ailment.."AsThoughDealing")
5504-
if damage > 0 then
5510+
-- If you deal 0 damage, you don't apply anything. Inverted Hits still shows the ailment's stats with a note,
5511+
-- since ordinary hits of the same skill may inflict it.
5512+
if damage > 0 or usesInversion then
55055513
skillFlags[string.lower(ailment)] = true
55065514
local incDur = skillModList:Sum("INC", cfg, "Enemy"..ailment.."Duration", "EnemyElementalAilmentDuration", "EnemyAilmentDuration") + enemyDB:Sum("INC", nil, "Self"..ailment.."Duration", "SelfElementalAilmentDuration", "SelfAilmentDuration")
55075515
local moreDur = skillModList:More(cfg, "Enemy"..ailment.."Duration", "EnemyElementalAilmentDuration", "EnemyAilmentDuration") * enemyDB:More(nil, "Self"..ailment.."Duration", "SelfElementalAilmentDuration", "SelfAilmentDuration")
55085516
output[ailment.."Duration"] = ailmentData[ailment].duration * (1 + incDur / 100) * moreDur * debuffDurationMult
55095517
-- Line Controls Crit Conditional for Crit Mastery
55105518
output[ailment.."EffectMod"] = calcLib.mod(skillModList, cfg, "Enemy"..ailment.."Effect") * calcLib.mod(enemyDB, nil, "Self"..ailment.."Effect")
5511-
if breakdown then
5519+
if breakdown and damage <= 0 then
5520+
breakdown[ailment.."DPS"] = { "Inverted hits deal no damage that can inflict "..ailment.."." }
5521+
elseif breakdown then
55125522
local maximum = globalOutput["Maximum"..ailment] or ailmentData[ailment].max
55135523
local current = m_max(m_min(globalOutput["Current"..ailment] or 0, maximum), 0)
55145524
local desired = m_max(m_min(enemyDB:Sum("BASE", nil, "Desired"..ailment.."Val"), maximum), 0)
@@ -5580,10 +5590,6 @@ function calcs.offence(env, actor, activeSkill)
55805590
end
55815591
t_insert(breakdown[ailment.."Duration"], s_format("= %.2fs", output[ailment.."Duration"]))
55825592
end
5583-
elseif usesInversion and breakdown then
5584-
skillFlags[string.lower(ailment)] = true
5585-
output[ailment.."EffectMod"] = calcLib.mod(skillModList, cfg, "Enemy"..ailment.."Effect") * calcLib.mod(enemyDB, nil, "Self"..ailment.."Effect")
5586-
breakdown[ailment.."DPS"] = { "Inverted hits deal no damage that can inflict "..ailment.."." }
55875593
end
55885594
end
55895595
end

‎src/Modules/ConfigOptions.lua‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ return {
212212
{ var = "minionsConditionCreatedRecently", type = "check", label = "Have your Minions been created Recently?", ifCond = "MinionsCreatedRecently", apply = function(val, modList, enemyModList)
213213
modList:NewMod("Condition:MinionsCreatedRecently", "FLAG", true, "Config")
214214
end },
215-
{ var = "ailmentMode", type = "list", label = "Ailment calculation mode:", tooltip = "Controls how the base damage for applying Ailments is calculated:\n\tAverage: damage is based on the average application, including both crits and non-crits\n\tCrits Only: damage is based solely on Ailments inflicted with crits\n\tInverted Hits: Calcs shows non-damaging ailments with each applicable resistance inverted. Uses average damage for types the skill cannot invert. Hit DPS keeps its usual chance weighting.", list = {{val="AVERAGE",label="Average"},{val="CRIT",label="Crits Only"},{val="INVERTED",label="Inverted Hits"}} },
215+
{ var = "ailmentMode", type = "list", label = "Ailment calculation mode:", tooltip = "Controls how the base damage for applying Ailments is calculated:\n\tAverage: damage is based on the average application, including both crits and non-crits\n\tCrits Only: damage is based solely on Ailments inflicted with crits\n\tInverted Hits: non-damaging ailments and the Freeze threshold are based on a hit that treats every Enemy Resistance it can as inverted,\n\t\tinstead of weighting by the chance to invert. Damage types the skill cannot invert use their average damage.\n\t\tHit damage keeps its chance weighting. Ignite, Bleed and Poison are unaffected, as they are based on damage before Enemy Resistances.", list = {{val="AVERAGE",label="Average"},{val="CRIT",label="Crits Only"},{val="INVERTED",label="Inverted Hits"}} },
216216
{ var = "physMode", type = "list", label = "Random element mode:", ifFlag = "randomPhys", tooltip = "Controls how modifiers which choose a random element will function.\n\tAverage: Modifiers will grant one third of their value to ^xB97123Fire^7, ^x3F6DB3Cold^7, and ^xADAA47Lightning ^7simultaneously\n\t^xB97123Fire ^7/ ^x3F6DB3Cold ^7/ ^xADAA47Lightning^7: Modifiers will grant their full value as the specified element\nIf a modifier chooses between just two elements, the full value can only be given as those two elements.", list = {{val="AVERAGE",label="Average"},{val="FIRE",label="^xB97123Fire"},{val="COLD",label="^x3F6DB3Cold"},{val="LIGHTNING",label="^xADAA47Lightning"}} },
217217
{ var = "lifeRegenMode", type = "list", label = "^xE05030Life ^7regen calculation mode:", ifCond = { "LifeRegenBurstAvg", "LifeRegenBurstFull" }, tooltip = "Controls how ^xE05030life ^7regeneration is calculated:\n\tMinimum: does not include burst regen\n\tAverage: includes burst regen, averaged based on uptime\n\tBurst: includes full burst regen", list = {{val="MIN",label="Minimum"},{val="AVERAGE",label="Average"},{val="FULL",label="Burst"}}, apply = function(val, modList, enemyModList)
218218
if val == "AVERAGE" then

0 commit comments

Comments
 (0)