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 ​
bool | auto_basic_attack | true |
float | basic_attack_interval | 0.5 |
bool | uses_target_search | true |
bool | uses_chasing | true |
bool | uses_attacking | true |
bool | uses_following | false |
bool | uses_player_command | false |
AttackLogicType | attack_logic_type | AttackLogicType.SIMPLE |
AttackStateLogic | attack_state_logic | |
PhaseSystem | phase_system | |
Array[CombatReaction] | global_reactions | [] |
Variables ​
Entity | entity | |
bool | enabled | true |
ActionState | current_action_state | |
Dictionary | action_states | {} |
float | basic_attack_timer | 0.0 |
bool | executing_action | false |
Methods ​
void | setup( system_hub: GameHost.SystemHub, entity_ref: Entity ) |
void | set_encounter( encounter: CombatSession ) |
void | start_combat() |
void | end_combat() |
void | process_combat( delta: float ) |
void | change_state( state_name: ActionStateName, from_death: bool = false ) |
ActionStateName | get_current_state_name() |
bool | has_state( state_name: ActionStateName ) |
ActionStateName | get_combat_entry_state() |
String | get_state_name_string( state_name: ActionStateName ) |
Dictionary | to_save_data() |
void | from_save_data( save_data: Dictionary ) |
void | cleanup() |
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
bool uses_target_search = true ​
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