Sgcrabking
Based on game build 714014 | Last updated: 2026-03-08
Overview
SGcrabking is the stategraph responsible for managing the behavioral state transitions of the Crab King boss entity. It orchestrates transitions between idle behavior, taunts, freeze/cast attacks, claw/spawn stacking preparation, healing sequences (including rock repair), and hit/death animations. The stategraph integrates with common combat states (via CommonStates.AddCombatStates), freezing and electrocution states, and relies heavily on the health, timer, locomotor, and boatphysics components.
Usage example
The stategraph is applied automatically to the Crab King prefab via its stategraph declaration. No direct instantiation is required. The component is invoked internally by the engine when the entity's state changes:
-- Internally handled by the entity; example of external influence:
inst:PushEvent("ck_taunt") -- forces Crab King into the "taunt" state
inst:PushEvent("activate", { isload = false }) -- initializes the Crab King in active mode
Dependencies & tags
Components used: health, timer, locomotor, boatphysics, heavyobstaclephysics
Tags: Adds state tags including idle, canrotate, busy, casting, spawning, fixing, fixpre, loserock_window, inert, noattack, noelectrocute, canwxscan, nointerrupt, invisible, hit, healing, fixing
Properties
No public properties are defined or initialized in the constructor for this stategraph. All state-specific data is stored in inst.sg.statemem or inst fields at runtime.
Main functions
GetTransitionState(inst)
- Description: Determines which transition state to enter next based on the Crab King's current intent flags and conditions (e.g.,
wantstosummonclaws,wantstoheal,wantstofreeze). If multiple flags are set, the order of evaluation is priority-based. - Parameters:
inst(Entity instance) — the Crab King entity. - Returns: string or
nil— name of the next transition state (e.g.,"taunt","spawnclaws","fix_pre","cast_pre"), ornilif no transition is pending. - Error states: None. Returns
nilwhen no state change is needed.
push_nearby_boats(inst)
- Description: Applies a repulsive force to nearby boats within a radius to simulate water displacement from the Crab King's attack or movement.
- Parameters:
inst(Entity instance) — the Crab King entity. - Returns: Nothing.
- Error states: Does nothing if no nearby entities with the
boatphysicscomponent are found.
heal(inst)
- Description: Triggers health regeneration for the Crab King based on base regen and buffs scaled by orange gem count.
- Parameters:
inst(Entity instance) — the Crab King entity. - Returns: Nothing.
- Error states: Regeneration amount is computed using
TUNING.CRABKING_REGENandTUNING.CRABKING_REGEN_BUFF.
testforlostrock(inst, rightarm)
- Description: Monitors animation progress during healing sequences (
fix_pre,fix_loop) to detect if a rock was lost; if so, transitions tofix_lostrockstate. - Parameters:
inst(Entity instance),rightarm(boolean) — indicates which arm is performing the repair. - Returns: Nothing.
- Error states: Does nothing unless
loserock_windowstate tag is active andregen_stun_cooldowntimer is not running.
spawnwaves(inst, numWaves, totalAngle, waveSpeed, wavePrefab, initialOffset, idleTime, instantActivate, random_angle)
- Description: Helper that forwards arguments to
SpawnAttackWavesto spawn water-based projectiles during attacks. - Parameters:
numWaves(number) — number of wave groups.totalAngle(number) — angular spread in degrees.waveSpeed(number) — speed of each wave.wavePrefab(string ornil) — prefab name.initialOffset(number ornil) — offset from center.idleTime(number) — delay between wave groups.instantActivate(boolean) — whether to activate immediately.random_angle(boolean) — whether to randomize rotation.
- Returns: Nothing.
throwchunk(inst, prefab)
- Description: Spawns a chunk prefab (e.g., debris) at the Crab King's position and gives it a randomized physics velocity.
- Parameters:
inst(Entity instance) — the Crab King entity.prefab(string) — prefab name to spawn.
- Returns: Nothing.
Events & listeners
-
Listens to:
activate— initializes the entity in active (inert_pst) or idle state, starts freeze cooldown, and spawns cannons.ck_taunt— triggerstauntstate.socket— enterssocketstate when gems are inserted.attacked— triggers hit反应, electrocution check, and potential state transition tohit_light.animover,animqueueover,animdone— drive state transitions on animation completion.timerdone— handles timeouts (e.g.,taunt,do_end_cast).startfalling,stopfalling— viaheavyobstaclephysics:AddFallingStatesfor crown drop logic.- Freezing and electrocution events injected by
CommonStates.AddFrozenStatesandCommonStates.AddElectrocuteStates. - Combat death/hit events via
CommonStates.AddCombatStates.
-
Pushes:
healthdelta— automatically viahealth:DoDelta.startfalling,stopfalling— on crown entity during death.- Custom events like
healthdelta,animover, etc., are pushed internally by the engine or viainst:PushEvent.