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

@@ -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,118 +0,0 @@
DamageTypes = [
"acid", "bludgeoning", "cold", "fire", "force",
"lightning", "necrotic", "piercing", "poison", "psychic",
"radiant", "slashing", "thunder"
]
Conditions = {};
Conditions.Blinded = {
description: ["a blinded creature can't see and automatically fails any ability check that requires sight.",
"Attack rolls against the creature have advantage, and the creature's attack rolls have disadvantage."]
}
Conditions.Charmed = {
description: ["A charmed creature can't attack the charmer or target the charmer with harmful abilities or magical effects",
"The charmer has advantage on any ability check to interact socially with the creature."]
}
Conditions.Deafened = {
description: ["A deafened creature can't hear and automatically fails any ability check that requires hearing"]
}
Conditions.Frightened = {
description: []
}
Conditions.Grappled = {
description: [
"A grappled creature's speed becomes 0, and it can't benefit from any bonuses to its speed",
"The condition ends if the grappler is incapacitated",
"The conditions also ends if if an effect removes the\
grappled creature from the reach of the grappler or grappling\
effect, such as when a creature is hurled\
away by the thunderwave spell."
],
effects: [
{stat: "attributes.speed.max", value: 0}
]
}
Conditions.Incapacitated = {
effects: [
{stat: "attributes.actions.max", value: 0},
{stat: "attributes.reactions.max", value: 0},
{stat: "attributes.bonusActions.max", value: 0}
]
}
Conditions.Invisible = {
}
Conditions.Paralyzed = {
//implies incapacitated
effects: [
{stat: "skills.strengthSave.fail", value: 1},
{stat: "skills.dexteritySave.fail", value: 1},
{stat: "attributes.speed.max", value: 0}
]
}
_.extend(Conditions.Paralyzed, Conditions.Incapacitated);
Conditions.Petrified = {
effects: [
{stat: "attributes.weight.mul", value: 10},
{stat: "attributes.ageRate.max", value: 0},
{stat: "attributes.ageRate.min", value: 0},
{stat: "skills.strengthSave.fail", value: 1},
{stat: "skills.dexteritySave.fail", value: 1},
{stat: "attributes.speed.max", value: 0}
]
}
for(var i = 0, l = DamageTypes.length; i < l; i++){
var str = "vulnerability." + DamageTypes[i] + ".mul"
Conditions.Petrified.effects.push({stat: str, value: 0.5});
}
_.extend(Conditions.Petrified, Conditions.Incapacitated);
Conditions.Poisoned = {
description: []
}
Conditions.Prone = {
description: [],
effects: [
{stat: "skills.strengthAttack.disadvantage", value: 1},
{stat: "skills.dexterityAttack.disadvantage", value: 1},
{stat: "skills.rangedAttack.disadvantage", value: 1}
]
}
Conditions.Restrained = {
effects: [
{stat: "attributes.speed.max", value: 0}
]
}
Conditions.Stunned = {
//implies incapacitated
effects: [
{stat: "attributes.speed.max", value: 0},
{stat: "skills.strengthSave.fail", value: 1},
{stat: "skills.dexteritySave.fail", value: 1}
]
}
_.extend(Conditions.Stunned, Conditions.Incapacitated);
Conditions.Unconscious = {
//implies incapacitated
//implies prone
effects: [
{stat: "attributes.speed.max", value: 0},
{stat: "skills.strengthSave.fail", value: 1},
{stat: "skills.dexteritySave.fail", value: 1}
]
}
_.extend(Conditions.Unconscious, Conditions.Incapacitated);
_.extend(Conditions.Unconscious, Conditions.Prone);

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,49 +0,0 @@
// turns dot notation strings into keys of root
// argument formats:
// 157, anything -> 157
// "some.number", object -> object.some.number
// "some.function", object -> object.some.function()
// "some.function arg1 arg2", object -> object.some.function(arg1, arg2)
pop = function(input, root){
if(typeof(input) === "string"){
//we need root for this part
if(root === undefined) return;
//this is a likely to fail if the string is malformed
try{
//split over spaces
var parts = input.split(" ");
//for each word
for (var i = 0; i < parts.length; i++){
//split over dots
var str = parts[i].split(".");
//start at root
parts[i] = root;
//for each word between dots
for (var j = 0; j < str.length; j++){
parts[i] = parts[i][str[j]];
}
}
//pull the first word out, might be a function
var func = parts.splice(0, 1)[0];
//if it's a function, apply the arguments to it
if(_.isFunction(func)) return +func.apply(root, parts);
//if it's a number, return it
if(!isNaN(func)) return +func;
} catch (err) {
//TODO pokemon catch statement is bad
//"gotta catch em all"
console.log(err);
return;
}
}
return +input;
}

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

@@ -1,44 +0,0 @@
roll = function (n, d){
if(!isNaN(n)){
//first digit is a number
if(d === undefined){
d = n;
n = 1;
}
if(n > 500){
console.log(n + " > 500, cannot lift that many dice to roll them");
return;
}
var result = {sum: 0, rolls: []};
for (var i = 0; i < n; i++){
var roll = Math.floor(Random.fraction() * d + 1)
result.sum += roll;
result.rolls.push(roll);
}
return result;
}
console.log("rolling dice failed for inputs: ", n, d);
return {sum: 0, rolls: []};
}
rollDropLow = function(n, d, drop){
var r = roll(n,d)
r.rolls.sort(function(a, b){return a-b}); //sort ascending
r.rolls.splice(0, drop); //remove the lowest elements
r.sum = 0;
for (var i = 0, l = r.rolls.length; i , l ; i++){
sum += r.rolls[i];
}
return r;
}
rollDropHigh = function(n, d, drop){
var r = roll(n,d)
r.rolls.sort(function(a, b){return b-a}); //sort descending
r.rolls.splice(0, drop); //remove the highest elements
r.sum = 0;
for (var i = 0, l = r.rolls.length; i , l ; i++){
sum += r.rolls[i];
}
return r;
}

View File

@@ -1,36 +0,0 @@
evaluate = function(character, string){
string = string.replace(/\b[a-z]+\b/g, function(sub){
//skill mods
if(character.skills[sub]){
return +character.skillMod(character.skills[sub]);
}
//attributes
if(character.attributes[sub]){
return +character.attributeValue(character.attributes[sub]);
}
return sub;
});
try{
result = math.eval(string);
return result
} catch(e){
console.log(e)
return string;
}
}
evaluateString = function(character, string){
//define brackets as curly brackets around anything that isn't a curly bracket
var brackets = /\{[^\{\}]*\}/g;
var result = string.replace(brackets, function(exp){
var exp = exp.replace(/(\{|\})/g, "") //remove brackets
var span = jQuery('<span/>', {
title: exp,
text: evaluate(character, exp),
class: "calculatedValue"
});
return span.prop('outerHTML');
});
//this is going to return HTML, ensure it is santized!
return result;
}

File diff suppressed because one or more lines are too long