Add cost requirement example to requirements guide
This commit is contained in:
parent
4354830460
commit
155420e302
1 changed files with 12 additions and 0 deletions
|
@ -6,6 +6,18 @@ The requirements system in Profectus is designed to handle various conditions th
|
||||||
|
|
||||||
To create a requirement, you can use one of the provided utility functions like [createCostRequirement](/api/modules/game/requirements#createcostrequirement), [createVisibilityRequirement](/api/modules/game/requirements#createvisibilityrequirement), or [createBooleanRequirement](/api/modules/game/requirements#createbooleanrequirement). These functions return a `Requirement` object with specific properties that define the requirement conditions.
|
To create a requirement, you can use one of the provided utility functions like [createCostRequirement](/api/modules/game/requirements#createcostrequirement), [createVisibilityRequirement](/api/modules/game/requirements#createvisibilityrequirement), or [createBooleanRequirement](/api/modules/game/requirements#createbooleanrequirement). These functions return a `Requirement` object with specific properties that define the requirement conditions.
|
||||||
|
|
||||||
|
Cost requirements are probably the most common requirement you'll be using. For something with multiple levels, like repeatables, you'll typically want to use a formula for the cost instead of a function, and the input to the formula will be the repeatable's `amount` property. Typically that means the code will look like this:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
createRepeatable(repeatable => ({
|
||||||
|
requirements: createCostRequirement(() => ({
|
||||||
|
resource: points,
|
||||||
|
cost: Formula.variable(repeatable.amount).add(1).times(100)
|
||||||
|
}))
|
||||||
|
}));
|
||||||
|
```
|
||||||
|
Important to note here is the parameter added to the `createRepeatable`'s options function. That is a reference to the repeatable being created, so you can access it's `amount` property in the formula.
|
||||||
|
|
||||||
## Using Requirements
|
## Using Requirements
|
||||||
|
|
||||||
Several features will have a `requirements` property that takes one or more requirements that must be fulfilled for a certain action to be performed with that feature.
|
Several features will have a `requirements` property that takes one or more requirements that must be fulfilled for a certain action to be performed with that feature.
|
||||||
|
|
Loading…
Reference in a new issue