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
|
//Log the buff
|
||||||
let logValue = prop.description?.value
|
let logValue = prop.description?.value
|
||||||
if (prop.description?.text) {
|
if (prop.description?.text) {
|
||||||
recalculateInlineCalculations(prop.description, action, 'reduce', userInput);
|
await recalculateInlineCalculations(prop.description, action, 'reduce', userInput);
|
||||||
logValue = prop.description?.value;
|
logValue = prop.description?.value;
|
||||||
}
|
}
|
||||||
result.appendLog({
|
result.appendLog({
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export default async function applyCreatureTemplateProperty(
|
|||||||
//Log the Creature that is about to be summoned
|
//Log the Creature that is about to be summoned
|
||||||
let logValue = prop.description?.value
|
let logValue = prop.description?.value
|
||||||
if (prop.description?.text) {
|
if (prop.description?.text) {
|
||||||
recalculateInlineCalculations(prop.description, action, 'reduce', userInput);
|
await recalculateInlineCalculations(prop.description, action, 'reduce', userInput);
|
||||||
logValue = prop.description?.value;
|
logValue = prop.description?.value;
|
||||||
}
|
}
|
||||||
// There are no targets for creature templates
|
// 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 resolve from '/imports/parser/resolve';
|
||||||
import { getEffectiveActionScope } from '/imports/api/engine/action/functions/getEffectiveActionScope';
|
import { getEffectiveActionScope } from '/imports/api/engine/action/functions/getEffectiveActionScope';
|
||||||
import { CalculatedField } from '/imports/api/properties/subSchemas/computedField';
|
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 InputProvider from '/imports/api/engine/action/functions/userInput/InputProvider';
|
||||||
import { EngineAction } from '/imports/api/engine/action/EngineActions';
|
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(
|
export default async function recalculateCalculation(
|
||||||
calcObj: CalculatedField,
|
calcObj: CalculatedField,
|
||||||
action,
|
action,
|
||||||
@@ -27,7 +24,7 @@ export default async function recalculateCalculation(
|
|||||||
const {
|
const {
|
||||||
result: unaffectedResult,
|
result: unaffectedResult,
|
||||||
context
|
context
|
||||||
} = await resolve(parseLevel, calcObj.parseNode, scope);
|
} = await resolve(parseLevel, calcObj.parseNode, scope, undefined, userInput);
|
||||||
calcObj.valueNode = unaffectedResult;
|
calcObj.valueNode = unaffectedResult;
|
||||||
|
|
||||||
// store the unaffected value
|
// store the unaffected value
|
||||||
@@ -48,7 +45,7 @@ export default async function recalculateCalculation(
|
|||||||
// Resolve the modified valueNode, use the same context
|
// Resolve the modified valueNode, use the same context
|
||||||
const {
|
const {
|
||||||
result: finalResult
|
result: finalResult
|
||||||
} = await resolve(parseLevel, calcObj.valueNode, scope, context);
|
} = await resolve(parseLevel, calcObj.valueNode, scope, context, userInput);
|
||||||
|
|
||||||
// Store the errors
|
// Store the errors
|
||||||
calcObj.errors = context.errors;
|
calcObj.errors = context.errors;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export default async function recalculateInlineCalculations(
|
|||||||
if (!inlineCalcObj?.inlineCalculations?.length) return;
|
if (!inlineCalcObj?.inlineCalculations?.length) return;
|
||||||
// Recalculate each calculation with the current scope
|
// Recalculate each calculation with the current scope
|
||||||
for (const calc of inlineCalcObj.inlineCalculations) {
|
for (const calc of inlineCalcObj.inlineCalculations) {
|
||||||
await recalculateCalculation(calc, action, undefined, userInput);
|
await recalculateCalculation(calc, action, parseLevel, userInput);
|
||||||
}
|
}
|
||||||
// Embed the new calculated values
|
// Embed the new calculated values
|
||||||
embedInlineCalculations(inlineCalcObj);
|
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];
|
expectedType = argumentsExpected[index];
|
||||||
}
|
}
|
||||||
if (expectedType === 'parseNode') return;
|
if (expectedType === 'parseNode') return;
|
||||||
failed = !(
|
const argFailed = !(
|
||||||
node.parseType === expectedType
|
node.parseType === expectedType
|
||||||
|| (node.parseType === 'constant' && node.valueType === 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 typeName = typeof expectedType === 'string' ? expectedType : expectedType.constructor.name;
|
||||||
const nodeName = node.parseType === 'constant' ? node.valueType : node.parseType;
|
const nodeName = node.parseType === 'constant' ? node.valueType : node.parseType;
|
||||||
context.error(`Incorrect arguments to ${callNode.functionName} function` +
|
context.error(`Incorrect arguments to ${callNode.functionName} function` +
|
||||||
`expected ${typeName} got ${nodeName}`);
|
`expected ${typeName} got ${nodeName}`);
|
||||||
}
|
}
|
||||||
|
failed = failed || argFailed;
|
||||||
});
|
});
|
||||||
return failed;
|
return failed;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user