From 8ea04fc78698b2b0db401be5a47da816639f8bd9 Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Thu, 23 Sep 2021 15:22:28 +0200 Subject: [PATCH] Implemented effect and proficiency inheritance from abilities to skills --- .../computeVariable/computeVariableAsSkill.js | 43 +++++++++++++++++-- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/app/imports/api/creature/computation/newEngine/computeComputation/computeByType/computeVariable/computeVariableAsSkill.js b/app/imports/api/creature/computation/newEngine/computeComputation/computeByType/computeVariable/computeVariableAsSkill.js index e9ae5ae1..88251218 100644 --- a/app/imports/api/creature/computation/newEngine/computeComputation/computeByType/computeVariable/computeVariableAsSkill.js +++ b/app/imports/api/creature/computation/newEngine/computeComputation/computeByType/computeVariable/computeVariableAsSkill.js @@ -1,14 +1,24 @@ -export default function computeVariableAsSkill(node, prop, scope){ +import aggregate from './aggregate/index.js'; + +export default function computeVariableAsSkill(computation, node, prop){ // Skills are based on some ability Modifier - let ability = scope[prop.ability]; + let ability = computation.scope[prop.ability]; prop.abilityMod = ability?.modifier || 0; - // TODO: Use this ability's skill effects/profs iff this skill is not a save + + // Inherit the ability's skill effects and proficiencies if skill is not a save + if (prop.skillType !== 'save' && ability){ + aggregateAbilityEffects({ + computation, + skillNode: node, + abilityNode: computation.dependencyGraph.getNode(prop.ability) + }); + } // Proficiency prop.proficiency = node.data.proficiency; // Get the character's proficiency bonus to apply - let profBonus = scope['proficiencyBonus']?.value || 0; + let profBonus = computation.scope['proficiencyBonus']?.value || 0; // Multiply the proficiency bonus by the actual proficiency if(prop.proficiency === 0.49){ @@ -61,3 +71,28 @@ export default function computeVariableAsSkill(node, prop, scope){ // Rollbonus prop.rollBonuses = aggregator.rollBonus; } + +function aggregateAbilityEffects({computation, skillNode, abilityNode}){ + computation.dependencyGraph.forEachLinkedNode( + abilityNode.id, + (linkedNode, link) => { + if (!linkedNode.data) linkedNode.data = {}; + // Ignore inactive props + if (linkedNode.data.inactive) return; + // Check that the link is a valid effect/proficiency to pass on + // to a skill from its ability + if (link.data === 'effect'){ + if (![ + 'advantage', 'disadvantage', 'passiveAdd', 'fail' + ].includes(linkedNode.data.operation)){ + return; + } + } + // Apply the aggregations + let arg = {node: skillNode, linkedNode, link}; + aggregate.effect(arg); + aggregate.proficiency(arg); + }, + true // enumerate only outbound links + ); +}