Implemented and cleaned up character schemas

This commit is contained in:
Thaum
2014-11-13 08:44:21 +00:00
parent d80fb19dfe
commit 7ab97a17cc
27 changed files with 403 additions and 259 deletions

View File

@@ -14,4 +14,6 @@ dburles:collection-helpers
reactive-var
cw4gn3r:jquery-event-drag
underscore
aldeed:collection2
aldeed:autoform

View File

@@ -2,6 +2,9 @@ accounts-base@1.1.2
accounts-password@1.0.4
accounts-ui-unstyled@1.1.4
accounts-ui@1.1.3
aldeed:autoform@3.2.0
aldeed:collection2@2.2.0
aldeed:simple-schema@1.0.3
application-configuration@1.0.3
autopublish@1.0.1
autoupdate@1.1.3
@@ -48,7 +51,9 @@ meteor@1.1.3
minifiers@1.1.2
minimongo@1.0.5
mobile-status-bar@1.0.1
mongo-livedata@1.0.6
mongo@1.0.8
mrt:moment@2.6.0
npm-bcrypt@0.7.7
observe-sequence@1.0.3
ordered-dict@1.0.1

View File

@@ -1,164 +1,18 @@
//set up the collection for characters
Characters = new Meteor.Collection("characters");
var attributes = [
{name: "strength"},
{name: "dexterity"},
{name: "constitution"},
{name: "intelligence"},
{name: "wisdom"},
{name: "charisma"},
{name: "hitPoints"},
{name: "experience"},
{name: "proficiencyBonus",
add: [
new Effect("Level 1", 2)
]
},
{name: "speed",
add: [
new Effect("Base Speed", 30)
]
},
{name: "armor",
add: [
new Effect("Base Armor Class", 10),
new Effect("Dexterity Modifier", "skillMod skills.dexterityArmor")
]
},
{name: "weight"},
{name: "weightCarried"},
{name: "age"},
{name: "ageRate"},
{name: "level1SpellSlots"},
{name: "level2SpellSlots"},
{name: "level3SpellSlots"},
{name: "level4SpellSlots"},
{name: "level5SpellSlots"},
{name: "level6SpellSlots"},
{name: "level7SpellSlots"},
{name: "level8SpellSlots"},
{name: "level9SpellSlots"},
{name: "ki"},
{name: "sorceryPoints"},
{name: "rages"}
];
Schemas.Character = new SimpleSchema({
strings: { type: Schemas.Strings },
attributes: { type: Schemas.Attributes },
skills: { type: Schemas.Skills },
vulerabilities: { type: Schemas.Vulnerabilities },
proficiencies: { type: Schemas.Proficiencies }
var skills = [
{skill: "strengthSave", ability: "strength"},
{skill: "dexteritySave", ability: "dexterity"},
{skill: "constitutionSave", ability: "constitution"},
{skill: "intelligenceSave", ability: "intelligence"},
{skill: "wisdomSave", ability: "wisdom"},
{skill: "charismaSave", ability: "charisma"},
//TODO add permission stuff for owner, readers and writers
//TODO hit dice
});
{skill: "acrobatics", ability: "dexterity"},
{skill: "animalHandling", ability: "wisdom"},
{skill: "arcana",ability: "intelligence"},
{skill: "athletics", ability: "strength"},
{skill: "deception", ability: "charisma"},
{skill: "history", ability: "intelligence"},
{skill: "insight", ability: "wisdom"},
{skill: "intimidation", ability: "charisma"},
{skill: "investigation", ability: "intelligence"},
{skill: "medicine", ability: "wisdom"},
{skill: "nature", ability: "intelligence"},
{skill: "perception", ability: "wisdom"},
{skill: "performance", ability: "charisma"},
{skill: "persuasion", ability: "charisma"},
{skill: "religion", ability: "intelligence"},
{skill: "sleightOfHand", ability: "dexterity"},
{skill: "stealth", ability: "dexterity"},
{skill: "survival", ability: "wisdom"},
{skill: "initiative", ability: "dexterity"},
{skill: "strengthAttack", ability: "strength", proficiency: 1},
{skill: "dexterityAttack", ability: "dexterity", proficiency: 1},
{skill: "constitutionAttack", ability: "constitution", proficiency: 1},
{skill: "intelligenceAttack", ability: "intelligence", proficiency: 1},
{skill: "wisdomAttack", ability: "wisdom", proficiency: 1},
{skill: "charismaAttack", ability: "charisma", proficiency: 1},
{skill: "rangedAttack", ability: "dexterity", proficiency: 1},
{skill: "dexterityArmor", ability: "dexterity"}
];
//Plain text fields for the character
var strings = [
"name",
"alignment",
"gender",
"race",
"class",
"description",
"personality",
"ideals",
"bonds",
"flaws",
"backstory",
"notes"
];
//Data structure for the character
//no functions can be added to this constructor
Character = function(owner){
//attributes
this.attributes = {};
for(var i = 0, l = attributes.length; i < l; i++){
this.attributes[attributes[i].name] = new Attribute(0);
this.attributes[attributes[i].name].add = attributes[i].add || [];
this.attributes[attributes[i].name].mul = attributes[i].mul || [];
this.attributes[attributes[i].name].min = attributes[i].min || [];
this.attributes[attributes[i].name].max = attributes[i].max || [];
}
//skills
this.skills = {};
for(var i = 0, l = skills.length; i < l; i++){
this.skills[skills[i].skill] = new Skill(skills[i].ability);
if(skills[i].proficiency)
this.skills[skills[i].skill].proficiency.push(skills[i].proficiency);
}
this.deathSave = {
pass : 0,
fail: 0,
canDeathSave: true
};
this.strings = {};
for(var i = 0, l = strings.length; i < l; i++){
this.strings[strings[i]] = "";
};
this.weaponProficiencies = [];
this.toolProficiencies = [];
this.languages = [];
/*
//anything that needs to be edited rather than added or removed
//needs its own collection.
this.hitDice = [];
this.features = [];
this.spells = [];
*/
this.vulnerability = {};
for(var i = 0, l = DamageTypes.length; i < l; i++){
this.vulnerability[DamageTypes[i]] = new Attribute(1);
this.vulnerability[DamageTypes[i]].min.push({name: "Resistance doesn't stack", value: 0.5});
this.vulnerability[DamageTypes[i]].max.push({name: "Vulnerability doesn't stack", value: 2});
}
//admin
this.owner = owner;
this.readers = [];
this.writers = [];
}
Characters.attachSchema(Schemas.Character);
//functions and calculated values go here
Characters.helpers({
@@ -266,8 +120,9 @@ 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}]);
@@ -286,6 +141,7 @@ Characters.helpers({
},
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}]);
@@ -322,4 +178,4 @@ getMod = function(score){
signedString = function(number){
return number > 0? "+" + number : "" + number;
}
}

