Skip to content

CombatSession ​

Inherits: RefCounted

CombatSession manages a single active combat encounter at runtime. It tracks all participating entities, manages combat timing, and coordinates encounter-wide events and states.

Description ​

This class is designed to work with CombatSystem's encounter management. CombatSystem creates, manages, and destroys these instances automatically. Now supports multiple unique encounters and encounter reaction signal management.

Variables ​

Stringencounter_id
Array[Entity]participants[]
floatstart_time
boolis_activefalse
Array[CombatEvent]events[]
Vector3encounter_center
floatmax_join_distance50.0
Array[EncounterGroup]encounter_nodes[]
Array[EncounterReaction]encounter_reactions[]

Methods ​

voidrecord_event( event: CombatEvent, limit: int )
booladd_participant( entity: Entity )
boolremove_participant( entity: Entity )
booladd_encounter_node( node: EncounterGroup )
boolremove_encounter_node( node: EncounterGroup )
boolshould_end_encounter()
voidend_encounter( reason: String )
boolcan_entity_join( entity: Entity, target_entity: Entity = null )
boolis_unique_encounter()
boolhas_encounter_node( node: EncounterGroup )
Array[EncounterGroup]get_encounters()
boolis_scripted_encounter()
Array[String]get_hostile_factions()
Array[Entity]get_entities_by_faction( faction_id: int )
Array[Entity]get_allies_of_entity( entity: Entity )
Array[Entity]get_enemies_of_entity( entity: Entity )
floatget_encounter_duration()
Stringget_encounter_duration_formatted()
boolhas_been_running_longer_than( seconds: float )
intget_participant_count()
intget_living_participant_count()
intget_participant_count_by_faction( faction_id: int )
boolhas_participant( entity: Entity )
boolhas_player_participants()
Array[Entity]get_player_participants()
Array[Entity]get_npc_participants()
intcleanup_invalid_participants()
Array[Entity]get_enemies_in_range( entity: Entity, range: float )
Array[Entity]get_allies_in_range( entity: Entity, range: float )
boolis_encounter_balanced( balance_threshold: float = 1.5 )
boolis_faction_outnumbered( faction_id: int, outnumber_threshold: float = 2.0 )
intforce_faction_into_combat( faction_id: int, target_entity: Entity )
intget_encounter_phase()
boolis_entity_allowed_to_attack( entity: Entity )

Signals ​

encounter_started( encounter: CombatSession ) ​

Signals for encounter lifecycle

participant_joined( encounter: CombatSession, entity: Entity ) ​

Emitted when an entity joins the combat.

participant_left( encounter: CombatSession, entity: Entity ) ​

Emitted when an entity leaves the combat.

encounter_ended( encounter: CombatSession, reason: String ) ​

Emitted when the combat ends, with the reason.

Variable descriptions ​

String encounter_id ​

Unique identifier for this encounter

Array[Entity] participants = [] ​

All entities currently participating in this encounter

float start_time ​

When this encounter started (unix timestamp)

bool is_active = false ​

Whether this encounter is currently active

Array[CombatEvent] events = [] ​

What happened in the fight, oldest first (CombatEvent): the record of the fight. Bounded: the oldest are dropped past GameplayConfig.combat_log_events_per_fight

Vector3 encounter_center ​

Geographic center point of the encounter (for proximity checks)

float max_join_distance = 50.0 ​

Maximum distance entities can be from center to join this encounter

Array[EncounterGroup] encounter_nodes = [] ​

References to unique encounter groups (supports multiple unique encounters)

Array[EncounterReaction] encounter_reactions = [] ​

All encounter reactions from unique encounters

Method descriptions ​

void record_event( event: CombatEvent, limit: int ) ​

Adds an event to the record of the fight

bool add_participant( entity: Entity ) ​

Add an entity to this encounter

bool remove_participant( entity: Entity ) ​

Remove an entity from this encounter

bool add_encounter_node( node: EncounterGroup ) ​

Add a unique encounter group to this instance

bool remove_encounter_node( node: EncounterGroup ) ​

Remove a unique encounter group from this instance

bool should_end_encounter() ​

Check if this encounter should end

void end_encounter( reason: String ) ​

End this encounter

bool can_entity_join( entity: Entity, target_entity: Entity = null ) ​

Check if an entity can join this encounter based on proximity and combat state

bool is_unique_encounter() ​

Check if this encounter involves any unique encounters

bool has_encounter_node( node: EncounterGroup ) ​

Check if this encounter involves a specific unique encounter

Array[EncounterGroup] get_encounters() ​

Get all encounters

bool is_scripted_encounter() ​

Check if this encounter is scripted (has any unique encounters)

Array[String] get_hostile_factions() ​

Get all hostile factions in this encounter

Array[Entity] get_entities_by_faction( faction_id: int ) ​

Get all entities of a specific faction in this encounter

Array[Entity] get_allies_of_entity( entity: Entity ) ​

Get all allies of a specific entity within this encounter

Array[Entity] get_enemies_of_entity( entity: Entity ) ​

Get all enemies of a specific entity within this encounter

float get_encounter_duration() ​

Get encounter duration in seconds

String get_encounter_duration_formatted() ​

Get encounter duration in a readable format

bool has_been_running_longer_than( seconds: float ) ​

Check if encounter has been running longer than specified time

int get_participant_count() ​

Get the number of participants

int get_living_participant_count() ​

Get the number of living participants

int get_participant_count_by_faction( faction_id: int ) ​

Get the number of participants by faction

bool has_participant( entity: Entity ) ​

Check if encounter has a specific entity

bool has_player_participants() ​

Check if encounter has any players

Array[Entity] get_player_participants() ​

Get all player participants (simplified for testing)

Array[Entity] get_npc_participants() ​

Get all NPC participants (simplified for testing)

int cleanup_invalid_participants() ​

Clean up invalid participants

Array[Entity] get_enemies_in_range( entity: Entity, range: float ) ​

Get enemies within range of a specific entity (encounter-aware version)

Array[Entity] get_allies_in_range( entity: Entity, range: float ) ​

Get allies within range of a specific entity (encounter-aware version)

bool is_encounter_balanced( balance_threshold: float = 1.5 ) ​

Check if this encounter is balanced (roughly equal forces)

bool is_faction_outnumbered( faction_id: int, outnumber_threshold: float = 2.0 ) ​

Check if a faction is outnumbered in this encounter

int force_faction_into_combat( faction_id: int, target_entity: Entity ) ​

Force all entities of a faction into combat (for scripted encounters)

int get_encounter_phase() ​

Get encounter phase (for multi-phase encounters)

bool is_entity_allowed_to_attack( entity: Entity ) ​

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