From aca4a4758782391e11efc73407d8bba484c32303 Mon Sep 17 00:00:00 2001 From: vaisest <4550061+vaisest@users.noreply.github.com> Date: Fri, 25 Sep 2026 14:59:33 +0300 Subject: [PATCH 1/3] Implement basic support for PoE2 cast on X triggers --- spec/System/TestTriggers_spec.lua | 373 ++++++- src/Data/ModCache.lua | 45 +- src/Data/SkillStatMap.lua | 52 + src/Modules/BuildDisplayStats.lua | 6 +- src/Modules/CalcBase.lua | 7 +- src/Modules/CalcMirages.lua | 422 -------- src/Modules/CalcOffence.lua | 41 +- src/Modules/CalcPerform.lua | 7 +- src/Modules/CalcSections.lua | 12 +- src/Modules/CalcSetup.lua | 3 + src/Modules/CalcTriggers.lua | 1662 +++++------------------------ src/Modules/Calcs.lua | 14 - src/Modules/Common.lua | 18 + src/Modules/ConfigOptions.lua | 10 + src/Modules/ModParser.lua | 9 + 15 files changed, 769 insertions(+), 1912 deletions(-) delete mode 100644 src/Modules/CalcMirages.lua diff --git a/spec/System/TestTriggers_spec.lua b/spec/System/TestTriggers_spec.lua index 91a9a56fdd..4e1fbeacb7 100644 --- a/spec/System/TestTriggers_spec.lua +++ b/spec/System/TestTriggers_spec.lua @@ -1,4 +1,43 @@ describe("TestTriggers", function() + -- Select an active skill within a socket group as the main skill + local function selectSkill(groupIndex, skillIndex) + local group = build.skillsTab.socketGroupList[groupIndex] + build.mainSocketGroup = groupIndex + build.calcsTab.input.skill_number = groupIndex + group.mainActiveSkill = skillIndex + group.mainActiveSkillCalcs = skillIndex + build.buildFlag = true + build.modFlag = true + runCallback("OnFrame") + build.calcsTab:BuildOutput() + runCallback("OnFrame") + end + + -- Equipping a weapon inserts a generated default attack group, shifting the indices + local function groupIndex(label) + for index, group in ipairs(build.skillsTab.socketGroupList) do + if group.displayLabel == label then + return index + end + end + end + + -- The same product reached by a different order of operations + local function assertNear(expected, actual) + assert.is_true(math.abs(expected - actual) <= math.abs(expected) * 1e-9, + ("expected %s, got %s"):format(tostring(expected), tostring(actual))) + end + + local function setConfig(var, value) + build.configTab.input[var] = value + build.configTab:BuildModList() + build.buildFlag = true + build.modFlag = true + runCallback("OnFrame") + build.calcsTab:BuildOutput() + runCallback("OnFrame") + end + before_each(function() newBuild() end) @@ -6,5 +45,335 @@ describe("TestTriggers", function() teardown(function() -- newBuild() takes care of resetting everything in setup() end) - -end) \ No newline at end of file + + describe("Meta gem Energy", function() + it("Maximum Energy is 100 per second of base cast time of the socketed skill", function() + build.skillsTab:PasteSocketGroup("Cast on Dodge 20/0 1\nSpark 20/0 1") + runCallback("OnFrame") + selectSkill(1, 2) + -- Spark has a 0.7 second base cast time and no added total cast time + assert.are.equals(70, build.calcsTab.mainOutput.MaxEnergy) + end) + + it("Modifiers to total cast time count double towards maximum Energy", function() + build.skillsTab:PasteSocketGroup("Cast on Dodge 20/0 1\nComet 20/0 1") + runCallback("OnFrame") + selectSkill(1, 2) + -- Comet is 1.00s base cast time plus 1.00s of added total cast time + assert.are.equals(100 * 1 + 200 * 1, build.calcsTab.mainOutput.MaxEnergy) + end) + + it("Maximum Energy is the total of every socketed skill", function() + build.skillsTab:PasteSocketGroup("Cast on Dodge 20/0 1\nComet 20/0 1\nSpark 20/0 1") + runCallback("OnFrame") + selectSkill(1, 2) + assert.are.equals(300 + 70, build.calcsTab.mainOutput.MaxEnergy) + end) + + it("All socketed skills trigger at the same rate", function() + build.skillsTab:PasteSocketGroup("Cast on Dodge 20/0 1\nComet 20/0 1\nSpark 20/0 1") + runCallback("OnFrame") + selectSkill(1, 2) + local cometRate = build.calcsTab.mainOutput.SkillTriggerRate + selectSkill(1, 3) + assert.are.equals(cometRate, build.calcsTab.mainOutput.SkillTriggerRate) + end) + + it("only reports a trigger rate cap for skills with a cooldown", function() + build.skillsTab:PasteSocketGroup("Cast on Dodge 20/0 1\nSpark 20/0 1") + runCallback("OnFrame") + selectSkill(1, 2) + assert.is_nil(build.calcsTab.mainOutput.TriggerRateCap) + end) + + it("falls back to self-cast for meta gems that are not supported", function() + build.skillsTab:PasteSocketGroup("Cast on Elemental Ailment 20/0 1\nComet 20/0 1") + runCallback("OnFrame") + selectSkill(1, 2) + local mainSkill = build.calcsTab.mainEnv.player.mainSkill + assert.is_nil(mainSkill.skillData.triggered) + assert.are.equals("Cast on Elemental Ailment is not supported yet", mainSkill.infoMessage) + assert.are.equals("DPS reported assuming Self-Cast", mainSkill.infoMessage2) + end) + + it("only parses Energy modifiers that apply to meta skills", function() + local mods = modLib.parseMod("Meta Skills gain 25% increased Energy while on Full Mana") + assert.are.equals("EnergyGenerated", mods[1].name) + assert.are.equals(25, mods[1].value) + for _, line in ipairs({ "Invocated skills have 30% increased Maximum Energy", "25% chance for Trigger skills to refund half of Energy Spent" }) do + for _, mod in ipairs(modLib.parseMod(line) or {}) do + assert.are_not.equals("EnergyGenerated", mod.name) + end + end + end) + end) + + describe("Cast on Dodge", function() + it("gains 2 Energy per whole metre travelled while dodge rolling", function() + build.skillsTab:PasteSocketGroup("Cast on Dodge 20/0 1\nSpark 20/0 1") + runCallback("OnFrame") + selectSkill(1, 2) + setConfig("dodgeRollsPerSecond", 1) + -- 4.6m base distance rounds down to 4m, 2 Energy each, +57% from gem level 20 + assertNear(2 * 1.57 * 4, build.calcsTab.mainOutput.EnergyPerSecond) + -- 70 Energy takes 23 metres, carried over between rolls. Energy past the maximum is discarded + assertNear(4 / 23, build.calcsTab.mainOutput.SkillTriggerRate) + end) + + it("adds the buff's dodge roll distance from additional quality effects", function() + build.spec:SelectClass(build.spec.tree.classNameMap.Mercenary) + for ascendClassId, ascendClass in pairs(build.spec.curClass.classes) do + if ascendClass.name == "Gemling Legionnaire" then + build.spec:SelectAscendClass(ascendClassId) + break + end + end + -- Advanced Thaumaturgy + local node = build.spec.nodes[14429] + node.alloc = true + build.spec.allocNodes[node.id] = node + build.skillsTab:PasteSocketGroup("Cast on Dodge 20/20 1\nSpark 20/0 1") + runCallback("OnFrame") + selectSkill(1, 2) + setConfig("dodgeRollsPerSecond", 1) + -- +1 metre from 20% quality, 5.6m rounds down to 5m + assertNear(2 * 5 * 1.57, build.calcsTab.mainOutput.EnergyPerSecond) + end) + + it("scales linearly with the number of dodge rolls per second", function() + build.skillsTab:PasteSocketGroup("Cast on Dodge 20/0 1\nSpark 20/0 1") + runCallback("OnFrame") + selectSkill(1, 2) + setConfig("dodgeRollsPerSecond", 1) + local baseRate = build.calcsTab.mainOutput.SkillTriggerRate + setConfig("dodgeRollsPerSecond", 2) + assert.are.equals(baseRate * 2, build.calcsTab.mainOutput.SkillTriggerRate) + end) + + it("does not lose a metre to floating point error", function() + build.configTab.input.customMods = "+0.1 metres to Dodge Roll distance\n+0.3 metres to Dodge Roll distance" + build.skillsTab:PasteSocketGroup("Cast on Dodge 20/0 1\nSpark 20/0 1") + runCallback("OnFrame") + selectSkill(1, 2) + setConfig("dodgeRollsPerSecond", 1) + -- 4.6 + 0.1 + 0.3 sums to 4.999... in floating point + assertNear(2 * 5 * 1.57, build.calcsTab.mainOutput.EnergyPerSecond) + end) + + it("scales distance with the square root of movement speed", function() + build.configTab.input.customMods = "44% increased Movement Speed" + build.skillsTab:PasteSocketGroup("Cast on Dodge 20/0 1\nSpark 20/0 1") + runCallback("OnFrame") + selectSkill(1, 2) + setConfig("dodgeRollsPerSecond", 1) + -- 4.6m * sqrt(1.44) = 5.52m rounds down to 5m + assertNear(2 * 5 * 1.57, build.calcsTab.mainOutput.EnergyPerSecond) + end) + + it("applies dodge roll distance as if you have Dodge Rolled Recently", function() + build.configTab.input.customMods = "+1 metre to Dodge Roll distance if you've Dodge Rolled Recently\n+2 metres to Dodge Roll distance if you haven't Dodge Rolled Recently" + build.skillsTab:PasteSocketGroup("Cast on Dodge 20/0 1\nSpark 20/0 1") + runCallback("OnFrame") + selectSkill(1, 2) + setConfig("dodgeRollsPerSecond", 1) + -- 4.6m + 1m rounds down to 5m + assertNear(2 * 5 * 1.57, build.calcsTab.mainOutput.EnergyPerSecond) + end) + + it("drives the triggered skill's cast rate", function() + build.skillsTab:PasteSocketGroup("Cast on Dodge 20/0 1\nSpark 20/0 1") + runCallback("OnFrame") + selectSkill(1, 2) + setConfig("dodgeRollsPerSecond", 1) + local output = build.calcsTab.mainOutput + assert.is_true(output.SkillTriggerRate > 0) + assert.are.equals(output.SkillTriggerRate, output.Speed) + end) + end) + + describe("Cast on Critical", function() + local function setupCastOnCritical() + build.skillsTab:PasteSocketGroup("Spark 20/0 1") + runCallback("OnFrame") + build.skillsTab:PasteSocketGroup("Cast on Critical 20/0 1\nComet 20/0 1") + runCallback("OnFrame") + selectSkill(2, 2) + end + + it("finds the Critical Hit source and reports it", function() + setupCastOnCritical() + assert.are.equals("Cast on Critical's Trigger: Spark", build.calcsTab.mainEnv.player.mainSkill.infoMessage) + assert.is_true(build.calcsTab.mainOutput.SkillTriggerRate > 0) + end) + + it("gains Energy per Monster Power scaled by the hit's share of the Ailment Threshold", function() + setupCastOnCritical() + setConfig("monsterPower", 20) + local output = build.calcsTab.mainOutput + + -- Recreate the source's contribution from its own cached output + local env = build.calcsTab.mainEnv + local sourceUUID = env.player.mainSkill.skillData.triggerSourceUUID + local cached = GlobalCache.cachedData[env.mode][sourceUUID] + local critDamage = 0 + for _, damageType in ipairs({"Physical", "Lightning", "Cold", "Fire", "Chaos"}) do + critDamage = critDamage + (cached.Env.player.output[damageType.."StoredCritAvg"] or 0) + end + local threshold = build.data.monsterAilmentThresholdTable[env.enemyLevel] + local critsPerSecond = (cached.HitSpeed or cached.Speed) * cached.CritChance / 100 + -- Energy gains round down to 0.01 + local energyPerCrit = math.floor(20 * critDamage / threshold * 1.57 * 100 + 1e-9) / 100 + + assertNear(energyPerCrit * critsPerSecond, output.EnergyPerSecond) + assertNear(critsPerSecond / math.ceil(300 / energyPerCrit), output.SkillTriggerRate) + end) + + it("scales with Monster Power", function() + setupCastOnCritical() + setConfig("monsterPower", 200) + local baseRate = build.calcsTab.mainOutput.SkillTriggerRate + setConfig("monsterPower", 100) + assert.is_true(build.calcsTab.mainOutput.SkillTriggerRate < baseRate) + end) + + it("applies the meta gem's 20% less Damage to socketed skills", function() + setupCastOnCritical() + local mainSkill = build.calcsTab.mainEnv.player.mainSkill + assert.are.equals(0.8, mainSkill.skillModList:More(mainSkill.skillCfg, "Damage")) + end) + + it("falls back to self-cast when nothing can Critically Hit", function() + build.skillsTab:PasteSocketGroup("Cast on Critical 20/0 1\nComet 20/0 1") + runCallback("OnFrame") + selectSkill(1, 2) + local mainSkill = build.calcsTab.mainEnv.player.mainSkill + assert.is_nil(mainSkill.skillData.triggered) + assert.are.equals("No Cast on Critical Triggering Skill Found", mainSkill.infoMessage) + assert.are.equals("DPS reported assuming Self-Cast", mainSkill.infoMessage2) + end) + + it("ignores hits from skills used by totems", function() + build.skillsTab:PasteSocketGroup("Spell Totem 20/0 1\nSpark 20/0 1") + runCallback("OnFrame") + build.skillsTab:PasteSocketGroup("Cast on Critical 20/0 1\nComet 20/0 1") + runCallback("OnFrame") + selectSkill(2, 2) + assert.are.equals("No Cast on Critical Triggering Skill Found", build.calcsTab.mainEnv.player.mainSkill.infoMessage) + end) + + it("counts every hit of the source's DPS multiplier", function() + setupCastOnCritical() + local baseEnergy = build.calcsTab.mainOutput.EnergyPerSecond + build.configTab.input.customMods = "100% more DPS" + setConfig("monsterPower", nil) + assertNear(baseEnergy * 2, build.calcsTab.mainOutput.EnergyPerSecond) + end) + end) + + describe("Spell on Melee Hit", function() + local function setupThundergodsWrath() + build.itemsTab:CreateDisplayItemFromRaw([[ + New Item + Wrapped Quarterstaff + Adds 200 to 300 Physical Damage + ]]) + build.itemsTab:AddDisplayItem() + runCallback("OnFrame") + build.skillsTab:PasteSocketGroup("Quarterstaff Strike 20/0 1") + runCallback("OnFrame") + build.skillsTab:PasteSocketGroup("Thundergod's Wrath 20/0 1\nSpark 20/0 1") + runCallback("OnFrame") + selectSkill(groupIndex("Thundergod's Wrath, Spark"), 2) + end + + it("gains Energy from the melee attack that hits", function() + setupThundergodsWrath() + assert.are.equals("Thundergod's Wrath's Trigger: Quarterstaff Strike", build.calcsTab.mainEnv.player.mainSkill.infoMessage) + assert.is_true(build.calcsTab.mainOutput.SkillTriggerRate > 0) + end) + + it("gains 3 Energy per Monster Power scaled by the hit's share of the Ailment Threshold", function() + setupThundergodsWrath() + setConfig("monsterPower", 20) + local env = build.calcsTab.mainEnv + local cached = GlobalCache.cachedData[env.mode][env.player.mainSkill.skillData.triggerSourceUUID] + local sourceOutput = cached.Env.player.output + local damage = 0 + for _, damageType in ipairs({"Physical", "Lightning", "Cold", "Fire", "Chaos"}) do + damage = damage + (sourceOutput.MainHand[damageType.."StoredCombinedAvg"] or 0) + end + local threshold = build.data.monsterAilmentThresholdTable[env.enemyLevel] + local hitsPerSecond = (cached.HitSpeed or cached.Speed) * sourceOutput.HitChance / 100 + local energyPerHit = math.floor(3 * 20 * damage / threshold * 1.57 * 100 + 1e-9) / 100 + assertNear(energyPerHit * hitsPerSecond, build.calcsTab.mainOutput.EnergyPerSecond) + assertNear(hitsPerSecond / math.ceil(70 / energyPerHit), build.calcsTab.mainOutput.SkillTriggerRate) + end) + + it("ignores sources that are not melee attacks", function() + build.skillsTab:PasteSocketGroup("Spark 20/0 1") + runCallback("OnFrame") + build.skillsTab:PasteSocketGroup("Thundergod's Wrath 20/0 1\nSpark 20/0 1") + runCallback("OnFrame") + selectSkill(groupIndex("Thundergod's Wrath, Spark"), 2) + assert.are.equals("No Thundergod's Wrath Triggering Skill Found", build.calcsTab.mainEnv.player.mainSkill.infoMessage) + end) + end) + + describe("Cast on Block", function() + local function setupCastOnBlock() + build.itemsTab:CreateDisplayItemFromRaw([[ + New Item + Effigial Tower Shield + Quality: 0 + ]]) + build.itemsTab:AddDisplayItem() + runCallback("OnFrame") + build.skillsTab:PasteSocketGroup("Cast on Block 20/0 1\nSpark 20/0 1") + runCallback("OnFrame") + selectSkill(groupIndex("Cast on Block, Spark"), 2) + end + + it("gains a flat 25 Energy per Block, with no Monster Power term", function() + setupCastOnBlock() + local blockChance = build.calcsTab.mainOutput.BlockChance + assert.is_true(blockChance > 0) + -- 25 Energy, +57% from gem level 20, at the default 700ms enemy attack time + local expected = 25 * 1.57 * (1000 / 700) * blockChance / 100 + assertNear(expected, build.calcsTab.mainOutput.EnergyPerSecond) + end) + + it("is unaffected by Monster Power", function() + setupCastOnBlock() + setConfig("monsterPower", 20) + local baseRate = build.calcsTab.mainOutput.SkillTriggerRate + setConfig("monsterPower", 1) + assert.are.equals(baseRate, build.calcsTab.mainOutput.SkillTriggerRate) + end) + + it("scales with how often the enemy attacks", function() + setupCastOnBlock() + setConfig("enemySpeed", 700) + local baseRate = build.calcsTab.mainOutput.SkillTriggerRate + setConfig("enemySpeed", 350) + assertNear(baseRate * 2, build.calcsTab.mainOutput.SkillTriggerRate) + end) + + it("falls back to self-cast when the enemy attack time is 0", function() + setupCastOnBlock() + setConfig("enemySpeed", 0) + local mainSkill = build.calcsTab.mainEnv.player.mainSkill + assert.is_nil(mainSkill.skillData.triggered) + assert.are.equals("Cast on Block gains no Energy from Blocks", mainSkill.infoMessage) + end) + end) + + describe("Cast on Charm Use", function() + it("gains 2 Energy per Charm Charge used", function() + build.skillsTab:PasteSocketGroup("Cast on Charm Use 20/0 1\nSpark 20/0 1") + runCallback("OnFrame") + selectSkill(groupIndex("Cast on Charm Use, Spark"), 2) + setConfig("multiplierCharmChargesUsedPerSecond", 10) + assertNear(2 * 1.57 * 10, build.calcsTab.mainOutput.EnergyPerSecond) + end) + end) +end) diff --git a/src/Data/ModCache.lua b/src/Data/ModCache.lua index 50484e61c0..a4a90ea806 100644 --- a/src/Data/ModCache.lua +++ b/src/Data/ModCache.lua @@ -86,14 +86,13 @@ c["+(9-14)% to Fire Resistance"]={nil,"+(9-14)% to Fire Resistance "} c["+(9-14)% to Lightning Resistance"]={nil,"+(9-14)% to Lightning Resistance "} c["+0.08% to Thorns Critical Hit Chance"]={{[1]={flags=32,keywordFlags=0,name="CritChance",type="BASE",value=0.08}},nil} c["+0.15% to Thorns Critical Hit Chance"]={{[1]={flags=32,keywordFlags=0,name="CritChance",type="BASE",value=0.15}},nil} -c["+0.2 metres to Dodge Roll distance"]={{}," metres to Dodge Roll distance "} +c["+0.2 metres to Dodge Roll distance"]={{[1]={flags=0,keywordFlags=0,name="DodgeRollDistance",type="BASE",value=0.2}},nil} c["+0.2 metres to Melee Strike Range"]={{[1]={flags=0,keywordFlags=0,name="MeleeWeaponRangeMetre",type="BASE",value=0.2},[2]={flags=0,keywordFlags=0,name="UnarmedRangeMetre",type="BASE",value=0.2}},nil} c["+0.3 metres to Melee Strike Range while Unarmed"]={{[1]={[1]={type="Condition",var="Unarmed"},flags=0,keywordFlags=0,name="MeleeWeaponRangeMetre",type="BASE",value=0.3},[2]={[1]={type="Condition",var="Unarmed"},flags=0,keywordFlags=0,name="UnarmedRangeMetre",type="BASE",value=0.3}},nil} c["+0.3% Critical Hit Chance per Power Charge"]={{[1]={[1]={type="Multiplier",var="PowerCharge"},flags=0,keywordFlags=0,name="CritChance",type="BASE",value=0.3}},nil} c["+0.4 metres to Melee Strike Range if you've dealt a Projectile Attack Hit in the past eight seconds"]={{[1]={[1]={type="Condition",var="HitProjectileRecently"},flags=0,keywordFlags=0,name="MeleeWeaponRangeMetre",type="BASE",value=0.4},[2]={[1]={type="Condition",var="HitProjectileRecently"},flags=0,keywordFlags=0,name="UnarmedRangeMetre",type="BASE",value=0.4}},nil} c["+0.4 metres to Melee Strike Range while Unarmed"]={{[1]={[1]={type="Condition",var="Unarmed"},flags=0,keywordFlags=0,name="MeleeWeaponRangeMetre",type="BASE",value=0.4},[2]={[1]={type="Condition",var="Unarmed"},flags=0,keywordFlags=0,name="UnarmedRangeMetre",type="BASE",value=0.4}},nil} -c["+0.5 metres to Dodge Roll distance while Surrounded"]={{}," metres to Dodge Roll distance "} -c["+0.5 metres to Dodge Roll distance while Surrounded 10% increased Movement Speed while Surrounded"]={{[1]={[1]={type="Condition",var="Surrounded"},[2]={type="Condition",var="Surrounded"},flags=0,keywordFlags=0,name="MovementSpeed",type="BASE",value=0.5}}," metres to Dodge Roll distance 10% increased "} +c["+0.5 metres to Dodge Roll distance while Surrounded"]={{[1]={[1]={type="Condition",var="Surrounded"},flags=0,keywordFlags=0,name="DodgeRollDistance",type="BASE",value=0.5}},nil} c["+0.5% to Thorns Critical Hit Chance per 50 Tribute"]={{[1]={[1]={actor="parent",div=50,stat="Tribute",type="PerStat"},flags=32,keywordFlags=0,name="CritChance",type="BASE",value=0.5}},nil} c["+0.6% to Unarmed Melee Attack Critical Hit Chance"]={{[1]={flags=16777477,keywordFlags=0,name="CritChance",type="BASE",value=0.6}},nil} c["+1 Charm Slot"]={{[1]={flags=0,keywordFlags=0,name="CharmLimit",type="BASE",value=1}},nil} @@ -108,8 +107,7 @@ c["+1 Ring Slot"]={{[1]={flags=0,keywordFlags=0,name="AdditionalRingSlot",type=" c["+1 Suffix Modifier allowed"]={{},nil} c["+1 Weapon Range per 10% Quality"]={{[1]={flags=0,keywordFlags=0,name="AlternateQualityLocalWeaponRangePer10Quality",type="BASE",value=1}},nil} c["+1 maximum stacks of Puppet Master"]={{}," maximum stacks of Puppet Master "} -c["+1 metre to Dodge Roll distance"]={{}," metre to Dodge Roll distance "} -c["+1 metre to Dodge Roll distance 50% increased Evasion Rating if you've Dodge Rolled Recently"]={{[1]={[1]={type="Condition",var="DodgeRolledRecently"},flags=0,keywordFlags=0,name="Evasion",type="BASE",value=1}}," metre to Dodge Roll distance 50% increased "} +c["+1 metre to Dodge Roll distance"]={{[1]={flags=0,keywordFlags=0,name="DodgeRollDistance",type="BASE",value=1}},nil} c["+1 second to Summon Skeleton Cooldown"]={{}," second to Summon Cooldown "} c["+1 to Armour per Strength"]={{[1]={[1]={stat="Str",type="PerStat"},flags=0,keywordFlags=0,name="Armour",type="BASE",value=1}},nil} c["+1 to Evasion Rating per 1 Item Armour on Equipped Gloves"]={{[1]={[1]={div=1,stat="ArmourOnGloves",type="PerStat"},flags=0,keywordFlags=0,name="Evasion",type="BASE",value=1}},nil} @@ -443,8 +441,7 @@ c["+2 Charm Slots"]={{[1]={flags=0,keywordFlags=0,name="CharmLimit",type="BASE", c["+2 Prefix Modifiers allowed"]={{},nil} c["+2 Suffix Modifiers allowed"]={{},nil} c["+2 maximum Energy Shield per 5 Strength"]={{[1]={[1]={div=5,stat="Str",type="PerStat"},flags=0,keywordFlags=0,name="EnergyShield",type="BASE",value=2}},nil} -c["+2 metres to Dodge Roll distance if you haven't Dodge Rolled Recently"]={{}," metres to Dodge Roll distance if you haven't Dodge Rolled Recently "} -c["+2 metres to Dodge Roll distance if you haven't Dodge Rolled Recently -1 metre to Dodge Roll distance if you've Dodge Rolled Recently"]={{}," metres to Dodge Roll distance if you haven't Dodge Rolled Recently -1 metre to Dodge Roll distance "} +c["+2 metres to Dodge Roll distance if you haven't Dodge Rolled Recently"]={{[1]={[1]={neg=true,type="Condition",var="DodgeRolledRecently"},flags=0,keywordFlags=0,name="DodgeRollDistance",type="BASE",value=2}},nil} c["+2 to Armour per 1 Item Energy Shield on Equipped Boots"]={{[1]={[1]={div=1,stat="EnergyShieldOnBoots",type="PerStat"},flags=0,keywordFlags=0,name="Armour",type="BASE",value=2}},nil} c["+2 to Dexterity per 25 Tribute"]={{[1]={[1]={actor="parent",div=25,stat="Tribute",type="PerStat"},flags=0,keywordFlags=0,name="Dex",type="BASE",value=2}},nil} c["+2 to Intelligence per 25 Tribute"]={{[1]={[1]={actor="parent",div=25,stat="Tribute",type="PerStat"},flags=0,keywordFlags=0,name="Int",type="BASE",value=2}},nil} @@ -1263,8 +1260,7 @@ c["+95 to maximum Life"]={{[1]={flags=0,keywordFlags=0,name="Life",type="BASE",v c["-0.2 seconds to current Energy Shield Recharge delay per Combo expended when using Skills"]={{[1]={flags=0,keywordFlags=0,name="EnergyShield",type="BASE",value=-0.2}}," seconds to current Recharge delay per Combo expended when using Skills "} c["-1 Prefix Modifier allowed"]={{},nil} c["-1 Suffix Modifier allowed"]={{},nil} -c["-1 metre to Dodge Roll distance if you've Dodge Rolled Recently"]={{}," metre to Dodge Roll distance "} -c["-1 metre to Dodge Roll distance if you've Dodge Rolled Recently Repeatable Attacks with this Bow Repeat +1 time if no enemies are in your Presence"]={{}," metre to Dodge Roll distance Repeatable Attacks with this Bow Repeat +1 time if no enemies are in your Presence "} +c["-1 metre to Dodge Roll distance if you've Dodge Rolled Recently"]={{[1]={[1]={type="Condition",var="DodgeRolledRecently"},flags=0,keywordFlags=0,name="DodgeRollDistance",type="BASE",value=-1}},nil} c["-1 second to base Energy Shield Recharge delay"]={{[1]={flags=0,keywordFlags=0,name="EnergyShieldRechargeFaster",type="BASE",value=-1}},nil} c["-1 to Maximum Frenzy Charges"]={{[1]={flags=0,keywordFlags=0,name="FrenzyChargesMax",type="BASE",value=-1}},nil} c["-1 to Maximum Power Charges"]={{[1]={flags=0,keywordFlags=0,name="PowerChargesMax",type="BASE",value=-1}},nil} @@ -5001,11 +4997,11 @@ c["75% increased Evasion Rating"]={{[1]={flags=0,keywordFlags=0,name="Evasion",t c["75% increased Mana Regeneration Rate"]={{[1]={flags=0,keywordFlags=0,name="ManaRegen",type="INC",value=75}},nil} c["75% increased Melee Damage with Spears while Surrounded"]={{[1]={[1]={type="Condition",var="Surrounded"},flags=268435716,keywordFlags=0,name="Damage",type="INC",value=75}},nil} c["75% increased Physical Damage"]={{[1]={flags=0,keywordFlags=0,name="PhysicalDamage",type="INC",value=75}},nil} -end)();(function() c["75% increased Spell Damage"]={{[1]={flags=2,keywordFlags=0,name="Damage",type="INC",value=75}},nil} c["75% increased Spirit"]={{[1]={flags=0,keywordFlags=0,name="Spirit",type="INC",value=75}},nil} c["75% increased Thorns damage if you've Blocked Recently"]={{[1]={[1]={type="Condition",var="BlockedRecently"},flags=32,keywordFlags=0,name="Damage",type="INC",value=75}},nil} c["75% increased chance to Shock"]={{[1]={flags=0,keywordFlags=0,name="EnemyShockChance",type="INC",value=75}},nil} +end)();(function() c["75% increased effect of Socketed Augment Items"]={{[1]={flags=0,keywordFlags=0,name="SocketedAugmentItemEffect",type="INC",value=75}},nil} c["75% more Stun Buildup with Lightning Damage"]={{[1]={[1]={type="Condition",var="LightningHasDamage"},flags=0,keywordFlags=0,name="EnemyHeavyStunBuildup",type="MORE",value=75}},nil} c["75% of Damage Converted to Fire Damage"]={{[1]={flags=0,keywordFlags=0,name="DamageConvertToFire",type="BASE",value=75}},nil} @@ -8590,21 +8586,18 @@ c["Melee Hits count as Rampage Kills Rampage"]={nil,"Melee Hits count as Rampage c["Melee Hits have 10% chance to Fortify"]={nil,"Melee Hits have 10% chance to Fortify "} c["Melee Hits which Stun Fortify"]={nil,"Melee Hits which Stun Fortify "} c["Mercury Footprints"]={nil,"Mercury Footprints "} -c["Meta Skills gain 0% reduced Energy"]={nil,"Meta Skills gain 0% reduced Energy "} -c["Meta Skills gain 13% increased Energy"]={nil,"Meta Skills gain 13% increased Energy "} -c["Meta Skills gain 15% increased Energy"]={nil,"Meta Skills gain 15% increased Energy "} -c["Meta Skills gain 16% increased Energy"]={nil,"Meta Skills gain 16% increased Energy "} -c["Meta Skills gain 16% increased Energy 2% increased Cast Speed per 20 Spirit"]={nil,"Meta Skills gain 16% increased Energy 2% increased Cast Speed per 20 Spirit "} -c["Meta Skills gain 20% increased Energy"]={nil,"Meta Skills gain 20% increased Energy "} -c["Meta Skills gain 25% increased Energy"]={nil,"Meta Skills gain 25% increased Energy "} -c["Meta Skills gain 25% increased Energy if you've dealt a Critical Hit Recently"]={nil,"Meta Skills gain 25% increased Energy if you've dealt a Critical Hit Recently "} -c["Meta Skills gain 25% increased Energy while on Full Mana"]={nil,"Meta Skills gain 25% increased Energy while on Full Mana "} -c["Meta Skills gain 35% more Energy"]={nil,"Meta Skills gain 35% more Energy "} -c["Meta Skills gain 35% more Energy Meta Skills have 50% increased Reservation Efficiency"]={nil,"Meta Skills gain 35% more Energy Meta Skills have 50% increased Reservation Efficiency "} -c["Meta Skills gain 4% increased Energy"]={nil,"Meta Skills gain 4% increased Energy "} -c["Meta Skills gain 4% increased Energy 5% increased Critical Hit Chance"]={nil,"Meta Skills gain 4% increased Energy 5% increased Critical Hit Chance "} -c["Meta Skills gain 6% increased Energy"]={nil,"Meta Skills gain 6% increased Energy "} -c["Meta Skills gain 8% increased Energy"]={nil,"Meta Skills gain 8% increased Energy "} +c["Meta Skills gain 0% reduced Energy"]={{[1]={[1]={skillType=122,type="SkillType"},flags=0,keywordFlags=0,name="EnergyGenerated",type="INC",value=-0}},nil} +c["Meta Skills gain 13% increased Energy"]={{[1]={[1]={skillType=122,type="SkillType"},flags=0,keywordFlags=0,name="EnergyGenerated",type="INC",value=13}},nil} +c["Meta Skills gain 15% increased Energy"]={{[1]={[1]={skillType=122,type="SkillType"},flags=0,keywordFlags=0,name="EnergyGenerated",type="INC",value=15}},nil} +c["Meta Skills gain 16% increased Energy"]={{[1]={[1]={skillType=122,type="SkillType"},flags=0,keywordFlags=0,name="EnergyGenerated",type="INC",value=16}},nil} +c["Meta Skills gain 20% increased Energy"]={{[1]={[1]={skillType=122,type="SkillType"},flags=0,keywordFlags=0,name="EnergyGenerated",type="INC",value=20}},nil} +c["Meta Skills gain 25% increased Energy"]={{[1]={[1]={skillType=122,type="SkillType"},flags=0,keywordFlags=0,name="EnergyGenerated",type="INC",value=25}},nil} +c["Meta Skills gain 25% increased Energy if you've dealt a Critical Hit Recently"]={{[1]={[1]={skillType=122,type="SkillType"},[2]={type="Condition",var="CritRecently"},flags=0,keywordFlags=0,name="EnergyGenerated",type="INC",value=25}},nil} +c["Meta Skills gain 25% increased Energy while on Full Mana"]={{[1]={[1]={skillType=122,type="SkillType"},[2]={type="Condition",var="FullMana"},flags=0,keywordFlags=0,name="EnergyGenerated",type="INC",value=25}},nil} +c["Meta Skills gain 35% more Energy"]={{[1]={[1]={skillType=122,type="SkillType"},flags=0,keywordFlags=0,name="EnergyGenerated",type="MORE",value=35}},nil} +c["Meta Skills gain 4% increased Energy"]={{[1]={[1]={skillType=122,type="SkillType"},flags=0,keywordFlags=0,name="EnergyGenerated",type="INC",value=4}},nil} +c["Meta Skills gain 6% increased Energy"]={{[1]={[1]={skillType=122,type="SkillType"},flags=0,keywordFlags=0,name="EnergyGenerated",type="INC",value=6}},nil} +c["Meta Skills gain 8% increased Energy"]={{[1]={[1]={skillType=122,type="SkillType"},flags=0,keywordFlags=0,name="EnergyGenerated",type="INC",value=8}},nil} c["Meta Skills gain 8% increased Energy for each Critical Hit you've dealt with Spells Recently"]={nil,"Meta Skills gain 8% increased Energy for each Critical Hit you've dealt with Spells Recently "} c["Meta Skills have 20% increased Reservation Efficiency"]={{[1]={[1]={skillType=122,type="SkillType"},flags=0,keywordFlags=0,name="ReservationEfficiency",type="INC",value=20}},nil} c["Meta Skills have 25% increased Reservation Efficiency"]={{[1]={[1]={skillType=122,type="SkillType"},flags=0,keywordFlags=0,name="ReservationEfficiency",type="INC",value=25}},nil} @@ -10003,7 +9996,6 @@ c["Your speed is Unaffected by Slows while Sprinting"]={nil,"Your speed is Unaff c["Your speed is Unaffected by Slows while Sprinting 10% less Movement and Skill Speed per Dodge Roll in the past 20 seconds"]={nil,"Your speed is Unaffected by Slows while Sprinting 10% less Movement and Skill Speed per Dodge Roll in the past 20 seconds "} c["Your speed is unaffected by Slows"]={{[1]={flags=0,keywordFlags=0,name="UnaffectedBySlows",type="FLAG",value=true}},nil} c["Your spells have 100% chance to Shock against Frozen Enemies"]={nil,"Your spells have 100% chance to Shock against Frozen Enemies "} -end)();(function() c["Zealot's Oath"]={{[1]={flags=0,keywordFlags=0,name="Keystone",type="LIST",value="Zealot's Oath"},[2]={flags=0,keywordFlags=0,name="Condition:HaveZealot'sOath",type="FLAG",value=true}},nil} c["Zealot's Oath during Effect"]={{[1]={[1]={type="Condition",var="UsingFlask"},flags=0,keywordFlags=0,name="ZealotsOath",type="FLAG",value=true}},nil} c["additional Elemental Infusion of the same type"]={nil,"additional Elemental Infusion of the same type "} @@ -10011,6 +10003,7 @@ c["additional Rune-only sockets:"]={{},nil} c["as being boosted by Chilled Ground"]={nil,"as being boosted by Chilled Ground "} c["as being boosted by Ignited Ground"]={nil,"as being boosted by Ignited Ground "} c["as being boosted by Ignited, Shocked, and Chilled Ground"]={nil,"as being boosted by Ignited, Shocked, and Chilled Ground "} +end)();(function() c["as being boosted by Shocked Ground"]={nil,"as being boosted by Shocked Ground "} c["being Shapeshifted for at least 8 seconds"]={nil,"being Shapeshifted for at least 8 seconds "} c["for 4 seconds, every 0.25 seconds while raised"]={nil,"for 4 seconds, every 0.25 seconds while raised "} diff --git a/src/Data/SkillStatMap.lua b/src/Data/SkillStatMap.lua index 3346810c6c..f60c626621 100644 --- a/src/Data/SkillStatMap.lua +++ b/src/Data/SkillStatMap.lua @@ -191,6 +191,58 @@ return function(mod, flag, skill) ["generic_ongoing_triggerer_is_invocation_skill"] = { flag("Condition:InvocationSkill"), }, +-- Meta gem Energy +["energy_generated_+%"] = { + mod("EnergyGenerated", "INC", nil), +}, +["generic_ongoing_trigger_triggers_at_maximum_energy"] = { + skill("triggersAtMaxEnergy", true), +}, +["generic_ongoing_trigger_maximum_energy_is_total_of_socketed_skills"] = { + skill("maxEnergyFromSocketedSkills", true), +}, +["generic_ongoing_trigger_maximum_energy"] = { + skill("maxEnergy", nil), +}, +-- Applied by the hidden support to each skill socketed in the meta gem +["generic_ongoing_trigger_1_maximum_energy_per_Xms_total_cast_time"] = { + skill("energyPerCastTimeMs", nil), +}, +["trigger_meta_gem_damage_+%_final"] = { + mod("Damage", "MORE", nil), +}, +["cast_on_dodge_dodge_roll_distance_granted_+"] = { + mod("DodgeRollDistance", "BASE", nil, 0, 0, { type = "GlobalEffect", effectType = "Buff" }), + div = 10, +}, +-- Energy that meta gems gain from this skill's hits +["active_skill_energy_generated_+%_final"] = { + mod("EnergyGeneratedFromSkill", "MORE", nil), +}, +["cast_on_crit_gain_X_centienergy_per_monster_power_on_crit"] = { + skill("energyPerPowerOnCrit", nil), + div = 100, +}, +["cast_on_dodge_roll_gain_X_centienergy_per_unit_travelled_while_dodge_rolling"] = { + skill("energyPerMetreDodgeRolling", nil), + div = 100, +}, +["cast_fire_spell_on_hit_gain_X_centienergy_per_monster_power_on_hit"] = { + skill("energyPerPowerOnMeleeHit", nil), + div = 100, +}, +["cast_lightning_spell_on_hit_gain_X_centienergy_per_monster_power_on_hit"] = { + skill("energyPerPowerOnMeleeHit", nil), + div = 100, +}, +["cast_on_block_gain_X_centienergy_on_block"] = { + skill("energyOnBlock", nil), + div = 100, +}, +["cast_on_using_charm_gain_X_centienergy_per_charm_charge_used_on_using_charm"] = { + skill("energyPerCharmCharge", nil), + div = 100, +}, ["base_skill_cost_life_instead_of_mana_%"] = { mod("HybridManaAndLifeCost_Life", "BASE", nil), }, diff --git a/src/Modules/BuildDisplayStats.lua b/src/Modules/BuildDisplayStats.lua index 1547d24501..f7103f60f5 100644 --- a/src/Modules/BuildDisplayStats.lua +++ b/src/Modules/BuildDisplayStats.lua @@ -82,21 +82,17 @@ local displayStats = { { stat = "IgniteDPS", label = "Ignite DPS", fmt = ".1f", compPercent = true, warnFunc = function(v) return v >= data.misc.DotDpsCap and "Ignite DPS exceeds in game limit" end }, { stat = "IgniteDamage", label = "Total Damage per Ignite", fmt = ".1f", compPercent = true, flag = "showAverage" }, { stat = "BurningGroundDPS", label = "Burning Ground DPS", fmt = ".1f", compPercent = true, warnFunc = function(v,o) return v >= data.misc.DotDpsCap and "Burning Ground DPS exceeds in game limit" end }, - { stat = "MirageBurningGroundDPS", label = "Mirage Burning Ground DPS", fmt = ".1f", compPercent = true, condFunc = function(v,o) return v ~= o.BurningGroundDPS end, warnFunc = function(v,o) return v >= data.misc.DotDpsCap and "Mirage Burning Ground DPS exceeds in game limit" end }, { stat = "WithIgniteDPS", label = "Total DPS inc. Ignite", fmt = ".1f", compPercent = true, flag = "notAverage", condFunc = function(v,o) return v ~= o.TotalDPS and (o.TotalDot or 0) == 0 and (o.PoisonDPS or 0) == 0 and (o.ImpaleDPS or 0) == 0 and (o.BleedDPS or 0) == 0 end }, { stat = "PoisonDPS", label = "Poison DPS", fmt = ".1f", compPercent = true, warnFunc = function(v) return v >= data.misc.DotDpsCap and "Poison DPS exceeds in game limit" end }, { stat = "CausticGroundDPS", label = "Caustic Ground DPS", fmt = ".1f", compPercent = true, warnFunc = function(v,o) return v >= data.misc.DotDpsCap and "Caustic Ground DPS exceeds in game limit" end }, - { stat = "MirageCausticGroundDPS", label = "Mirage Caustic Ground DPS", fmt = ".1f", compPercent = true, condFunc = function(v,o) return v ~= o.CausticGroundDPS end, warnFunc = function(v,o) return v >= data.misc.DotDpsCap and "Mirage Caustic Ground DPS exceeds in game limit" end }, { stat = "PoisonDamage", label = "Total Damage per Poison", fmt = ".1f", compPercent = true, flag = "showAverage" }, { stat = "WithPoisonDPS", label = "Total DPS inc. Poison", fmt = ".1f", compPercent = true, flag = "notAverage", condFunc = function(v,o) return v ~= o.TotalDPS and (o.TotalDot or 0) == 0 and (o.IgniteDPS or 0) == 0 and (o.ImpaleDPS or 0) == 0 and (o.BleedDPS or 0) == 0 end }, { stat = "DecayDPS", label = "Decay DPS", fmt = ".1f", compPercent = true }, - { stat = "TotalDotDPS", label = "Total DoT DPS", fmt = ".1f", compPercent = true, condFunc = function(v,o) return o.showTotalDotDPS or ( v ~= o.TotalDot and v ~= o.TotalPoisonDPS and v ~= o.CausticGroundDPS and v ~= (o.TotalIgniteDPS or o.IgniteDPS) and v ~= o.BurningGroundDPS and v ~= o.BleedDPS and v~= o.CorruptingBloodDPS and v ~= o.MirageCausticGroundDPS and v ~= o.MirageBurningGroundDPS) end, warnFunc = function(v) return v >= data.misc.DotDpsCap and "DoT DPS exceeds in game limit" end }, + { stat = "TotalDotDPS", label = "Total DoT DPS", fmt = ".1f", compPercent = true, condFunc = function(v,o) return o.showTotalDotDPS or ( v ~= o.TotalDot and v ~= o.TotalPoisonDPS and v ~= o.CausticGroundDPS and v ~= (o.TotalIgniteDPS or o.IgniteDPS) and v ~= o.BurningGroundDPS and v ~= o.BleedDPS and v~= o.CorruptingBloodDPS) end, warnFunc = function(v) return v >= data.misc.DotDpsCap and "DoT DPS exceeds in game limit" end }, { stat = "ImpaleDPS", label = "Impale Damage", fmt = ".1f", compPercent = true, flag = "impale", flag = "showAverage" }, { stat = "WithImpaleDPS", label = "Damage inc. Impale", fmt = ".1f", compPercent = true, flag = "impale", flag = "showAverage", condFunc = function(v,o) return v ~= o.TotalDPS and (o.TotalDot or 0) == 0 and (o.IgniteDPS or 0) == 0 and (o.PoisonDPS or 0) == 0 and (o.BleedDPS or 0) == 0 end }, { stat = "ImpaleDPS", label = "Impale DPS", fmt = ".1f", compPercent = true, flag = "impale", flag = "notAverage" }, { stat = "WithImpaleDPS", label = "Total DPS inc. Impale", fmt = ".1f", compPercent = true, flag = "impale", flag = "notAverage", condFunc = function(v,o) return v ~= o.TotalDPS and (o.TotalDot or 0) == 0 and (o.IgniteDPS or 0) == 0 and (o.PoisonDPS or 0) == 0 and (o.BleedDPS or 0) == 0 end }, - { stat = "MirageDPS", label = "Total Mirage DPS", fmt = ".1f", compPercent = true, flag = "mirageArcher", condFunc = function(v,o) return v > 0 end }, - { stat = "MirageDPS", label = "Total Wisp DPS", fmt = ".1f", compPercent = true, flag = "wisp", condFunc = function(v,o) return v > 0 end }, { stat = "CullingDPS", label = "Culling DPS", fmt = ".1f", compPercent = true, condFunc = function(v,o) return (o.CullingDPS or 0) > 0 end }, { stat = "ReservationDPS", label = "Reservation DPS", fmt = ".1f", compPercent = true, condFunc = function(v,o) return (o.ReservationDPS or 0) > 0 end }, { stat = "CombinedDPS", label = "Combined DPS", fmt = ".1f", compPercent = true, flag = "notAverage", condFunc = function(v,o) return v ~= ((o.TotalDPS or 0) + (o.TotalDot or 0)) and v ~= o.WithImpaleDPS and ( o.showTotalDotDPS or ( v ~= o.WithPoisonDPS and v ~= o.WithIgniteDPS and v ~= o.WithBleedDPS ) ) end }, diff --git a/src/Modules/CalcBase.lua b/src/Modules/CalcBase.lua index c79fd05666..7dedffacbd 100644 --- a/src/Modules/CalcBase.lua +++ b/src/Modules/CalcBase.lua @@ -15,17 +15,20 @@ return calcs ---@field BattleMageCryDuration number? ---@field BattlemageUpTimeRatio number? ---@field BleedDamage number? +---@field BlockChance number? ---@field ChaosHitAverage number? ---@field ChaosResist number? ---@field ColdHitAverage number? ---@field ColdResistOverCap number? ---@field ColdResistTotal number? +---@field CritChance number? ---@field CullMultiplier number? ---@field Dex number? ---@field EffectiveBlockChance number? ---@field EffectiveProjectileBlockChance number? ---@field EffectiveSpellBlockChance number? ---@field EffectiveSpellProjectileBlockChance number? +---@field EnergyPerSecond number? ---@field EnergyShieldLeechDuration number? ---@field EnergyShieldRecoupRecoveryAvg number? ---@field EnergyShieldRegenRecovery number? @@ -63,6 +66,7 @@ return calcs ---@field ManaRecoupRecoveryAvg number? ---@field ManaRegenRecovery number? ---@field ManaUnreserved number? +---@field MaxEnergy number? ---@field PhysicalTakenDamage number? ---@field PhysicalTakenHit number? ---@field PoisonAvoidChance number? @@ -73,10 +77,12 @@ return calcs ---@field SelfIgniteEffect number? ---@field SelfPoisonDuration number? ---@field SelfPoisonEffect number? +---@field SkillTriggerRate number? ---@field Str number? ---@field TotalVaalRejuvenationTotemLife number? ---@field TotemChaosResist number? ---@field TotemLife number? +---@field TriggerRateCap number? ---@class Breakdown ---@field MainHand Breakdown? @@ -149,7 +155,6 @@ return calcs ---@field weapon2Flags number ---@field minion? Actor ---@field minionList? string[] ----@field mirage? table ---@field slotName? string ---@field skillPart? number ---@field skillPartName? string diff --git a/src/Modules/CalcMirages.lua b/src/Modules/CalcMirages.lua deleted file mode 100644 index 83908fb4fb..0000000000 --- a/src/Modules/CalcMirages.lua +++ /dev/null @@ -1,422 +0,0 @@ --- Path of Building --- --- Module: Calc Mirages --- Handles mirages that use player skills --- - ----@class Calcs -local calcs = require("Modules.CalcBase") -local pairs = pairs -local ipairs = ipairs -local t_insert = table.insert -local t_remove = table.remove -local m_min = math.min -local m_max = math.max -local m_ceil = math.ceil -local m_floor = math.floor -local m_modf = math.modf -local s_format = string.format -local m_huge = math.huge -local bor = OR64 -- bit.bor -local band = AND64 -- bit.band - -local function calculateMirage(env, config) - if not config then - return - end - - local mirageSkill = nil - - if config.compareFunc then - for _, skill in ipairs(env.player.activeSkillList) do - if not skill.skillCfg.skillCond["usedByMirage"] then - mirageSkill = config.compareFunc(skill, env, config, mirageSkill) - end - end - end - - if mirageSkill then - local newSkill, newEnv = calcs.copyActiveSkill(env, env.mode, mirageSkill) - newSkill.skillCfg.skillCond["usedByMirage"] = true - newEnv.limitedSkills = newEnv.limitedSkills or {} - newEnv.limitedSkills[cacheSkillUUID(newSkill, newEnv)] = true - newSkill.skillData.mirageUses = env.player.mainSkill.skillData.storedUses - newSkill.skillTypes[SkillType.OtherThingUsesSkill] = true - - config.preCalcFunc(env, newSkill, newEnv) - - newEnv.player.mainSkill = newSkill - calcs.perform(newEnv) - config.postCalcFunc(env, newSkill, newEnv) - else - config.mirageSkillNotFoundFunc(env, config) - end - return not config.calcMainSkillOffence -end - -function calcs.mirages(env) - local config - - if env.player.mainSkill.skillCfg.skillCond["usedByMirage"] or env.player.mainSkill.skillFlags.disable then - return - end - - if env.player.mainSkill.skillData.triggeredByMirageArcher then - config = { - calcMainSkillOffence = true, - compareFunc = function(skill, env, config, mirageSkill) - if not env.player.mainSkill.skillCfg.skillCond["usedByMirage"] and env.player.weaponData1.type == "Bow" then - return env.player.mainSkill - end - end, - preCalcFunc = function(env, newSkill, newEnv) - local moreDamage = newSkill.skillModList:Sum("BASE", newSkill.skillCfg, "MirageArcherLessDamage") - local moreAttackSpeed = newSkill.skillModList:Sum("BASE", newSkill.skillCfg, "MirageArcherLessAttackSpeed") - local mirageCount = newSkill.skillModList:Sum("BASE", env.player.mainSkill.skillCfg, "MirageArcherMaxCount") - - env.player.mainSkill.mirage = { } - env.player.mainSkill.mirage.name = newSkill.activeEffect.grantedEffect.name - env.player.mainSkill.mirage.count = mirageCount - - if not env.player.mainSkill.infoMessage then - env.player.mainSkill.infoMessage = tostring(mirageCount) .. " Mirage Archers using " .. newSkill.activeEffect.grantedEffect.name - end - - -- Add new modifiers to new skill (which already has all the old skill's modifiers) - newSkill.skillModList:NewMod("Damage", "MORE", moreDamage, "Mirage Archer", env.player.mainSkill.ModFlags, env.player.mainSkill.KeywordFlags) - newSkill.skillModList:NewMod("Speed", "MORE", moreAttackSpeed, "Mirage Archer", env.player.mainSkill.ModFlags, env.player.mainSkill.KeywordFlags) - - -- Does not use player resources - newSkill.skillModList:NewMod("HasNoCost", "FLAG", true, "Used by mirage") - - if newSkill.skillPartName then - env.player.mainSkill.mirage.skillPart = newSkill.skillPart - env.player.mainSkill.mirage.skillPartName = newSkill.skillPartName - env.player.mainSkill.mirage.infoMessage2 = newSkill.activeEffect.grantedEffect.name - else - env.player.mainSkill.mirage.skillPartName = nil - end - end, - postCalcFunc = function(env, newSkill, newEnv) - env.player.mainSkill.mirage.output = newEnv.player.output - env.player.mainSkill.skillFlags.mirageArcher = true - if newSkill.minion then - env.player.mainSkill.mirage.minion = {} - env.player.mainSkill.mirage.minion.output = newEnv.minion.output - end - - if newEnv.player.breakdown then - env.player.mainSkill.mirage.breakdown = newEnv.player.breakdown - if newSkill.minion then - env.player.mainSkill.mirage.minion.breakdown = newEnv.minion.breakdown - end - end - end, - mirageSkillNotFoundFunc = function(env, config) - if not env.player.mainSkill.infoMessage2 then - env.player.mainSkill.infoMessage2 = "No Mirage Archer active skill found" - end - end - } - elseif env.player.mainSkill.activeEffect.grantedEffect.name == "Reflection" then - local usedSkillBestDps - local maxMirageWarriors = env.player.mainSkill.skillModList:Sum("BASE", env.player.mainSkill.skillCfg, "SaviourMirageWarriorMaxCount") - config = { - compareFunc = function(skill, env, config, mirageSkill) - if skill ~= env.player.mainSkill and skill.skillTypes[SkillType.Attack] and not skill.skillTypes[SkillType.Totem] and not skill.skillTypes[SkillType.SummonsTotem] and band(skill.skillCfg.flags, bor(ModFlag.Sword, ModFlag.Weapon1H)) == bor(ModFlag.Sword, ModFlag.Weapon1H) and not skill.skillCfg.skillCond["usedByMirage"] then - local uuid = cacheSkillUUID(skill, env) - if not GlobalCache.cachedData[env.mode][uuid] then - calcs.buildActiveSkill(env, env.mode, skill, uuid) - end - - if GlobalCache.cachedData[env.mode][uuid] and GlobalCache.cachedData[env.mode][uuid].CritChance and GlobalCache.cachedData[env.mode][uuid].CritChance > 0 then - if not mirageSkill then - usedSkillBestDps = GlobalCache.cachedData[env.mode][uuid].TotalDPS - return GlobalCache.cachedData[env.mode][uuid].ActiveSkill - elseif GlobalCache.cachedData[env.mode][uuid].TotalDPS > usedSkillBestDps then - usedSkillBestDps = GlobalCache.cachedData[env.mode][uuid].TotalDPS - return GlobalCache.cachedData[env.mode][uuid].ActiveSkill - end - end - end - return mirageSkill - end, - preCalcFunc = function(env, newSkill, newEnv) - local moreDamage = env.player.mainSkill.skillModList:Sum("BASE", env.player.mainSkill.skillCfg, "SaviourMirageWarriorLessDamage") - -- Add new modifiers to new skill (which already has all the old skill's modifiers) - newSkill.skillModList:NewMod("Damage", "MORE", moreDamage, "The Saviour", env.player.mainSkill.ModFlags, env.player.mainSkill.KeywordFlags) - if env.player.itemList["Weapon 1"] and env.player.itemList["Weapon 2"] and env.player.itemList["Weapon 1"].name == env.player.itemList["Weapon 2"].name then - maxMirageWarriors = maxMirageWarriors / 2 - end - newSkill.skillModList:NewMod("QuantityMultiplier", "BASE", maxMirageWarriors, "The Saviour Mirage Warriors", env.player.mainSkill.ModFlags, env.player.mainSkill.KeywordFlags) - -- Does not use player resources - newSkill.skillModList:NewMod("HasNoCost", "FLAG", true, "Used by mirage") - end, - postCalcFunc = function(env, newSkill, newEnv) - env.player.mainSkill = newSkill - env.player.mainSkill.infoMessage = tostring(maxMirageWarriors) .. " Mirage Warriors using " .. newSkill.activeEffect.grantedEffect.name - - -- Re-link over the output - env.player.output = newEnv.player.output - if newSkill.minion then - env.minion = newEnv.player.mainSkill.minion - env.minion.output = newEnv.minion.output - end - - -- Re-link over the breakdown (if present) - if newEnv.player.breakdown then - env.player.breakdown = newEnv.player.breakdown - if newSkill.minion then - env.minion.breakdown = newEnv.minion.breakdown - end - end - end, - mirageSkillNotFoundFunc = function(env, config) - env.player.mainSkill.disableReason = "No Saviour active skill found" - env.player.mainSkill.skillFlags.disable = true - end - } - elseif env.player.mainSkill.activeEffect.grantedEffect.name == "Tawhoa's Chosen" then - local usedSkillBestDps - local EffectiveSourceRate - - local triggerCD - local triggerCDAdjusted - local triggerCDTickRounded - local triggeredCD - local triggeredCDAdjusted - local triggeredCDTickRounded - local icdrSkill - local TriggerRateCap - local actionCooldown - local SkillTriggerRate - - config = { - compareFunc = function(skill, env, config, mirageSkill) - local isDisabled = skill.skillFlags and skill.skillFlags.disable - local skillTypeMatch = (skill.skillTypes[SkillType.Slam] or skill.skillTypes[SkillType.Melee]) and skill.skillTypes[SkillType.Attack] - local skillTypeExcludes = skill.skillTypes[SkillType.Vaal] or skill.skillTypes[SkillType.Totem] or skill.skillTypes[SkillType.SummonsTotem] - if skill ~= env.player.mainSkill and not isTriggered(skill) and not isDisabled and skillTypeMatch and not skillTypeExcludes and not skill.skillCfg.skillCond["usedByMirage"] then - local uuid = cacheSkillUUID(skill, env) - if not GlobalCache.cachedData[env.mode][uuid] or env.mode == "CALCULATOR" then - calcs.buildActiveSkill(env, env.mode, skill, uuid) - end - - if not mirageSkill or (GlobalCache.cachedData[env.mode][uuid] and GlobalCache.cachedData[env.mode][uuid].TotalDPS > usedSkillBestDps) then - usedSkillBestDps = GlobalCache.cachedData[env.mode][uuid].TotalDPS - EffectiveSourceRate = GlobalCache.cachedData[env.mode][uuid].Speed - return GlobalCache.cachedData[env.mode][uuid].ActiveSkill - end - end - return mirageSkill - end, - preCalcFunc = function(env, newSkill, newEnv) - icdrSkill = calcLib.mod(newSkill.skillModList, newSkill.skillCfg, "CooldownRecovery") - - triggeredCD = newSkill.skillData.cooldown or 0 - triggeredCDAdjusted = triggeredCD / icdrSkill - triggeredCDTickRounded = m_ceil(triggeredCDAdjusted * data.misc.ServerTickRate) / data.misc.ServerTickRate - - triggerCD = env.player.mainSkill.skillData.cooldown or 0 - triggerCDAdjusted = triggerCD / icdrSkill - triggerCDTickRounded = m_ceil(triggerCDAdjusted * data.misc.ServerTickRate) / data.misc.ServerTickRate - - actionCooldown = m_max( triggeredCDTickRounded or 0, triggerCDTickRounded or 0 ) - - TriggerRateCap = m_huge - if actionCooldown ~= 0 then - TriggerRateCap = 1 / actionCooldown - end - - SkillTriggerRate = EffectiveSourceRate ~= 0 and calcMultiSpellRotationImpact(env, {{ uuid = cacheSkillUUID(env.player.mainSkill, env), cd = triggeredCD, icdr = icdrSkill }}, EffectiveSourceRate, triggerCD) or 0 - - -- Override attack speed with trigger rate - newSkill.skillData.triggerRate = SkillTriggerRate - newSkill.skillData.triggered = true - newSkill.skillFlags.triggered = true - - -- Does not use player resources - newSkill.skillModList:NewMod("HasNoCost", "FLAG", true, "Used by Tawhoa's Chosen") - - local moreDamage = env.player.mainSkill.skillModList:Sum("BASE", env.player.mainSkill.skillCfg, "ChieftainMirageChieftainMoreDamage") - -- Add new modifiers to new skill (which already has all the old skill's modifiers) - newSkill.skillModList:NewMod("Damage", "MORE", moreDamage, "Tawhoa's Chosen", env.player.mainSkill.ModFlags, env.player.mainSkill.KeywordFlags) - end, - postCalcFunc = function(env, newSkill, newEnv) - env.player.mainSkill = newSkill - env.player.mainSkill.infoMessage = "Tawhoa's Chosen using " .. newSkill.activeEffect.grantedEffect.name - - env.player.output = newEnv.player.output - env.player.output.Speed = SkillTriggerRate - env.player.output.TriggerRateCap = TriggerRateCap - env.player.output.EffectiveSourceRate = EffectiveSourceRate - env.player.output.SkillTriggerRate = SkillTriggerRate - - if newEnv.player.breakdown then - if triggeredCD ~= 0 then - newEnv.player.breakdown.TriggerRateCap = { - s_format("%.2f ^8(base cooldown of triggered skill)", triggeredCD), - s_format("/ %.2f ^8(increased/reduced cooldown recovery)", icdrSkill), - s_format("= %.2f ^8(final cooldown of triggered skill)", triggeredCDAdjusted), - "", - s_format("%.2f ^8(Tawhoa's Chosen base cooldown)", triggerCD), - s_format("/ %.2f ^8(increased/reduced cooldown recovery)", icdrSkill), - s_format("= %.2f ^8(effective trigger cooldown)", triggerCDAdjusted), - "", - s_format("%.2f ^8(biggest of trigger cooldown and triggered skill cooldown)", m_max(triggerCDAdjusted, triggeredCDAdjusted)), - "", - s_format("%.2f ^8(adjusted for server tick rate)", actionCooldown), - "", - "Trigger rate:", - s_format("1 / %.3f", actionCooldown), - s_format("= %.2f ^8per second", TriggerRateCap), - } - else - newEnv.player.breakdown.TriggerRateCap = { - "Triggered skill has no base cooldown", - "", - s_format("%.2f ^8(Tawhoa's Chosen base cooldown)", triggerCD), - s_format("/ %.2f ^8(increased/reduced cooldown recovery)", icdrSkill), - s_format("= %.2f ^8(effective trigger cooldown)", triggerCDAdjusted), - "", - s_format("%.2f ^8(adjusted for server tick rate)", actionCooldown), - "", - "Trigger rate:", - s_format("1 / %.3f", actionCooldown), - s_format("= %.2f ^8per second", TriggerRateCap), - } - end - - env.player.breakdown = newEnv.player.breakdown - end - end, - mirageSkillNotFoundFunc = function(env, config) - env.player.mainSkill.disableReason = "No Tawhoa's Chosen active skill found" - env.player.mainSkill.skillFlags.disable = true - end - } - elseif env.player.mainSkill.skillData.triggeredBySacredWisps then - config = { - calcMainSkillOffence = true, - compareFunc = function(skill, env, config, mirageSkill) - if not env.player.mainSkill.skillCfg.skillCond["usedByMirage"] and env.player.weaponData1.type == "Wand" then - return env.player.mainSkill - end - end, - preCalcFunc = function(env, newSkill, newEnv) - local lessDamage = newSkill.skillModList:Sum("BASE", env.player.mainSkill.skillCfg, "SacredWispsLessDamage") - local wispsMaxCount - local wispsCastChance - - -- Find Wisps summoning skill for cast chance and wisp count - for _, skill in ipairs(env.player.activeSkillList) do - if skill.activeEffect.grantedEffect.name == "Summon Sacred Wisps" then - wispsCastChance = skill.skillModList:Sum("BASE", env.player.mainSkill.skillCfg, "SacredWispsChance") - wispsMaxCount = skill.skillModList:Sum("BASE", env.player.mainSkill.skillCfg, "SacredWispsMaxCount") - break - end - end - - env.player.mainSkill.mirage = { } - env.player.mainSkill.mirage.name = newSkill.activeEffect.grantedEffect.name - env.player.mainSkill.mirage.count = wispsMaxCount - - if not env.player.mainSkill.infoMessage then - env.player.mainSkill.infoMessage = tostring(wispsMaxCount) .. " Sacred Wisps using " .. newSkill.activeEffect.grantedEffect.name - end - - -- Add new modifiers to new skill (which already has all the old skill's modifiers) - newSkill.skillModList:NewMod("Damage", "MORE", lessDamage, "Used by Sacred Wisps", env.player.mainSkill.ModFlags, env.player.mainSkill.KeywordFlags) - newSkill.skillModList:NewMod("Speed", "MORE", wispsCastChance - 100, "Sacred Wisps cast chance", env.player.mainSkill.ModFlags, env.player.mainSkill.KeywordFlags) - - -- Does not use player resources - newSkill.skillModList:NewMod("HasNoCost", "FLAG", true, "Used by Sacred Wisps") - - if newSkill.skillPartName then - env.player.mainSkill.mirage.skillPart = newSkill.skillPart - env.player.mainSkill.mirage.skillPartName = newSkill.skillPartName - env.player.mainSkill.mirage.infoMessage2 = newSkill.activeEffect.grantedEffect.name - else - env.player.mainSkill.mirage.skillPartName = nil - end - end, - postCalcFunc = function(env, newSkill, newEnv) - env.player.mainSkill.mirage.output = newEnv.player.output - env.player.mainSkill.skillFlags.wisp = true - if newSkill.minion then - env.player.mainSkill.mirage.minion = {} - env.player.mainSkill.mirage.minion.output = newEnv.minion.output - end - - if newEnv.player.breakdown then - env.player.mainSkill.mirage.breakdown = newEnv.player.breakdown - if newSkill.minion then - env.player.mainSkill.mirage.minion.breakdown = newEnv.minion.breakdown - end - end - end, - mirageSkillNotFoundFunc = function(env, config) - if not env.player.mainSkill.infoMessage2 then - env.player.mainSkill.infoMessage2 = "No active skill for Sacred Wisps found" - end - end - } - elseif env.player.mainSkill.skillData.triggeredByGeneralsCry then - env.player.mainSkill[SkillType.Triggered] = true - local maxMirageWarriors = 0 - local cooldown = 1 - local generalsCryActiveSkill - - -- Find the active General's Cry gem to get active properties - for _, skill in ipairs(env.player.activeSkillList) do - if skill.activeEffect.grantedEffect.name == "General's Cry" and env.player.mainSkill.socketGroup.slot == env.player.mainSkill.socketGroup.slot then - cooldown = calcSkillCooldown(skill.skillModList, skill.skillCfg, skill.skillData) - generalsCryActiveSkill = skill - break - end - end - - -- Scale dps with GC's cooldown - env.player.mainSkill.skillData.dpsMultiplier = (env.player.mainSkill.skillData.dpsMultiplier or 1) * (1 / cooldown) - - -- Does not use player resources - env.player.mainSkill.skillModList:NewMod("HasNoCost", "FLAG", true, "Used by mirage") - - -- Non-channelled skills only attack once, disregard attack rate - if not env.player.mainSkill.skillTypes[SkillType.Channel] then - env.player.mainSkill.skillData.timeOverride = 1 - end - - -- Supported Attacks Count as Exerted - for _, value in ipairs(env.player.mainSkill.skillModList:Tabulate("INC", env.player.mainSkill.skillCfg, "ExertIncrease")) do - local mod = value.mod - env.player.mainSkill.skillModList:NewMod("Damage", mod.type, mod.value, mod.source, mod.flags, mod.keywordFlags) - end - for _, value in ipairs(env.player.mainSkill.skillModList:Tabulate("MORE", env.player.mainSkill.skillCfg, "ExertIncrease")) do - local mod = value.mod - env.player.mainSkill. skillModList:NewMod("Damage", mod.type, mod.value, mod.source, mod.flags, mod.keywordFlags) - end - for _, value in ipairs(env.player.mainSkill.skillModList:Tabulate("MORE", env.player.mainSkill.skillCfg, "ExertAttackIncrease")) do - local mod = value.mod - env.player.mainSkill.skillModList:NewMod("Damage", mod.type, mod.value, mod.source, mod.flags, mod.keywordFlags) - end - for _, value in ipairs(env.player.mainSkill.skillModList:Tabulate("MORE", env.player.mainSkill.skillCfg, "OverexertionExertAverageIncrease")) do - local mod = value.mod - env.player.mainSkill.skillModList:NewMod("Damage", mod.type, mod.value, mod.source, mod.flags, mod.keywordFlags) - end - for _, value in ipairs(env.player.mainSkill.skillModList:Tabulate("BASE", env.player.mainSkill.skillCfg, "ExertDoubleDamageChance")) do - local mod = value.mod - env.player.mainSkill.skillModList:NewMod("DoubleDamageChance", mod.type, mod.value, mod.source, mod.flags, mod.keywordFlags) - end - - -- Scale dps with mirage quantity - for _, value in ipairs(generalsCryActiveSkill.skillModList:Tabulate("BASE", generalsCryActiveSkill.skillCfg, "GeneralsCryDoubleMaxCount")) do - local mod = value.mod - env.player.mainSkill.skillModList:NewMod("QuantityMultiplier", mod.type, mod.value, mod.source, mod.flags, mod.keywordFlags) - maxMirageWarriors = maxMirageWarriors + mod.value - end - env.player.mainSkill.infoMessage = tostring(maxMirageWarriors) .. " GC Mirage Warriors using " .. env.player.mainSkill.activeEffect.grantedEffect.name - end - - return calculateMirage(env, config) -end \ No newline at end of file diff --git a/src/Modules/CalcOffence.lua b/src/Modules/CalcOffence.lua index 960a5e16d4..d3bfa1b85e 100644 --- a/src/Modules/CalcOffence.lua +++ b/src/Modules/CalcOffence.lua @@ -6410,48 +6410,11 @@ function calcs.offence(env, actor, activeSkill) end local bestCull = 1 - if activeSkill.mirage and activeSkill.mirage.output and activeSkill.mirage.output.TotalDPS then - local mirageCount = activeSkill.mirage.count or 1 - output.MirageDPS = activeSkill.mirage.output.TotalDPS * mirageCount - output.CombinedDPS = output.CombinedDPS + activeSkill.mirage.output.TotalDPS * mirageCount - output.MirageBurningGroundDPS = activeSkill.mirage.output.BurningGroundDPS - output.MirageCausticGroundDPS = activeSkill.mirage.output.CausticGroundDPS - - if activeSkill.mirage.output.IgniteDPS and activeSkill.mirage.output.IgniteDPS > (output.IgniteDPS or 0) then - output.MirageDPS = output.MirageDPS + activeSkill.mirage.output.IgniteDPS - output.IgniteDPS = 0 - end - if activeSkill.mirage.output.BleedDPS and activeSkill.mirage.output.BleedDPS > (output.BleedDPS or 0) then - output.MirageDPS = output.MirageDPS + activeSkill.mirage.output.BleedDPS - output.BleedDPS = 0 - end - - if activeSkill.mirage.output.PoisonDPS then - output.MirageDPS = output.MirageDPS + activeSkill.mirage.output.PoisonDPS * mirageCount - output.CombinedDPS = output.CombinedDPS + activeSkill.mirage.output.PoisonDPS * mirageCount - end - if activeSkill.mirage.output.ImpaleDPS then - output.MirageDPS = output.MirageDPS + activeSkill.mirage.output.ImpaleDPS * mirageCount - output.CombinedDPS = output.CombinedDPS + activeSkill.mirage.output.ImpaleDPS * mirageCount - end - if activeSkill.mirage.output.DecayDPS then - output.MirageDPS = output.MirageDPS + activeSkill.mirage.output.DecayDPS - output.CombinedDPS = output.CombinedDPS + activeSkill.mirage.output.DecayDPS - end - if activeSkill.mirage.output.TotalDot and (skillFlags.DotCanStack or not output.TotalDot or output.TotalDot == 0) then - output.MirageDPS = output.MirageDPS + activeSkill.mirage.output.TotalDot * (skillFlags.DotCanStack and mirageCount or 1) - output.CombinedDPS = output.CombinedDPS + activeSkill.mirage.output.TotalDot * (skillFlags.DotCanStack and mirageCount or 1) - end - if activeSkill.mirage.output.CullMultiplier > 1 then - bestCull = activeSkill.mirage.output.CullMultiplier - end - end - local TotalDotDPS = (output.TotalDot or 0) + (output.TotalPoisonDPS or output.PoisonDPS or 0) - + (m_max(output.CausticGroundDPS or 0, output.MirageCausticGroundDPS or 0 )) + + (output.CausticGroundDPS or 0) + (output.TotalIgniteDPS or output.IgniteDPS or 0) - + (m_max(output.BurningGroundDPS or 0, output.MirageBurningGroundDPS or 0)) + + (output.BurningGroundDPS or 0) + (output.TotalBleedDPS or output.BleedDPS or 0) + (output.CorruptingBloodDPS or 0) + (output.DecayDPS or 0) diff --git a/src/Modules/CalcPerform.lua b/src/Modules/CalcPerform.lua index b0fe494a77..03fe773fdb 100644 --- a/src/Modules/CalcPerform.lua +++ b/src/Modules/CalcPerform.lua @@ -3511,11 +3511,8 @@ function calcs.perform(env, skipEHP) calcs.buildDefenceEstimations(env, env.player) end - -- TURNING OFF CALC TRIGGERS AND MIRAGES FOR TIME BEING - --calcs.triggers(env, env.player) - --if not calcs.mirages(env) then - calcs.offence(env, env.player, env.player.mainSkill) - --end + calcs.triggers(env, env.player) + calcs.offence(env, env.player, env.player.mainSkill) if env.minion then calcs.defence(env, env.minion) diff --git a/src/Modules/CalcSections.lua b/src/Modules/CalcSections.lua index 787ffca96b..b5f78eec72 100644 --- a/src/Modules/CalcSections.lua +++ b/src/Modules/CalcSections.lua @@ -581,15 +581,11 @@ return { { label = "Inc. Cast Speed", flag = "spell", notFlag = "triggered", { format = "{0:mod:1}%", { modName = "Speed", modType = "INC", cfg = "skill", }, }, }, { label = "More Cast Speed", flag = "spell", notFlag = "triggered", { format = "{0:mod:1}%", { modName = "Speed", modType = "MORE", cfg = "skill", }, }, }, { label = "Casts per second", flag = "spell", notFlag = "triggered", { format = "{2:output:Speed}", { breakdown = "Speed" }, }, }, - { label = "Cast Time", flag = "addsCastTime", { format = "{2:output:addsCastTime}", { breakdown = "AddedCastTime" }, }, }, - { label = "Trigger Rate Cap", flag = "triggered", notFlagList = {"focused", "hasOverride"}, { format = "{2:output:TriggerRateCap}", { breakdown = "TriggerRateCap" }, { modName = "CooldownRecovery", modType = "INC", cfg = "skill", }, }, }, - { label = "Trigger Rate Cap", flagList = {"triggered", "hasOverride"}, notFlag = "focused", { format = "{2:output:TriggerRateCap}", { breakdown = "TriggerRateCap" }, { modName = "CooldownRecovery", modType = "OVERRIDE", cfg = "skill", }, }, }, - { label = "Trigger Rate Cap", flagList = {"triggered", "focused"}, { format = "{2:output:TriggerRateCap}", { breakdown = "TriggerRateCap" }, { modName = "FocusCooldownRecovery", modType = "INC", cfg = "skill", }, }, }, - { label = "Eff. Source Rate", flag = "triggered", notFlag = "focused", notFlag = "globalTrigger", { format = "{2:output:EffectiveSourceRate}", { breakdown = "EffectiveSourceRate" } }, }, - { label = "Skill Trigger Rate", flag = "triggered", notFlag = "focused", { format = "{2:output:SkillTriggerRate}", { breakdown = "SkillTriggerRate" }, { breakdown = "SimData" }, }, }, - { label = "Skill Trigger Rate", flagList = {"triggered", "focused"}, { format = "{2:output:SkillTriggerRate}", { breakdown = "SkillTriggerRate" }, { breakdown = "SimData" }, { modName = "FocusCooldownRecovery", modType = "INC", cfg = "skill", }, }, }, + { label = "Trigger Rate Cap", flag = "triggered", haveOutput = "TriggerRateCap", { format = "{2:output:TriggerRateCap}", { breakdown = "TriggerRateCap" }, { modName = "CooldownRecovery", modType = "INC", cfg = "skill", }, }, }, + { label = "Maximum Energy", haveOutput = "MaxEnergy", { format = "{0:output:MaxEnergy}", { breakdown = "MaxEnergy" }, }, }, + { label = "Energy per second", haveOutput = "EnergyPerSecond", { format = "{2:output:EnergyPerSecond}", { breakdown = "EnergyPerSecond" }, }, }, + { label = "Skill Trigger Rate", flag = "triggered", { format = "{2:output:SkillTriggerRate}", { breakdown = "SkillTriggerRate" }, }, }, { label = "Cast time", flag = "spell", notFlag = "triggered", { format = "{2:output:Time}s", }, }, - { label = "CWDT Threshold", haveOutput = "CWDTThreshold", flag = "triggered", { format = "{2:output:CWDTThreshold}", { breakdown = "CWDTThreshold" }, }, }, { label = "Channel time", flag = "channelRelease", haveOutput = "ChannelTime", { format = "{2:output:ChannelTime}s", { breakdown = "ChannelTime" } }, }, { label = "Hit Rate", haveOutput = "HitSpeed", { format = "{2:output:HitSpeed}", { breakdown = "HitSpeed" } }, }, } } diff --git a/src/Modules/CalcSetup.lua b/src/Modules/CalcSetup.lua index 95b78f6bc9..950ff2e03b 100644 --- a/src/Modules/CalcSetup.lua +++ b/src/Modules/CalcSetup.lua @@ -59,6 +59,9 @@ function calcs.initModDB(env, modDB) modDB:NewMod("MaxLifeLeechInstance", "BASE", 10, "Base") modDB:NewMod("MaxManaLeechInstance", "BASE", 10, "Base") modDB:NewMod("MaxEnergyShieldLeechInstance", "BASE", 10, "Base") + modDB:NewMod("DodgeRollDistance", "BASE", 4.6, "Base") + modDB:NewMod("DodgeRollsPerSecond", "BASE", 1, "Base") + modDB:NewMod("MonsterPower", "BASE", 20, "Base") -- Power of a Unique enemy modDB:NewMod("TrapThrowingTime", "BASE", 0.6, "Base") modDB:NewMod("MineLayingTime", "BASE", 0.3, "Base") modDB:NewMod("WarcryCastTime", "BASE", 0.8, "Base") diff --git a/src/Modules/CalcTriggers.lua b/src/Modules/CalcTriggers.lua index 91a1a75534..c68a92e761 100644 --- a/src/Modules/CalcTriggers.lua +++ b/src/Modules/CalcTriggers.lua @@ -7,19 +7,14 @@ ---@class Calcs local calcs = require("Modules.CalcBase") -local pairs = pairs local ipairs = ipairs local t_insert = table.insert -local t_remove = table.remove local m_min = math.min -local m_max = math.max -local m_ceil = math.ceil local m_floor = math.floor -local m_modf = math.modf +local m_ceil = math.ceil +local m_sqrt = math.sqrt local s_format = string.format local m_huge = math.huge -local bor = OR64 -- bit.bor -local band = AND64 -- bit.band -- Add trigger-based damage modifiers local function addTriggerIncMoreMods(activeSkill, sourceSkill) @@ -31,1441 +26,328 @@ local function addTriggerIncMoreMods(activeSkill, sourceSkill) end end -local function slotMatch(env, skill) - local fromItem = (env.player.mainSkill.activeEffect.grantedEffect.fromItem or skill.activeEffect.grantedEffect.fromItem) - fromItem = fromItem or (env.player.mainSkill.activeEffect.srcInstance and env.player.mainSkill.activeEffect.srcInstance.fromItem) or (skill.activeEffect.srcInstance and skill.activeEffect.srcInstance.fromItem) - local match1 = fromItem and skill.socketGroup and skill.socketGroup.slot == env.player.mainSkill.socketGroup.slot - local match2 = (not env.player.mainSkill.activeEffect.grantedEffect.fromItem) and skill.socketGroup == env.player.mainSkill.socketGroup - return (match1 or match2) -end - -function isTriggered(skill) +local function isTriggered(skill) return skill.skillData.triggeredByUnique or skill.skillData.triggered or skill.skillTypes[SkillType.InbuiltTrigger] or skill.skillTypes[SkillType.Triggered] or skill.activeEffect.grantedEffect.triggered or (skill.activeEffect.srcInstance and skill.activeEffect.srcInstance.triggered) end -local function processAddedCastTime(skill, breakdown) - if skill.skillModList:Flag(skill.skillCfg, "SpellCastTimeAddedToCooldownIfTriggered") then - local baseCastTime = skill.skillData.castTimeOverride or skill.activeEffect.grantedEffect.castTime or 1 - local inc = skill.skillModList:Sum("INC", skill.skillCfg, "Speed") - local more = skill.skillModList:More(skill.skillCfg, "Speed") - local csi = round((1 + inc/100) * more, 2) - local addsCastTime = baseCastTime / csi - skill.skillFlags.addsCastTime = true - if breakdown then - breakdown.AddedCastTime = { - s_format("%.2f ^8(base cast time of %s)", baseCastTime, skill.activeEffect.grantedEffect.name), - s_format("%.2f ^8(increased/reduced)", 1 + inc/100), - s_format("%.2f ^8(more/less)", more), - s_format("= %.2f ^8cast time", addsCastTime) - } - end - return addsCastTime, csi - end -end +local dmgTypeList = {"Physical", "Lightning", "Cold", "Fire", "Chaos"} -local function packageSkillDataForSimulation(skill, env) - return { uuid = cacheSkillUUID(skill, env), cd = skill.skillData.cooldown, cdOverride = skill.skillModList:Override(skill.skillCfg, "CooldownRecovery"), addsCastTime = processAddedCastTime(skill), icdr = calcLib.mod(skill.skillModList, skill.skillCfg, "CooldownRecovery"), addedCooldown = skill.skillModList:Sum("BASE", skill.skillCfg, "CooldownRecovery")} +---@param env Env +---@param skill ActiveSkill +---@return table +local function getSkillFlags(env, skill) + local statSet = env.mode == "CALCS" and skill.activeEffect.statSetCalcs or skill.activeEffect.statSet + return statSet and statSet.skillFlags or {} end -local function defaultComparer(env, uuid, source, triggerRate) - local cachedSpeed = GlobalCache.cachedData[env.mode][uuid].HitSpeed or GlobalCache.cachedData[env.mode][uuid].Speed - return (not source and cachedSpeed) or (cachedSpeed and cachedSpeed > (triggerRate or 0)) +-- PoE2 Meta gems +-- +-- A meta gem accumulates Energy from its own condition and triggers every skill +-- socketed alongside it once Energy reaches maximum while discarding excess energy. +-- Maximum Energy is the sum of the Energy cost of each socketed skill, which is +-- derived from that skill's total cast time. + +-- Energy cost of a single skill socketed in a meta gem. +-- Modifiers to Total cast time count double towards the cost. +---@param skill ActiveSkill +---@return number +local function calcSocketedSkillEnergy(skill) + local energyPerSecond = 1000 / skill.skillData.energyPerCastTimeMs + local baseCastTime = skill.activeEffect.grantedEffect.castTime or 0 + local addedCastTime = skill.skillModList:Sum("BASE", skill.skillCfg, "TotalCastTime") + return baseCastTime * energyPerSecond + addedCastTime * energyPerSecond * 2 end --- Identify the trigger action skill for trigger conditions, take highest Attack Per Second -local function findTriggerSkill(env, skill, source, triggerRate, comparer) - local comparer = comparer or defaultComparer - - local uuid = cacheSkillUUID(skill, env) - if not GlobalCache.cachedData[env.mode][uuid] or env.mode == "CALCULATOR" then - calcs.buildActiveSkill(env, env.mode, skill, uuid) - end - - if GlobalCache.cachedData[env.mode][uuid] and comparer(env, uuid, source, triggerRate) and (skill.skillFlags and not skill.skillFlags.disable) and (skill.skillCfg and not skill.skillCfg.skillCond["usedByMirage"]) and not skill.skillTypes[SkillType.OtherThingUsesSkill] then - return skill, GlobalCache.cachedData[env.mode][uuid].HitSpeed or GlobalCache.cachedData[env.mode][uuid].Speed, uuid +-- The meta gem driving the skill currently being calculated +---@param env Env +---@param actor Actor +---@return ActiveSkill? +local function findMetaGemSkill(env, actor) + local srcInstance = actor.mainSkill.triggeredBy.srcInstance + for _, skill in ipairs(env.player.activeSkillList) do + if skill.skillTypes[SkillType.Meta] and skill.socketGroup == actor.mainSkill.socketGroup and skill.activeEffect.srcInstance == srcInstance then + return skill + end end - return source, triggerRate, source and cacheSkillUUID(source, env) 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) - local rotationIndex = 1 - 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 - - 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 - skill.count = 0 - end - - while next_trigger < SIM_TIME do - 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 - -- 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) - break +-- Total Energy needed for one trigger, and the skills that will be triggered +---@param env Env +---@param metaSkill ActiveSkill +---@param breakdown string[]? +---@return number maxEnergy +---@return ActiveSkill[] triggeredSkills +local function calcMaxEnergy(env, metaSkill, breakdown) + local maxEnergy = metaSkill.skillData.maxEnergy or 0 + local triggeredSkills = {} + for _, skill in ipairs(env.player.activeSkillList) do + if skill.socketGroup == metaSkill.socketGroup and skill.skillData.energyPerCastTimeMs and not getSkillFlags(env, skill).disable then + t_insert(triggeredSkills, skill) + if metaSkill.skillData.maxEnergyFromSocketedSkills then + local energy = calcSocketedSkillEnergy(skill) + maxEnergy = maxEnergy + energy + if breakdown then + t_insert(breakdown, s_format("+ %.0f ^8(%s)", energy, skill.activeEffect.grantedEffect.name)) + end 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 - end - - 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 / (SIM_TIME / sd.count + (triggerIncrement / chance * 100) - triggerIncrement) }) - if cacheSkillUUID(actor.mainSkill, env) == sd.uuid then - mainRate = trigRateTable.rates[#trigRateTable.rates].rate end end - - return mainRate, trigRateTable + return maxEnergy, triggeredSkills end -local function helmetFocusHandler(env) - if not env.player.mainSkill.skillFlags.minion and not env.player.mainSkill.skillFlags.disable and env.player.mainSkill.triggeredBy then - local triggerName = "Focus" - env.player.mainSkill.skillData.triggered = true - ---@class Output - local output = env.player.output - ---@class Breakdown - local breakdown = env.player.breakdown - local triggerCD = env.player.mainSkill.triggeredBy.grantedEffect.levels[env.player.mainSkill.triggeredBy.level].cooldown - local triggeredCD = env.player.mainSkill.skillData.cooldown - - local icdrFocus = calcLib.mod(env.player.mainSkill.skillModList, env.player.mainSkill.skillCfg, "FocusCooldownRecovery") - local icdrSkill = calcLib.mod(env.player.mainSkill.skillModList, env.player.mainSkill.skillCfg, "CooldownRecovery") +---@param skill ActiveSkill +local function canHit(skill) + return skill.skillTypes[SkillType.Attack] or skill.skillTypes[SkillType.Damage] +end - -- Skills trigger only on activation - -- Next possible activation will be duration + cooldown - -- cooldown is in milliseconds - local skillFocus = env.data.skills["Focus"] - local focusDuration = (skillFocus.constantStats[1][2] / 1000) - local focusCD = (skillFocus.levels[1].cooldown / icdrFocus) - local focusTotalCD = focusDuration + focusCD +---@param output Output +---@param kind "StoredCritAvg"|"StoredCombinedAvg" +---@return number +local function sumDamageTypes(output, kind) + local total = 0 + for _, damageType in ipairs(dmgTypeList) do + total = total + (output[damageType .. kind] or 0) + end + return total +end - -- skill cooldown should still apply to focus triggers - local modActionCooldown = m_max( triggeredCD or 0, (triggerCD or 0) / icdrSkill ) - local rateCapAdjusted = m_ceil(modActionCooldown * data.misc.ServerTickRate) / data.misc.ServerTickRate - local triggerRate = m_huge - if rateCapAdjusted ~= 0 then - triggerRate = 1 / rateCapAdjusted +-- Hit damage before mitigation, as used for ailments. +---@param output Output +---@param kind "StoredCritAvg"|"StoredCombinedAvg" +---@param skillData table +---@return number +local function unmitigatedDamage(output, kind, skillData) + if output.MainHand or output.OffHand then + local mainHand = output.MainHand and sumDamageTypes(output.MainHand, kind) or 0 + local offHand = output.OffHand and sumDamageTypes(output.OffHand, kind) or 0 + if mainHand > 0 and offHand > 0 and not skillData.combinesHitsWhenDualWielding then + return (mainHand + offHand) / 2 end + return mainHand + offHand + end + return sumDamageTypes(output, kind) +end - output.TriggerRateCap = triggerRate - output.SkillTriggerRate = 1 / focusTotalCD +---@param env Env +---@return number +local function getMonsterPower(env) + return env.modDB:Override(nil, "MonsterPower") or env.modDB:Sum("BASE", nil, "MonsterPower") +end - if breakdown then - if triggeredCD then - breakdown.TriggerRateCap = { - s_format("%.2f ^8(base cooldown of triggered skill)", triggeredCD), - s_format("/ %.2f ^8(increased/reduced cooldown recovery)", icdrSkill), - s_format("= %.4f ^8(final cooldown of triggered skill)", triggeredCD / icdrSkill), - "", - s_format("%.2f ^8(base cooldown of trigger)", triggerCD), - s_format("/ %.2f ^8(increased/reduced cooldown recovery)", icdrSkill), - s_format("= %.4f ^8(final cooldown of trigger)", triggerCD / icdrSkill), - "", - s_format("%.3f ^8(biggest of trigger cooldown and triggered skill cooldown)", modActionCooldown), - "", - (env.player.mainSkill.skillData.ignoresTickRate and "") or s_format("%.3f ^8(adjusted for server tick rate)", rateCapAdjusted), - "", - "Trigger rate:", - s_format("1 / %.3f", rateCapAdjusted), - s_format("= %.2f ^8per second", triggerRate), - } - else - breakdown.TriggerRateCap = { - "Triggered skill has no base cooldown", - "", - s_format("%.2f ^8(base cooldown of trigger)", triggerCD), - s_format("/ %.2f ^8(increased/reduced cooldown recovery)", icdrSkill), - s_format("= %.4f ^8(final cooldown of trigger)", triggerCD / icdrSkill), - "", - (env.player.mainSkill.skillData.ignoresTickRate and "") or s_format("%.3f ^8(adjusted for server tick rate)", rateCapAdjusted), - "", - "Trigger rate:", - s_format("1 / %.3f", rateCapAdjusted), - s_format("= %.3f ^8per second", triggerRate), - } - end - breakdown.SkillTriggerRate = { - s_format("%.2f ^8(focus base cooldown)", skillFocus.levels[1].cooldown), - s_format("/ %.2f ^8(increased/reduced cooldown recovery)", icdrFocus), - s_format("+ %.2f ^8(skills are only triggered on activation thus we add focus duration)", focusDuration), - s_format("= %.2f ^8(effective skill cooldown for trigger purposes)", focusTotalCD), - "", - s_format("%.3f casts per second ^8(Assuming player uses focus exactly when its cooldown of %.2fs expires)", 1 / focusTotalCD, focusTotalCD) - } +---@alias MetaGemEnergyFunc fun(env: Env, actor: Actor, metaData: table, energyMult: number, maxEnergy: number, config: MetaGemConfig): energyPerEvent: number?, eventRate: number?, source: ActiveSkill? + +---@class MetaGemConfig +---@field eventName string What gains the Energy, used in breakdowns +---@field energy MetaGemEnergyFunc Energy per event, events per second, and the skill causing them if any. No Energy means no source was found +---@field energyStat string? hitEnergy: skillData key of the meta gem's Energy per Monster Power +---@field onCrit boolean? hitEnergy: only Critical Hits generate Energy +---@field sourceCond (fun(skill: ActiveSkill): boolean?)? hitEnergy: which skills can generate Energy + +-- Energy gained from our own hits scales with the share of the enemy's Ailment Threshold +-- the hit deals, so harder hits generate more +---@param env Env +---@param cachedData CachedSkillData +---@param metaData table +---@param config MetaGemConfig +---@return number? energyPerHit +---@return number? hitRate +local function calcHitEnergy(env, cachedData, metaData, config) + local output = cachedData.Env.player.output + local rate = (cachedData.HitSpeed or cachedData.Speed or 0) * (output.DpsMultiplier or 1) + if config.onCrit then + if (output.CritChance or 0) <= 0 then + return end - - -- Account for Trigger-related INC/MORE modifiers - addTriggerIncMoreMods(env.player.mainSkill, env.player.mainSkill) - env.player.mainSkill.infoMessage = "Assuming perfect focus Re-Use" - env.player.mainSkill.infoTrigger = triggerName - env.player.mainSkill.skillData.triggerRate = output.SkillTriggerRate - env.player.mainSkill.skillFlags.globalTrigger = true + -- Critical Hit chance already accounts for missing + rate = rate * output.CritChance / 100 + else + rate = rate * (output.HitChance or 100) / 100 end + local damage = unmitigatedDamage(output, config.onCrit and "StoredCritAvg" or "StoredCombinedAvg", cachedData.ActiveSkill.skillData) + return metaData[config.energyStat] * getMonsterPower(env) * damage / output.EnemyAilmentThreshold, rate end -local function CWCHandler(env) - if not env.player.mainSkill.skillFlags.minion and not env.player.mainSkill.skillFlags.disable then - local triggeredSkills = {} - local trigRate = 0 - local source = nil - local triggerName = "Cast While Channeling" - local output = env.player.output - ---@class Breakdown - local breakdown = env.player.breakdown - for _, skill in ipairs(env.player.activeSkillList) do - local match1 = env.player.mainSkill.activeEffect.grantedEffect.fromItem and skill.socketGroup and skill.socketGroup.slot == env.player.mainSkill.socketGroup.slot - local match2 = (not env.player.mainSkill.activeEffect.grantedEffect.fromItem) and skill.socketGroup == env.player.mainSkill.socketGroup - if env.player.mainSkill.triggeredBy.gemData and calcLib.canGrantedEffectSupportActiveSkill(env.player.mainSkill.triggeredBy.gemData.grantedEffect, skill) and skill ~= env.player.mainSkill and (match1 or match2) and not isTriggered(skill) then - source, trigRate = findTriggerSkill(env, skill, source, trigRate) - end - if skill.skillData.triggeredWhileChannelling and (match1 or match2) then - t_insert(triggeredSkills, packageSkillDataForSimulation(skill, env)) - end - end - if not source or #triggeredSkills < 1 then - env.player.mainSkill.skillData.triggered = nil - env.player.mainSkill.infoMessage2 = "DPS reported assuming Self-Cast" - env.player.mainSkill.infoMessage = s_format("No %s Triggering Skill Found", triggerName) - env.player.mainSkill.infoTrigger = "" - else - local triggeredName = env.player.mainSkill.activeEffect.grantedEffect.name or "Triggered" - - output.addsCastTime = processAddedCastTime(env.player.mainSkill, breakdown) - - local icdr = calcLib.mod(env.player.mainSkill.skillModList, env.player.mainSkill.skillCfg, "CooldownRecovery") or 1 - local adjTriggerInterval = m_ceil(source.skillData.triggerTime * data.misc.ServerTickRate) / data.misc.ServerTickRate - local triggerRateOfTrigger = 1/adjTriggerInterval - local triggeredCD = env.player.mainSkill.skillData.cooldown - local cooldownOverride = env.player.mainSkill.skillModList:Override(env.player.mainSkill.skillCfg, "CooldownRecovery") - - if cooldownOverride then - env.player.mainSkill.skillFlags.hasOverride = true - end - - local triggeredTotalCooldown = cooldownOverride or m_max(triggeredCD or 0, output.addsCastTime or 0) / icdr - local triggeredCDAdjusted = m_ceil(triggeredTotalCooldown * data.misc.ServerTickRate) / data.misc.ServerTickRate - local effCDTriggeredSkill = m_ceil(triggeredCDAdjusted * triggerRateOfTrigger) / triggerRateOfTrigger - - local simBreakdown = nil - output.TriggerRateCap = m_min(1 / effCDTriggeredSkill, triggerRateOfTrigger) - output.SkillTriggerRate, simBreakdown = calcMultiSpellRotationImpact(env, triggeredSkills, triggerRateOfTrigger, 0) - - if breakdown then - if triggeredCD or cooldownOverride then - breakdown.TriggerRateCap = { - s_format("Cast While Channeling triggers %s every %.2fs while channeling %s ", triggeredName, source.skillData.triggerTime, source.activeEffect.grantedEffect.name), - s_format("%.3f ^8(adjusted for server tick rate)", adjTriggerInterval), - "", - s_format("%.2f ^8(base cooldown of triggered skill)", triggeredCD), - s_format("/ %.2f ^8(increased/reduced cooldown recovery)", icdr), - s_format("= %.4f ^8(final cooldown of triggered skill)", triggeredCD / icdr), - "", - } - if cooldownOverride ~= nil then - breakdown.TriggerRateCap[4] = s_format("%.2f ^8(hard override of cooldown of %s)", cooldownOverride, triggeredName) - t_remove(breakdown.TriggerRateCap, 5) - t_remove(breakdown.TriggerRateCap, 5) - end - else - breakdown.TriggerRateCap = { - s_format("Cast While Channeling triggers %s every %.2fs while channeling %s ", triggeredName, source.skillData.triggerTime, source.activeEffect.grantedEffect.name), - s_format("%.3f ^8(adjusted for server tick rate)", adjTriggerInterval), - "", - triggeredName .. " has no base cooldown or cooldown override", - "", - } - end - - local function extraIncreaseNeeded(affectedCD) - if not cooldownOverride then - local nextBreakpoint = effCDTriggeredSkill - adjTriggerInterval - local timeOverBreakpoint = triggeredTotalCooldown - nextBreakpoint - local alreadyReducedTime = triggeredTotalCooldown * icdr - triggeredTotalCooldown - if timeOverBreakpoint < affectedCD then - local divNeeded = affectedCD / (affectedCD - timeOverBreakpoint - alreadyReducedTime) - local incTotal = m_ceil(( divNeeded - 1 ) * 100) - return incTotal - (icdr - 1) * 100 - end - end - end - - if output.addsCastTime then - t_insert(breakdown.TriggerRateCap, "Cast While Channeling had no base cooldown") - t_insert(breakdown.TriggerRateCap, s_format("+ %.2f ^8(%s adds cast time as cooldown to trigger)", output.addsCastTime, triggeredName)) - t_insert(breakdown.TriggerRateCap, s_format("/ %.2f ^8(increased/reduced cooldown recovery)", icdr)) - t_insert(breakdown.TriggerRateCap, s_format("= %.4f ^8(final cooldown of triggered skill)", output.addsCastTime / icdr)) - t_insert(breakdown.TriggerRateCap, "") - t_insert(breakdown.TriggerRateCap, s_format("%.3f ^8(adjusted for server tick rate)", triggeredCDAdjusted)) - t_insert(breakdown.TriggerRateCap, "") - - local extraCSINeeded = extraIncreaseNeeded(output.addsCastTime) - local extraICDRNeeded = extraIncreaseNeeded(triggeredTotalCooldown*icdr) - if extraICDRNeeded then - t_insert(breakdown.TriggerRateCap, s_format("^8(extra ICDR of %d%% would reach next breakpoint)", extraICDRNeeded)) - end - if extraCSINeeded then - t_insert(breakdown.TriggerRateCap, s_format("^8(extra Cast Rate Increase of %d%% would reach next breakpoint)", extraCSINeeded)) - t_insert(breakdown.TriggerRateCap,"") - end - else - local extraICDRNeeded = extraIncreaseNeeded(triggeredTotalCooldown*icdr) - if extraICDRNeeded then - t_insert(breakdown.TriggerRateCap, s_format("^8(extra ICDR of %d%% would reach next breakpoint)", extraICDRNeeded)) - t_insert(breakdown.TriggerRateCap,"") - end - end - - t_insert(breakdown.TriggerRateCap, "Trigger rate:") - t_insert(breakdown.TriggerRateCap, s_format("1 / %.3f ^8(trigger rate adjusted for triggering interval)", 1 / output.TriggerRateCap)) - t_insert(breakdown.TriggerRateCap, s_format("= %.2f ^8 %s casts per second", output.TriggerRateCap, triggeredName)) - - if #triggeredSkills > 1 then - breakdown.SkillTriggerRate = { - s_format("%.2f ^8(%s triggers per second)", triggerRateOfTrigger, triggerName), - s_format("/ %.2f ^8(Estimated impact of linked spells)", (triggerRateOfTrigger / output.SkillTriggerRate) or 1), - s_format("= %.2f ^8%s casts per second", output.SkillTriggerRate, triggeredName), - } - - if simBreakdown.extraSimInfo then - t_insert(breakdown.SkillTriggerRate, "") - t_insert(breakdown.SkillTriggerRate, simBreakdown.extraSimInfo) - end - breakdown.SimData = { - rowList = { }, - colList = { - { label = "Rate", key = "rate" }, - { label = "Skill Name", key = "skillName" }, - { label = "Slot Name", key = "slotName" }, - { label = "Gem Index", key = "gemIndex" }, - }, - } - for _, rateData in ipairs(simBreakdown.rates) do - local t = { } - for str in string.gmatch(rateData.name, "([^_]+)") do - t_insert(t, str) - end - - local row = { - rate = round(rateData.rate,2), - skillName = t[1], - slotName = t[2], - gemIndex = t[3], - } - t_insert(breakdown.SimData.rowList, row) - end +-- Pick the skill whose hits trigger the meta gem most often. +-- Energy beyond maximum is discarded, so sources are compared by trigger rate +---@type MetaGemEnergyFunc +local function hitEnergy(env, actor, metaData, energyMult, maxEnergy, config) + local source, bestEnergy, bestRate, bestTriggerRate = nil, 0, 0, 0 + for _, skill in ipairs(env.player.activeSkillList) do + local flags = getSkillFlags(env, skill) + -- Only hits made by the player themselves generate Energy + local usedByPlayer = not (skill.skillTypes[SkillType.OtherThingUsesSkill] or skill.skillTypes[SkillType.UsedByProxy] or flags.totem or flags.trap or flags.mine) + if canHit(skill) and not isTriggered(skill) and usedByPlayer and not flags.disable and (not config.sourceCond or config.sourceCond(skill)) then + local uuid = cacheSkillUUID(skill, env) + if not GlobalCache.cachedData[env.mode][uuid] or env.mode == "CALCULATOR" then + calcs.buildActiveSkill(env, env.mode, skill, uuid) + end + local cachedData = GlobalCache.cachedData[env.mode][uuid] + if cachedData then + local energy, rate = calcHitEnergy(env, cachedData, metaData, config) + local energyPerHit = energy and m_floor(energy * energyMult * 100 + 1e-9) / 100 + local triggerRate = energyPerHit and energyPerHit > 0 and rate / m_ceil(maxEnergy / energyPerHit - 1e-9) + if triggerRate and triggerRate > bestTriggerRate then + source, bestEnergy, bestRate, bestTriggerRate = skill, energy, rate, triggerRate end end - - -- Account for Trigger-related INC/MORE modifiers - addTriggerIncMoreMods(env.player.mainSkill, env.player.mainSkill) - env.player.output.ChannelTimeToTrigger = source.skillData.triggerTime - env.player.mainSkill.skillData.triggered = true - env.player.mainSkill.skillFlags.globalTrigger = true - env.player.mainSkill.skillData.triggerRate = output.SkillTriggerRate - env.player.mainSkill.skillData.triggerSourceUUID = cacheSkillUUID(source, env) - env.player.mainSkill.infoMessage = triggerName .."'s Trigger: ".. source.activeEffect.grantedEffect.name - env.player.infoTrigger = env.player.mainSkill.infoTrigger or triggerName end end + if source then + return bestEnergy, bestRate, source + end end -local function defaultTriggerHandler(env, config) - local actor = config.actor - local output = config.actor.output - ---@class Breakdown - local breakdown = config.actor.breakdown - local source = config.source - local triggeredSkills = config.triggeredSkills or {} - local trigRate = config.trigRate - local uuid - - -- Find trigger skill and triggered skills - if config.triggeredSkillCond or config.triggerSkillCond then - for _, skill in ipairs(env.player.activeSkillList) do - if config.triggerSkillCond and config.triggerSkillCond(env, skill) and (not isTriggered(skill) or actor.mainSkill.skillFlags.globalTrigger or config.allowTriggered) and skill ~= actor.mainSkill then - source, trigRate, uuid = findTriggerSkill(env, skill, source, trigRate, config.comparer) - end - if config.triggeredSkillCond and config.triggeredSkillCond(env,skill) then - t_insert(triggeredSkills, packageSkillDataForSimulation(skill, env)) - end - end +---@type MetaGemEnergyFunc +local function blockEnergy(env, actor, metaData) + local enemySkillTime = actor.output.enemySkillTime or 0 + if enemySkillTime <= 0 then + return metaData.energyOnBlock, 0 end - if #triggeredSkills > 0 or not config.triggeredSkillCond then - if not source and not (actor.mainSkill.skillFlags.globalTrigger and config.triggeredSkillCond) then - actor.mainSkill.skillData.triggered = nil - actor.mainSkill.infoMessage2 = "DPS reported assuming Self-Cast" - actor.mainSkill.infoMessage = s_format("No %s Triggering Skill Found", config.triggerName) - actor.mainSkill.infoTrigger = "" - else - actor.mainSkill.skillData.triggered = true - - -- Account for Arcanist Brand using activation frequency - if breakdown and actor.mainSkill.skillData.triggeredByBrand then - breakdown.EffectiveSourceRate = { - s_format("%.2f ^8(base activation cooldown of %s)", actor.mainSkill.triggeredBy.mainSkill.skillData.repeatFrequency, config.triggerName), - s_format("* %.2f ^8(more activation frequency)", actor.mainSkill.triggeredBy.activationFreqMore), - s_format("* %.2f ^8(increased activation frequency)", actor.mainSkill.triggeredBy.activationFreqInc), - s_format("= %.2f ^8(activation rate of %s)", trigRate, actor.mainSkill.triggeredBy.mainSkill.activeEffect.grantedEffect.name) - } - elseif breakdown then - breakdown.EffectiveSourceRate = {} - if trigRate and source then - if config.assumingEveryHitKills then - t_insert(breakdown.EffectiveSourceRate, "Assuming every attack kills") - end - t_insert(breakdown.EffectiveSourceRate, s_format("%.2f ^8(%s %s)", trigRate, config.sourceName or source.activeEffect.grantedEffect.name, config.useCastRate and "cast rate" or "attack rate")) - end - end - - -- Dual wield triggers - if trigRate and source and env.player.weaponData1.type and env.player.weaponData2.type and not source.skillData.combinesHitsWhenDualWielding and (source.skillTypes[SkillType.Melee] or source.skillTypes[SkillType.Attack]) and actor.mainSkill.triggeredBy and actor.mainSkill.triggeredBy.grantedEffect.support and actor.mainSkill.triggeredBy.grantedEffect.fromItem then - trigRate = trigRate / 2 - if breakdown then - t_insert(breakdown.EffectiveSourceRate, 2, s_format("/ 2 ^8(due to dual wielding)")) - end - end - - actor.mainSkill.skillData.ignoresTickRate = actor.mainSkill.skillData.ignoresTickRate or (actor.mainSkill.skillData.storedUses and actor.mainSkill.skillData.storedUses > 1) - - --Account for source unleash - if source and GlobalCache.cachedData[env.mode][uuid] and source.skillModList:Flag(nil, "HasSeals") and source.skillModList:Flag(nil, "DamageSeal") then - local unleashDpsMult = GlobalCache.cachedData[env.mode][uuid].ActiveSkill.skillData.dpsMultiplier or 1 - trigRate = trigRate * unleashDpsMult - actor.mainSkill.skillFlags.HasSeals = true - actor.mainSkill.skillData.ignoresTickRate = true - if breakdown then - t_insert(breakdown.EffectiveSourceRate, s_format("x %.2f ^8(multiplier from Unleash)", unleashDpsMult)) - end - end - - --Account for skills that can hit multiple times per use - if source and GlobalCache.cachedData[env.mode][uuid] and source.skillPartName and source.skillPartName:match("(.*)All(.*)Projectiles(.*)") and source.skillFlags.projectile then - local multiHitDpsMult = GlobalCache.cachedData[env.mode][uuid].Env.player.output.ProjectileCount or 1 - trigRate = trigRate * multiHitDpsMult - if breakdown then - t_insert(breakdown.EffectiveSourceRate, s_format("x %.2f ^8(%d projectiles hit)", multiHitDpsMult, multiHitDpsMult)) - end - end - - --Special handling for Kitava's Thirst - -- Repeated hits do not consume mana and do not trigger Kitava's thirst - if actor.mainSkill.skillData.triggeredByManaSpent then - local repeats = 1 + source.skillModList:Sum("BASE", nil, "RepeatCount") - trigRate = trigRate / repeats - if breakdown and repeats > 1 then - t_insert(breakdown.EffectiveSourceRate, s_format("/%d ^8(repeated attacks/casts do not count as they don't use mana)", repeats)) - end - end - - -- Battlemage's Cry uptime - if actor.mainSkill.skillData.triggeredByBattleMageCry and GlobalCache.cachedData[env.mode][uuid] and source and source.skillTypes[SkillType.Melee] then - local battleMageExertsCount = GlobalCache.cachedData[env.mode][uuid].Env.player.output.BattleCryExertsCount - local battleMageDuration = ceil_b(GlobalCache.cachedData[env.mode][uuid].Env.player.output.BattleMageCryDuration, data.misc.ServerTickTime) - local battleMageCastTime = GlobalCache.cachedData[env.mode][uuid].Env.player.output.BattleMageCryCastTime - local battleMageCooldown = ceil_b(GlobalCache.cachedData[env.mode][uuid].Env.player.output.BattleMageCryCooldown, data.misc.ServerTickTime) - - -- Cap the number of hits that happen during the duration - local battleMageHits = m_max(m_min(trigRate * battleMageDuration, battleMageExertsCount), 0) - - if breakdown then - t_insert(breakdown.EffectiveSourceRate, s_format("^8(min(%.2f * %.2f, %d) = %.2f average number of exerted attacks capped by exerted count)", trigRate, battleMageDuration, battleMageExertsCount, battleMageHits)) - t_insert(breakdown.EffectiveSourceRate, s_format("= %.2f / (%.2f + %.2f) ^8(the calculated number of exerted attacks happens every cooldown + duration)", battleMageHits, battleMageCastTime, battleMageCooldown)) - end - - -- The hits happen every battlemage cooldown + duration - trigRate = battleMageHits / (battleMageCastTime + battleMageCooldown) - end - - -- Infernal Cry uptime - if actor.mainSkill.activeEffect.grantedEffect.name == "Combust" and GlobalCache.cachedData[env.mode][uuid] and source and source.skillTypes[SkillType.Melee] then - local infernalCryExertsCount = GlobalCache.cachedData[env.mode][uuid].Env.player.output.InfernalEmpoweredCount - local infernalCryDuration = ceil_b(GlobalCache.cachedData[env.mode][uuid].Env.player.output.InfernalCryDuration, data.misc.ServerTickTime) - local infernalCryCastTime = GlobalCache.cachedData[env.mode][uuid].Env.player.output.InfernalCryCastTime - local infernalCryCooldown = ceil_b(GlobalCache.cachedData[env.mode][uuid].Env.player.output.InfernalCryCooldown, data.misc.ServerTickTime) - - -- Cap the number of hits that happen during the duration - local infernalCryHits = m_max(m_min(trigRate * infernalCryDuration, infernalCryExertsCount), 0) - - if breakdown then - t_insert(breakdown.EffectiveSourceRate, s_format("^8(min(%.2f * %.2f, %d) = %.2f average number of exerted attacks capped by exerted count)", trigRate, infernalCryDuration, infernalCryExertsCount, infernalCryHits)) - t_insert(breakdown.EffectiveSourceRate, s_format("= %.2f / (%.2f + %.2f) ^8(the calculated number of exerted attacks happens every cooldown + duration)", infernalCryHits, infernalCryCastTime, infernalCryCooldown)) - end - - -- The hits happen every Infernal Cry cooldown + duration - trigRate = infernalCryHits / (infernalCryCastTime + infernalCryCooldown) - end - - -- Handling for mana spending rate for Manaforged Arrows Support - if actor.mainSkill.skillData.triggeredByManaforged and trigRate > 0 then - local triggeredUUID = cacheSkillUUID(actor.mainSkill, env) - if not GlobalCache.cachedData[env.mode][triggeredUUID] then - calcs.buildActiveSkill(env, env.mode, actor.mainSkill, triggeredUUID, {[triggeredUUID] = true}) - end - local triggeredManaCost = GlobalCache.cachedData[env.mode][triggeredUUID].Env.player.output.ManaCostRaw or 0 - if triggeredManaCost > 0 then - local manaSpentThreshold = triggeredManaCost * actor.mainSkill.skillData.ManaForgedArrowsPercentThreshold - local sourceManaCost = GlobalCache.cachedData[env.mode][uuid].Env.player.output.ManaCostRaw or 0 - if sourceManaCost > 0 then - if breakdown then - breakdown.EffectiveSourceRate = { - s_format("%.4f ^8(Mana cost of trigger source)", sourceManaCost), - s_format(""), - s_format("%.4f ^8(Mana Cost of triggered)", triggeredManaCost), - s_format("%.2f ^8(Manaforged threshold multiplier)", actor.mainSkill.skillData.ManaForgedArrowsPercentThreshold), - s_format("= %.4f ^8(Manaforged trigger threshold)", manaSpentThreshold), - s_format(""), - s_format("%.4f ^8(Manaforged trigger threshold)", manaSpentThreshold), - s_format("/ %.4f ^8(Mana cost of trigger source)", sourceManaCost), - s_format("= %.2f ^8(Skill usages required)", manaSpentThreshold / sourceManaCost), - s_format(""), - breakdown.EffectiveSourceRate[1], - s_format("/ ceil(%.2f) ^8(%d Skill usages required)", manaSpentThreshold / sourceManaCost, m_ceil(manaSpentThreshold / sourceManaCost)), - } - end - trigRate = trigRate / m_ceil(manaSpentThreshold / sourceManaCost) - else - if breakdown then - t_insert(breakdown.EffectiveSourceRate, s_format("Source skill has no mana cost", output.EffectiveSourceRate)) - end - trigRate = 0 - end - end - end - - local icdr = calcLib.mod(actor.mainSkill.skillModList, actor.mainSkill.skillCfg, "CooldownRecovery") or 1 - local addedCooldown = actor.mainSkill.skillModList:Sum("BASE", actor.mainSkill.skillCfg, "CooldownRecovery") - addedCooldown = addedCooldown ~= 0 and addedCooldown or nil - 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 actor.mainSkill.skillData.triggeredByBrand then - triggerCD = actor.mainSkill.triggeredBy.mainSkill.skillData.repeatFrequency / actor.mainSkill.triggeredBy.activationFreqMore / actor.mainSkill.triggeredBy.activationFreqInc - triggerCD = triggerCD * icdr -- cancels out division by icdr lower, brand activation rate is not affected by icdr - end - - local triggeredName = (actor.mainSkill.activeEffect.grantedEffect and actor ~= env.minion and actor.mainSkill.activeEffect.grantedEffect.name) or "Triggered skill" - local csi - output.addsCastTime, csi = processAddedCastTime(env.player.mainSkill, breakdown) - - local triggeredCDAdjusted = ( (triggeredCD or 0) + (addedCooldown or 0) ) / icdr - local triggerCDAdjusted = ( (triggerCD or 0) + (output.addsCastTime or 0) ) / icdr - local triggeredCDTickRounded = actor.mainSkill.skillData and actor.mainSkill.skillData.ignoresTickRate and triggeredCDAdjusted or m_ceil(triggeredCDAdjusted * data.misc.ServerTickRate) / data.misc.ServerTickRate - local triggerCDTickRounded = actor.mainSkill.triggeredBy and actor.mainSkill.triggeredBy.ignoresTickRate and triggerCDAdjusted or m_ceil(triggerCDAdjusted * data.misc.ServerTickRate) / data.misc.ServerTickRate - local actionCooldown = cooldownOverride or m_max((triggerCD or 0) + (output.addsCastTime or 0), (triggeredCD or 0) + (addedCooldown or 0)) - local actionCooldownAdjusted = cooldownOverride or m_max(triggerCDAdjusted, triggeredCDAdjusted) - local actionCooldownTickRounded = cooldownOverride and (m_ceil(cooldownOverride * data.misc.ServerTickRate) / data.misc.ServerTickRate) or m_max(triggerCDTickRounded, triggeredCDTickRounded) - - output.TriggerRateCap = source == actor.mainSkill and actor.mainSkill.skillData.triggerRateCapOverride or m_huge - if actionCooldownTickRounded ~= 0 then - output.TriggerRateCap = 1 / actionCooldownTickRounded - end - if config.triggerName == "Doom Blast" and env.build.configTab.input["doomBlastSource"] == "expiration" then - local expirationRate = 1 / GlobalCache.cachedData[env.mode][uuid].Env.player.output.Duration - if breakdown and breakdown.EffectiveSourceRate then - breakdown.EffectiveSourceRate[1] = s_format("1 / %.2f ^8(source curse duration)", GlobalCache.cachedData[env.mode][uuid].Env.player.output.Duration) - end - if expirationRate > trigRate then - env.player.modDB:NewMod("UsesCurseOverlaps", "FLAG", true, "Config") - if breakdown and breakdown.EffectiveSourceRate then - t_insert(breakdown.EffectiveSourceRate, 2, s_format("max(%.2f, %.2f) ^8(If a curse expires instantly curse expiration is equivalent to curse replacement)", expirationRate, trigRate)) - t_insert(breakdown.EffectiveSourceRate, 2, s_format("%.2f ^8(%s cast rate)", trigRate, source.activeEffect.grantedEffect.name)) - end - else - trigRate = expirationRate - end - elseif config.triggerName == "Doom Blast" and env.build.configTab.input["doomBlastSource"] == "hexblast" then - local hexBlast, rate - for _, skill in ipairs(env.player.activeSkillList) do - if skill.activeEffect.grantedEffect.name == "Hexblast" and not isTriggered(skill) and skill ~= actor.mainSkill then - hexBlast, rate, uuid = findTriggerSkill(env, skill, hexBlast, rate) - end - end - if hexBlast then - if breakdown then - breakdown.EffectiveSourceRate[1] = s_format("1 / (%.2f + %.2f) ^8(sum of triggered curse and hexblast cast time)", 1/trigRate, 1/rate) - end - trigRate = 1/ (1/trigRate + 1/rate) - end - end - - if breakdown and not breakdown.TriggerRateCap then - breakdown.TriggerRateCap = {} - - if cooldownOverride then - t_insert(breakdown.TriggerRateCap, s_format("%.2f ^8(hard override of cooldown of %s)", cooldownOverride, triggeredName)) - elseif triggeredCDAdjusted == 0 then - t_insert(breakdown.TriggerRateCap, triggeredName .. " has no base cooldown or cooldown override") - else -- triggeredCDAdjusted ~= 0 triggered skill has some kind of cooldown - if triggeredCD then - t_insert(breakdown.TriggerRateCap, s_format("%.2f ^8(base cooldown of triggered skill)", triggeredCD)) - else - t_insert(breakdown.TriggerRateCap, triggeredName .. " has no base cooldown or cooldown override") - end - if addedCooldown then - t_insert(breakdown.TriggerRateCap, s_format("+ %.2f ^8(flat added cooldown)", addedCooldown)) - end - t_insert(breakdown.TriggerRateCap, s_format("/ %.2f ^8(increased/reduced cooldown recovery)", icdr)) - t_insert(breakdown.TriggerRateCap, s_format("= %.4f ^8(final cooldown of triggered skill)", triggeredCDAdjusted)) - end - - t_insert(breakdown.TriggerRateCap, "") - - if actor ~= env.minion then -- Minion triggers have internal triggers - if triggerCDAdjusted == 0 then - t_insert(breakdown.TriggerRateCap, s_format("Trigger rate based on %s cooldown", triggeredName)) - else -- triggerCDAdjusted ~= 0 trigger has some kind of cooldown - if triggerCD then - t_insert(breakdown.TriggerRateCap, s_format("%.2f ^8(base cooldown of %s)", triggerCD, config.triggerName)) - else - t_insert(breakdown.TriggerRateCap, config.triggerName .. " has no base cooldown") - end - if output.addsCastTime then - t_insert(breakdown.TriggerRateCap, s_format("+ %.2f ^8(this skill adds cast time to cooldown when triggered)", output.addsCastTime)) - end - t_insert(breakdown.TriggerRateCap, s_format("/ %.2f ^8(increased/reduced cooldown recovery)", icdr)) - t_insert(breakdown.TriggerRateCap, s_format("= %.4f ^8(final cooldown of trigger)", triggerCDAdjusted)) - end - end - - t_insert(breakdown.TriggerRateCap, "") - - if triggeredCDAdjusted ~= 0 and triggerCDAdjusted ~= 0 then - t_insert(breakdown.TriggerRateCap, s_format("%.3f ^8(biggest of trigger cooldown and triggered skill cooldown)", actionCooldownAdjusted)) - end - - local displayCooldownRounding = (actor.mainSkill.skillData and not actor.mainSkill.skillData.ignoresTickRate and triggeredCDAdjusted ~= 0) or (actor.mainSkill.triggeredBy and not actor.mainSkill.triggeredBy.ignoresTickRate and triggerCDAdjusted ~= 0) - if displayCooldownRounding then - t_insert(breakdown.TriggerRateCap, s_format("%.3f ^8(adjusted for server tick rate)", actionCooldownTickRounded)) - end - - local function extraIncreaseNeeded(affectedCD) - if not cooldownOverride then - local nextBreakpoint = actionCooldownTickRounded - data.misc.ServerTickTime - local timeOverBreakpoint = actionCooldownAdjusted - nextBreakpoint - local alreadyReducedTime = actionCooldown - actionCooldownAdjusted - if timeOverBreakpoint < affectedCD then - local divNeeded = affectedCD / (affectedCD - timeOverBreakpoint - alreadyReducedTime) - local incTotal = m_ceil(( divNeeded - 1 ) * 100) - return incTotal - (icdr - 1) * 100 - end - end - end - - local extraICDRNeeded = extraIncreaseNeeded(actionCooldown) - if extraICDRNeeded then - t_insert(breakdown.TriggerRateCap, s_format("^8(extra ICDR of %d%% would reach next breakpoint)", extraICDRNeeded)) - end - - local extraCSIncNeeded = output.addsCastTime and extraIncreaseNeeded(output.addsCastTime) - if extraCSIncNeeded then - t_insert(breakdown.TriggerRateCap, s_format("^8(extra ICS of %d%% would reach next breakpoint)", extraCSIncNeeded)) - end - - t_insert(breakdown.TriggerRateCap, "") - - if not (triggeredCD or triggerCD or cooldownOverride) then - 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)) - t_insert(breakdown.TriggerRateCap, s_format("= %.2f ^8per second", output.TriggerRateCap)) - end - end - - if env.player.mainSkill.activeEffect.grantedEffect.name == "Doom Blast" and env.build.configTab.input["doomBlastSource"] == "vixen" then - if not env.player.itemList["Gloves"] or env.player.itemList["Gloves"].title ~= "Vixen's Entrapment" then - output.VixenModeNoVixenGlovesWarn = true - end - - env.player.modDB:NewMod("UsesCurseOverlaps", "FLAG", true, "Config") - local vixens = env.data.skills["SupportUniqueCastCurseOnCurse"] - local vixensCD = vixens and vixens.levels[1].cooldown / icdr - output.EffectiveSourceRate = calcMultiSpellRotationImpact(env, {{ uuid = cacheSkillUUID(env.player.mainSkill, env), icdr = icdr}}, trigRate, vixensCD) - output.VixensTooMuchCastSpeedWarn = vixensCD > (1 / trigRate) - if breakdown then - t_insert(breakdown.EffectiveSourceRate, s_format("%.2f / %.2f = %.2f ^8(Vixen's trigger cooldown)", vixensCD * icdr, icdr, vixensCD)) - t_insert(breakdown.EffectiveSourceRate, s_format("%.2f ^8(Simulated trigger rate of a curse socketed in Vixen's given ^7%.2f ^8CD and ^7%.2f ^8source rate)", output.EffectiveSourceRate, vixensCD, trigRate)) - end - elseif trigRate ~= nil and not actor.mainSkill.skillFlags.globalTrigger and not config.ignoreSourceRate then - output.EffectiveSourceRate = trigRate - else - output.EffectiveSourceRate = output.TriggerRateCap - actor.mainSkill.skillFlags.globalTrigger = true - end - - if breakdown and not actor.mainSkill.skillData.sourceRateIsFinal then - t_insert(breakdown.EffectiveSourceRate, s_format("= %.2f ^8(Effective source rate)", output.EffectiveSourceRate)) - end - - local skillName = (source and source.activeEffect.grantedEffect.name) or (actor.mainSkill.triggeredBy and actor.mainSkill.triggeredBy.grantedEffect.name) or actor.mainSkill.activeEffect.grantedEffect.name - - if output.EffectiveSourceRate ~= 0 then - local triggerChance = 100 - 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 - - local sourceHitChance = GlobalCache.cachedData[env.mode][uuid].HitChance or 0 - if sourceHitChance ~= 100 then - -- Some skills hit with both weapons at the same time. Each weapon rolls accuracy and crit independently - if source and env.player.weaponData1.type and env.player.weaponData2.type and source.skillData.combinesHitsWhenDualWielding then - local mainHandHit = GlobalCache.cachedData[env.mode][uuid].Env.player.output.MainHand.HitChance - local offHandHit = GlobalCache.cachedData[env.mode][uuid].Env.player.output.OffHand.HitChance - local bothHit = mainHandHit * offHandHit / 100 - local mainHandMiss = (100 - mainHandHit) - local offHandMiss = (100 - offHandHit) - local effectiveHitChance = bothHit + mainHandHit * offHandMiss / 100 + mainHandMiss * offHandHit / 100 - triggerChance = triggerChance * effectiveHitChance / 100 - if breakdown then - t_insert(triggerChanceBreakdown, s_format("x %.2f%% ^8(%s effective hit chance for skills that hit with both weapons)", effectiveHitChance, source.activeEffect.grantedEffect.name)) - end - else - triggerChance = triggerChance * (sourceHitChance or 0) / 100 - if breakdown then - t_insert(triggerChanceBreakdown, s_format("x %.2f%% ^8(%s hit chance)", sourceHitChance, source.activeEffect.grantedEffect.name)) - end - end - end - if actor.mainSkill.skillData.triggerOnCrit then - local onCritChance = actor.mainSkill.skillData.chanceToTriggerOnCrit or (GlobalCache.cachedData[env.mode][uuid] and GlobalCache.cachedData[env.mode][uuid].Env.player.mainSkill.skillData.chanceToTriggerOnCrit) - config.triggerChance = config.triggerChance or actor.mainSkill.skillData.chanceToTriggerOnCrit or onCritChance - - local sourceCritChance = GlobalCache.cachedData[env.mode][uuid].CritChance or 0 - if sourceCritChance ~= 100 then - -- Some skills hit with both weapons at the same time. Each weapon rolls accuracy and crit independently - if source and env.player.weaponData1.type and env.player.weaponData2.type and source.skillData.combinesHitsWhenDualWielding then - local mainHandCrit = GlobalCache.cachedData[env.mode][uuid].Env.player.output.MainHand.CritChance - local offHandCrit = GlobalCache.cachedData[env.mode][uuid].Env.player.output.OffHand.CritChance - local bothHit = mainHandCrit * offHandCrit / 100 - local mainHandMiss = (100 - mainHandCrit) - local offHandMiss = (100 - offHandCrit) - local effectiveCritChance = bothHit + mainHandCrit * offHandMiss / 100 + mainHandMiss * offHandCrit / 100 - triggerChance = triggerChance * effectiveCritChance / 100 - if breakdown then - t_insert(triggerChanceBreakdown, s_format("x %.2f%% ^8(%s effective crit chance for skills that hit with both weapons)", effectiveCritChance, source.activeEffect.grantedEffect.name)) - end - else - triggerChance = triggerChance * (sourceCritChance or 0) / 100 - if breakdown then - t_insert(triggerChanceBreakdown, s_format("x %.2f%% ^8(%s crit chance)", sourceCritChance, source.activeEffect.grantedEffect.name)) - end - end - end - end - end - - --Trigger chance - if config.triggerChance and config.triggerChance ~= 100 then - triggerChance = triggerChance * config.triggerChance / 100 - if breakdown then - t_insert(triggerChanceBreakdown, s_format("x %.2f%% ^8(chance to trigger)", config.triggerChance)) - end - 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 - 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 - if overlaps then - breakdown.SkillTriggerRate = { - s_format("min(%.2f, %.2f * %d) ^8(%d overlaps)", output.TriggerRateCap, output.EffectiveSourceRate, overlaps, overlaps) - } - else - breakdown.SkillTriggerRate = { - s_format("min(%.2f, %.2f)", output.TriggerRateCap, output.EffectiveSourceRate) - } - end - end - 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 triggerBotsEffective = actor.modDB:Flag(nil, "HaveTriggerBots") and actor.mainSkill.skillTypes[SkillType.Spell] - if triggerBotsEffective then - output.SkillTriggerRate = 2 * output.SkillTriggerRate - end - - -- stagesAreOverlaps is the skill part which makes the stages behave as overlaps - local hits_per_cast = config.stagesAreOverlaps and env.player.mainSkill.skillPart == config.stagesAreOverlaps and env.player.mainSkill.activeEffect.srcInstance.skillStageCount or 1 - output.SkillTriggerRate = hits_per_cast * output.SkillTriggerRate - if breakdown then - breakdown.SkillTriggerRate = { - s_format("%.2f ^8(%s)", output.EffectiveSourceRate, (actor.mainSkill.skillData.triggeredByBrand and s_format("%s activations per second", source.activeEffect.grantedEffect.name)) or (not trigRate and s_format("%s triggers per second", skillName)) or "Effective source rate"), - s_format("/ %.2f ^8(Estimated impact of skill rotation, cooldown alignment and trigger chance)", m_max(output.EffectiveSourceRate / output.SkillTriggerRate, 1)), - s_format("= %.2f ^8per second", output.SkillTriggerRate), - } - if triggerChance ~= 100 then - t_insert(breakdown.SkillTriggerRate, 1, "") - t_insert(breakdown.SkillTriggerRate, 1, s_format("= %.2f%% ^8(Effective chance to trigger)", triggerChance)) - for _, line in ipairs(triggerChanceBreakdown) do - t_insert(breakdown.SkillTriggerRate, 1, line) - end - t_insert(breakdown.SkillTriggerRate, 1, "100% ^8(Base chance)") - end - if triggerBotsEffective then - t_insert(breakdown.SkillTriggerRate, 3, "x 2 ^8(Trigger bots effectively cause the skill to trigger twice)") - end - if hits_per_cast > 1 then - t_insert(breakdown.SkillTriggerRate, 3, s_format("x %.2f ^8(hits per triggered skill cast)", hits_per_cast)) - end - if simBreakdown.extraSimInfo then - t_insert(breakdown.SkillTriggerRate, "") - t_insert(breakdown.SkillTriggerRate, simBreakdown.extraSimInfo) - end - breakdown.SimData = { - rowList = { }, - colList = { - { label = "Rate", key = "rate" }, - { label = "Skill Name", key = "skillName" }, - { label = "Slot Name", key = "slotName" }, - { label = "Gem Index", key = "gemIndex" }, - }, - } - for _, rateData in ipairs(simBreakdown.rates) do - local t = { } - for str in string.gmatch(rateData.name, "([^_]+)") do - t_insert(t, str) - end + return metaData.energyOnBlock, (actor.output.EffectiveBlockChance or 0) / 100 / enemySkillTime +end - local row = { - rate = round(rateData.rate, 2), - skillName = t[1], - slotName = t[2], - gemIndex = t[3], - } - 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)) - end - end - else - if breakdown then - breakdown.SkillTriggerRate = { - s_format("The trigger needs to be triggered for any skill to be triggered."), - } - end - output.SkillTriggerRate = 0 - end - actor.mainSkill.skillData.triggerRate = output.SkillTriggerRate +---@param skill ActiveSkill +local function isMeleeAttack(skill) + return skill.skillTypes[SkillType.Melee] and skill.skillTypes[SkillType.Attack] +end - -- Account for Trigger-related INC/MORE modifiers - output.Speed = actor.mainSkill.skillData.triggerRate - addTriggerIncMoreMods(actor.mainSkill, source or actor.mainSkill) - if source and source ~= actor.mainSkill then - actor.mainSkill.skillData.triggerSourceUUID = cacheSkillUUID(source, env) - actor.mainSkill.infoMessage = (config.customTriggerName or ((config.triggerName ~= source.activeEffect.grantedEffect.name and config.triggerName or triggeredName) .. ( actor == env.minion and "'s attack Trigger: " or "'s Trigger: "))) .. source.activeEffect.grantedEffect.name - else - actor.mainSkill.infoMessage = actor.mainSkill.triggeredBy and actor.mainSkill.triggeredBy.grantedEffect.name or config.triggerName .. " Trigger" - end +-- Keyed by the hidden support each meta gem applies to its socketed skills. +-- energy returns the Energy gained per event, how often that event happens, and the skill causing it if any +---@type table +local metaGemConfigs = { + ["SupportMetaCastOnCritPlayer"] = { eventName = "Critical Hit", energy = hitEnergy, energyStat = "energyPerPowerOnCrit", onCrit = true }, + ["SupportMetaCastFireSpellOnHitPlayer"] = { eventName = "melee Hit", energy = hitEnergy, energyStat = "energyPerPowerOnMeleeHit", sourceCond = isMeleeAttack }, + ["SupportMetaCastLightningSpellOnHitPlayer"] = { eventName = "melee Hit", energy = hitEnergy, energyStat = "energyPerPowerOnMeleeHit", sourceCond = isMeleeAttack }, + ["SupportMetaCastOnBlockPlayer"] = { eventName = "Block", energy = blockEnergy }, + ["SupportMetaCastCurseOnBlockPlayer"] = { eventName = "Block", energy = blockEnergy }, + ["SupportMetaCastOnDodgePlayer"] = { eventName = "dodge roll metre", energy = function(env, actor, metaData) + -- Roll distance scales with the square root of movement speed. Energy is gained at each whole metre, + -- and metres left in a roll after a trigger count towards the next one + local distance = m_floor(calcLib.val(env.modDB, "DodgeRollDistance", { skillCond = { DodgeRolledRecently = true } }) * m_sqrt(actor.output.MovementSpeedMod or 1) + 1e-9) + local rollsPerSecond = env.modDB:Override(nil, "DodgeRollsPerSecond") or env.modDB:Sum("BASE", nil, "DodgeRollsPerSecond") + return metaData.energyPerMetreDodgeRolling, distance * rollsPerSecond + end }, + ["SupportMetaCastOnCharmUsePlayer"] = { eventName = "Charm Charge", energy = function(env, actor, metaData) + return metaData.energyPerCharmCharge, env.modDB:Sum("BASE", nil, "Multiplier:CharmChargesUsedPerSecond") + end }, +} - actor.mainSkill.infoTrigger = config.triggerName - end - end +---@param skill ActiveSkill +---@param message string +local function assumeSelfCast(skill, message) + skill.skillData.triggered = nil + skill.infoMessage = message + skill.infoMessage2 = "DPS reported assuming Self-Cast" + skill.infoTrigger = "" end -local configTable = { - ["law of the wilds"] = function() - return { - triggerSkillCond = function(env, skill) - return not skill.skillTypes[SkillType.SummonsTotem] and (skill.skillTypes[SkillType.Melee] or skill.skillTypes[SkillType.Attack]) and band(skill.skillCfg.flags, ModFlag.Claw) > 0 - end - } - end, - ["the rippling thoughts"] = function(env) - if env.player.mainSkill.activeEffect.grantedEffect.name == "Storm Cascade" then - return { - triggerSkillCond = function(env, skill) - return (skill.skillTypes[SkillType.Melee] or skill.skillTypes[SkillType.Attack]) - end - } - end - end, - ["the surging thoughts"] = function(env) - if env.player.mainSkill.activeEffect.grantedEffect.name == "Storm Cascade" then - return { - triggerSkillCond = function(env, skill) - return (skill.skillTypes[SkillType.Melee] or skill.skillTypes[SkillType.Attack]) - end - } - end - end, - ["the hidden blade"] = function(env) - env.player.mainSkill.skillFlags.globalTrigger = true - env.player.mainSkill.skillData.triggerRateCapOverride = 2 - if env.player.modDB:Flag(nil, "Condition:Phasing") then - if env.player.breakdown then - env.player.breakdown.TriggerRateCap = { - s_format("%.2f ^8(Unseen Strike from The Hidden Blade has no cooldown but is still triggered)", env.player.mainSkill.skillData.triggerRateCapOverride), - s_format("= %.2f", env.player.mainSkill.skillData.triggerRateCapOverride), - } - end - return {source = env.player.mainSkill} - end - env.player.mainSkill.skillFlags.disable = true - env.player.mainSkill.disableReason = "This skill is requires you to be phasing" - end, - ["replica eternity shroud"] = function(env) - env.player.mainSkill.skillFlags.globalTrigger = true - return {source = env.player.mainSkill} - end, - ["shroud of the lightless"] = function(env) - env.player.mainSkill.skillFlags.globalTrigger = true - return {source = env.player.mainSkill} - end, - ["limbsplit"] = function() - return {triggerName = "Gore Shockwave", triggerSkillCond = function(env, skill) return (skill.skillTypes[SkillType.Melee] or skill.skillTypes[SkillType.Attack]) end} - end, - ["the cauteriser"] = function() - return {triggerName = "Gore Shockwave", triggerSkillCond = function(env, skill) return (skill.skillTypes[SkillType.Melee] or skill.skillTypes[SkillType.Attack]) end} - end, - ["duskblight"] = function() - return {triggerName = "Stalking Pustule", triggerSkillCond = function(env, skill) return (skill.skillTypes[SkillType.Damage] or skill.skillTypes[SkillType.Attack]) end} - end, - ["lioneye's paws"] = function(env) - -- Due to the way the triggerExtraSkill function in mod parser works this trigger does not use the custom trigger skill (RainOfArrowsOnAttackingWithBow) - -- the normal version is used here instead. The stats are the same but the normal version does not have cooldown. - env.player.mainSkill.skillData.cooldown = 1 - return {triggerOnUse = true, triggerSkillCond = function(env, skill) return skill.skillTypes[SkillType.Attack] and band(skill.skillCfg.flags, ModFlag.Bow) > 0 end} - end, - ["replica lioneye's paws"] = function(env) - -- Due to the way the triggerExtraSkill function in mod parser works this trigger does not use the custom trigger skill (RainOfArrowsOnAttackingWithBow) - -- the normal version is used here instead. The stats are the same but the normal version does not have cooldown. - env.player.mainSkill.skillData.cooldown = 1 - return {triggerOnUse = true, triggerSkillCond = function(env, skill) return skill.skillTypes[SkillType.Attack] and band(skill.skillCfg.flags, ModFlag.Bow) > 0 end} - end, - ["moonbender's wing"] = function(env) - --Similar situation to "Replica Lioneye's Paws" - env.player.mainSkill.skillData.cooldown = 1 - return {triggerName = "Lightning Warp", triggerSkillCond = function(env, skill) return (skill.skillTypes[SkillType.Melee] or skill.skillTypes[SkillType.Attack]) end} - end, - ["ngamahu's flame"] = function() - return {triggerName = "Molten Burst", triggerSkillCond = function(env, skill) return (skill.skillTypes[SkillType.Melee] or skill.skillTypes[SkillType.Attack]) end} - end, - ["cameria's avarice"] = function() - return {triggerName = "Icicle Burst", triggerSkillCond = function(env, skill) return (skill.skillTypes[SkillType.Damage] or skill.skillTypes[SkillType.Attack]) end} - end, - ["uul-netol's embrace"] = function() - return {triggerName = "Bone Nova", triggerSkillCond = function(env, skill) return (skill.skillTypes[SkillType.Damage] or skill.skillTypes[SkillType.Attack]) end} - end, - ["rigwald's crest"] = function(env) - env.player.mainSkill.skillData.sourceRateIsFinal = true - return {assumingEveryHitKills = true, triggerSkillCond = function(env, skill) return (skill.skillTypes[SkillType.Damage] or skill.skillTypes[SkillType.Attack]) end} - end, - ["jorrhast's blacksteel"] = function(env) - env.player.mainSkill.skillData.sourceRateIsFinal = true - return {assumingEveryHitKills = true, triggerSkillCond = function(env, skill) return (skill.skillTypes[SkillType.Damage] or skill.skillTypes[SkillType.Attack]) end} - end, - ["ashcaller"] = function(env) - env.player.mainSkill.skillData.sourceRateIsFinal = true - return {assumingEveryHitKills = true, triggerSkillCond = function(env, skill) return (skill.skillTypes[SkillType.Damage] or skill.skillTypes[SkillType.Attack]) end} - end, - ["arakaali's fang"] = function() - return {assumingEveryHitKills = true, triggerSkillCond = function(env, skill) return (skill.skillTypes[SkillType.Damage] or skill.skillTypes[SkillType.Attack]) end} - end, - ["sporeguard"] = function() - return {assumingEveryHitKills = true, triggerSkillCond = function(env, skill) return (skill.skillTypes[SkillType.Damage] or skill.skillTypes[SkillType.Attack]) end} - end, - ["mark of the elder"] = function() - return {assumingEveryHitKills = true, triggerSkillCond = function(env, skill) return (skill.skillTypes[SkillType.Damage] or skill.skillTypes[SkillType.Attack]) end} - end, - ["mark of the shaper"] = function() - return {assumingEveryHitKills = true, triggerSkillCond = function(env, skill) return (skill.skillTypes[SkillType.Damage] or skill.skillTypes[SkillType.Attack]) end} - end, - ["poet's pen"] = function() - return {triggerOnUse = true, - triggerSkillCond = function(env, skill) - return (skill.skillTypes[SkillType.Damage] or skill.skillTypes[SkillType.Attack]) and band(skill.skillCfg.flags, ModFlag.Wand) > 0 - end, - triggeredSkillCond = function(env, skill) - return skill.skillData.triggeredByUnique and env.player.mainSkill.socketGroup.slot == skill.socketGroup.slot and skill.skillTypes[SkillType.Spell] - end} - end, - ["maloney's mechanism"] = function(env) - local _, _, uniqueTriggerName = env.player.itemList[env.player.mainSkill.slotName].modSource:find(".*:.*:(.*),.*") - local isReplica = uniqueTriggerName:match("Replica.") - return {triggerOnUse = true, triggerName = uniqueTriggerName, useCastRate = isReplica, - triggerSkillCond = function(env, skill) - local attack = skill.skillTypes[SkillType.Attack] and (band(skill.skillCfg.flags, ModFlag.Bow) > 0) and not isReplica - local spell = skill.skillTypes[SkillType.Spell] and isReplica - return (attack or spell) - end, - triggeredSkillCond = function(env, skill) - return skill.skillData.triggeredByUnique and env.player.mainSkill.socketGroup.slot == skill.socketGroup.slot and skill.skillTypes[SkillType.RangedAttack] - end} - end, - ["asenath's chant"] = function() - return {triggerOnUse = true, - triggerSkillCond = function(env, skill) - return (skill.skillTypes[SkillType.Damage] or skill.skillTypes[SkillType.Attack]) and band(skill.skillCfg.flags, ModFlag.Bow) > 0 - end, - triggeredSkillCond = function(env, skill) - return skill.skillData.triggeredByUnique and env.player.mainSkill.socketGroup.slot == skill.socketGroup.slot and skill.skillTypes[SkillType.Spell] - end} - end, - ["vixen's entrapment"] = function() - return {useCastRate = true, - triggerSkillCond = function(env, skill) - return skill.skillTypes[SkillType.Hex] - end} - end, - ["flames of judgement"] = function(env) - env.player.mainSkill.skillData.sourceRateIsFinal = true - return {triggerName = env.player.mainSkill.activeEffect.grantedEffect.name, - triggerSkillCond = function(env, skill) return skill.activeEffect.grantedEffect.name == "Queen's Demand" end, - triggeredSkillCond = function(env, skill) return skill.skillData.triggeredByUnique and env.player.mainSkill.socketGroup.slot == skill.socketGroup.slot end} - end, - ["storm of judgement"] = function(env) - env.player.mainSkill.skillData.sourceRateIsFinal = true - return {triggerName = env.player.mainSkill.activeEffect.grantedEffect.name, - triggerSkillCond = function(env, skill) return skill.activeEffect.grantedEffect.name == "Queen's Demand" end, - triggeredSkillCond = function(env, skill) return skill.skillData.triggeredByUnique and env.player.mainSkill.socketGroup.slot == skill.socketGroup.slot end} - end, - ["trigger craft"] = function(env) - if env.player.mainSkill.skillData.triggeredByCraft then - local trigRate, source, uuid, useCastRate, triggeredSkills - triggeredSkills = {} - for _, skill in ipairs(env.player.activeSkillList) do - if (skill.skillTypes[SkillType.Damage] or skill.skillTypes[SkillType.Attack] or skill.skillTypes[SkillType.Spell]) and not skill.skillFlags.aura and skill ~= env.player.mainSkill and not skill.skillData.triggeredByCraft and not skill.activeEffect.grantedEffect.fromItem and not isTriggered(skill) then - source, trigRate, uuid = findTriggerSkill(env, skill, source, trigRate) - if skill.skillFlags and (skill.skillFlags.totem or skill.skillFlags.golem or skill.skillFlags.banner or skill.skillFlags.ballista) and skill.activeEffect.grantedEffect.castTime then - if skill.activeEffect.grantedEffect.levels ~= nil then - trigRate = 1 / (skill.activeEffect.grantedEffect.castTime + (skill.activeEffect.grantedEffect.levels[skill.activeEffect.level].cooldown or 0)) - else - trigRate = 1 / skill.activeEffect.grantedEffect.castTime - end - useCastRate = true - end - end - if skill.skillData.triggeredByCraft and env.player.mainSkill.socketGroup.slot == skill.socketGroup.slot then - t_insert(triggeredSkills, packageSkillDataForSimulation(skill, env)) - end - end - return {trigRate = trigRate, source = source, uuid = uuid, useCastRate = useCastRate, triggeredSkills = triggeredSkills} - end - end, - ["kitava's thirst"] = function(env) - local requiredManaCost = env.player.modDB:Sum("BASE", nil, "KitavaRequiredManaCost") - return {triggerChance = env.player.modDB:Sum("BASE", nil, "KitavaTriggerChance"), - triggerName = "Kitava's Thirst", - comparer = function(env, uuid, source, triggerRate) - local cachedSpeed = GlobalCache.cachedData[env.mode][uuid].HitSpeed or GlobalCache.cachedData[env.mode][uuid].Speed - local cachedManaCost = GlobalCache.cachedData[env.mode][uuid].ManaCost - return ( (not source and cachedSpeed) or (cachedSpeed and cachedSpeed > (triggerRate or 0)) ) and ( (cachedManaCost or 0) > requiredManaCost ) - end, - triggerSkillCond = function(env, skill) - return true - -- Filtering done by skill() in SkillStatMap, comparer and default excludes - end} - end, - ["mjolner"] = function() - return {triggerSkillCond = function(env, skill) - return (skill.skillTypes[SkillType.Damage] or skill.skillTypes[SkillType.Attack]) and band(skill.skillCfg.flags, bor(ModFlag.Mace, ModFlag.Weapon1H)) > 0 and not slotMatch(env, skill) - end, - triggeredSkillCond = function(env, skill) - return skill.skillData.triggeredByMjolner and slotMatch(env, skill) - end} - end, - ["cospri's malice"] = function() - return {triggerSkillCond = function(env, skill) - return skill.skillTypes[SkillType.Melee] and band(skill.skillCfg.flags, bor(ModFlag.Sword, ModFlag.Weapon1H)) > 0 - end, - triggeredSkillCond = function(env, skill) return skill.skillData.triggeredByCospris and env.player.mainSkill.socketGroup.slot == skill.socketGroup.slot end} - end, - ["cast on critical strike"] = function() - return {triggerSkillCond = function(env, skill) return skill.skillTypes[SkillType.Attack] and slotMatch(env, skill) end, - triggeredSkillCond = function(env, skill) return skill.skillData.triggeredByCoc and slotMatch(env, skill) end} - end, - ["cast on melee kill"] = function(env) - if env.player.modDB:Flag(nil, "Condition:KilledRecently") then - return {assumingEveryHitKills = true, - triggerSkillCond = function(env, skill) - return skill.skillTypes[SkillType.Attack] and skill.skillTypes[SkillType.Melee] and slotMatch(env, skill) - end, - triggeredSkillCond = function(env, skill) return skill.skillData.triggeredByMeleeKill and slotMatch(env, skill) end} - else - env.player.mainSkill.infoMessage2 = "DPS reported assuming Self-Cast" - env.player.mainSkill.infoMessage = "Cast on Melee Kill requires recent kills" - end - end, - ["nova"] = function(env) - if env.minion and env.minion.mainSkill then - return {triggerName = "Summon Holy Relic", - actor = env.minion, - triggeredSkills = {{ uuid = cacheSkillUUID(env.minion.mainSkill, env), cd = env.minion.mainSkill.skillData.cooldown}}, - triggerSkillCond = function(env, skill) return skill.skillTypes[SkillType.Attack] end} - end - end, - ["cast when damage taken"] = function(env) - if env.player.mainSkill.skillData.triggeredByDamageTaken then - local thresholdMod = calcLib.mod(env.player.mainSkill.skillModList, nil, "CWDTThreshold") - env.player.output.CWDTThreshold = env.player.mainSkill.skillData.triggeredByDamageTaken * thresholdMod - if env.player.breakdown and env.player.output.CWDTThreshold ~= env.player.mainSkill.skillData.triggeredByDamageTaken then - env.player.breakdown.CWDTThreshold = { - s_format("%.2f ^8(base threshold)", env.player.mainSkill.skillData.triggeredByDamageTaken), - s_format("x %.2f ^8(threshold modifier)", thresholdMod), - s_format("= %.2f", env.player.output.CWDTThreshold), - } - end - env.player.mainSkill.skillFlags.globalTrigger = true - return {source = env.player.mainSkill} - end - end, - ["cast when stunned"] = function(env) - env.player.mainSkill.skillFlags.globalTrigger = true - return {triggerChance = env.player.mainSkill.skillData.chanceToTriggerOnStun, - source = env.player.mainSkill} - end, - ["automation"] = function(env) - if env.player.mainSkill.activeEffect.grantedEffect.name == "Automation" then - -- This calculated the trigger rate of the Automation gem it self - env.player.mainSkill.skillFlags.globalTrigger = true - return {source = env.player.mainSkill} - end - env.player.mainSkill.skillData.sourceRateIsFinal = true - - -- Trigger rate of the triggered skill is capped by the cooldown of Automation - -- which will likely be different from the cooldown of the triggered skill - -- and is affected by different cooldown modifiers - env.player.mainSkill.skillData.ignoresTickRate = true +---@param env Env +---@param actor Actor +---@param metaSkill ActiveSkill +---@param config MetaGemConfig +local function metaGemTriggerHandler(env, actor, metaSkill, config) + local output = actor.output + ---@class Breakdown + local breakdown = actor.breakdown + ---@type ActiveSkill + local skill = actor.mainSkill + local triggerName = metaSkill.activeEffect.grantedEffect.name + + local maxEnergyBreakdown = breakdown and {} + local maxEnergy, triggeredSkills = calcMaxEnergy(env, metaSkill, maxEnergyBreakdown) + if maxEnergy <= 0 then + assumeSelfCast(skill, s_format("%s has no socketed skills that use Energy", triggerName)) + return + end + local energyMult = calcLib.mod(metaSkill.skillModList, metaSkill.skillCfg, "EnergyGenerated") + local energyPerEvent, eventRate, source = config.energy(env, actor, metaSkill.skillData, energyMult, maxEnergy, config) + if not energyPerEvent then + assumeSelfCast(skill, s_format("No %s Triggering Skill Found", triggerName)) + return + end - -- This basically does min(trigger rate of steelskin assuming no trigger cooldown, trigger rate of Automation) - return {triggerOnUse = true, - useCastRate = true, - triggerSkillCond = function(env, skill) - return skill.activeEffect.grantedEffect.name == "Automation" - end} - end, - ["spellslinger"] = function(env) - if env.player.mainSkill.activeEffect.grantedEffect.name == "Spellslinger" then - return {triggerName = "Spellslinger", - triggerOnUse = true, - triggerSkillCond = function(env, skill) - local isWandAttack = (not skill.weaponTypes or (skill.weaponTypes and skill.weaponTypes["Wand"])) and skill.skillTypes[SkillType.Attack] - return isWandAttack and not skill.skillData.triggeredBySpellSlinger - end} - end - env.player.mainSkill.skillData.sourceRateIsFinal = true - return {triggerOnUse = true, - useCastRate = true, - triggerSkillCond = function(env, skill) - return skill.activeEffect.grantedEffect.name == "Spellslinger" - end} - end, - ["call to arms"] = function(env) - if env.player.mainSkill.activeEffect.grantedEffect.name == "Call to Arms" then - env.player.mainSkill.skillFlags.globalTrigger = true - return {source = env.player.mainSkill} - end - env.player.mainSkill.skillData.sourceRateIsFinal = true - env.player.mainSkill.skillData.ignoresTickRate = true - return {triggerOnUse = true, - useCastRate = true, - triggerSkillCond = function(env, skill) - return skill.activeEffect.grantedEffect.name == "Call to Arms" - end} - end, - ["autoexertion"] = function(env) - if env.player.mainSkill.activeEffect.grantedEffect.name == "Autoexertion" then - env.player.mainSkill.skillFlags.globalTrigger = true - return {source = env.player.mainSkill} - end - env.player.mainSkill.skillData.sourceRateIsFinal = true - env.player.mainSkill.skillData.ignoresTickRate = true - return {triggerOnUse = true, - useCastRate = true, - triggerSkillCond = function(env, skill) - return skill.activeEffect.grantedEffect.name == "Autoexertion" - end} - end, - ["mark on hit"] = function() - return {triggerSkillCond = function(env, skill) return skill.skillTypes[SkillType.Attack] end} - end, - ["hextouch"] = function(env) - env.player.mainSkill.skillData.sourceRateIsFinal = true - return {triggerSkillCond = function(env, skill) - return skill.skillTypes[SkillType.Attack] and slotMatch(env, skill) - end} - end, - ["oskarm"] = function(env) - env.player.mainSkill.skillData.sourceRateIsFinal = true - return {triggerSkillCond = function(env, skill) - return skill.skillTypes[SkillType.Attack] - end} - end, - ["tempest shield"] = function(env) - env.player.mainSkill.skillFlags.globalTrigger = true - return {source = env.player.mainSkill} - end, - ["shattershard"] = function(env) - env.player.mainSkill.skillFlags.globalTrigger = true - 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] = true}) - 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)", GlobalCache.cachedData[env.mode][uuid].Env.player.output.Duration), - s_format("= %.2f ^8per second", env.player.mainSkill.skillData.triggerRateCapOverride), + -- Energy gains round down to 0.01 + energyPerEvent = m_floor(energyPerEvent * energyMult * 100 + 1e-9) / 100 + if energyPerEvent * eventRate <= 0 then + assumeSelfCast(skill, s_format("%s gains no Energy from %ss", triggerName, config.eventName)) + return + end + -- Excess Energy is discarded when the meta gem triggers, so each trigger takes a whole number of events + local events = m_ceil(maxEnergy / energyPerEvent - 1e-9) + output.EnergyPerSecond = energyPerEvent * eventRate + output.MaxEnergy = maxEnergy + + -- A triggered skill's own cooldown still caps how often it can go off + local triggerRateCap = m_huge + local cooldown, rounded = calcSkillCooldown(skill.skillModList, skill.skillCfg, skill.skillData) + if cooldown > 0 then + triggerRateCap = 1 / cooldown + output.TriggerRateCap = triggerRateCap + if breakdown then + breakdown.TriggerRateCap = { + s_format("1 / %.3fs ^8(cooldown%s)", cooldown, rounded and ", rounded up to nearest server tick" or ""), + s_format("= %.2f ^8per second", triggerRateCap), } end - return {source = env.player.mainSkill} - end, - ["battlemage's cry"] = function(env) - if env.player.mainSkill.activeEffect.grantedEffect.name ~= "Battlemage's Cry" then - return {triggerSkillCond = function(env, skill) return skill.skillTypes[SkillType.Melee] end, - comparer = function(env, uuid, source, triggerRate) - -- Skills with no uptime ratio are not exerted by battlemage so should not be considered. - local uptimeRatio = GlobalCache.cachedData[env.mode][uuid].Env.player.output.BattlemageUpTimeRatio - return defaultComparer(env, uuid, source, triggerRate) and uptimeRatio - end, - triggeredSkillCond = function(env, skill) return skill.skillData.triggeredByBattleMageCry and slotMatch(env, skill) end} - end - end, - ["arcanist brand"] = function(env) - if env.player.mainSkill.activeEffect.grantedEffect.name ~= "Arcanist Brand" then - env.player.mainSkill.skillData.sourceRateIsFinal = true - for _, skill in ipairs(env.player.activeSkillList) do - if skill.activeEffect.grantedEffect.name == "Arcanist Brand" then - env.player.mainSkill.triggeredBy.mainSkill = skill - break - end - end + end - local activationFreqInc = (100 + env.player.mainSkill.triggeredBy.mainSkill.skillModList:Sum("INC", env.player.mainSkill.skillCfg, "Speed", "BrandActivationFrequency")) / 100 - local activationFreqMore = env.player.mainSkill.triggeredBy.mainSkill.skillModList:More(env.player.mainSkill.skillCfg, "BrandActivationFrequency") - env.player.mainSkill.triggeredBy.activationFreqInc = activationFreqInc - env.player.mainSkill.triggeredBy.activationFreqMore = activationFreqMore - env.player.mainSkill.triggeredBy.ignoresTickRate = true - return {trigRate = env.player.mainSkill.triggeredBy.mainSkill.skillData.repeatFrequency * activationFreqInc * activationFreqMore, - source = env.player.mainSkill.triggeredBy.mainSkill, - triggeredSkillCond = function(env, skill) return skill.skillData.triggeredByBrand and slotMatch(env, skill) end} - end - end, - ["cast on death"] = function(env) - env.player.mainSkill.skillFlags.globalTrigger = true - env.player.mainSkill.skillData.triggered = true - env.player.mainSkill.infoMessage = env.player.mainSkill.activeEffect.grantedEffect.name .. " Triggered on Death" - end, - ["combust"] = function(env) - return {triggerSkillCond = function(env, skill) return skill.skillTypes[SkillType.Melee] end, - comparer = function(env, uuid, source, triggerRate) - -- Skills with no uptime ratio are not exerted by infernal cry so should not be considered. - local uptimeRatio = GlobalCache.cachedData[env.mode][uuid].Env.player.output.InfernalUpTimeRatio - return defaultComparer(env, uuid, source, triggerRate) and uptimeRatio - end,} - end, - ["prismatic burst"] = function(env) - return {triggerSkillCond = function(env, skill) return skill.skillTypes[SkillType.Attack] and slotMatch(env, skill) end} - end, - ["shockwave"] = function(env) - return {triggerSkillCond = function(env, skill) return skill.skillTypes[SkillType.Melee] and slotMatch(env, skill) end} - end, - ["manaforged arrows"] = function(env) - return {triggerOnUse = true, - triggerName = "Manaforged Arrows", - triggerSkillCond = function(env, skill) return skill.skillTypes[SkillType.Attack] and band(skill.skillCfg.flags, ModFlag.Bow) > 0 end} - end, - ["doom blast"] = function(env) - if env.build.configTab.input["doomBlastSource"] == "replacement" then - env.player.modDB:NewMod("UsesCurseOverlaps", "FLAG", true, "Config") - end - env.player.mainSkill.skillData.ignoresTickRate = true - return {useCastRate = true, - overlaps = #env.player.modDB:Tabulate("BASE", nil, "Multiplier:CurseOverlaps") > 0 and m_max(env.player.modDB:Sum("BASE", nil, "Multiplier:CurseOverlaps"), 1), - customTriggerName = "Doom Blast triggering Hex: ", - triggerSkillCond = function(env, skill) return skill.skillTypes[SkillType.Hex] and slotMatch(env, skill) end} - end, - ["cast while channelling"] = function() - return {customHandler = CWCHandler} - end, - ["focus"] = function() - return {customHandler = helmetFocusHandler} - end, - ["snipe"] = function(env) - local snipeStages = m_min(env.player.modDB:Sum("BASE", nil, "Multiplier:SnipeStage"), env.player.modDB:Sum("BASE", nil, "Multiplier:SnipeStagesMax")) - local snipeHitMulti = env.player.mainSkill.skillModList:Sum("BASE", env.player.mainSkill.skillCfg, "snipeHitMulti") - local snipeAilmentMulti = env.player.mainSkill.skillModList:Sum("BASE", env.player.mainSkill.skillCfg, "snipeAilmentMulti") - local triggeredSkills = {} + output.SkillTriggerRate = m_min(eventRate / events, triggerRateCap) + skill.skillData.triggered = true + skill.skillData.triggerRate = output.SkillTriggerRate + if source then + skill.skillData.triggerSourceUUID = cacheSkillUUID(source, env) + skill.infoMessage = triggerName .. "'s Trigger: " .. source.activeEffect.grantedEffect.name + else + skill.infoMessage = triggerName .. " Trigger" + end + skill.infoTrigger = triggerName + addTriggerIncMoreMods(skill, source or skill) - for _, skill in ipairs(env.player.activeSkillList) do - if skill.skillData.triggeredBySnipe and skill.socketGroup and skill.socketGroup.slot == env.player.mainSkill.socketGroup.slot then - t_insert(triggeredSkills, skill) - end + if breakdown then + breakdown.MaxEnergy = maxEnergyBreakdown + if metaSkill.skillData.maxEnergyFromSocketedSkills then + t_insert(breakdown.MaxEnergy, 1, "Energy cost of each socketed skill (100 per second of base cast time, 200 per second of added total cast time):") end + t_insert(breakdown.MaxEnergy, s_format("= %.0f ^8(maximum Energy)", maxEnergy)) - if env.player.mainSkill.activeEffect.grantedEffect.name == "Snipe" then - if (env.limitedSkills and env.limitedSkills[cacheSkillUUID(env.player.mainSkill, env)]) then - -- Snipe is being used by some other skill. In this case snipe does not get more damage mods - snipeStages = 0 - else - -- max(1, snipeStages) makes it behave consistently with other channeled ranged skills (scourge arrow) - env.player.mainSkill.skillData.hitTimeMultiplier = m_max(1, snipeStages) - 0.5 --First stage takes 0.5x time to channel compared to subsequent stages - end - if #triggeredSkills < 1 then - -- Snipe is being used as a standalone skill - if snipeStages then - env.player.mainSkill.skillModList:NewMod("Multiplier:SnipeStages", "BASE", snipeStages, "Snipe") - env.player.mainSkill.skillModList:NewMod("Damage", "MORE", snipeHitMulti, "Snipe", ModFlag.Hit, 0, { type = "Multiplier", var = "SnipeStages" }) - env.player.mainSkill.skillModList:NewMod("Damage", "MORE", snipeAilmentMulti, "Snipe", ModFlag.Ailment, 0, { type = "Multiplier", var = "SnipeStages" }) - end - else - -- Snipe is being used as a trigger source, it triggers other skills but does no damage it self - env.player.mainSkill.skillModList:NewMod("DealNoLightning", "FLAG", true, { type = "SkillName", skillName = "Snipe", includeTransfigured = true }) - env.player.mainSkill.skillModList:NewMod("DealNoCold", "FLAG", true, { type = "SkillName", skillName = "Snipe", includeTransfigured = true }) - env.player.mainSkill.skillModList:NewMod("DealNoFire", "FLAG", true, { type = "SkillName", skillName = "Snipe", includeTransfigured = true }) - env.player.mainSkill.skillModList:NewMod("DealNoChaos", "FLAG", true, { type = "SkillName", skillName = "Snipe", includeTransfigured = true }) - env.player.mainSkill.skillModList:NewMod("DealNoPhysical", "FLAG", true, { type = "SkillName", skillName = "Snipe", includeTransfigured = true }) - end + breakdown.EnergyPerSecond = {} + if source then + t_insert(breakdown.EnergyPerSecond, s_format("%.2f ^8(Energy per %s from %s)", energyPerEvent, config.eventName, source.activeEffect.grantedEffect.name)) + t_insert(breakdown.EnergyPerSecond, s_format("^8(Monster Power x unmitigated %s damage / enemy Ailment Threshold)", config.eventName)) else - local currentSkillSnipeIndex - for index, skill in ipairs(triggeredSkills) do - if skill == env.player.mainSkill then - currentSkillSnipeIndex = index - break - end - end - - -- Does snipe have enough stages to trigger this skill? - if currentSkillSnipeIndex and currentSkillSnipeIndex <= snipeStages then - local source - local trigRate - env.player.mainSkill.skillModList:NewMod("Multiplier:SnipeStages", "BASE", snipeStages, "Snipe") - env.player.mainSkill.skillModList:NewMod("Damage", "MORE", snipeAilmentMulti, "Snipe", ModFlag.Ailment, 0, { type = "Multiplier", var = "SnipeStages" }) - env.player.mainSkill.skillModList:NewMod("Damage", "MORE", snipeHitMulti, "Snipe", ModFlag.Hit, 0, { type = "Multiplier", var = "SnipeStages" }) - for _, skill in ipairs(env.player.activeSkillList) do - if skill.activeEffect.grantedEffect.name == "Snipe" and skill.socketGroup and skill.socketGroup.slot == env.player.mainSkill.socketGroup.slot then - skill.skillData.hitTimeMultiplier = snipeStages - 0.5 - local uuid = cacheSkillUUID(skill, env) - if not GlobalCache.cachedData[env.mode][uuid] or env.mode == "CALCULATOR" then - calcs.buildActiveSkill(env, env.mode, skill, uuid) - end - local cachedSpeed = GlobalCache.cachedData[env.mode][uuid].Env.player.output.HitSpeed - if (skill.skillFlags and not skill.skillFlags.disable) and (skill.skillCfg and not skill.skillCfg.skillCond["usedByMirage"]) and not skill.skillTypes[SkillType.OtherThingUsesSkill] and ((not source and cachedSpeed) or (cachedSpeed and cachedSpeed > (trigRate or 0))) then - trigRate = cachedSpeed - env.player.output.ChannelTimeToTrigger = GlobalCache.cachedData[env.mode][uuid].Env.player.output.HitTime - source = skill - end - end - end - - return {trigRate = trigRate, source = source} - else - env.player.mainSkill.skillData.triggered = nil - env.player.mainSkill.infoMessage2 = "DPS reported assuming Self-Cast" - env.player.mainSkill.infoMessage = "Not enough Snipe stages to trigger this skill" - env.player.mainSkill.infoTrigger = "" - end - end - end, - ["avenging flame"] = function(env) - return {triggerSkillCond = function(env, skill) return skill.skillFlags.totem and slotMatch(env, skill) end, - comparer = function(env, uuid, source, currentTotemLife) - local totemLife = GlobalCache.cachedData[env.mode][uuid].Env.player.output.TotemLife - return (not source and totemLife) or (totemLife and totemLife > (currentTotemLife or 0)) - end, - ignoreSourceRate = true} - end, - ["intuitive link"] = function(env) - if env.player.mainSkill.activeEffect.grantedEffect.name ~= "Intuitive Link" then - for _, skill in ipairs(env.player.activeSkillList) do - if skill.activeEffect.grantedEffect.name == "Intuitive Link" then - env.player.mainSkill.triggeredBy.mainSkill = skill - break - end - end - return {triggeredSkillCond = function(env, skill) return skill.skillTypes[SkillType.Spell] and slotMatch(env, skill) and skill ~= env.player.mainSkill.triggeredBy.mainSkill end, - trigRate = env.modDB:Sum("BASE", nil, "IntuitiveLinkSourceRate"), - source = env.player.mainSkill.triggeredBy.mainSkill, - sourceName = "Custom source", - useCastRate = true} + t_insert(breakdown.EnergyPerSecond, s_format("%.2f ^8(Energy per %s)", energyPerEvent, config.eventName)) end - end, - ["supporttriggerelementalspellonblock"] = 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, - ["supporttriggerfirespellonhit"] = function(env) - return {triggerSkillCond = function(env, skill) - -- Skill is triggered only when the weapon with the enchant on it hits - return skill.skillTypes[SkillType.Melee] - end, - triggeredSkillCond = function(env, skill) - return skill.skillData.triggeredBySettlersEnchantTrigger and slotMatch(env, skill) - end} - end, -} + t_insert(breakdown.EnergyPerSecond, s_format("x %.2f ^8(%ss per second)", eventRate, config.eventName)) + t_insert(breakdown.EnergyPerSecond, s_format("= %.2f ^8(Energy per second)", output.EnergyPerSecond)) --- Find unique item trigger name -local function getUniqueItemTriggerName(skill) - if skill.skillData.triggerSource then - return skill.skillData.triggerSource - elseif skill.supportList and #skill.supportList >= 1 then - for _, gemInstance in ipairs(skill.supportList) do - if gemInstance.grantedEffect and gemInstance.grantedEffect.fromItem and not gemInstance.grantedEffect.support then - return gemInstance.grantedEffect.name - end + breakdown.SkillTriggerRate = { + s_format("%.2f ^8(%ss per second)", eventRate, config.eventName), + s_format("/ %d ^8(%ss to reach %.0f maximum Energy)", events, config.eventName, maxEnergy), + s_format("= %.2f ^8per second", eventRate / events), + } + if output.SkillTriggerRate < eventRate / events then + t_insert(breakdown.SkillTriggerRate, s_format("capped at %.2f ^8(trigger rate cap)", triggerRateCap)) end end - - if skill.socketGroup and skill.socketGroup.source then - local _, _, uniqueTriggerName = skill.socketGroup.source:find(".*:.*:(.*),.*") - return uniqueTriggerName - end end +---@param env Env +---@param actor Actor? function calcs.triggers(env, actor) - local skillFlags - if env.mode == "CALCS" then - skillFlags = actor.mainSkill.activeEffect.statSetCalcs.skillFlags - else - skillFlags = actor.mainSkill.activeEffect.statSet.skillFlags + if not actor then + return end - if actor and not skillFlags.disable and not (env.limitedSkills and env.limitedSkills[cacheSkillUUID(actor.mainSkill, env)]) then - local skillName = actor.mainSkill.activeEffect.grantedEffect.name - local triggerName = actor.mainSkill.triggeredBy and actor.mainSkill.triggeredBy.grantedEffect.name - local uniqueName = isTriggered(actor.mainSkill) and getUniqueItemTriggerName(actor.mainSkill) - local skillNameLower = skillName and skillName:lower() - local triggerNameLower = triggerName and triggerName:lower() - local awakenedTriggerNameLower = triggerNameLower and triggerNameLower:gsub("^awakened ", "") - local uniqueNameLower = uniqueName and uniqueName:lower() - local config = skillNameLower and configTable[skillNameLower] and configTable[skillNameLower](env) - config = config or triggerNameLower and configTable[triggerNameLower] and configTable[triggerNameLower](env) - config = config or awakenedTriggerNameLower and configTable[awakenedTriggerNameLower] and configTable[awakenedTriggerNameLower](env) - config = config or uniqueNameLower and configTable[uniqueNameLower] and configTable[uniqueNameLower](env) - if config then - config.actor = config.actor or actor - config.triggerName = config.triggerName or triggerName or skillName or uniqueName - config.triggerChance = config.triggerChance or (actor.mainSkill.activeEffect.srcInstance and actor.mainSkill.activeEffect.srcInstance.triggerChance) - local triggerHandler = config.customHandler or defaultTriggerHandler - triggerHandler(env, config) - else - actor.mainSkill.skillData.triggered = nil - end + -- Only Energy based meta gems are handled here. Other triggers such as Blasphemy keep their own flags + local triggeredBy = actor.mainSkill.triggeredBy + if not (triggeredBy and actor.mainSkill.skillData.energyPerCastTimeMs) or getSkillFlags(env, actor.mainSkill).disable then + return + end + local config = metaGemConfigs[triggeredBy.grantedEffect.id] + local metaSkill = findMetaGemSkill(env, actor) + if config and metaSkill then + metaGemTriggerHandler(env, actor, metaSkill, config) + else + local triggerName = metaSkill and metaSkill.activeEffect.grantedEffect.name or triggeredBy.grantedEffect.name + assumeSelfCast(actor.mainSkill, s_format("%s is not supported yet", triggerName)) end end diff --git a/src/Modules/Calcs.lua b/src/Modules/Calcs.lua index 0a4032a5e3..1e5c74e7cc 100644 --- a/src/Modules/Calcs.lua +++ b/src/Modules/Calcs.lua @@ -19,7 +19,6 @@ require("Modules.CalcActiveSkill") require("Modules.CalcDefence") require("Modules.CalcOffence") require("Modules.CalcTriggers") -require("Modules.CalcMirages") -- Get the average value of a table -- note this is unused function math.average(t) @@ -379,19 +378,6 @@ function calcs.calcFullDPS(build, mode, override, specEnv) end local playerOut = captureFields(usedEnv.player.output) - if activeSkill.mirage then - local mirageCount = (activeSkill.mirage.count or 1) * activeSkillCount - t_insert(pass.actors, { - out = captureFields(activeSkill.mirage.output), - name = activeSkill.mirage.name .. " (Mirage)", - count = mirageCount, - trigger = activeSkill.mirage.infoTrigger, - skillPart = activeSkill.mirage.skillPartName, - sourceName = skillName .. " (Mirage)", - dotScale = (dotCanStack or (playerOut.TotalDot and playerOut.TotalDot == 0)) and (dotCanStack and mirageCount or 1) or nil, - }) - end - local minionContributed = minionOut and minionOut.TotalDPS and minionOut.TotalDPS > 0 t_insert(pass.actors, { out = playerOut, diff --git a/src/Modules/Common.lua b/src/Modules/Common.lua index cef84e00d8..b4c9ccd09d 100644 --- a/src/Modules/Common.lua +++ b/src/Modules/Common.lua @@ -928,6 +928,24 @@ function cacheSkillUUID(skill, env) end -- Global Cache related +---@class CachedSkillData +---@field Name string +---@field Speed number +---@field HitSpeed number? +---@field ManaCost number? +---@field LifeCost number? +---@field ESCost number? +---@field RageCost number? +---@field HitChance number? +---@field AccuracyHitChance number? +---@field PreEffectiveCritChance number? +---@field CritChance number? +---@field TotalDPS number? +---@field ActiveSkill ActiveSkill +---@field Env Env + +---@param uuid string +---@param env Env function cacheData(uuid, env) GlobalCache.cachedData[env.mode][uuid] = { Name = env.player.mainSkill.activeEffect.grantedEffect.name, diff --git a/src/Modules/ConfigOptions.lua b/src/Modules/ConfigOptions.lua index 9033f6a152..2b27e93de9 100644 --- a/src/Modules/ConfigOptions.lua +++ b/src/Modules/ConfigOptions.lua @@ -723,6 +723,16 @@ local configSettings = { { var = "vortexCastOnFrostbolt", type = "check", label = "Cast on Frostbolt?", ifSkill = "Vortex of Projection", apply = function(val, modList, enemyModList) modList:NewMod("Condition:CastOnFrostbolt", "FLAG", true, "Config", { type = "SkillName", skillName = "Vortex of Projection" }) end }, + { label = "Meta Skills:", ifSkillType = SkillType.Meta }, + { var = "monsterPower", type = "count", label = "Monster Power:", ifSkillType = SkillType.Meta, defaultPlaceholderState = 20, tooltip = "Meta Skills gain Energy in proportion to the Power of the enemies involved.\nPower is assumed to be 20, the Power of a Unique enemy, but you can override it here.\n\tEach enemy's Power is its base Power multiplied by a rarity coefficient\n\tBase Power is usually between 0.5 and 3, depending on how strong the monster is\n\tThe rarity coefficient is 1, 2 or 5 for Normal, Magic or Rare enemies\n\tUnique enemies always have 20 Power\n\nThe total Power of a full pack is usually also around 15 to 20, but only if you hit every monster in it.", apply = function(val, modList, enemyModList) + modList:NewMod("MonsterPower", "OVERRIDE", val, "Config") + end }, + { var = "dodgeRollsPerSecond", type = "float", label = "Dodge Rolls per second:", ifSkill = "Cast on Dodge", defaultPlaceholderState = 1, apply = function(val, modList, enemyModList) + modList:NewMod("DodgeRollsPerSecond", "OVERRIDE", val, "Config") + end }, + { var = "multiplierCharmChargesUsedPerSecond", type = "float", label = "Charm Charges used per second:", ifSkill = "Cast on Charm Use", apply = function(val, modList, enemyModList) + modList:NewMod("Multiplier:CharmChargesUsedPerSecond", "BASE", val, "Config") + end }, { label = "Warcry Skills:", ifFlag = "UsesWarcryPower" }, { var = "multiplierWarcryPower", type = "count", label = "Warcry Power:", ifFlag = "UsesWarcryPower", tooltip = "Power determines how strong your Warcry buffs will be, and is based on the total strength of nearby enemies.\nPower is assumed to be 20 if your target is a Boss, but you can override it here if necessary.\n\tEach Normal enemy grants 1 Power\n\tEach Magic enemy grants 2 Power\n\tEach Rare enemy grants 10 Power\n\tEach Unique enemy grants 20 Power", apply = function(val, modList, enemyModList) modList:NewMod("WarcryPower", "OVERRIDE", val, "Config") diff --git a/src/Modules/ModParser.lua b/src/Modules/ModParser.lua index ff8a00f8fa..5040c9cc62 100644 --- a/src/Modules/ModParser.lua +++ b/src/Modules/ModParser.lua @@ -686,6 +686,8 @@ local modNameList = { ["melee strike range with this weapon"] = "MeleeWeaponRange", ["metres to melee strike range"] = { "MeleeWeaponRangeMetre", "UnarmedRangeMetre" }, ["metre to melee strike range"] = { "MeleeWeaponRangeMetre", "UnarmedRangeMetre" }, + ["metres to dodge roll distance"] = "DodgeRollDistance", + ["metre to dodge roll distance"] = "DodgeRollDistance", ["to deal double damage"] = "DoubleDamageChance", ["to deal triple damage"] = "TripleDamageChance", ["curse activation"] = "CurseActivation", @@ -2089,6 +2091,7 @@ local modTagList = { { type = "StatThreshold", stat = "ManaReserved", threshold = 1} } }, ["if you've shattered an enemy recently"] = { tag = { type = "Condition", var = "ShatteredEnemyRecently" } }, ["if you've dodge rolled recently"] = { tag = { type = "Condition", var = "DodgeRolledRecently" } }, + ["if you haven't dodge rolled recently"] = { tag = { type = "Condition", var = "DodgeRolledRecently", neg = true } }, -- Enemy status conditions ["at close range"] = { tag = { type = "Condition", var = "AtCloseRange" } }, ["against rare [ao][nr]d? unique enemies"] = { tag = { type = "ActorCondition", actor = "enemy", var = "RareOrUnique" } }, @@ -3565,6 +3568,12 @@ local specialModList = { mod("ExtraSkill", "LIST", { skillId = "Snipe", level = num }), mod("ExtraSupport", "LIST", { skillId = "ChannelledSnipeSupport", level = num }, { type = "SocketedIn", slotName = "{SlotName}" }), } end, + -- Meta gem Energy + ["meta skills gain (%d+)%% increased energy"] = function(num) return { mod("EnergyGenerated", "INC", num, { type = "SkillType", skillType = SkillType.Meta }) } end, + ["meta skills gain (%d+)%% reduced energy"] = function(num) return { mod("EnergyGenerated", "INC", -num, { type = "SkillType", skillType = SkillType.Meta }) } end, + ["meta skills gain (%d+)%% more energy"] = function(num) return { mod("EnergyGenerated", "MORE", num, { type = "SkillType", skillType = SkillType.Meta }) } end, + ["meta skills gain (%d+)%% increased energy if you've dealt a critical hit recently"] = function(num) return { mod("EnergyGenerated", "INC", num, { type = "SkillType", skillType = SkillType.Meta }, { type = "Condition", var = "CritRecently" }) } end, + ["meta skills gain (%d+)%% increased energy while on full mana"] = function(num) return { mod("EnergyGenerated", "INC", num, { type = "SkillType", skillType = SkillType.Meta }, { type = "Condition", var = "FullMana" }) } end, -- Global gem modifiers ["gems socketed in red sockets have [%+%-](%d+) to level"] = function(num) return { mod("GemProperty", "LIST", { keyword = "all", key = "level", value = num, keyOfScaledMod = "value" }, { type = "SocketedIn", slotName = "{SlotName}", socketColor = "R" }) } end, ["gems socketed in green sockets have [%+%-](%d+)%% to quality"] = function(num) return { mod("GemProperty", "LIST", { keyword = "all", key = "quality", value = num, keyOfScaledMod = "value" }, { type = "SocketedIn", slotName = "{SlotName}", socketColor = "G" }) } end, From 59762f3df8785eb11d33b66369b07ad906514dae Mon Sep 17 00:00:00 2001 From: vaisest <4550061+vaisest@users.noreply.github.com> Date: Wed, 11 Nov 2026 12:08:02 +0200 Subject: [PATCH 2/3] Add PoB1-like triggerSourceCache to fix CoC calc performance --- src/Modules/CalcBase.lua | 1 + src/Modules/CalcSetup.lua | 1 + src/Modules/CalcTriggers.lua | 13 ++++++++++--- src/Modules/Calcs.lua | 10 ++++++---- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/Modules/CalcBase.lua b/src/Modules/CalcBase.lua index 7dedffacbd..ef009b1d1e 100644 --- a/src/Modules/CalcBase.lua +++ b/src/Modules/CalcBase.lua @@ -225,6 +225,7 @@ return calcs ---@field weaponModList1? ModList ---@field sourceGemPropertyInfo? table ---@field override? CalcOverride +---@field triggerSourceCache? table Trigger source calculations shared by one calculator override's passes ---@field virtuousMoteSkillCount? table ---@field skillsUsed? table ---@field conditionsUsed? table diff --git a/src/Modules/CalcSetup.lua b/src/Modules/CalcSetup.lua index 950ff2e03b..b7990a5929 100644 --- a/src/Modules/CalcSetup.lua +++ b/src/Modules/CalcSetup.lua @@ -867,6 +867,7 @@ function calcs.initEnv(build, mode, override, specEnv) env.mode = mode env.buildBreakdown = mode == "MAIN" or mode == "CALCS" env.spec = override.spec or build.spec + env.override = override env.classId = env.spec.curClassId modDB = new("ModDB"):ModDB() diff --git a/src/Modules/CalcTriggers.lua b/src/Modules/CalcTriggers.lua index c68a92e761..cc4e7e8dff 100644 --- a/src/Modules/CalcTriggers.lua +++ b/src/Modules/CalcTriggers.lua @@ -178,10 +178,17 @@ local function hitEnergy(env, actor, metaData, energyMult, maxEnergy, config) local usedByPlayer = not (skill.skillTypes[SkillType.OtherThingUsesSkill] or skill.skillTypes[SkillType.UsedByProxy] or flags.totem or flags.trap or flags.mine) if canHit(skill) and not isTriggered(skill) and usedByPlayer and not flags.disable and (not config.sourceCond or config.sourceCond(skill)) then local uuid = cacheSkillUUID(skill, env) - if not GlobalCache.cachedData[env.mode][uuid] or env.mode == "CALCULATOR" then - calcs.buildActiveSkill(env, env.mode, skill, uuid) + local sourceCache = env.triggerSourceCache + local cachedData = sourceCache and sourceCache[uuid] + if not cachedData then + if not GlobalCache.cachedData[env.mode][uuid] or env.mode == "CALCULATOR" then + calcs.buildActiveSkill(env, env.mode, skill, uuid) + end + cachedData = GlobalCache.cachedData[env.mode][uuid] + if sourceCache then + sourceCache[uuid] = cachedData + end end - local cachedData = GlobalCache.cachedData[env.mode][uuid] if cachedData then local energy, rate = calcHitEnergy(env, cachedData, metaData, config) local energyPerHit = energy and m_floor(energy * energyMult * 100 + 1e-9) / 100 diff --git a/src/Modules/Calcs.lua b/src/Modules/Calcs.lua index 1e5c74e7cc..0ac3a38bee 100644 --- a/src/Modules/Calcs.lua +++ b/src/Modules/Calcs.lua @@ -119,9 +119,10 @@ function calcs.getMiscCalculator(build) local accelerate = fastEnv and fastCalcOptions or nil fastEnv = calcs.initEnv(build, "CALCULATOR", override, { cachedPlayerDB = cachedPlayerDB, cachedEnemyDB = cachedEnemyDB, cachedMinionDB = cachedMinionDB, env = fastEnv, accelerate = accelerate }) fastEnv.override = override + fastEnv.triggerSourceCache = {} calcs.perform(fastEnv, fastCalcOptions.skipEHP) if (useFullDPS ~= false or build.viewMode == "TREE") and usedFullDPS then - local fullDPS = calcs.calcFullDPS(build, "CALCULATOR", override, { cachedPlayerDB = cachedPlayerDB, cachedEnemyDB = cachedEnemyDB, cachedMinionDB = cachedMinionDB, env = nil}) + local fullDPS = calcs.calcFullDPS(build, "CALCULATOR", override, { cachedPlayerDB = cachedPlayerDB, cachedEnemyDB = cachedEnemyDB, cachedMinionDB = cachedMinionDB, env = nil, triggerSourceCache = fastEnv.triggerSourceCache }) fastEnv.player.output.SkillDPS = fullDPS.skills fastEnv.player.output.FullDPS = fullDPS.combinedDPS fastEnv.player.output.FullDotDPS = fullDPS.TotalDotDPS @@ -129,14 +130,13 @@ function calcs.getMiscCalculator(build) return fastEnv.player.output end local env, cachedPlayerDB, cachedEnemyDB, cachedMinionDB = calcs.initEnv(build, "CALCULATOR", override) - -- we need to preserve the override somewhere for use by possible trigger-based build-outs with overrides - env.override = override + env.triggerSourceCache = {} calcs.perform(env) if (useFullDPS ~= false or build.viewMode == "TREE") and usedFullDPS then -- prevent upcoming calculation from using Cached Data and thus forcing it to re-calculate new FullDPS roll-up -- without this, FullDPS increase/decrease when for node/item/gem comparison would be all 0 as it would be comparing -- A with A (due to cache reuse) instead of A with B - local fullDPS = calcs.calcFullDPS(build, "CALCULATOR", override, { cachedPlayerDB = cachedPlayerDB, cachedEnemyDB = cachedEnemyDB, cachedMinionDB = cachedMinionDB, env = nil}) + local fullDPS = calcs.calcFullDPS(build, "CALCULATOR", override, { cachedPlayerDB = cachedPlayerDB, cachedEnemyDB = cachedEnemyDB, cachedMinionDB = cachedMinionDB, env = nil, triggerSourceCache = env.triggerSourceCache }) env.player.output.SkillDPS = fullDPS.skills env.player.output.FullDPS = fullDPS.combinedDPS env.player.output.FullDotDPS = fullDPS.TotalDotDPS @@ -268,6 +268,7 @@ end function calcs.calcFullDPS(build, mode, override, specEnv) local fullEnv, cachedPlayerDB, cachedEnemyDB, cachedMinionDB = calcs.initEnv(build, mode, override, specEnv) + fullEnv.triggerSourceCache = mode == "CALCULATOR" and (specEnv and specEnv.triggerSourceCache or {}) or nil local usedEnv = nil -- Optional per-skill result cache driven by input diffing (specEnv.fullDPSCache): -- with capture set, each skill's harvested results are stored in the cache store along @@ -319,6 +320,7 @@ function calcs.calcFullDPS(build, mode, override, specEnv) if not skillEnv then skillEnv = calcs.initEnv(build, mode, getSocketGroupOverride(build, override, activeSkill.socketGroup)) end + skillEnv.triggerSourceCache = fullEnv.triggerSourceCache end activeSkill = findActiveSkillInEnv(skillEnv, sourceSkill) or activeSkill local uuid = cacheStore and cacheSkillUUID(activeSkill, skillEnv) From c0d60ba9351bc74b693a113159cdafde4d1f24c6 Mon Sep 17 00:00:00 2001 From: vaisest <4550061+vaisest@users.noreply.github.com> Date: Thu, 12 Nov 2026 02:41:45 +0200 Subject: [PATCH 3/3] Add support for x% chance to refund half --- spec/System/TestTriggers_spec.lua | 57 +++++++++++++++++++++++++++++++ src/Data/ModCache.lua | 13 ++++--- src/Data/SkillStatMap.lua | 3 ++ src/Modules/CalcTriggers.lua | 30 ++++++++++++++-- src/Modules/ModParser.lua | 2 ++ 5 files changed, 95 insertions(+), 10 deletions(-) diff --git a/spec/System/TestTriggers_spec.lua b/spec/System/TestTriggers_spec.lua index 4e1fbeacb7..2e9a283436 100644 --- a/spec/System/TestTriggers_spec.lua +++ b/spec/System/TestTriggers_spec.lua @@ -191,6 +191,63 @@ describe("TestTriggers", function() end) end) + describe("Energy Retention", function() + -- Cast on Dodge with no added distance gains 4 metres per roll at 3.14 Energy per metre + local energyPerMetre = 2 * 1.57 + + it("refunds half of the triggered skill's Energy cost on 35% of triggers", function() + build.skillsTab:PasteSocketGroup("Cast on Dodge 20/0 1\nSpark 20/0 1\nEnergy Retention 1/0 1") + runCallback("OnFrame") + selectSkill(1, 2) + setConfig("dodgeRollsPerSecond", 1) + -- 70 Energy takes 23 metres, or 12 metres after a refund of 35 + local metres = 0.65 * math.ceil(70 / energyPerMetre) + 0.35 * math.ceil(35 / energyPerMetre) + assertNear(4 / metres, build.calcsTab.mainOutput.SkillTriggerRate) + end) + + it("rolls the refund separately for each triggered skill", function() + build.skillsTab:PasteSocketGroup("Cast on Dodge 20/0 1\nComet 20/0 1\nSpark 20/0 1\nEnergy Retention 1/0 1") + runCallback("OnFrame") + selectSkill(1, 2) + setConfig("dodgeRollsPerSecond", 1) + -- Comet refunds 150 and Spark refunds 35 of the 370 maximum Energy + local metres = 0 + for _, outcome in ipairs({ { 0, 0.65 * 0.65 }, { 35, 0.65 * 0.35 }, { 150, 0.35 * 0.65 }, { 185, 0.35 * 0.35 } }) do + metres = metres + outcome[2] * math.ceil((370 - outcome[1]) / energyPerMetre) + end + assertNear(4 / metres, build.calcsTab.mainOutput.SkillTriggerRate) + end) + + it("supports the item modifiers", function() + local mods, extra = modLib.parseMod("7% chance for Trigger skills to refund half of Energy Spent") + assert.is_nil(extra) + assert.are.equals("EnergyRefundChance", mods[1].name) + assert.are.equals(7, mods[1].value) + assert.are.equals(SkillType.Triggers, mods[1][1].skillType) + + build.configTab.input.customMods = "25% chance for Trigger skills to refund half of Energy Spent" + build.skillsTab:PasteSocketGroup("Cast on Dodge 20/0 1\nSpark 20/0 1") + runCallback("OnFrame") + selectSkill(1, 2) + setConfig("dodgeRollsPerSecond", 1) + local metres = 0.75 * math.ceil(70 / energyPerMetre) + 0.25 * math.ceil(35 / energyPerMetre) + assertNear(4 / metres, build.calcsTab.mainOutput.SkillTriggerRate) + + build.configTab.input.customMods = "Trigger skills refund half of Energy spent" + setConfig("dodgeRollsPerSecond", 1) + assertNear(4 / math.ceil(35 / energyPerMetre), build.calcsTab.mainOutput.SkillTriggerRate) + end) + + it("caps the refund chance at 100%", function() + build.configTab.input.customMods = "Trigger skills refund half of Energy spent" + build.skillsTab:PasteSocketGroup("Cast on Dodge 20/0 1\nSpark 20/0 1\nEnergy Retention 1/0 1") + runCallback("OnFrame") + selectSkill(1, 2) + setConfig("dodgeRollsPerSecond", 1) + assertNear(4 / math.ceil(35 / energyPerMetre), build.calcsTab.mainOutput.SkillTriggerRate) + end) + end) + describe("Cast on Critical", function() local function setupCastOnCritical() build.skillsTab:PasteSocketGroup("Spark 20/0 1") diff --git a/src/Data/ModCache.lua b/src/Data/ModCache.lua index a4a90ea806..6c9a6576c8 100644 --- a/src/Data/ModCache.lua +++ b/src/Data/ModCache.lua @@ -1931,8 +1931,7 @@ c["12 Life Regeneration per second"]={{[1]={flags=0,keywordFlags=0,name="LifeReg c["12 Life Regeneration per second per Socket filled"]={{[1]={[1]={type="Multiplier",var="RunesSocketedIn{SlotName}"},flags=0,keywordFlags=0,name="LifeRegen",type="BASE",value=12}},nil} c["12 to 14 Added Cold Damage per Frenzy Charge"]={{[1]={[1]={type="Multiplier",var="FrenzyCharge"},flags=0,keywordFlags=0,name="ColdMin",type="BASE",value=12},[2]={[1]={type="Multiplier",var="FrenzyCharge"},flags=0,keywordFlags=0,name="ColdMax",type="BASE",value=14}},nil} c["12% chance for Spell Skills to fire 2 additional Projectiles"]={{[1]={flags=2,keywordFlags=0,name="TwoAdditionalProjectilesChance",type="BASE",value=12}},nil} -c["12% chance for Trigger skills to refund half of Energy Spent"]={{}," for Trigger skills to refund half of Energy Spent "} -c["12% chance for Trigger skills to refund half of Energy Spent 8% increased chance to inflict Ailments"]={{[1]={flags=0,keywordFlags=0,name="AilmentChance",type="BASE",value=12}}," for Trigger skills to refund half of Energy Spent 8% increased "} +c["12% chance for Trigger skills to refund half of Energy Spent"]={{[1]={[1]={skillType=32,type="SkillType"},flags=0,keywordFlags=0,name="EnergyRefundChance",type="BASE",value=12}},nil} c["12% chance to Avoid Elemental Ailments per Grand Spectrum"]={{[1]={[1]={type="Multiplier",var="GrandSpectrum"},flags=0,keywordFlags=0,name="AvoidElementalAilments",type="BASE",value=12}},nil} c["12% chance to Blind Enemies on Hit"]={{[1]={flags=0,keywordFlags=0,name="BlindChance",type="BASE",value=12}},nil} c["12% chance when collecting an Elemental Infusion to gain an"]={{}," when collecting an Elemental Infusion to gain an "} @@ -3180,7 +3179,7 @@ c["25% chance for Lightning Damage with Hits to be Lucky"]={{[1]={flags=0,keywor c["25% chance for Projectiles to Pierce Enemies within 3m distance of you"]={{[1]={flags=0,keywordFlags=0,name="ProjectileCount",type="BASE",value=25}}," for to Pierce Enemies within 3m distance of you "} c["25% chance for Skills to retain 40% of Glory on use"]={{}," for Skills to retain 40% of Glory on use "} c["25% chance for Slam Skills you use yourself to cause an additional Aftershock"]={{}," for Slam Skills you use yourself to cause an additional Aftershock "} -c["25% chance for Trigger skills to refund half of Energy Spent"]={{}," for Trigger skills to refund half of Energy Spent "} +c["25% chance for Trigger skills to refund half of Energy Spent"]={{[1]={[1]={skillType=32,type="SkillType"},flags=0,keywordFlags=0,name="EnergyRefundChance",type="BASE",value=25}},nil} c["25% chance on Consuming a Shock on an Enemy to reapply it"]={{}," on Consuming a Shock on an Enemy to reapply it "} c["25% chance on Shocking Enemies to created Shocked Ground"]={{[1]={[1]={actor="enemy",type="ActorCondition",var="OnShockedGround"},flags=0,keywordFlags=0,name="ShockBase",type="BASE",value=20}},nil} c["25% chance that if you would gain Power Charges, you instead gain up to your maximum number of Power Charges"]={{[1]={flags=0,keywordFlags=0,name="FlaskCharges",type="BASE",value=25}}," that if you would gain Power , you instead gain up to your maximum number of Power Charges "} @@ -5001,8 +5000,8 @@ c["75% increased Spell Damage"]={{[1]={flags=2,keywordFlags=0,name="Damage",type c["75% increased Spirit"]={{[1]={flags=0,keywordFlags=0,name="Spirit",type="INC",value=75}},nil} c["75% increased Thorns damage if you've Blocked Recently"]={{[1]={[1]={type="Condition",var="BlockedRecently"},flags=32,keywordFlags=0,name="Damage",type="INC",value=75}},nil} c["75% increased chance to Shock"]={{[1]={flags=0,keywordFlags=0,name="EnemyShockChance",type="INC",value=75}},nil} -end)();(function() c["75% increased effect of Socketed Augment Items"]={{[1]={flags=0,keywordFlags=0,name="SocketedAugmentItemEffect",type="INC",value=75}},nil} +end)();(function() c["75% more Stun Buildup with Lightning Damage"]={{[1]={[1]={type="Condition",var="LightningHasDamage"},flags=0,keywordFlags=0,name="EnemyHeavyStunBuildup",type="MORE",value=75}},nil} c["75% of Damage Converted to Fire Damage"]={{[1]={flags=0,keywordFlags=0,name="DamageConvertToFire",type="BASE",value=75}},nil} c["75% of Volatility Physical Damage Taken as Cold Damage"]={{[1]={flags=0,keywordFlags=0,name="PhysicalDamageTakenAsCold",type="BASE",value=75}}," Volatility "} @@ -5224,7 +5223,7 @@ c["86% more Recovery if used while on Low Mana"]={{[1]={[1]={type="Condition",va c["89% increased Life Recovered"]={{[1]={flags=0,keywordFlags=0,name="FlaskRecovery",type="INC",value=89}},nil} c["89% increased Mana Recovered"]={{[1]={flags=0,keywordFlags=0,name="FlaskRecovery",type="INC",value=89}},nil} c["9 Mana gained when you Block"]={{[1]={flags=0,keywordFlags=0,name="ManaOnBlock",type="BASE",value=9}},nil} -c["9% chance for Trigger skills to refund half of Energy Spent"]={{}," for Trigger skills to refund half of Energy Spent "} +c["9% chance for Trigger skills to refund half of Energy Spent"]={{[1]={[1]={skillType=32,type="SkillType"},flags=0,keywordFlags=0,name="EnergyRefundChance",type="BASE",value=9}},nil} c["9% chance to Freeze"]={{[1]={flags=0,keywordFlags=0,name="EnemyFreezeChance",type="BASE",value=9}},nil} c["9% chance to Shock"]={{[1]={flags=0,keywordFlags=0,name="EnemyShockChance",type="BASE",value=9}},nil} c["9% increased Area of Effect of Curses"]={{[1]={flags=0,keywordFlags=2,name="AreaOfEffect",type="INC",value=9}},nil} @@ -9680,7 +9679,7 @@ c["Trigger Spark Skill on killing a Shocked Enemy"]={nil,"Trigger Spark Skill on c["Trigger a Socketed Bow Skill when you Attack with a Bow, with a 1 second Cooldown"]={nil,"Trigger a Socketed Bow Skill when you Attack with a Bow, with a 1 second Cooldown "} c["Trigger a Socketed Bow Skill when you Cast a Spell while wielding a Bow, with a 1 second Cooldown"]={nil,"Trigger a Socketed Bow Skill when you Cast a Spell while wielding a Bow, with a 1 second Cooldown "} c["Trigger a Socketed Cold Spell on Melee Critical Hit, with a 0.25 second Cooldown"]={{[1]={[1]={slotName="{SlotName}",type="SocketedIn"},flags=0,keywordFlags=0,name="ExtraSupport",type="LIST",value={level=1,skillId="SupportUniqueCosprisMaliceColdSpellsCastOnMeleeCriticalStrike"}}},nil} -c["Trigger skills refund half of Energy spent"]={nil,"Trigger skills refund half of Energy spent "} +c["Trigger skills refund half of Energy spent"]={{[1]={[1]={skillType=32,type="SkillType"},flags=0,keywordFlags=0,name="EnergyRefundChance",type="BASE",value=100}},nil} c["Triggered Spells deal 14% increased Spell Damage"]={{[1]={[1]={skillType=37,type="SkillType"},flags=2,keywordFlags=131072,name="Damage",type="INC",value=14}},nil} c["Triggered Spells deal 16% increased Spell Damage"]={{[1]={[1]={skillType=37,type="SkillType"},flags=2,keywordFlags=131072,name="Damage",type="INC",value=16}},nil} c["Triggered Spells deal 33% increased Spell Damage"]={{[1]={[1]={skillType=37,type="SkillType"},flags=2,keywordFlags=131072,name="Damage",type="INC",value=33}},nil} @@ -10003,8 +10002,8 @@ c["additional Rune-only sockets:"]={{},nil} c["as being boosted by Chilled Ground"]={nil,"as being boosted by Chilled Ground "} c["as being boosted by Ignited Ground"]={nil,"as being boosted by Ignited Ground "} c["as being boosted by Ignited, Shocked, and Chilled Ground"]={nil,"as being boosted by Ignited, Shocked, and Chilled Ground "} -end)();(function() c["as being boosted by Shocked Ground"]={nil,"as being boosted by Shocked Ground "} +end)();(function() c["being Shapeshifted for at least 8 seconds"]={nil,"being Shapeshifted for at least 8 seconds "} c["for 4 seconds, every 0.25 seconds while raised"]={nil,"for 4 seconds, every 0.25 seconds while raised "} c["gain 6 Cold Surges or 6 Fire Surges"]={{}," Cold Surges or 6 Fire Surges "} diff --git a/src/Data/SkillStatMap.lua b/src/Data/SkillStatMap.lua index f60c626621..1787eea1fd 100644 --- a/src/Data/SkillStatMap.lua +++ b/src/Data/SkillStatMap.lua @@ -208,6 +208,9 @@ return function(mod, flag, skill) ["generic_ongoing_trigger_1_maximum_energy_per_Xms_total_cast_time"] = { skill("energyPerCastTimeMs", nil), }, +["trigger_skills_refund_half_energy_spent_chance_%"] = { + mod("EnergyRefundChance", "BASE", nil), +}, ["trigger_meta_gem_damage_+%_final"] = { mod("Damage", "MORE", nil), }, diff --git a/src/Modules/CalcTriggers.lua b/src/Modules/CalcTriggers.lua index cc4e7e8dff..8fdf18c787 100644 --- a/src/Modules/CalcTriggers.lua +++ b/src/Modules/CalcTriggers.lua @@ -279,8 +279,28 @@ local function metaGemTriggerHandler(env, actor, metaSkill, config) assumeSelfCast(skill, s_format("%s gains no Energy from %ss", triggerName, config.eventName)) return end + -- Each triggered skill separately rolls to refund half of its Energy cost + local refundChance = m_min(metaSkill.skillModList:Sum("BASE", metaSkill.skillCfg, "EnergyRefundChance"), 100) / 100 + local refunds = { [0] = 1 } + if refundChance > 0 then + -- calculate all possible combinations of refunds and odds for them + for _, triggeredSkill in ipairs(triggeredSkills) do + local refund = calcSocketedSkillEnergy(triggeredSkill) / 2 + local nextRefunds = {} + for amount, chance in pairs(refunds) do + -- add back cases where this skill does not get refunded + nextRefunds[amount] = (nextRefunds[amount] or 0) + chance * (1 - refundChance) + -- and where it does get refunded + nextRefunds[amount + refund] = (nextRefunds[amount + refund] or 0) + chance * refundChance + end + refunds = nextRefunds + end + end -- Excess Energy is discarded when the meta gem triggers, so each trigger takes a whole number of events - local events = m_ceil(maxEnergy / energyPerEvent - 1e-9) + local events = 0 + for refund, chance in pairs(refunds) do + events += chance * m_ceil((maxEnergy - refund) / energyPerEvent - 1e-9) + end output.EnergyPerSecond = energyPerEvent * eventRate output.MaxEnergy = maxEnergy @@ -329,9 +349,13 @@ local function metaGemTriggerHandler(env, actor, metaSkill, config) breakdown.SkillTriggerRate = { s_format("%.2f ^8(%ss per second)", eventRate, config.eventName), - s_format("/ %d ^8(%ss to reach %.0f maximum Energy)", events, config.eventName, maxEnergy), - s_format("= %.2f ^8per second", eventRate / events), } + if refundChance > 0 then + t_insert(breakdown.SkillTriggerRate, s_format("/ %.2f ^8(average %ss to reach %.0f maximum Energy, %d%% chance per skill to refund half its cost)", events, config.eventName, maxEnergy, refundChance * 100)) + else + t_insert(breakdown.SkillTriggerRate, s_format("/ %d ^8(%ss to reach %.0f maximum Energy)", events, config.eventName, maxEnergy)) + end + t_insert(breakdown.SkillTriggerRate, s_format("= %.2f ^8per second", eventRate / events)) if output.SkillTriggerRate < eventRate / events then t_insert(breakdown.SkillTriggerRate, s_format("capped at %.2f ^8(trigger rate cap)", triggerRateCap)) end diff --git a/src/Modules/ModParser.lua b/src/Modules/ModParser.lua index 5040c9cc62..ebc7ebd558 100644 --- a/src/Modules/ModParser.lua +++ b/src/Modules/ModParser.lua @@ -3574,6 +3574,8 @@ local specialModList = { ["meta skills gain (%d+)%% more energy"] = function(num) return { mod("EnergyGenerated", "MORE", num, { type = "SkillType", skillType = SkillType.Meta }) } end, ["meta skills gain (%d+)%% increased energy if you've dealt a critical hit recently"] = function(num) return { mod("EnergyGenerated", "INC", num, { type = "SkillType", skillType = SkillType.Meta }, { type = "Condition", var = "CritRecently" }) } end, ["meta skills gain (%d+)%% increased energy while on full mana"] = function(num) return { mod("EnergyGenerated", "INC", num, { type = "SkillType", skillType = SkillType.Meta }, { type = "Condition", var = "FullMana" }) } end, + ["(%d+)%% chance for trigger skills to refund half of energy spent"] = function(num) return { mod("EnergyRefundChance", "BASE", num, { type = "SkillType", skillType = SkillType.Triggers }) } end, + ["trigger skills refund half of energy spent"] = { mod("EnergyRefundChance", "BASE", 100, { type = "SkillType", skillType = SkillType.Triggers }) }, -- Global gem modifiers ["gems socketed in red sockets have [%+%-](%d+) to level"] = function(num) return { mod("GemProperty", "LIST", { keyword = "all", key = "level", value = num, keyOfScaledMod = "value" }, { type = "SocketedIn", slotName = "{SlotName}", socketColor = "R" }) } end, ["gems socketed in green sockets have [%+%-](%d+)%% to quality"] = function(num) return { mod("GemProperty", "LIST", { keyword = "all", key = "quality", value = num, keyOfScaledMod = "value" }, { type = "SocketedIn", slotName = "{SlotName}", socketColor = "G" }) } end,