• Calculates the cost and how many upgrades you can buy Uses inverseFunctionApprox to calculate the maximum affordable quantity. The priority is: target === 1 > costBulk > el. For sum upgrades, this function has a max time complexity of O(n^2) where n is the number of iterations. For el upgrades, this function has a max time complexity of O(n) where n is the number of iterations.

    Parameters

    • value: DecimalSource

      The current value of the currency.

    • upgrade: UpgradeStatic

      The upgrade object to calculate.

    • Optionalstart: DecimalSource

      The starting level of the upgrade. Defaults the current level of the upgrade.

    • end: DecimalSource = Decimal.dInf

      The ending level or quantity to reach for the upgrade. If not provided, it will buy the maximum amount of upgrades possible (using target = Infinity).

    • Optionalmode: MeanMode

      The mode/mean method to use. See MeanMode

    • Optionaliterations: number

      The amount of iterations to perform. Defaults to 15.

    • el: boolean = false

      ie Endless: Flag to exclude the sum calculation and only perform binary search. (DEPRECATED, use el in the upgrade object instead)

    Returns [amount: Decimal, cost: Decimal]

    [amount, cost] - Returns 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].