Optional
boundsA function to provide the bounds of what level could be given currency
.
By default, the lower bound is 0 and the upper bound is currency
.
This can make calculations extremely inaccurate at higher currencies.
For example, if you have a currency that is 1e100, and you can only buy 102 upgrades with it, the function first has to binary search from 1e50, then to 1e25, then to 3.16e12, etc.
By providing a bounds function, you can make the calculations more accurate. For example, if you can only buy 102 upgrades with 1e100 currency, you can provide a bounds function that returns something like [0, 1000].
It should satisfy the following for all currency
>= 0 (and where cost' is the inverse of the cost function):
Basically, the bounds function should include the interval where the inverse cost function is within that interval, but the max bound should grow slower than the currency (y=x), for accurate calculations.
// Given a cost function,
const costFn = (n) => n.pow(2);
// the bounds function should be something like:
const boundsFn = (currency) => [new Decimal(0), currency.pow(0.75)];
// This is because the inverse of the cost function is n = sqrt(cost),
// and the maximum level that can be bought with the currency is the square root of the currency.
// So the bounds grows faster (y=x^0.75) than the inverse (y=x^0.5), but still slower than the currency (y=x).
The cost of upgrades at a certain level.
This function should evaluate to a non-negative number, and should be deterministic and continuous for all levels above 0.
Also, if you do not set your own costBulk
function, the function should always be greater than the level.
Optional
costThe cost of buying a bulk of upgrades at a certain level. (inverse of cost function). EL is automatically applied to the cost. WARNING: In v8.x.x and above, the return order is [amount, cost] instead of [cost, amount].
// A cost function that returns the sum of the levels and the target.
// In this example, the cost function is twice the level. The cost bulk function is the sum of the levels and the target.
// -target^2 + target + level^2 + level
(level, target) => target.pow(2).mul(-1).add(target).add(level.pow(2)).add(level)
Readonly
descriptionThe description of the upgrade. Can be a string or a function that returns a string.
// A dynamic description that returns a string
const description = (level) => `This upgrade is at level ${level}`;
// ... create upgrade here (see currencyStatic.addUpgrade)
const upgrade = currencyStatic.getUpgrade("upgradeID");
// Buy 1 level of the upgrade
currencyStatic.buyUpgrade("upgradeID", 1);
// Getter property
console.log(upgrade.description); // "This upgrade is at level 1"
Optional
effectThe effect of the upgrade. This runs when the upgrade is bought, and instantly if runEffectInstantly
is true.
The current level of the upgrade.
The upgrade object that the effect is being run on.
The currency static class that the upgrade is being run on.
Optional
elEndless / Everlasting: Flag to exclude the sum calculation and only perform binary search. Note: A function value is also allowed, and will be evaluated when the upgrade is bought or calculated. (but you should use a getter function instead)
Readonly
idThe ID of the upgrade. Used to retrieve the upgrade later.
Optional
maxThe maximum level of the upgrade. Warning: If not set, the upgrade will not have a maximum level and can continue to increase indefinitely.
The name of the upgrade. Defaults to the ID.
Interface for an upgrade.