From 163b0545e8f514667d9c2fffe896f527f2b24efb Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Sat, 18 Jul 2015 08:18:31 -0500 Subject: [PATCH] Adjustments for error handling --- common/script/methods/statCalculations.js | 21 +++++++++++++-------- test/common/statCalculations.js | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/common/script/methods/statCalculations.js b/common/script/methods/statCalculations.js index c5d6ab9a73..51a554f9cf 100644 --- a/common/script/methods/statCalculations.js +++ b/common/script/methods/statCalculations.js @@ -23,22 +23,27 @@ function equipmentStatBonus(stat, equipped) { _(equipmentTypes).each(function(type) { var equippedItem = equipped[type] - var equipmentStat = gear[equippedItem][stat]; + if(gear[equippedItem]) { + var equipmentStat = gear[equippedItem][stat]; - total += equipmentStat; + total += equipmentStat; + } }); return total; } function classBonus(user, stat) { - var bonus = user._statsComputed[stat] - - user.stats.buffs[stat] - - levelBonus(user.stats.lvl) - - equipmentStatBonus(stat, user.items.gear.equipped) - - user.stats[stat] + var computedStats = user._statsComputed; + if(computedStats) { + var bonus = computedStats[stat] + - user.stats.buffs[stat] + - levelBonus(user.stats.lvl) + - equipmentStatBonus(stat, user.items.gear.equipped) + - user.stats[stat] - return bonus; + return bonus; + } } module.exports = { diff --git a/test/common/statCalculations.js b/test/common/statCalculations.js index 40e0931a82..f0ffd38ce6 100644 --- a/test/common/statCalculations.js +++ b/test/common/statCalculations.js @@ -78,5 +78,28 @@ describe('stat calculation functions', function() { 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; + }); }); });