An interface for an item. An item is a type of upgrade that does not have a level. Ex. A potion that gives you 10 gold.

interface ItemInit {
    amount?: Decimal;
    cost: ((level: Decimal) => Decimal);
    description?: string | ((level: Decimal, itemContext: Item, currencyContext: CurrencyStatic<[], string, [], string>) => string);
    effect?: ((tier: Decimal, amount: Decimal, itemContext: Item, currencyContext: CurrencyStatic<[], string, [], string>) => void);
    id: string;
    name?: string;
}

Implemented by

Properties

amount?: Decimal

The default amount of the item. Automatically set to 0 if not provided.

This does not account for items that were bought on different tiers. You should use your own amount system.

cost: ((level: Decimal) => Decimal)

The cost of items at a certain level.

Type declaration

    • (level): Decimal
    • Parameters

      • level: Decimal

        The level that the cost is being calculated for.

      Returns Decimal

      The cost of the item. It should be a non-negative integer greater than or equal to 0.

// An item that costs 10 times the level
(level) => level.mul(10);
description?: string | ((level: Decimal, itemContext: Item, currencyContext: CurrencyStatic<[], string, [], string>) => string)

The description of the item. Can be a string or a function that returns a string.

The current level of the item.

The item object that the description is being run on.

The currency static class that the item is being run on.

// A dynamic description that returns a string
const description = (a, b) => `This is a ${a} that returns a ${b}`;

// ... create item here (see currencyStatic.addUpgrade)

const item = currencyStatic.getUpgrade("itemID");

// Getter property
console.log(item.description); // "This is a undefined that returns a undefined"

// Getter function
console.log(item.descriptionFn("dynamic", "string")); // "This is a dynamic that returns a string"
effect?: ((tier: Decimal, amount: Decimal, itemContext: Item, currencyContext: CurrencyStatic<[], string, [], string>) => void)

The effect of the item. This runs when the item is bought, and instantly if runEffectInstantly is true.

Type declaration

    • (tier, amount, itemContext, currencyContext): void
    • Parameters

      • tier: Decimal

        The tier of the item that was bought.

      • amount: Decimal

        The amount of the item currently owned.

      • itemContext: Item

        The item object that the effect is being run on.

      • currencyContext: CurrencyStatic<[], string, [], string>

        The currency static class that the item is being run on.

      Returns void

id: string

The ID of the item. Used to retrieve the item later.

name?: string

The name of the item. Defaults to the ID.