View File

@@ -1,12 +0,0 @@
//Attributes are numerical values
Attribute = function(base){
//the unmodified value of the attribute
//should be zero for most attributes after a long rest
this.base = base;
//effects of the form {name: "Ring of Protection", value: 1}
this.add = []; //bonuses added to the attribute
this.mul = []; //multipliers to the attribute (after adding bonuses)
this.min = []; //effects setting the minimum value of the attribute
this.max = []; //effects setting the maximum value of the attribute
this.conditional = []; //conditional modifiers
}

View File

@@ -1,5 +0,0 @@
Effect = function(stat, value){
this.stat = stat;
this.value = value;
this._id = Random.id();
}

View File

@@ -1,6 +0,0 @@
HitDice = function(sides){
this.sides = sides;
this.bonus = 0;
this.number = 0;
this.max = 0;
}

View File

@@ -1,18 +0,0 @@
//Skills are bonuses to rolls: "+2" etc.
//They are based off of some ability
Skill = function(ability){
//proficiencies of the form {name: "Jack of all Trades", value: 0.5}
//only the highest is used
this.proficiency = [];
//ability name that this skill uses as base for roll
this.ability = ability;
this.add = [];
this.mul = [];
this.min = [];
this.max = [];
this.advantage = []; //effects granting advantage
this.disadvantage = [];
this.passiveAdd = []; //only added to passive checks
this.fail = []; //all checks are failed
this.conditional = []; //conditional modifiers
}

