Made Attacks come from items

This commit is contained in:
Thaum
2015-03-09 14:03:11 +00:00
parent 40a050d88f
commit 55784d0e3b
17 changed files with 185 additions and 67 deletions

View File

@@ -13,22 +13,28 @@ Schemas.Attack = new SimpleSchema({
defaultValue: "New Attack",
trim: false
},
range: {
details: {
type: String,
optional: true,
trim: false
},
attackBonus: {
type: String,
optional: true,
defaultValue: "strengthMod + proficiencyBonus",
optional: true,
trim: false
},
damage: {
damageBonus: {
type: String,
defaultValue: "strengthMod",
optional: true,
trim: false
},
damageDice: {
type: String,
optional: true,
defaultValue: "1d8 + {strengthMod}",
trim: false
defaultValue: "1d8",
allowedValues: DAMAGE_DICE
},
damageType: {
type: String,
@@ -36,10 +42,26 @@ Schemas.Attack = new SimpleSchema({
"poison", "psychic", "radiant", "thunder"],
defaultValue: "slashing"
},
//indicates what the attack originated from
type: {
type: String,
defaultValue: "editable",
allowedValues: ["editable", "feature", "class", "buff", "equipment", "racial", "inate"]
},
//the id of the feature, buff or item that created this effect
sourceId: {
type: String,
regEx: SimpleSchema.RegEx.Id,
optional: true
},
color: {
type: String,
allowedValues: _.pluck(colorOptions, "key"),
defaultValue: "q"
},
enabled: {
type: Boolean,
defaultValue: true
}
});

View File

@@ -36,16 +36,22 @@ Items.helpers({
}
});
//remove effects if their item source is removed
//remove effects and attacks if their item source is removed
Items.before.remove(function (userId, item) {
Effects.find({sourceId: item._id, type: "equipment"}).forEach(function(effect){
Effects.remove(effect._id);
});
Attacks.find({sourceId: item._id, type: "equipment"}).forEach(function(attack){
Attacks.remove(attack._id);
});
});
//keep the effects on the correct character and enabled when equipped
//keep the effects and attacks on the correct character and enabled when equipped
Items.after.update(function (userId, item, fieldNames, modifier, options) {
Effects.find({sourceId: item._id, type: "equipment"}).forEach(function(effect){
Effects.update(effect._id, { $set: {charId: item.charId, enabled: item.equipped} });
}, {fetchPrevious: false});
});
Effects.update(effect._id, { $set: {charId: item.charId, enabled: item.equipped, name: item.name} });
});
Attacks.find({sourceId: item._id, type: "equipment"}).forEach(function(attack){
Attacks.update(attack._id, { $set: {charId: item.charId, enabled: item.equipped, name: item.name} });
});
}, {fetchPrevious: false});