Fixed rolled effects not applying to checks
This commit is contained in:
@@ -7,6 +7,7 @@ import rollDice from '/imports/parser/rollDice.js';
|
|||||||
import numberToSignedString from '/imports/ui/utility/numberToSignedString.js';
|
import numberToSignedString from '/imports/ui/utility/numberToSignedString.js';
|
||||||
import { applyTriggers } from '/imports/api/engine/actions/applyTriggers.js';
|
import { applyTriggers } from '/imports/api/engine/actions/applyTriggers.js';
|
||||||
import ActionContext from '/imports/api/engine/actions/ActionContext.js';
|
import ActionContext from '/imports/api/engine/actions/ActionContext.js';
|
||||||
|
import evaluateCalculation from '/imports/api/engine/computation/utility/evaluateCalculation.js';
|
||||||
|
|
||||||
const doCheck = new ValidatedMethod({
|
const doCheck = new ValidatedMethod({
|
||||||
name: 'creatureProperties.doCheck',
|
name: 'creatureProperties.doCheck',
|
||||||
@@ -72,7 +73,11 @@ function rollCheck(prop, actionContext) {
|
|||||||
throw (`${prop.type} not supported for checks`);
|
throw (`${prop.type} not supported for checks`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const rollModifierText = numberToSignedString(rollModifier, true);
|
let rollModifierText = numberToSignedString(rollModifier, true);
|
||||||
|
|
||||||
|
const { effectBonus, effectString } = applyUnresolvedEffects(prop, scope)
|
||||||
|
rollModifierText += effectString;
|
||||||
|
rollModifier += effectBonus;
|
||||||
|
|
||||||
let value, values, resultPrefix;
|
let value, values, resultPrefix;
|
||||||
if (scope['$checkAdvantage'] === 1){
|
if (scope['$checkAdvantage'] === 1){
|
||||||
@@ -106,3 +111,21 @@ function rollCheck(prop, actionContext) {
|
|||||||
value: `${resultPrefix} **${result}**`,
|
value: `${resultPrefix} **${result}**`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function applyUnresolvedEffects(prop, scope) {
|
||||||
|
let effectBonus = 0;
|
||||||
|
let effectString = '';
|
||||||
|
if (!prop.effects) {
|
||||||
|
return { effectBonus, effectString};
|
||||||
|
}
|
||||||
|
prop.effects.forEach(effect => {
|
||||||
|
if (!effect.amount?.parseNode) return;
|
||||||
|
if (effect.operation !== 'add') return;
|
||||||
|
effect.amount._parseLevel = 'reduce';
|
||||||
|
evaluateCalculation(effect.amount, scope);
|
||||||
|
if (typeof effect.amount?.value !== 'number') return;
|
||||||
|
effectBonus += effect.amount.value;
|
||||||
|
effectString += ` ${effect.amount.value < 0 ? '-' : '+'} [${effect.amount.calculation}] ${Math.abs(effect.amount.value)}`
|
||||||
|
});
|
||||||
|
return { effectBonus, effectString};
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { pick } from "lodash";
|
||||||
|
|
||||||
export default function aggregateEffect({node, linkedNode, link}){
|
export default function aggregateEffect({node, linkedNode, link}){
|
||||||
if (link.data !== 'effect') return;
|
if (link.data !== 'effect') return;
|
||||||
// store the effect aggregator, its presence indicates that the variable is
|
// store the effect aggregator, its presence indicates that the variable is
|
||||||
@@ -19,11 +21,22 @@ export default function aggregateEffect({node, linkedNode, link}){
|
|||||||
|
|
||||||
// Store a summary of the effect itself
|
// Store a summary of the effect itself
|
||||||
node.data.effects = node.data.effects || [];
|
node.data.effects = node.data.effects || [];
|
||||||
|
// Store either just
|
||||||
|
let effectAmount;
|
||||||
|
if (!linkedNode.data.amount) {
|
||||||
|
effectAmount = undefined;
|
||||||
|
} else if (typeof linkedNode.data.amount.value === 'string') {
|
||||||
|
effectAmount = pick(linkedNode.data.amount, [
|
||||||
|
'calculation', 'parseNode', 'parseError', 'value'
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
effectAmount = pick(linkedNode.data.amount, ['value']);
|
||||||
|
}
|
||||||
node.data.effects.push({
|
node.data.effects.push({
|
||||||
_id: linkedNode.data._id,
|
_id: linkedNode.data._id,
|
||||||
name: linkedNode.data.name,
|
name: linkedNode.data.name,
|
||||||
operation: linkedNode.data.operation,
|
operation: linkedNode.data.operation,
|
||||||
amount: linkedNode.data.amount && {value: linkedNode.data.amount.value},
|
amount: effectAmount,
|
||||||
type: linkedNode.data.type,
|
type: linkedNode.data.type,
|
||||||
// ancestors: linkedNode.data.ancestors,
|
// ancestors: linkedNode.data.ancestors,
|
||||||
});
|
});
|
||||||
@@ -33,7 +46,7 @@ export default function aggregateEffect({node, linkedNode, link}){
|
|||||||
// Get the result of the effect
|
// Get the result of the effect
|
||||||
const result = linkedNode.data.amount?.value;
|
const result = linkedNode.data.amount?.value;
|
||||||
// Skip aggregating if the result is not resolved completely
|
// Skip aggregating if the result is not resolved completely
|
||||||
if (typeof result === 'string') return;
|
if (typeof result === 'string' || result === undefined) return;
|
||||||
// Aggregate the effect based on its operation
|
// Aggregate the effect based on its operation
|
||||||
switch(linkedNode.data.operation){
|
switch(linkedNode.data.operation){
|
||||||
case 'base':
|
case 'base':
|
||||||
|
|||||||
@@ -134,6 +134,7 @@
|
|||||||
import IncrementButton from '/imports/ui/components/IncrementButton.vue';
|
import IncrementButton from '/imports/ui/components/IncrementButton.vue';
|
||||||
import getProficiencyIcon from '/imports/ui/utility/getProficiencyIcon.js';
|
import getProficiencyIcon from '/imports/ui/utility/getProficiencyIcon.js';
|
||||||
import {snackbar} from '/imports/ui/components/snackbars/SnackbarQueue.js';
|
import {snackbar} from '/imports/ui/components/snackbars/SnackbarQueue.js';
|
||||||
|
import sortEffects from '/imports/ui/utility/sortEffects.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@@ -177,6 +178,9 @@
|
|||||||
proficiencyIcon(){
|
proficiencyIcon(){
|
||||||
return getProficiencyIcon(this.model.proficiency);
|
return getProficiencyIcon(this.model.proficiency);
|
||||||
},
|
},
|
||||||
|
effects() {
|
||||||
|
return sortEffects(this.model.effects);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
numberToSignedString,
|
numberToSignedString,
|
||||||
@@ -202,11 +206,6 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
meteor: {
|
|
||||||
effects() {
|
|
||||||
return this.model.effects;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ import AttributeEffect from '/imports/ui/properties/components/attributes/Attrib
|
|||||||
import SkillProficiency from '/imports/ui/properties/components/skills/SkillProficiency.vue';
|
import SkillProficiency from '/imports/ui/properties/components/skills/SkillProficiency.vue';
|
||||||
import CreatureVariables from '/imports/api/creature/creatures/CreatureVariables.js';
|
import CreatureVariables from '/imports/api/creature/creatures/CreatureVariables.js';
|
||||||
import getProficiencyIcon from '/imports/ui/utility/getProficiencyIcon.js';
|
import getProficiencyIcon from '/imports/ui/utility/getProficiencyIcon.js';
|
||||||
|
import sortEffects from '/imports/ui/utility/sortEffects.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@@ -169,7 +170,10 @@ export default {
|
|||||||
},
|
},
|
||||||
passiveScore(){
|
passiveScore(){
|
||||||
return 10 + this.model.value + this.model.passiveBonus;
|
return 10 + this.model.value + this.model.passiveBonus;
|
||||||
}
|
},
|
||||||
|
effects() {
|
||||||
|
return sortEffects(this.model.effects);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
numberToSignedString,
|
numberToSignedString,
|
||||||
@@ -186,9 +190,6 @@ export default {
|
|||||||
variables(){
|
variables(){
|
||||||
return CreatureVariables.findOne({_creatureId: this.context.creatureId}) || {};
|
return CreatureVariables.findOne({_creatureId: this.context.creatureId}) || {};
|
||||||
},
|
},
|
||||||
effects() {
|
|
||||||
return this.model.effects;
|
|
||||||
},
|
|
||||||
baseProficiencies(){
|
baseProficiencies(){
|
||||||
if (this.context.creatureId){
|
if (this.context.creatureId){
|
||||||
let creatureId = this.context.creatureId;
|
let creatureId = this.context.creatureId;
|
||||||
|
|||||||
Reference in New Issue
Block a user