From 6f4710bee32b37789258706b9bf80324dea181ca Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Tue, 6 Aug 2019 16:37:52 +0200 Subject: [PATCH] Roll modifiers are effects that target rolls based on their tags --- app/imports/api/properties/RollModifier.js | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 app/imports/api/properties/RollModifier.js diff --git a/app/imports/api/properties/RollModifier.js b/app/imports/api/properties/RollModifier.js new file mode 100644 index 00000000..ea16ef5b --- /dev/null +++ b/app/imports/api/properties/RollModifier.js @@ -0,0 +1,52 @@ +import SimpleSchema from 'simpl-schema'; + +/* + * RollModifiers are reason-value attached to rolls + * that modify their final value in some way + * These are separate from effects because they are a always a result of the + * creature's stats, and never cause a recomputation themselves + */ +let RollModifierSchema = new SimpleSchema({ + name: { + type: String, + optional: true, + }, + operation: { + type: String, + defaultValue: 'add', + allowedValues: [ + 'damageBonus', + 'rollBonus', + ], + }, + calculation: { + type: String, + optional: true, + }, + // which tags the modifier is applied to + // all tags must match + 'tags.$': { + type: String, + optional: true, + }, +}); + +const StoredRollModifierSchema = new SimpleSchema({ + _id: { + type: String, + regEx: SimpleSchema.RegEx.Id, + autoValue(){ + if (!this.isSet) return Random.id(); + } + }, +}).extend(RollModifierSchema); + +const ComputedRollModifierSchema = new SimpleSchema({ + // The computed result of the effect + result: { + type: SimpleSchema.oneOf(Number, String), + optional: true, + }, +}).extend(RollModifierSchema); + +export { RollModifierSchema, StoredRollModifierSchema, ComputedRollModifierSchema };