habitica/common/script/methods/statCalculations.js

49 lines
1.2 KiB
JavaScript
Raw Normal View History

2015-07-17 22:37:57 +00:00
'use strict';
var Content = require('../content.coffee');
function levelBonus(level) {
// Level bonus is derived by taking the level, subtracting one,
// taking the smaller of it or maxLevel (100),
// dividing that by two and then raising it to a whole number
// TODO: 100 is a magic number, extract from script.index into own module and call here
var levelOrMaxLevel = Math.min((level - 1), 100)
var levelDividedByTwo = levelOrMaxLevel / 2
var statBonus = Math.ceil(levelDividedByTwo )
return statBonus;
}
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;
}
2015-07-18 13:07:16 +00:00
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]
return bonus;
}
2015-07-17 22:37:57 +00:00
module.exports = {
2015-07-18 13:07:16 +00:00
classBonus: classBonus,
equipmentStatBonus: equipmentStatBonus,
levelBonus: levelBonus
2015-07-17 22:37:57 +00:00
}