mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-08-03 08:21:07 +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) {
|
_(equipmentTypes).each(function(type) {
|
||||||
var equippedItem = equipped[type]
|
var equippedItem = equipped[type]
|
||||||
var equipmentStat = gear[equippedItem][stat];
|
if(gear[equippedItem]) {
|
||||||
|
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;
|
||||||
- user.stats.buffs[stat]
|
if(computedStats) {
|
||||||
- levelBonus(user.stats.lvl)
|
var bonus = computedStats[stat]
|
||||||
- equipmentStatBonus(stat, user.items.gear.equipped)
|
- user.stats.buffs[stat]
|
||||||
- user.stats[stat]
|
- levelBonus(user.stats.lvl)
|
||||||
|
- equipmentStatBonus(stat, user.items.gear.equipped)
|
||||||
|
- user.stats[stat]
|
||||||
|
|
||||||
return bonus;
|
return bonus;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue