Represents an item.

Implements

Constructors

  • Creates a new item.

    Parameters

    • init: ItemInit

      The initialization data for the item.

    • dataPointer: Pointer<ItemData>

      The pointer to the data of the item.

    • currencyPointer: Pointer<CurrencyStatic<[], string, [], string>>

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

    Returns Item

Properties

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);
currencyPointerFn: (() => CurrencyStatic<[], string, [], string>)

Type declaration

    • (): CurrencyStatic<[], string, [], string>
    • Returns CurrencyStatic<[], string, [], string>

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

defaultAmount: Decimal = Decimal.dZero
effect: undefined | ((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.

The tier of the item that was bought.

The amount of the item currently owned.

The item object that the effect is being run on.

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

id: string

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

name: string

The name of the item. Defaults to the ID.

Accessors

  • get amount(): Decimal
  • The amount of the item that was bought.

    Returns Decimal

    The amount of the item that was bought.

    This does not account for items that were bought on different tiers.

  • set amount(n): void
  • The default amount of the item. Automatically set to 0 if not provided.

    Parameters

    Returns void

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

  • get description(): string
  • The description of the item. Can be a string or a function that returns a string.

    Returns string

    // 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"
  • set description(value): void
  • The description of the item. Can be a string or a function that returns a string.

    Parameters

    Returns void

    // 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"