CombatManager ​
Inherits: Node
Complete combat orchestration system that handles damage calculations, effect pooling, combat logging, world effects management, and encounter coordination.
Variables ​
CombatCalculations | combat_calculations | |
EffectInstancePool | effect_instance_pool | |
CombatLogManager | combat_log_manager | |
CombatEventRecorder | event_recorder | |
VFXManager | vfx_manager | |
Dictionary | active_encounters | {} |
Dictionary | entity_to_encounter_map | {} |
float | encounter_merge_distance | 50.0 |
float | encounter_cleanup_interval | 5.0 |
bool | combat_music_active | false |
float | combat_music_stop_delay | 2.0 |
EnvironmentalEffects | environmental_effects | |
Array[EffectInstance] | world_effects | [] |
Dictionary | world_effects_by_type | {} |
Dictionary | world_effects_by_originator | {} |
Methods ​
void | connect_party_manager_signals( party_manager: PartyManager ) |
EnvironmentalEffects | get_environmental_effects() |
bool | is_environmental_effects_ready() |
Array[EffectInstance] | get_active_environmental_effects() |
void | cleanup_environmental_effects() |
void | handle_entity_entered_combat( entity: Entity ) |
void | handle_entity_left_combat( entity: Entity ) |
void | handle_unique_encounter_combat_started( encounter_node: EncounterGroup, initiating_entity: Entity ) |
void | handle_unique_encounter_combat_ended( encounter_node: EncounterGroup, reason: String ) |
bool | is_entity_in_encounter( entity: Entity ) |
CombatSession | get_encounter_for_entity( entity: Entity ) |
Array[Entity] | get_entities_in_encounter_with( entity: Entity ) |
void | unregister_entity_from_combat_tracking( entity: Entity ) |
void | register_entity_for_combat_tracking( entity: Entity ) |
Array[CombatSession] | get_all_encounters() |
void | start_combat_music() |
void | register_world_effect( effect_instance: EffectInstance ) |
void | unregister_world_effect( effect_instance: EffectInstance ) |
bool | has_world_effect( effect_instance: EffectInstance ) |
EffectInstance | spawn_world_effect( effect: Effect, position: Vector3 ) |
EffectInstance | spawn_world_effect_on_target( effect: Effect, target: Variant ) |
Array[EffectInstance] | get_world_effects() |
Array[EffectInstance] | get_world_effects_by_type( effect_type: String ) |
Array[EffectInstance] | get_world_area_effects() |
Array[EffectInstance] | get_world_collision_effects() |
Array[EffectInstance] | get_world_projectile_effects() |
Array | get_world_effects_by_originator( originator: Entity ) |
Array[EffectInstance] | get_world_area_effects_by_originator( originator: Entity ) |
Array[EffectInstance] | get_world_effects_near_point( point: Vector3, max_distance: float = 5.0 ) |
EffectInstance | find_existing_world_effect_by_stacking_rule( effect_def: Effect, originator: Entity ) |
int | cleanup_world_effects() |
int | clear_world_effects_by_originator( originator: Entity ) |
void | clear_world_effects() |
DamageResult | apply_damage( attacker: Variant, target: Variant, raw_damage: float, damage_type: int, effect_instance: EffectInstance, can_be_avoided: bool = true, chain_depth: int = 0 ) |
void | announce_miss( attacker: Entity, target: Entity, effect_instance: EffectInstance ) |
DamageResult | run_damage_done( attacker: Variant, raw_damage: float, damage_type: int, effect_instance: EffectInstance = null ) |
HealingResult | apply_healing( healer_entity: Variant, target_entity: Variant, raw_healing: float, effect_instance: EffectInstance, chain_depth: int = 0, only_pool_id: int = 0 ) |
HealingResult | run_healing_done( healer: Variant, raw_healing: float, effect_instance: EffectInstance = null ) |
int | cleanup_invalid_encounters() |
void | cleanup() |
Dictionary | save_data() |
void | load_data( save_data: Dictionary, system_hub: GameHost.SystemHub ) |
Signals ​
encounter_started( encounter: CombatSession ) ​
Emitted when a new encounter starts
encounter_ended( encounter: CombatSession, reason: String ) ​
Emitted when an encounter ends with the reason
experience_grant_requested( amount: int ) ​
Emitted when an NPC dies in combat with players, requesting experience grant
damage_pipeline_completed( result: DamageResult ) ​
Emitted when a hit has been fully resolved, with the typed result (also emitted on both entities)
healing_pipeline_completed( result: HealingResult ) ​
Emitted when a heal has been fully resolved, with the typed result (also emitted on both entities)
Variable descriptions ​
CombatCalculations combat_calculations ​
Global combat configuration loaded from database
EffectInstancePool effect_instance_pool ​
Pool for reusing effect instances
CombatLogManager combat_log_manager ​
Manager for combat logging and history
CombatEventRecorder event_recorder ​
Builds the combat events (the record of a fight and the lines of the combat channels)
VFXManager vfx_manager ​
vfx system ref
Dictionary active_encounters = ​
All currently active encounters [encounter_id: CombatSession]
Dictionary entity_to_encounter_map = ​
Quick lookup for which encounter an entity is in [entity_id: encounter_id]
float encounter_merge_distance = 50.0 ​
Maximum distance to merge encounters
float encounter_cleanup_interval = 5.0 ​
How often to clean up invalid encounters (seconds)
bool combat_music_active = false ​
Whether combat music is currently playing
float combat_music_stop_delay = 2.0 ​
Delay before stopping combat music after last encounter ends
EnvironmentalEffects environmental_effects ​
Environmental effects node for world effect origination
Array[EffectInstance] world_effects = [] ​
All active world effects
Dictionary world_effects_by_type = ​
World effects organized by type [effect_type: Array[EffectInstance]]
Dictionary world_effects_by_originator = ​
World effects organized by originator [entity_id: Array[EffectInstance]]
Method descriptions ​
void connect_party_manager_signals( party_manager: PartyManager ) ​
Setup encounter system
EnvironmentalEffects get_environmental_effects() ​
Get reference to the environmental effects node
bool is_environmental_effects_ready() ​
Check if environmental effects system is ready
Array[EffectInstance] get_active_environmental_effects() ​
Get all active environmental effects
void cleanup_environmental_effects() ​
Clean up all environmental effects (useful for scene transitions)
void handle_entity_entered_combat( entity: Entity ) ​
Process entity entering combat - find or create encounter
void handle_entity_left_combat( entity: Entity ) ​
Process entity leaving combat - remove from encounter
void handle_unique_encounter_combat_started( encounter_node: EncounterGroup, initiating_entity: Entity ) ​
Handle when a unique encounter group enters combat
void handle_unique_encounter_combat_ended( encounter_node: EncounterGroup, reason: String ) ​
Handle when a unique encounter group ends combat
bool is_entity_in_encounter( entity: Entity ) ​
Check if an entity is currently in any encounter
CombatSession get_encounter_for_entity( entity: Entity ) ​
Get the encounter that an entity is currently in
Array[Entity] get_entities_in_encounter_with( entity: Entity ) ​
Get all entities in the same encounter as the given entity
void unregister_entity_from_combat_tracking( entity: Entity ) ​
Remove entity from combat tracking when they're freed/destroyed
void register_entity_for_combat_tracking( entity: Entity ) ​
Register an entity for combat tracking and connect signals
Array[CombatSession] get_all_encounters() ​
Get all active encounters as an array
void start_combat_music() ​
Start combat music if not already playing
void register_world_effect( effect_instance: EffectInstance ) ​
Register an effect with the world manager (called by EffectInstance when no entity owner)
void unregister_world_effect( effect_instance: EffectInstance ) ​
Unregister an effect from the world manager
bool has_world_effect( effect_instance: EffectInstance ) ​
Check if a world effect is registered
EffectInstance spawn_world_effect( effect: Effect, position: Vector3 ) ​
Spawn a world effect at a specific position using EnvironmentalEffects as originator
EffectInstance spawn_world_effect_on_target( effect: Effect, target: Variant ) ​
Spawn a world effect targeting a specific entity
Array[EffectInstance] get_world_effects() ​
Get all world effects (copy for safety)
Array[EffectInstance] get_world_effects_by_type( effect_type: String ) ​
Get world effects by type
Array[EffectInstance] get_world_area_effects() ​
Get area effects in the world
Array[EffectInstance] get_world_collision_effects() ​
Get collision effects in the world
Array[EffectInstance] get_world_projectile_effects() ​
Get projectile effects in the world
Array get_world_effects_by_originator( originator: Entity ) ​
Find world effects by originator
Array[EffectInstance] get_world_area_effects_by_originator( originator: Entity ) ​
Find world area effects by originator
Array[EffectInstance] get_world_effects_near_point( point: Vector3, max_distance: float = 5.0 ) ​
Find world effects by target point (within range)
EffectInstance find_existing_world_effect_by_stacking_rule( effect_def: Effect, originator: Entity ) ​
Find existing world effect that matches stacking rules (called by EffectInstance)
int cleanup_world_effects() ​
Clean up finished world effects (call this in _process or _ready)
int clear_world_effects_by_originator( originator: Entity ) ​
Remove all world effects from a specific originator (useful when entity dies/leaves)
void clear_world_effects() ​
Remove all world effects (useful for scene transitions)
DamageResult apply_damage( attacker: Variant, target: Variant, raw_damage: float, damage_type: int, effect_instance: EffectInstance, can_be_avoided: bool = true, chain_depth: int = 0 ) ​
Resolves one hit from start to finish and returns the DamageResult every consumer reads. Phase 1: the attacker's calculation (crits, attack power ...) fills done. Phase 2: the target completes the result (redirection, immunity, dodge / block / armor, shields, health, death). A script error inside the target's processing returns null from take_damage; it is turned into a FAILED result here, so a crash can never be mistaken for a hit. chain_depth is 0 for a normal hit and result.next_chain_depth() for damage caused by reacting to a hit (damage reflection, reactive damage).
void announce_miss( attacker: Entity, target: Entity, effect_instance: EffectInstance ) ​
Tells everyone that an attack missed (the outcome of a failed hit roll)
DamageResult run_damage_done( attacker: Variant, raw_damage: float, damage_type: int, effect_instance: EffectInstance = null ) ​
Runs only the attacker's damage-done phase (crits, attack power ...) on a number and returns the DamageResult (done is the final number; the triggers and steps are recorded). For effects that apply a number of their own (the pool and stat modifier effects) instead of hitting a target.
HealingResult apply_healing( healer_entity: Variant, target_entity: Variant, raw_healing: float, effect_instance: EffectInstance, chain_depth: int = 0, only_pool_id: int = 0 ) ​
Resolves one heal from start to finish and returns the HealingResult: the healer's calculation fills done, the target completes the result (healing-taken modifiers, pools, revive). A script error is turned into a FAILED result. only_pool_id limits the heal to one pool (0 = every pool that receives healing)
HealingResult run_healing_done( healer: Variant, raw_healing: float, effect_instance: EffectInstance = null ) ​
Runs only the healer's healing-done phase on a number and returns the HealingResult (done is the final number)
int cleanup_invalid_encounters() ​
Clean up invalid encounters and participants
void cleanup() ​
Complete system cleanup - clear all encounters, effects, and environmental effects
Dictionary save_data() ​
The state of the combat system for a save (the combat music, the world effects).
void load_data( save_data: Dictionary, system_hub: GameHost.SystemHub ) ​
Restores the combat system from a save.