Tested and fixed class level computations
This commit is contained in:
@@ -2,7 +2,7 @@ const linkDependenciesByType = {
|
|||||||
action: linkResources,
|
action: linkResources,
|
||||||
attack: linkResources,
|
attack: linkResources,
|
||||||
attribute: linkAttribute,
|
attribute: linkAttribute,
|
||||||
characterClass: linkVariableName,
|
class: linkVariableName,
|
||||||
classLevel: linkClassLevel,
|
classLevel: linkClassLevel,
|
||||||
constant: linkVariableName,
|
constant: linkVariableName,
|
||||||
damageMultiplier: linkDamageMultiplier,
|
damageMultiplier: linkDamageMultiplier,
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ function computeVariableProp(node, prop, scope){
|
|||||||
computeVariableAsSkill(node, prop, scope)
|
computeVariableAsSkill(node, prop, scope)
|
||||||
} else if (prop.type === 'constant'){
|
} else if (prop.type === 'constant'){
|
||||||
computeVariableAsConstant(node, prop, scope)
|
computeVariableAsConstant(node, prop, scope)
|
||||||
} else if (prop.type === 'characterClass'){
|
} else if (prop.type === 'class'){
|
||||||
computeVariableAsClass(node, prop, scope)
|
computeVariableAsClass(node, prop, scope)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ export default function aggregateClassLevel({node, linkedNode, link}){
|
|||||||
if (linkedProp.level > aggregator.level) aggregator.level = linkedProp.level;
|
if (linkedProp.level > aggregator.level) aggregator.level = linkedProp.level;
|
||||||
aggregator.levelsFilled[linkedProp.level] = true;
|
aggregator.levelsFilled[linkedProp.level] = true;
|
||||||
} else if (link.data === 'level'){
|
} else if (link.data === 'level'){
|
||||||
node.baseValue = (node.baseValue || 0) + node.data.classLevelAggregator.level;
|
node.data.baseValue = (node.data.baseValue || 0) +
|
||||||
|
linkedNode.data.classLevelAggregator.level;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,12 @@ export default function computeVariableAsAttribute(node, prop){
|
|||||||
let classLevelAgg = node.data.classLevelAggregator;
|
let classLevelAgg = node.data.classLevelAggregator;
|
||||||
if (!classLevelAgg) return;
|
if (!classLevelAgg) return;
|
||||||
prop.level = classLevelAgg.level;
|
prop.level = classLevelAgg.level;
|
||||||
classLevelAgg.levelsFilled.forEach((filled, index) => {
|
for (let index = 1; index < classLevelAgg.level; index++ ){
|
||||||
|
const filled = classLevelAgg.levelsFilled[index];
|
||||||
if (!filled){
|
if (!filled){
|
||||||
if (!prop.missingLevels) prop.missingLevels = [];
|
if (!prop.missingLevels) prop.missingLevels = [];
|
||||||
prop.missingLevels.push(index);
|
prop.missingLevels.push(index);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
prop.missingLevels?.sort((a, b) => a - b);
|
prop.missingLevels?.sort((a, b) => a - b);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
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 scope = id => computation.scope[id];
|
||||||
|
const prop = id => computation.propsById[id];
|
||||||
|
assert.equal(scope('level').value, 5);
|
||||||
|
assert.equal(scope('wizard').level, 4);
|
||||||
|
assert.equal(prop('wizzardId').level, 4);
|
||||||
|
assert.deepEqual(prop('wizzardId').missingLevels, [3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
var testProperties = [
|
||||||
|
clean({
|
||||||
|
_id: 'wizzardId',
|
||||||
|
type: 'class',
|
||||||
|
variableName: 'wizard',
|
||||||
|
classType: 'startingClass',
|
||||||
|
ancestors: [{id: 'charId'}],
|
||||||
|
}),
|
||||||
|
clean({
|
||||||
|
_id: 'rangerId',
|
||||||
|
type: 'class',
|
||||||
|
variableName: 'ranger',
|
||||||
|
classType: 'multiClass',
|
||||||
|
ancestors: [{id: 'charId'}],
|
||||||
|
}),
|
||||||
|
clean({
|
||||||
|
_id: 'wiz1Id',
|
||||||
|
type: 'classLevel',
|
||||||
|
variableName: 'wizard',
|
||||||
|
level: 1,
|
||||||
|
ancestors: [{id: 'charId'}],
|
||||||
|
}),
|
||||||
|
clean({
|
||||||
|
_id: 'wiz2Id',
|
||||||
|
type: 'classLevel',
|
||||||
|
variableName: 'wizard',
|
||||||
|
level: 2,
|
||||||
|
ancestors: [{id: 'charId'}],
|
||||||
|
}),
|
||||||
|
clean({
|
||||||
|
_id: 'wiz4Id',
|
||||||
|
type: 'classLevel',
|
||||||
|
variableName: 'wizard',
|
||||||
|
level: 4,
|
||||||
|
ancestors: [{id: 'charId'}],
|
||||||
|
}),
|
||||||
|
clean({
|
||||||
|
_id: 'rang1Id',
|
||||||
|
type: 'classLevel',
|
||||||
|
variableName: 'ranger',
|
||||||
|
level: 1,
|
||||||
|
ancestors: [{id: 'charId'}],
|
||||||
|
}),
|
||||||
|
];
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import computeAction from './computeAction.testFn.js';
|
import computeAction from './computeAction.testFn.js';
|
||||||
import computeAttribute from './computeAttribute.testFn.js';
|
import computeAttribute from './computeAttribute.testFn.js';
|
||||||
|
import computeClasses from './computeClasses.testFn.js';
|
||||||
|
|
||||||
export default [{
|
export default [{
|
||||||
text: 'Computes actions',
|
text: 'Computes actions',
|
||||||
@@ -7,4 +8,7 @@ export default [{
|
|||||||
},{
|
},{
|
||||||
text: 'Computes attributes',
|
text: 'Computes attributes',
|
||||||
fn: computeAttribute,
|
fn: computeAttribute,
|
||||||
},]
|
},{
|
||||||
|
text: 'Computes classes',
|
||||||
|
fn: computeClasses,
|
||||||
|
}];
|
||||||
|
|||||||
@@ -42,5 +42,7 @@ function compute(graph, node, scope){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function pushDependenciesToStack(nodeId, graph, stack){
|
function pushDependenciesToStack(nodeId, graph, stack){
|
||||||
graph.forEachLinkedNode(nodeId, linkedNode => stack.push(linkedNode), true);
|
graph.forEachLinkedNode(nodeId, linkedNode => {
|
||||||
|
stack.push(linkedNode);
|
||||||
|
}, true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ const propertySchemasIndex = {
|
|||||||
attack: ComputedOnlyAttackSchema,
|
attack: ComputedOnlyAttackSchema,
|
||||||
attribute: ComputedOnlyAttributeSchema,
|
attribute: ComputedOnlyAttributeSchema,
|
||||||
buff: ComputedOnlyBuffSchema,
|
buff: ComputedOnlyBuffSchema,
|
||||||
characterClass: ComputedOnlyClassSchema,
|
class: ComputedOnlyClassSchema,
|
||||||
classLevel: ComputedOnlyClassLevelSchema,
|
classLevel: ComputedOnlyClassLevelSchema,
|
||||||
constant: ComputedOnlyConstantSchema,
|
constant: ComputedOnlyConstantSchema,
|
||||||
container: ComputedOnlyContainerSchema,
|
container: ComputedOnlyContainerSchema,
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ const propertySchemasIndex = {
|
|||||||
attack: ComputedAttackSchema,
|
attack: ComputedAttackSchema,
|
||||||
attribute: ComputedAttributeSchema,
|
attribute: ComputedAttributeSchema,
|
||||||
buff: ComputedBuffSchema,
|
buff: ComputedBuffSchema,
|
||||||
characterClass: ComputedClassSchema,
|
class: ComputedClassSchema,
|
||||||
classLevel: ClassLevelSchema,
|
classLevel: ClassLevelSchema,
|
||||||
constant: ConstantSchema,
|
constant: ConstantSchema,
|
||||||
damage: ComputedDamageSchema,
|
damage: ComputedDamageSchema,
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ const propertySchemasIndex = {
|
|||||||
attack: AttackSchema,
|
attack: AttackSchema,
|
||||||
attribute: AttributeSchema,
|
attribute: AttributeSchema,
|
||||||
buff: BuffSchema,
|
buff: BuffSchema,
|
||||||
characterClass: ClassSchema,
|
class: ClassSchema,
|
||||||
classLevel: ClassLevelSchema,
|
classLevel: ClassLevelSchema,
|
||||||
constant: ConstantSchema,
|
constant: ConstantSchema,
|
||||||
damage: DamageSchema,
|
damage: DamageSchema,
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ const PROPERTIES = Object.freeze({
|
|||||||
helpText: 'When a buff is activated as a child of an action, it will copy the properties under itself onto a target character.',
|
helpText: 'When a buff is activated as a child of an action, it will copy the properties under itself onto a target character.',
|
||||||
suggestedParents: ['action', 'attack', 'savingThrow', 'spell'],
|
suggestedParents: ['action', 'attack', 'savingThrow', 'spell'],
|
||||||
},
|
},
|
||||||
characterClass: {
|
class: {
|
||||||
icon: 'mdi-card-account-details',
|
icon: 'mdi-card-account-details',
|
||||||
name: 'Class',
|
name: 'Class',
|
||||||
helpText: 'Your character should ideally have one starting class. Classes hold class levels',
|
helpText: 'Your character should ideally have one starting class. Classes hold class levels',
|
||||||
|
|||||||
Reference in New Issue
Block a user