View File

@@ -1,11 +0,0 @@
Spell = function(name){
this.name = name;
this.level = 0;
this.school = "";
this.range = "";
this.verbal = false;
this.somatic = false;
this.material = false;
this.duration = "";
this.description = "";
}

View File

@@ -0,0 +1,50 @@
Schemas.Attribute = new SimpleSchema({
//the unmodified value of the attribute
//should be zero for most attributes after a long rest
base: {
type: Number,
defaultValue: 0
},
//effect arrays
add: { type: [Schemas.Effect], defaultValue: [] },
mul: { type: [Schemas.Effect], defaultValue: [] },
min: { type: [Schemas.Effect], defaultValue: [] },
max: { type: [Schemas.Effect], defaultValue: [] },
conditional:{ type: [Schemas.Effect], defaultValue: [] }
});
Schemas.Attributes = new SimpleSchema({
strength: {type: Schemas.Attribute},
dexterity: {type: Schemas.Attribute},
constitution: {type: Schemas.Attribute},
intelligence: {type: Schemas.Attribute},
wisdom: {type: Schemas.Attribute},
charisma: {type: Schemas.Attribute},
hitPoints: {type: Schemas.Attribute},
experience: {type: Schemas.Attribute},
proficiencyBonus: {type: Schemas.Attribute},
speed: {type: Schemas.Attribute},
weight: {type: Schemas.Attribute},
weightCarried: {type: Schemas.Attribute},
age: {type: Schemas.Attribute},
ageRate: {type: Schemas.Attribute},
level1SpellSlots: {type: Schemas.Attribute},
level2SpellSlots: {type: Schemas.Attribute},
level3SpellSlots: {type: Schemas.Attribute},
level4SpellSlots: {type: Schemas.Attribute},
level5SpellSlots: {type: Schemas.Attribute},
level6SpellSlots: {type: Schemas.Attribute},
level7SpellSlots: {type: Schemas.Attribute},
level8SpellSlots: {type: Schemas.Attribute},
level9SpellSlots: {type: Schemas.Attribute},
ki: {type: Schemas.Attribute},
sorceryPoints: {type: Schemas.Attribute},
rages: {type: Schemas.Attribute},
armor: {type: Schemas.Attribute},
"armor.add": {
type: [Schemas.Effect],
defaultValue: [
new Effect("Dexterity Modifier", "skillMod skills.dexterityArmor")
]
}
});

View File

@@ -0,0 +1,18 @@
Schemas.DeathSave = new SimpleSchema({
pass: {
type: Number,
min: 0,
max: 3,
defaultValue: 0
},
fail: {
type: Number,
min: 0,
max: 3,
defaultValue: 0
},
canDeathSave: {
type: Boolean,
defaultValue: true
}
});

View File

@@ -0,0 +1,17 @@
/*
* A buff becomes an effect when applied on a creature.
* It is the effect plus the stat to which it should be applied
*/
Schemas.Buff = new SimpleSchema({
stat: {
type: String
},
effect: {
type: Schemas.Effect
}
});
Buff = function(name, stat, value){
this.stat = stat;
this.effect = new Effect(name, value);
};

View File

