The name of the currency. This is optional, and you can use it for display purposes.
The upgrade names for the currency. See CurrencyStatic for more information.
Creates a new instance of the game class.
The parameters for the currency static class.
A pointer to the game instance.
The name of the currency. This is optional, and you can use it for display purposes.
ReadonlyboostA boost object that affects the currency gain.
ReadonlydefaultThe default boost of the currency.
ReadonlydefaultThe default value of the currency.
Optional ReadonlygameThe game pointer/reference
ReadonlyitemsAn array that represents items and their effects.
ReadonlynameThe name of the currency. This is optional, and you can use it for display purposes.
Protected ReadonlypointerA function that returns the pointer of the data
ReadonlyupgradesAn array that represents upgrades
ProtectedpointerThe static data for the currency.
Use this class as a static class as it now has all the properties of CurrencyStatic. This property is only here for backwards compatibility.
Creates upgrades. To update an upgrade, use updateUpgrade instead.
An array of upgrade objects.
Whether to run the effect immediately. Defaults to true.
The added upgrades.
currency.addUpgrade({
id: "healthBoost", // The ID of the upgrade, used to retrieve it later
name: "Health Boost", // The name of the upgrade, for display purposes (optional, defaults to the ID)
description: "Increases health by 10.", // The description of the upgrade, for display purposes (optional, defaults to "")
cost: (level) => level.mul(10), // Cost of the upgrade, 10 times the level
maxLevel: 10, // Maximum level of the upgrade (optional, defaults to 1)
// Effect of the upgrade (runs when the upgrade is bought, and instantly if runEffectInstantly is true)
effect: (level, context) => {
// Set / update the boost
// health: currencyStatic
health.boost.setBoost(
"healthBoost",
"Health Boost",
"Boosts health by 2x per level.",
n => n.mul(Decimal.pow(2, level.sub(1))),
2,
);
}
});
Buys an item based on its ID or array position if enough currency is available.
The ID or position of the item to buy or upgrade.
Optionaltier: DecimalSourceThe tier of the item that to calculate.
Optionaltarget: DecimalSourceThe target level or quantity to reach for the item. See the argument in calculateItem.
Returns true if the purchase or upgrade is successful, or false if there is not enough currency or the item does not exist.
Buys an upgrade based on its ID or array position if enough currency is available.
The ID or position of the upgrade to buy or upgrade.
Optionaltarget: DecimalSourceThe target level or quantity to reach for the upgrade. See the argument in calculateUpgrade.
Optionalmode: MeanModeSee the argument in calculateUpgrade.
Optionaliterations: numberSee the argument in calculateUpgrade.
Returns true if the purchase or upgrade is successful, or false if there is not enough currency or the upgrade does not exist.
Calculates the cost and how many items you can buy. See calculateItem for more information.
The ID or position of the item to calculate.
Optionaltier: DecimalSourceThe tier of the item that to calculate.
Optionaltarget: DecimalSourceThe target level or quantity to reach for the item. If omitted, it calculates the maximum affordable quantity.
The amount of items you can buy and the cost of the items. If you can't afford any, it returns [Decimal.dZero, Decimal.dZero].
Calculates the cost and how many upgrades you can buy. See calculateUpgrade for more information.
The ID or position of the upgrade to calculate.
The target level or quantity to reach for the upgrade. If omitted, it calculates the maximum affordable quantity.
Optionalmode: MeanModeSee the argument in calculateUpgrade.
Optionaliterations: numberSee the argument in calculateUpgrade.
The amount of upgrades you can buy and the cost of the upgrades. If you can't afford any, it returns [Decimal.dZero, Decimal.dZero].
The new currency value after applying the boost.
Delta time / multiplier in milliseconds, assuming you gain once every second. Ex. 500 = 0.5 seconds = half gain.
What was gained, NOT the new value.
Retrieves an item object based on the provided id.
The id of the item to retrieve.
The item object if found, otherwise null.
Calculates how much is needed for the next upgrade.
Index or ID of the upgrade
How many before the next upgrade
Optionalmode: MeanModeSee the argument in calculateUpgrade.
Optionaliterations: numberSee the argument in calculateUpgrade.
The cost of the next upgrade.
Use getNextCostMax instead as it is more versatile.
Calculates the cost of the next upgrade after the maximum affordable quantity.
Index or ID of the upgrade
How many before the next upgrade
Optionalmode: MeanModeSee the argument in calculateUpgrade.
Optionaliterations: numberSee the argument in calculateUpgrade.
The cost of the next upgrade.
// Calculate the cost of the next healthBoost upgrade
currency.gain(1e6); // Gain 1 thousand currency
console.log(currency.calculateUpgrade("healthBoost")); // The maximum affordable quantity and the cost of the upgrades. Ex. [new Decimal(100), new Decimal(1000)]
console.log(currency.getNextCostMax("healthBoost")); // The cost of the next upgrade after the maximum affordable quantity. (The cost of the 101st upgrade)
Retrieves an upgrade object based on the provided id.
The id of the upgrade to retrieve.
The upgrade object if found, otherwise null.
Queries upgrades based on the provided id. Returns an array of upgrades that match the id.
The id of the upgrade to query.
An array of upgrades that match the id.
const currency = new CurrencyStatic(undefined, [
{ id: "healthBoostSmall", cost: (level) => level.mul(10) },
{ id: "healthBoostLarge", cost: (level) => level.mul(20) },
{ id: "damageBoostSmall", cost: (level) => level.mul(10) },
{ id: "damageBoostLarge", cost: (level) => level.mul(20) },
] as const satisfies UpgradeInit[]);
// Get all health upgrades
const healthUpgrades = currency.queryUpgrade(/health/); // [{ id: "healthBoostSmall", ... }, { id: "healthBoostLarge", ... }]
// Get all small upgrades
const smallUpgrades = currency.queryUpgrade(["healthBoostSmall", "damageBoostSmall"]);
// or
const smallUpgrades2 = currency.queryUpgrade(/.*Small/);
Resets the currency and upgrade levels.
OptionalresetCurrency: booleanWhether to reset the currency value. Default is true.
OptionalresetUpgradeLevels: booleanWhether to reset the upgrade levels. Default is true.
OptionalrunUpgradeEffect: booleanWhether to run the upgrade effect. Default is true.
Optionalreset: Partial<CurrencyStaticResetOptions>Runs the effect of an upgrade or item.
The item to run the effect for.
The tier of the item that was bought.
Runs the effect of an upgrade or item.
The upgrade to run the effect for.
Updates an upgrade. To create an upgrade, use addUpgrade instead.
The id of the upgrade to update.
The new upgrade object.
Represents a game currency. Currency is the data class. This class extends CurrencyStatic and adds additional functionality for Game.