Hostedbrain
Based on game build 714014 | Last updated: 2026-02-27
Overview
The HostedBrain component defines the AI behavior for entities that operate as coordinated "hosted" units—typically parasitic minions (e.g., spider-related entities) that engage in group combat. It orchestrates behavior through a behavior tree to prioritize attacking while respecting a shared targeting system (via combat:SuggestTarget and combat:ShareTarget). Units maintain formation relative to their target and coordinate with nearby hosted allies to limit simultaneous attacks. The brain ensures proper cleanup upon removal and registers for combat-related events.
This brain is built on top of Brain (via Class(Brain, ...)), reusing common utility behaviors (Wander, ChaseAndAttack, Leash, FaceEntity, DoAction, StandStill), and integrates with the Combat component for target management.
Dependencies & Tags
- Components used:
combat: accessed viainst.components.combatto check cooldowns, suggest targets, and share aggro.Transform: used for position/angle calculations.
- Tags used:
HOSTED_MUST_TAGS = { "shadowthrall_parasite_hosted" }: entities must have this tag to be considered as potential allies for targeting.HOSTED_CANT_TAGS = { "FX", "NOCLICK", "DECOR", "INLIMBO" }: implicitly excluded from targeting/search (used by common utility functions).
- No tags are added or removed by this component.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst.reserved_target | entity? | nil | Temporarily assigned when this entity reserves the right to attack the current combat target (used to prevent excessive simultaneous attacks in formation). Cleared after returning to formation via DoAction(ClearReservedTarget). |
PARASITES (global) | table | {} | Tracks all active hosted entities using this brain (keyed by entity instance). Used to count how many allies are already attacking the same target. |
Main Functions
ClearReservedTarget(inst)
- Description: Resets the
reserved_targetproperty on the instance, effectively releasing the reservation to attack. Typically invoked after the entity returns to formation. - Parameters:
inst: The entity instance whosereserved_targetshould be cleared.
- Returns: None.
GetTarget(inst)
- Description: Retrieves the current combat target stored in the
Combatcomponent. - Parameters:
inst: The entity instance.
- Returns:
entity?— The current target, ornilif no target is set.
GetTargetPos(inst)
- Description: Returns the world position of the current combat target, if valid.
- Parameters:
inst: The entity instance.
- Returns:
{x: number, y: number, z: number}ornil.
GetFormationPos(inst)
- Description: Calculates a position behind the combat target (relative to the entity’s current angle), used as the destination in the
Leashbehavior to maintain formation. - Parameters:
inst: The entity instance.
- Returns:
{x: number, y: number, z: number}ornilif no target.
CanAttackTarget(inst)
- Description: Determines if this entity is permitted to attack the current target. Enforces formation attack coordination: if
FORMATION_SIMULTANEOUS_ATTACKS(set to2) allies are already attacking, or if a random roll fails (70% chance to claim attack right), it returnsfalseto stagger attacks. If allowed, it reserves the target for itself. - Parameters:
inst: The entity instance.
- Returns:
boolean—trueif the entity may attack now and has reserved the target;falseotherwise.
OnAttacked(inst, data)
- Description: Event handler for the
"attacked"event. Automatically sets the attacker as the new combat target and shares aggro with up to 30 nearby entities that have theshadowthrall_parasite_hostedtag. - Parameters:
inst: The entity instance.data: Event data containingdata.attacker.
- Returns: None.
OnRemoved(inst)
- Description: Removes this entity from the global
PARASITEStable to stop it from being considered in attack coordination. - Parameters:
inst: The entity instance.
- Returns: None.
HostedBrain:OnStart()
- Description: Initializes the behavior tree and event listeners. Adds this instance to
PARASITES(if still valid), sets up"attacked"and"onremove"callbacks, and defines the root behavior tree logic:- Prioritize attacking if
CanAttackTargetreturnstrue. - Return to formation (
Leash) if target is out of range or not actively attacking. - Clear reserved target upon reaching formation.
- Face the target while idle.
- Wander locally if no target.
- Stand still as fallback.
- Prioritize attacking if
- Parameters: None.
- Returns: None.
HostedBrain:OnStop()
- Description: Cleans up upon brain deactivation: removes this entity from
PARASITES, clearsreserved_target, and unregisters event callbacks. - Parameters: None.
- Returns: None.
Events & Listeners
- Listens to:
"attacked": TriggersOnAttacked, which sets the attacker as target and shares aggro with allies."onremove": TriggersOnRemoved, which deregisters the entity from global tracking.
- Pushes: None (no events are explicitly fired by this component).