diff --git a/common/script/methods/statCalculations.js b/common/script/methods/statCalculations.js index aac1880158..7b6826b63f 100644 --- a/common/script/methods/statCalculations.js +++ b/common/script/methods/statCalculations.js @@ -15,6 +15,23 @@ function levelBonus(level) { return statBonus; } -module.exports = { - levelBonus: levelBonus +function equipmentStatBonus(stat, equipped) { + var gear = Content.gear.flat; + var total = 0; + + var equipmentTypes = ['weapon', 'armor', 'head', 'shield']; + + _(equipmentTypes).each(function(type) { + var equippedItem = equipped[type] + var equipmentStat = gear[equippedItem][stat]; + + total += equipmentStat; + }); + + return total; +} + +module.exports = { + levelBonus: levelBonus, + equipmentStatBonus: equipmentStatBonus } diff --git a/test/common/statCalculations.js b/test/common/statCalculations.js index 9f996ca68d..68fa399132 100644 --- a/test/common/statCalculations.js +++ b/test/common/statCalculations.js @@ -7,7 +7,7 @@ var expect = chai.expect; var statCalc = require('../../common/script/methods/statCalculations'); describe('stat calculation functions', function() { - describe('calculateLevelStatBonus', function() { + describe('levelBonus', function() { it('calculates bonus as half of level for even numbered level under 100', function() { var level = 50; var bonus = statCalc.levelBonus(level); @@ -32,4 +32,25 @@ describe('stat calculation functions', function() { expect(bonus).to.eql(0); }); }); + + describe('equipmentStatBonus', function() { + it('tallies up stats from euqipment that is equipped', function() { + var equippedGear = { + "weapon" : "weapon_special_1", + "shield" : "shield_special_1", + "head" : "head_special_1", + "armor" : "armor_special_1" + }; + + var strStat = statCalc.equipmentStatBonus('str', equippedGear); + var conStat = statCalc.equipmentStatBonus('con', equippedGear); + var intStat = statCalc.equipmentStatBonus('int', equippedGear); + var perStat = statCalc.equipmentStatBonus('per', equippedGear); + + expect(strStat).to.eql(24); + expect(conStat).to.eql(24); + expect(intStat).to.eql(24); + expect(perStat).to.eql(24); + }); + }); });