Fixed #382 dice roll functions not working
This commit is contained in:
@@ -80,7 +80,7 @@ async function logBuff(prop, targetIds, action, userInput, result) {
|
||||
//Log the buff
|
||||
let logValue = prop.description?.value
|
||||
if (prop.description?.text) {
|
||||
recalculateInlineCalculations(prop.description, action, 'reduce', userInput);
|
||||
await recalculateInlineCalculations(prop.description, action, 'reduce', userInput);
|
||||
logValue = prop.description?.value;
|
||||
}
|
||||
result.appendLog({
|
||||
|
||||
@@ -10,7 +10,7 @@ export default async function applyCreatureTemplateProperty(
|
||||
//Log the Creature that is about to be summoned
|
||||
let logValue = prop.description?.value
|
||||
if (prop.description?.text) {
|
||||
recalculateInlineCalculations(prop.description, action, 'reduce', userInput);
|
||||
await recalculateInlineCalculations(prop.description, action, 'reduce', userInput);
|
||||
logValue = prop.description?.value;
|
||||
}
|
||||
// There are no targets for creature templates
|
||||
|
||||
@@ -8,13 +8,10 @@ import { getSingleProperty } from '/imports/api/engine/loadCreatures';
|
||||
import resolve from '/imports/parser/resolve';
|
||||
import { getEffectiveActionScope } from '/imports/api/engine/action/functions/getEffectiveActionScope';
|
||||
import { CalculatedField } from '/imports/api/properties/subSchemas/computedField';
|
||||
import { ResolveLevel } from '/imports/parser/parseTree/NodeFactory';
|
||||
import InputProvider from '/imports/api/engine/action/functions/userInput/InputProvider';
|
||||
import { EngineAction } from '/imports/api/engine/action/EngineActions';
|
||||
import ResolveLevel from '/imports/parser/types/ResolveLevel';
|
||||
|
||||
// TODO Redo the work of
|
||||
// imports/api/engine/computation/computeComputation/computeByType/computeCalculation.js
|
||||
// But in the action scope
|
||||
export default async function recalculateCalculation(
|
||||
calcObj: CalculatedField,
|
||||
action,
|
||||
@@ -27,7 +24,7 @@ export default async function recalculateCalculation(
|
||||
const {
|
||||
result: unaffectedResult,
|
||||
context
|
||||
} = await resolve(parseLevel, calcObj.parseNode, scope);
|
||||
} = await resolve(parseLevel, calcObj.parseNode, scope, undefined, userInput);
|
||||
calcObj.valueNode = unaffectedResult;
|
||||
|
||||
// store the unaffected value
|
||||
@@ -48,7 +45,7 @@ export default async function recalculateCalculation(
|
||||
// Resolve the modified valueNode, use the same context
|
||||
const {
|
||||
result: finalResult
|
||||
} = await resolve(parseLevel, calcObj.valueNode, scope, context);
|
||||
} = await resolve(parseLevel, calcObj.valueNode, scope, context, userInput);
|
||||
|
||||
// Store the errors
|
||||
calcObj.errors = context.errors;
|
||||
|
||||
@@ -13,7 +13,7 @@ export default async function recalculateInlineCalculations(
|
||||
if (!inlineCalcObj?.inlineCalculations?.length) return;
|
||||
// Recalculate each calculation with the current scope
|
||||
for (const calc of inlineCalcObj.inlineCalculations) {
|
||||
await recalculateCalculation(calc, action, undefined, userInput);
|
||||
await recalculateCalculation(calc, action, parseLevel, userInput);
|
||||
}
|
||||
// Embed the new calculated values
|
||||
embedInlineCalculations(inlineCalcObj);
|
||||
|
||||
53
app/imports/api/engine/action/test/diceRollFunctions.test.ts
Normal file
53
app/imports/api/engine/action/test/diceRollFunctions.test.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { assert } from 'chai';
|
||||
import {
|
||||
allLogContent,
|
||||
createTestCreature,
|
||||
getRandomIds,
|
||||
removeAllCreaturesAndProps,
|
||||
runActionById
|
||||
} from '/imports/api/engine/action/functions/actionEngineTest.testFn';
|
||||
|
||||
const [
|
||||
creatureId, dropLowestId
|
||||
] = getRandomIds(2);
|
||||
|
||||
const actionTestCreature = {
|
||||
_id: creatureId,
|
||||
props: [
|
||||
{
|
||||
_id: dropLowestId,
|
||||
type: 'note',
|
||||
summary: { text: 'Note summary {dropLowest(10d6,3)}' },
|
||||
children: [
|
||||
{
|
||||
type: 'roll',
|
||||
name: 'Roll',
|
||||
variableName: 'dropLowestVar',
|
||||
roll: { calculation: 'dropLowest(10d6,3)' }
|
||||
}
|
||||
]
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
describe.only('Built in dice functions', function () {
|
||||
// Increase timeout
|
||||
this.timeout(8000);
|
||||
|
||||
before(async function () {
|
||||
await removeAllCreaturesAndProps();
|
||||
await createTestCreature(actionTestCreature);
|
||||
});
|
||||
|
||||
it('Rolls 10d6 and drops the lowest 3 values', async function () {
|
||||
const action = await runActionById(dropLowestId);
|
||||
assert.exists(action);
|
||||
assert.deepEqual(allLogContent(action), [{
|
||||
value: 'Note summary 33',
|
||||
}, {
|
||||
inline: true,
|
||||
name: 'Roll',
|
||||
value: '10d6 [~~3~~, 4, 5, 6, ~~1~~, ~~2~~, 3, 4, 5, 6]\n**33**',
|
||||
}]);
|
||||
});
|
||||
});
|
||||
@@ -172,16 +172,17 @@ const call: CallFactory = {
|
||||
expectedType = argumentsExpected[index];
|
||||
}
|
||||
if (expectedType === 'parseNode') return;
|
||||
failed = !(
|
||||
const argFailed = !(
|
||||
node.parseType === expectedType
|
||||
|| (node.parseType === 'constant' && node.valueType === expectedType)
|
||||
);
|
||||
if (failed && fn === 'reduce') {
|
||||
if (argFailed && fn === 'reduce') {
|
||||
const typeName = typeof expectedType === 'string' ? expectedType : expectedType.constructor.name;
|
||||
const nodeName = node.parseType === 'constant' ? node.valueType : node.parseType;
|
||||
context.error(`Incorrect arguments to ${callNode.functionName} function` +
|
||||
`expected ${typeName} got ${nodeName}`);
|
||||
}
|
||||
failed = failed || argFailed;
|
||||
});
|
||||
return failed;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user