@@ -0,0 +1,35 @@
/*
* Effects are reason-value pairs attached to skills and abilities
* that modify their final value or presentation in some way
*/
Schemas.Effect = new SimpleSchema({
_id: {
type: String,
regEx: SimpleSchema.RegEx.Id,
autoValue: function(){
if(!isSet) return Random.id();
}
},
name: {
type: String
},
value: {
type: Number,
decimal: true,
optional: true
},
calculation: {
type: String,
optional: true
}
});
Effect = function(name, value){
this._id = Random.id();
this.name = name;
if (typeof value === "string"){
this.calculation = value;
} else if (typeof valye === "number"){
this.value = value;
}
};

View File

@@ -0,0 +1,10 @@
Schemas.Proficiency = new simpleSchema({
name: {type: String},
source: {type: String}
})
Schemas.Proficiencies = new SimpleSchema({
weapons: {type: [Schemas.Proficiency]},
tools: {type: [Schemas.Proficiency]},
languages: {type: [Schemas.Proficiency]}
});

View File

@@ -0,0 +1,159 @@
Schemas.Skill = new SimpleSchema({
//attribute name that this skill used as base mod for roll
ability: { type: String, defaultValue: "" },
//multiplied by profBonus and added to base mod
//only highest value proficiency is used
proficiency: { type: [Schemas.Effect], defaultValue: [] },
//added to base mod
add: { type: [Schemas.Effect], defaultValue: [] },
//multiplied by base + adds
mul: { type: [Schemas.Effect], defaultValue: [] },
//lower bounds, highest used
min: { type: [Schemas.Effect], defaultValue: [] },
//upper bounds, lowest used
max: { type: [Schemas.Effect], defaultValue: [] },
//things giving advantage
advantage: { type: [Schemas.Effect], defaultValue: [] },
//things giving disadvantage
disadvantage: { type: [Schemas.Effect], defaultValue: [] },
//added to passive checks only
passiveAdd: { type: [Schemas.Effect], defaultValue: [] },
//things causing all rolls to fail
fail: { type: [Schemas.Effect], defaultValue: [] },
//things that only apply sometimes
conditional: { type: [Schemas.Effect], defaultValue: [] }
});
Schemas.Skills = new SimpleSchema({
//saves
strengthSave: {type: Schemas.Skill},
"strengthSave.ability": { type: String, defaultValue: "strength" },
dexteritySave: {type: Schemas.Skill},
"dexteritySave.ability": { type: String, defaultValue: "dexterity" },
constitutionSave:{type: Schemas.Skill},
"constitutionSave.ability": { type: String, defaultValue: "constitution" },
intelligenceSave:{type: Schemas.Skill},
"intelligenceSave.ability": { type: String, defaultValue: "intelligence" },
wisdomSave: {type: Schemas.Skill},
"wisdomSave.ability": { type: String, defaultValue: "wisdom" },
charismaSave: {type: Schemas.Skill},
"charismaSave.ability": { type: String, defaultValue: "charisma" },
//skill skills
acrobatics: {type: Schemas.Skill},
"acrobatics.ability": { type: String, defaultValue: "dexterity" },
animalHandling: {type: Schemas.Skill},
"animalHandling.ability": { type: String, defaultValue: "wisdom" },
arcana: {type: Schemas.Skill},
"arcana.ability": { type: String, defaultValue: "intelligence" },
athletics: {type: Schemas.Skill},
"athletics.ability": { type: String, defaultValue: "strength" },
deception: {type: Schemas.Skill},
"deception.ability": { type: String, defaultValue: "charisma" },
history: {type: Schemas.Skill},
"history.ability": { type: String, defaultValue: "intelligence" },
insight: {type: Schemas.Skill},
"insight.ability": { type: String, defaultValue: "wisdom" },
intimidation: {type: Schemas.Skill},
"intimidation.ability": { type: String, defaultValue: "charisma" },
investigation: {type: Schemas.Skill},
"investigation.ability": { type: String, defaultValue: "intelligence" },
medicine: {type: Schemas.Skill},
"medicine.ability": { type: String, defaultValue: "wisdom" },
nature: {type: Schemas.Skill},
"nature.ability": { type: String, defaultValue: "intelligence" },
perception: {type: Schemas.Skill},
"perception.ability": { type: String, defaultValue: "wisdom" },
performance: {type: Schemas.Skill},
"performance.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" },
sleightOfHand: {type: Schemas.Skill},
"sleightOfHand.ability": { type: String, defaultValue: "dexterity" },
stealth: {type: Schemas.Skill},
"stealth.ability": { type: String, defaultValue: "dexterity" },
survival: {type: Schemas.Skill},
"survival.ability": { type: String, defaultValue: "wisdom" },
//Mechanical Skills
initiative: {type: Schemas.Skill},
"initiative.ability": { type: String, defaultValue: "dexterity" },
strengthAttack: {type: Schemas.Skill},
"strengthAttack.ability": {type: String,defaultValue: "strength"},
"strengthAttack.proficiency": {
type: [Schemas.Effect],
defaultValue: [{_id: Random.id(),name: "Attack Proficiency",value: 1}]
},
dexterityAttack: {type: Schemas.Skill},
"dexterityAttack.ability": { type: String, defaultValue: "dexterity" },
"dexterityAttack.proficiency": {
type: [Schemas.Effect],
defaultValue: [{_id: Random.id(),name: "Attack Proficiency",value: 1}]
},
constitutionAttack: {type: Schemas.Skill},
"constitutionAttack.ability":{ type: String, defaultValue: "constitution" },
"constitutionAttack.proficiency": {
type: [Schemas.Effect],
defaultValue: [{_id: Random.id(),name: "Attack Proficiency",value: 1}]
},
intelligenceAttack: {type: Schemas.Skill},
"intelligenceAttack.ability":{ type: String, defaultValue: "intelligence" },
"intelligenceAttack.proficiency": {
type: [Schemas.Effect],
defaultValue: [{_id: Random.id(),name: "Attack Proficiency",value: 1}]
},
wisdomAttack: {type: Schemas.Skill},
"wisdomAttack.ability": { type: String, defaultValue: "wisdom" },
"wisdomAttack.proficiency": {
type: [Schemas.Effect],
defaultValue: [{_id: Random.id(),name: "Attack Proficiency",value: 1}]
},
charismaAttack: {type: Schemas.Skill},
"charismaAttack.ability": { type: String, defaultValue: "charisma" },
"charismaAttack.proficiency": {
type: [Schemas.Effect],
defaultValue: [{_id: Random.id(),name: "Attack Proficiency",value: 1}]
},
rangedAttack: {type: Schemas.Skill},
"rangedAttack.ability": { type: String, defaultValue: "dexterity" },
"rangedAttack.proficiency": {
type: [Schemas.Effect],
defaultValue: [{_id: Random.id(),name: "Attack Proficiency",value: 1}]
},
dexterityArmor: {type: Schemas.Skill},
"dexterityArmor.ability": { type: String, defaultValue: "dexterity" }
});

