Skip to content

EffectsComponent ​

Inherits: RefCounted

EffectsComponent manages all active effects on an entity. It handles the addition, removal, and tracking of various effects that can be applied to entities in the game.

Description ​

Key features:

  • Maintains a list of all active effects on the entity
  • Handles the application and removal of effects with proper stacking rules
  • Provides methods for querying and managing effects
  • Efficiently tracks active status effects for quick lookups
  • Effects register themselves via EffectInstance.start_effect()
  • Decoupled from Entity - emits own signals for Entity to forward

Variables ​

Array[EffectInstance]active_effects[]
Dictionaryactive_status_effects{} # Key: status effect id, Value: Array[EffectInstance]
Dictionarystatus_effect_flags{} # Key: status effect id, Value: bool
Array[EffectInstance]applied_effects[]
Dictionaryactive_status_types{} # Key: base_status_type, Value: int

Methods ​

voidgained_effect( effect_instance: EffectInstance )
voidlost_effect( effect_instance: EffectInstance )
voidupdated_effect( effect_instance: EffectInstance )
boolhas_status_type( status_type: String )
boolhas_any_cc_effects()
boolhas_movement_impairing_effects()
boolhas_ability_blocking_effects()
Dictionaryget_status_effects_detail()
EffectInstancefind_existing_effect_by_stacking_rule( new_effect: Effect, originator: Variant )
EffectInstancefind_effect_by_id( effect_id: int )
EffectInstancefind_effect_by_id_and_originator( effect_id: int, originator: Variant )
Array[String]get_all_active_status_effects()
Array[EffectInstance]get_active_effects_by_type( effect_type: String )
voidremove_all_effects()
Dictionaryto_save_data()
voidfrom_save_data( save_data: Dictionary, system_hub: GameHost.SystemHub )
intget_active_effect_count()
boolhas_any_active_effects()
voidremove_effects_on_death()
voidtrack_applied( effect_instance: EffectInstance )
voiduntrack_applied( effect_instance: EffectInstance )
voidremove_effects_from_originator( originator: Variant )

Signals ​

effect_gained( effect_instance: EffectInstance ) ​

Signal emitted when an effect is gained

effect_lost( effect_instance: EffectInstance ) ​

Signal emitted when an effect is lost

effect_updated( effect_instance: EffectInstance ) ​

Signal emitted when an effect is updated (stacks changed, duration refreshed)

Variable descriptions ​

Array[EffectInstance] active_effects = [] ​

Array of all active effects currently applied to the entity

Dictionary active_status_effects = # Key: status effect id, Value: Array[EffectInstance] ​

Fast lookup for active status effects - O(1) performance

Dictionary status_effect_flags = # Key: status effect id, Value: bool ​

Quick boolean cache for common status effect queries

Array[EffectInstance] applied_effects = [] ​

Every active effect this entity is the originator of (on itself or on others), kept for the effects that are in groups: the groups with the scope "per originator" count them

Dictionary active_status_types = # Key: base_status_type, Value: int ​

How many active status effects of each type (the definition's base_status_type: "Incapacitate", "Root", "Silence" ...) the entity has, so two stuns that overlap end independently and the entity is stunned until the last one is gone

Method descriptions ​

void gained_effect( effect_instance: EffectInstance ) ​

Adds a new effect to the entity and emits a signal

void lost_effect( effect_instance: EffectInstance ) ​

Removes an effect from the entity and emits a signal

void updated_effect( effect_instance: EffectInstance ) ​

Updates an existing effect and emits a signal (called when stacks change or duration refreshes)

bool has_status_type( status_type: String ) ​

True while at least one active status effect of this type ("Incapacitate", "Root", "Silence" ...) is on the entity

bool has_any_cc_effects() ​

True while any status effect the definitions call crowd control (stun, root, silence, disarm, flee, disorient) is on the entity

bool has_movement_impairing_effects() ​

True while the entity cannot move freely (root, incapacitate, cripple)

bool has_ability_blocking_effects() ​

True while the entity cannot use all of its abilities (silence, disarm, incapacitate)

Dictionary get_status_effects_detail() ​

Every active status effect: id -> {name, type, count, time_remaining (the longest of them)}

EffectInstance find_existing_effect_by_stacking_rule( new_effect: Effect, originator: Variant ) ​

Finds existing effect based on the effect's stacking rule

EffectInstance find_effect_by_id( effect_id: int ) ​

Finds effect by ID only (for Global stacking rule)

EffectInstance find_effect_by_id_and_originator( effect_id: int, originator: Variant ) ​

Finds effect by ID and originator (for Per_Originator stacking rule)

Array[String] get_all_active_status_effects() ​

Get the names of all currently active status effects

Array[EffectInstance] get_active_effects_by_type( effect_type: String ) ​

Get all active effects of a specific effect type

void remove_all_effects() ​

Remove all effects from the entity

Dictionary to_save_data() ​

Convert effects manager state to save data

void from_save_data( save_data: Dictionary, system_hub: GameHost.SystemHub ) ​

Load effects manager state from save data

int get_active_effect_count() ​

How many effects are active on the entity.

bool has_any_active_effects() ​

Is any effect active on the entity?

void remove_effects_on_death() ​

Death takes the effects off, except those of a group that persists through death (flasks)

void track_applied( effect_instance: EffectInstance ) ​

Remembers an effect the entity put on someone else.

void untrack_applied( effect_instance: EffectInstance ) ​

Forgets an effect the entity put on someone else.

void remove_effects_from_originator( originator: Variant ) ​

Ends every effect a given entity applied (it left combat, it died, a charm broke). An effect several sources share (stacking rule Global) only loses the stacks that source added, and goes on for the others