Dragonflybrain
Based on game build 714014 | Last updated: 2026-02-27
Overview
DragonflyBrain is the behavior tree controller for the Dragonfly entity. It orchestrates high-level AI decisions—including combat targeting, lavae spawner coordination, resetting behavior when the Dragonfly strays too far from its spawn point, and leash-based movement—by constructing and maintaining a behavior tree during OnStart(). It interacts with core systems including combat, known locations, spawners, and stuck detection to ensure context-aware decision-making.
Dependencies & Tags
- Components used:
combat,knownlocations,rampingspawner,stuckdetection - Tags:
lava(used internally for entity filtering during spawner position selection)
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity instance | — | The entity the brain belongs to (inherited from Brain). |
bt | BehaviorTree instance | nil (assigned in OnStart) | The constructed behavior tree managing AI execution. |
_spawnpos | Vector3 or nil | nil | Cached spawn position for lavae entities; computed once per spawner cycle. |
resetting | boolean or nil | nil | Tracks whether a reset sequence is currently in progress. |
Main Functions
OnSpawnLavae()
- Description: Resets the cached spawn position and triggers the spawner to create one lavae entity. Called via the
"spawnlavae"event. - Parameters: None.
- Returns:
nil.
OnStart()
- Description: Constructs and assigns the behavior tree (
self.bt) for the Dragonfly. The root node evaluates sub-trees in priority order: reset-fight logic, lavae spawning (with parallel leash and stuck handling), chase-and-attack, leash to home point, and (currently commented out) wander. This defines the Dragonfly’s full behavioral repertoire. - Parameters: None.
- Returns:
nil.
OnInitializationComplete()
- Description: Records the Dragonfly’s initial world position as the
"spawnpoint"using theknownlocationscomponent. This point serves as the reference for home, reset distance, and spawner positioning. - Parameters: None.
- Returns:
nil.
HomePoint(inst)
- Description: Helper function returning the stored
"spawnpoint"location from theknownlocationscomponent. Used as the target for the leash behavior. - Parameters:
inst(Entity): The entity whose spawn point is queried (typically the Dragonfly itself).
- Returns:
Vector3(via:Get()), ornilif"spawnpoint"has not been set.
ShouldResetFight(self)
- Description: Determines if the Dragonfly has strayed beyond the configured reset distance (
TUNING.DRAGONFLY_RESET_DIST) from its spawn point or entered water. If true, setsinst.reset = trueand invokesinst:Reset(). Also updates the"flyover"state memory based on reset status. - Parameters:
self(DragonflyBrain): The brain instance.
- Returns:
boolean—trueif a reset is needed, otherwisefalse.
ShouldRetryReset(self)
- Description: Ensures the Dragonfly persists in attempting the
"GOHOME"action during a reset attempt. Returnsfalseon first call (to allowGoHometo buffer) andtrueonly if a"GOHOME"action is no longer buffered and the reset is still active. - Parameters:
self(DragonflyBrain).
- Returns:
boolean—trueif the buffered action should be re-evaluated, otherwisefalse.
GoHome(inst)
- Description: Creates a buffered
"GOHOME"action targeting the Dragonfly’s spawn point. Used to guide the entity back during reset attempts. - Parameters:
inst(Entity): The Dragonfly entity.
- Returns:
BufferedAction— Action request withaction = ACTIONS.GOHOME.
ShouldSpawnFn(self)
- Description: Determines whether to enter the lavae-spawning state. If no active waves remain, clears cached spawn position. Otherwise, computes and caches a spawn position near a lava pond near
"spawnpoint"or defaults to the Dragonfly’s own position. Updates"flyover"state memory and returns the computed boolean flag. - Parameters:
self(DragonflyBrain).
- Returns:
boolean—trueif spawners should execute, otherwisefalse.
Events & Listeners
- Listens to: None (no
inst:ListenForEventcalls are present). - Pushes:
"doattack"— viacombat:TryAttack()(indirect, via thecombatcomponent)."rampingspawner_spawn"— viarampingspawner:SpawnEntity()(indirect, via therampingspawnercomponent)."spawnlavae"— explicitly inOnSpawnLavae()and in the behavior tree’s"Spawn Lavae"branch."reset"— implicitly viainst:Reset()called withinShouldResetFight().