View File

@@ -0,0 +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: "" },
});

View File

@@ -0,0 +1,24 @@
Schemas.Vulnerability = _.extend({
"min.defaultValue": [
new Effect("Resistance doesn't stack", 0.5)
],
"max.defaultValue": [
new Effect("Vulnerability doesn't stack", 2)
]
}, Schemas.Attribute);
Schemas.Vulnerabilities = new SimpleSchema({
acid: {type: Schemas.Vulnerability},
bludgeoning:{type: Schemas.Vulnerability},
cold: {type: Schemas.Vulnerability},
fire: {type: Schemas.Vulnerability},
force: {type: Schemas.Vulnerability},
lightning: {type: Schemas.Vulnerability},
necrotic: {type: Schemas.Vulnerability},
piercing: {type: Schemas.Vulnerability},
poison: {type: Schemas.Vulnerability},
psychic: {type: Schemas.Vulnerability},
radiant: {type: Schemas.Vulnerability},
slashing: {type: Schemas.Vulnerability},
thunder: {type: Schemas.Vulnerability}
});

View File

@@ -1,7 +1,10 @@
Containers = new Meteor.Collection('containers');
//set up the collection for containers
Containers = new Meteor.Collection("containers");
Container = function(name, owner){
this.name = name;
this.owner = owner;
this.isCarried = true;
};
Schemas.Container = new SimpleSchema({
name: { type: String },
owner: { type: String, regEx: SimpleSchema.RegEx.Id},
isCarried: { type: Boolean }
});
Containers.attachSchema(Schemas.Container);

