Skip to content

EffectInstance ​

Inherits: RefCounted

Lightweight runtime instance of an effect that references an EffectDefinition for behavior Handles all runtime state while the definition provides immutable logic

Variables ​

Effectdefinition
boolhit_was_critfalse
Variantoriginator
Varianttarget
Varianteffect_owner
SignalRegistrysignal_registry
SourceTypesourceSourceType.PERSISTENT
CombatManagercombat_manager
ChronoManagerchrono_manager
ObjectRegistryobject_registry
GameHost.SystemHubhub
Stringregistered_with"" # "entity", "world", or "none"
Variantregistered_managernull
boolactivefalse
intstack_count1
floattime_started
boolrejectedfalse
Stringrejection_reason""
EndReasonend_reasonEndReason.REMOVED
boolrestoringfalse
Variantintended_targetnull
floatcharge_fraction1.0
Array[Effect]bonus_child_effects[]
EffectInstance:parent_instance
CastRecordcast_recordnull
floathit_multiplier1.0
inthit_outcome0
Dictionarystack_sources{}
floatduration0.0
floatbase_duration0.0
floattime_remaining0.0
floattick_interval0.0
Timerduration_timernull
Timertick_timernull
floatlast_tick_time0.0
Array[EffectInstance]active_child_effects[]
Dictionarycustom_effect_data{}
Array[Dictionary]signal_connections[]

Methods ​

voidinitialize( system_hub: GameHost.SystemHub, effect_def: Effect, new_originator: Variant = null, new_target: Variant = null )
Dictionaryget_requirement_context()
voidstart_effect()
voidupdate_duration( new_duration: float )
voidremove_effect( reason: EndReason = EndReason.REMOVED )
Stringend_reason_text( reason: EndReason ) static
floatget_time_remaining()
boolis_active()
Dictionaryto_save_data()
voidfrom_save_data( save_data: Dictionary, system_hub: GameHost.SystemHub )
CastRecordget_cast_record()
voidreset()
voidcleanup()
voidremove_stacks_from( source_entity: Variant )
intget_uses_remaining()

Signals ​

effect_started( effect: EffectInstance ) ​

Emitted when the effect is started

effect_ended( effect: EffectInstance ) ​

Emitted when the effect has ended or been removed

sfx_at_position_requested( audio: AudioStream, position: Vector3, volume_db: float, pitch_scale: float ) ​

Emitted when SFX needs to be played at a position (for Vector3 targets)

external_inventory_requested( inventory: InventoryComponent, owner: Variant, active: bool ) ​

Emitted when external inventory UI needs to be opened

Enumerations ​

enum EndReason ​

Why an effect ended (read it in a listener of effect_ended / effect_lost, or ask end_reason_text)

  • REMOVED = 0 - taken off without a more specific reason (an event action, an item taken off ...)
  • EXPIRED = 1 - its duration ran out
  • DISPELLED = 2 - cleansed or purged by a Clear effect
  • REPLACED = 3 - pushed out by another effect of the same group
  • DEATH = 4 - the entity it was on died
  • USED_UP = 5 - its charges, its uses or its shield were used up, or it was consumed
  • COMPLETED = 6 - it did what it was for (a dash that arrived, a one-off effect that is done)
  • SOURCE_LEFT = 7 - its source (the caster) left, died or lost its hold

enum SourceType ​

The options of source type: intrinsic, external, stateful, persistent.

  • INTRINSIC = 0
  • EXTERNAL = 1
  • STATEFUL = 2

Constants ​

  • float MIN_DURATION = 0.1 - ========== TIMING MANAGEMENT ==========

Variable descriptions ​

Effect definition ​

Reference to the immutable effect definition (shared across all instances)

bool hit_was_crit = false ​

True when a hit or heal of this effect was a critical strike (set by the damage and heal effects; the crit VFX reads it)

Variant originator ​

The entity that created this effect

Variant target ​

The entity that this effect is applied to

Variant effect_owner ​

The effect owner (Ability, InteractableObject, etc.)

SignalRegistry signal_registry ​

Signal registry for managing signal connections

SourceType source = SourceType.PERSISTENT ​

Source type for save/load logic

CombatManager combat_manager ​

SystemManager refs

ChronoManager chrono_manager ​

The manager of timers the effect takes its timers from.

ObjectRegistry object_registry ​

The registry of the objects of the world.

GameHost.SystemHub hub ​

The systems of the game, for the effects that evaluate conditions (a condition may look an entity up by its id)

String registered_with = "" # "entity", "world", or "none" ​

