Added basic timing, made features a part of character schema
This commit is contained in:
7
rpg-docs/Model/Campaign/Instance.js
Normal file
7
rpg-docs/Model/Campaign/Instance.js
Normal file
@@ -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);
|
||||||
8
rpg-docs/Model/Campaign/Party.js
Normal file
8
rpg-docs/Model/Campaign/Party.js
Normal file
@@ -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);
|
||||||
@@ -6,15 +6,38 @@ Schemas.Character = new SimpleSchema({
|
|||||||
attributes: { type: Schemas.Attributes },
|
attributes: { type: Schemas.Attributes },
|
||||||
skills: { type: Schemas.Skills },
|
skills: { type: Schemas.Skills },
|
||||||
vulerabilities: { type: Schemas.Vulnerabilities },
|
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 add permission stuff for owner, readers and writers
|
||||||
//TODO hit dice
|
//TODO hit dice
|
||||||
});
|
});
|
||||||
|
|
||||||
Characters.attachSchema(Schemas.Character);
|
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({
|
Characters.helpers({
|
||||||
attributeValue: function(attribute){
|
attributeValue: function(attribute){
|
||||||
if (attribute === undefined) return;
|
if (attribute === undefined) return;
|
||||||
@@ -121,53 +144,16 @@ Characters.helpers({
|
|||||||
return 10 + mod;
|
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(){
|
level: function(){
|
||||||
var xp = this.attributeValue(this.attributes.experience);
|
var xp = this.attributeValue(this.attributes.experience);
|
||||||
var xpTable = [0, 300, 900, 2700, 6500, 14000, 23000, 34000, 48000, 64000,
|
var xpTable = [0, 300, 900, 2700, 6500, 14000, 23000, 34000, 48000, 64000,
|
||||||
85000, 100000, 120000, 140000, 165000, 195000, 225000, 265000,
|
85000, 100000, 120000, 140000, 165000, 195000, 225000, 265000,
|
||||||
305000, 355000];
|
305000, 355000];
|
||||||
for(var i = 0, l = xpTable.length; i < l; i++){
|
_.each(xpTable, function(value, i){
|
||||||
if(xp < xpTable[i]){
|
if(xp < value){
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
return 20;
|
return 20;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
11
rpg-docs/Model/Character/SubSchemas/Features.js
Normal file
11
rpg-docs/Model/Character/SubSchemas/Features.js
Normal file
@@ -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},
|
||||||
|
})
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
Schemas.Strings = new SimpleSchema({
|
Schemas.Strings = new SimpleSchema({
|
||||||
name: { type: String, defaultValue: "" },
|
name: { type: String, defaultValue: "", optional: true },
|
||||||
alignment: { type: String, defaultValue: "" },
|
alignment: { type: String, defaultValue: "", optional: true },
|
||||||
gender: { type: String, defaultValue: "" },
|
gender: { type: String, defaultValue: "", optional: true },
|
||||||
race: { type: String, defaultValue: "" },
|
race: { type: String, defaultValue: "", optional: true },
|
||||||
description:{ type: String, defaultValue: "" },
|
description:{ type: String, defaultValue: "", optional: true },
|
||||||
personality:{ type: String, defaultValue: "" },
|
personality:{ type: String, defaultValue: "", optional: true },
|
||||||
ideals: { type: String, defaultValue: "" },
|
ideals: { type: String, defaultValue: "", optional: true },
|
||||||
bonds: { type: String, defaultValue: "" },
|
bonds: { type: String, defaultValue: "", optional: true },
|
||||||
flaws: { type: String, defaultValue: "" },
|
flaws: { type: String, defaultValue: "", optional: true },
|
||||||
backstory: { type: String, defaultValue: "" },
|
backstory: { type: String, defaultValue: "", optional: true },
|
||||||
notes: { type: String, defaultValue: "" },
|
notes: { type: String, defaultValue: "", optional: true },
|
||||||
});
|
});
|
||||||
@@ -32,8 +32,7 @@ Template.textField.events({
|
|||||||
var setter = {};
|
var setter = {};
|
||||||
setter["strings."+this.field] = text;
|
setter["strings."+this.field] = text;
|
||||||
Characters.update(this.character._id, {$set: setter}, function(error, result) {
|
Characters.update(this.character._id, {$set: setter}, function(error, result) {
|
||||||
console.log(error);
|
if(error) console.log(error);
|
||||||
console.log(result);
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
"click #textOutput": function(){
|
"click #textOutput": function(){
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
Schemas = {};
|
Schemas = {};
|
||||||
|
SimpleSchema.debug = true
|
||||||
11
rpg-docs/lib/functions/buffsToCharacter.js
Normal file
11
rpg-docs/lib/functions/buffsToCharacter.js
Normal file
@@ -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} } });
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
[[[[[ ~/workspace/rpg-docs ]]]]]
|
|
||||||
|
|
||||||
=> Started proxy.
|
|
||||||
=> Started MongoDB.
|
|
||||||
[34mI20141109-18:31:54.578(0)? [39m** You've set up some data subscriptions with Meteor.publish(), but
|
|
||||||
[34mI20141109-18:31:54.660(0)? [39m** you still have autopublish turned on. Because autopublish is still
|
|
||||||
[34mI20141109-18:31:54.660(0)? [39m** on, your Meteor.publish() calls won't have much effect. All data
|
|
||||||
[34mI20141109-18:31:54.660(0)? [39m** will still be sent to all clients.
|
|
||||||
[34mI20141109-18:31:54.660(0)? [39m**
|
|
||||||
[34mI20141109-18:31:54.661(0)? [39m** Turn off autopublish by removing the autopublish package:
|
|
||||||
[34mI20141109-18:31:54.661(0)? [39m**
|
|
||||||
[34mI20141109-18:31:54.661(0)? [39m** $ meteor remove autopublish
|
|
||||||
[34mI20141109-18:31:54.661(0)? [39m**
|
|
||||||
[34mI20141109-18:31:54.661(0)? [39m** .. and make sure you have Meteor.publish() and Meteor.subscribe() calls
|
|
||||||
[34mI20141109-18:31:54.661(0)? [39m** for each collection that you want clients to see.
|
|
||||||
[34mI20141109-18:31:54.662(0)? [39m
|
|
||||||
=> Started your app.
|
|
||||||
|
|
||||||
=> App running at: http://localhost:3000/
|
|
||||||
=> Client modified -- refreshing
|
|
||||||
Reference in New Issue
Block a user