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