Started restructuring the library with attacks, saves, and limited parenting

This commit is contained in:
Stefan Zermatten
2019-08-12 16:42:30 +02:00
parent 6f4710bee3
commit a8b3fc3f2f
14 changed files with 204 additions and 91 deletions

View File

@@ -0,0 +1,38 @@
import SimpleSchema from 'simpl-schema';
import AdjustmentSchema from '/imports/api/creature/subSchemas/AdjustmentSchema.js';
import { ActionSchema } from '/imports/api/properties/Actions.js';
// Attacks are special instances of actions
let AttackSchema = new SimpleSchema()
.extend(ActionSchema)
.extend({
// What gets added to the d20 roll
rollBonus: {
type: String,
optional: true,
},
// What damage does it do to the targets
adjustments: {
type: Array,
defaultValue: [],
},
'adjustments.$': {
type: AdjustmentSchema,
},
// If set reference an item whose quantity is reduced by 1 every time this
// attack is rolled
ammunition: {
type: String,
regEx: SimpleSchema.RegEx.Id,
optional: true,
},
// Set better defaults for the action
type: {
defaultValue: 'attack',
},
tags: {
defaultValue: ['attack'],
},
});
export { AttackSchema };

View File

@@ -1,16 +0,0 @@
import SimpleSchema from 'simpl-schema';
import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX.js';
// TODO use variable name in computation engine, rather than a generated one
let ClassSchema = new SimpleSchema({
name: {
type: String,
optional: true,
},
variableName: {
type: String,
regEx: VARIABLE_NAME_REGEX,
},
});
export { ClassSchema };

View File

@@ -0,0 +1,31 @@
import SimpleSchema from 'simpl-schema';
import AdjustmentSchema from '/imports/api/creature/subSchemas/AdjustmentSchema.js';
import { StoredBuffWithIdSchema } from '/imports/api/properties/Buffs.js';
let RollResultSchema = new SimpleSchema ({
comparison: {
type: String,
allowedValues: ['>', '<', '>=', '<=', '==', 'always', 'else'],
},
targetValue: {
type: String,
optional: true,
},
adjustments: {
type: Array,
defaultValue: [],
},
'adjustments.$': {
type: AdjustmentSchema,
},
// The buffs to be applied
buffs: {
type: Array,
defaultValue: [],
},
'buffs.$': {
type: StoredBuffWithIdSchema,
},
});
export { RollResultSchema };

View File

