Skip to content

EncounterGroup ​

Inherits: Node

An encounter while the game runs: a group of NPCs that fights as one. It is not a node of the scene. The encounter is a record (UniqueEncounterData) and an NPC belongs to it through the Encounter field of its own unique data (UniqueEntityData.encounter_id); the ObjectRegistry makes one EncounterGroup for every encounter of the world when the world loads and gives it its members. The members can stand anywhere in the scene. The group coordinates the fight: it joins the members to a fight together, applies the formation and the spacing, rotates who attacks, runs the reactions, and brings a defeated group back (respawn). Its place is the average position of its members (get_center, also global_position).

Variables ​

UniqueEncounterDataunique_data
boolactivetrue
EncounterStateencounter_stateEncounterState.OUT_OF_COMBAT
CombatSessionencounter_instancenull
Timerspacing_check_timernull
Timerrespawn_timernull
floatgroup_combat_start_time0.0
Array[Entity]forced_combat_entities[]
Array[Entity]current_attackers[]
floatlast_attack_rotation_time0.0
Array[Entity]original_group_members[]
Dictionarygroup_member_lookup{} # entity_instance_id -> bool
Array[Entity]dynamic_participants[]
Array[EncounterReaction]active_reactions[]
ChronoManagerchrono_manager
GameHost.SystemHubsystem_hub
Vector3:global_position

Methods ​

voidinitialize_encounter( p_system_hub: GameHost.SystemHub, members: Array = [] )
intget_unique_id()
Stringget_display_name()
Vector3get_center()
boolis_original_group_member( entity: Entity )
Array[Entity]get_original_group_members()
Array[Entity]get_living_group_members()
Array[Entity]get_combat_group_members()
booladd_dynamic_participant( entity: Entity )
boolremove_dynamic_participant( entity: Entity )
Array[Entity]get_all_participants()
voidadd_member( entity: Entity )
intcleanup_invalid_participants()
boolis_in_combat()
boolis_defeated()
boolcan_start_combat()
voidset_active_state( p_system_hub: GameHost.SystemHub, set_active: bool )
voidrespawn_group()
boolis_entity_allowed_to_attack( entity: Entity )
voidon_behavior_changed()
Dictionaryto_save_data()
voidfrom_save_data( save_data: Dictionary )

Signals ​

encounter_activated( activated: bool ) ​

The encounter was switched on or off.

encounter_combat_started( encounter: EncounterGroup ) ​

Emitted when the group goes into combat.

encounter_combat_ended( encounter: EncounterGroup, reason: String ) ​

Emitted when the combat of the group ends, with the reason.

encounter_phase_changed( encounter: EncounterGroup, phase_index: int ) ​

Emitted when the group moves to another phase (a boss fight).

group_behavior_changed( encounter: EncounterGroup, new_behavior: UniqueEncounterData.GroupBehavior ) ​

Emitted when the group takes another behavior.

encounter_respawned( encounter: EncounterGroup ) ​

The defeated group came back (its respawn timer ran out)

Enumerations ​

enum EncounterState ​

  • OUT_OF_COMBAT = 0
  • IN_COMBAT = 1

Variable descriptions ​

UniqueEncounterData unique_data ​

The record of the encounter: its settings (formation, behavior, reactions, respawn) and what the world keeps of it

bool active = true ​

Is encounter active in game

EncounterState encounter_state = EncounterState.OUT_OF_COMBAT ​

Current encounter state

CombatSession encounter_instance = null ​

Reference to the runtime encounter instance (created when combat starts)

Timer spacing_check_timer = null ​

Timer for spacing checks using ChronoManager

Timer respawn_timer = null ​

Counts down to the return of a defeated group (UniqueEncounterData.respawns)

float group_combat_start_time = 0.0 ​

Track when group combat started

Array[Entity] forced_combat_entities = [] ​

Track entities that have been forced into combat

Array[Entity] current_attackers = [] ​

Track active attack coordination (for turn-based combat)

float last_attack_rotation_time = 0.0 ​

The time the group last changed which member attacks.

Array[Entity] original_group_members = [] ​

The NPCs that belong to the encounter (their unique data names it)

Dictionary group_member_lookup = # entity_instance_id -> bool ​

Quick lookup for group membership

Array[Entity] dynamic_participants = [] ​

Entities that joined the encounter after it started

Array[EncounterReaction] active_reactions = [] ​

Active reaction instances (deep copied from unique_data.reactions)

ChronoManager chrono_manager ​

TimerSystem ref

GameHost.SystemHub system_hub ​

System hub for spawning/combat management

Vector3: global_position ​

Where the group is: the average position of its living members (all of them when none is alive). The old node had a place; this keeps the name for what asks for it.

Method descriptions ​

void initialize_encounter( p_system_hub: GameHost.SystemHub, members: Array = [] ) ​

Sets the encounter up with the hub of the game systems and the NPCs that belong to it.

int get_unique_id() ​

Get unique ID for this encounter

String get_display_name() ​

The name of the encounter (for the debug tools and the editor)

Vector3 get_center() ​

The average position of the living members (all the members when none is alive); the origin when it has none.

bool is_original_group_member( entity: Entity ) ​

Check if an entity is an original group member (fast lookup)

Array[Entity] get_original_group_members() ​

Get all original group members (returns cached array)

Array[Entity] get_living_group_members() ​

Get all living original group members

Array[Entity] get_combat_group_members() ​

Get all original group members currently in combat

bool add_dynamic_participant( entity: Entity ) ​

Add a dynamic participant (entity that joined after encounter started)

bool remove_dynamic_participant( entity: Entity ) ​

Remove a dynamic participant

Array[Entity] get_all_participants() ​

Get all participants (original + dynamic)

void add_member( entity: Entity ) ​

Add a member to the encounter (used by reinforcement actions). It joins as a dynamic participant: it stays where it stands and leaves the group when the fight ends

int cleanup_invalid_participants() ​

Clean up invalid group members and dynamic participants

bool is_in_combat() ​

Check if encounter is currently in combat

bool is_defeated() ​

Check if encounter has been defeated

bool can_start_combat() ​

Check if encounter can start combat

void set_active_state( p_system_hub: GameHost.SystemHub, set_active: bool ) ​

Sets the active state of the encounter and all its entities

void respawn_group() ​

The group comes back: every member that is dead stands up at its start (members with a respawn timer of their own that is still running, and NPCs that can only be killed once, are left alone), and the encounter is ready to fight again with its reactions as new

bool is_entity_allowed_to_attack( entity: Entity ) ​

Check if an entity is allowed to attack (for coordinated behaviors)

void on_behavior_changed() ​

Called when group behavior changes (can be called by ModifyGroupBehaviorAction)

Dictionary to_save_data() ​

Save encounter state (entities are saved separately by ObjectRegistry)

void from_save_data( save_data: Dictionary ) ​

Load encounter state