Skip to content

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.

MemberWhat it does
check(entity: Entity) -> boolDoes the entity meet the requirement? The one function a type must implement
get_failure_message(entity) -> StringWhy it is not met, with the entity's numbers: "Requires level 20 (you are level 12)"
get_summary() -> StringA 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]:

FunctionReturns
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:

TypeSignal it watches
Levelentity_leveled_up
Statentity_stat_changed (only for its own stat)
Equipment Slotequipment_changed (only for its own slot)
Player Classthe class change signal of the player (Player entities only)

Where they are stored and checked ​

OwnerPropertyChecked by
AbilityDefinitionrequirementsActiveAbilityDefinition (through RequirementChecker) and the ability instance (reactive)
EffectrequirementsEffect.check_requirements(entity): the first failed one rejects the effect and gives its message
ItemDefinitionrequirementscheck_requirements, meets_requirements, get_requirement_failure_message
Questrequirementscan_accept, get_failed_requirements, get_requirement_failure_messages
CraftingRecipeDefinitionrequirementsits craft check, which lists the failure messages of the unmet ones
CraftSchoolDefinitionlearning_requirementsthe check for learning the school
ConversationResponseresponse_requirementsConversationInstance, which offers only the responses that pass

Writing your own requirement ​

  1. Make a script that extends Requirement, with @tool and a class_name, in your project folder res://src/requirements/ (the addon's own data_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.
  2. Add @export properties for its settings. They are the fields the dialog shows.
  3. Implement check, get_failure_message and get_summary.
  4. If the answer can change while the game runs, connect to the entity's signal in connect_to_entity_signals and emit requirement_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_kills

The classes ​

ClassWhat it is
RequirementBase class for all requirement types in the game.
RequirementAbilityRankNeeds 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.
RequirementCheckerUtility class for checking requirements and generating feedback Can be used as a static utility or instantiated for batch checking
RequirementEquipmentSlotRequires entity to have equipment in specific slot
RequirementFactionRequires entity to have a minimum reputation with a faction
RequirementKnowsAbilityNeeds the entity to have an ability, optionally at a rank: "needs Fireball to learn Fireball II".
RequirementKnowsRecipeNeeds the character to know a crafting recipe (learned, or given by the profession, or by a specialization).
RequirementLevelRequires 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)
RequirementPlayerClassDefinitionRequires entity to be one of the specified player classes
RequirementProfessionNeeds a profession (a craft school): learned, and optionally at a skill level or in a tier.
RequirementProficiencyRequires a level in a proficiency (swords, heavy armor, lockpicking): "needs Plate 25 to wear this".
RequirementResponseSeenRequirement that checks if a player has seen/selected a specific response Useful for branching conversations based on player choices
RequirementSkillNodeNeeds 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.
RequirementSkillTierNeeds 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).
RequirementSkillTreePointsNeeds a number of points spent in a skill tree of the player (and optionally not more than a number).
RequirementSpecializationNeeds a specialization of a proficiency or a profession (or needs that the character does NOT have it).
RequirementStatRequires entity to have a minimum value in a specific stat
RequirementWeaponRequires entity to have specific weapon types equipped