Normalized all scope['$...'] to be unwrapped values
This commit is contained in:
@@ -72,10 +72,10 @@ function applyAttackWithoutTarget({ attack, actionContext }) {
|
||||
name += ' (Disadvantage)';
|
||||
}
|
||||
if (!criticalMiss) {
|
||||
scope['$attackHit'] = { value: true }
|
||||
scope['$attackHit'] = true
|
||||
}
|
||||
if (!criticalHit) {
|
||||
scope['$attackMiss'] = { value: true };
|
||||
scope['$attackMiss'] = true;
|
||||
}
|
||||
|
||||
actionContext.addLog({
|
||||
@@ -121,9 +121,9 @@ function applyAttackToTarget({ attack, target, actionContext }) {
|
||||
inline: true,
|
||||
});
|
||||
if (criticalMiss || result < armor) {
|
||||
scope['$attackMiss'] = { value: true };
|
||||
scope['$attackMiss'] = true;
|
||||
} else {
|
||||
scope['$attackHit'] = { value: true };
|
||||
scope['$attackHit'] = true;
|
||||
}
|
||||
} else {
|
||||
actionContext.addLog({
|
||||
@@ -163,9 +163,9 @@ function rollAttack(attack, scope) {
|
||||
value = rollDice(1, 20)[0];
|
||||
resultPrefix = `1d20 [${value}] ${rollModifierText}`
|
||||
}
|
||||
scope['$attackDiceRoll'] = { value };
|
||||
scope['$attackDiceRoll'] = value;
|
||||
const result = value + attack.value;
|
||||
scope['$attackRoll'] = { value: result };
|
||||
scope['$attackRoll'] = result;
|
||||
const { criticalHit, criticalMiss } = applyCrits(value, scope);
|
||||
return { resultPrefix, result, value, criticalHit, criticalMiss };
|
||||
}
|
||||
@@ -175,11 +175,11 @@ function applyCrits(value, scope) {
|
||||
let criticalHit = value >= criticalHitTarget;
|
||||
let criticalMiss;
|
||||
if (criticalHit) {
|
||||
scope['$criticalHit'] = { value: true };
|
||||
scope['$criticalHit'] = true;
|
||||
} else {
|
||||
criticalMiss = value === 1;
|
||||
if (criticalMiss) {
|
||||
scope['$criticalMiss'] = { value: true };
|
||||
scope['$criticalMiss'] = true;
|
||||
}
|
||||
}
|
||||
return { criticalHit, criticalMiss };
|
||||
|
||||
@@ -3,22 +3,22 @@ import recalculateCalculation from './shared/recalculateCalculation.js';
|
||||
import rollDice from '/imports/parser/rollDice.js';
|
||||
import { applyNodeTriggers } from '/imports/api/engine/actions/applyTriggers.js';
|
||||
|
||||
export default function applyBranch(node, actionContext){
|
||||
export default function applyBranch(node, actionContext) {
|
||||
applyNodeTriggers(node, 'before', actionContext);
|
||||
const applyChildren = function(){
|
||||
const applyChildren = function () {
|
||||
applyNodeTriggers(node, 'after', actionContext);
|
||||
node.children.forEach(child => applyProperty(child, actionContext));
|
||||
};
|
||||
const scope = actionContext.scope;
|
||||
const targets = actionContext.targets;
|
||||
const prop = node.node;
|
||||
switch(prop.branchType){
|
||||
switch (prop.branchType) {
|
||||
case 'if':
|
||||
recalculateCalculation(prop.condition, actionContext);
|
||||
if (prop.condition?.value) applyChildren();
|
||||
break;
|
||||
case 'index':
|
||||
if (node.children.length){
|
||||
if (node.children.length) {
|
||||
recalculateCalculation(prop.condition, actionContext);
|
||||
if (!isFinite(prop.condition?.value)) {
|
||||
actionContext.addLog({
|
||||
@@ -35,31 +35,31 @@ export default function applyBranch(node, actionContext){
|
||||
}
|
||||
break;
|
||||
case 'hit':
|
||||
if (scope['$attackHit']?.value){
|
||||
if (!targets.length && !prop.silent) actionContext.addLog({value: '**On hit**'});
|
||||
if (scope['$attackHit']) {
|
||||
if (!targets.length && !prop.silent) actionContext.addLog({ value: '**On hit**' });
|
||||
applyChildren();
|
||||
}
|
||||
break;
|
||||
case 'miss':
|
||||
if (scope['$attackMiss']?.value){
|
||||
if (!targets.length && !prop.silent) actionContext.addLog({value: '**On miss**'});
|
||||
if (scope['$attackMiss']) {
|
||||
if (!targets.length && !prop.silent) actionContext.addLog({ value: '**On miss**' });
|
||||
applyChildren();
|
||||
}
|
||||
break;
|
||||
case 'failedSave':
|
||||
if (scope['$saveFailed']?.value){
|
||||
if (!targets.length && !prop.silent) actionContext.addLog({value: '**On failed save**'});
|
||||
if (scope['$saveFailed']) {
|
||||
if (!targets.length && !prop.silent) actionContext.addLog({ value: '**On failed save**' });
|
||||
applyChildren();
|
||||
}
|
||||
break;
|
||||
case 'successfulSave':
|
||||
if (scope['$saveSucceeded']?.value){
|
||||
if (!targets.length && !prop.silent) actionContext.addLog({value: '**On save**',});
|
||||
if (scope['$saveSucceeded']) {
|
||||
if (!targets.length && !prop.silent) actionContext.addLog({ value: '**On save**', });
|
||||
applyChildren();
|
||||
}
|
||||
break;
|
||||
case 'random':
|
||||
if (node.children.length){
|
||||
if (node.children.length) {
|
||||
let index = rollDice(1, node.children.length)[0] - 1;
|
||||
applyNodeTriggers(node, 'after', actionContext);
|
||||
applyProperty(node.children[index], actionContext);
|
||||
|
||||
@@ -27,7 +27,7 @@ export default function applyDamage(node, actionContext) {
|
||||
// Choose target
|
||||
let damageTargets = prop.target === 'self' ? [actionContext.creature] : actionContext.targets;
|
||||
// Determine if the hit is critical
|
||||
let criticalHit = scope['$criticalHit']?.value &&
|
||||
let criticalHit = scope['$criticalHit'] &&
|
||||
prop.damageType !== 'healing' // Can't critically heal
|
||||
;
|
||||
// Double the damage rolls if the hit is critical
|
||||
|
||||
@@ -31,8 +31,8 @@ export default function applySavingThrow(node, actionContext) {
|
||||
// If there are no save targets, apply all children as if the save both
|
||||
// succeeeded and failed
|
||||
if (!saveTargets?.length) {
|
||||
scope['$saveFailed'] = { value: true };
|
||||
scope['$saveSucceeded'] = { value: true };
|
||||
scope['$saveFailed'] = true;
|
||||
scope['$saveSucceeded'] = true;
|
||||
applyNodeTriggers(node, 'after', actionContext);
|
||||
return node.children.forEach(child => applyProperty(child, actionContext));
|
||||
}
|
||||
@@ -90,14 +90,14 @@ export default function applySavingThrow(node, actionContext) {
|
||||
value = values[0];
|
||||
resultPrefix = `1d20 [ ${value} ] ${rollModifierText}`
|
||||
}
|
||||
scope['$saveDiceRoll'] = { value };
|
||||
scope['$saveDiceRoll'] = value;
|
||||
const result = value + rollModifier || 0;
|
||||
scope['$saveRoll'] = { value: result };
|
||||
scope['$saveRoll'] = result;
|
||||
const saveSuccess = result >= dc;
|
||||
if (saveSuccess) {
|
||||
scope['$saveSucceeded'] = { value: true };
|
||||
scope['$saveSucceeded'] = true;
|
||||
} else {
|
||||
scope['$saveFailed'] = { value: true };
|
||||
scope['$saveFailed'] = true;
|
||||
}
|
||||
if (!prop.silent) actionContext.addLog({
|
||||
name: saveSuccess ? 'Successful save' : 'Failed save',
|
||||
|
||||
Reference in New Issue
Block a user