From 0ead14d159eeb8e19d9d0931f376f6d2ea9880d0 Mon Sep 17 00:00:00 2001 From: Thaum Date: Thu, 13 Nov 2014 12:45:57 +0000 Subject: [PATCH] Added basic timing, made features a part of character schema --- rpg-docs/Model/Campaign/Instance.js | 7 ++ rpg-docs/Model/Campaign/Party.js | 8 ++ rpg-docs/Model/Character/Characters.js | 80 ++++++++----------- rpg-docs/Model/Character/Features.js | 9 --- .../Model/Character/SubSchemas/Features.js | 11 +++ .../Model/Character/SubSchemas/Strings.js | 22 ++--- .../views/character/textField/textField.js | 3 +- rpg-docs/lib/constants/Schemas.js | 3 +- rpg-docs/lib/functions/buffsToCharacter.js | 11 +++ rpg-docs/nohup.out | 20 ----- 10 files changed, 84 insertions(+), 90 deletions(-) create mode 100644 rpg-docs/Model/Campaign/Instance.js create mode 100644 rpg-docs/Model/Campaign/Party.js delete mode 100644 rpg-docs/Model/Character/Features.js create mode 100644 rpg-docs/Model/Character/SubSchemas/Features.js create mode 100644 rpg-docs/lib/functions/buffsToCharacter.js delete mode 100644 rpg-docs/nohup.out diff --git a/rpg-docs/Model/Campaign/Instance.js b/rpg-docs/Model/Campaign/Instance.js new file mode 100644 index 00000000..4f9caee8 --- /dev/null +++ b/rpg-docs/Model/Campaign/Instance.js @@ -0,0 +1,7 @@ +Instances = new Meteor.Collection("instances"); + +Schemas.Instance = new SimpleSchema({ + //an instance is a single flow of time all parties in an instance are in-sync time wise +}); + +Instances.attachSchema(Schemas.Instance); \ No newline at end of file diff --git a/rpg-docs/Model/Campaign/Party.js b/rpg-docs/Model/Campaign/Party.js new file mode 100644 index 00000000..e5aad4f3 --- /dev/null +++ b/rpg-docs/Model/Campaign/Party.js @@ -0,0 +1,8 @@ +Parties = new Meteor.Collection("parties"); + +Schemas.Party = new SimpleSchema({ + //each character/monster can only be in one party at a time + //each party can only be in a single instance at a time +}); + +Parties.attachSchema(Schemas.Party); \ No newline at end of file diff --git a/rpg-docs/Model/Character/Characters.js b/rpg-docs/Model/Character/Characters.js index e8ef9d4b..df8272ce 100644 --- a/rpg-docs/Model/Character/Characters.js +++ b/rpg-docs/Model/Character/Characters.js @@ -6,15 +6,38 @@ Schemas.Character = new SimpleSchema({ attributes: { type: Schemas.Attributes }, skills: { type: Schemas.Skills }, vulerabilities: { type: Schemas.Vulnerabilities }, - proficiencies: { type: Schemas.Proficiencies } - + proficiencies: { type: Schemas.Proficiencies }, + features: { type: [Schemas.Feature]}, + time: { type: Number, min: 0, decimal: true}, + initiativeOrder:{ type: Number, min: 0, max: 1, decimal: true} //TODO add permission stuff for owner, readers and writers //TODO hit dice }); Characters.attachSchema(Schemas.Character); -//functions and calculated values go here +//react to time changing +Characters.find({fields: {time: 1}}).observeChanges({ + changed: function(id, fields){ + var currentTime = fields.time; + console.log(id + "time changed to " + currentTime) + var features = Characters.findOne(id, { fields: {features: 1} }).features; + _.each(features, function(feature){ + //expired features, if no expiry time is set, this is always false + if(feature.expires >= currentTime){ + //remove buffs + pullBuffs(id, feature.buffs); + //disable feature + Characters.update( + {_id: id, "features._id": feature.id}, + {$set: {"features.$.enabled": false}} + ); + } + }); + } +}); + +//functions and calculated values Characters.helpers({ attributeValue: function(attribute){ if (attribute === undefined) return; @@ -47,7 +70,7 @@ Characters.helpers({ return value; }, - + proficiency: function(skill){ //return largest value in proficiency array var prof = 0; @@ -73,7 +96,7 @@ Characters.helpers({ //multiply proficiency bonus by largest value in proficiency array var prof = this.proficiency(skill); - + //add multiplied proficiency bonus to modifier mod += prof * this.attributeValue(this.attributes.proficiencyBonus); @@ -120,54 +143,17 @@ Characters.helpers({ var mod = +getMod(this.attributeValue(attribute)); return 10 + mod; }, - - pushEffects : function(effectName, effectsArray){ - throw "this function is not implemented correctly for buffs->effects" - //check that the arguments are of the right for - check(effectName, String); - check(effectsArray, [{ _id: String, stat: String, value: Number}]); - for(var i = 0; i < effectsArray.length; i++){ - var effect = effectsArray[i]; - - //check if the character exists with the field we are changing - if(pop(effect.stat, this) !== undefined){ - var newEffect = {}; - newEffect[effect.stat] = {_id: effect.id, name: effectName, value: effect.value}; - //update the field - Characters.update(this._id, {$push: newEffect}); - } - } - }, - - pullEffects : function(effectsArray){ - throw "this function is not implemented correctly for buffs->effects" - //check that the arguments are of the right form - check(effectsArray, [{ _id: String, stat: String, value: Number}]); - - for(var i = 0; i < effectsArray.length; i++){ - var effect = effectsArray[i]; - - //check if the character exists with the field we are changing - if(pop(effect.stat, this) !== undefined){ - var effectToPull = {}; - effectToPull[effect.stat] = {_id: effect.id}; - //update the field - Characters.update(this._id, {$pull: effectToPull}); - } - } - }, - level: function(){ var xp = this.attributeValue(this.attributes.experience); var xpTable = [0, 300, 900, 2700, 6500, 14000, 23000, 34000, 48000, 64000, - 85000, 100000, 120000, 140000, 165000, 195000, 225000, 265000, - 305000, 355000]; - for(var i = 0, l = xpTable.length; i < l; i++){ - if(xp < xpTable[i]){ + 85000, 100000, 120000, 140000, 165000, 195000, 225000, 265000, + 305000, 355000]; + _.each(xpTable, function(value, i){ + if(xp < value){ return i; } - } + }); return 20; } }); diff --git a/rpg-docs/Model/Character/Features.js b/rpg-docs/Model/Character/Features.js deleted file mode 100644 index 52303808..00000000 --- a/rpg-docs/Model/Character/Features.js +++ /dev/null @@ -1,9 +0,0 @@ -Features = new Meteor.Collection("features"); - -Feature = function(characterId){ - this.character = characterId; - this.name = "New Feature"; - this.description = ""; - this.effects = []; - this.enabled = false; -} \ No newline at end of file diff --git a/rpg-docs/Model/Character/SubSchemas/Features.js b/rpg-docs/Model/Character/SubSchemas/Features.js new file mode 100644 index 00000000..e6f059d4 --- /dev/null +++ b/rpg-docs/Model/Character/SubSchemas/Features.js @@ -0,0 +1,11 @@ +Schemas.Feature = new SimpleSchema({ + _id: {type: String, regEx: SimpleSchema.RegEx.Id}, + character: {type: String, regEx: SimpleSchema.RegEx.Id}, + name: {type: String}, + description:{type: String}, + buffs: {type: [Schemas.Buff], optional: true}, + enabled: {type: Boolean}, + expires: {type: Number, optional: true}, + duration: {type: Number, optional: true}, + uses: {type: Number, min: 0, optional: true}, +}) \ No newline at end of file diff --git a/rpg-docs/Model/Character/SubSchemas/Strings.js b/rpg-docs/Model/Character/SubSchemas/Strings.js index ad58247e..d62cfca0 100644 --- a/rpg-docs/Model/Character/SubSchemas/Strings.js +++ b/rpg-docs/Model/Character/SubSchemas/Strings.js @@ -1,13 +1,13 @@ Schemas.Strings = new SimpleSchema({ - name: { type: String, defaultValue: "" }, - alignment: { type: String, defaultValue: "" }, - gender: { type: String, defaultValue: "" }, - race: { type: String, defaultValue: "" }, - description:{ type: String, defaultValue: "" }, - personality:{ type: String, defaultValue: "" }, - ideals: { type: String, defaultValue: "" }, - bonds: { type: String, defaultValue: "" }, - flaws: { type: String, defaultValue: "" }, - backstory: { type: String, defaultValue: "" }, - notes: { type: String, defaultValue: "" }, + name: { type: String, defaultValue: "", optional: true }, + alignment: { type: String, defaultValue: "", optional: true }, + gender: { type: String, defaultValue: "", optional: true }, + race: { type: String, defaultValue: "", optional: true }, + description:{ type: String, defaultValue: "", optional: true }, + personality:{ type: String, defaultValue: "", optional: true }, + ideals: { type: String, defaultValue: "", optional: true }, + bonds: { type: String, defaultValue: "", optional: true }, + flaws: { type: String, defaultValue: "", optional: true }, + backstory: { type: String, defaultValue: "", optional: true }, + notes: { type: String, defaultValue: "", optional: true }, }); \ No newline at end of file diff --git a/rpg-docs/client/views/character/textField/textField.js b/rpg-docs/client/views/character/textField/textField.js index e91ffd11..bd696df5 100644 --- a/rpg-docs/client/views/character/textField/textField.js +++ b/rpg-docs/client/views/character/textField/textField.js @@ -32,8 +32,7 @@ Template.textField.events({ var setter = {}; setter["strings."+this.field] = text; Characters.update(this.character._id, {$set: setter}, function(error, result) { - console.log(error); - console.log(result); + if(error) console.log(error); }); }, "click #textOutput": function(){ diff --git a/rpg-docs/lib/constants/Schemas.js b/rpg-docs/lib/constants/Schemas.js index 33163227..68d83f0e 100644 --- a/rpg-docs/lib/constants/Schemas.js +++ b/rpg-docs/lib/constants/Schemas.js @@ -1 +1,2 @@ -Schemas = {}; \ No newline at end of file +Schemas = {}; +SimpleSchema.debug = true \ No newline at end of file diff --git a/rpg-docs/lib/functions/buffsToCharacter.js b/rpg-docs/lib/functions/buffsToCharacter.js new file mode 100644 index 00000000..f3bc785d --- /dev/null +++ b/rpg-docs/lib/functions/buffsToCharacter.js @@ -0,0 +1,11 @@ +pushBuffs = function(id, buffArray){ + _.each(buffArray, function(buff){ + Characters.update(id, {$push: {"buff.stat": buff.effect}}); + }); +}; + +pullBuffs = function(id, buffArray){ + _.each(buffArray, function(buff){ + Characters.update(id, {$pull: {"buff.stat": {_id: buff.effect._id} } }); + }); +}; \ No newline at end of file diff --git a/rpg-docs/nohup.out b/rpg-docs/nohup.out deleted file mode 100644 index f101dbc9..00000000 --- a/rpg-docs/nohup.out +++ /dev/null @@ -1,20 +0,0 @@ -[[[[[ ~/workspace/rpg-docs ]]]]] - -=> Started proxy. -=> Started MongoDB. -I20141109-18:31:54.578(0)? ** You've set up some data subscriptions with Meteor.publish(), but -I20141109-18:31:54.660(0)? ** you still have autopublish turned on. Because autopublish is still -I20141109-18:31:54.660(0)? ** on, your Meteor.publish() calls won't have much effect. All data -I20141109-18:31:54.660(0)? ** will still be sent to all clients. -I20141109-18:31:54.660(0)? ** -I20141109-18:31:54.661(0)? ** Turn off autopublish by removing the autopublish package: -I20141109-18:31:54.661(0)? ** -I20141109-18:31:54.661(0)? ** $ meteor remove autopublish -I20141109-18:31:54.661(0)? ** -I20141109-18:31:54.661(0)? ** .. and make sure you have Meteor.publish() and Meteor.subscribe() calls -I20141109-18:31:54.661(0)? ** for each collection that you want clients to see. -I20141109-18:31:54.662(0)?  -=> Started your app. - -=> App running at: http://localhost:3000/ -=> Client modified -- refreshing \ No newline at end of file