Fixed bug where rolls weren't recalculating in actions
This commit is contained in:
@@ -147,14 +147,21 @@ export type CreatureProperty = ConvertToUnion<CreaturePropertyTypes>;
|
||||
|
||||
const CreatureProperties = new Mongo.Collection<CreatureProperty>('creatureProperties');
|
||||
|
||||
const genericCreaturePropertySchema = TypedSimpleSchema.from({})
|
||||
.extend(CreaturePropertySchema)
|
||||
.extend(ColorSchema)
|
||||
.extend(ChildSchema)
|
||||
.extend(SoftRemovableSchema);
|
||||
|
||||
// Attach the default schema
|
||||
CreatureProperties.attachSchema(genericCreaturePropertySchema);
|
||||
|
||||
// Attach the schemas for each type
|
||||
let key: keyof typeof propertySchemasIndex;
|
||||
for (key in propertySchemasIndex) {
|
||||
const schema = new SimpleSchema({});
|
||||
schema.extend(propertySchemasIndex[key]);
|
||||
schema.extend(CreaturePropertySchema);
|
||||
schema.extend(ColorSchema);
|
||||
schema.extend(ChildSchema);
|
||||
schema.extend(SoftRemovableSchema);
|
||||
const schema = TypedSimpleSchema.from({})
|
||||
.extend(propertySchemasIndex[key])
|
||||
.extend(genericCreaturePropertySchema)
|
||||
CreatureProperties.attachSchema(schema, {
|
||||
selector: { type: key }
|
||||
});
|
||||
|
||||
@@ -44,7 +44,7 @@ export default async function applyRollProperty(
|
||||
}
|
||||
|
||||
// If we didn't end up with a constant or a number of finite value, give up
|
||||
if (reduced?.parseType !== 'constant' || !isFiniteNode(reduced)) {
|
||||
if (!isFiniteNode(reduced)) {
|
||||
return applyDefaultAfterPropTasks(action, prop, task.targetIds, inputProvider);
|
||||
}
|
||||
const value = reduced.value;
|
||||
|
||||
@@ -11,10 +11,11 @@ import { CalculatedField } from '/imports/api/properties/subSchemas/computedFiel
|
||||
import InputProvider from '/imports/api/engine/action/functions/userInput/InputProvider';
|
||||
import { EngineAction } from '/imports/api/engine/action/EngineActions';
|
||||
import ResolveLevel from '/imports/parser/types/ResolveLevel';
|
||||
import constant from '/imports/parser/parseTree/constant';
|
||||
|
||||
export default async function recalculateCalculation(
|
||||
calcObj: CalculatedField,
|
||||
action,
|
||||
action: EngineAction,
|
||||
parseLevel: ResolveLevel = 'reduce',
|
||||
userInput: InputProvider,
|
||||
) {
|
||||
@@ -34,11 +35,11 @@ export default async function recalculateCalculation(
|
||||
// Apply all the effects and proficiencies
|
||||
aggregateCalculationEffects(
|
||||
calcObj,
|
||||
id => getSingleProperty(action.creatureId, id)
|
||||
(id: string) => getSingleProperty(action.creatureId, id)
|
||||
);
|
||||
aggregateCalculationProficiencies(
|
||||
calcObj,
|
||||
id => getSingleProperty(action.creatureId, id),
|
||||
(id: string) => getSingleProperty(action.creatureId, id),
|
||||
scope['proficiencyBonus']?.value || 0
|
||||
);
|
||||
|
||||
@@ -61,12 +62,13 @@ export async function rollAndReduceCalculation(
|
||||
if (!calcObj) throw new Error('calcObj is required');
|
||||
const context = new Context();
|
||||
const scope = await getEffectiveActionScope(action);
|
||||
|
||||
// Compile
|
||||
recalculateCalculation(calcObj, action, 'compile', userInput);
|
||||
const compiled = calcObj.valueNode;
|
||||
await recalculateCalculation(calcObj, action, 'compile', userInput);
|
||||
const compiled = calcObj.valueNode ?? constant.create({ value: 0 });
|
||||
|
||||
// Roll
|
||||
const { result: rolled } = await resolve('roll', calcObj.valueNode, scope, context, userInput);
|
||||
const { result: rolled } = await resolve('roll', compiled, scope, context, userInput);
|
||||
|
||||
// Reduce
|
||||
const { result: reduced } = await resolve('reduce', rolled, scope, context, userInput);
|
||||
|
||||
@@ -41,12 +41,13 @@ const constant: ConstantFactory = {
|
||||
},
|
||||
}
|
||||
|
||||
export function isFiniteNode(node: ParseNode): node is FiniteNumberConstantNode {
|
||||
export function isFiniteNode(node: ParseNode | undefined): node is FiniteNumberConstantNode {
|
||||
return node
|
||||
&& node.parseType === 'constant'
|
||||
&& node.valueType === 'number'
|
||||
&& typeof node.value === 'number'
|
||||
&& isFinite(node.value);
|
||||
&& isFinite(node.value)
|
||||
|| false;
|
||||
}
|
||||
|
||||
export default constant;
|
||||
|
||||
Reference in New Issue
Block a user