mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 07:37:25 +01:00
Add calculation for equipment stat bonus
This commit is contained in:
@@ -15,6 +15,23 @@ function levelBonus(level) {
|
|||||||
return statBonus;
|
return statBonus;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
function equipmentStatBonus(stat, equipped) {
|
||||||
levelBonus: levelBonus
|
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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ var expect = chai.expect;
|
|||||||
var statCalc = require('../../common/script/methods/statCalculations');
|
var statCalc = require('../../common/script/methods/statCalculations');
|
||||||
|
|
||||||
describe('stat calculation functions', function() {
|
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() {
|
it('calculates bonus as half of level for even numbered level under 100', function() {
|
||||||
var level = 50;
|
var level = 50;
|
||||||
var bonus = statCalc.levelBonus(level);
|
var bonus = statCalc.levelBonus(level);
|
||||||
@@ -32,4 +32,25 @@ describe('stat calculation functions', function() {
|
|||||||
expect(bonus).to.eql(0);
|
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user