Implemented a javascript code style
This commit is contained in:
@@ -4,4 +4,4 @@ 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);
|
||||
Instances.attachSchema(Schemas.Instance);
|
||||
|
||||
@@ -5,4 +5,4 @@ Schemas.Party = new SimpleSchema({
|
||||
//each party can only be in a single instance at a time
|
||||
});
|
||||
|
||||
Parties.attachSchema(Schemas.Party);
|
||||
Parties.attachSchema(Schemas.Party);
|
||||
|
||||
@@ -5,29 +5,32 @@ Actions = new Mongo.Collection("actions");
|
||||
*/
|
||||
Schemas.Action = new SimpleSchema({
|
||||
charId: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
name: {
|
||||
type: String, trim: false
|
||||
type: String,
|
||||
trim: false,
|
||||
},
|
||||
description: {
|
||||
type: String, trim: false
|
||||
type: String,
|
||||
trim: false,
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
allowedValues: ["action, bonus, reaction, free"],
|
||||
defaultValue: "action"
|
||||
defaultValue: "action",
|
||||
},
|
||||
//the immediate impact of doing this action (eg. -1 rages)
|
||||
adjustments: {
|
||||
type: [Schemas.Adjustment], defaultValue: []
|
||||
}
|
||||
type: [Schemas.Adjustment],
|
||||
defaultValue: [],
|
||||
},
|
||||
});
|
||||
|
||||
Actions.attachSchema(Schemas.Action);
|
||||
|
||||
Actions.attachBehaviour('softRemovable');
|
||||
Actions.attachBehaviour("softRemovable");
|
||||
makeChild(Actions);
|
||||
|
||||
Actions.allow(CHARACTER_SUBSCHEMA_ALLOW);
|
||||
|
||||
@@ -5,62 +5,75 @@ Attacks = new Mongo.Collection("attacks");
|
||||
*/
|
||||
Schemas.Attack = new SimpleSchema({
|
||||
charId: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
defaultValue: "New Attack",
|
||||
trim: false
|
||||
defaultValue: "New Attack",
|
||||
trim: false,
|
||||
},
|
||||
details: {
|
||||
type: String,
|
||||
optional: true,
|
||||
trim: false
|
||||
optional: true,
|
||||
trim: false,
|
||||
},
|
||||
attackBonus: {
|
||||
type: String,
|
||||
defaultValue: "strengthMod + proficiencyBonus",
|
||||
optional: true,
|
||||
trim: false
|
||||
optional: true,
|
||||
trim: false,
|
||||
},
|
||||
damageBonus: {
|
||||
type: String,
|
||||
defaultValue: "strengthMod",
|
||||
optional: true,
|
||||
trim: false
|
||||
optional: true,
|
||||
trim: false,
|
||||
},
|
||||
damageDice: {
|
||||
type: String,
|
||||
optional: true,
|
||||
defaultValue: "1d8",
|
||||
allowedValues: DAMAGE_DICE
|
||||
allowedValues: DAMAGE_DICE,
|
||||
},
|
||||
damageType: {
|
||||
type: String,
|
||||
allowedValues: ["bludgeoning", "piercing", "slashing", "acid", "cold", "fire", "force", "lightning", "necrotic",
|
||||
"poison", "psychic", "radiant", "thunder"],
|
||||
defaultValue: "slashing"
|
||||
allowedValues: [
|
||||
"bludgeoning",
|
||||
"piercing",
|
||||
"slashing",
|
||||
"acid",
|
||||
"cold",
|
||||
"fire",
|
||||
"force",
|
||||
"lightning",
|
||||
"necrotic",
|
||||
"poison",
|
||||
"psychic",
|
||||
"radiant",
|
||||
"thunder",
|
||||
],
|
||||
defaultValue: "slashing",
|
||||
},
|
||||
//the id of the feature, buff or item that created this effect
|
||||
parent: {
|
||||
type: Schemas.Parent
|
||||
},
|
||||
color: {
|
||||
type: String,
|
||||
allowedValues: _.pluck(colorOptions, "key"),
|
||||
defaultValue: "q"
|
||||
type: String,
|
||||
allowedValues: _.pluck(colorOptions, "key"),
|
||||
defaultValue: "q",
|
||||
},
|
||||
enabled: {
|
||||
type: Boolean,
|
||||
defaultValue: true
|
||||
}
|
||||
defaultValue: true,
|
||||
},
|
||||
});
|
||||
|
||||
Attacks.attachSchema(Schemas.Attack);
|
||||
|
||||
Attacks.attachBehaviour('softRemovable');
|
||||
makeChild(Attacks, ['name', 'enabled']); //children of lots of things
|
||||
Attacks.attachBehaviour("softRemovable");
|
||||
makeChild(Attacks, ["name", "enabled"]); //children of lots of things
|
||||
|
||||
Attacks.allow(CHARACTER_SUBSCHEMA_ALLOW);
|
||||
Attacks.deny(CHARACTER_SUBSCHEMA_DENY);
|
||||
|
||||
@@ -7,21 +7,22 @@ Schemas.Buff = new SimpleSchema({
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
autoValue: function(){
|
||||
if(!this.isSet) return Random.id();
|
||||
}},
|
||||
if (!this.isSet) return Random.id();
|
||||
},
|
||||
},
|
||||
charId: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
//expiry time
|
||||
expiry: { type: Number, optional: true},
|
||||
duration: { type: Number }
|
||||
expiry: {type: Number, optional: true},
|
||||
duration: {type: Number},
|
||||
});
|
||||
|
||||
Buffs.attachSchema(Schemas.Buff);
|
||||
|
||||
Buffs.attachBehaviour('softRemovable');
|
||||
makeParent(Buffs, 'name'); //parents of effects and attacks
|
||||
Buffs.attachBehaviour("softRemovable");
|
||||
makeParent(Buffs, "name"); //parents of effects and attacks
|
||||
|
||||
Buffs.allow(CHARACTER_SUBSCHEMA_ALLOW);
|
||||
Buffs.deny(CHARACTER_SUBSCHEMA_DENY);
|
||||
|
||||
@@ -3,16 +3,16 @@ Characters = new Mongo.Collection("characters");
|
||||
|
||||
Schemas.Character = new SimpleSchema({
|
||||
//strings
|
||||
name: { type: String, defaultValue: "", trim: false},
|
||||
alignment: { type: String, defaultValue: "", trim: false},
|
||||
gender: { type: String, defaultValue: "", trim: false},
|
||||
race: { type: String, defaultValue: "", trim: false},
|
||||
description: { type: String, defaultValue: "", trim: false},
|
||||
personality: { type: String, defaultValue: "", trim: false},
|
||||
ideals: { type: String, defaultValue: "", trim: false},
|
||||
bonds: { type: String, defaultValue: "", trim: false},
|
||||
flaws: { type: String, defaultValue: "", trim: false},
|
||||
backstory: { type: String, defaultValue: "", trim: false},
|
||||
name: {type: String, defaultValue: "", trim: false},
|
||||
alignment: {type: String, defaultValue: "", trim: false},
|
||||
gender: {type: String, defaultValue: "", trim: false},
|
||||
race: {type: String, defaultValue: "", trim: false},
|
||||
description: {type: String, defaultValue: "", trim: false},
|
||||
personality: {type: String, defaultValue: "", trim: false},
|
||||
ideals: {type: String, defaultValue: "", trim: false},
|
||||
bonds: {type: String, defaultValue: "", trim: false},
|
||||
flaws: {type: String, defaultValue: "", trim: false},
|
||||
backstory: {type: String, defaultValue: "", trim: false},
|
||||
|
||||
//attributes
|
||||
//ability scores
|
||||
@@ -73,99 +73,100 @@ Schemas.Character = new SimpleSchema({
|
||||
slashingMultiplier: {type: Schemas.Attribute},
|
||||
thunderMultiplier: {type: Schemas.Attribute},
|
||||
|
||||
|
||||
//skills
|
||||
//saves
|
||||
strengthSave: {type: Schemas.Skill},
|
||||
"strengthSave.ability": { type: String, defaultValue: "strength" },
|
||||
"strengthSave.ability": {type: String, defaultValue: "strength"},
|
||||
|
||||
dexteritySave: {type: Schemas.Skill},
|
||||
"dexteritySave.ability": { type: String, defaultValue: "dexterity" },
|
||||
"dexteritySave.ability": {type: String, defaultValue: "dexterity"},
|
||||
|
||||
constitutionSave:{type: Schemas.Skill},
|
||||
"constitutionSave.ability": { type: String, defaultValue: "constitution" },
|
||||
"constitutionSave.ability": {type: String, defaultValue: "constitution"},
|
||||
|
||||
intelligenceSave:{type: Schemas.Skill},
|
||||
"intelligenceSave.ability": { type: String, defaultValue: "intelligence" },
|
||||
"intelligenceSave.ability": {type: String, defaultValue: "intelligence"},
|
||||
|
||||
wisdomSave: {type: Schemas.Skill},
|
||||
"wisdomSave.ability": { type: String, defaultValue: "wisdom" },
|
||||
"wisdomSave.ability": {type: String, defaultValue: "wisdom"},
|
||||
|
||||
charismaSave: {type: Schemas.Skill},
|
||||
"charismaSave.ability": { type: String, defaultValue: "charisma" },
|
||||
|
||||
"charismaSave.ability": {type: String, defaultValue: "charisma"},
|
||||
|
||||
//skill skills
|
||||
acrobatics: {type: Schemas.Skill},
|
||||
"acrobatics.ability": { type: String, defaultValue: "dexterity" },
|
||||
acrobatics: {type: Schemas.Skill},
|
||||
"acrobatics.ability": {type: String, defaultValue: "dexterity"},
|
||||
|
||||
animalHandling: {type: Schemas.Skill},
|
||||
"animalHandling.ability": { type: String, defaultValue: "wisdom" },
|
||||
animalHandling: {type: Schemas.Skill},
|
||||
"animalHandling.ability": {type: String, defaultValue: "wisdom"},
|
||||
|
||||
arcana: {type: Schemas.Skill},
|
||||
"arcana.ability": { type: String, defaultValue: "intelligence" },
|
||||
arcana: {type: Schemas.Skill},
|
||||
"arcana.ability": {type: String, defaultValue: "intelligence"},
|
||||
|
||||
athletics: {type: Schemas.Skill},
|
||||
"athletics.ability": { type: String, defaultValue: "strength" },
|
||||
athletics: {type: Schemas.Skill},
|
||||
"athletics.ability": {type: String, defaultValue: "strength"},
|
||||
|
||||
deception: {type: Schemas.Skill},
|
||||
"deception.ability": { type: String, defaultValue: "charisma" },
|
||||
deception: {type: Schemas.Skill},
|
||||
"deception.ability": {type: String, defaultValue: "charisma"},
|
||||
|
||||
history: {type: Schemas.Skill},
|
||||
"history.ability": { type: String, defaultValue: "intelligence" },
|
||||
history: {type: Schemas.Skill},
|
||||
"history.ability": {type: String, defaultValue: "intelligence"},
|
||||
|
||||
insight: {type: Schemas.Skill},
|
||||
"insight.ability": { type: String, defaultValue: "wisdom" },
|
||||
insight: {type: Schemas.Skill},
|
||||
"insight.ability": {type: String, defaultValue: "wisdom"},
|
||||
|
||||
intimidation: {type: Schemas.Skill},
|
||||
"intimidation.ability": { type: String, defaultValue: "charisma" },
|
||||
intimidation: {type: Schemas.Skill},
|
||||
"intimidation.ability": {type: String, defaultValue: "charisma"},
|
||||
|
||||
investigation: {type: Schemas.Skill},
|
||||
"investigation.ability": { type: String, defaultValue: "intelligence" },
|
||||
"investigation.ability": {type: String, defaultValue: "intelligence"},
|
||||
|
||||
medicine: {type: Schemas.Skill},
|
||||
"medicine.ability": { type: String, defaultValue: "wisdom" },
|
||||
"medicine.ability": {type: String, defaultValue: "wisdom"},
|
||||
|
||||
nature: {type: Schemas.Skill},
|
||||
"nature.ability": { type: String, defaultValue: "intelligence" },
|
||||
"nature.ability": {type: String, defaultValue: "intelligence"},
|
||||
|
||||
perception: {type: Schemas.Skill},
|
||||
"perception.ability": { type: String, defaultValue: "wisdom" },
|
||||
"perception.ability": {type: String, defaultValue: "wisdom"},
|
||||
|
||||
performance: {type: Schemas.Skill},
|
||||
"performance.ability": { type: String, defaultValue: "charisma" },
|
||||
"performance.ability": {type: String, defaultValue: "charisma"},
|
||||
|
||||
persuasion: {type: Schemas.Skill},
|
||||
"persuasion.ability": { type: String, defaultValue: "charisma" },
|
||||
persuasion: {type: Schemas.Skill},
|
||||
"persuasion.ability": {type: String, defaultValue: "charisma"},
|
||||
|
||||
religion: {type: Schemas.Skill},
|
||||
"religion.ability": { type: String, defaultValue: "intelligence" },
|
||||
religion: {type: Schemas.Skill},
|
||||
"religion.ability": {type: String, defaultValue: "intelligence"},
|
||||
|
||||
sleightOfHand: {type: Schemas.Skill},
|
||||
"sleightOfHand.ability": { type: String, defaultValue: "dexterity" },
|
||||
"sleightOfHand.ability": {type: String, defaultValue: "dexterity"},
|
||||
|
||||
stealth: {type: Schemas.Skill},
|
||||
"stealth.ability": { type: String, defaultValue: "dexterity" },
|
||||
"stealth.ability": {type: String, defaultValue: "dexterity"},
|
||||
|
||||
survival: {type: Schemas.Skill},
|
||||
"survival.ability": { type: String, defaultValue: "wisdom" },
|
||||
|
||||
"survival.ability": {type: String, defaultValue: "wisdom"},
|
||||
|
||||
//Mechanical Skills
|
||||
initiative: {type: Schemas.Skill},
|
||||
"initiative.ability": { type: String, defaultValue: "dexterity" },
|
||||
initiative: {type: Schemas.Skill},
|
||||
"initiative.ability": {type: String, defaultValue: "dexterity"},
|
||||
|
||||
dexterityArmor: {type: Schemas.Skill},
|
||||
"dexterityArmor.ability": { type: String, defaultValue: "dexterity" },
|
||||
"dexterityArmor.ability": {type: String, defaultValue: "dexterity"},
|
||||
|
||||
//mechanics
|
||||
deathSave: { type: Schemas.DeathSave },
|
||||
deathSave: {type: Schemas.DeathSave},
|
||||
|
||||
//permissions
|
||||
owner: { type: String, regEx: SimpleSchema.RegEx.Id },
|
||||
readers: { type: [String], regEx: SimpleSchema.RegEx.Id, defaultValue: [] },
|
||||
writers: { type: [String], regEx: SimpleSchema.RegEx.Id, defaultValue: [] },
|
||||
color: {type: String, allowedValues: _.pluck(colorOptions, "key"), defaultValue: "q"},
|
||||
owner: {type: String, regEx: SimpleSchema.RegEx.Id},
|
||||
readers: {type: [String], regEx: SimpleSchema.RegEx.Id, defaultValue: []},
|
||||
writers: {type: [String], regEx: SimpleSchema.RegEx.Id, defaultValue: []},
|
||||
color: {
|
||||
type: String,
|
||||
allowedValues: _.pluck(colorOptions, "key"),
|
||||
defaultValue: "q",
|
||||
},
|
||||
//TODO add per-character settings
|
||||
"settings.experiencesInc": {type: Number, defaultValue: 20}, //how many experiences to load at a time in XP table
|
||||
});
|
||||
@@ -174,9 +175,11 @@ Characters.attachSchema(Schemas.Character);
|
||||
|
||||
var attributeBase = function(charId, statName){
|
||||
check(statName, String);
|
||||
var effects = Effects.find({charId: charId, stat: statName, enabled: true}).fetch();
|
||||
var effects = Effects.find(
|
||||
{charId: charId, stat: statName, enabled: true}
|
||||
).fetch();
|
||||
effects = _.groupBy(effects, "operation");
|
||||
var value = _.contains(DAMAGE_MULTIPLIERS, statName)? 1 : 0;
|
||||
var value = _.contains(DAMAGE_MULTIPLIERS, statName) ? 1 : 0;
|
||||
|
||||
//start with the highest base value
|
||||
_.each(effects.base, function(effect){
|
||||
@@ -199,13 +202,13 @@ var attributeBase = function(charId, statName){
|
||||
//ensure value is >= all mins
|
||||
_.each(effects.min, function(effect){
|
||||
var min = evaluateEffect(charId, effect);
|
||||
value = value > min? value : min;
|
||||
value = value > min ? value : min;
|
||||
});
|
||||
|
||||
//ensure value is <= all maxes
|
||||
_.each(effects.max, function(effect){
|
||||
var max = evaluateEffect(charId, effect);
|
||||
value = value < max? value : max;
|
||||
value = value < max ? value : max;
|
||||
});
|
||||
return value;
|
||||
};
|
||||
@@ -221,16 +224,24 @@ Characters.helpers({
|
||||
fieldSelector[fieldName] = 1;
|
||||
var char = Characters.findOne(this._id, {fields: fieldSelector});
|
||||
var field = char[fieldName];
|
||||
if(field === undefined){
|
||||
throw new Meteor.Error("getField failed",
|
||||
"getField could not find field " + fieldName + " in character "+ char._id);
|
||||
if (field === undefined){
|
||||
throw new Meteor.Error(
|
||||
"getField failed",
|
||||
"getField could not find field " +
|
||||
fieldName +
|
||||
" in character " +
|
||||
char._id
|
||||
);
|
||||
}
|
||||
return field;
|
||||
},
|
||||
//returns the value of a field
|
||||
fieldValue : function(fieldName){
|
||||
if(!Schemas.Character.schema(fieldName)){
|
||||
throw new Meteor.Error("Field not found", "Character's schema does not contain a field called: " + fieldName);
|
||||
if (!Schemas.Character.schema(fieldName)){
|
||||
throw new Meteor.Error(
|
||||
"Field not found",
|
||||
"Character's schema does not contain a field called: " + fieldName
|
||||
);
|
||||
}
|
||||
//duck typing to get the right value function
|
||||
//.ability implies skill
|
||||
@@ -277,7 +288,9 @@ Characters.helpers({
|
||||
mod += prof * this.attributeValue("proficiencyBonus");
|
||||
|
||||
//apply all effects
|
||||
var rawEffects = Effects.find({charId: charId, stat: skillName, enabled: true}).fetch();
|
||||
var rawEffects = Effects.find(
|
||||
{charId: charId, stat: skillName, enabled: true}
|
||||
).fetch();
|
||||
var effects = _.groupBy(rawEffects, "operation");
|
||||
_.forEach(effects.add, function(effect){
|
||||
mod += evaluateEffect(charId, effect);
|
||||
@@ -287,11 +300,11 @@ Characters.helpers({
|
||||
});
|
||||
_.forEach(effects.min, function(effect){
|
||||
var min = evaluateEffect(charId, effect);
|
||||
mod = mod > min? mod : min;
|
||||
mod = mod > min ? mod : min;
|
||||
});
|
||||
_.forEach(effects.max, function(effect){
|
||||
var max = evaluateEffect(charId, effect);
|
||||
mod = mod < max? mod : max;
|
||||
mod = mod < max ? mod : max;
|
||||
});
|
||||
return signedString(mod);
|
||||
}),
|
||||
@@ -300,7 +313,9 @@ Characters.helpers({
|
||||
var charId = this._id;
|
||||
//return largest value in proficiency array
|
||||
var prof = 0;
|
||||
Proficiencies.find({charId: charId, name: skillName, enabled: true}).forEach(function(proficiency){
|
||||
Proficiencies.find(
|
||||
{charId: charId, name: skillName, enabled: true}
|
||||
).forEach(function(proficiency){
|
||||
var newProf = proficiency.value;
|
||||
if (newProf > prof){
|
||||
prof = newProf;
|
||||
@@ -316,7 +331,9 @@ Characters.helpers({
|
||||
var charId = this._id;
|
||||
var mod = +this.skillMod(skillName);
|
||||
var value = 10 + mod;
|
||||
Effects.find({charId: charId, stat: skillName, enabled: true, operation: "passiveAdd"}).forEach(function(effect){
|
||||
Effects.find(
|
||||
{charId: charId, stat: skillName, enabled: true, operation: "passiveAdd"}
|
||||
).forEach(function(effect){
|
||||
value += evaluateEffect(charId, effect);
|
||||
});
|
||||
return value;
|
||||
@@ -325,10 +342,14 @@ Characters.helpers({
|
||||
|
||||
advantage: function(skillName){
|
||||
var charId = this._id;
|
||||
var advantage = Effects.find({charId: charId, stat: skillName, enabled: true, operation: "advantage"}).count();
|
||||
var disadvantage = Effects.find({charId: charId, stat: skillName, enabled: true, operation: "disadvantage"}).count();
|
||||
if(advantage && !disadvantage) return 1;
|
||||
if(disadvantage && !advantage) return -1;
|
||||
var advantage = Effects.find(
|
||||
{charId: charId, stat: skillName, enabled: true, operation: "advantage"}
|
||||
).count();
|
||||
var disadvantage = Effects.find(
|
||||
{charId: charId, stat: skillName, enabled: true, operation: "disadvantage"}
|
||||
).count();
|
||||
if (advantage && !disadvantage) return 1;
|
||||
if (disadvantage && !advantage) return -1;
|
||||
return 0;
|
||||
},
|
||||
|
||||
@@ -343,15 +364,12 @@ Characters.helpers({
|
||||
|
||||
xpLevel: function(){
|
||||
var xp = this.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; i < 19; i++){
|
||||
if(xp < xpTable[i]){
|
||||
for (var i = 0; i < 19; i++){
|
||||
if (xp < XP_TABLE[i]){
|
||||
return i;
|
||||
}
|
||||
};
|
||||
if(xp > 355000) return 20;
|
||||
}
|
||||
if (xp > 355000) return 20;
|
||||
return 0;
|
||||
},
|
||||
|
||||
@@ -359,22 +377,25 @@ Characters.helpers({
|
||||
var level = 0;
|
||||
Classes.find({charId: this._id}).forEach(function(cls){
|
||||
level += cls.level;
|
||||
})
|
||||
});
|
||||
return level;
|
||||
},
|
||||
|
||||
experience: function(){
|
||||
var xp = 0;
|
||||
Experiences.find({charId: this._id}, {fields: {value: 1}}).forEach(function(e){
|
||||
Experiences.find(
|
||||
{charId: this._id},
|
||||
{fields: {value: 1}}
|
||||
).forEach(function(e){
|
||||
xp += e.value;
|
||||
})
|
||||
});
|
||||
return xp;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
//clean up all data related to that character before removing it
|
||||
Characters.after.remove(function (userId, character) {
|
||||
if(Meteor.isServer){
|
||||
Characters.after.remove(function(userId, character) {
|
||||
if (Meteor.isServer){
|
||||
Actions .remove({charId: character._id});
|
||||
Attacks .remove({charId: character._id});
|
||||
Buffs .remove({charId: character._id});
|
||||
@@ -391,25 +412,25 @@ Characters.after.remove(function (userId, character) {
|
||||
});
|
||||
|
||||
Characters.allow({
|
||||
insert: function (userId, doc) {
|
||||
insert: function(userId, doc) {
|
||||
// the user must be logged in, and the document must be owned by the user
|
||||
return (userId && doc.owner === userId);
|
||||
},
|
||||
update: function (userId, doc, fields, modifier) {
|
||||
update: function(userId, doc, fields, modifier) {
|
||||
// can only change documents you have write access to
|
||||
return doc.owner === userId ||
|
||||
_.contains(doc.writers, userId);
|
||||
},
|
||||
remove: function (userId, doc) {
|
||||
remove: function(userId, doc) {
|
||||
// can only remove your own documents
|
||||
return doc.owner === userId;
|
||||
},
|
||||
fetch: ["owner", "writers"]
|
||||
fetch: ["owner", "writers"],
|
||||
});
|
||||
|
||||
Characters.deny({
|
||||
update: function (userId, docs, fields, modifier) {
|
||||
update: function(userId, docs, fields, modifier) {
|
||||
// can't change owners
|
||||
return _.contains(fields, 'owner');
|
||||
return _.contains(fields, "owner");
|
||||
}
|
||||
});
|
||||
|
||||
@@ -8,21 +8,25 @@ Schemas.Class = new SimpleSchema({
|
||||
type: Date,
|
||||
autoValue: function() {
|
||||
if (this.isInsert) {
|
||||
return new Date;
|
||||
return new Date();
|
||||
} else if (this.isUpsert) {
|
||||
return {$setOnInsert: new Date};
|
||||
return {$setOnInsert: new Date()};
|
||||
} else {
|
||||
this.unset();
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
color: {
|
||||
type: String,
|
||||
allowedValues: _.pluck(colorOptions, "key"),
|
||||
defaultValue: "q",
|
||||
},
|
||||
color: {type: String, allowedValues: _.pluck(colorOptions, "key"), defaultValue: "q"}
|
||||
});
|
||||
|
||||
Classes.attachSchema(Schemas.Class);
|
||||
|
||||
Classes.attachBehaviour('softRemovable');
|
||||
makeParent(Classes, 'name'); //parents of effects and attacks
|
||||
Classes.attachBehaviour("softRemovable");
|
||||
makeParent(Classes, "name"); //parents of effects and attacks
|
||||
|
||||
Classes.allow(CHARACTER_SUBSCHEMA_ALLOW);
|
||||
Classes.deny(CHARACTER_SUBSCHEMA_DENY);
|
||||
|
||||
@@ -7,27 +7,39 @@ Effects = new Mongo.Collection("effects");
|
||||
Schemas.Effect = new SimpleSchema({
|
||||
charId: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
optional: true, //TODO make necessary if there is no owner
|
||||
trim: false
|
||||
trim: false,
|
||||
},
|
||||
operation: {
|
||||
type: String,
|
||||
defaultValue: "add",
|
||||
allowedValues: ["base", "proficiency","add","mul","min","max","advantage","disadvantage","passiveAdd","fail","conditional"]
|
||||
allowedValues: [
|
||||
"base",
|
||||
"proficiency",
|
||||
"add",
|
||||
"mul",
|
||||
"min",
|
||||
"max",
|
||||
"advantage",
|
||||
"disadvantage",
|
||||
"passiveAdd",
|
||||
"fail",
|
||||
"conditional",
|
||||
],
|
||||
},
|
||||
value: {
|
||||
type: Number,
|
||||
decimal: true,
|
||||
optional: true
|
||||
optional: true,
|
||||
},
|
||||
calculation: {
|
||||
type: String,
|
||||
optional: true,
|
||||
trim: false
|
||||
trim: false,
|
||||
},
|
||||
//the thing that created this effect
|
||||
parent: {
|
||||
@@ -36,17 +48,17 @@ Schemas.Effect = new SimpleSchema({
|
||||
//which stat the effect is applied to
|
||||
stat: {
|
||||
type: String,
|
||||
optional: true
|
||||
optional: true,
|
||||
},
|
||||
enabled: {
|
||||
type: Boolean,
|
||||
defaultValue: true
|
||||
}
|
||||
defaultValue: true,
|
||||
},
|
||||
});
|
||||
|
||||
Effects.attachSchema(Schemas.Effect);
|
||||
|
||||
if(Meteor.isServer) Characters.after.insert(function (userId, char) {
|
||||
if (Meteor.isServer) Characters.after.insert(function(userId, char) {
|
||||
Effects.insert({
|
||||
charId: char._id,
|
||||
type: "inate",
|
||||
@@ -56,8 +68,8 @@ if(Meteor.isServer) Characters.after.insert(function (userId, char) {
|
||||
calculation: "level * constitutionMod",
|
||||
parent: {
|
||||
id: char._id,
|
||||
collection: "Characters"
|
||||
}
|
||||
collection: "Characters",
|
||||
},
|
||||
});
|
||||
Effects.insert({
|
||||
charId: char._id,
|
||||
@@ -68,8 +80,8 @@ if(Meteor.isServer) Characters.after.insert(function (userId, char) {
|
||||
calculation: "floor(level / 4 + 1.75)",
|
||||
parent: {
|
||||
id: char._id,
|
||||
collection: "Characters"
|
||||
}
|
||||
collection: "Characters",
|
||||
},
|
||||
});
|
||||
Effects.insert({
|
||||
charId: char._id,
|
||||
@@ -80,8 +92,8 @@ if(Meteor.isServer) Characters.after.insert(function (userId, char) {
|
||||
calculation: "dexterityArmor",
|
||||
parent: {
|
||||
id: char._id,
|
||||
collection: "Characters"
|
||||
}
|
||||
collection: "Characters",
|
||||
},
|
||||
});
|
||||
Effects.insert({
|
||||
charId: char._id,
|
||||
@@ -92,12 +104,12 @@ if(Meteor.isServer) Characters.after.insert(function (userId, char) {
|
||||
value: 10,
|
||||
parent: {
|
||||
id: char._id,
|
||||
collection: "Characters"
|
||||
}
|
||||
collection: "Characters",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
Effects.attachBehaviour('softRemovable');
|
||||
Effects.attachBehaviour("softRemovable");
|
||||
makeChild(Effects, ["enabled"]); //children of lots of things
|
||||
|
||||
Effects.allow(CHARACTER_SUBSCHEMA_ALLOW);
|
||||
|
||||
@@ -9,19 +9,19 @@ Schemas.Experience = new SimpleSchema({
|
||||
type: Date,
|
||||
autoValue: function() {
|
||||
if (this.isInsert) {
|
||||
return new Date;
|
||||
return new Date();
|
||||
} else if (this.isUpsert) {
|
||||
return {$setOnInsert: new Date};
|
||||
return {$setOnInsert: new Date()};
|
||||
} else {
|
||||
this.unset();
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Experiences.attachSchema(Schemas.Experience);
|
||||
|
||||
Experiences.attachBehaviour('softRemovable');
|
||||
Experiences.attachBehaviour("softRemovable");
|
||||
|
||||
Experiences.allow(CHARACTER_SUBSCHEMA_ALLOW);
|
||||
Experiences.deny(CHARACTER_SUBSCHEMA_DENY);
|
||||
|
||||
@@ -6,10 +6,17 @@ Schemas.Feature = new SimpleSchema({
|
||||
description: {type: String, optional: true, trim: false},
|
||||
uses: {type: String, optional: true, trim: false},
|
||||
used: {type: Number, defaultValue: 0},
|
||||
reset: {type: String, allowedValues: ["manual", "longRest", "shortRest"], defaultValue: "manual"},
|
||||
reset: {
|
||||
type: String,
|
||||
allowedValues: ["manual", "longRest", "shortRest"],
|
||||
defaultValue: "manual",
|
||||
},
|
||||
enabled: {type: Boolean, defaultValue: true},
|
||||
alwaysEnabled:{type: Boolean, defaultValue: true},
|
||||
color: {type: String, allowedValues: _.pluck(colorOptions, "key"), defaultValue: "q"}
|
||||
color: {type: String,
|
||||
allowedValues: _.pluck(colorOptions, "key"),
|
||||
defaultValue: "q",
|
||||
},
|
||||
});
|
||||
|
||||
Features.attachSchema(Schemas.Feature);
|
||||
@@ -20,11 +27,11 @@ Features.helpers({
|
||||
},
|
||||
usesValue: function(){
|
||||
return evaluate(this.charId, this.uses);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Features.attachBehaviour('softRemovable');
|
||||
makeParent(Features, ['name', 'enabled']); //parents of effects and attacks
|
||||
Features.attachBehaviour("softRemovable");
|
||||
makeParent(Features, ["name", "enabled"]); //parents of effects and attacks
|
||||
|
||||
Features.allow(CHARACTER_SUBSCHEMA_ALLOW);
|
||||
Features.deny(CHARACTER_SUBSCHEMA_DENY);
|
||||
|
||||
@@ -4,12 +4,16 @@ Schemas.Note = new SimpleSchema({
|
||||
charId: {type: String, regEx: SimpleSchema.RegEx.Id},
|
||||
name: {type: String, trim: false},
|
||||
description: {type: String, optional: true, trim: false},
|
||||
color: {type: String, allowedValues: _.pluck(colorOptions, "key"), defaultValue: "q"}
|
||||
color: {
|
||||
type: String,
|
||||
allowedValues:_.pluck(colorOptions, "key"),
|
||||
defaultValue: "q",
|
||||
},
|
||||
});
|
||||
|
||||
Notes.attachSchema(Schemas.Note);
|
||||
|
||||
Notes.attachBehaviour('softRemovable');
|
||||
Notes.attachBehaviour("softRemovable");
|
||||
|
||||
Notes.allow(CHARACTER_SUBSCHEMA_ALLOW);
|
||||
Notes.deny(CHARACTER_SUBSCHEMA_DENY);
|
||||
|
||||
@@ -3,7 +3,7 @@ Proficiencies = new Mongo.Collection("proficiencies");
|
||||
Schemas.Proficiency = new SimpleSchema({
|
||||
charId: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
@@ -24,12 +24,12 @@ Schemas.Proficiency = new SimpleSchema({
|
||||
enabled: {
|
||||
type: Boolean,
|
||||
defaultValue: true,
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Proficiencies.attachSchema(Schemas.Proficiency);
|
||||
|
||||
Proficiencies.attachBehaviour('softRemovable');
|
||||
Proficiencies.attachBehaviour("softRemovable");
|
||||
makeChild(Proficiencies);
|
||||
|
||||
Proficiencies.allow(CHARACTER_SUBSCHEMA_ALLOW);
|
||||
|
||||
@@ -7,7 +7,11 @@ Schemas.SpellLists = new SimpleSchema({
|
||||
saveDC: {type: String, optional: true, trim: false},
|
||||
attackBonus: {type: String, optional: true, trim: false},
|
||||
maxPrepared: {type: String, optional: true, trim: false},
|
||||
color: {type: String, allowedValues: _.pluck(colorOptions, "key"), defaultValue: "q"},
|
||||
color: {
|
||||
type: String,
|
||||
allowedValues: _.pluck(colorOptions, "key"),
|
||||
defaultValue: "q",
|
||||
},
|
||||
"settings.showUnprepared": {type: Boolean, defaultValue: true},
|
||||
});
|
||||
|
||||
@@ -16,14 +20,17 @@ SpellLists.attachSchema(Schemas.SpellLists);
|
||||
SpellLists.helpers({
|
||||
numPrepared: function(){
|
||||
var num = 0;
|
||||
Spells.find({charId: this.charId, listId: this._id, prepared: 1}, {fields: {prepareCost: 1}}).forEach(function(spell){
|
||||
Spells.find(
|
||||
{charId: this.charId, listId: this._id, prepared: 1},
|
||||
{fields: {prepareCost: 1}}
|
||||
).forEach(function(spell){
|
||||
num += spell.prepareCost;
|
||||
});
|
||||
return num;
|
||||
}
|
||||
});
|
||||
|
||||
SpellLists.attachBehaviour('softRemovable');
|
||||
SpellLists.attachBehaviour("softRemovable");
|
||||
makeParent(SpellLists); //parents of spells
|
||||
|
||||
SpellLists.allow(CHARACTER_SUBSCHEMA_ALLOW);
|
||||
|
||||
@@ -2,25 +2,65 @@ Spells = new Mongo.Collection("spells");
|
||||
|
||||
Schemas.Spell = new SimpleSchema({
|
||||
charId: {type: String, regEx: SimpleSchema.RegEx.Id},
|
||||
prepared: {type: String, defaultValue: "prepared", allowedValues: ["prepared","unprepared","always"]},
|
||||
name: {type: String, trim: false, defaultValue: "New Spell"},
|
||||
description: {type: String, optional: true, trim: false},
|
||||
castingTime: {type: String, optional: true, defaultValue: "action", trim: false},
|
||||
range: {type: String, optional: true, trim: false},
|
||||
duration: {type: String, optional: true, trim: false, defaultValue: "Instantaneous"},
|
||||
"components.verbal": {type: Boolean, defaultValue: false},
|
||||
"components.somatic": {type: Boolean, defaultValue: false},
|
||||
"components.material": {type: String, optional: true},
|
||||
prepared: {
|
||||
type: String,
|
||||
defaultValue: "prepared",
|
||||
allowedValues: ["prepared", "unprepared", "always"],
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
trim: false,
|
||||
defaultValue: "New Spell",
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
optional: true,
|
||||
trim: false,
|
||||
},
|
||||
castingTime: {
|
||||
type: String,
|
||||
optional: true,
|
||||
defaultValue: "action",
|
||||
trim: false,
|
||||
},
|
||||
range: {
|
||||
type: String,
|
||||
optional: true,
|
||||
trim: false,
|
||||
},
|
||||
duration: {
|
||||
type: String,
|
||||
optional: true,
|
||||
trim: false,
|
||||
defaultValue: "Instantaneous",
|
||||
},
|
||||
"components.verbal": {type: Boolean, defaultValue: false},
|
||||
"components.somatic": {type: Boolean, defaultValue: false},
|
||||
"components.concentration": {type: Boolean, defaultValue: false},
|
||||
ritual: {type: Boolean, defaultValue: false},
|
||||
level: {type: Number, defaultValue: 1},
|
||||
school: {type: String, defaultValue: "Abjuration", allowedValues: magicSchools},
|
||||
color: {type: String, allowedValues: _.pluck(colorOptions, "key"), defaultValue: "q"}
|
||||
"components.material": {type: String, optional: true},
|
||||
ritual: {
|
||||
type: Boolean,
|
||||
defaultValue: false,
|
||||
},
|
||||
level: {
|
||||
type: Number,
|
||||
defaultValue: 1,
|
||||
},
|
||||
school: {
|
||||
type: String,
|
||||
defaultValue: "Abjuration",
|
||||
allowedValues: magicSchools,
|
||||
},
|
||||
color: {
|
||||
type: String,
|
||||
allowedValues: _.pluck(colorOptions, "key"),
|
||||
defaultValue: "q",
|
||||
},
|
||||
});
|
||||
|
||||
Spells.attachSchema(Schemas.Spell);
|
||||
|
||||
Spells.attachBehaviour('softRemovable');
|
||||
Spells.attachBehaviour("softRemovable");
|
||||
makeChild(Spells); //children of spell lists
|
||||
|
||||
Spells.allow(CHARACTER_SUBSCHEMA_ALLOW);
|
||||
|
||||
@@ -5,21 +5,21 @@
|
||||
Schemas.Adjustment = new SimpleSchema({
|
||||
name: {
|
||||
type: String,
|
||||
optional: true
|
||||
optional: true,
|
||||
},
|
||||
//which stat the adjustment is applied to
|
||||
stat: {
|
||||
type: String,
|
||||
optional: true
|
||||
optional: true,
|
||||
},
|
||||
//the value added to the stat
|
||||
value: {
|
||||
type: Number,
|
||||
decimal: true,
|
||||
optional: true
|
||||
optional: true,
|
||||
},
|
||||
calculation: {
|
||||
type: String,
|
||||
optional: true
|
||||
}
|
||||
optional: true,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -3,11 +3,11 @@ Schemas.Attribute = new SimpleSchema({
|
||||
//should be zero after reset
|
||||
adjustment: {
|
||||
type: Number,
|
||||
defaultValue: 0
|
||||
defaultValue: 0,
|
||||
},
|
||||
reset: {
|
||||
type: String,
|
||||
defaultValue: "longRest",
|
||||
allowedValues: ["longRest", "shortRest"]
|
||||
}
|
||||
allowedValues: ["longRest", "shortRest"],
|
||||
},
|
||||
});
|
||||
|
||||
@@ -3,20 +3,20 @@ Schemas.DeathSave = new SimpleSchema({
|
||||
type: Number,
|
||||
min: 0,
|
||||
max: 3,
|
||||
defaultValue: 0
|
||||
defaultValue: 0,
|
||||
},
|
||||
fail: {
|
||||
type: Number,
|
||||
min: 0,
|
||||
max: 3,
|
||||
defaultValue: 0
|
||||
defaultValue: 0,
|
||||
},
|
||||
canDeathSave: {
|
||||
type: Boolean,
|
||||
defaultValue: true
|
||||
defaultValue: true,
|
||||
},
|
||||
stable: {
|
||||
type: Boolean,
|
||||
defaultValue: false
|
||||
}
|
||||
defaultValue: false,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Schemas.Skill = new SimpleSchema({
|
||||
//attribute name that this skill used as base mod for roll
|
||||
ability: { type: String, defaultValue: "" },
|
||||
ability: {type: String, defaultValue: ""},
|
||||
});
|
||||
|
||||
@@ -16,7 +16,7 @@ Schemas.TemporaryHitPoints = new SimpleSchema({
|
||||
} else {
|
||||
this.unset();
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -29,11 +29,13 @@ TemporaryHitPoints.helpers({
|
||||
});
|
||||
|
||||
//remove the temporary hit points when they hit zero
|
||||
TemporaryHitPoints.after.update(function (userId, thp, fieldNames, modifier, options) {
|
||||
if(thp.used >= thp.maximum && thp.deleteOnZero){
|
||||
TemporaryHitPoints.remove(thp._id);
|
||||
}
|
||||
}, {fetchPrevious: false});
|
||||
TemporaryHitPoints.after.update(
|
||||
function(userId, thp, fieldNames, modifier, options){
|
||||
if (thp.used >= thp.maximum && thp.deleteOnZero){
|
||||
TemporaryHitPoints.remove(thp._id);
|
||||
}
|
||||
}, {fetchPrevious: false}
|
||||
);
|
||||
|
||||
TemporaryHitPoints.allow(CHARACTER_SUBSCHEMA_ALLOW);
|
||||
TemporaryHitPoints.deny(CHARACTER_SUBSCHEMA_DENY);
|
||||
|
||||
@@ -2,13 +2,17 @@
|
||||
Containers = new Mongo.Collection("containers");
|
||||
|
||||
Schemas.Container = new SimpleSchema({
|
||||
name: { type: String, trim: false },
|
||||
charId: { type: String, regEx: SimpleSchema.RegEx.Id},
|
||||
isCarried: { type: Boolean },
|
||||
name: {type: String, trim: false},
|
||||
charId: {type: String, regEx: SimpleSchema.RegEx.Id},
|
||||
isCarried: {type: Boolean},
|
||||
weight: {type: Number, min: 0, defaultValue: 0, decimal: true},
|
||||
value: {type: Number, min: 0, defaultValue: 0, decimal: true},
|
||||
description:{type: String, optional: true, trim: false},
|
||||
color: {type: String, allowedValues: _.pluck(colorOptions, "key"), defaultValue: "q"}
|
||||
color: {
|
||||
type: String,
|
||||
allowedValues: _.pluck(colorOptions, "key"),
|
||||
defaultValue: "q",
|
||||
},
|
||||
});
|
||||
|
||||
Containers.attachSchema(Schemas.Container);
|
||||
@@ -16,7 +20,10 @@ Containers.attachSchema(Schemas.Container);
|
||||
Containers.helpers({
|
||||
contentsValue: function(){
|
||||
var value = 0;
|
||||
Items.find({"parent.id": this._id}, {fields: {quantity: 1, value: 1}}).forEach(function(item){
|
||||
Items.find(
|
||||
{"parent.id": this._id},
|
||||
{fields: {quantity: 1, value: 1}}
|
||||
).forEach(function(item){
|
||||
value += item.totalValue();
|
||||
});
|
||||
return value;
|
||||
@@ -26,7 +33,10 @@ Containers.helpers({
|
||||
},
|
||||
contentsWeight: function(){
|
||||
var weight = 0;
|
||||
Items.find({"parent.id": this._id}, {fields: {quantity: 1, weight: 1}}).forEach(function(item){
|
||||
Items.find(
|
||||
{"parent.id": this._id},
|
||||
{fields: {quantity: 1, weight: 1}}
|
||||
).forEach(function(item){
|
||||
weight += item.totalWeight();
|
||||
});
|
||||
return weight;
|
||||
@@ -35,12 +45,12 @@ Containers.helpers({
|
||||
return this.contentsWeight() + this.weight;
|
||||
},
|
||||
moveToCharacter: function(characterId){
|
||||
if(this.charId === characterId) return;
|
||||
if (this.charId === characterId) return;
|
||||
Items.update(this._id, {$set: {charId: characterId}});
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Containers.attachBehaviour('softRemovable');
|
||||
Containers.attachBehaviour("softRemovable");
|
||||
makeParent(Containers); //parents of items
|
||||
|
||||
Containers.allow(CHARACTER_SUBSCHEMA_ALLOW);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Items = new Mongo.Collection('items');
|
||||
Items = new Mongo.Collection("items");
|
||||
|
||||
Schemas.Item = new SimpleSchema({
|
||||
name: {type: String, defaultValue: "New Item", trim: false},
|
||||
@@ -10,7 +10,11 @@ Schemas.Item = new SimpleSchema({
|
||||
value: {type: Number, min: 0, defaultValue: 0, decimal: true},
|
||||
enabled: {type: Boolean, defaultValue: false},
|
||||
requiresAttunement: {type: Boolean, defaultValue: false},
|
||||
color: {type: String, allowedValues: _.pluck(colorOptions, "key"), defaultValue: "q"}
|
||||
color: {
|
||||
type: String,
|
||||
allowedValues: _.pluck(colorOptions, "key"),
|
||||
defaultValue: "q",
|
||||
},
|
||||
});
|
||||
|
||||
Items.attachSchema(Schemas.Item);
|
||||
@@ -23,40 +27,77 @@ Items.helpers({
|
||||
return this.weight * this.quantity;
|
||||
},
|
||||
pluralName: function(){
|
||||
if(this.plural && this.quantity !== 1){
|
||||
if (this.plural && this.quantity !== 1){
|
||||
return this.plural;
|
||||
} else{
|
||||
} else {
|
||||
return this.name;
|
||||
}
|
||||
},
|
||||
equip: function(characterId){
|
||||
var charId = characterId || this.charId;
|
||||
if(!charId || ! Characters.findOne(charId)) throw "Invalid character";
|
||||
if(this.parent.collection === "Characters" && this.parent.id === charId && this.enabled) return;
|
||||
Items.update(this._id, {$set: {"parent.collection": "Characters", "parent.id": charId, enabled: true}});
|
||||
if (!charId || !Characters.findOne(charId)) throw "Invalid character";
|
||||
if (this.parent.collection === "Characters" &&
|
||||
this.parent.id === charId &&
|
||||
this.enabled) {
|
||||
return;
|
||||
}
|
||||
Items.update(
|
||||
this._id,
|
||||
{$set: {
|
||||
"parent.collection": "Characters",
|
||||
"parent.id": charId,
|
||||
enabled: true,
|
||||
}}
|
||||
);
|
||||
},
|
||||
unequip: function(){
|
||||
if(!this.enabled) return;
|
||||
if (!this.enabled) return;
|
||||
Items.update(this._id, {$set: {enabled: false}});
|
||||
},
|
||||
moveToContainer: function(containerId){
|
||||
if( !containerId || !Containers.findOne(containerId) ) throw "Invalid container";
|
||||
if(this.parent.collection === "Containers" && this.parent.id === containerId && !this.enabled) return;
|
||||
Items.update(this._id, {$set: {"parent.collection": "Containers", "parent.id": containerId, enabled: false}});
|
||||
if (!containerId || !Containers.findOne(containerId)){
|
||||
throw "Invalid container";
|
||||
}
|
||||
if (this.parent.collection === "Containers" &&
|
||||
this.parent.id === containerId &&
|
||||
!this.enabled) return;
|
||||
Items.update(
|
||||
this._id,
|
||||
{$set: {
|
||||
"parent.collection": "Containers",
|
||||
"parent.id": containerId,
|
||||
enabled: false,
|
||||
}}
|
||||
);
|
||||
},
|
||||
moveToCharacter: function(characterId){
|
||||
if(!characterId || ! Characters.findOne(characterId)) throw "Invalid character";
|
||||
if(this.parent.collection === "Characters" && this.parent.id === characterId && !this.enabled) return;
|
||||
Items.update(this._id, {$set: {"parent.collection": "Characters", "parent.id": characterId, charId: characterId, enabled: false}});
|
||||
if (!characterId || !Characters.findOne(characterId)) {
|
||||
throw "Invalid character";
|
||||
}
|
||||
if (this.parent.collection === "Characters" &&
|
||||
this.parent.id === characterId &&
|
||||
!this.enabled) return;
|
||||
Items.update(
|
||||
this._id,
|
||||
{$set: {
|
||||
"parent.collection": "Characters",
|
||||
"parent.id": characterId,
|
||||
charId: characterId,
|
||||
enabled: false,
|
||||
}}
|
||||
);
|
||||
},
|
||||
splitToParent: function(parent, moveQuantity){
|
||||
check(parent, {id: String, collection: String});
|
||||
check(moveQuantity, Number);
|
||||
var parentCollection = Meteor.isClient? window[parent.collection] : global[parent.collection];
|
||||
if(!parent.id || !parentCollection.findOne(parent.id)) throw "Invalid parent";
|
||||
var parentCollection = Meteor.isClient ?
|
||||
window[parent.collection] : global[parent.collection];
|
||||
if (!parent.id || !parentCollection.findOne(parent.id)){
|
||||
throw "Invalid parent";
|
||||
}
|
||||
var oldStack = this;
|
||||
//we can only move as much as we have, leaving 0 behind at worst
|
||||
if(oldStack.quantity < moveQuantity) moveQuantity = oldStack.quantity;
|
||||
if (oldStack.quantity < moveQuantity) moveQuantity = oldStack.quantity;
|
||||
var oldQuantity = oldStack.quantity - moveQuantity;
|
||||
|
||||
var newStack = _.pick(oldStack, Schemas.Item.objectKeys());
|
||||
@@ -65,31 +106,39 @@ Items.helpers({
|
||||
|
||||
var existingStack = Items.findOne(_.omit(newStack, "quantity"));
|
||||
var updateStackSize = function(){
|
||||
if(oldQuantity > 0){
|
||||
if (oldQuantity > 0){
|
||||
Items.update(oldStack._id, {$set: {quantity: oldQuantity}});
|
||||
} else {
|
||||
Items.remove(oldStack._id);
|
||||
}
|
||||
};
|
||||
if(existingStack){
|
||||
Items.update(existingStack._id, {$inc: {quantity: moveQuantity}}, {}, function(){
|
||||
updateStackSize();
|
||||
});
|
||||
}else{
|
||||
if (existingStack){
|
||||
Items.update(
|
||||
existingStack._id,
|
||||
{$inc: {quantity: moveQuantity}},
|
||||
{},
|
||||
function(){
|
||||
updateStackSize();
|
||||
}
|
||||
);
|
||||
} else {
|
||||
Items.insert(newStack, function(err, id){
|
||||
if(err) throw err;
|
||||
if (err) throw err;
|
||||
updateStackSize();
|
||||
//copy the children also
|
||||
Meteor.call("cloneChildren", oldStack._id, {collection: "Items", id: id});
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Items.before.update(function(userId, doc, fieldNames, modifier, options){
|
||||
if(
|
||||
if (
|
||||
modifier && modifier.$set && modifier.$set.enabled && //we are equipping this item
|
||||
!(modifier.$set["parent.collection"] === "Characters" && modifier.$set["parent.id"]) //and we haven't specified a character to equip to
|
||||
!(
|
||||
modifier.$set["parent.collection"] === "Characters" &&
|
||||
modifier.$set["parent.id"]
|
||||
) //and we haven"t specified a character to equip to
|
||||
){
|
||||
//equip it to the current character
|
||||
modifier.$set["parent.collection"] = "Characters";
|
||||
@@ -97,21 +146,21 @@ Items.before.update(function(userId, doc, fieldNames, modifier, options){
|
||||
}
|
||||
});
|
||||
|
||||
Items.attachBehaviour('softRemovable');
|
||||
Items.attachBehaviour("softRemovable");
|
||||
makeChild(Items); //children of containers
|
||||
makeParent(Items, ['name', 'enabled']); //parents of effects and attacks
|
||||
makeParent(Items, ["name", "enabled"]); //parents of effects and attacks
|
||||
|
||||
Items.allow(CHARACTER_SUBSCHEMA_ALLOW);
|
||||
|
||||
//give characters default items
|
||||
Characters.after.insert(function (userId, char) {
|
||||
if(Meteor.isServer){
|
||||
Characters.after.insert(function(userId, char) {
|
||||
if (Meteor.isServer){
|
||||
var containerId = Containers.insert({
|
||||
name: "Coin Pouch",
|
||||
charId: char._id,
|
||||
isCarried: true,
|
||||
description: "A sturdy pouch for coins",
|
||||
color: "d"
|
||||
color: "d",
|
||||
});
|
||||
Items.insert({
|
||||
name: "Gold piece",
|
||||
@@ -123,8 +172,8 @@ Characters.after.insert(function (userId, char) {
|
||||
color: "n",
|
||||
parent: {
|
||||
id: containerId,
|
||||
collection: "Containers"
|
||||
}
|
||||
collection: "Containers",
|
||||
},
|
||||
});
|
||||
Items.insert({
|
||||
name: "Silver piece",
|
||||
@@ -136,8 +185,8 @@ Characters.after.insert(function (userId, char) {
|
||||
color: "q",
|
||||
parent: {
|
||||
id: containerId,
|
||||
collection: "Containers"
|
||||
}
|
||||
collection: "Containers",
|
||||
},
|
||||
});
|
||||
Items.insert({
|
||||
name: "Copper piece",
|
||||
@@ -149,8 +198,8 @@ Characters.after.insert(function (userId, char) {
|
||||
color: "s",
|
||||
parent: {
|
||||
id: containerId,
|
||||
collection: "Containers"
|
||||
}
|
||||
collection: "Containers",
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -4,17 +4,17 @@ Schema.User = new SimpleSchema({
|
||||
username: {
|
||||
type: String,
|
||||
regEx: /^[a-z0-9A-Z_]{3,15}$/,
|
||||
optional: true
|
||||
optional: true,
|
||||
},
|
||||
emails: {
|
||||
type: [Object],
|
||||
// this must be optional if you also use other login services like facebook,
|
||||
// but if you use only accounts-password, then it can be required
|
||||
optional: true
|
||||
optional: true,
|
||||
},
|
||||
"emails.$.address": {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Email
|
||||
regEx: SimpleSchema.RegEx.Email,
|
||||
},
|
||||
"emails.$.verified": {
|
||||
type: Boolean
|
||||
@@ -25,20 +25,20 @@ Schema.User = new SimpleSchema({
|
||||
services: {
|
||||
type: Object,
|
||||
optional: true,
|
||||
blackbox: true
|
||||
blackbox: true,
|
||||
},
|
||||
roles: {
|
||||
type: [String],
|
||||
optional: true
|
||||
}
|
||||
optional: true,
|
||||
},
|
||||
});
|
||||
|
||||
Meteor.users.attachSchema(Schema.User);
|
||||
|
||||
Meteor.users.allow({
|
||||
update: function (userId, doc, fields, modifier) {
|
||||
update: function(userId, doc, fields, modifier) {
|
||||
return userId === doc._id &&
|
||||
fields.length === 1 &&
|
||||
fields[0] === 'username';
|
||||
fields[0] === "username";
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user