From 2cb14146d48af2d572b082fd7f5eae0d832d2776 Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Thu, 23 Sep 2021 15:44:50 +0200 Subject: [PATCH] Tested and fixed skill compuations --- .../computeVariable/computeVariableAsSkill.js | 2 +- .../tests/computeSkills.testFn.js | 84 +++++++++++++++++++ .../computeComputation/tests/index.js | 4 + app/imports/api/properties/Attributes.js | 2 +- 4 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 app/imports/api/creature/computation/newEngine/computeComputation/tests/computeSkills.testFn.js 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 88251218..da0ed54b 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 @@ -37,7 +37,7 @@ export default function computeVariableAsSkill(computation, node, prop){ prop.hide = statBase === undefined && prop.proficiency == 0 || undefined; - prop.value = statBase; + prop.value = (statBase || 0) + prop.abilityMod + profBonus; return; } // Combine aggregator diff --git a/app/imports/api/creature/computation/newEngine/computeComputation/tests/computeSkills.testFn.js b/app/imports/api/creature/computation/newEngine/computeComputation/tests/computeSkills.testFn.js new file mode 100644 index 00000000..fa6c86a8 --- /dev/null +++ b/app/imports/api/creature/computation/newEngine/computeComputation/tests/computeSkills.testFn.js @@ -0,0 +1,84 @@ +import { buildComputationFromProps } from '/imports/api/creature/computation/newEngine/buildCreatureComputation.js'; +import { assert } from 'chai'; +import computeCreatureComputation from '../../computeCreatureComputation.js'; +import clean from '../../utility/cleanProp.testFn.js'; + +export default function(){ + const computation = buildComputationFromProps(testProperties); + computeCreatureComputation(computation); + const prop = id => computation.propsById[id]; + + assert.equal(prop('atheleticsId').proficiency, 2, 'Inherits proficiency from ability'); + assert.equal(prop('atheleticsId').value, 7, 'calculates value correctly'); + assert.equal(prop('atheleticsId').advantage, 1, 'Inherits advantage from ability'); + assert.equal(prop('strengthSaveId').advantage, undefined, 'Saves don\'t inherit effects'); + assert.equal(prop('strengthSaveId').value, 4, 'Saves calculate correctly'); + + assert.equal(prop('acrobaticsId').value, 1); + assert.equal(prop('toolsId').value, 7); +} + +var testProperties = [ + clean({ + _id: 'strengthId', + variableName: 'strength', + type: 'attribute', + attributeType: 'ability', + baseValue: { + calculation: '12' + }, + }), + clean({ + _id: 'profBonusId', + variableName: 'proficiencyBonus', + type: 'attribute', + attributeType: 'modifier', + baseValue: { + calculation: '3' + }, + }), + clean({ + _id: 'atheleticsId', + variableName: 'athletics', + type: 'skill', + skillType: 'skill', + ability: 'strength', + }), + clean({ + _id: 'acrobaticsId', + variableName: 'acrobatics', + type: 'skill', + skillType: 'skill', + baseProficiency: 0.49, + }), + clean({ + _id: 'toolsId', + variableName: 'tools', + type: 'skill', + skillType: 'tool', + baseProficiency: 0.5, + baseValue: { + calculation: '5', + } + }), + clean({ + _id: 'strengthAdvantageId', + type: 'effect', + operation: 'advantage', + stats: ['strength'], + }), + clean({ + _id: 'strengthProficiencyId', + type: 'proficiency', + value: 2, + stats: ['strength'], + }), + clean({ + _id: 'strengthSaveId', + variableName: 'strengthSave', + type: 'skill', + skillType: 'save', + ability: 'strength', + baseProficiency: 1, + }), +]; diff --git a/app/imports/api/creature/computation/newEngine/computeComputation/tests/index.js b/app/imports/api/creature/computation/newEngine/computeComputation/tests/index.js index 26920321..b9c8baf7 100644 --- a/app/imports/api/creature/computation/newEngine/computeComputation/tests/index.js +++ b/app/imports/api/creature/computation/newEngine/computeComputation/tests/index.js @@ -5,6 +5,7 @@ import computeConstants from './computeConstants.testFn.js'; import computeInventory from './computeInventory.testFn.js'; import computeDamageMultipliers from './computeDamageMultipliers.testFn.js'; import computeEffects from './computeEffects.testFn.js'; +import computeSkills from './computeSkills.testFn.js'; export default [{ text: 'Computes actions', @@ -27,4 +28,7 @@ export default [{ },{ text: 'Computes effects', fn: computeEffects, +},{ + text: 'Computes skills', + fn: computeSkills, }]; diff --git a/app/imports/api/properties/Attributes.js b/app/imports/api/properties/Attributes.js index b55194f4..df50be09 100644 --- a/app/imports/api/properties/Attributes.js +++ b/app/imports/api/properties/Attributes.js @@ -26,7 +26,7 @@ let AttributeSchema = createPropertySchema({ allowedValues: [ 'ability', //Strength, Dex, Con, etc. 'stat', // Speed, Armor Class - 'modifier', // Proficiency Bonus, Initiative + 'modifier', // Proficiency Bonus, displayed as +x 'hitDice', // d12 hit dice 'healthBar', // Hitpoints, Temporary Hitpoints, can take damage 'bar', // Displayed as a health bar, can't take damage