bitburner-src/src/utils/calculateEffectWithFactors.ts

25 lines
1005 B
TypeScript
Raw Normal View History

/**
* This is a component that implements a mathematical formula used commonly throughout the
* game. This formula is (typically) used to calculate the effect that various statistics
* have on a game mechanic. It looks something like:
*
* (stat ^ exponential factor) + (stat / linear factor)
*
* where the exponential factor is a number between 0 and 1 and the linear factor
* is typically a relatively larger number.
*
* This formula ensures that the effects of the statistic that is being processed
* has diminishing returns, but never loses its effectiveness as you continue
* to raise it.
*/
2021-09-09 05:47:34 +02:00
export function calculateEffectWithFactors(n: number, expFac: number, linearFac: number): number {
2021-09-05 01:09:30 +02:00
if (expFac <= 0 || expFac >= 1) {
2021-09-09 05:47:34 +02:00
console.warn(`Exponential factor is ${expFac}. This is not an intended value for it`);
2021-09-05 01:09:30 +02:00
}
if (linearFac < 1) {
2021-09-09 05:47:34 +02:00
console.warn(`Linear factor is ${linearFac}. This is not an intended value for it`);
2021-09-05 01:09:30 +02:00
}
2021-09-05 01:09:30 +02:00
return Math.pow(n, expFac) + n / linearFac;
}