BehaviorReaction ​
Inherits: Resource
BehaviorReaction represents an event-driven response that can switch behavior schedules. Uses clean signal-based communication with automatic connection tracking.
Properties ​
String | reaction_name | "Unnamed Behavior Reaction" |
TriggerEvent | trigger_event | TriggerEvent.PLAYER_NEARBY |
Array[EntityCondition] | conditions | [] |
float | reaction_cooldown | 0.0 |
ReactionType | reaction_type | ReactionType.SWITCH_SCHEDULE |
int | target_schedule_index | 0 |
String | target_schedule_name | "" |
bool | return_to_previous | true |
float | return_delay | 2.0 |
int | target_hour | 9 |
int | target_minute | 0 |
float | health_threshold_percent | 30.0 |
Variables ​
Entity | entity | |
ModularBehaviorScript | behavior_script | |
Timer | cooldown_timer | |
TaskSchedule | previous_schedule | null |
Timer | return_timer | null |
bool | is_active | false |
ChronoManager | chrono_manager | |
EventManager | event_manager |
Methods ​
void | setup( system_hub: GameHost.SystemHub, entity_ref: Entity, script: ModularBehaviorScript ) |
bool | should_trigger() |
bool | try_trigger() |
bool | execute_reaction() |
void | return_to_previous_schedule() |
void | on_player_detection_changed( player_nearby: bool ) |
bool | is_on_cooldown() |
float | get_cooldown_remaining() |
bool | force_trigger() |
void | cancel_reaction() |
void | cleanup() |
Signals ​
reaction_triggered( reaction_name: String, trigger_event: TriggerEvent ) ​
Emitted when this reaction triggers
reaction_returned( reaction_name: String ) ​
Emitted when this reaction returns to previous schedule
reaction_failed( reaction_name: String, reason: String ) ​
Emitted when reaction fails to execute
Enumerations ​
enum TriggerEvent ​
Events that can trigger behavior reactions
- PLAYER_NEARBY =
0- When player enters detection radius - PLAYER_LEFT =
1- When player leaves detection radius - TIME_CHANGED =
2- When game time reaches specific hour - HEALTH_BELOW_PERCENT =
3- When entity health drops below threshold - EVENT_STARTED =
4- When a world event begins - EVENT_ENDED =
5- When a world event ends - QUEST_ACCEPTED =
6- When player accepts a quest - QUEST_COMPLETED =
7- When player completes a quest - ITEM_EQUIPPED =
8- When entity equips an item - ITEM_UNEQUIPPED =
9- When entity unequips an item
enum ReactionType ​
Types of reactions that can be performed
- SWITCH_SCHEDULE =
0- Switch to a different schedule - PAUSE_BEHAVIOR =
1- Temporarily pause all behavior - RESUME_BEHAVIOR =
2- Resume paused behavior - RESET_SCHEDULE =
3- Reset current schedule to beginning - TRIGGER_TASK =
4- Execute a specific task immediately
Property descriptions ​
String reaction_name = "Unnamed Behavior Reaction" ​
Display name for this reaction (for debugging)
TriggerEvent trigger_event = TriggerEvent.PLAYER_NEARBY ​
Event that triggers this reaction
Array[EntityCondition] conditions = [] ​
Conditions that must be met for reaction to execute (in addition to event trigger)
float reaction_cooldown = 0.0 ​
Cooldown before this reaction can trigger again (seconds)
Reaction Behavior
ReactionType reaction_type = ReactionType.SWITCH_SCHEDULE ​
Type of reaction this performs
int target_schedule_index = 0 ​
Index of schedule to switch to (for SWITCH_SCHEDULE type)
String target_schedule_name = "" ​
Name of schedule to switch to (alternative to index)
bool return_to_previous = true ​
Whether to return to previous schedule after trigger ends
float return_delay = 2.0 ​
Time to wait before returning to previous schedule
Event Settings
int target_hour = 9 ​
For TIME_CHANGED: target hour (0-23)
int target_minute = 0 ​
For TIME_CHANGED: target minute (0-59)
float health_threshold_percent = 30.0 ​
For HEALTH_BELOW_PERCENT: health threshold
Variable descriptions ​
Entity entity ​
Reference to the entity
ModularBehaviorScript behavior_script ​
Reference to the modular behavior script
Timer cooldown_timer ​
Internal cooldown timer
TaskSchedule previous_schedule = null ​
Previous schedule before this reaction triggered
Timer return_timer = null ​
Timer for returning to previous schedule
bool is_active = false ​
Whether this reaction is currently active
ChronoManager chrono_manager ​
SystemRefrences
EventManager event_manager ​
The event manager the reaction listens to.
Method descriptions ​
void setup( system_hub: GameHost.SystemHub, entity_ref: Entity, script: ModularBehaviorScript ) ​
Setup the reaction with entity and behavior script references
bool should_trigger() ​
Check if reaction should trigger (called by signal handlers)
bool try_trigger() ​
Execute the reaction if conditions are met
bool execute_reaction() ​
Execute the specific reaction type
void return_to_previous_schedule() ​
Return to previous schedule
void on_player_detection_changed( player_nearby: bool ) ​
External method for player detection (called by behavior state component)
bool is_on_cooldown() ​
Check if reaction is currently on cooldown
float get_cooldown_remaining() ​
Get remaining cooldown time
bool force_trigger() ​
Force trigger the reaction (bypasses cooldown and conditions)
void cancel_reaction() ​
Cancel active reaction and return to previous schedule
void cleanup() ​
Clean up all resources