Add cost requirement example to requirements guide

This commit is contained in:
Anthony Lawn 2023-04-24 10:43:22 -05:00 committed by GitHub
parent 4354830460
commit 155420e302
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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.
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
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.