Skip to content

ModularCombatScript ​

Inherits: DatabaseResource < Resource

Modular combat script system that defines how an entity behaves in combat. This resource-based approach allows for flexible AI behavior from simple NPCs to complex scripted boss encounters.

Description ​

The combat script owns and manages all action states, making decisions about when to transition and what actions to take in each state.

Properties ​

boolauto_basic_attacktrue
floatbasic_attack_interval0.5
booluses_target_searchtrue
booluses_chasingtrue
booluses_attackingtrue
booluses_followingfalse
booluses_player_commandfalse
AttackLogicTypeattack_logic_typeAttackLogicType.SIMPLE
AttackStateLogicattack_state_logic
PhaseSystemphase_system
Array[CombatReaction]global_reactions[]

Variables ​

Entityentity
boolenabledtrue
ActionStatecurrent_action_state
Dictionaryaction_states{}
floatbasic_attack_timer0.0
boolexecuting_actionfalse

Methods ​

voidsetup( system_hub: GameHost.SystemHub, entity_ref: Entity )
voidset_encounter( encounter: CombatSession )
voidstart_combat()
voidend_combat()
voidprocess_combat( delta: float )
voidchange_state( state_name: ActionStateName, from_death: bool = false )
ActionStateNameget_current_state_name()
boolhas_state( state_name: ActionStateName )
ActionStateNameget_combat_entry_state()
Stringget_state_name_string( state_name: ActionStateName )
Dictionaryto_save_data()
voidfrom_save_data( save_data: Dictionary )
voidcleanup()

Enumerations ​

enum ActionStateName ​

Combat script state names

  • INACTIVE = 0
  • TARGET_SEARCH = 1
  • CHASING = 2
  • ATTACKING = 3
  • INCAPACITATED = 4
  • DEAD = 5
  • FOLLOWING = 6
  • PLAYER_COMMAND = 7
  • DISORIENTED = 8
  • FLEE = 9

enum AttackLogicType ​

Type of attack logic this script uses

  • SIMPLE = 0 - Just spam basic attack (Scenario 1 - melee)
  • PRIORITY = 1 - Check conditions, use highest priority action (Scenario 1 - caster)
  • TIMELINE = 2 - Scripted sequence based on time/phases (Scenario 2 - boss)
  • TACTICAL = 3 - Complex positioning and action decisions (Scenario 3 - action RPG)

Property descriptions ​

Script Settings

bool auto_basic_attack = true ​

Whether to perform basic attacks automatically when no other actions available

float basic_attack_interval = 0.5 ​

Minimum interval between basic attacks (seconds)

State Configuration

Which states this combat script uses (determines valid transitions)

bool uses_chasing = true ​

True when the script has a chasing state.

bool uses_attacking = true ​

True when the script has an attacking state.

bool uses_following = false ​

True when the script has a following state (a companion follows its leader).

bool uses_player_command = false ​

True when the script has a state where the player gives the orders.

Combat Behavior

AttackLogicType attack_logic_type = AttackLogicType.SIMPLE ​

Type of attack logic this script uses

AttackStateLogic attack_state_logic ​

The logic resource that defines what to do in the ATTACKING state

PhaseSystem phase_system ​

Optional phase system for scripted boss fights (Scenario 2)

Array[CombatReaction] global_reactions = [] ​

Global reactions that work in any state

Variable descriptions ​

Entity entity ​

Reference to the entity using this script

bool enabled = true ​

Whether this script is currently active (can be toggled at runtime for player control)

ActionState current_action_state ​

Current active action state

Dictionary action_states = ​

Dictionary to store all states this script uses

float basic_attack_timer = 0.0 ​

Timer for basic attack intervals

bool executing_action = false ​

Whether we're currently executing an action

Method descriptions ​

void setup( system_hub: GameHost.SystemHub, entity_ref: Entity ) ​

Initialize the combat script with entity reference

void set_encounter( encounter: CombatSession ) ​

Set the current encounter and notify all combat reactions

void start_combat() ​

Starts the script: the phase system is told and the script is enabled.

void end_combat() ​

Ends the combat part of the script.

void process_combat( delta: float ) ​

Called every frame to process combat logic

void change_state( state_name: ActionStateName, from_death: bool = false ) ​

Change to a new action state

ActionStateName get_current_state_name() ​

Get the current state as an enum

bool has_state( state_name: ActionStateName ) ​

Check if this script has a specific state

ActionStateName get_combat_entry_state() ​

Get the next appropriate state when entering combat

String get_state_name_string( state_name: ActionStateName ) ​

Convert state name enum to string for debugging

Dictionary to_save_data() ​

Save runtime state for persistence

void from_save_data( save_data: Dictionary ) ​

Restore runtime state from saved data

void cleanup() ​

Cleanup any resources when script is no longer needed