Began implementing actual character sheet

This commit is contained in:
Thaum
2014-11-25 15:06:30 +00:00
parent 252d0f989b
commit 5eea4714b2
41 changed files with 505 additions and 279 deletions

View File

@@ -60,6 +60,8 @@ Schemas.Character = new SimpleSchema({
ki: {type: Schemas.Attribute},
sorceryPoints: {type: Schemas.Attribute},
rages: {type: Schemas.Attribute},
superiorityDice: {type: Schemas.Attribute},
expertiseDice: {type: Schemas.Attribute},
//hit dice
@@ -236,9 +238,9 @@ Schemas.Character = new SimpleSchema({
deathSave: { type: Schemas.DeathSave },
time: { type: Number, min: 0, decimal: true, defaultValue: 0},
initiativeOrder:{ type: Number, min: 0, max: 1, decimal: true, defaultValue: 0},
expirations: { type: [Schemas.Expiration], defaultValue: []}
expirations: { type: [Schemas.Expiration], defaultValue: []},
spells: { type: [Schemas.Spell], defaultValue: []}
//TODO add permission stuff for owner, readers and writers
//TODO spells
});
Characters.attachSchema(Schemas.Character);
@@ -257,6 +259,32 @@ Characters.find({},{fields: {time: 1, expirations: 1}}).observe({
}
});
var attributeBase = function(attribute){
var value = 0;
//add all values in add array
_.each(attribute.add, function(effect){
value += evaluateEffect(charId, effect);
});
//multiply all values in mul array
_.each(attribute.mul, function(effect){
value *= evaluateEffect(charId, effect);
});
//largest min
_.each(attribute.min, function(effect){
var min = evaluateEffect(charId, effect);
value = value > min? value : min;
});
//smallest max
_.each(attribute.max, function(effect){
var max = evaluateEffect(charId, effect);
value = value < max? value : max;
});
return value;
}
//functions and calculated values.
//These functions can only rely on this._id since no other
//field is likely to be attached to all returned characters
@@ -311,29 +339,37 @@ Characters.helpers({
var charId = this._id;
var attribute = this.getField(attributeName);
//base value
var value = attribute.base;
//add all values in add array
_.each(attribute.add, function(effect){
value += evaluateEffect(charId, effect);
});
var value = attributeBase(attribute);
value += attribute.adjustment;
//this attribute returns, pull it from the array, we may visit it again safely
visitedAttributes = _.without(visitedAttributes, attributeName);
return value;
}
})(),
//multiply all values in mul array
_.each(attribute.mul, function(effect){
value *= evaluateEffect(charId, effect);
});
attributeBase: (function(){
//store a private array of attributes we've visited without returning
//if we try to visit the same attribute twice before resolving its value
//we are in a dependency loop and need to GTFO
var visitedAttributes = [];
return function(attributeName){
check(attributeName, String);
//we're still evaluating this attribute, must be in a loop
if(_.contains(visitedAttributes, attributeName)) {
console.log("dependency loop detected");
return NaN;
}
//push this attribute to the list of visited attributes
//we can't visit it again unless it returns first
visitedAttributes.push(attributeName);
//largest min
_.each(attribute.min, function(effect){
var min = evaluateEffect(charId, effect);
value = value > min? value : min;
});
//smallest max
_.each(attribute.max, function(effect){
var max = evaluateEffect(charId, effect);
value = value < max? value : max;
});
//done traversing the tree, this attribute returns, pull it from the array
var charId = this._id;
var attribute = this.getField(attributeName);
//base value
var value = attributeBase(attribute);
//this attribute returns, pull it from the array, we may visit it again safely
visitedAttributes = _.without(visitedAttributes, attributeName);
return value;
}

View File

@@ -1,7 +1,7 @@
Schemas.Attribute = new SimpleSchema({
//the unmodified value of the attribute
//the temporary shift of the attribute
//should be zero for most attributes after a long rest
base: {
adjustment: {
type: Number,
defaultValue: 0
},
@@ -16,7 +16,7 @@ Schemas.Attribute = new SimpleSchema({
//note that to make an invulnerability add a new max of zero value
Schemas.Vulnerability = new SimpleSchema({
//same as attribute
base: {
adjustment: {
type: Number,
defaultValue: 0
},

View File

@@ -1,15 +1,17 @@
Items = new Meteor.Collection('items');
Schemas.Item = new SimpleSchema({
name: {type: String},
description:{type: String},
name: {type: String, defaultValue: "New Item"},
plural: {type: String, optional: true},
description:{type: String, defaultValue: ""},
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]}
buffs: {type: [Schemas.Buff], defaultValue: []},
equipmentSlot: {type: String, defaultValue: "", allowedValues: ["head", "body", "arms", "hands", "held", "feet"]},
});
Items.attachSchema(Schemas.Item);