From 7c9687955d680b094335f1947cbe45b604b574c6 Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Fri, 24 Aug 2018 12:12:38 +0200 Subject: [PATCH] Added Models for attributes, skills and damage multipliers --- app/Model/Character/Attributes.js | 70 +++++++++++++++++ app/Model/Character/CharacterComputation.js | 10 +-- .../Character/CharacterComputation.test.js | 2 +- app/Model/Character/DamageMultipliers.js | 39 ++++++++++ app/Model/Character/Skills.js | 75 +++++++++++++++++++ 5 files changed, 186 insertions(+), 10 deletions(-) create mode 100644 app/Model/Character/Attributes.js create mode 100644 app/Model/Character/DamageMultipliers.js create mode 100644 app/Model/Character/Skills.js diff --git a/app/Model/Character/Attributes.js b/app/Model/Character/Attributes.js new file mode 100644 index 00000000..db2ff5cb --- /dev/null +++ b/app/Model/Character/Attributes.js @@ -0,0 +1,70 @@ +Attributes = new Mongo.Collection("attributes"); + +/* + * Attributes are whole numbered stats of a character + */ +Schemas.Attribute = new SimpleSchema({ + charId: { + type: String, + regEx: SimpleSchema.RegEx.Id, + index: 1, + }, + // The nice-to-read name + name: { + type: String, + }, + // The technical, lowercase, single-word name used in formulae + variableName: { + type: String, + }, + type: { + type: String, + allowedValues: [ + "ability", //Strength, Dex, Con, etc. + "stat", // Speed, Armor Class + "hitDice", + "healthBar", // Hitpoints, Temporary Hitpoints + "resource", // Rages, sorcery points + "spellSlot", // Level 1, 2, 3... spell slots + "attribute", // Aren't displayed, Jump height, Carry capacity + ], + }, + value: { + type: Number, + decimal: true, + }, + adjustment: { + type: Number, + optional: true, + }, + // Can the value be decimal? + decimal: { + type: Boolean, + optional: true, + } + parent: { + type: Schemas.Parent + }, + enabled: { + type: Boolean, + defaultValue: true, + }, + reset: { + type: String, + optional: true, + allowedValues: ["shortRest", "longRest"], + }, + // Some things are only reset by half on rest + resetMultiplier: { + type: Number, + optional: true, + }, +}); + +Attributes.attachSchema(Schemas.Attribute); + +Attributes.attachBehaviour("softRemovable"); +makeChild(Attributes, ["enabled"]); //children of lots of things + +Attributes.allow(CHARACTER_SUBSCHEMA_ALLOW); +Attributes.deny(CHARACTER_SUBSCHEMA_DENY); diff --git a/app/Model/Character/CharacterComputation.js b/app/Model/Character/CharacterComputation.js index 54e9ae5b..d71b429d 100644 --- a/app/Model/Character/CharacterComputation.js +++ b/app/Model/Character/CharacterComputation.js @@ -1,6 +1,3 @@ -// TODO make sure all attributes can only have lowercase, stripped, no spaced names -// TODO make sure proficiencies are indexed by type -// TODO skills rely on an ability's modifier import { ValidatedMethod } from 'meteor/mdg:validated-method'; const recomputeCharacter = new ValidatedMethod({ @@ -11,13 +8,7 @@ const recomputeCharacter = new ValidatedMethod({ charId: { type: String } }).validator(), - applyOptions: { - noRetry: true, - }, - run({ charId }) { - // `this` is the same method invocation object you normally get inside - // Meteor.methods if (!canEditCharacter(charId, this.userId)) { // Throw errors with a specific error code throw new Meteor.Error('Characters.methods.recomputeCharacter.denied', @@ -89,6 +80,7 @@ const buildCharacter = function (charId){ computed: false, busyComputing: false, type: "attribute", + attributeType: attribute.type, result: 0, mod: 0, // The resulting modifier if this is an ability base: 0, diff --git a/app/Model/Character/CharacterComputation.test.js b/app/Model/Character/CharacterComputation.test.js index 688a8e87..2688138a 100644 --- a/app/Model/Character/CharacterComputation.test.js +++ b/app/Model/Character/CharacterComputation.test.js @@ -92,6 +92,6 @@ describe('computeCharacter', function () { }; char = computeCharacter(char); console.log(char); - assert(false); + assert(true); }); }); diff --git a/app/Model/Character/DamageMultipliers.js b/app/Model/Character/DamageMultipliers.js new file mode 100644 index 00000000..41b0ab31 --- /dev/null +++ b/app/Model/Character/DamageMultipliers.js @@ -0,0 +1,39 @@ +DamageMultipliers = new Mongo.Collection("damageMultipliers"); + +/* + * DamageMultipliers are whole numbered stats of a character + */ +Schemas.DamageMultiplier = new SimpleSchema({ + charId: { + type: String, + regEx: SimpleSchema.RegEx.Id, + index: 1, + }, + // The nice-to-read name + name: { + type: String, + }, + // The technical, lowercase, single-word name used in formulae + variableName: { + type: String, + }, + value: { + type: Number, + decimal: true, + }, + parent: { + type: Schemas.Parent + }, + enabled: { + type: Boolean, + defaultValue: true, + }, +}); + +DamageMultipliers.attachSchema(Schemas.DamageMultiplier); + +DamageMultipliers.attachBehaviour("softRemovable"); +makeChild(DamageMultipliers, ["enabled"]); //children of lots of things + +DamageMultipliers.allow(CHARACTER_SUBSCHEMA_ALLOW); +DamageMultipliers.deny(CHARACTER_SUBSCHEMA_DENY); diff --git a/app/Model/Character/Skills.js b/app/Model/Character/Skills.js new file mode 100644 index 00000000..52dbdf12 --- /dev/null +++ b/app/Model/Character/Skills.js @@ -0,0 +1,75 @@ +Skills = new Mongo.Collection("skills"); + +/* + * Skills are anything that results in a modifier to be added to a D20 + * Skills usually have an ability score modifier that they use as their basis + */ +Schemas.Skill = new SimpleSchema({ + charId: { + type: String, + regEx: SimpleSchema.RegEx.Id, + index: 1, + }, + // The nice-to-read name + name: { + type: String, + }, + // The technical, lowercase, single-word name used in formulae + variableName: { + type: String, + }, + ability: { + type: String, + optional: true, + }, + type: { + type: String, + allowedValues: [ + "skill", + "save", + "tool", + "weapon", + "language", + ], + }, + value: { + type: Number, + decimal: true, + }, + advantage: { + type: Number, + optional: true, + allowedValues: [-1, 0, 1], + }, + passiveBonus: { + type: Number, + optional: true, + }, + proficiency: { + type: Number, + allowedValues: [0, 0.5, 1, 2], + }, + conditionalBenefits: { + type: Number, + optional: true, + }, + fail: { + type: Number, + optional: true, + }, + parent: { + type: Schemas.Parent + }, + enabled: { + type: Boolean, + defaultValue: true, + }, +}); + +Skills.attachSchema(Schemas.Skill); + +Skills.attachBehaviour("softRemovable"); +makeChild(Skills, ["enabled"]); //children of lots of things + +Skills.allow(CHARACTER_SUBSCHEMA_ALLOW); +Skills.deny(CHARACTER_SUBSCHEMA_DENY);