Track where this effect is registered for proper cleanup

Variant registered_manager = null ​

Reference to the manager

bool active = false ​

Whether the effect is currently active

int stack_count = 1 ​

Current number of stacks this effect has

float time_started ​

When this effect was started (timestamp)

bool rejected = false ​

Set by an effect that found, while it applied, that it cannot stay (a status effect the target is immune to): the instance ends without registering

String rejection_reason = "" ​

Why the effect was rejected (a requirement it did not meet, an exclusive group that refused it), for the log and the UI

EndReason end_reason = EndReason.REMOVED ​

Why the effect ended (set just before effect_ended is emitted; EXPIRED when the duration ran out)

bool restoring = false ​

True while a loaded effect applies for the first time: the effect restores itself instead of running its application (see Effect.restore_after_load)

Variant intended_target = null ​

What the effect was aimed at, also when it applies to the originator (applies_to Self makes target the originator): a misdirection on the caster still knows who it was aimed at

float charge_fraction = 1.0 ​

How far the shot that caused this effect was drawn (0 to 1; 1 when it was not drawn): damage and healing that scale with the charge read it

Array[Effect] bonus_child_effects = [] ​

Effects a composite effect applies to its targets on top of its own children: the ammo of a shot (a poison arrow poisons whoever the arrow hits)

EffectInstance: parent_instance ​

The effect that applied this one as one of its children (null for a root effect)

CastRecord cast_record = null ​

What the effects of this cast did so far (shared by every effect instance of the cast); see get_cast_record

float hit_multiplier = 1.0 ​

How much of its damage and healing the effect keeps: 1 normally, less after a glancing hit (see HitRules). Set when the effect starts

int hit_outcome = 0 ​

The outcome of the hit roll this effect took part in (HitRules.Outcome.HIT when it did not roll)

Dictionary stack_sources = ​

Who contributed the stacks of a shared effect (originator -> stacks), so losing one source only takes away its own stacks

float duration = 0.0 ​

Effect duration (0 = permanent, -1 = immediate)

float base_duration = 0.0 ​

The duration the effect starts with and goes back to when a stack refreshes it (a loaded effect starts with what was left)

float time_remaining = 0.0 ​

Time remaining for the effect

float tick_interval = 0.0 ​

Tick interval for ticking effects (0 = no ticking)

Timer duration_timer = null ​

Timer for duration management (only created when needed)

Timer tick_timer = null ​

Timer for tick management (only created when needed)

float last_tick_time = 0.0 ​

Last tick time for manual tick tracking

Array[EffectInstance] active_child_effects = [] ​

Array of active child effect instances (for cleanup tracking)

Dictionary custom_effect_data = ​

Custom data dictionary for effect-specific runtime information

Array[Dictionary] signal_connections = [] ​

Array of connected signal connections for cleanup

Method descriptions ​

void initialize( system_hub: GameHost.SystemHub, effect_def: Effect, new_originator: Variant = null, new_target: Variant = null ) ​

Initialize the effect instance with definition and basic setup

Dictionary get_requirement_context() ​

What the requirements of the effect may ask about what it belongs to: the rank of its ability, the item level of its item

void start_effect() ​

Start the effect and begin its logic. Effects that start inside effects are counted: past GameplayConfig.max_effect_depth the effect is refused

void update_duration( new_duration: float ) ​

Update the duration of an active effect (useful for diminishing returns, etc.)

void remove_effect( reason: EndReason = EndReason.REMOVED ) ​

Remove/cancel the effect

String end_reason_text( reason: EndReason ) ​

The words for a reason an effect ended ("expired", "was dispelled" ...), for logs and the interface

float get_time_remaining() ​

Get time remaining for this effect

bool is_active() ​

Check if effect is still active

Dictionary to_save_data() ​

Save instance runtime state

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

Load instance runtime state

CastRecord get_cast_record() ​

What the effects of this cast did so far. Made when first asked for; a child effect shares the record of its parent, and the effects an ability starts share one

void reset() ​

Sets the instance up for reuse: whatever it was doing ends quietly and its runtime state goes back to the start

void cleanup() ​

Clean up all resources used by this effect instance

void remove_stacks_from( source_entity: Variant ) ​

Takes away the stacks one source added to this shared effect (that source left combat, died, or its charm broke). The effect ends when no source is left; otherwise it carries on with the stacks that remain, and with another source as its originator when the first one is the one leaving

int get_uses_remaining() ​

How many counted uses are left (-1 when the effect is not limited)