Requirements: how they are built ​
A requirement is a small Resource stored inside the resource that uses it (an ability, an item, a quest ...), in an Array[Requirement]. It is not in the Database: it has no id and no file of its own, it is saved with its owner. The Basic guide explains how to use them.
The base class ​
Requirement extends Resource and is pure validation: it never changes anything.
| Member | What it does |
|---|---|
check(entity: Entity) -> bool | Does the entity meet the requirement? The one function a type must implement |
get_failure_message(entity) -> String | Why it is not met, with the entity's numbers: "Requires level 20 (you are level 12)" |
get_summary() -> String | A short description for tooltips: "Requires level 20" |
connect_to_entity_signals(entity) and disconnect_from_entity_signals(entity) | Connect to the signals of the entity that can change the answer (level up, stat change, equipment change, class change). Optional |
signal requirement_state_changed(requirement, entity) | Emitted by a type when the answer may have changed |
validate() -> Array[Dictionary] | Configuration problems as {type, message, severity} entries ("warning" or "error"); empty when it is fine. A type overrides it to point out settings that make it useless |
Checking a list ​
RequirementChecker is a static utility that works on an Array[Requirement]:
| Function | Returns |
|---|---|
check_all(entity, requirements) | A dictionary: passed (bool), failures (an entry for each failed requirement with requirement_type, failure_message and summary), and all_checked |
meets_all_requirements(entity, requirements) | true when every requirement passes (an empty list passes; a null entry is skipped) |
get_failure_message(entity, requirements) | The messages of the failed requirements, one per line, or an empty string |
get_requirements_summary(requirements) | The summaries, one per line, for a tooltip |
validate_requirements(requirements) | Every problem of the list, each with requirement_index and requirement_type added (a null entry gives a NULL_REQUIREMENT error with its index). For the editor's warnings |
Every requirement in a list must pass. There is no "any": a different shape of rule is a Condition.
Reactive requirements ​
An ability that has requirements watches them. When the ability is set up (AbilityInstance.setup_requirement_monitoring) each requirement connects itself to the signals of the user, and the ability listens to requirement_state_changed. The answer is re-checked then (check_and_update_requirement_state): an ability whose requirements stop holding goes INACTIVE, and goes back to READY (or ON_COOLDOWN) when they hold again. A passive ability also removes its passive effects while it is inactive, and applies them again when it is active. A type that wants this implements the two connect_... functions and emits the signal; the shipped ones do:
| Type | Signal it watches |
|---|---|
| Level | entity_leveled_up |
| Stat | entity_stat_changed (only for its own stat) |
| Equipment Slot | equipment_changed (only for its own slot) |
| Player Class | the class change signal of the player (Player entities only) |
Where they are stored and checked ​
| Owner | Property | Checked by |
|---|---|---|
AbilityDefinition | requirements | ActiveAbilityDefinition (through RequirementChecker) and the ability instance (reactive) |
Effect | requirements | Effect.check_requirements(entity): the first failed one rejects the effect and gives its message |
ItemDefinition | requirements | check_requirements, meets_requirements, get_requirement_failure_message |
Quest | requirements | can_accept, get_failed_requirements, get_requirement_failure_messages |
CraftingRecipeDefinition | requirements | its craft check, which lists the failure messages of the unmet ones |
CraftSchoolDefinition | learning_requirements | the check for learning the school |
ConversationResponse | response_requirements | ConversationInstance, which offers only the responses that pass |
Writing your own requirement ​
- Make a script that
extends Requirement, with@tooland aclass_name, in your project folderres://src/requirements/(the addon's owndata_classes/requirements/types/is found too, but an update of the addon replaces it). The editor's add dialog lists every script of both folders, and the name in the list is made from the file name. - Add
@exportproperties for its settings. They are the fields the dialog shows. - Implement
check,get_failure_messageandget_summary. - If the answer can change while the game runs, connect to the entity's signal in
connect_to_entity_signalsand emitrequirement_state_changed.
gdscript
@tool
class_name RequirementKills extends Requirement
## Requires the entity to have killed a number of enemies
@export var minimum_kills: int = 10
func check(entity: Entity) -> bool:
return entity != null and int(entity.get_meta("kills", 0)) >= minimum_kills
func get_failure_message(entity: Entity) -> String:
return "Requires %d kills" % minimum_kills
func get_summary() -> String:
return "Requires %d kills" % minimum_killsThe classes ​
| Class | What it is |
|---|---|
| Requirement | Base class for all requirement types in the game. |
| RequirementAbilityRank | Needs the ability that uses the effect to be at a rank: put it on an effect of an ability so that rank 3 adds the burn and rank 5 the second projectile. |
| RequirementChecker | Utility class for checking requirements and generating feedback Can be used as a static utility or instantiated for batch checking |
| RequirementEquipmentSlot | Requires entity to have equipment in specific slot |
| RequirementFaction | Requires entity to have a minimum reputation with a faction |
| RequirementKnowsAbility | Needs the entity to have an ability, optionally at a rank: "needs Fireball to learn Fireball II". |
| RequirementKnowsRecipe | Needs the character to know a crafting recipe (learned, or given by the profession, or by a specialization). |
| RequirementLevel | Requires the entity to be at or above a level, and optionally at or below another (a level range: a buff that only works up to level 60) |
| RequirementPlayerClassDefinition | Requires entity to be one of the specified player classes |
| RequirementProfession | Needs a profession (a craft school): learned, and optionally at a skill level or in a tier. |
| RequirementProficiency | Requires a level in a proficiency (swords, heavy armor, lockpicking): "needs Plate 25 to wear this". |
| RequirementResponseSeen | Requirement that checks if a player has seen/selected a specific response Useful for branching conversations based on player choices |
| RequirementSkillNode | Needs a node of a skill tree to be unlocked (a rank of it, or one choice of a choice node), or needs that it is NOT. |
| RequirementSkillTier | Needs a proficiency or a profession to be in a tier (Journeyman or higher), or to be at the cap of its tier (ready to be trained further). |
| RequirementSkillTreePoints | Needs a number of points spent in a skill tree of the player (and optionally not more than a number). |
| RequirementSpecialization | Needs a specialization of a proficiency or a profession (or needs that the character does NOT have it). |
| RequirementStat | Requires entity to have a minimum value in a specific stat |
| RequirementWeapon | Requires entity to have specific weapon types equipped |