View File

@@ -1,23 +1,26 @@
Items = new Meteor.Collection('items');
Item = function(name, container){
this.name = name;
this.container = container;
this.quantity = 1;
this.weight = 0.0;
//value in gold pieces
this.value = 0;
this.description = "";
//is this item a coin, letter of credit, ect.
this.tradeGood = false;
this.stakcable = false;
this.effects = [];
}
Schemas.Item = new SimpleSchema({
name: {type: String},
description:{type: String},
container: {type: String, regEx: SimpleSchema.RegEx.Id},
quantity: {type: Number, min: 0, defaultValue: 1},
weight: {type: Number, min: 0, defaultValue: 0, decimal: true},
value: {type: Number, min: 0, defaultValue: 0, decimal: true},
tradeGood: {type: Boolean, defaultValue: false},
stackable: {type: Boolean, defaultValue: false},
buffs: {type: [Schemas.Buff]}
});
Items.attachSchema(Schemas.Item);
Items.helpers({
totalValue: function(){
return this.value * this.quantity;
},
totalWeight: function(){
return this.weight * this.quantity;
},
pluralName: function(){
if(this.stackable && this.plural && this.quantity > 1){
return this.plural;
@@ -25,31 +28,4 @@ Items.helpers({
return this.name;
}
}
});
if(Meteor.isClient){
Template.registerHelper("valueString", function(value){
var resultArray = [];
//sp
var gp = Math.floor(value);
if(gp > 0) resultArray.push(gp + "gp");
//sp
var sp = Math.floor(10 * (value % 1));
if(sp > 0) resultArray.push(sp + "sp");
//cp
var cp = 10 * ((value * 10) % 1);
cp = Math.round(cp * 1000) / 1000;
if(cp > 0) resultArray.push(cp + "cp");
//build string with correct spacing
var result = "";
for(var i = 0; i < resultArray.length; i++){
//add a space between values
if(i !== 0){
result += " ";
}
result += resultArray[i];
}
return result;
});
}
});

View File

@@ -0,0 +1,24 @@
Template.registerHelper("valueString", function(value){
var resultArray = [];
//sp
var gp = Math.floor(value);
if(gp > 0) resultArray.push(gp + "gp");
//sp
var sp = Math.floor(10 * (value % 1));
if(sp > 0) resultArray.push(sp + "sp");
//cp
var cp = 10 * ((value * 10) % 1);
cp = Math.round(cp * 1000) / 1000;
if(cp > 0) resultArray.push(cp + "cp");
//build string with correct spacing
var result = "";
for(var i = 0; i < resultArray.length; i++){
//add a space between values
if(i !== 0){
result += " ";
}
result += resultArray[i];
}
return result;
});

View File

@@ -31,7 +31,10 @@ Template.textField.events({
//TODO sanitise the html
var setter = {};
setter["strings."+this.field] = text;
Characters.update(this.character._id, {$set: setter});
Characters.update(this.character._id, {$set: setter}, function(error, result) {
console.log(error);
console.log(result);
});
},
"click #textOutput": function(){
Template.instance().editing.set(true);

View File

@@ -6,5 +6,5 @@
{{/each}}
</div>
<input id="addCharacter" type="button" value="Add Character">
<input id="nukeCharacters" type="button" value="Clear all characters">
{{> quickForm collection="Characters" id="insertCharacterForm" type="insert"}}
</template>

View File

@@ -0,0 +1 @@
Schemas = {};