@@ -1,25 +1,4 @@
import SimpleSchema from 'simpl-schema';
import AdjustmentSchema from '/imports/api/creature/subSchemas/AdjustmentSchema.js';
import { StoredBuffWithIdSchema } from '/imports/api/properties/Buffs.js';
let RollChildrenSchema = new SimpleSchema({
// The adjustments to be applied
adjustments: {
type: Array,
defaultValue: [],
},
'adjustments.$': {
type: AdjustmentSchema,
},
// The buffs to be applied
buffs: {
type: Array,
defaultValue: [],
},
'buffs.$': {
type: StoredBuffWithIdSchema,
},
});
/**
* Rolls are children to actions or other rolls, they are triggered with 0 or
@@ -40,34 +19,11 @@ let RollChildrenSchema = new SimpleSchema({
* child rolls are applied
*/
let RollSchema = new SimpleSchema({
// The roll made against the target value. A calculation that resolves to a
// number or a roll. If it is a number, it will be added to a d20 roll
roll: {
// The number to add to a d20 roll
rollBonus: {
type: String,
optional: true,
},
// The target number to meet or exceed
targetNumber: {
type: String,
optional: true,
},
// Is this roll a saving throw
rollType: {
type: String,
defaultValue: 'roll',
allowedValues: ['roll', 'savingThrow'],
},
// Apply this only if the parent roll missed
// i.e. roll failed or target suceeded on their save
onMiss: {
type: Boolean,
optional: true,
},
// Swap who wins ties
invertTies: {
type: Boolean,
optional: true,
},
// Effects can apply to this tag specifically
// Ranged spell attack, Ranged weapon attack, etc.
tags: {
@@ -77,15 +33,6 @@ let RollSchema = new SimpleSchema({
'tags.$': {
type: String,
},
// The buffs and adjustments to apply based on the outcome of the roll
hit: {
type: RollChildrenSchema,
defaultValue: {},
},
miss: {
type: RollChildrenSchema,
defaultValue: {},
},
});
export { RollSchema };

View File

@@ -0,0 +1,49 @@
import SimpleSchema from 'simpl-schema';
import AdjustmentSchema from '/imports/api/creature/subSchemas/AdjustmentSchema.js';
import { StoredBuffWithIdSchema } from '/imports/api/properties/Buffs.js';
// These are the rolls made when saves are called for
// For the saving throw bonus or proficiency, see ./Skills.js
let SavingThrowSchema = new SimpleSchema ({
dc: {
type: String,
optional: true,
},
// The variable name of ability the saving throw relies on
ability: {
type: String,
optional: true,
},
passAdjustments: {
type: Array,
defaultValue: [],
},
'passAdjustments.$': {
type: AdjustmentSchema,
},
// The buffs to be applied
passBuffs: {
type: Array,
defaultValue: [],
},
'passBuffs.$': {
type: StoredBuffWithIdSchema,
},
failAdjustments: {
type: Array,
defaultValue: [],
},
'failAdjustments.$': {
type: AdjustmentSchema,
},
// The buffs to be applied
failBuffs: {
type: Array,
defaultValue: [],
},
'failBuffs.$': {
type: StoredBuffWithIdSchema,
},
});
export { SavingThrowSchema };

View File

@@ -10,6 +10,7 @@ let SkillSchema = new SimpleSchema({
optional: true,
},
// The technical, lowercase, single-word name used in formulae
// Ignored for skilltype = save
variableName: {
type: String,
regEx: /^\w*[a-z]\w*$/i,

View File

@@ -1,8 +1,7 @@
import { CreatureSchema } from '/imports/api/creature/Creatures.js';
import { ActionSchema } from '/imports/api/properties/Actions.js';
import { AttackSchema } from 'app/imports/api/properties/Attacks.js';
import { AttributeSchema } from '/imports/api/properties/Attributes.js';
import { StoredBuffSchema } from '/imports/api/properties/Buffs.js';
import { ClassSchema } from '/imports/api/properties/Classes.js';
import { ClassLevelSchema } from '/imports/api/properties/ClassLevels.js';
import { DamageMultiplierSchema } from '/imports/api/properties/DamageMultipliers.js';
import { EffectSchema } from '/imports/api/properties/Effects.js';
@@ -12,19 +11,19 @@ import { FolderSchema } from '/imports/api/properties/Folders.js';
import { NoteSchema } from '/imports/api/properties/Notes.js';
import { ProficiencySchema } from '/imports/api/properties/Proficiencies.js';
import { RollSchema } from '/imports/api/properties/Rolls.js';
import { RollResultSchema } from '/imports/api/properties/RollResult.js';
import { SavingThrowSchema } from '/imports/api/properties/SavingThrows.js';
import { SkillSchema } from '/imports/api/properties/Skills.js';
import { SpellListSchema } from '/imports/api/properties/SpellLists.js';
import { SpellSchema } from '/imports/api/properties/Spells.js';
import { ContainerSchema } from '/imports/api/properties/Containers.js';
import { ItemSchema } from '/imports/api/properties/Items.js';
const propertySchemas = {
creature: CreatureSchema,
action: ActionSchema,
attack: AttackSchema,
attribute: AttributeSchema,
buff: StoredBuffSchema,
class: ClassSchema,
classLevel: ClassLevelSchema,
damageMultiplier: DamageMultiplierSchema,
effect: EffectSchema,
@@ -34,6 +33,8 @@ const propertySchemas = {
note: NoteSchema,
proficiency: ProficiencySchema,
roll: RollSchema,
rollResult: RollResultSchema,
savingThrow: SavingThrowSchema,
skill: SkillSchema,
spellList: SpellListSchema,
spell: SpellSchema,