From f76f30806c6c19b4b3a1576cb2be22e22e5786e3 Mon Sep 17 00:00:00 2001 From: David Medgyesy Date: Thu, 26 Nov 2026 19:58:18 +0100 Subject: [PATCH 1/4] Model Monastery Bell blocks from shield attacks --- spec/System/TestTriggers_spec.lua | 146 ++++++++++++++++++++++++++++++ src/Data/ModCache.lua | 2 +- src/Modules/CalcPerform.lua | 3 + src/Modules/CalcSections.lua | 4 + src/Modules/CalcTriggers.lua | 133 ++++++++++++++++++++++----- src/Modules/Common.lua | 1 + src/Modules/ModParser.lua | 1 + 7 files changed, 265 insertions(+), 25 deletions(-) diff --git a/spec/System/TestTriggers_spec.lua b/spec/System/TestTriggers_spec.lua index 4628749ed50..740fb7c05e0 100644 --- a/spec/System/TestTriggers_spec.lua +++ b/spec/System/TestTriggers_spec.lua @@ -1266,6 +1266,152 @@ describe("TestTriggers", function() assert.True(build.calcsTab.mainOutput.SkillTriggerRate ~= nil) end) + describe("The Monastery Bell", function() + local function equipUnique(category, name, slot) + local items = data.uniques[category] + local index = isValueInArrayPred(items, function(raw) return raw:sub(1, #name + 1) == name .. "\n" end) + assert.is_not_nil(index) + local item = new("Item"):Item(items[index]) + build.itemsTab:AddItem(item, true) + build.itemsTab.slots[slot]:SetSelItemId(item.id) + build.buildFlag = true + runCallback("OnFrame") + end + + local function allocateReliquarianBell() + local spec = build.spec + spec:SelectClass(spec.tree.classNameMap.Scion) + spec:SelectAscendClass(spec.tree.ascendNameMap.Reliquarian.ascendClassId) + spec:AllocNode(spec.nodes[26055]) + assert.is_not_nil(spec.allocNodes[26055]) + build.buildFlag = true + runCallback("OnFrame") + end + + local function selectSkill(name) + runCallback("OnFrame") + for groupIndex, group in ipairs(build.skillsTab.socketGroupList) do + for skillIndex, skill in ipairs(group.displaySkillList or {}) do + if skill.activeEffect.grantedEffect.name == name then + build.mainSocketGroup = groupIndex + group.mainActiveSkill = skillIndex + build.buildFlag = true + runCallback("OnFrame") + assert.are.equal(name, build.calcsTab.mainEnv.player.mainSkill.activeEffect.grantedEffect.name) + return build.calcsTab.mainOutput, group + end + end + end + error("Missing active skill: " .. name) + end + + local function setCustomMods(text) + build.configTab.input.customMods = text + build.configTab:BuildModList() + build.buildFlag = true + end + + it("triggers Shield Shatter from the item and the passive while respecting hit chance", function() + equipUnique("shield", "Shattershard", "Weapon 2") + setCustomMods("Your Hits can't be Evaded") + build.skillsTab:PasteSocketGroup("Shield Charge 20/0 1\nFaster Attacks 20/0 1\n") + local normal = selectSkill("Shield Shatter") + assert.are.near(1 / normal.Duration, normal.SkillTriggerRate, 1e-6) + + equipUnique("mace", "The Monastery Bell", "Weapon 1") + local charge, chargeGroup = selectSkill("Shield Charge") + local shatter = selectSkill("Shield Shatter") + assert.are.near(charge.Speed, shatter.SkillTriggerRate, 1e-6) + assert.are.near(normal.Duration, shatter.Duration, 1e-6) + + allocateReliquarianBell() + assert.are.near(charge.Speed, selectSkill("Shield Shatter").SkillTriggerRate, 1e-6) + build.itemsTab.slots["Weapon 1"]:SetSelItemId(0) + build.configTab.input.enemyBlockChance = 50 + build.configTab:BuildModList() + build.buildFlag = true + assert.are.near(charge.Speed / 2, selectSkill("Shield Shatter").SkillTriggerRate, 1e-6) + + build.configTab.input.enemyBlockChance = 100 + build.configTab:BuildModList() + build.buildFlag = true + assert.are.equal(0, selectSkill("Shield Shatter").SkillTriggerRate) + + chargeGroup.enabled = false + build.skillsTab:PasteSocketGroup("Smite 20/0 1\n") + local fallback = selectSkill("Shield Shatter") + assert.is_nil(fallback.ShieldAttackBlockRate) + assert.are.near(1 / fallback.Duration, fallback.SkillTriggerRate, 1e-6) + end) + + it("reports recovery from Bell blocks once per use of a repeating shield attack", function() + equipUnique("mace", "The Monastery Bell", "Weapon 1") + equipUnique("shield", "Aegis Aurora", "Weapon 2") + setCustomMods("Your Hits can't be Evaded\nRecover 100 Life when you Block\nRecover 5% of your maximum Mana when you Block\nRecover 100 Energy Shield when you Block Spell Damage") + build.skillsTab:PasteSocketGroup("Smite 20/0 1\n") + local normal = selectSkill("Smite") + assert.is_nil(normal.ShieldAttackBlockRate) + + build.skillsTab:PasteSocketGroup("Shield Crush 20/0 1\nMultistrike 20/0 1\n") + local crush = selectSkill("Shield Crush") + assert.are.equal(3, crush.Repeats) + assert.are.near(crush.Speed / crush.Repeats, crush.ShieldAttackBlockRate, 1e-6) + assert.are.equal(100, crush.LifeOnBlock) + assert.True(crush.ManaOnBlock > 0) + assert.True(crush.EnergyShieldOnBlock > 0) + assert.are.equal(100, crush.EnergyShieldOnSpellBlock) + assert.are.near(crush.LifeOnBlock * crush.ShieldAttackBlockRate, crush.ShieldAttackLifeOnBlockRate, 1e-6) + assert.are.near(crush.ManaOnBlock * crush.ShieldAttackBlockRate, crush.ShieldAttackManaOnBlockRate, 1e-6) + assert.are.near(crush.EnergyShieldOnBlock * crush.ShieldAttackBlockRate, crush.ShieldAttackESOnBlockRate, 1e-6) + assert.are.equal(0, crush.LifeOnHit) + assert.are.equal(normal.EffectiveBlockChance, crush.EffectiveBlockChance) + assert.are.near(normal.TotalEHP, crush.TotalEHP, 1e-6) + end) + + for _, name in ipairs({ "Festering Resentment", "Svalinn" }) do + it("respects the cooldown and spell rotation of " .. name, function() + local slot + if name == "Festering Resentment" then + equipUnique("dagger", name, "Weapon 1") + equipUnique("shield", "Shattershard", "Weapon 2") + allocateReliquarianBell() + slot = "Weapon 1" + else + equipUnique("mace", "The Monastery Bell", "Weapon 1") + equipUnique("shield", name, "Weapon 2") + slot = "Weapon 2" + end + setCustomMods("Your Hits can't be Evaded\n100% increased Attack Speed") + build.skillsTab:PasteSocketGroup("Shield Charge 20/0 1\nFaster Attacks 20/0 1\n") + build.skillsTab:PasteSocketGroup("Slot: " .. slot .. "\nArc 20/0 1\n") + local oneSpell = selectSkill("Arc") + assert.True(oneSpell.ShieldAttackBlockRate > oneSpell.TriggerRateCap) + assert.are.near(oneSpell.ShieldAttackBlockRate / 2, oneSpell.SkillTriggerRate, 1e-6) + + build.skillsTab:PasteSocketGroup("Slot: " .. slot .. "\nFireball 20/0 1\n") + build.configTab.input.enemyBlockChance = 50 + build.configTab:BuildModList() + local arc = selectSkill("Arc") + local fireball = selectSkill("Fireball") + assert.are.near(oneSpell.ShieldAttackBlockRate / 2, arc.ShieldAttackBlockRate, 1e-6) + assert.are.near(arc.ShieldAttackBlockRate / 2, arc.SkillTriggerRate, 1e-6) + assert.are.near(arc.ShieldAttackBlockRate, arc.SkillTriggerRate + fireball.SkillTriggerRate, 1e-6) + end) + end + + it("uses Bell blocks for Tempest Shield and keeps its cooldown", function() + equipUnique("mace", "The Monastery Bell", "Weapon 1") + equipUnique("shield", "Aegis Aurora", "Weapon 2") + setCustomMods("Your Hits can't be Evaded") + build.skillsTab:PasteSocketGroup("Tempest Shield 20/0 1\n") + local normal = selectSkill("Tempest Shield") + build.skillsTab:PasteSocketGroup("Shield Crush 20/0 1\n") + local tempest = selectSkill("Tempest Shield") + assert.True(tempest.ShieldAttackBlockRate > normal.SkillTriggerRate) + assert.are.near(tempest.ShieldAttackBlockRate / 2, tempest.SkillTriggerRate, 1e-6) + end) + end) + it("Trigger Combust", function() build.skillsTab:PasteSocketGroup("Infernal Cry 20/0 1\n") runCallback("OnFrame") diff --git a/src/Data/ModCache.lua b/src/Data/ModCache.lua index 94ce6007e71..b862881832c 100755 --- a/src/Data/ModCache.lua +++ b/src/Data/ModCache.lua @@ -15164,7 +15164,7 @@ c["Corrupted Blood cannot be inflicted on you"]={{[1]={flags=0,keywordFlags=0,na c["Corrupted Blood cannot be inflicted on you if you have at least 5 Corrupted Blood Debuffs on you"]={nil,"Corrupted Blood cannot be inflicted on you if you have at least 5 Corrupted Blood Debuffs on you "} c["Corrupted Soul"]={{[1]={flags=0,keywordFlags=0,name="Keystone",type="LIST",value="Corrupted Soul"},[2]={flags=0,keywordFlags=0,name="Condition:HaveCorruptedSoul",type="FLAG",value=true}},nil} c["Cost every third time you Pay it"]={nil,"Cost every third time you Pay it "} -c["Count as Blocking Attack Damage from the first target Hit with each Shield Attack"]={nil,"Count as Blocking Attack Damage from the first target Hit with each Shield Attack "} +c["Count as Blocking Attack Damage from the first target Hit with each Shield Attack"]={{[1]={flags=0,keywordFlags=0,name="ShieldAttacksCountAsBlocks",type="FLAG",value=true}},nil} c["Count as having maximum number of Endurance Charges"]={{[1]={flags=0,keywordFlags=0,name="HaveMaximumEnduranceCharges",type="FLAG",value=true}},nil} c["Count as having maximum number of Endurance Charges Count as having maximum number of Frenzy Charges Count as having maximum number of Power Charges"]={nil,"Count as having maximum number of Endurance Charges Count as having maximum number of Frenzy Charges Count as having maximum number of Power Charges "} c["Count as having maximum number of Frenzy Charges"]={{[1]={flags=0,keywordFlags=0,name="HaveMaximumFrenzyCharges",type="FLAG",value=true}},nil} diff --git a/src/Modules/CalcPerform.lua b/src/Modules/CalcPerform.lua index 2aaa8459a81..d9ea64a50c9 100644 --- a/src/Modules/CalcPerform.lua +++ b/src/Modules/CalcPerform.lua @@ -3910,6 +3910,9 @@ function calcs.perform(env, skipEHP) if not calcs.mirages(env) and calcs.offence(env, env.player, env.player.mainSkill) == false then return false -- Rejected trigger-source probes are never cached end + if not skipEHP then + calcs.shieldAttackBlockRecovery(env) + end if env.minion then if modDB:Flag(nil, "MinionsGainYourSpellSuppressionChance") then diff --git a/src/Modules/CalcSections.lua b/src/Modules/CalcSections.lua index b103db1be51..8653611345c 100644 --- a/src/Modules/CalcSections.lua +++ b/src/Modules/CalcSections.lua @@ -1762,6 +1762,10 @@ return { { label = "Mana on Block", haveOutput = "ManaOnBlock", { format = "{0:output:ManaOnBlock}", { modName = "ManaOnBlock" }, }, }, { label = "ES on Block", haveOutput = "EnergyShieldOnBlock", { format = "{0:output:EnergyShieldOnBlock}", { modName = "EnergyShieldOnBlock" }, }, }, { label = "ES on Spell Block", haveOutput = "EnergyShieldOnSpellBlock", { format = "{0:output:EnergyShieldOnSpellBlock}", { modName = "EnergyShieldOnSpellBlock" }, }, }, + { label = "Monastery Bell Blocks", haveOutput = "ShieldAttackBlockRate", { format = "{2:output:ShieldAttackBlockRate}/s", { breakdown = "ShieldAttackBlockRate" }, }, }, + { label = "Life from Bell Blocks", haveOutput = "ShieldAttackLifeOnBlockRate", { format = "{1:output:ShieldAttackLifeOnBlockRate}/s", { modName = "LifeOnBlock" }, }, }, + { label = "Mana from Bell Blocks", haveOutput = "ShieldAttackManaOnBlockRate", { format = "{1:output:ShieldAttackManaOnBlockRate}/s", { modName = "ManaOnBlock" }, }, }, + { label = "ES from Bell Blocks", haveOutput = "ShieldAttackESOnBlockRate", { format = "{1:output:ShieldAttackESOnBlockRate}/s", { modName = "EnergyShieldOnBlock" }, }, }, } }, { defaultCollapsed = false, label = "Dodge", data = { extra = "{0:output:AttackDodgeChance}%/{0:output:SpellDodgeChance}%", { label = "Dodge Chance", { format = "{0:output:AttackDodgeChance}% (+{0:output:AttackDodgeChanceOverCap}%)", diff --git a/src/Modules/CalcTriggers.lua b/src/Modules/CalcTriggers.lua index 25a701c352a..7b158de6ce5 100644 --- a/src/Modules/CalcTriggers.lua +++ b/src/Modules/CalcTriggers.lua @@ -100,13 +100,101 @@ local function findTriggerSkill(env, skill, source, triggerRate, comparer, minim return source, triggerRate, source and cacheSkillUUID(source, env) end +local function getShieldAttackBlockSource(env, mainOutput) + if not env.player.modDB:Flag(nil, "ShieldAttacksCountAsBlocks") then + return + end + + local source + for _, skill in ipairs(env.player.activeSkillList) do + local flags = skill.skillFlags + -- A retaliation attack already needs a block, so it cannot sustain its own block source. + if flags.shieldAttack and not (flags.disable or flags.totem or flags.mine or flags.trap or flags.minion) + and not skill.skillTypes[SkillType.Retaliation] and not skill.skillTypes[SkillType.OtherThingUsesSkill] + and not skill.skillCfg.skillCond["usedByMirage"] and not isTriggered(skill) then + local attackOutput + if skill == env.player.mainSkill then + attackOutput = mainOutput + else + local candidate, _, uuid = findTriggerSkill(env, skill, nil, nil, nil, nil, env.triggerSourceCache) + attackOutput = candidate and GlobalCache.cachedData[env.mode][uuid] + end + if attackOutput then + -- Overlaps and repeats share a single block per skill use. + local useRate = (attackOutput.HitSpeed or attackOutput.Speed or 0) / (attackOutput.Repeats or 1) + local hitChance = attackOutput.HitChance or 0 + local rate = useRate * hitChance / 100 + if not source or rate > source.rate then + source = { skill = skill, useRate = useRate, hitChance = hitChance, rate = rate } + end + end + end + end + return source +end + +local function recordShieldAttackBlocks(env, source) + local player = env.player + local output = player.output + output.ShieldAttackBlockRate = source.rate + output.ShieldAttackLifeOnBlockRate = not player.modDB:Flag(nil, "CannotGainLife") and output.LifeOnBlock * source.rate or 0 + output.ShieldAttackManaOnBlockRate = not player.modDB:Flag(nil, "CannotGainMana") and output.ManaOnBlock * source.rate or 0 + output.ShieldAttackESOnBlockRate = not player.modDB:Flag(nil, "CannotGainEnergyShield") and output.EnergyShieldOnBlock * source.rate or 0 + if player.breakdown then + player.breakdown.ShieldAttackBlockRate = { + s_format("%.2f ^8(%s uses per second)", source.useRate, source.skill.activeEffect.grantedEffect.name), + s_format("x %.2f%% ^8(chance to hit)", source.hitChance), + s_format("= %.2f ^8(attack blocks per second from shield attacks)", source.rate), + } + end +end + +function calcs.shieldAttackBlockRecovery(env) + if env.player.output.ShieldAttackBlockRate == nil then + local source = getShieldAttackBlockSource(env, env.player.output) + if source then + recordShieldAttackBlocks(env, source) + end + end +end + +local function onBlockTrigger(env, config) + local source = getShieldAttackBlockSource(env) + env.player.mainSkill.skillFlags.globalTrigger = not source + if source then + recordShieldAttackBlocks(env, source) + config.source = source.skill + config.trigRate = source.rate + config.shieldAttackBlock = source + else + config.source = env.player.mainSkill + end + return config +end + +local function socketedSpellOnBlock(env) + local mainSkill = env.player.mainSkill + local slot = mainSkill.socketGroup.slot + local support = mainSkill.triggeredBy and mainSkill.triggeredBy.grantedEffect + return onBlockTrigger(env, { + triggeredSkillCond = function(_, skill) + return slot and skill.socketGroup and skill.socketGroup.slot == slot + and skill.triggeredBy and skill.triggeredBy.grantedEffect == support + end, + }) +end + -- Calculate the impact other skills and source rate to trigger cooldown alignment have on the trigger rate -- for more details regarding the implementation see comments of #4599 and #5428 function calcMultiSpellRotationImpact(env, skillRotation, sourceRate, triggerCD, chance, actor) + if sourceRate <= 0 then + return 0, { simTime = 0, rates = {} } + end local rotationIndex = 1 local next_trigger = 0 local triggerIncrement = 1 / sourceRate - local SIM_TIME = triggerIncrement * 1000 -- Simulate 1000 attacks + local simAttacks = 1000 + local SIM_TIME = triggerIncrement * simAttacks local chance = chance or 100 local skillCount = #skillRotation local actor = actor or env.player @@ -117,7 +205,7 @@ function calcMultiSpellRotationImpact(env, skillRotation, sourceRate, triggerCD, skill.count = 0 end - while next_trigger < SIM_TIME do + for _ = 1, simAttacks do local currentIndex = rotationIndex repeat if skillRotation[currentIndex].next_trig <= next_trigger then -- Skill at current index off cooldown, Trigger it. @@ -413,6 +501,7 @@ local function defaultTriggerHandler(env, config) local source = config.source local triggeredSkills = config.triggeredSkills or {} local trigRate = config.trigRate + local shieldAttackBlock = config.shieldAttackBlock local uuid local sourceWeapon = config.sourceWeapon -- Only attacks using the granting weapon can activate source-weapon triggers @@ -450,7 +539,10 @@ local function defaultTriggerHandler(env, config) } elseif breakdown then breakdown.EffectiveSourceRate = {} - if trigRate and source then + if shieldAttackBlock then + t_insert(breakdown.EffectiveSourceRate, s_format("%.2f ^8(%s uses per second for The Monastery Bell)", shieldAttackBlock.useRate, source.activeEffect.grantedEffect.name)) + t_insert(breakdown.EffectiveSourceRate, s_format("x %.2f%% ^8(chance to hit)", shieldAttackBlock.hitChance)) + elseif trigRate and source then if config.assumingEveryHitKills then t_insert(breakdown.EffectiveSourceRate, "Assuming every attack kills") end @@ -461,7 +553,7 @@ local function defaultTriggerHandler(env, config) -- Dual wield triggers local sourceWeaponTrigger = sourceWeapon and source and source.skillFlags.bothWeaponAttack local itemSupportTrigger = actor.mainSkill.triggeredBy and actor.mainSkill.triggeredBy.grantedEffect.support and actor.mainSkill.triggeredBy.grantedEffect.fromItem - if trigRate and source and env.player.weaponData1.type and env.player.weaponData2.type and not source.skillData.doubleHitsWhenDualWielding and (source.skillTypes[SkillType.Melee] or source.skillTypes[SkillType.Attack]) and (sourceWeaponTrigger or itemSupportTrigger) then + if not shieldAttackBlock and trigRate and source and env.player.weaponData1.type and env.player.weaponData2.type and not source.skillData.doubleHitsWhenDualWielding and (source.skillTypes[SkillType.Melee] or source.skillTypes[SkillType.Attack]) and (sourceWeaponTrigger or itemSupportTrigger) then trigRate = trigRate / 2 if breakdown then t_insert(breakdown.EffectiveSourceRate, 2, s_format("/ 2 ^8(due to dual wielding)")) @@ -708,7 +800,7 @@ local function defaultTriggerHandler(env, config) t_insert(breakdown.TriggerRateCap, "") if not (triggeredCD or triggerCD or cooldownOverride) then - t_insert(breakdown.TriggerRateCap, "Assuming cast on every kill/attack/hit") + t_insert(breakdown.TriggerRateCap, shieldAttackBlock and "One block per shield skill use that hits" or "Assuming cast on every kill/attack/hit") else t_insert(breakdown.TriggerRateCap, "Trigger rate:") t_insert(breakdown.TriggerRateCap, s_format("1 / %.3f", actionCooldownTickRounded)) @@ -748,7 +840,7 @@ local function defaultTriggerHandler(env, config) local triggerChanceBreakdown = {} --Accuracy and crit chance - if source and (source.skillTypes[SkillType.Melee] or source.skillTypes[SkillType.Attack]) and GlobalCache.cachedData[env.mode][uuid] and not config.triggerOnUse then + if not shieldAttackBlock and source and (source.skillTypes[SkillType.Melee] or source.skillTypes[SkillType.Attack]) and GlobalCache.cachedData[env.mode][uuid] and not config.triggerOnUse then local sourceHitChance = GlobalCache.cachedData[env.mode][uuid].HitChance or 0 if sourceHitChance ~= 100 then @@ -826,6 +918,9 @@ local function defaultTriggerHandler(env, config) output.SkillTriggerRate = output.EffectiveSourceRate else -- Triggers like Cast on Crit go through simulation to calculate the trigger rate of each skill in the trigger group output.SkillTriggerRate, simBreakdown = calcMultiSpellRotationImpact(env, config.triggeredSkillCond and triggeredSkills or {packageSkillDataForSimulation(actor.mainSkill, env)}, output.EffectiveSourceRate, (not actor.mainSkill.skillData.triggeredByBrand and ( triggerCD or triggeredCD ) or 0), triggerChance, actor) + if shieldAttackBlock then + output.SkillTriggerRate = m_min(output.SkillTriggerRate, output.TriggerRateCap) + end local triggerBotsEffective = actor.modDB:Flag(nil, "HaveTriggerBots") and actor.mainSkill.skillTypes[SkillType.Spell] if triggerBotsEffective then output.SkillTriggerRate = 2 * output.SkillTriggerRate @@ -1316,11 +1411,13 @@ local configTable = { end} end, ["tempest shield"] = function(env) - env.player.mainSkill.skillFlags.globalTrigger = true - return {source = env.player.mainSkill} + return onBlockTrigger(env, {}) end, ["shattershard"] = function(env) - env.player.mainSkill.skillFlags.globalTrigger = true + local config = onBlockTrigger(env, {}) + if config.shieldAttackBlock then + return config + end local uuid = cacheSkillUUID(env.player.mainSkill, env) if not GlobalCache.cachedData[env.mode][uuid] or env.mode == "CALCULATOR" then calcs.buildActiveSkill(env, env.mode, env.player.mainSkill, uuid, {uuid}) @@ -1333,7 +1430,7 @@ local configTable = { s_format("= %.2f ^8per second", env.player.mainSkill.skillData.triggerRateCapOverride), } end - return {source = env.player.mainSkill} + return config end, ["battlemage's cry"] = function(env) if env.player.mainSkill.activeEffect.grantedEffect.name ~= "Battlemage's Cry" then @@ -1523,20 +1620,8 @@ local configTable = { useCastRate = true} end end, - ["svalinn cast on block"] = function(env) -- Svalinn Girded Tower Shield - env.player.mainSkill.skillFlags.globalTrigger = true - return {source = env.player.mainSkill, - triggeredSkillCond = function(env, skill) - return slotMatch(env, skill) and skill.triggeredBy and calcLib.canGrantedEffectSupportActiveSkill(skill.triggeredBy.grantedEffect, skill) - end} - end, - ["festering resentment cast on block"] = function(env) -- Festering Resentment Demon Dagger - env.player.mainSkill.skillFlags.globalTrigger = true - return {source = env.player.mainSkill, - triggeredSkillCond = function(env, skill) - return slotMatch(env, skill) and skill.triggeredBy and calcLib.canGrantedEffectSupportActiveSkill(skill.triggeredBy.grantedEffect, skill) - end} - end, + ["svalinn cast on block"] = socketedSpellOnBlock, + ["festering resentment cast on block"] = socketedSpellOnBlock, ["hex on trap"] = function(env) -- Hand of the Lords Carnal Mitts return {triggerSkillCond = function(env, skill) -- Hex is triggered only when a trap is triggered diff --git a/src/Modules/Common.lua b/src/Modules/Common.lua index e8c7dfd03fb..85f434f9df8 100644 --- a/src/Modules/Common.lua +++ b/src/Modules/Common.lua @@ -927,6 +927,7 @@ function cacheData(uuid, env) Name = env.player.mainSkill.activeEffect.grantedEffect.name, Speed = env.player.output.Speed, HitSpeed = env.player.output.HitSpeed, + Repeats = env.player.output.Repeats, ManaCost = env.player.output.ManaCost, LifeCost = env.player.output.LifeCost, ESCost = env.player.output.ESCost, diff --git a/src/Modules/ModParser.lua b/src/Modules/ModParser.lua index a7f29d28835..0ef430d6329 100644 --- a/src/Modules/ModParser.lua +++ b/src/Modules/ModParser.lua @@ -4237,6 +4237,7 @@ local specialModList = { ["y?o?u?r? ?chance to block attack damage is lucky"] = { flag("BlockChanceIsLucky"), flag("ProjectileBlockChanceIsLucky") }, ["y?o?u?r? ?chance to block attack damage is unlucky"] = { flag("BlockChanceIsUnlucky"), flag("ProjectileBlockChanceIsUnlucky") }, ["y?o?u?r? ?chance to block is unlucky"] = { flag("BlockChanceIsUnlucky"), flag("ProjectileBlockChanceIsUnlucky"), flag("SpellBlockChanceIsUnlucky"), flag("SpellProjectileBlockChanceIsUnlucky") }, + ["count as blocking attack damage from the first target hit with each shield attack"] = { flag("ShieldAttacksCountAsBlocks") }, ["y?o?u?r? ?chance to block spell damage is lucky"] = { flag("SpellBlockChanceIsLucky"), flag("SpellProjectileBlockChanceIsLucky") }, ["y?o?u?r? ?chance to block spell damage is unlucky"] = { flag("SpellBlockChanceIsUnlucky"), flag("SpellProjectileBlockChanceIsUnlucky") }, ["your lucky or unlucky effects use the best or worst from three rolls instead of two"] = { flag("ExtremeLuck")}, From be05644f7bc2f6bda43b6f89ce2d790dd122a73b Mon Sep 17 00:00:00 2001 From: David Medgyesy Date: Thu, 26 Nov 2026 20:30:27 +0100 Subject: [PATCH 2/4] Correct Bell trigger timing, shared cooldowns and incoming blocks --- spec/System/TestTriggers_spec.lua | 113 +++++++++++++--- src/Modules/CalcDefence.lua | 9 +- src/Modules/CalcTriggers.lua | 207 +++++++++++++++++++++++++----- 3 files changed, 276 insertions(+), 53 deletions(-) diff --git a/spec/System/TestTriggers_spec.lua b/spec/System/TestTriggers_spec.lua index 740fb7c05e0..a3e4df46d0f 100644 --- a/spec/System/TestTriggers_spec.lua +++ b/spec/System/TestTriggers_spec.lua @@ -1267,6 +1267,12 @@ describe("TestTriggers", function() end) describe("The Monastery Bell", function() + before_each(function() + -- Isolate player-generated blocks unless the case specifies an attacking enemy. + build.configTab.input.enemySpeed = 0 + build.configTab:BuildModList() + end) + local function equipUnique(category, name, slot) local items = data.uniques[category] local index = isValueInArrayPred(items, function(raw) return raw:sub(1, #name + 1) == name .. "\n" end) @@ -1288,17 +1294,21 @@ describe("TestTriggers", function() runCallback("OnFrame") end - local function selectSkill(name) + local function selectSkill(name, occurrence) + local matches = 0 runCallback("OnFrame") for groupIndex, group in ipairs(build.skillsTab.socketGroupList) do for skillIndex, skill in ipairs(group.displaySkillList or {}) do if skill.activeEffect.grantedEffect.name == name then - build.mainSocketGroup = groupIndex - group.mainActiveSkill = skillIndex - build.buildFlag = true - runCallback("OnFrame") - assert.are.equal(name, build.calcsTab.mainEnv.player.mainSkill.activeEffect.grantedEffect.name) - return build.calcsTab.mainOutput, group + matches = matches + 1 + if matches == (occurrence or 1) then + build.mainSocketGroup = groupIndex + group.mainActiveSkill = skillIndex + build.buildFlag = true + runCallback("OnFrame") + assert.are.equal(name, build.calcsTab.mainEnv.player.mainSkill.activeEffect.grantedEffect.name) + return build.calcsTab.mainOutput, group + end end end end @@ -1341,7 +1351,13 @@ describe("TestTriggers", function() build.skillsTab:PasteSocketGroup("Smite 20/0 1\n") local fallback = selectSkill("Shield Shatter") assert.is_nil(fallback.ShieldAttackBlockRate) - assert.are.near(1 / fallback.Duration, fallback.SkillTriggerRate, 1e-6) + assert.are.equal(0, fallback.SkillTriggerRate) + build.configTab.input.enemySpeed = 700 + build.configTab:BuildModList() + build.buildFlag = true + local incoming = selectSkill("Shield Shatter") + assert.True(incoming.SkillTriggerRate > 0) + assert.True(incoming.SkillTriggerRate <= 1 / incoming.Duration) end) it("reports recovery from Bell blocks once per use of a repeating shield attack", function() @@ -1399,16 +1415,81 @@ describe("TestTriggers", function() end) end - it("uses Bell blocks for Tempest Shield and keeps its cooldown", function() + it("counts shield throws independently of the displayed Trarthus skill part", function() equipUnique("mace", "The Monastery Bell", "Weapon 1") - equipUnique("shield", "Aegis Aurora", "Weapon 2") - setCustomMods("Your Hits can't be Evaded") + equipUnique("shield", "Shattershard", "Weapon 2") + setCustomMods("Your Hits can't be Evaded\n100% increased Attack Speed") + local name = "Spectral Shield Throw of Trarthus" + build.skillsTab:PasteSocketGroup(name .. " 20/0 1\n") + local shield, group = selectSkill(name) + group.gemList[1].skillPart = 2 + build.buildFlag = true + local shards = selectSkill(name) + assert.True(shards.HitSpeed ~= shield.Speed) + assert.are.near(shield.Speed, shards.ShieldAttackBlockRate, 1e-6) + assert.are.near(shield.Speed, selectSkill("Shield Shatter").SkillTriggerRate, 1e-6) + -- Repeated Bell hits keep the Shatter buff active and prevent ordinary blocks. + build.configTab.input.enemySpeed = 700 + build.configTab:BuildModList() + build.buildFlag = true + assert.are.near(shield.Speed, selectSkill("Shield Shatter").SkillTriggerRate, 1e-6) + end) + + it("keeps misses on the attack timeline and shares Arc's cooldown across socket groups", function() + equipUnique("mace", "The Monastery Bell", "Weapon 1") + equipUnique("shield", "Svalinn", "Weapon 2") + setCustomMods("Your Hits can't be Evaded\n300% increased Attack Speed") + build.skillsTab:PasteSocketGroup("Shield Charge 20/0 1\n") + build.skillsTab:PasteSocketGroup("Slot: Weapon 2\nArc 20/0 1\n") + local function arcRate(enemyBlock) + build.configTab.input.enemyBlockChance = enemyBlock + build.configTab:BuildModList() + build.buildFlag = true + return selectSkill("Arc").SkillTriggerRate + end + local half = arcRate(50) + local fewerHits = arcRate(53) + assert.True(half > fewerHits and fewerHits > 0) + local single = arcRate(0) + build.skillsTab:PasteSocketGroup("Slot: Weapon 2\nArc 20/0 1\n") + local first = selectSkill("Arc") + local second = selectSkill("Arc", 2) + assert.True(first.SkillTriggerRate > 0 and second.SkillTriggerRate > 0) + assert.are.near(single, first.SkillTriggerRate + second.SkillTriggerRate, 1e-6) + assert.True(single <= first.TriggerRateCap) + end) + + it("adds incoming blocks to Tempest Shield discharges independently of its activation cooldown", function() + equipUnique("mace", "The Monastery Bell", "Weapon 1") + equipUnique("shield", "Svalinn", "Weapon 2") + setCustomMods("Your Hits can't be Evaded\n300% increased Attack Speed") build.skillsTab:PasteSocketGroup("Tempest Shield 20/0 1\n") - local normal = selectSkill("Tempest Shield") - build.skillsTab:PasteSocketGroup("Shield Crush 20/0 1\n") - local tempest = selectSkill("Tempest Shield") - assert.True(tempest.ShieldAttackBlockRate > normal.SkillTriggerRate) - assert.are.near(tempest.ShieldAttackBlockRate / 2, tempest.SkillTriggerRate, 1e-6) + build.skillsTab:PasteSocketGroup("Shield Charge 20/0 1\n") + build.skillsTab:PasteSocketGroup("Slot: Weapon 2\nArc 20/0 1\n") + local bell = selectSkill("Tempest Shield") + assert.True(bell.ShieldAttackBlockRate > 5) + assert.are.near(bell.ShieldAttackBlockRate, bell.SkillTriggerRate, 1e-6) + assert.are.near(bell.SkillTriggerRate, bell.Speed, 1e-6) + + build.configTab.input.enemySpeed = 1000 + build.configTab.input.enemyDamageType = "Spell" + build.configTab:BuildModList() + build.buildFlag = true + local mixed = selectSkill("Tempest Shield") + local incoming = mixed.EffectiveSpellBlockChance / 100 + assert.True(incoming > 0) + assert.are.near(bell.SkillTriggerRate + incoming, mixed.SkillTriggerRate, 1e-6) + build.configTab.input.enemyBlockChance = 100 + build.configTab:BuildModList() + build.buildFlag = true + local blocked = selectSkill("Tempest Shield") + assert.are.equal(0, blocked.ShieldAttackBlockRate) + assert.are.near(incoming, blocked.SkillTriggerRate, 1e-6) + assert.are.near(incoming, selectSkill("Arc").SkillTriggerRate, 1e-6) + build.configTab.input.enemyDamageType = "DamageOverTime" + build.configTab:BuildModList() + build.buildFlag = true + assert.are.equal(0, selectSkill("Tempest Shield").SkillTriggerRate) end) end) diff --git a/src/Modules/CalcDefence.lua b/src/Modules/CalcDefence.lua index c8ab58c6ed6..63c449c72eb 100644 --- a/src/Modules/CalcDefence.lua +++ b/src/Modules/CalcDefence.lua @@ -1698,6 +1698,11 @@ function calcs.defence(env, actor) end end +function calcs.enemySkillTime(env, actor) + local baseTime = (env.configInput.enemySpeed or env.configPlaceholder.enemySpeed or 700) / 1000 + return baseTime / (1 + actor.enemy.modDB:Sum("INC", nil, "Speed") / 100) / calcs.actionSpeedMod(actor.enemy) +end + -- Performs all extra defensive calculations ( eg EHP, maxHit ) function calcs.buildDefenceEstimations(env, actor) local modDB = actor.modDB @@ -2990,9 +2995,7 @@ function calcs.buildDefenceEstimations(env, actor) -- survival time do - output.enemySkillTime = (env.configInput.enemySpeed or env.configPlaceholder.enemySpeed or 700) / (1 + enemyDB:Sum("INC", nil, "Speed") / 100) - local enemyActionSpeed = calcs.actionSpeedMod(actor.enemy) - output.enemySkillTime = output.enemySkillTime / 1000 / enemyActionSpeed + output.enemySkillTime = calcs.enemySkillTime(env, actor) output["EHPSurvivalTime"] = output["TotalNumberOfHits"] * output.enemySkillTime if breakdown then breakdown["EHPSurvivalTime"] = { diff --git a/src/Modules/CalcTriggers.lua b/src/Modules/CalcTriggers.lua index 7b158de6ce5..820604a7368 100644 --- a/src/Modules/CalcTriggers.lua +++ b/src/Modules/CalcTriggers.lua @@ -121,7 +121,7 @@ local function getShieldAttackBlockSource(env, mainOutput) end if attackOutput then -- Overlaps and repeats share a single block per skill use. - local useRate = (attackOutput.HitSpeed or attackOutput.Speed or 0) / (attackOutput.Repeats or 1) + local useRate = (attackOutput.Speed or 0) / (attackOutput.Repeats or 1) local hitChance = attackOutput.HitChance or 0 local rate = useRate * hitChance / 100 if not source or rate > source.rate then @@ -158,16 +158,64 @@ function calcs.shieldAttackBlockRecovery(env) end end +local function shatterDuration(env, skill) + local uuid = cacheSkillUUID(skill, env) + if not GlobalCache.cachedData[env.mode][uuid] or env.mode == "CALCULATOR" then + calcs.buildActiveSkill(env, env.mode, skill, uuid, {uuid}) + end + return GlobalCache.cachedData[env.mode][uuid].Env.player.output.Duration +end + +local function incomingBlockRate(env, source) + local player = env.player + local category = env.configInput.enemyDamageType or "Average" + local interval = calcs.enemySkillTime(env, player) + if not (interval > 0 and interval < m_huge) or category == "DamageOverTime" or player.enemy.modDB:Flag(nil, "CannotBeBlocked") then + return 0 + end + local output = player.output + local attack = 1 - output.EffectiveAttackDodgeChance / 100 + local spell = 1 - output.EffectiveSpellDodgeChance / 100 + local chances = { + Melee = attack * (1 - output.MeleeEvadeChance / 100) * output.EffectiveBlockChance, + Projectile = attack * (1 - output.ProjectileEvadeChance / 100) * output.EffectiveProjectileBlockChance, + Spell = spell * output.EffectiveSpellBlockChance, + SpellProjectile = spell * output.EffectiveSpellProjectileBlockChance, + Untyped = output.EffectiveBlockChance, + } + local chance = chances[category] or (chances.Melee + chances.Projectile + chances.Spell + chances.SpellProjectile) / 4 + local rate = chance / 100 / interval + if rate > 0 then + for _, skill in ipairs(player.activeSkillList) do + if skill.activeEffect.grantedEffect.id == "ShieldShatter" and not skill.skillFlags.disable then + local duration = shatterDuration(env, skill) + -- An ordinary block starts a block lockout. A Bell hit can refresh it at any time. + -- Estimate the fraction of time with no Bell hit in the preceding buff duration. + local uses = duration * source.useRate + local whole = m_floor(uses) + local hit = source.hitChance / 100 + local available = (1 - hit) ^ whole * (1 - (uses - whole) * hit) + return available / (1 / rate + duration) + end + end + end + return rate +end + local function onBlockTrigger(env, config) - local source = getShieldAttackBlockSource(env) - env.player.mainSkill.skillFlags.globalTrigger = not source - if source then - recordShieldAttackBlocks(env, source) - config.source = source.skill - config.trigRate = source.rate - config.shieldAttackBlock = source - else - config.source = env.player.mainSkill + local player = env.player + config.source = player.mainSkill + player.mainSkill.skillFlags.globalTrigger = true + if player.modDB:Flag(nil, "ShieldAttacksCountAsBlocks") then + local source = getShieldAttackBlockSource(env) + if source then + recordShieldAttackBlocks(env, source) + config.source = source.skill + end + config.shieldAttackBlock = source or { useRate = 0, hitChance = 0, rate = 0 } + config.incomingBlockRate = incomingBlockRate(env, config.shieldAttackBlock) + config.trigRate = config.shieldAttackBlock.rate + config.incomingBlockRate + player.mainSkill.skillFlags.globalTrigger = false end return config end @@ -177,6 +225,7 @@ local function socketedSpellOnBlock(env) local slot = mainSkill.socketGroup.slot local support = mainSkill.triggeredBy and mainSkill.triggeredBy.grantedEffect return onBlockTrigger(env, { + shareSpellCooldowns = true, triggeredSkillCond = function(_, skill) return slot and skill.socketGroup and skill.socketGroup.slot == slot and skill.triggeredBy and skill.triggeredBy.grantedEffect == support @@ -184,49 +233,118 @@ local function socketedSpellOnBlock(env) }) end +-- Reuse the same hit rolls at the same attack times for every build comparison. +-- Shuffled ranks give an exact hit count for whole percentages across 4000 uses. +local blockSamples = 4000 +local hitRanks = {} +do + local seed = 1 + for i = 1, blockSamples do + seed = seed * 48271 % 2147483647 + local j = 1 + seed % i + hitRanks[i] = hitRanks[j] + hitRanks[j] = i + end +end + +local function blockEvents(source, incomingRate) + local useRate = source.rate > 0 and source.useRate or 0 + local duration = blockSamples / m_max(useRate, incomingRate) + local hitThreshold = m_floor(blockSamples * source.hitChance / 100 + 0.5) + local attackIndex = 0 + local function nextHit() + while attackIndex < blockSamples and useRate > 0 and hitThreshold > 0 do + attackIndex = attackIndex + 1 + if hitRanks[attackIndex] <= hitThreshold then + return (attackIndex - 1) / useRate + end + end + return m_huge + end + local nextAttack = nextHit() + local interval = incomingRate > 0 and 1 / incomingRate or m_huge + local nextIncoming = interval / 2 + return function() + local time = m_min(nextAttack, nextIncoming) + if time >= duration then + return + elseif nextIncoming < nextAttack then + nextIncoming = nextIncoming + interval + else + nextAttack = nextHit() + end + return time + end, duration +end + -- Calculate the impact other skills and source rate to trigger cooldown alignment have on the trigger rate -- for more details regarding the implementation see comments of #4599 and #5428 -function calcMultiSpellRotationImpact(env, skillRotation, sourceRate, triggerCD, chance, actor) +function calcMultiSpellRotationImpact(env, skillRotation, sourceRate, triggerCD, chance, actor, blockSource, incomingRate) if sourceRate <= 0 then return 0, { simTime = 0, rates = {} } end local rotationIndex = 1 - local next_trigger = 0 local triggerIncrement = 1 / sourceRate local simAttacks = 1000 - local SIM_TIME = triggerIncrement * simAttacks + local simTime = triggerIncrement * simAttacks + local nextBlock + if blockSource then + nextBlock, simTime = blockEvents(blockSource, incomingRate) + -- Both streams have at most blockSamples events within the window. + simAttacks = 2 * blockSamples + end + local next_trigger = 0 local chance = chance or 100 local skillCount = #skillRotation local actor = actor or env.player + local cooldowns = {} for _, skill in ipairs(skillRotation) do skill.cd = m_max(skill.cdOverride or ( ((skill.cd or 0) + (skill.addedCooldown or 0)) / (skill.icdr or 1)), ( (triggerCD or 0) + (skill.addsCastTime or 0) ) / (skill.icdr or 1)) - skill.next_trig = 0 + cooldowns[skill.cooldownGroup or skill] = 0 skill.count = 0 end + if blockSource and skillCount == 1 and skillRotation[1].cd == 0 then + local rate = sourceRate * chance / 100 + return rate, { simTime = 0, rates = { { name = skillRotation[1].uuid, rate = rate } } } + end + for _ = 1, simAttacks do + if nextBlock then + next_trigger = nextBlock() + if not next_trigger then + break + end + end local currentIndex = rotationIndex repeat - if skillRotation[currentIndex].next_trig <= next_trigger then -- Skill at current index off cooldown, Trigger it. - skillRotation[currentIndex].count = skillRotation[currentIndex].count + 1 + local skill = skillRotation[currentIndex] + local cooldownGroup = skill.cooldownGroup or skill + if cooldowns[cooldownGroup] <= next_trigger then -- Skill at current index off cooldown, Trigger it. + skill.count = skill.count + 1 -- Cooldown starts at the beginning of current tick and ends at the next tick after cooldown expiration - skillRotation[currentIndex].next_trig = ceil_b(floor_b(next_trigger, data.misc.ServerTickTime) + skillRotation[currentIndex].cd, data.misc.ServerTickTime) + cooldowns[cooldownGroup] = ceil_b(floor_b(next_trigger, data.misc.ServerTickTime) + skill.cd, data.misc.ServerTickTime) + if nextBlock then + rotationIndex = currentIndex % skillCount + 1 + end break end currentIndex = (currentIndex % skillCount) + 1 -- Current skill on cooldown, try the next one. until(currentIndex == rotationIndex) -- All skills checked, trigger wasted - rotationIndex = (rotationIndex % skillCount) + 1 -- Move on to the next skill in rotation - next_trigger = next_trigger + triggerIncrement + if not nextBlock then + rotationIndex = rotationIndex % skillCount + 1 + next_trigger = next_trigger + triggerIncrement + end end - local trigRateTable = { simTime = SIM_TIME, rates = {}, } + local trigRateTable = { simTime = simTime, rates = {}, } local mainRate = 0 for _, sd in ipairs(skillRotation) do -- Account for trigger chance. Adds the expected value of a geometric distribution where p = chance multiplied by triggerIncrement -- This allows for O(1) estimation of trigger chance impact on trigger rate as number of triggers approaches infinity -- Credit to Logik and Quickstick. More info in prs linked here: https://github.com/PathOfBuildingCommunity/PathOfBuilding/pull/7244 and on discord. - t_insert(trigRateTable.rates, { name = sd.uuid, rate = 1 / (SIM_TIME / sd.count + (triggerIncrement / chance * 100) - triggerIncrement) }) + t_insert(trigRateTable.rates, { name = sd.uuid, rate = 1 / (simTime / sd.count + (triggerIncrement / chance * 100) - triggerIncrement) }) if cacheSkillUUID(actor.mainSkill, env) == sd.uuid then mainRate = trigRateTable.rates[#trigRateTable.rates].rate end @@ -515,7 +633,12 @@ local function defaultTriggerHandler(env, config) source, trigRate, uuid = findTriggerSkill(env, skill, source, trigRate, config.comparer, config.minimumCostPerUse, sourceCache) end if config.triggeredSkillCond and config.triggeredSkillCond(env,skill) then - t_insert(triggeredSkills, packageSkillDataForSimulation(skill, env)) + local spell = packageSkillDataForSimulation(skill, env) + if config.shareSpellCooldowns then + local gem = skill.activeEffect.gemData + spell.cooldownGroup = gem and gem.grantedEffect == skill.activeEffect.grantedEffect and gem.gameId or skill.activeEffect.grantedEffect.id + end + t_insert(triggeredSkills, spell) end end end @@ -540,8 +663,11 @@ local function defaultTriggerHandler(env, config) elseif breakdown then breakdown.EffectiveSourceRate = {} if shieldAttackBlock then - t_insert(breakdown.EffectiveSourceRate, s_format("%.2f ^8(%s uses per second for The Monastery Bell)", shieldAttackBlock.useRate, source.activeEffect.grantedEffect.name)) - t_insert(breakdown.EffectiveSourceRate, s_format("x %.2f%% ^8(chance to hit)", shieldAttackBlock.hitChance)) + if shieldAttackBlock.skill then + t_insert(breakdown.EffectiveSourceRate, s_format("%.2f ^8(%s uses per second)", shieldAttackBlock.useRate, source.activeEffect.grantedEffect.name)) + t_insert(breakdown.EffectiveSourceRate, s_format("x %.2f%% ^8(chance to hit)", shieldAttackBlock.hitChance)) + end + t_insert(breakdown.EffectiveSourceRate, s_format("+ %.2f ^8(estimated blocks per second from the configured enemy)", config.incomingBlockRate)) elseif trigRate and source then if config.assumingEveryHitKills then t_insert(breakdown.EffectiveSourceRate, "Assuming every attack kills") @@ -673,6 +799,10 @@ local function defaultTriggerHandler(env, config) local triggerCD = actor.mainSkill.triggeredBy and env.player.mainSkill.triggeredBy.grantedEffect.levels[env.player.mainSkill.triggeredBy.level].cooldown triggerCD = triggerCD or source.triggeredBy and source.triggeredBy.grantedEffect.levels[source.triggeredBy.level].cooldown local triggeredCD = actor.mainSkill.skillData.cooldown + if config.blockDischarge then + -- The reservation skill's cooldown applies when activating the buff. + triggeredCD = nil + end if actor.mainSkill.skillData.triggeredByBrand then triggerCD = actor.mainSkill.triggeredBy.mainSkill.skillData.repeatFrequency / actor.mainSkill.triggeredBy.activationFreqMore / actor.mainSkill.triggeredBy.activationFreqInc @@ -900,7 +1030,12 @@ local function defaultTriggerHandler(env, config) end -- If the current triggered skill ignores tick rate and is the only triggered skill by this trigger use charge based calcs - if actor.mainSkill.skillData.ignoresTickRate and ( not config.triggeredSkillCond or (triggeredSkills and #triggeredSkills == 1 and triggeredSkills[1] == packageSkillDataForSimulation(actor.mainSkill, env)) ) then + if config.blockDischarge then + output.SkillTriggerRate = output.EffectiveSourceRate + if breakdown then + breakdown.SkillTriggerRate = { s_format("%.2f ^8(discharges per second, one per block)", output.SkillTriggerRate) } + end + elseif actor.mainSkill.skillData.ignoresTickRate and ( not config.triggeredSkillCond or (triggeredSkills and #triggeredSkills == 1 and triggeredSkills[1] == packageSkillDataForSimulation(actor.mainSkill, env)) ) then local overlaps = config.stagesAreOverlaps and env.player.mainSkill.skillPart == config.stagesAreOverlaps and env.player.mainSkill.activeEffect.srcInstance.skillStageCount or config.overlaps output.SkillTriggerRate = m_min(output.TriggerRateCap, output.EffectiveSourceRate * (overlaps or 1)) if breakdown then @@ -917,7 +1052,10 @@ local function defaultTriggerHandler(env, config) elseif actor.mainSkill.skillFlags.globalTrigger and not config.triggeredSkillCond then -- Trigger does not use source rate breakpoints for one reason or another output.SkillTriggerRate = output.EffectiveSourceRate else -- Triggers like Cast on Crit go through simulation to calculate the trigger rate of each skill in the trigger group - output.SkillTriggerRate, simBreakdown = calcMultiSpellRotationImpact(env, config.triggeredSkillCond and triggeredSkills or {packageSkillDataForSimulation(actor.mainSkill, env)}, output.EffectiveSourceRate, (not actor.mainSkill.skillData.triggeredByBrand and ( triggerCD or triggeredCD ) or 0), triggerChance, actor) + local simBreakdown + local rotation = config.triggeredSkillCond and triggeredSkills or { packageSkillDataForSimulation(actor.mainSkill, env) } + local cooldown = not actor.mainSkill.skillData.triggeredByBrand and (triggerCD or triggeredCD) or 0 + output.SkillTriggerRate, simBreakdown = calcMultiSpellRotationImpact(env, rotation, output.EffectiveSourceRate, cooldown, triggerChance, actor, shieldAttackBlock, config.incomingBlockRate) if shieldAttackBlock then output.SkillTriggerRate = m_min(output.SkillTriggerRate, output.TriggerRateCap) end @@ -976,7 +1114,9 @@ local function defaultTriggerHandler(env, config) } t_insert(breakdown.SimData.rowList, row) end - t_insert(breakdown.SimData, s_format("Simulation duration: %.2f ^8(In game source skill usage duration in seconds)", simBreakdown.simTime, simBreakdown.simTime)) + if simBreakdown.simTime > 0 then + t_insert(breakdown.SimData, s_format("Simulation duration: %.2f ^8(In game source skill usage duration in seconds)", simBreakdown.simTime)) + end end end else @@ -1411,22 +1551,21 @@ local configTable = { end} end, ["tempest shield"] = function(env) - return onBlockTrigger(env, {}) + local config = onBlockTrigger(env, {}) + config.blockDischarge = config.shieldAttackBlock ~= nil + return config end, ["shattershard"] = function(env) local config = onBlockTrigger(env, {}) if config.shieldAttackBlock then return config end - local uuid = cacheSkillUUID(env.player.mainSkill, env) - if not GlobalCache.cachedData[env.mode][uuid] or env.mode == "CALCULATOR" then - calcs.buildActiveSkill(env, env.mode, env.player.mainSkill, uuid, {uuid}) - end - env.player.mainSkill.skillData.triggerRateCapOverride = 1 / GlobalCache.cachedData[env.mode][uuid].Env.player.output.Duration + local duration = shatterDuration(env, env.player.mainSkill) + env.player.mainSkill.skillData.triggerRateCapOverride = 1 / duration if env.player.breakdown then env.player.breakdown.SkillTriggerRate = { s_format("Shattershard uses duration as pseudo cooldown"), - s_format("1 / %.2f ^8(Shattershard duration)", GlobalCache.cachedData[env.mode][uuid].Env.player.output.Duration), + s_format("1 / %.2f ^8(Shattershard duration)", duration), s_format("= %.2f ^8per second", env.player.mainSkill.skillData.triggerRateCapOverride), } end From 98ac9f8a82b6621bcf3830d4a25c99669a6f32a8 Mon Sep 17 00:00:00 2001 From: David Medgyesy Date: Fri, 27 Nov 2026 10:51:27 +0100 Subject: [PATCH 3/4] Use shield attacks as the trigger source for Bell blocks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Builds without The Monastery Bell, and builds that have it without a shield attack to block with, calculate as they do on dev again. With a blocking shield attack the on-block triggers use the existing trigger handling, with that attack as the source and its chance to hit as the chance to trigger. This replaces the separate block simulation, the estimate of incoming blocks and the shared spell cooldowns, and drops the display-only recovery rows in Calcs. Co-authored-by: Jan Šťastný <36244281+ShadowTrolll@users.noreply.github.com> --- spec/System/TestTriggers_spec.lua | 315 ++++++++++++++-------------- src/Modules/CalcDefence.lua | 9 +- src/Modules/CalcPerform.lua | 3 - src/Modules/CalcSections.lua | 4 - src/Modules/CalcTriggers.lua | 329 +++++++----------------------- src/Modules/Common.lua | 1 - 6 files changed, 244 insertions(+), 417 deletions(-) diff --git a/spec/System/TestTriggers_spec.lua b/spec/System/TestTriggers_spec.lua index a3e4df46d0f..dc6b3d1231a 100644 --- a/spec/System/TestTriggers_spec.lua +++ b/spec/System/TestTriggers_spec.lua @@ -1267,12 +1267,6 @@ describe("TestTriggers", function() end) describe("The Monastery Bell", function() - before_each(function() - -- Isolate player-generated blocks unless the case specifies an attacking enemy. - build.configTab.input.enemySpeed = 0 - build.configTab:BuildModList() - end) - local function equipUnique(category, name, slot) local items = data.uniques[category] local index = isValueInArrayPred(items, function(raw) return raw:sub(1, #name + 1) == name .. "\n" end) @@ -1284,12 +1278,19 @@ describe("TestTriggers", function() runCallback("OnFrame") end - local function allocateReliquarianBell() + local bellNodeId = 26055 + local function selectReliquarian() local spec = build.spec spec:SelectClass(spec.tree.classNameMap.Scion) spec:SelectAscendClass(spec.tree.ascendNameMap.Reliquarian.ascendClassId) - spec:AllocNode(spec.nodes[26055]) - assert.is_not_nil(spec.allocNodes[26055]) + assert.are.equal("The Monastery Bell", spec.nodes[bellNodeId].dn) + build.buildFlag = true + runCallback("OnFrame") + end + + local function allocateBellNode() + build.spec:AllocNode(build.spec.nodes[bellNodeId]) + assert.is_not_nil(build.spec.allocNodes[bellNodeId]) build.buildFlag = true runCallback("OnFrame") end @@ -1298,7 +1299,8 @@ describe("TestTriggers", function() local matches = 0 runCallback("OnFrame") for groupIndex, group in ipairs(build.skillsTab.socketGroupList) do - for skillIndex, skill in ipairs(group.displaySkillList or {}) do + -- A disabled group keeps its last skill list + for skillIndex, skill in ipairs(group.enabled and group.displaySkillList or {}) do if skill.activeEffect.grantedEffect.name == name then matches = matches + 1 if matches == (occurrence or 1) then @@ -1321,175 +1323,192 @@ describe("TestTriggers", function() build.buildFlag = true end - it("triggers Shield Shatter from the item and the passive while respecting hit chance", function() + -- The trigger simulation counts a whole number of triggers over 1000 attacks + local function assertRate(expected, actual) + assert.are.near(expected, actual, expected * 0.002) + end + + for _, name in ipairs({ "Festering Resentment", "Svalinn" }) do + it("keeps the usual block assumptions for " .. name .. " without the Bell or a shield attack to block with", function() + local slot, hasShatter + selectReliquarian() + if name == "Svalinn" then + equipUnique("shield", name, "Weapon 2") + slot = "Weapon 2" + else + equipUnique("dagger", name, "Weapon 1") + equipUnique("shield", "Shattershard", "Weapon 2") + slot, hasShatter = "Weapon 1", true + end + setCustomMods("Your Hits can't be Evaded") + build.skillsTab:PasteSocketGroup("Slot: " .. slot .. "\nArc 20/0 1\nArc 20/0 1\n") + build.skillsTab:PasteSocketGroup("Tempest Shield 20/0 1\n") + + local function triggerRates() + local rates = {} + local arc = selectSkill("Arc") + -- Blocks come as often as the trigger's cooldown allows and alternate between both spells + assert.are.near(1 / 0.264, arc.TriggerRateCap, 1e-6) + assert.are.near(arc.TriggerRateCap / 2, arc.SkillTriggerRate, 1e-6) + rates.firstArc, rates.secondArc = arc.SkillTriggerRate, selectSkill("Arc", 2).SkillTriggerRate + local tempestShield = selectSkill("Tempest Shield") + assert.are.equal(tempestShield.TriggerRateCap, tempestShield.SkillTriggerRate) + rates.tempestShield = tempestShield.SkillTriggerRate + if hasShatter then + local shatter = selectSkill("Shield Shatter") + assert.are.near(1 / shatter.Duration, shatter.SkillTriggerRate, 1e-6) + rates.shatter = shatter.SkillTriggerRate + end + return rates + end + + local usual = triggerRates() + build.skillsTab:PasteSocketGroup("Shield Charge 20/0 1\n") + local _, chargeGroup = selectSkill("Shield Charge") + assert.are.same(usual, triggerRates()) + + -- Retaliation skills and attacks that do not use the shield are no source of blocks + chargeGroup.enabled = false + build.skillsTab:PasteSocketGroup("Smite 20/0 1\n") + build.skillsTab:PasteSocketGroup("Shield of Light 20/0 1\n") + allocateBellNode() + assert.are.same(usual, triggerRates()) + end) + end + + it("triggers Shield Shatter with each shield attack that hits", function() equipUnique("shield", "Shattershard", "Weapon 2") + selectReliquarian() setCustomMods("Your Hits can't be Evaded") - build.skillsTab:PasteSocketGroup("Shield Charge 20/0 1\nFaster Attacks 20/0 1\n") - local normal = selectSkill("Shield Shatter") - assert.are.near(1 / normal.Duration, normal.SkillTriggerRate, 1e-6) + build.skillsTab:PasteSocketGroup("Shield Charge 20/0 1\n") + local usual = selectSkill("Shield Shatter") equipUnique("mace", "The Monastery Bell", "Weapon 1") - local charge, chargeGroup = selectSkill("Shield Charge") + local charge = selectSkill("Shield Charge") local shatter = selectSkill("Shield Shatter") - assert.are.near(charge.Speed, shatter.SkillTriggerRate, 1e-6) - assert.are.near(normal.Duration, shatter.Duration, 1e-6) + assert.True(shatter.SkillTriggerRate > 4 * usual.SkillTriggerRate) + assertRate(charge.Speed, shatter.SkillTriggerRate) + assert.are.equal(usual.Duration, shatter.Duration) - allocateReliquarianBell() - assert.are.near(charge.Speed, selectSkill("Shield Shatter").SkillTriggerRate, 1e-6) + -- Attacking faster blocks proportionally more often + setCustomMods("Your Hits can't be Evaded\n100% increased Attack Speed") + local fasterCharge = selectSkill("Shield Charge") + local fasterShatter = selectSkill("Shield Shatter") + assert.True(fasterCharge.Speed > 1.5 * charge.Speed) + assertRate(shatter.SkillTriggerRate * fasterCharge.Speed / charge.Speed, fasterShatter.SkillTriggerRate) + + -- Attacks that miss do not block + setCustomMods("100% increased Attack Speed") + local evadedCharge = selectSkill("Shield Charge") + assert.True(evadedCharge.HitChance > 0 and evadedCharge.HitChance < 100) + assert.are.equal(fasterCharge.Speed, evadedCharge.Speed) + assertRate(fasterShatter.SkillTriggerRate * evadedCharge.HitChance / 100, selectSkill("Shield Shatter").SkillTriggerRate) + + -- The Reliquarian passive has the same modifier as the mace + setCustomMods("Your Hits can't be Evaded") build.itemsTab.slots["Weapon 1"]:SetSelItemId(0) - build.configTab.input.enemyBlockChance = 50 - build.configTab:BuildModList() - build.buildFlag = true - assert.are.near(charge.Speed / 2, selectSkill("Shield Shatter").SkillTriggerRate, 1e-6) - - build.configTab.input.enemyBlockChance = 100 - build.configTab:BuildModList() - build.buildFlag = true - assert.are.equal(0, selectSkill("Shield Shatter").SkillTriggerRate) - - chargeGroup.enabled = false - build.skillsTab:PasteSocketGroup("Smite 20/0 1\n") - local fallback = selectSkill("Shield Shatter") - assert.is_nil(fallback.ShieldAttackBlockRate) - assert.are.equal(0, fallback.SkillTriggerRate) - build.configTab.input.enemySpeed = 700 - build.configTab:BuildModList() build.buildFlag = true - local incoming = selectSkill("Shield Shatter") - assert.True(incoming.SkillTriggerRate > 0) - assert.True(incoming.SkillTriggerRate <= 1 / incoming.Duration) + assert.are.equal(usual.SkillTriggerRate, selectSkill("Shield Shatter").SkillTriggerRate) + local preview = build.calcsTab.calcs.getMiscCalculator(build)({ addNodes = { [build.spec.nodes[bellNodeId]] = true } }) + allocateBellNode() + local passive = selectSkill("Shield Shatter") + assertRate(selectSkill("Shield Charge").Speed, passive.SkillTriggerRate) + assert.are.equal(passive.SkillTriggerRate, preview.SkillTriggerRate) end) - it("reports recovery from Bell blocks once per use of a repeating shield attack", function() + it("blocks once per use of a repeating shield attack and uses the attack that blocks most often", function() equipUnique("mace", "The Monastery Bell", "Weapon 1") - equipUnique("shield", "Aegis Aurora", "Weapon 2") - setCustomMods("Your Hits can't be Evaded\nRecover 100 Life when you Block\nRecover 5% of your maximum Mana when you Block\nRecover 100 Energy Shield when you Block Spell Damage") - build.skillsTab:PasteSocketGroup("Smite 20/0 1\n") - local normal = selectSkill("Smite") - assert.is_nil(normal.ShieldAttackBlockRate) + equipUnique("shield", "Shattershard", "Weapon 2") + setCustomMods("Your Hits can't be Evaded") + build.skillsTab:PasteSocketGroup("Shield Crush 20/0 1\n") + local _, crushGroup = selectSkill("Shield Crush") + local single = selectSkill("Shield Shatter").SkillTriggerRate + -- Multistrike attacks faster, but its two repeats belong to the same use build.skillsTab:PasteSocketGroup("Shield Crush 20/0 1\nMultistrike 20/0 1\n") - local crush = selectSkill("Shield Crush") - assert.are.equal(3, crush.Repeats) - assert.are.near(crush.Speed / crush.Repeats, crush.ShieldAttackBlockRate, 1e-6) - assert.are.equal(100, crush.LifeOnBlock) - assert.True(crush.ManaOnBlock > 0) - assert.True(crush.EnergyShieldOnBlock > 0) - assert.are.equal(100, crush.EnergyShieldOnSpellBlock) - assert.are.near(crush.LifeOnBlock * crush.ShieldAttackBlockRate, crush.ShieldAttackLifeOnBlockRate, 1e-6) - assert.are.near(crush.ManaOnBlock * crush.ShieldAttackBlockRate, crush.ShieldAttackManaOnBlockRate, 1e-6) - assert.are.near(crush.EnergyShieldOnBlock * crush.ShieldAttackBlockRate, crush.ShieldAttackESOnBlockRate, 1e-6) - assert.are.equal(0, crush.LifeOnHit) - assert.are.equal(normal.EffectiveBlockChance, crush.EffectiveBlockChance) - assert.are.near(normal.TotalEHP, crush.TotalEHP, 1e-6) - end) + crushGroup.enabled = false + local repeating = selectSkill("Shield Crush") + assert.are.equal(3, repeating.Repeats) + local shatter = selectSkill("Shield Shatter") + assert.True(shatter.SkillTriggerRate < single) + assertRate(repeating.Speed / 3, shatter.SkillTriggerRate) - for _, name in ipairs({ "Festering Resentment", "Svalinn" }) do - it("respects the cooldown and spell rotation of " .. name, function() - local slot - if name == "Festering Resentment" then - equipUnique("dagger", name, "Weapon 1") - equipUnique("shield", "Shattershard", "Weapon 2") - allocateReliquarianBell() - slot = "Weapon 1" - else - equipUnique("mace", "The Monastery Bell", "Weapon 1") - equipUnique("shield", name, "Weapon 2") - slot = "Weapon 2" - end - setCustomMods("Your Hits can't be Evaded\n100% increased Attack Speed") - build.skillsTab:PasteSocketGroup("Shield Charge 20/0 1\nFaster Attacks 20/0 1\n") - build.skillsTab:PasteSocketGroup("Slot: " .. slot .. "\nArc 20/0 1\n") - local oneSpell = selectSkill("Arc") - assert.True(oneSpell.ShieldAttackBlockRate > oneSpell.TriggerRateCap) - assert.are.near(oneSpell.ShieldAttackBlockRate / 2, oneSpell.SkillTriggerRate, 1e-6) - - build.skillsTab:PasteSocketGroup("Slot: " .. slot .. "\nFireball 20/0 1\n") - build.configTab.input.enemyBlockChance = 50 - build.configTab:BuildModList() - local arc = selectSkill("Arc") - local fireball = selectSkill("Fireball") - assert.are.near(oneSpell.ShieldAttackBlockRate / 2, arc.ShieldAttackBlockRate, 1e-6) - assert.are.near(arc.ShieldAttackBlockRate / 2, arc.SkillTriggerRate, 1e-6) - assert.are.near(arc.ShieldAttackBlockRate, arc.SkillTriggerRate + fireball.SkillTriggerRate, 1e-6) - end) - end + crushGroup.enabled = true + build.buildFlag = true + assert.are.equal(single, selectSkill("Shield Shatter").SkillTriggerRate) + end) - it("counts shield throws independently of the displayed Trarthus skill part", function() + it("counts one block per shield throw regardless of the displayed Trarthus skill part", function() equipUnique("mace", "The Monastery Bell", "Weapon 1") equipUnique("shield", "Shattershard", "Weapon 2") - setCustomMods("Your Hits can't be Evaded\n100% increased Attack Speed") + setCustomMods("Your Hits can't be Evaded") local name = "Spectral Shield Throw of Trarthus" build.skillsTab:PasteSocketGroup(name .. " 20/0 1\n") local shield, group = selectSkill(name) + local rate = selectSkill("Shield Shatter").SkillTriggerRate + assertRate(shield.Speed, rate) group.gemList[1].skillPart = 2 build.buildFlag = true local shards = selectSkill(name) - assert.True(shards.HitSpeed ~= shield.Speed) - assert.are.near(shield.Speed, shards.ShieldAttackBlockRate, 1e-6) - assert.are.near(shield.Speed, selectSkill("Shield Shatter").SkillTriggerRate, 1e-6) - -- Repeated Bell hits keep the Shatter buff active and prevent ordinary blocks. - build.configTab.input.enemySpeed = 700 - build.configTab:BuildModList() - build.buildFlag = true - assert.are.near(shield.Speed, selectSkill("Shield Shatter").SkillTriggerRate, 1e-6) + assert.are.equal(shield.Speed, shards.Speed) + assert.True(shards.HitSpeed > shards.Speed) + assert.are.equal(rate, selectSkill("Shield Shatter").SkillTriggerRate) end) - it("keeps misses on the attack timeline and shares Arc's cooldown across socket groups", function() - equipUnique("mace", "The Monastery Bell", "Weapon 1") - equipUnique("shield", "Svalinn", "Weapon 2") - setCustomMods("Your Hits can't be Evaded\n300% increased Attack Speed") - build.skillsTab:PasteSocketGroup("Shield Charge 20/0 1\n") - build.skillsTab:PasteSocketGroup("Slot: Weapon 2\nArc 20/0 1\n") - local function arcRate(enemyBlock) - build.configTab.input.enemyBlockChance = enemyBlock - build.configTab:BuildModList() - build.buildFlag = true - return selectSkill("Arc").SkillTriggerRate - end - local half = arcRate(50) - local fewerHits = arcRate(53) - assert.True(half > fewerHits and fewerHits > 0) - local single = arcRate(0) - build.skillsTab:PasteSocketGroup("Slot: Weapon 2\nArc 20/0 1\n") - local first = selectSkill("Arc") - local second = selectSkill("Arc", 2) - assert.True(first.SkillTriggerRate > 0 and second.SkillTriggerRate > 0) - assert.are.near(single, first.SkillTriggerRate + second.SkillTriggerRate, 1e-6) - assert.True(single <= first.TriggerRateCap) - end) + for _, name in ipairs({ "Festering Resentment", "Svalinn" }) do + it("respects the cooldown and spell rotation of " .. name, function() + local slot + if name == "Svalinn" then + equipUnique("mace", "The Monastery Bell", "Weapon 1") + equipUnique("shield", name, "Weapon 2") + slot = "Weapon 2" + else + equipUnique("dagger", name, "Weapon 1") + equipUnique("shield", "Shattershard", "Weapon 2") + selectReliquarian() + allocateBellNode() + slot = "Weapon 1" + end + setCustomMods("Your Hits can't be Evaded") + build.skillsTab:PasteSocketGroup("Shield Charge 20/0 1\n") + build.skillsTab:PasteSocketGroup("Slot: " .. slot .. "\nArc 20/0 1\n") + local charge = selectSkill("Shield Charge") + local arc, spellGroup = selectSkill("Arc") + -- Each block triggers the spell while blocks are further apart than the cooldown + assert.True(charge.Speed < arc.TriggerRateCap) + assertRate(charge.Speed, arc.SkillTriggerRate) + + -- Blocks during the cooldown are wasted + setCustomMods("Your Hits can't be Evaded\n300% increased Attack Speed") + local fastCharge = selectSkill("Shield Charge") + local fastArc = selectSkill("Arc") + assert.True(fastCharge.Speed > 2 * fastArc.TriggerRateCap) + assert.True(fastArc.SkillTriggerRate > arc.SkillTriggerRate) + assert.True(fastArc.SkillTriggerRate <= fastArc.TriggerRateCap) + + -- Spells in the same item take turns + setCustomMods("Your Hits can't be Evaded") + spellGroup.enabled = false + build.skillsTab:PasteSocketGroup("Slot: " .. slot .. "\nArc 20/0 1\nFireball 20/0 1\n") + assertRate(charge.Speed / 2, selectSkill("Arc").SkillTriggerRate) + assertRate(charge.Speed / 2, selectSkill("Fireball").SkillTriggerRate) + end) + end - it("adds incoming blocks to Tempest Shield discharges independently of its activation cooldown", function() + it("discharges Tempest Shield with each block regardless of its activation cooldown", function() equipUnique("mace", "The Monastery Bell", "Weapon 1") equipUnique("shield", "Svalinn", "Weapon 2") setCustomMods("Your Hits can't be Evaded\n300% increased Attack Speed") build.skillsTab:PasteSocketGroup("Tempest Shield 20/0 1\n") + local usual = selectSkill("Tempest Shield") + assert.True(usual.SkillTriggerRate < 1) + build.skillsTab:PasteSocketGroup("Shield Charge 20/0 1\n") - build.skillsTab:PasteSocketGroup("Slot: Weapon 2\nArc 20/0 1\n") - local bell = selectSkill("Tempest Shield") - assert.True(bell.ShieldAttackBlockRate > 5) - assert.are.near(bell.ShieldAttackBlockRate, bell.SkillTriggerRate, 1e-6) - assert.are.near(bell.SkillTriggerRate, bell.Speed, 1e-6) - - build.configTab.input.enemySpeed = 1000 - build.configTab.input.enemyDamageType = "Spell" - build.configTab:BuildModList() - build.buildFlag = true - local mixed = selectSkill("Tempest Shield") - local incoming = mixed.EffectiveSpellBlockChance / 100 - assert.True(incoming > 0) - assert.are.near(bell.SkillTriggerRate + incoming, mixed.SkillTriggerRate, 1e-6) - build.configTab.input.enemyBlockChance = 100 - build.configTab:BuildModList() - build.buildFlag = true - local blocked = selectSkill("Tempest Shield") - assert.are.equal(0, blocked.ShieldAttackBlockRate) - assert.are.near(incoming, blocked.SkillTriggerRate, 1e-6) - assert.are.near(incoming, selectSkill("Arc").SkillTriggerRate, 1e-6) - build.configTab.input.enemyDamageType = "DamageOverTime" - build.configTab:BuildModList() - build.buildFlag = true - assert.are.equal(0, selectSkill("Tempest Shield").SkillTriggerRate) + local charge = selectSkill("Shield Charge") + local tempestShield = selectSkill("Tempest Shield") + assert.True(charge.Speed > 5) + assertRate(charge.Speed, tempestShield.SkillTriggerRate) + assert.are.equal(usual.Cooldown, tempestShield.Cooldown) end) end) diff --git a/src/Modules/CalcDefence.lua b/src/Modules/CalcDefence.lua index 63c449c72eb..c8ab58c6ed6 100644 --- a/src/Modules/CalcDefence.lua +++ b/src/Modules/CalcDefence.lua @@ -1698,11 +1698,6 @@ function calcs.defence(env, actor) end end -function calcs.enemySkillTime(env, actor) - local baseTime = (env.configInput.enemySpeed or env.configPlaceholder.enemySpeed or 700) / 1000 - return baseTime / (1 + actor.enemy.modDB:Sum("INC", nil, "Speed") / 100) / calcs.actionSpeedMod(actor.enemy) -end - -- Performs all extra defensive calculations ( eg EHP, maxHit ) function calcs.buildDefenceEstimations(env, actor) local modDB = actor.modDB @@ -2995,7 +2990,9 @@ function calcs.buildDefenceEstimations(env, actor) -- survival time do - output.enemySkillTime = calcs.enemySkillTime(env, actor) + output.enemySkillTime = (env.configInput.enemySpeed or env.configPlaceholder.enemySpeed or 700) / (1 + enemyDB:Sum("INC", nil, "Speed") / 100) + local enemyActionSpeed = calcs.actionSpeedMod(actor.enemy) + output.enemySkillTime = output.enemySkillTime / 1000 / enemyActionSpeed output["EHPSurvivalTime"] = output["TotalNumberOfHits"] * output.enemySkillTime if breakdown then breakdown["EHPSurvivalTime"] = { diff --git a/src/Modules/CalcPerform.lua b/src/Modules/CalcPerform.lua index d9ea64a50c9..2aaa8459a81 100644 --- a/src/Modules/CalcPerform.lua +++ b/src/Modules/CalcPerform.lua @@ -3910,9 +3910,6 @@ function calcs.perform(env, skipEHP) if not calcs.mirages(env) and calcs.offence(env, env.player, env.player.mainSkill) == false then return false -- Rejected trigger-source probes are never cached end - if not skipEHP then - calcs.shieldAttackBlockRecovery(env) - end if env.minion then if modDB:Flag(nil, "MinionsGainYourSpellSuppressionChance") then diff --git a/src/Modules/CalcSections.lua b/src/Modules/CalcSections.lua index 8653611345c..b103db1be51 100644 --- a/src/Modules/CalcSections.lua +++ b/src/Modules/CalcSections.lua @@ -1762,10 +1762,6 @@ return { { label = "Mana on Block", haveOutput = "ManaOnBlock", { format = "{0:output:ManaOnBlock}", { modName = "ManaOnBlock" }, }, }, { label = "ES on Block", haveOutput = "EnergyShieldOnBlock", { format = "{0:output:EnergyShieldOnBlock}", { modName = "EnergyShieldOnBlock" }, }, }, { label = "ES on Spell Block", haveOutput = "EnergyShieldOnSpellBlock", { format = "{0:output:EnergyShieldOnSpellBlock}", { modName = "EnergyShieldOnSpellBlock" }, }, }, - { label = "Monastery Bell Blocks", haveOutput = "ShieldAttackBlockRate", { format = "{2:output:ShieldAttackBlockRate}/s", { breakdown = "ShieldAttackBlockRate" }, }, }, - { label = "Life from Bell Blocks", haveOutput = "ShieldAttackLifeOnBlockRate", { format = "{1:output:ShieldAttackLifeOnBlockRate}/s", { modName = "LifeOnBlock" }, }, }, - { label = "Mana from Bell Blocks", haveOutput = "ShieldAttackManaOnBlockRate", { format = "{1:output:ShieldAttackManaOnBlockRate}/s", { modName = "ManaOnBlock" }, }, }, - { label = "ES from Bell Blocks", haveOutput = "ShieldAttackESOnBlockRate", { format = "{1:output:ShieldAttackESOnBlockRate}/s", { modName = "EnergyShieldOnBlock" }, }, }, } }, { defaultCollapsed = false, label = "Dodge", data = { extra = "{0:output:AttackDodgeChance}%/{0:output:SpellDodgeChance}%", { label = "Dodge Chance", { format = "{0:output:AttackDodgeChance}% (+{0:output:AttackDodgeChanceOverCap}%)", diff --git a/src/Modules/CalcTriggers.lua b/src/Modules/CalcTriggers.lua index 820604a7368..c923ffd15e1 100644 --- a/src/Modules/CalcTriggers.lua +++ b/src/Modules/CalcTriggers.lua @@ -100,251 +100,79 @@ local function findTriggerSkill(env, skill, source, triggerRate, comparer, minim return source, triggerRate, source and cacheSkillUUID(source, env) end -local function getShieldAttackBlockSource(env, mainOutput) - if not env.player.modDB:Flag(nil, "ShieldAttacksCountAsBlocks") then - return - end - - local source - for _, skill in ipairs(env.player.activeSkillList) do - local flags = skill.skillFlags - -- A retaliation attack already needs a block, so it cannot sustain its own block source. - if flags.shieldAttack and not (flags.disable or flags.totem or flags.mine or flags.trap or flags.minion) - and not skill.skillTypes[SkillType.Retaliation] and not skill.skillTypes[SkillType.OtherThingUsesSkill] - and not skill.skillCfg.skillCond["usedByMirage"] and not isTriggered(skill) then - local attackOutput - if skill == env.player.mainSkill then - attackOutput = mainOutput - else - local candidate, _, uuid = findTriggerSkill(env, skill, nil, nil, nil, nil, env.triggerSourceCache) - attackOutput = candidate and GlobalCache.cachedData[env.mode][uuid] - end - if attackOutput then - -- Overlaps and repeats share a single block per skill use. - local useRate = (attackOutput.Speed or 0) / (attackOutput.Repeats or 1) - local hitChance = attackOutput.HitChance or 0 - local rate = useRate * hitChance / 100 - if not source or rate > source.rate then - source = { skill = skill, useRate = useRate, hitChance = hitChance, rate = rate } +-- Config for skills triggered by blocking +-- With "Count as Blocking Attack Damage from the first target Hit with each Shield Attack" the shield attack that +-- blocks most often is the trigger source. Otherwise blocks are assumed to come as often as the skill can trigger +local function onBlockTrigger(env, config) + local mainSkill = env.player.mainSkill + if env.player.modDB:Flag(nil, "ShieldAttacksCountAsBlocks") then + local bestRate + for _, skill in ipairs(env.player.activeSkillList) do + local flags = skill.skillFlags + -- Retaliation attacks need a block before they can be used, so they are not counted as a source of blocks + if flags.shieldAttack and not flags.disable and not skill.skillTypes[SkillType.Retaliation] and not isTriggered(skill) then + local source, _, uuid = findTriggerSkill(env, skill, nil, nil, nil, nil, env.triggerSourceCache) + local cachedData = source and GlobalCache.cachedData[env.mode][uuid] + if cachedData then + -- Only the first target hit by each use blocks, however often the skill hits or repeats + local rate = cachedData.Speed / (1 + skill.skillModList:Sum("BASE", skill.skillCfg, "RepeatCount")) * (cachedData.HitChance or 0) + if not bestRate or rate > bestRate then + bestRate = rate + config.source, config.trigRate, config.sourceUUID = skill, cachedData.Speed, uuid + end end end end - end - return source -end - -local function recordShieldAttackBlocks(env, source) - local player = env.player - local output = player.output - output.ShieldAttackBlockRate = source.rate - output.ShieldAttackLifeOnBlockRate = not player.modDB:Flag(nil, "CannotGainLife") and output.LifeOnBlock * source.rate or 0 - output.ShieldAttackManaOnBlockRate = not player.modDB:Flag(nil, "CannotGainMana") and output.ManaOnBlock * source.rate or 0 - output.ShieldAttackESOnBlockRate = not player.modDB:Flag(nil, "CannotGainEnergyShield") and output.EnergyShieldOnBlock * source.rate or 0 - if player.breakdown then - player.breakdown.ShieldAttackBlockRate = { - s_format("%.2f ^8(%s uses per second)", source.useRate, source.skill.activeEffect.grantedEffect.name), - s_format("x %.2f%% ^8(chance to hit)", source.hitChance), - s_format("= %.2f ^8(attack blocks per second from shield attacks)", source.rate), - } - end -end - -function calcs.shieldAttackBlockRecovery(env) - if env.player.output.ShieldAttackBlockRate == nil then - local source = getShieldAttackBlockSource(env, env.player.output) - if source then - recordShieldAttackBlocks(env, source) - end - end -end - -local function shatterDuration(env, skill) - local uuid = cacheSkillUUID(skill, env) - if not GlobalCache.cachedData[env.mode][uuid] or env.mode == "CALCULATOR" then - calcs.buildActiveSkill(env, env.mode, skill, uuid, {uuid}) - end - return GlobalCache.cachedData[env.mode][uuid].Env.player.output.Duration -end - -local function incomingBlockRate(env, source) - local player = env.player - local category = env.configInput.enemyDamageType or "Average" - local interval = calcs.enemySkillTime(env, player) - if not (interval > 0 and interval < m_huge) or category == "DamageOverTime" or player.enemy.modDB:Flag(nil, "CannotBeBlocked") then - return 0 - end - local output = player.output - local attack = 1 - output.EffectiveAttackDodgeChance / 100 - local spell = 1 - output.EffectiveSpellDodgeChance / 100 - local chances = { - Melee = attack * (1 - output.MeleeEvadeChance / 100) * output.EffectiveBlockChance, - Projectile = attack * (1 - output.ProjectileEvadeChance / 100) * output.EffectiveProjectileBlockChance, - Spell = spell * output.EffectiveSpellBlockChance, - SpellProjectile = spell * output.EffectiveSpellProjectileBlockChance, - Untyped = output.EffectiveBlockChance, - } - local chance = chances[category] or (chances.Melee + chances.Projectile + chances.Spell + chances.SpellProjectile) / 4 - local rate = chance / 100 / interval - if rate > 0 then - for _, skill in ipairs(player.activeSkillList) do - if skill.activeEffect.grantedEffect.id == "ShieldShatter" and not skill.skillFlags.disable then - local duration = shatterDuration(env, skill) - -- An ordinary block starts a block lockout. A Bell hit can refresh it at any time. - -- Estimate the fraction of time with no Bell hit in the preceding buff duration. - local uses = duration * source.useRate - local whole = m_floor(uses) - local hit = source.hitChance / 100 - local available = (1 - hit) ^ whole * (1 - (uses - whole) * hit) - return available / (1 / rate + duration) - end - end - end - return rate -end - -local function onBlockTrigger(env, config) - local player = env.player - config.source = player.mainSkill - player.mainSkill.skillFlags.globalTrigger = true - if player.modDB:Flag(nil, "ShieldAttacksCountAsBlocks") then - local source = getShieldAttackBlockSource(env) - if source then - recordShieldAttackBlocks(env, source) - config.source = source.skill + if config.source then + config.ignoreRepeats = true + mainSkill.skillFlags.globalTrigger = false + return config end - config.shieldAttackBlock = source or { useRate = 0, hitChance = 0, rate = 0 } - config.incomingBlockRate = incomingBlockRate(env, config.shieldAttackBlock) - config.trigRate = config.shieldAttackBlock.rate + config.incomingBlockRate - player.mainSkill.skillFlags.globalTrigger = false end + mainSkill.skillFlags.globalTrigger = true + config.source = mainSkill return config end -local function socketedSpellOnBlock(env) - local mainSkill = env.player.mainSkill - local slot = mainSkill.socketGroup.slot - local support = mainSkill.triggeredBy and mainSkill.triggeredBy.grantedEffect - return onBlockTrigger(env, { - shareSpellCooldowns = true, - triggeredSkillCond = function(_, skill) - return slot and skill.socketGroup and skill.socketGroup.slot == slot - and skill.triggeredBy and skill.triggeredBy.grantedEffect == support - end, - }) -end - --- Reuse the same hit rolls at the same attack times for every build comparison. --- Shuffled ranks give an exact hit count for whole percentages across 4000 uses. -local blockSamples = 4000 -local hitRanks = {} -do - local seed = 1 - for i = 1, blockSamples do - seed = seed * 48271 % 2147483647 - local j = 1 + seed % i - hitRanks[i] = hitRanks[j] - hitRanks[j] = i - end -end - -local function blockEvents(source, incomingRate) - local useRate = source.rate > 0 and source.useRate or 0 - local duration = blockSamples / m_max(useRate, incomingRate) - local hitThreshold = m_floor(blockSamples * source.hitChance / 100 + 0.5) - local attackIndex = 0 - local function nextHit() - while attackIndex < blockSamples and useRate > 0 and hitThreshold > 0 do - attackIndex = attackIndex + 1 - if hitRanks[attackIndex] <= hitThreshold then - return (attackIndex - 1) / useRate - end - end - return m_huge - end - local nextAttack = nextHit() - local interval = incomingRate > 0 and 1 / incomingRate or m_huge - local nextIncoming = interval / 2 - return function() - local time = m_min(nextAttack, nextIncoming) - if time >= duration then - return - elseif nextIncoming < nextAttack then - nextIncoming = nextIncoming + interval - else - nextAttack = nextHit() - end - return time - end, duration -end - -- Calculate the impact other skills and source rate to trigger cooldown alignment have on the trigger rate -- for more details regarding the implementation see comments of #4599 and #5428 -function calcMultiSpellRotationImpact(env, skillRotation, sourceRate, triggerCD, chance, actor, blockSource, incomingRate) - if sourceRate <= 0 then - return 0, { simTime = 0, rates = {} } - end +function calcMultiSpellRotationImpact(env, skillRotation, sourceRate, triggerCD, chance, actor) local rotationIndex = 1 - local triggerIncrement = 1 / sourceRate - local simAttacks = 1000 - local simTime = triggerIncrement * simAttacks - local nextBlock - if blockSource then - nextBlock, simTime = blockEvents(blockSource, incomingRate) - -- Both streams have at most blockSamples events within the window. - simAttacks = 2 * blockSamples - end local next_trigger = 0 + local triggerIncrement = 1 / sourceRate + local SIM_TIME = triggerIncrement * 1000 -- Simulate 1000 attacks local chance = chance or 100 local skillCount = #skillRotation local actor = actor or env.player - local cooldowns = {} for _, skill in ipairs(skillRotation) do skill.cd = m_max(skill.cdOverride or ( ((skill.cd or 0) + (skill.addedCooldown or 0)) / (skill.icdr or 1)), ( (triggerCD or 0) + (skill.addsCastTime or 0) ) / (skill.icdr or 1)) - cooldowns[skill.cooldownGroup or skill] = 0 + skill.next_trig = 0 skill.count = 0 end - if blockSource and skillCount == 1 and skillRotation[1].cd == 0 then - local rate = sourceRate * chance / 100 - return rate, { simTime = 0, rates = { { name = skillRotation[1].uuid, rate = rate } } } - end - - for _ = 1, simAttacks do - if nextBlock then - next_trigger = nextBlock() - if not next_trigger then - break - end - end + while next_trigger < SIM_TIME do local currentIndex = rotationIndex repeat - local skill = skillRotation[currentIndex] - local cooldownGroup = skill.cooldownGroup or skill - if cooldowns[cooldownGroup] <= next_trigger then -- Skill at current index off cooldown, Trigger it. - skill.count = skill.count + 1 + if skillRotation[currentIndex].next_trig <= next_trigger then -- Skill at current index off cooldown, Trigger it. + skillRotation[currentIndex].count = skillRotation[currentIndex].count + 1 -- Cooldown starts at the beginning of current tick and ends at the next tick after cooldown expiration - cooldowns[cooldownGroup] = ceil_b(floor_b(next_trigger, data.misc.ServerTickTime) + skill.cd, data.misc.ServerTickTime) - if nextBlock then - rotationIndex = currentIndex % skillCount + 1 - end + skillRotation[currentIndex].next_trig = ceil_b(floor_b(next_trigger, data.misc.ServerTickTime) + skillRotation[currentIndex].cd, data.misc.ServerTickTime) break end currentIndex = (currentIndex % skillCount) + 1 -- Current skill on cooldown, try the next one. until(currentIndex == rotationIndex) -- All skills checked, trigger wasted - if not nextBlock then - rotationIndex = rotationIndex % skillCount + 1 - next_trigger = next_trigger + triggerIncrement - end + rotationIndex = (rotationIndex % skillCount) + 1 -- Move on to the next skill in rotation + next_trigger = next_trigger + triggerIncrement end - local trigRateTable = { simTime = simTime, rates = {}, } + local trigRateTable = { simTime = SIM_TIME, rates = {}, } local mainRate = 0 for _, sd in ipairs(skillRotation) do -- Account for trigger chance. Adds the expected value of a geometric distribution where p = chance multiplied by triggerIncrement -- This allows for O(1) estimation of trigger chance impact on trigger rate as number of triggers approaches infinity -- Credit to Logik and Quickstick. More info in prs linked here: https://github.com/PathOfBuildingCommunity/PathOfBuilding/pull/7244 and on discord. - t_insert(trigRateTable.rates, { name = sd.uuid, rate = 1 / (simTime / sd.count + (triggerIncrement / chance * 100) - triggerIncrement) }) + t_insert(trigRateTable.rates, { name = sd.uuid, rate = 1 / (SIM_TIME / sd.count + (triggerIncrement / chance * 100) - triggerIncrement) }) if cacheSkillUUID(actor.mainSkill, env) == sd.uuid then mainRate = trigRateTable.rates[#trigRateTable.rates].rate end @@ -619,8 +447,7 @@ local function defaultTriggerHandler(env, config) local source = config.source local triggeredSkills = config.triggeredSkills or {} local trigRate = config.trigRate - local shieldAttackBlock = config.shieldAttackBlock - local uuid + local uuid = config.sourceUUID local sourceWeapon = config.sourceWeapon -- Only attacks using the granting weapon can activate source-weapon triggers local sourceWeaponFlag = sourceWeapon and actor.mainSkill.socketGroup.slot and (actor.mainSkill.socketGroup.slot:match("^Weapon 2") and "weapon2Attack" or "weapon1Attack") @@ -633,12 +460,7 @@ local function defaultTriggerHandler(env, config) source, trigRate, uuid = findTriggerSkill(env, skill, source, trigRate, config.comparer, config.minimumCostPerUse, sourceCache) end if config.triggeredSkillCond and config.triggeredSkillCond(env,skill) then - local spell = packageSkillDataForSimulation(skill, env) - if config.shareSpellCooldowns then - local gem = skill.activeEffect.gemData - spell.cooldownGroup = gem and gem.grantedEffect == skill.activeEffect.grantedEffect and gem.gameId or skill.activeEffect.grantedEffect.id - end - t_insert(triggeredSkills, spell) + t_insert(triggeredSkills, packageSkillDataForSimulation(skill, env)) end end end @@ -662,13 +484,7 @@ local function defaultTriggerHandler(env, config) } elseif breakdown then breakdown.EffectiveSourceRate = {} - if shieldAttackBlock then - if shieldAttackBlock.skill then - t_insert(breakdown.EffectiveSourceRate, s_format("%.2f ^8(%s uses per second)", shieldAttackBlock.useRate, source.activeEffect.grantedEffect.name)) - t_insert(breakdown.EffectiveSourceRate, s_format("x %.2f%% ^8(chance to hit)", shieldAttackBlock.hitChance)) - end - t_insert(breakdown.EffectiveSourceRate, s_format("+ %.2f ^8(estimated blocks per second from the configured enemy)", config.incomingBlockRate)) - elseif trigRate and source then + if trigRate and source then if config.assumingEveryHitKills then t_insert(breakdown.EffectiveSourceRate, "Assuming every attack kills") end @@ -679,7 +495,7 @@ local function defaultTriggerHandler(env, config) -- Dual wield triggers local sourceWeaponTrigger = sourceWeapon and source and source.skillFlags.bothWeaponAttack local itemSupportTrigger = actor.mainSkill.triggeredBy and actor.mainSkill.triggeredBy.grantedEffect.support and actor.mainSkill.triggeredBy.grantedEffect.fromItem - if not shieldAttackBlock and trigRate and source and env.player.weaponData1.type and env.player.weaponData2.type and not source.skillData.doubleHitsWhenDualWielding and (source.skillTypes[SkillType.Melee] or source.skillTypes[SkillType.Attack]) and (sourceWeaponTrigger or itemSupportTrigger) then + if trigRate and source and env.player.weaponData1.type and env.player.weaponData2.type and not source.skillData.doubleHitsWhenDualWielding and (source.skillTypes[SkillType.Melee] or source.skillTypes[SkillType.Attack]) and (sourceWeaponTrigger or itemSupportTrigger) then trigRate = trigRate / 2 if breakdown then t_insert(breakdown.EffectiveSourceRate, 2, s_format("/ 2 ^8(due to dual wielding)")) @@ -798,11 +614,7 @@ local function defaultTriggerHandler(env, config) local cooldownOverride = actor.mainSkill.skillModList:Override(actor.mainSkill.skillCfg, "CooldownRecovery") local triggerCD = actor.mainSkill.triggeredBy and env.player.mainSkill.triggeredBy.grantedEffect.levels[env.player.mainSkill.triggeredBy.level].cooldown triggerCD = triggerCD or source.triggeredBy and source.triggeredBy.grantedEffect.levels[source.triggeredBy.level].cooldown - local triggeredCD = actor.mainSkill.skillData.cooldown - if config.blockDischarge then - -- The reservation skill's cooldown applies when activating the buff. - triggeredCD = nil - end + local triggeredCD = not config.ignoreSkillCooldown and actor.mainSkill.skillData.cooldown or nil if actor.mainSkill.skillData.triggeredByBrand then triggerCD = actor.mainSkill.triggeredBy.mainSkill.skillData.repeatFrequency / actor.mainSkill.triggeredBy.activationFreqMore / actor.mainSkill.triggeredBy.activationFreqInc @@ -930,7 +742,7 @@ local function defaultTriggerHandler(env, config) t_insert(breakdown.TriggerRateCap, "") if not (triggeredCD or triggerCD or cooldownOverride) then - t_insert(breakdown.TriggerRateCap, shieldAttackBlock and "One block per shield skill use that hits" or "Assuming cast on every kill/attack/hit") + t_insert(breakdown.TriggerRateCap, "Assuming cast on every kill/attack/hit") else t_insert(breakdown.TriggerRateCap, "Trigger rate:") t_insert(breakdown.TriggerRateCap, s_format("1 / %.3f", actionCooldownTickRounded)) @@ -970,7 +782,7 @@ local function defaultTriggerHandler(env, config) local triggerChanceBreakdown = {} --Accuracy and crit chance - if not shieldAttackBlock and source and (source.skillTypes[SkillType.Melee] or source.skillTypes[SkillType.Attack]) and GlobalCache.cachedData[env.mode][uuid] and not config.triggerOnUse then + if source and (source.skillTypes[SkillType.Melee] or source.skillTypes[SkillType.Attack]) and GlobalCache.cachedData[env.mode][uuid] and not config.triggerOnUse then local sourceHitChance = GlobalCache.cachedData[env.mode][uuid].HitChance or 0 if sourceHitChance ~= 100 then @@ -1030,12 +842,7 @@ local function defaultTriggerHandler(env, config) end -- If the current triggered skill ignores tick rate and is the only triggered skill by this trigger use charge based calcs - if config.blockDischarge then - output.SkillTriggerRate = output.EffectiveSourceRate - if breakdown then - breakdown.SkillTriggerRate = { s_format("%.2f ^8(discharges per second, one per block)", output.SkillTriggerRate) } - end - elseif actor.mainSkill.skillData.ignoresTickRate and ( not config.triggeredSkillCond or (triggeredSkills and #triggeredSkills == 1 and triggeredSkills[1] == packageSkillDataForSimulation(actor.mainSkill, env)) ) then + if actor.mainSkill.skillData.ignoresTickRate and ( not config.triggeredSkillCond or (triggeredSkills and #triggeredSkills == 1 and triggeredSkills[1] == packageSkillDataForSimulation(actor.mainSkill, env)) ) then local overlaps = config.stagesAreOverlaps and env.player.mainSkill.skillPart == config.stagesAreOverlaps and env.player.mainSkill.activeEffect.srcInstance.skillStageCount or config.overlaps output.SkillTriggerRate = m_min(output.TriggerRateCap, output.EffectiveSourceRate * (overlaps or 1)) if breakdown then @@ -1052,13 +859,12 @@ local function defaultTriggerHandler(env, config) elseif actor.mainSkill.skillFlags.globalTrigger and not config.triggeredSkillCond then -- Trigger does not use source rate breakpoints for one reason or another output.SkillTriggerRate = output.EffectiveSourceRate else -- Triggers like Cast on Crit go through simulation to calculate the trigger rate of each skill in the trigger group - local simBreakdown - local rotation = config.triggeredSkillCond and triggeredSkills or { packageSkillDataForSimulation(actor.mainSkill, env) } - local cooldown = not actor.mainSkill.skillData.triggeredByBrand and (triggerCD or triggeredCD) or 0 - output.SkillTriggerRate, simBreakdown = calcMultiSpellRotationImpact(env, rotation, output.EffectiveSourceRate, cooldown, triggerChance, actor, shieldAttackBlock, config.incomingBlockRate) - if shieldAttackBlock then - output.SkillTriggerRate = m_min(output.SkillTriggerRate, output.TriggerRateCap) + local skillRotation = config.triggeredSkillCond and triggeredSkills or {packageSkillDataForSimulation(actor.mainSkill, env)} + if config.ignoreSkillCooldown then + skillRotation[1].cd = nil end + local simBreakdown + output.SkillTriggerRate, simBreakdown = calcMultiSpellRotationImpact(env, skillRotation, output.EffectiveSourceRate, (not actor.mainSkill.skillData.triggeredByBrand and ( triggerCD or triggeredCD ) or 0), triggerChance, actor) local triggerBotsEffective = actor.modDB:Flag(nil, "HaveTriggerBots") and actor.mainSkill.skillTypes[SkillType.Spell] if triggerBotsEffective then output.SkillTriggerRate = 2 * output.SkillTriggerRate @@ -1114,9 +920,7 @@ local function defaultTriggerHandler(env, config) } t_insert(breakdown.SimData.rowList, row) end - if simBreakdown.simTime > 0 then - t_insert(breakdown.SimData, s_format("Simulation duration: %.2f ^8(In game source skill usage duration in seconds)", simBreakdown.simTime)) - end + t_insert(breakdown.SimData, s_format("Simulation duration: %.2f ^8(In game source skill usage duration in seconds)", simBreakdown.simTime, simBreakdown.simTime)) end end else @@ -1552,20 +1356,25 @@ local configTable = { end, ["tempest shield"] = function(env) local config = onBlockTrigger(env, {}) - config.blockDischarge = config.shieldAttackBlock ~= nil + -- Tempest Shield's cooldown limits activating the buff, not how often a block discharges it + config.ignoreSkillCooldown = config.sourceUUID ~= nil return config end, ["shattershard"] = function(env) local config = onBlockTrigger(env, {}) - if config.shieldAttackBlock then + if config.sourceUUID then + -- Shield Shatter only prevents ordinary blocks for its duration return config end - local duration = shatterDuration(env, env.player.mainSkill) - env.player.mainSkill.skillData.triggerRateCapOverride = 1 / duration + local uuid = cacheSkillUUID(env.player.mainSkill, env) + if not GlobalCache.cachedData[env.mode][uuid] or env.mode == "CALCULATOR" then + calcs.buildActiveSkill(env, env.mode, env.player.mainSkill, uuid, {uuid}) + end + env.player.mainSkill.skillData.triggerRateCapOverride = 1 / GlobalCache.cachedData[env.mode][uuid].Env.player.output.Duration if env.player.breakdown then env.player.breakdown.SkillTriggerRate = { s_format("Shattershard uses duration as pseudo cooldown"), - s_format("1 / %.2f ^8(Shattershard duration)", duration), + s_format("1 / %.2f ^8(Shattershard duration)", GlobalCache.cachedData[env.mode][uuid].Env.player.output.Duration), s_format("= %.2f ^8per second", env.player.mainSkill.skillData.triggerRateCapOverride), } end @@ -1759,8 +1568,18 @@ local configTable = { useCastRate = true} end end, - ["svalinn cast on block"] = socketedSpellOnBlock, - ["festering resentment cast on block"] = socketedSpellOnBlock, + ["svalinn cast on block"] = function(env) -- Svalinn Girded Tower Shield + return onBlockTrigger(env, { + triggeredSkillCond = function(env, skill) + return slotMatch(env, skill) and skill.triggeredBy and calcLib.canGrantedEffectSupportActiveSkill(skill.triggeredBy.grantedEffect, skill) + end}) + end, + ["festering resentment cast on block"] = function(env) -- Festering Resentment Demon Dagger + return onBlockTrigger(env, { + triggeredSkillCond = function(env, skill) + return slotMatch(env, skill) and skill.triggeredBy and calcLib.canGrantedEffectSupportActiveSkill(skill.triggeredBy.grantedEffect, skill) + end}) + end, ["hex on trap"] = function(env) -- Hand of the Lords Carnal Mitts return {triggerSkillCond = function(env, skill) -- Hex is triggered only when a trap is triggered diff --git a/src/Modules/Common.lua b/src/Modules/Common.lua index 85f434f9df8..e8c7dfd03fb 100644 --- a/src/Modules/Common.lua +++ b/src/Modules/Common.lua @@ -927,7 +927,6 @@ function cacheData(uuid, env) Name = env.player.mainSkill.activeEffect.grantedEffect.name, Speed = env.player.output.Speed, HitSpeed = env.player.output.HitSpeed, - Repeats = env.player.output.Repeats, ManaCost = env.player.output.ManaCost, LifeCost = env.player.output.LifeCost, ESCost = env.player.output.ESCost, From f2c8d73eec85894a1ea1a784d0de1c323bace406 Mon Sep 17 00:00:00 2001 From: David Medgyesy Date: Fri, 27 Nov 2026 14:14:17 +0100 Subject: [PATCH 4/4] Account for recovery from Monastery Bell blocks Attribute life, mana and energy shield recovery to the selected shield attack, counting at most one block per use. Build on ShadowTrolll/PathOfBuilding@ea5ead4aefb718b11f42fc2c09b3a67190dfc68e for the skill-scoped recovery calculation. --- spec/System/TestTriggers_spec.lua | 31 +++++++++++++++++++++++++++++++ src/Modules/BuildDisplayStats.lua | 6 +++--- src/Modules/CalcOffence.lua | 27 ++++++++++++++++++++++++--- src/Modules/CalcSections.lua | 14 +++++++++++++- 4 files changed, 71 insertions(+), 7 deletions(-) diff --git a/spec/System/TestTriggers_spec.lua b/spec/System/TestTriggers_spec.lua index dc6b3d1231a..8cd37a580cf 100644 --- a/spec/System/TestTriggers_spec.lua +++ b/spec/System/TestTriggers_spec.lua @@ -1438,6 +1438,37 @@ describe("TestTriggers", function() assert.are.equal(single, selectSkill("Shield Shatter").SkillTriggerRate) end) + it("adds Bell recovery for the selected shield attack once per use", function() + equipUnique("shield", "Shattershard", "Weapon 2") + setCustomMods("40 Life gained when you Block\n20 Mana gained when you Block\nGain 30 Energy Shield when you Block") + build.configTab.input.enemyEvasion = 3000 + build.configTab:BuildModList() + build.skillsTab:PasteSocketGroup("Shield Crush 20/0 1\nMultistrike 20/0 1\n") + build.skillsTab:PasteSocketGroup("Fireball 20/0 1\n") + + local withoutBell = selectSkill("Shield Crush") + assert.is_nil(withoutBell.LifeOnBlockRate) + assert.is_nil(withoutBell.ManaOnBlockRate) + assert.is_nil(withoutBell.EnergyShieldOnBlockRate) + + equipUnique("mace", "The Monastery Bell", "Weapon 1") + local crush = selectSkill("Shield Crush") + assert.are.equal(3, crush.Repeats) + assert.True(crush.HitChance > 0 and crush.HitChance < 100) + local expectedBlocks = crush.Speed / crush.Repeats * crush.HitChance / 100 + for resource, gain in pairs({ Life = 40, Mana = 20, EnergyShield = 30 }) do + local suffix = resource .. "OnBlockRate" + assert.are.near(gain * expectedBlocks, crush[suffix], 1e-6) + assert.are.near(crush[resource .. "LeechRate"] + crush[resource .. "OnHitRate"] + crush[suffix], + crush[resource .. "LeechGainRate"], 1e-6) + end + assertRate(expectedBlocks, selectSkill("Shield Shatter").SkillTriggerRate) + local fireball = selectSkill("Fireball") + assert.is_nil(fireball.LifeOnBlockRate) + assert.is_nil(fireball.ManaOnBlockRate) + assert.is_nil(fireball.EnergyShieldOnBlockRate) + end) + it("counts one block per shield throw regardless of the displayed Trarthus skill part", function() equipUnique("mace", "The Monastery Bell", "Weapon 1") equipUnique("shield", "Shattershard", "Weapon 2") diff --git a/src/Modules/BuildDisplayStats.lua b/src/Modules/BuildDisplayStats.lua index 950c579f09a..2deb9316538 100644 --- a/src/Modules/BuildDisplayStats.lua +++ b/src/Modules/BuildDisplayStats.lua @@ -160,7 +160,7 @@ local displayStats = { { stat = "LifeRegenRecovery", label = "Life Regen", fmt = ".1f", color = colorCodes.LIFE, condFunc = function(v, o) return o.LifeRecovery <= 0 and o.LifeRegenRecovery ~= 0 end, breakdown = "LifeRegenRecovery" }, { stat = "LifeRegenRecovery", label = "Life Recovery", fmt = ".1f", color = colorCodes.LIFE, condFunc = function(v, o) return o.LifeRecovery > 0 and o.LifeRegenRecovery ~= 0 end, breakdown = "LifeRegenRecovery" }, { stat = "LifeRecharge", label = "Life Recharge", fmt = ".1f", color = colorCodes.LIFE, condFunc = function(v,o) return v > 0 end }, - { stat = "LifeLeechGainRate", label = "Life Leech/On Hit Rate", fmt = ".1f", color = colorCodes.LIFE, compPercent = true, breakdown = "LifeLeech" }, + { stat = "LifeLeechGainRate", label = "Life Leech/Gain Rate", fmt = ".1f", color = colorCodes.LIFE, compPercent = true, breakdown = "LifeLeech" }, { stat = "LifeLeechGainPerHit", label = "Life Leech/Gain per Hit", fmt = ".1f", color = colorCodes.LIFE, compPercent = true }, { }, { stat = "Mana", label = "Total Mana", fmt = "d", compactValue = true, color = colorCodes.MANA, compPercent = true, modNames = { "Mana" }, ignoredSections = { "Base from Gear", "Inc. from Tree" } }, @@ -169,7 +169,7 @@ local displayStats = { { stat = "ManaUnreservedPercent", label = "Unreserved Mana", fmt = "d%%", color = colorCodes.MANA, condFunc = function(v, o) return v < 100 end, breakdown = "ManaReserved" }, { stat = "ManaRegenRecovery", label = "Mana Regen", fmt = ".1f", color = colorCodes.MANA, condFunc = function(v,o) return o.ManaRecovery <= 0 and o.ManaRegenRecovery ~= 0 end }, { stat = "ManaRegenRecovery", label = "Mana Recovery", fmt = ".1f", color = colorCodes.MANA, condFunc = function(v,o) return o.ManaRecovery > 0 and o.ManaRegenRecovery ~= 0 end }, - { stat = "ManaLeechGainRate", label = "Mana Leech/On Hit Rate", fmt = ".1f", color = colorCodes.MANA, compPercent = true }, + { stat = "ManaLeechGainRate", label = "Mana Leech/Gain Rate", fmt = ".1f", color = colorCodes.MANA, compPercent = true }, { stat = "ManaLeechGainPerHit", label = "Mana Leech/Gain per Hit", fmt = ".1f", color = colorCodes.MANA, compPercent = true }, { }, -- the breakdown for armour, es and ev doesn't have anything relevant, and @@ -179,7 +179,7 @@ local displayStats = { { stat = "Spec:EnergyShieldInc", label = "%Inc ES from Tree", color = colorCodes.ES, fmt = "d%%" }, { stat = "EnergyShieldRegenRecovery", label = "ES Regen", color = colorCodes.ES, fmt = ".1f", condFunc = function(v,o) return o.EnergyShieldRecovery <= 0 and o.EnergyShieldRegenRecovery ~= 0 end }, { stat = "EnergyShieldRegenRecovery", label = "ES Recovery", color = colorCodes.ES, fmt = ".1f", condFunc = function(v,o) return o.EnergyShieldRecovery > 0 and o.EnergyShieldRegenRecovery ~= 0 end }, - { stat = "EnergyShieldLeechGainRate", label = "ES Leech/On Hit Rate", color = colorCodes.ES, fmt = ".1f", compPercent = true }, + { stat = "EnergyShieldLeechGainRate", label = "ES Leech/Gain Rate", color = colorCodes.ES, fmt = ".1f", compPercent = true }, { stat = "EnergyShieldLeechGainPerHit", label = "ES Leech/Gain per Hit", color = colorCodes.ES, fmt = ".1f", compPercent = true }, { }, { stat = "Ward", label = "Ward", fmt = "d", compactValue = true, color = colorCodes.WARD, compPercent = true, modNames = { "Ward" }, ignoredSections = defenseIgnoredSections }, diff --git a/src/Modules/CalcOffence.lua b/src/Modules/CalcOffence.lua index fa2291f1e3a..4f2d254894a 100644 --- a/src/Modules/CalcOffence.lua +++ b/src/Modules/CalcOffence.lua @@ -4180,14 +4180,35 @@ function calcs.offence(env, actor, activeSkill) skillFlags.leechLife = output.LifeLeechRate > 0 skillFlags.leechES = output.EnergyShieldLeechRate > 0 skillFlags.leechMana = output.ManaLeechRate > 0 + -- Only the first target hit by each shield attack use counts as a Bell block. + if actor == env.player and skillFlags.shieldAttack and skillModList:Flag(nil, "ShieldAttacksCountAsBlocks") + and not (skillFlags.mine or skillFlags.trap or skillFlags.totem) then + local usesPerSecond = output.Speed / output.Repeats + local blockRate = usesPerSecond * output.HitChance / 100 + for _, resource in ipairs({ "Life", "Mana", "EnergyShield" }) do + local onBlock = output[resource .. "OnBlock"] or 0 + if onBlock > 0 and blockRate > 0 and not skillModList:Flag(skillCfg, "CannotGain" .. resource) then + local rateStat = resource .. "OnBlockRate" + output[rateStat] = onBlock * blockRate + if breakdown then + breakdown[rateStat] = { + s_format("%.1f ^8(gained on block)", onBlock), + s_format("x %.2f ^8(shield attack uses per second)", usesPerSecond), + s_format("x %.2f%% ^8(chance to hit)", output.HitChance), + s_format("= %.1f ^8(per second)", output[rateStat]), + } + end + end + end + end if skillData.showAverage then output.LifeLeechGainPerHit = output.LifeLeechPerHit + output.LifeOnHit output.EnergyShieldLeechGainPerHit = output.EnergyShieldLeechPerHit + output.EnergyShieldOnHit output.ManaLeechGainPerHit = output.ManaLeechPerHit + output.ManaOnHit else - output.LifeLeechGainRate = output.LifeLeechRate + output.LifeOnHitRate - output.EnergyShieldLeechGainRate = output.EnergyShieldLeechRate + output.EnergyShieldOnHitRate - output.ManaLeechGainRate = output.ManaLeechRate + output.ManaOnHitRate + output.LifeLeechGainRate = output.LifeLeechRate + output.LifeOnHitRate + (output.LifeOnBlockRate or 0) + output.EnergyShieldLeechGainRate = output.EnergyShieldLeechRate + output.EnergyShieldOnHitRate + (output.EnergyShieldOnBlockRate or 0) + output.ManaLeechGainRate = output.ManaLeechRate + output.ManaOnHitRate + (output.ManaOnBlockRate or 0) end if breakdown then local hitRate = output.HitChance / 100 * (globalOutput.HitSpeed or globalOutput.Speed) * skillData.dpsMultiplier diff --git a/src/Modules/CalcSections.lua b/src/Modules/CalcSections.lua index b103db1be51..f1e8e5c4328 100644 --- a/src/Modules/CalcSections.lua +++ b/src/Modules/CalcSections.lua @@ -1152,7 +1152,7 @@ return { }, }, } } } }, -{ 1, "LeechGain", 1, colorCodes.OFFENCE, {{ defaultCollapsed = false, label = "Leech & Gain on Hit", data = { +{ 1, "LeechGain", 1, colorCodes.OFFENCE, {{ defaultCollapsed = false, label = "Leech & Gain on Hit/Block", data = { { label = "Life Leech Cap", flag = "leechLife", { format = "{1:output:MaxLifeLeechRate}", { breakdown = "MaxLifeLeechRate" }, { modName = "MaxLifeLeechRate" }, @@ -1185,6 +1185,10 @@ return { { label = "Off Hand", flag = "weapon2Attack", modName = "LifeOnHit", modType = "BASE", cfg = "weapon2" }, { label = "Enemy modifiers", modName = { "SelfLifeOnHit" }, modType = "BASE", cfg = "skill", enemy = true }, }, }, + { label = "Life Gain on Block Rate", haveOutput = "LifeOnBlockRate", { format = "{1:output:LifeOnBlockRate}", + { breakdown = "LifeOnBlockRate" }, + { modName = "LifeOnBlock" }, + }, }, { label = "Life Gain on Kill", haveOutput = "LifeOnKill", { format = "{1:output:LifeOnKill}", {modName = "LifeOnKill"}, }, }, @@ -1220,6 +1224,10 @@ return { { label = "Off Hand", flag = "weapon2Attack", modName = "EnergyShieldOnHit", modType = "BASE", cfg = "weapon2" }, { label = "Enemy modifiers", modName = { "SelfEnergyShieldOnHit" }, modType = "BASE", cfg = "skill", enemy = true }, }, }, + { label = "ES Gain on Block Rate", haveOutput = "EnergyShieldOnBlockRate", { format = "{1:output:EnergyShieldOnBlockRate}", + { breakdown = "EnergyShieldOnBlockRate" }, + { modName = "EnergyShieldOnBlock" }, + }, }, { label = "ES Gain on Kill", haveOutput = "EnergyShieldOnKill", { format = "{1:output:EnergyShieldOnKill}", {modName = "EnergyShieldOnKill"}, }, }, @@ -1253,6 +1261,10 @@ return { { label = "Off Hand", flag = "weapon2Attack", modName = "ManaOnHit", modType = "BASE", cfg = "weapon2" }, { label = "Enemy modifiers", modName = { "SelfManaOnHit" }, modType = "BASE", cfg = "skill", enemy = true }, }, }, + { label = "Mana Gain on Block Rate", haveOutput = "ManaOnBlockRate", { format = "{1:output:ManaOnBlockRate}", + { breakdown = "ManaOnBlockRate" }, + { modName = "ManaOnBlock" }, + }, }, { label = "Mana Gain on Kill", haveOutput = "ManaOnKill", { format = "{1:output:ManaOnKill}", {modName = "ManaOnKill"}, }, },