refactor(stats): Math helpers ES2015 module

This commit is contained in:
Sabe Jones
2015-11-17 15:41:26 -05:00
parent 8b7f50bfcf
commit 4bf20959dd
3 changed files with 121 additions and 57 deletions

View File

@@ -13,6 +13,14 @@ api = module.exports = {};
api.i18n = i18n;
import statHelpers from './statHelpers.js'
api.maxLevel = statHelpers.maxLevel;
api.capByLevel = statHelpers.capByLevel;
api.maxHealth = statHelpers.maxHealth;
api.tnl = statHelpers.tnl;
api.diminishingReturns = statHelpers.diminishingReturns;
$w = api.$w = function(s) {
return s.split(' ');
};
@@ -182,63 +190,6 @@ api.shouldDo = function(day, dailyTask, options) {
}
};
/*
------------------------------------------------------
Level cap
------------------------------------------------------
*/
api.maxLevel = 100;
api.capByLevel = function(lvl) {
if (lvl > api.maxLevel) {
return api.maxLevel;
} else {
return lvl;
}
};
/*
------------------------------------------------------
Health cap
------------------------------------------------------
*/
api.maxHealth = 50;
/*
------------------------------------------------------
Scoring
------------------------------------------------------
*/
api.tnl = function(lvl) {
return Math.round(((Math.pow(lvl, 2) * 0.25) + (10 * lvl) + 139.75) / 10) * 10;
};
/*
A hyperbola function that creates diminishing returns, so you can't go to infinite (eg, with Exp gain).
{max} The asymptote
{bonus} All the numbers combined for your point bonus (eg, task.value * user.stats.int * critChance, etc)
{halfway} (optional) the point at which the graph starts bending
*/
api.diminishingReturns = function(bonus, max, halfway) {
if (halfway == null) {
halfway = max / 2;
}
return max * (bonus / (bonus + halfway));
};
api.monod = function(bonus, rateOfIncrease, max) {
return rateOfIncrease * max * bonus / (rateOfIncrease * bonus + max);
};
/*
Preen history for users with > 7 history entries
This takes an infinite array of single day entries [day day day day day...], and turns it into a condensed array