Module: game/formulas/formulas
Classes
InternalFormula
• Abstract
InternalFormula<T
>: Object
Type parameters
Name | Type |
---|---|
T | extends [FormulaSource ] | FormulaSource [] |
Defined in
profectus/src/game/formulas/formulas.ts:43
profectus/src/game/formulas/formulas.ts:51
default
• default<T
>: Object
A class that can be used for cost/goal functions. It can be evaluated similar to a cost function, but also provides extra features for supported formulas. For example, a lot of math functions can be inverted. Typically, the use of these extra features is to support cost/goal functions that have multiple levels purchased/completed at once efficiently.
See
- calculateMaxAffordable
- /game/requirements.createCostRequirement
Type parameters
Name | Type |
---|---|
T | extends [FormulaSource ] | FormulaSource [] |
Defined in
profectus/src/game/formulas/formulas.ts:1249
Functions
calculateCost
▸ calculateCost(formula
, amountToBuy
, cumulativeCost?
, directSum?
): DecimalSource
Utility for calculating the cost of a formula for a given amount of purchases. If cumulativeCost is changed to false, the calculation will be much faster with higher numbers.
Parameters
Name | Type | Description |
---|---|---|
formula | InvertibleFormula | The formula to use for calculating buy max from |
amountToBuy | DecimalSource | The amount of purchases to calculate the cost for |
cumulativeCost? | true | Whether or not to count spent resources on each purchase or not. If true, costs will be approximated for performance, skewing towards higher cost |
directSum? | number | How many purchases to manually sum for improved accuracy. If not specified, defaults to 10 when cost is cumulative and 0 when not |
Returns
Other signatures
▸ calculateCost(formula
, amountToBuy
, cumulativeCost
, directSum?
): DecimalSource
Name | Type |
---|---|
formula | InvertibleIntegralFormula |
amountToBuy | DecimalSource |
cumulativeCost | boolean |
directSum? | number |
Defined in
profectus/src/game/formulas/formulas.ts:1498
profectus/src/game/formulas/formulas.ts:1504
profectus/src/game/formulas/formulas.ts:1510
calculateMaxAffordable
▸ calculateMaxAffordable(formula
, resource
, cumulativeCost?
, directSum?
, maxBulkAmount?
): ComputedRef
<default
| 0
>
Utility for calculating the maximum amount of purchases possible with a given formula and resource. If cumulativeCost is changed to false, the calculation will be much faster with higher numbers.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
formula | GenericFormula | undefined | The formula to use for calculating buy max from |
resource | Resource <DecimalSource > | undefined | The resource used when purchasing (is only read from) |
cumulativeCost | Computable <boolean > | true | Whether or not to count spent resources on each purchase or not. If true, costs will be approximated for performance, skewing towards fewer purchases |
directSum? | Computable <number > | undefined | How many of the most expensive purchases should be manually summed for better accuracy. If unspecified uses 10 when spending resources and 0 when not |
maxBulkAmount | Computable <DecimalSource > | Decimal.dInf | Cap on how many can be purchased at once. If equal to 1 or lte to directSum then the formula does not need to be invertible. Defaults to Infinity. |
Returns
ComputedRef
<default
| 0
>
Defined in
profectus/src/game/formulas/formulas.ts:1419
findNonInvertible
▸ findNonInvertible(formula
): GenericFormula
| null
Utility for recursively searching through a formula for the cause of non-invertibility.
Parameters
Name | Type | Description |
---|---|---|
formula | GenericFormula | The formula to search for a non-invertible formula within |
Returns
GenericFormula
| null
Defined in
profectus/src/game/formulas/formulas.ts:1375
hasVariable
▸ hasVariable(value
): value is InvertibleFormula
Name | Type |
---|---|
value | FormulaSource |
Defined in
profectus/src/game/formulas/formulas.ts:24
printFormula
▸ printFormula(formula
): string
Stringifies a formula so it's more easy to read in the console
Parameters
Name | Type | Description |
---|---|---|
formula | FormulaSource | The formula to print |
Returns
string
Defined in
profectus/src/game/formulas/formulas.ts:1393
unrefFormulaSource
▸ unrefFormulaSource(value
, variable?
): DecimalSource
Name | Type |
---|---|
value | FormulaSource |
variable? | DecimalSource |