Berniebrain
Based on game build 714014 | Last updated: 2026-02-27
Overview
The BernieBrain component implements the behavior tree for the "Bernie" character (shaggy monster). It handles leader detection based on player sanity and relationship conditions, coordination of taunting nearby sanity-based creatures, and triggering of the transformation into "Big Bernie" when specific proximity and player state conditions are met. It extends Brain, uses the behavior tree (BT) system, and relies on the Combat and Timer components to manage targeting and cooldowns, and the Sanity component (indirectly via deprecated IsCrazy usage) to verify player sanity states.
Dependencies & Tags
- Components used:
combat: accessed viatarget.components.combat:TargetIs(),:CanTarget(),:SetTarget()timer: accessed viaself.inst.components.timer:TimerExists(name)to check for cooldown timerssanity: accessed indirectly via deprecatedself._leader.components.sanity:IsCrazy()call (commented out in current code)
- Tags checked (via
inst:HasTag()or passed toFindEntities):shadowcreature,_combat,locomotor,INLIMBO,notaunt,bernieowner - Tags added/removed: None directly within this brain; relies on external tags attached to
instand targets.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
_targets | table or nil | nil | List of valid tauntable shadow creatures within range; set during behavior tree evaluation. |
_leader | entity or nil | nil | The current leader player the Bernie is following or targeting for "Big Bernie" transformation; updated each frame or conditionally. |
Main Functions
BernieBrain:OnStart()
- Description: Initializes and assigns the behavior tree for Bernie. This is the entry point called when the brain begins executing. It constructs a priority-based behavior tree with nodes for transformation, taunting, leader presence checks, following, and wandering.
- Parameters: None.
- Returns: None.
IsTauntable(inst, target)
- Description: A helper function used by
FindShadowCreaturesandTauntCreatures. Determines if a given entity qualifies as a valid target for taunting by Bernie (i.e., has acombatcomponent, is not already targeting Bernie, and can be targeted by Bernie). - Parameters:
inst: The Bernie entity instance.target: The candidate target entity.
- Returns:
boolean—trueiftargetcan be taunted, otherwisefalse.
FindShadowCreatures(inst)
- Description: Scans the area around Bernie for nearby entities tagged as
shadowcreature(and with_combatandlocomotortags) while excluding those tagged withINLIMBOornotaunt. Filters the results to retain only those that are tauntable perIsTauntable. - Parameters:
inst— the Bernie entity instance. - Returns: A table of valid tauntable shadow creatures if any exist within
TAUNT_DIST(16 units); otherwisenil.
TauntCreatures(self)
- Description: Assigns Bernie as the current target of all entities listed in
self._targetsusing thecombatcomponent, and transitions Bernie into the"taunt"state if at least one creature was successfully taunted. - Parameters:
self: The brain instance (carries_targetsandinst).
- Returns: None.
FindLeader(self)
- Description: Searches through all players to find the closest valid leader. A leader must be visible, on the same platform as Bernie, and satisfy either
isleadercrazyorhotheadedrelationship checks. Selection prioritizes proximity (uses squared distance comparisons for efficiency). - Parameters:
self— the brain instance. - Returns: The closest qualifying player entity or
nilif none found.
GetLeader(self)
- Description: Validates the currently cached
_leader. If the leader is no longer valid (not existing, not visible, not satisfying sanity/relationship checks), it clears_leadertonil. Note: The sanity check uses the deprecatedIsCrazy()call, which is commented out in the current logic. - Parameters:
self— the brain instance. - Returns: The valid leader entity or
nil.
countbigbernies(leader)
- Description: Returns the number of Bernie entities currently registered under
leader.bigbernies, used to track how many Bernies have transformed for a given player. - Parameters:
leader— the player entity with abigberniestable. - Returns:
number— the count of Bernies.
ShouldGoBig(self)
- Description: Determines if Bernie should transform into "Big Bernie". A qualifying player must have the
"bernieowner"tag, must not have initializedbigberniesorblockbigberniestables, must satisfyisleadercrazyorhotheadedchecks, must be visible, and must be withinBIG_LEADER_DIST_SQ(64 units, i.e., 8 units squared). - Parameters:
self— the brain instance. - Returns:
boolean—trueif transformation conditions are met; otherwisefalse. Also setsself._leaderto the qualifying player.
OnEndBlockBigBernies(leader)
- Description: Cleans up the
blockbigberniestimer on the leader after.5seconds, unblocking further Big Bernie transformations from other Bernies. - Parameters:
leader— the player entity. - Returns: None.
DoGoBig(inst, leader)
- Description: Initiates transformation into "Big Bernie". Prevents race conditions by setting a
.5second block timer (blockbigbernies) on the leader if not already present, and callsinst:GoBig(leader). - Parameters:
inst: The Bernie entity instance.leader: The player entity to link the transformation to.
- Returns: None.
Events & Listeners
- Listens to: None. Behavior is driven by explicit state transitions and behavior tree evaluation, not event listeners.
- Pushes: None. Transitions are handled by calling
self.inst.sg:GoToState(...).