Added UI for action branches

This commit is contained in:
Stefan Zermatten
2022-02-09 16:47:38 +02:00
parent 2bdd60b5e8
commit 15ead403a5
16 changed files with 219 additions and 9 deletions

View File

@@ -54,9 +54,24 @@ function applyAttackWithoutTarget({prop, scope, log}){
scope['$attackRoll'] = {value};
let criticalHitTarget = scope.criticalHitTarget?.value || 20;
let criticalHit = value >= criticalHitTarget;
if (criticalHit) scope['$criticalHit'] = {value: true};
if (criticalHit){
scope['$criticalHit'] = {value: true};
scope['$attackHit'] = {value: true};
} else {
let criticalMiss = value === 1;
if (criticalMiss){
scope['$criticalMiss'] = 1;
log.content.push({
name: 'Critical Miss!',
});
scope['$attackMiss'] = {value: true};
} else {
// Untargeted attacks hit by default
scope['$attackHit'] = {value: true}
}
}
let result = value + prop.attackRoll.value;
scope['$toHit'] = {value: result};
scope['$attackRoll'] = {value: result};
log.content.push({
name: criticalHit ? 'Critical Hit!' : 'To Hit',
value: `1d20 [${value}] + ${prop.attackRoll.value} = ` + result,

View File

@@ -1,5 +1,6 @@
import applyProperty from '../applyProperty.js';
import recalculateCalculation from './shared/recalculateCalculation.js';
import rollDice from '/imports/parser/rollDice.js';
export default function applyBranch(node, {
creature, targets, scope, log
@@ -27,6 +28,14 @@ export default function applyBranch(node, {
case 'successfulSave':
if (scope['$saveSucceeded']?.value) applyChildren();
break;
case 'random':
if (node.children.length){
let index = rollDice(1, node.children.length)[0] - 1;
applyProperty(node.children[index], {
creature, targets, scope, log
});
}
break;
case 'eachTarget':
if (targets.length){
targets.forEach(target => {