Tested and fixed proficiencies by tag

This commit is contained in:
Stefan Zermatten
2023-05-06 10:45:03 +02:00
parent 9fb85b8c50
commit 4550661a59
5 changed files with 80 additions and 10 deletions

View File

@@ -272,6 +272,9 @@ function linkProficiencies(dependencyGraph, prop, computation) {
// The stats depend on the proficiency
if (prop.inactive) return;
if (prop.targetByTags) {
// Tag targeted proficiencies depend on the creature's proficiencyBonus,
// since they add it directly to the targeted field
dependencyGraph.addLink(prop._id, 'proficiencyBonus', 'skillProficiencyBonus');
getEffectTagTargets(prop, computation).forEach(targetId => {
const targetProp = computation.propsById[targetId];
if (

View File

@@ -61,8 +61,7 @@ function aggregateCalculationProficiencies(node, computation) {
if (!linkedNode.data) return;
// Ignore inactive props
if (linkedNode.data.inactive) return;
// Collate effects
// Collate proficiencies
calcObj.proficiencies = calcObj.proficiencies || [];
calcObj.proficiencies.push({
_id: linkedNode.data._id,

View File

@@ -0,0 +1,64 @@
import { buildComputationFromProps } from '/imports/api/engine/computation/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('strengthId').value, 8,
'The proficiency bonus should not change the strength score'
);
assert.equal(
prop('strengthId').modifier, -1,
'The proficiency bonus should not change the strength modifier'
);
assert.exists(prop('actionId').attackRoll.proficiencies, 'The proficiency aggregator should be here')
assert.exists(prop('actionId').attackRoll.proficiencies[0], 'The proficiency should be here')
// attack roll = strength.mod + proficiencyBonus/2 rounded down
// = -1 + 13/2 = -1 + 6 = 5
assert.equal(
prop('actionId').attackRoll.value, 5,
'The proficiency should apply correctly to modify the attack roll'
);
}
var testProperties = [
clean({
_id: 'strengthId',
variableName: 'strength',
type: 'attribute',
attributeType: 'ability',
baseValue: {
calculation: '8'
},
}),
clean({
_id: 'actionId',
type: 'action',
ancestors: [{ id: 'charId' }],
attackRoll: {
calculation: 'strength.modifier',
},
tags: ['rapier', 'martial weapon', 'weapon', 'attack']
}),
clean({
_id: 'profBonusId',
type: 'attribute',
variableName: 'proficiencyBonus',
ancestors: [{ id: 'charId' }],
baseValue: {
calculation: '13'
},
}),
clean({
_id: 'tagTargetedProficiency',
type: 'proficiency',
stats: ['strength'], // Should be ignored, we are targeting by tags
value: 0.49,
targetByTags: true,
targetTags: ['martial weapon']
}),
];

View File

@@ -6,29 +6,33 @@ import computeInventory from './computeInventory.testFn.js';
import computeDamageMultipliers from './computeDamageMultipliers.testFn.js';
import computeEffects from './computeEffects.testFn.js';
import computeSkills from './computeSkills.testFn.js';
import computeProficiencies from './computeProficiencies.testFn.js';
export default [{
text: 'Computes actions',
fn: computeAction,
},{
}, {
text: 'Computes attributes',
fn: computeAttribute,
},{
}, {
text: 'Computes classes',
fn: computeClasses,
},{
}, {
text: 'Computes constants',
fn: computeConstants,
},{
}, {
text: 'Computes inventory',
fn: computeInventory,
},{
}, {
text: 'Computes damage multipliers',
fn: computeDamageMultipliers,
},{
}, {
text: 'Computes effects',
fn: computeEffects,
},{
}, {
text: 'Computes skills',
fn: computeSkills,
}, {
text: 'Computes proficiencies',
fn: computeProficiencies,
}];

View File

@@ -35,7 +35,7 @@ let ProficiencySchema = new SimpleSchema({
optional: true,
max: STORAGE_LIMITS.variableName,
},
// Which tags the effect is applied to
// Which tags the proficiency is applied to
targetTags: {
type: Array,
optional: true,