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
57 changes: 57 additions & 0 deletions spec/System/TestDefence_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,63 @@ describe("TestDefence", function()
return build.calcsTab.calcs.reducePoolsByDamage(nil, takenDamages, build.calcsTab.calcsEnv.player)
end

local function calculateAvoidance(avoidance, elusive, category, worstOf, mixedDamage)
build.configTab.input.enemyDamageType = category
build.configTab.input.enemyIsBoss = "None"
build.configTab.input.enemyCritChance = 0
build.configTab.input.EHPUnluckyWorstOf = worstOf
build.configTab.input.buffElusive = elusive
for _, damageType in ipairs({ "Physical", "Lightning", "Cold", "Fire", "Chaos" }) do
build.configTab.input["enemy"..damageType.."Damage"] = (damageType == "Cold" or mixedDamage and damageType == "Fire") and "1000" or "0"
end
build.configTab.input.customMods = "+1000 to maximum Life\n+60% to Cold Resistance\n"..avoidance
if elusive then
build.configTab.input.customMods = build.configTab.input.customMods.."\nGain Elusive on Critical Strike\n100% increased Elusive Effect"
end
build.configTab:BuildModList()
runCallback("OnFrame")
return build.calcsTab.calcsOutput
end

it("adds Elusive and type-specific damage avoidance without applying either twice", function()
for _, category in ipairs({ "Melee", "Projectile", "Spell", "SpellProjectile", "Untyped", "Average" }) do
for _, worstOf in ipairs({ 1, 2, 4 }) do
for _, chance in ipairs({ 0, 15, 70 }) do
local combined = math.min(15 + chance, data.misc.AvoidChanceCap)
local output = calculateAvoidance(chance.."% chance to Avoid Cold Damage from Hits\n10% chance to Avoid Projectiles", true, category, worstOf)
assert.are.equal(15, output.AvoidAllDamageFromHitsChance)
assert.are.equal(combined, output.AvoidColdDamageChance)
assert.are.equal(15, output.AvoidPhysicalDamageChance)
if category == "SpellProjectile" then
assert.are.near(100 * (0.1 ^ worstOf), output.ConfiguredNotHitChance, 0.000001)
end
local reference = calculateAvoidance(combined.."% chance to Avoid Cold Damage from Hits\n10% chance to Avoid Projectiles", false, category, worstOf)
assert.are.near(reference.TotalEHP, output.TotalEHP, 0.000001)
end
end
end
end)

it("applies additive damage avoidance and projectile avoidance as independent probabilities", function()
local baseline = calculateAvoidance("", false, "SpellProjectile", 1)
local damageAvoidance = calculateAvoidance("15% chance to Avoid Cold Damage from Hits", true, "SpellProjectile", 1)
assert.are.near(baseline.TotalEHP / 0.7, damageAvoidance.TotalEHP, 0.000001)

local projectileAvoidance = calculateAvoidance("15% chance to Avoid Cold Damage from Hits\n10% chance to Avoid Projectiles", true, "SpellProjectile", 1)
-- 30% damage avoidance and 10% projectile avoidance leave 63% of attempts dealing damage.
assert.are.near(baseline.TotalEHP / 0.63, projectileAvoidance.TotalEHP, 0.000001)
end)

it("applies type-specific avoidance only to its portion of a mixed-damage hit", function()
local baseline = calculateAvoidance("", false, "Spell", 1, true)
local output = calculateAvoidance("15% chance to Avoid Cold Damage from Hits", true, "Spell", 1, true)
assert.are.equal(30, output.AvoidColdDamageChance)
assert.are.equal(15, output.AvoidFireDamageChance)
local damage = baseline.ColdTakenHit + baseline.FireTakenHit
local expectedDamage = baseline.ColdTakenHit * 0.7 + baseline.FireTakenHit * 0.85
assert.are.near(baseline.TotalEHP * damage / expectedDamage, output.TotalEHP, 0.000001)
end)

it("attributes resistances inherited by minions to Bonemeld after loading a build", function()
build.skillsTab:PasteSocketGroup("Raise Zombie 20/0 1")
build.itemsTab:CreateDisplayItemFromRaw("Rarity: UNIQUE\nBonemeld\nMarble Amulet\nImplicits: 0\nMinions gain added Resistances equal to 50% of your Resistances")
Expand Down
32 changes: 11 additions & 21 deletions src/Modules/CalcDefence.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1574,10 +1574,10 @@ function calcs.defence(env, actor)
output.EnergyShieldOnSpellBlock = modDB:Sum("BASE", nil, "EnergyShieldOnSpellBlock")
output.EnergyShieldOnSuppress = modDB:Sum("BASE", nil, "EnergyShieldOnSuppress")

-- damage avoidances
-- All-damage and type-specific damage avoidance are additive and share a cap.
output.specificTypeAvoidance = false
for _, damageType in ipairs(dmgTypeList) do
output["Avoid"..damageType.."DamageChance"] = m_min(modDB:Sum("BASE", nil, "Avoid"..damageType.."DamageChance"), data.misc.AvoidChanceCap)
output["Avoid"..damageType.."DamageChance"] = m_min(modDB:Sum("BASE", nil, "Avoid"..damageType.."DamageChance", "AvoidAllDamageFromHitsChance"), data.misc.AvoidChanceCap)
if output["Avoid"..damageType.."DamageChance"] > 0 then
output.specificTypeAvoidance = true
end
Expand Down Expand Up @@ -1688,11 +1688,11 @@ function calcs.buildDefenceEstimations(env, actor)
-- chance to not be hit calculations
if damageCategoryConfig ~= "DamageOverTime" then
local worstOf = env.configInput.EHPUnluckyWorstOf or 1
output.MeleeNotHitChance = 100 - (1 - output.MeleeEvadeChance / 100) * (1 - output.EffectiveAttackDodgeChance / 100) * (1 - output.AvoidAllDamageFromHitsChance / 100) * 100
output.ProjectileNotHitChance = 100 - (1 - output.ProjectileEvadeChance / 100) * (1 - output.EffectiveAttackDodgeChance / 100) * (1 - output.AvoidAllDamageFromHitsChance / 100) * (1 - (output.specificTypeAvoidance and 0 or output.AvoidProjectilesChance) / 100) * 100
output.SpellNotHitChance = 100 - (1 - output.EffectiveSpellDodgeChance / 100) * (1 - output.AvoidAllDamageFromHitsChance / 100) * 100
output.SpellProjectileNotHitChance = 100 - (1 - output.EffectiveSpellDodgeChance / 100) * (1 - output.AvoidAllDamageFromHitsChance / 100) * (1 - (output.specificTypeAvoidance and 0 or output.AvoidProjectilesChance) / 100) * 100
output.UntypedNotHitChance = 100 - (1 - output.AvoidAllDamageFromHitsChance / 100) * 100
output.MeleeNotHitChance = 100 - (1 - output.MeleeEvadeChance / 100) * (1 - output.EffectiveAttackDodgeChance / 100) * 100
output.ProjectileNotHitChance = 100 - (1 - output.ProjectileEvadeChance / 100) * (1 - output.EffectiveAttackDodgeChance / 100) * (1 - output.AvoidProjectilesChance / 100) * 100
output.SpellNotHitChance = 100 - (1 - output.EffectiveSpellDodgeChance / 100) * 100
output.SpellProjectileNotHitChance = 100 - (1 - output.EffectiveSpellDodgeChance / 100) * (1 - output.AvoidProjectilesChance / 100) * 100
output.UntypedNotHitChance = 0
output.AverageNotHitChance = (output.MeleeNotHitChance + output.ProjectileNotHitChance + output.SpellNotHitChance + output.SpellProjectileNotHitChance) / 4
output.AverageEvadeChance = (output.MeleeEvadeChance + output.ProjectileEvadeChance) / 4
output.ConfiguredNotHitChance = output[damageCategoryConfig.."NotHitChance"]
Expand Down Expand Up @@ -2801,7 +2801,6 @@ function calcs.buildDefenceEstimations(env, actor)
local blockEffect = (1 - BlockChance * output.BlockEffect / 100)
local suppressChance = 0
local suppressionEffect = 1
local ExtraAvoidChance = 0
local averageAvoidChance = 0
if not env.configInput.DisableEHPGainOnBlock and (output["NumberOfDamagingHits"] > 1) then
DamageIn.LifeWhenHit = output.LifeOnBlock * BlockChance
Expand Down Expand Up @@ -2829,12 +2828,6 @@ function calcs.buildDefenceEstimations(env, actor)
DamageIn.EnergyShieldWhenHit = (DamageIn.EnergyShieldWhenHit or 0) + output.EnergyShieldOnSuppress * ( damageCategoryConfig == "Average" and 0.5 or 1 )
DamageIn.LifeWhenHit = (DamageIn.LifeWhenHit or 0) + output.LifeOnSuppress * ( damageCategoryConfig == "Average" and 0.5 or 1 )
end
-- extra avoid chance
if damageCategoryConfig == "Projectile" or damageCategoryConfig == "SpellProjectile" then
ExtraAvoidChance = ExtraAvoidChance + output.AvoidProjectilesChance
elseif damageCategoryConfig == "Average" then
ExtraAvoidChance = ExtraAvoidChance + output.AvoidProjectilesChance / 2
end
-- gain when hit (currently just gain on block/suppress, and Defiance of Destiny)
if not env.configInput.DisableEHPGainOnBlock and (output["NumberOfDamagingHits"] > 1) then
DamageIn.MissingLifeBeforeEnemyHit = modDB:Sum("BASE", nil, "MissingLifeBeforeEnemyHit")
Expand All @@ -2854,7 +2847,7 @@ function calcs.buildDefenceEstimations(env, actor)
end
local AvoidChance = 0
if output.specificTypeAvoidance then
AvoidChance = m_min(output["Avoid"..damageType.."DamageChance"] + ExtraAvoidChance, data.misc.AvoidChanceCap)
AvoidChance = output["Avoid"..damageType.."DamageChance"]
-- unlucky config to lower the value of block, dodge, evade etc for ehp
local worstOf = env.configInput.EHPUnluckyWorstOf or 1
if worstOf > 1 then
Expand Down Expand Up @@ -2913,14 +2906,14 @@ function calcs.buildDefenceEstimations(env, actor)
if output.AttackDodgeChance > 0 then
t_insert(breakdown["ConfiguredNotHitChance"], s_format("x %.2f ^8(chance for dodge to fail)", 1 - output.AttackDodgeChance / 100))
end
if damageCategoryConfig == "Projectile" and not output.specificTypeAvoidance and output.AvoidProjectilesChance > 0 then
if damageCategoryConfig == "Projectile" and output.AvoidProjectilesChance > 0 then
t_insert(breakdown["ConfiguredNotHitChance"], s_format("x %.2f ^8(chance for avoidance to fail)", 1 - output.AvoidProjectilesChance / 100))
end
elseif damageCategoryConfig == "Spell" or damageCategoryConfig == "SpellProjectile" then
if output.SpellDodgeChance > 0 then
t_insert(breakdown["ConfiguredNotHitChance"], s_format("%.2f ^8(chance for dodge to fail)", 1 - output.SpellDodgeChance / 100))
end
if damageCategoryConfig == "SpellProjectile" and not output.specificTypeAvoidance and output.AvoidProjectilesChance > 0 then
if damageCategoryConfig == "SpellProjectile" and output.AvoidProjectilesChance > 0 then
t_insert(breakdown["ConfiguredNotHitChance"], s_format("x %.2f ^8(chance for avoidance to fail)", 1 - output.AvoidProjectilesChance / 100))
end
elseif damageCategoryConfig == "Average" then
Expand All @@ -2930,13 +2923,10 @@ function calcs.buildDefenceEstimations(env, actor)
if output.AttackDodgeChance > 0 or output.SpellDodgeChance > 0 then
t_insert(breakdown["ConfiguredNotHitChance"], s_format("x%.2f ^8(chance for dodge to fail)", 1 - (output.AttackDodgeChance + output.SpellDodgeChance) / 2 / 100))
end
if not output.specificTypeAvoidance and output.AvoidProjectilesChance > 0 then
if output.AvoidProjectilesChance > 0 then
t_insert(breakdown["ConfiguredNotHitChance"], s_format("x %.2f ^8(chance for avoidance to fail)", 1 - output.AvoidProjectilesChance / 2 / 100))
end
end
if output.AvoidAllDamageFromHitsChance > 0 then
t_insert(breakdown["ConfiguredNotHitChance"], s_format("x %.2f ^8(chance for damage avoidance to fail)", 1 - output.AvoidAllDamageFromHitsChance / 100))
end
local worstOf = env.configInput.EHPUnluckyWorstOf or 1
if worstOf > 1 then
t_insert(breakdown["ConfiguredNotHitChance"], s_format("unlucky worst of %d", worstOf))
Expand Down
10 changes: 5 additions & 5 deletions src/Modules/CalcSections.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1730,11 +1730,11 @@ return {
} },
{ 1, "DamageAvoidance", 3, colorCodes.DEFENCE, { { defaultCollapsed = false, label = "Damage Avoidance", data = {
{ label = "Avoid All Dmg Ch.", haveOutput = "AvoidAllDamageFromHitsChance", { format = "{0:output:AvoidAllDamageFromHitsChance}%", { modName = "AvoidAllDamageFromHitsChance" }, }, },
{ label = "Avoid Physical Ch.", haveOutput = "AvoidPhysicalDamageChance", { format = "{0:output:AvoidPhysicalDamageChance}%", { modName = "AvoidPhysicalDamageChance" }, }, },
{ label = "Avoid Lightning Ch.", haveOutput = "AvoidLightningDamageChance", { format = "{0:output:AvoidLightningDamageChance}%", { modName = "AvoidLightningDamageChance" }, }, },
{ label = "Avoid Cold Chance", haveOutput = "AvoidColdDamageChance", { format = "{0:output:AvoidColdDamageChance}%", { modName = "AvoidColdDamageChance" }, }, },
{ label = "Avoid Fire Chance", haveOutput = "AvoidFireDamageChance", { format = "{0:output:AvoidFireDamageChance}%", { modName = "AvoidFireDamageChance" }, }, },
{ label = "Avoid Chaos Chance", haveOutput = "AvoidChaosDamageChance", { format = "{0:output:AvoidChaosDamageChance}%", { modName = "AvoidChaosDamageChance" }, }, },
{ label = "Avoid Physical Ch.", haveOutput = "AvoidPhysicalDamageChance", { format = "{0:output:AvoidPhysicalDamageChance}%", { modName = { "AvoidPhysicalDamageChance", "AvoidAllDamageFromHitsChance" } }, }, },
{ label = "Avoid Lightning Ch.", haveOutput = "AvoidLightningDamageChance", { format = "{0:output:AvoidLightningDamageChance}%", { modName = { "AvoidLightningDamageChance", "AvoidAllDamageFromHitsChance" } }, }, },
{ label = "Avoid Cold Chance", haveOutput = "AvoidColdDamageChance", { format = "{0:output:AvoidColdDamageChance}%", { modName = { "AvoidColdDamageChance", "AvoidAllDamageFromHitsChance" } }, }, },
{ label = "Avoid Fire Chance", haveOutput = "AvoidFireDamageChance", { format = "{0:output:AvoidFireDamageChance}%", { modName = { "AvoidFireDamageChance", "AvoidAllDamageFromHitsChance" } }, }, },
{ label = "Avoid Chaos Chance", haveOutput = "AvoidChaosDamageChance", { format = "{0:output:AvoidChaosDamageChance}%", { modName = { "AvoidChaosDamageChance", "AvoidAllDamageFromHitsChance" } }, }, },
{ label = "Avoid Proj Ch.", haveOutput = "AvoidProjectilesChance", { format = "{0:output:AvoidProjectilesChance}%", { modName = "AvoidProjectilesChance" }, }, },
} }, { defaultCollapsed = false, label = "Block", data = {
extra = "{3:output:EffectiveBlockChance}%/{3:output:EffectiveSpellBlockChance}%",
Expand Down
Loading