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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
246 changes: 246 additions & 0 deletions spec/System/TestTriggers_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,252 @@ 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 bellNodeId = 26055
local function selectReliquarian()
local spec = build.spec
spec:SelectClass(spec.tree.classNameMap.Scion)
spec:SelectAscendClass(spec.tree.ascendNameMap.Reliquarian.ascendClassId)
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

local function selectSkill(name, occurrence)
local matches = 0
runCallback("OnFrame")
for groupIndex, group in ipairs(build.skillsTab.socketGroupList) 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
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
error("Missing active skill: " .. name)
end

local function setCustomMods(text)
build.configTab.input.customMods = text
build.configTab:BuildModList()
build.buildFlag = true
end

-- 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\n")
local usual = selectSkill("Shield Shatter")

equipUnique("mace", "The Monastery Bell", "Weapon 1")
local charge = selectSkill("Shield Charge")
local shatter = selectSkill("Shield Shatter")
assert.True(shatter.SkillTriggerRate > 4 * usual.SkillTriggerRate)
assertRate(charge.Speed, shatter.SkillTriggerRate)
assert.are.equal(usual.Duration, shatter.Duration)

-- 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.buildFlag = true
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("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", "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")
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)

crushGroup.enabled = true
build.buildFlag = true
assert.are.equal(single, selectSkill("Shield Shatter").SkillTriggerRate)
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")
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.are.equal(shield.Speed, shards.Speed)
assert.True(shards.HitSpeed > shards.Speed)
assert.are.equal(rate, selectSkill("Shield Shatter").SkillTriggerRate)
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("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")
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)

it("Trigger Combust", function()
build.skillsTab:PasteSocketGroup("Infernal Cry 20/0 1\n")
runCallback("OnFrame")
Expand Down
2 changes: 1 addition & 1 deletion src/Data/ModCache.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
69 changes: 56 additions & 13 deletions src/Modules/CalcTriggers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,40 @@ local function findTriggerSkill(env, skill, source, triggerRate, comparer, minim
return source, triggerRate, source and cacheSkillUUID(source, env)
end

-- 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
if config.source then
config.ignoreRepeats = true
mainSkill.skillFlags.globalTrigger = false
return config
end
end
mainSkill.skillFlags.globalTrigger = true
config.source = mainSkill
return config
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)
Expand Down Expand Up @@ -413,7 +447,7 @@ local function defaultTriggerHandler(env, config)
local source = config.source
local triggeredSkills = config.triggeredSkills or {}
local trigRate = config.trigRate
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")
Expand Down Expand Up @@ -580,7 +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
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
Expand Down Expand Up @@ -825,7 +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
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 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
Expand Down Expand Up @@ -1316,11 +1355,17 @@ local configTable = {
end}
end,
["tempest shield"] = function(env)
env.player.mainSkill.skillFlags.globalTrigger = true
return {source = env.player.mainSkill}
local config = onBlockTrigger(env, {})
-- 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)
env.player.mainSkill.skillFlags.globalTrigger = true
local config = onBlockTrigger(env, {})
if config.sourceUUID then
-- Shield Shatter only prevents ordinary blocks for its duration
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})
Expand All @@ -1333,7 +1378,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
Expand Down Expand Up @@ -1524,18 +1569,16 @@ local configTable = {
end
end,
["svalinn cast on block"] = function(env) -- Svalinn Girded Tower Shield
env.player.mainSkill.skillFlags.globalTrigger = true
return {source = env.player.mainSkill,
return onBlockTrigger(env, {
triggeredSkillCond = function(env, skill)
return slotMatch(env, skill) and skill.triggeredBy and calcLib.canGrantedEffectSupportActiveSkill(skill.triggeredBy.grantedEffect, skill)
end}
end})
end,
["festering resentment cast on block"] = function(env) -- Festering Resentment Demon Dagger
env.player.mainSkill.skillFlags.globalTrigger = true
return {source = env.player.mainSkill,
return onBlockTrigger(env, {
triggeredSkillCond = function(env, skill)
return slotMatch(env, skill) and skill.triggeredBy and calcLib.canGrantedEffectSupportActiveSkill(skill.triggeredBy.grantedEffect, skill)
end}
end})
end,
["hex on trap"] = function(env) -- Hand of the Lords Carnal Mitts
return {triggerSkillCond = function(env, skill)
Expand Down
Loading