Adjustments for error handling

This commit is contained in:
Blade Barringer 2015-07-18 08:18:31 -05:00
parent 6d5b57d139
commit 163b0545e8
2 changed files with 36 additions and 8 deletions

View file

@ -23,16 +23,20 @@ function equipmentStatBonus(stat, equipped) {
_(equipmentTypes).each(function(type) { _(equipmentTypes).each(function(type) {
var equippedItem = equipped[type] var equippedItem = equipped[type]
if(gear[equippedItem]) {
var equipmentStat = gear[equippedItem][stat]; var equipmentStat = gear[equippedItem][stat];
total += equipmentStat; total += equipmentStat;
}
}); });
return total; return total;
} }
function classBonus(user, stat) { function classBonus(user, stat) {
var bonus = user._statsComputed[stat] var computedStats = user._statsComputed;
if(computedStats) {
var bonus = computedStats[stat]
- user.stats.buffs[stat] - user.stats.buffs[stat]
- levelBonus(user.stats.lvl) - levelBonus(user.stats.lvl)
- equipmentStatBonus(stat, user.items.gear.equipped) - equipmentStatBonus(stat, user.items.gear.equipped)
@ -40,6 +44,7 @@ function classBonus(user, stat) {
return bonus; return bonus;
} }
}
module.exports = { module.exports = {
classBonus: classBonus, classBonus: classBonus,

View file

@ -78,5 +78,28 @@ describe('stat calculation functions', function() {
expect(classBonus).to.eql(20) expect(classBonus).to.eql(20)
}); });
it('does not return value if user has not been wrapped (_statComputed)', function() {
var equippedGear = {
"weapon" : "weapon_warrior_1",
"shield" : "shield_warrior_1",
"head" : "head_warrior_1",
"armor" : "armor_warrior_1"
};
var user = {
stats: {
lvl: 10,
buffs: { str: 10 },
str: 10
},
items: {
gear: { equipped: equippedGear }
}
};
var stat = 'str';
var classBonus = statCalc.classBonus(user, stat);
expect(classBonus).to.not.exist;
});
}); });
}); });