The interface for initializing a skill tree node.

interface SkillInit {
    bounds?: ((currency: Decimal, start: Decimal, end: Decimal) => [min: Decimal, max: Decimal]);
    cost: [currency: CurrencyStatic<[], string, [], string>, cost: ((level: Decimal, context: SkillInit) => Decimal)];
    costBulk?: [currency: CurrencyStatic<[], string, [], string>, cost: ((level: Decimal, context: SkillInit) => [cost: Decimal, amount: Decimal])];
    description?: string | ((level: Decimal, upgradeContext: UpgradeStatic, currencyContext: CurrencyStatic<[], string, [], string>) => string);
    effect?: ((level: Decimal, context: SkillNode) => void);
    el?: boolean | (() => boolean);
    id: string;
    level?: Decimal;
    maxLevel?: Decimal;
    name?: string;
    required?: (RequiredSkill | SkillNode)[] | ((skillTreeContext: SkillTree) => (RequiredSkill | SkillNode)[]);
}

Hierarchy

  • Omit<UpgradeInit,
        | "costBulk"
        | "effect"
        | "cost"
        | "descriptionFn"
        | "defaultLevel">
    • SkillInit

Implemented by

Properties

bounds?: ((currency: Decimal, start: Decimal, end: Decimal) => [min: Decimal, max: Decimal])

A 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):

  • 0 <= min < cost'(currency) < max < currency

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.

Type declaration

    • (currency, start, end): [min: Decimal, max: Decimal]
    • Parameters

      • currency: Decimal

        The currency value.

      • start: Decimal

        The starting level of the upgrade.

      • end: Decimal

        The ending level or quantity to reach for the upgrade.

      Returns [min: Decimal, max: Decimal]

      [min, max] - The minimum and maximum level that can be bought with the currency.

// 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).
cost: [currency: CurrencyStatic<[], string, [], string>, cost: ((level: Decimal, context: SkillInit) => Decimal)]

The cost of the skill tree node. [currency, cost] - The currency and cost of the skill tree node.

costBulk?: [currency: CurrencyStatic<[], string, [], string>, cost: ((level: Decimal, context: SkillInit) => [cost: Decimal, amount: Decimal])]

A function that returns the cost of buying multiple levels of the skill.

description?: string | ((level: Decimal, upgradeContext: UpgradeStatic, currencyContext: CurrencyStatic<[], string, [], string>) => string)

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

The current level of the upgrade.

The upgrade object that the description is being run on.

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

// 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"
effect?: ((level: Decimal, context: SkillNode) => void)

The effect of the skill tree node.

Type declaration

    • (level, context): void
    • Parameters

      • level: Decimal

        The level of the skill tree node.

      • context: SkillNode

        The skill tree node.

      Returns void

el?: boolean | (() => boolean)

Endless / 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)

id: string

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

level?: Decimal

The default level of the upgrade. Automatically set to 1 if not provided.

maxLevel?: Decimal

The maximum level of the upgrade. Warning: If not set, the upgrade will not have a maximum level and can continue to increase indefinitely.

name?: string

The name of the upgrade. Defaults to the ID.

required?: (RequiredSkill | SkillNode)[] | ((skillTreeContext: SkillTree) => (RequiredSkill | SkillNode)[])

The skill nodes that are required to unlock this skill node. See RequiredSkill for more information. Can also be a function that takes the skill tree context and returns the required skills.