Rolls now work in actions

This commit is contained in:
Stefan Zermatten
2021-02-22 11:55:08 +02:00
parent 6571fb860a
commit d00eedac19
5 changed files with 64 additions and 3 deletions

View File

@@ -1,8 +1,9 @@
import applyAction from '/imports/api/creature/actions/applyAction.js';
import applyAdjustment from '/imports/api/creature/actions/applyAdjustment.js';
import applyAttack from '/imports/api/creature/actions/applyAttack.js';
import applyDamage from '/imports/api/creature/actions/applyDamage.js';
import applyBuff from '/imports/api/creature/actions/applyBuff.js';
import applyDamage from '/imports/api/creature/actions/applyDamage.js';
import applyRoll from '/imports/api/creature/actions/applyRoll.js';
import applyToggle from '/imports/api/creature/actions/applyToggle.js';
function applyProperty(options){
@@ -42,7 +43,7 @@ function applyProperty(options){
case 'toggle':
return applyToggle(options);
case 'roll':
// applyRoll(options);
applyRoll(options);
break;
case 'savingThrow':
// applySavingThrow(options);

View File

@@ -0,0 +1,32 @@
import evaluateString from '/imports/api/creature/computation/afterComputation/evaluateString.js';
export default function applyRoll({
prop,
creature,
actionContext,
log,
}){
let scope = {
...creature.variables,
...actionContext,
};
try {
var {result, errors} = evaluateString(prop.roll, scope, 'reduce');
actionContext[prop.variableName] = result;
log.content.push({
name: prop.name,
resultPrefix: prop.variableName + ' = ' + prop.roll + ' = ',
result,
});
if (errors.length) {
log.content.push({
error: errors.join(', '),
});
}
} catch (e){
log.content.push({
error: e.toString(),
});
}
}

View File

@@ -1,6 +1,6 @@
import evaluateString from '/imports/api/creature/computation/afterComputation/evaluateString.js';
export default function applyDamage({
export default function applyToggle({
prop,
creature,
actionContext,