mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-05-17 19:28:42 +00:00
Adjustments for error handling
This commit is contained in:
parent
6d5b57d139
commit
163b0545e8
2 changed files with 36 additions and 8 deletions
|
|
@ -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 = {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue