AbilityComponent ​
Inherits: RefCounted
AbilityComponent orchestrates ability instances for an entity. Manages collections, routes use attempts, and handles global cooldown. Passive effect application is fully owned by AbilityInstance - this component does not touch passive effect state directly.
Variables ​
Entity | user | null |
AbilityInstance | basic_attack | null |
AbilityInstance | original_basic_attack_instance | null |
Array[AbilityInstance] | active_abilities | [] |
Array[AbilityInstance] | passive_abilities | [] |
Timer | global_cooldown_timer | null |
ChronoManager | chrono_manager | |
GameHost.SystemHub | system_hub | |
Dictionary | group_cooldown_timers | {} |
Dictionary | locked_schools | {} |
AbilityInstance | weapon_basic_attack | null |
Methods ​
void | refresh_npc_ranks() |
void | add_rank_bonus( source: Variant, bonus: int, ability_ids: Array, group_ids: Array, school_ids: Array, all: bool = false ) |
void | remove_rank_bonus( source: Variant ) |
int | get_rank_bonus_for( ability_def: AbilityDefinition ) |
void | setup_starting_abilites() |
bool | add_basic_attack_instance( ability_instance: AbilityInstance ) |
bool | swap_basic_attack( ability_instance: AbilityInstance ) |
bool | remove_basic_attack() |
bool | add_active_ability_instance( ability_instance: AbilityInstance ) |
bool | add_passive_ability_instance( ability_instance: AbilityInstance ) |
bool | remove_active_ability_by_id( ability_id: int ) |
bool | remove_active_ability_instance( ability_instance: AbilityInstance ) |
bool | remove_passive_ability_by_id( ability_id: int ) |
bool | remove_passive_ability_instance( ability_instance: AbilityInstance ) |
void | deactivate_all_toggles() |
AbilityInstance | get_ability_instance_by_id( ability_id: int ) |
AbilityInstance | get_active_ability_instance_by_id( ability_id: int ) |
AbilityInstance | get_passive_ability_instance_by_id( ability_id: int ) |
AbilityInstance | get_ability_instance_by_name( ability_name: String ) |
AbilityInstance | get_active_ability_instance_by_name( ability_name: String ) |
AbilityInstance | get_passive_ability_instance_by_name( ability_name: String ) |
Array[AbilityInstance] | get_all_ability_instances() |
void | modify_ability_property( ability_name: String, property_name: String, effect_value: float, calculation_type: int, source: Variant = "stat" ) |
void | clear_ability_property_modifiers( source: Variant ) |
AbilityInstance.AbilityUseAttemptResult | attempt_use_basic_attack() |
AbilityInstance.AbilityUseAttemptResult | attempt_use_ability_instance( ability_instance: AbilityInstance, target: Variant, from_action: bool ) |
AbilityInstance.AbilityUseAttemptResult | attempt_use_ability_by_id( ability_id: int, target: Variant, from_action: bool ) |
bool | is_on_global_cooldown() |
float | get_global_cooldown_remaining() |
Dictionary | to_save_data() |
void | from_save_data( save_data: Dictionary ) |
void | cleanup_timers() |
void | cleanup() |
AbilityInstance | get_passive_ability_by_id( ability_id: int ) |
void | lock_school( school_id: int ) |
void | unlock_school( school_id: int ) |
bool | is_school_locked( school_id: int ) |
void | start_group_cooldowns( group_ids: Array[int], own_duration: float, source: Variant = null ) |
float | get_group_cooldown_remaining( group_ids: Array[int] ) |
void | set_weapon_basic_attack( ability_id: int ) |
void | clear_weapon_basic_attack() |
Signals ​
ability_use_attempt_rejected( user: Entity, ability_instance: AbilityInstance, use_result: AbilityInstance.AbilityUseAttemptResult ) ​
========== SIGNALS ==========
ability_use_attempt_approved( user: Entity, ability_instance: AbilityInstance ) ​
Emitted when an attempt to use an ability passed every check and the ability is going to run.
global_cooldown_started() ​
Emitted when the global cooldown starts.
global_cooldown_ended() ​
Emitted when the global cooldown ends.
ability_learned( ability_instance: AbilityInstance, ability_type: String ) ​
Emitted when the entity learns an ability: the instance and its type (active or passive).
ability_forgotten( ability_instance: AbilityInstance, ability_type: String ) ​
Emitted when the entity loses an ability: the instance and its type.
Variable descriptions ​
Entity user = null ​
========== PROPERTIES ==========
AbilityInstance basic_attack = null ​
The basic attack the entity uses now.
AbilityInstance original_basic_attack_instance = null ​
The basic attack the entity started with, kept so a swapped one can be taken off again.
Array[AbilityInstance] active_abilities = [] ​
The active abilities the entity knows.
Array[AbilityInstance] passive_abilities = [] ​
The passive abilities the entity knows.
Timer global_cooldown_timer = null ​
The timer of the global cooldown (stopped when there is none).
ChronoManager chrono_manager ​
The manager of timers the component takes its timers from.
GameHost.SystemHub system_hub ​
The hub of the game systems.
Dictionary group_cooldown_timers = ​
Cooldowns shared through groups (potions, trinkets): group id -> the timer that runs while any member is on cooldown
Dictionary locked_schools = ​
Schools whose abilities cannot be used (a counterspell, a school-specific silence): school id -> how many locks hold it
AbilityInstance weapon_basic_attack = null ​
The basic attack a wielded weapon class provides (WeaponClassDefinition.basic_attack_ability_id): it replaces the basic attack of the entity while the weapon is wielded, and the original comes back when it is not. 0 puts the original back
Method descriptions ​
void refresh_npc_ranks() ​
An NPC's abilities take the rank its definition says at its level (called when the NPC is made and whenever its level changes)
void add_rank_bonus( source: Variant, bonus: int, ability_ids: Array, group_ids: Array, school_ids: Array, all: bool = false ) ​
An effect (or anything else with an identity) gives ranks to the abilities it names. Empty lists with all false give nothing
void remove_rank_bonus( source: Variant ) ​
Takes away what a source gave
int get_rank_bonus_for( ability_def: AbilityDefinition ) ​
The ranks that all the sources together add to an ability
void setup_starting_abilites() ​
Gives the entity the abilities of its definition (and of its template and class): its basic attack, active and passive abilities.
bool add_basic_attack_instance( ability_instance: AbilityInstance ) ​
Sets the basic attack of the entity. False for an empty instance.
bool swap_basic_attack( ability_instance: AbilityInstance ) ​
Replaces the basic attack (a weapon that has its own). The original is kept for remove_basic_attack.
bool remove_basic_attack() ​
Takes the swapped basic attack away and gives the original back.
bool add_active_ability_instance( ability_instance: AbilityInstance ) ​
Adds an active ability. False when the entity already has it or the instance is empty.
bool add_passive_ability_instance( ability_instance: AbilityInstance ) ​
Add a passive ability instance. AbilityInstance manages its own passive effect application via its init and requirement monitoring - no manual effect application needed here.
bool remove_active_ability_by_id( ability_id: int ) ​
Removes an active ability by its id. False when the entity does not know it.
bool remove_active_ability_instance( ability_instance: AbilityInstance ) ​
Removes an active ability instance.
bool remove_passive_ability_by_id( ability_id: int ) ​
Removes a passive ability by its id. False when the entity does not know it.
bool remove_passive_ability_instance( ability_instance: AbilityInstance ) ​
Removes a passive ability instance.
void deactivate_all_toggles() ​
Switches every toggle ability of this entity off (death, a dispel, a stance reset)
AbilityInstance get_ability_instance_by_id( ability_id: int ) ​
The ability (basic attack, active or passive) with this id, or null.
AbilityInstance get_active_ability_instance_by_id( ability_id: int ) ​
The active ability with this id, or null.
AbilityInstance get_passive_ability_instance_by_id( ability_id: int ) ​
The passive ability with this id, or null.
AbilityInstance get_ability_instance_by_name( ability_name: String ) ​
The ability (basic attack, active or passive) with this display name, or null.
AbilityInstance get_active_ability_instance_by_name( ability_name: String ) ​
The active ability with this display name, or null.
AbilityInstance get_passive_ability_instance_by_name( ability_name: String ) ​
The passive ability with this display name, or null.
Array[AbilityInstance] get_all_ability_instances() ​
Every ability of the entity: the basic attack, the active ones and the passive ones.
void modify_ability_property( ability_name: String, property_name: String, effect_value: float, calculation_type: int, source: Variant = "stat" ) ​
Changes a property of an ability by name ("*" for all of them): the amount, how it is applied (add, multiply ...) and where it comes from.
void clear_ability_property_modifiers( source: Variant ) ​
Takes away everything one source (an effect instance, a stat effect) modified on this entity's abilities
AbilityInstance.AbilityUseAttemptResult attempt_use_basic_attack() ​
Tries to use the basic attack. The result says whether it ran or why not.
AbilityInstance.AbilityUseAttemptResult attempt_use_ability_instance( ability_instance: AbilityInstance, target: Variant, from_action: bool ) ​
Tries to use an ability on a target (an entity or a point). From action says whether a key press asked for it. The result says whether it ran or why not.
AbilityInstance.AbilityUseAttemptResult attempt_use_ability_by_id( ability_id: int, target: Variant, from_action: bool ) ​
Tries to use the ability with this id (the same as attempt_use_ability_instance).
bool is_on_global_cooldown() ​
Is the global cooldown running?
float get_global_cooldown_remaining() ​
How many seconds of the global cooldown are left.
Dictionary to_save_data() ​
The abilities of the entity for a save: the global cooldown, the basic attack and each ability with its cooldowns and charges.
void from_save_data( save_data: Dictionary ) ​
Restores the abilities from a save.
void cleanup_timers() ​
Returns the cooldown timers to the manager.
void cleanup() ​
Cleans up every ability and timer of the component (the entity is going away).
AbilityInstance get_passive_ability_by_id( ability_id: int ) ​
Alias used by the item classes (armor and weapon class passives)
void lock_school( school_id: int ) ​
Locks a school: abilities of it cannot be used. It counts, so two locks need two unlocks.
void unlock_school( school_id: int ) ​
Takes one lock off a school.
bool is_school_locked( school_id: int ) ​
Is the school locked now?
void start_group_cooldowns( group_ids: Array[int], own_duration: float, source: Variant = null ) ​
Using a member of a group that shares its cooldown (a potion, a trinket, an ability) puts every other member on cooldown: the abilities of this entity, and the consumables in its inventory. The length is the group's own (when it sets one) or own_duration, the cooldown of the member that was used. source (an AbilityInstance or an ItemInstance) is skipped: it has its own cooldown.
float get_group_cooldown_remaining( group_ids: Array[int] ) ​
The longest time left on a shared cooldown among these groups (0 = none running)
void set_weapon_basic_attack( ability_id: int ) ​
Makes the basic attack of the weapon the basic attack of the entity (0 clears it).
void clear_weapon_basic_attack() ​
Takes the weapon basic attack away: the entity uses its own again.