Implemented item editing

This commit is contained in:
Thaum
2015-01-26 13:28:10 +00:00
parent 6a2e7f0832
commit dc6ea555e5
25 changed files with 331 additions and 133 deletions

View File

@@ -223,7 +223,7 @@ Characters.attachSchema(Schemas.Character);
var attributeBase = function(charId, statName){
check(statName, String);
var effects = Effects.find({charId: charId, stat: statName}).fetch();
var effects = Effects.find({charId: charId, stat: statName, enabled: true}).fetch();
effects = _.groupBy(effects, "operation");
var value = 0;
@@ -360,7 +360,7 @@ Characters.helpers({
//add multiplied proficiency bonus to modifier
mod += prof * this.attributeValue("proficiencyBonus");
Effects.find({charId: charId, stat: skillName}).forEach(function(effect){
Effects.find({charId: charId, stat: skillName, enabled: true}).forEach(function(effect){
switch(effect.operation) {
case "add":
mod += evaluateEffect(charId, effect);
@@ -390,7 +390,7 @@ Characters.helpers({
var charId = this._id;
//return largest value in proficiency array
var prof = 0;
Effects.find({charId: charId, stat: skillName}).forEach(function(effect){
Effects.find({charId: charId, stat: skillName, enabled: true}).forEach(function(effect){
if(effect.operation === "proficiency"){
var newProf = evaluateEffect(charId, effect);
if (newProf > prof){
@@ -408,7 +408,7 @@ Characters.helpers({
var charId = this._id
var mod = +this.skillMod(skillName);
var value = 10 + mod;
Effects.find({charId: charId, stat: skillName}).forEach(function(effect){
Effects.find({charId: charId, stat: skillName, enabled: true}).forEach(function(effect){
if(effect.operation === "passiveAdd"){
value += evaluateEffect(charId, effect);
}

View File

@@ -43,7 +43,27 @@ Schemas.Effect = new SimpleSchema({
stat: {
type: String,
optional: true
},
enabled: {
type: Boolean,
defaultValue: true
}
});
Effects.attachSchema(Schemas.Effect);
//Keep effects in-sync with items
Effects.find({type: "equipment"}, {fields: {type: 1, enabled: 1, sourceId: 1}}).observe({
added: function(newEffect){
var item = Items.findOne(newEffect.sourceId);
if(item && item.equipped !== newEffect.enabled){
Effects.update(newEffect._id, {$set: {enabled: item.equipped}})
}
},
changed: function(newEffect, oldEffect){
var item = Items.findOne(newEffect.sourceId);
if(item && item.equipped !== newEffect.enabled){
Effects.update(newEffect._id, {$set: {enabled: item.equipped}})
}
}
})

View File

@@ -1,41 +0,0 @@
/*
* Effects are reason-value 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(!this.isSet) return Random.id();
}
},
name: {
type: String
},
operation: {
type: String,
defaultValue: "add",
allowedValues: ["base", "proficiency","add","mul","min","max","advantage","disadvantage","passiveAdd","fail","conditional"]
},
value: {
type: Number,
decimal: true,
optional: true
},
calculation: {
type: String,
optional: true
},
//indicates what the effect originated from
type: {
type: String,
defaultValue: "editable",
allowedValues: ["editable", "feature", "buff", "equipment", "inate"]
},
//which stat the effect is applied to
stat: {
type: String,
optional: true
}
});