Fixed checks not applying rolled effects

This commit is contained in:
ThaumRystra
2023-11-12 21:11:04 +02:00
parent 2e3e6e22b6
commit 800ef3328c
9 changed files with 52 additions and 10 deletions

View File

@@ -10,7 +10,7 @@ import resolve from '/imports/parser/resolve.js';
// Redo the work of imports/api/engine/computation/computeComputation/computeByType/computeCalculation.js
// But in the action scope
export default function recalculateCalculation(calcObj, actionContext, context, parseLevel = 'reduce') {
export default function recalculateCalculation(calcObj, actionContext, parseLevel = 'reduce', context) {
if (!calcObj?.parseNode) return;
calcObj._parseLevel = parseLevel;
// Re-resolve the parse node
@@ -40,7 +40,7 @@ export default function recalculateCalculation(calcObj, actionContext, context,
export function rollAndReduceCalculation(calcObj, actionContext, context) {
// Compile
recalculateCalculation(calcObj, actionContext, context, 'compile');
recalculateCalculation(calcObj, actionContext, 'compile', context);
const compiled = calcObj.valueNode;
const compileErrors = context.errors;

View File

@@ -8,6 +8,7 @@ import numberToSignedString from '/imports/api/utility/numberToSignedString.js';
import { applyTriggers } from '/imports/api/engine/actions/applyTriggers.js';
import ActionContext from '/imports/api/engine/actions/ActionContext.js';
import recalculateCalculation from '/imports/api/engine/actions/applyPropertyByType/shared/recalculateCalculation';
import { getSingleProperty } from '/imports/api/engine/loadCreatures';
const doCheck = new ValidatedMethod({
name: 'creatureProperties.doCheck',
@@ -120,13 +121,14 @@ function rollCheck(prop, actionContext) {
export function applyUnresolvedEffects(prop, actionContext) {
let effectBonus = 0;
let effectString = '';
if (!prop.effects) {
if (!prop.effectIds) {
return { effectBonus, effectString };
}
prop.effects.forEach(effect => {
prop.effectIds.forEach(id => {
const effect = getSingleProperty(actionContext.creature._id, id);
if (!effect.amount?.parseNode) return;
if (effect.operation !== 'add') return;
recalculateCalculation(effect.amount, actionContext, context, 'reduce');
recalculateCalculation(effect.amount, actionContext, undefined, 'reduce');
if (typeof effect.amount?.value !== 'number') return;
effectBonus += effect.amount.value;
effectString += ` ${effect.amount.value < 0 ? '-' : '+'} [${effect.amount.calculation}] ${Math.abs(effect.amount.value)}`

View File

@@ -272,6 +272,7 @@ function linkPointBuy(dependencyGraph, prop) {
type: 'pointBuyRow',
tableName: prop.name,
tableId: prop._id,
rowIndex: index,
}
dependencyGraph.addNode(pointBuyRow._id, pointBuyRow);
linkVariableName(dependencyGraph, pointBuyRow);

View File

@@ -32,10 +32,10 @@ export default function computeCalculation(computation, node) {
delete calcObj._localScope;
}
export function resolveCalculationNode(calculation, parseNode, scope) {
export function resolveCalculationNode(calculation, parseNode, scope, givenContext) {
const fn = calculation._parseLevel;
const calculationScope = { ...calculation._localScope, ...scope };
const { result: resultNode, context } = resolve(fn, parseNode, calculationScope);
const { result: resultNode, context } = resolve(fn, parseNode, calculationScope, givenContext);
calculation.errors = context.errors;
calculation.valueNode = resultNode;
}

View File

@@ -32,11 +32,12 @@ export default function aggregateDefinition({ node, linkedNode, link }) {
if (propBaseValue === undefined) return;
// Store a summary of the definition as a base value effect
node.data.effectIds = node.data.effectIds || [];
node.data.definitions = node.data.definitions || [];
if (prop.type === 'pointBuyRow') {
node.data.effectIds.push(prop.tableId);
node.data.definitions.push({ _id: prop.tableId, type: 'pointBuy', row: prop.index });
} else {
node.data.effectIds.push(prop._id);
node.data.definitions.push({ _id: prop._id, type: node.data.type });
}
if (node.data.baseValue === undefined || propBaseValue > node.data.baseValue) {
node.data.baseValue = propBaseValue;

View File

@@ -50,5 +50,6 @@ export default function computeVariableAsAttribute(computation, node, prop) {
// Store effects and proficiencies
prop.effectIds = node.data.effectIds;
prop.definitions = node.data.definitions;
prop.proficiencyIds = node.data.proficiencyIds;
}

View File

@@ -35,6 +35,7 @@ export default function computeVariableAsSkill(computation, node, prop) {
// Store effects and proficiencies
prop.effectIds = node.data.effectIds;
prop.definitions = node.data.definitions;
prop.proficiencyIds = node.data.proficiencyIds;
// If there is no aggregator, determine if the prop can hide, then exit

View File

@@ -215,6 +215,24 @@ let ComputedOnlyAttributeSchema = createPropertySchema({
'proficiencyIds.$': {
type: String,
},
'definitions': {
type: Array,
optional: true,
removeBeforeCompute: true,
},
'definitions.$': {
type: Object,
},
'definitions.$._id': {
type: String,
},
'definitions.$.type': {
type: String,
},
'definitions.$.row': {
type: Number,
optional: true,
},
});
const ComputedAttributeSchema = new SimpleSchema()

View File

@@ -150,6 +150,24 @@ let ComputedOnlySkillSchema = createPropertySchema({
'proficiencyIds.$': {
type: String,
},
'definitions': {
type: Array,
optional: true,
removeBeforeCompute: true,
},
'definitions.$': {
type: Object,
},
'definitions.$._id': {
type: String,
},
'definitions.$.type': {
type: String,
},
'definitions.$.row': {
type: Number,
optional: true,
},
})
const ComputedSkillSchema = new SimpleSchema()