Sgklaus
Based on game build 714014 | Last updated: 2026-03-08
Overview
SGklaus is a stategraph that controls the AI behavior of Klaus, the winter season boss. It orchestrates movement, combat sequences (claw swipes, chomp lunges), summoning Deer soldiers, transitions (including the enrage state and calling for help), laughter cycles (triggered when nearby Deers survive attacks), and the death/resurrection loop. It interacts with multiple components—combat, commander, health, freezable, burnable, sleeper, hauntable, grouptargeter, locomotor, lootdropper, timer, and epicscare—to drive the boss’s behavior, responsiveness, and visual/audio feedback.
Usage example
This is a stategraph, not a component, and is registered via return StateGraph("klaus", states, events, "init") at the end of the file. It is used internally by the klaus prefab to manage its behavior.
Dependencies & tags
Components used: combat, commander, health, freezable, burnable, sleeper, hauntable, grouptargeter, locomotor, lootdropper, timer, epicscare.
Tags added/removed: idle, canrotate, hit, busy, attack, nosleep, nofreeze, noelectrocute, caninterrupt, transition, enrage, corpse. Tags are dynamically added/removed during state transitions (e.g., nosleep, nofreeze, noelectrocute during attacks, transitions, and resurrection).
Properties
No public properties are exposed directly by this stategraph file. State-specific data is stored in inst.sg.mem and inst.sg.statemem (e.g., wantstotransition, laughing, deer, target, speed, jump).
Main functions
The stategraph itself is a configuration table (states, events) returned as a StateGraph. The core logic resides in state handlers (onenter, timeline, ontimeout, onexit, onupdate, events) and helper functions defined at module scope. These helpers are documented here:
DeerCanCast(deer)
- Description: Validates whether a Deer soldier is capable of casting a spell. Checks multiple state and component conditions.
- Parameters:
deer(Entity) – the Deer entity to validate. - Returns:
boolean–trueif the Deer can cast,falseotherwise. - Error states: Returns
falseif the Deer is asleep, frozen, burning, dead, panicking, or taking fire damage.
PickCommandDeer(inst, highprio, lowprio)
- Description: Selects a suitable Deer soldier to issue a command to, based on priority and validity. Iterates over all soldiers and respects priority order.
- Parameters:
inst(Entity) – Klaus entity.highprio(Entity, optional) – high-priority Deer (e.g., previously used).lowprio(Entity, optional) – fallback low-priority Deer.
- Returns:
Entity or nil– selected Deer ornilif none qualify. - Error states: Returns
nilif no valid Deers can cast.
ChooseAttack(inst)
- Description: Decides between commanding Deer soldiers (if cooldown allows and soldiers exist) or performing a direct attack.
- Parameters:
inst(Entity) – Klaus entity. - Returns:
boolean– alwaystrue. - Error states: Attempts to command only if
command_cdtimer is not running. Falls back to"attack"state if no Deer can be selected.
TryChomp(inst)
- Description: Finds and initiates a chomp attack on a valid target.
- Parameters:
inst(Entity) – Klaus entity. - Returns:
boolean–trueif a chomp attack was started,falseotherwise. - Error states: Returns
falseifFindChompTarget()returnsnil.
CalcChompSpeed(inst, target)
- Description: Calculates the forward speed for Klaus’s chomp lunge, based on distance to the target.
- Parameters:
inst(Entity) – Klaus entity.target(Entity) – target to lunge toward.
- Returns:
number– speed multiplier for the lunge (> 0if moving,0otherwise). - Error states: Returns
0if target is invalid, too close, or position retrieval fails.
StartLaughing(inst)
- Description: Initializes the laughter cycle by setting the number of remaining laughs.
- Parameters:
inst(Entity) – Klaus entity. - Returns: Nothing.
ReduceLaughing(inst, amt)
- Description: Decreases the laughter count; removes the laughter state if count reaches zero.
- Parameters:
inst(Entity) – Klaus entity.amt(number) – amount to subtract from laugh count.
- Returns: Nothing.
StopLaughing(inst)
- Description: Immediately terminates any laughter state by clearing the laugh count.
- Parameters:
inst(Entity) – Klaus entity. - Returns: Nothing.
Events & listeners
- Listens to:
doattack– triggersChooseAttack.attacked– initiateshitstate unless busy or recovering.chomp– triggersTryChompor queues chomp intent.enrage– triggerstransitiontoenrage(if not enraged and not busy).transition– triggerstransitiontocallforhelp(if not already enraging and not busy).animover,death,freeze,electrocute,sleep,wake,sink,voidfall,corpsechomped,dropkey– viaCommonHandlers.
- Pushes:
epicscare(viaEpicScare:Scare) duringtaunt_roar.dropkeywith aklaussackkeyentity during death (if unchained).locomote,onextinguish,epicscare,attackedevents are forwarded as needed.