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)}`