Sgdaywalker2
Based on game build 714014 | Last updated: 2026-03-08
Overview
SGdaywalker2 is a stategraph component that controls the Daywalker2 entity's behavioral sequences, including targeted attacks (laser, cannon, tackle, pounce), item-based actions (rummaging, junk throw), environmental interactions (AOE trampling, collapsing workables), and transitions through idle, aggressive, sleeping, and defeated states. It coordinates attack logic, particle effects, sound, and AI state transitions using event-driven callbacks and timeline frame events.
Usage example
-- Example: Triggering a cannon attack from the Daywalker2 entity
inst:PushEvent("doattack", { target = enemy_entity })
-- Internally, ChooseAttack will select cannon if conditions are met
-- This transitions into 'laser_pre' → 'cannon' state sequence
-- firing multiple lasers via timeline frame events and handling knockback/damage
-- Example: Handling rummage completion
-- Upon 'rummage' event payload, the 'rummage' state begins
-- When ruminage times out, rummage_ontimeout() decides whether to throw or lift
inst:PushEvent("rummage", { data = { ... } })
Dependencies & tags
Components used:
combat(viainst.components.combat:DoAttack())workable(viacomponents.workable)mine(viacomponents.mine)physics(viaphysics)scare(viaScare(5)call in epic scare component)
Tags:
"rummaging"— added during rummaging or rummage hit."idle"— active during idle, talk, angry, etc."canrotate"— allows facing rotation toward target."busy"— blocks interruption (added during most non-idle states)."nosleep"— prevents sleep transitions during critical actions."sleeping"— used internally to track sleep state."caninterrupt"— allows interruption (added after attack phases)."notalksound"— suppresses talk sound during some attacks."attack"— marks attack states."hit"— active during hit states."talking"— active during talk states."angry"— active during angry state."defeated"— block to prevent reactivation after defeat."noelectrocute"— blocks electrocution during emerge/rummage."stalking"— conditionally added in idle when stalking."walk"— tracked for walking state."nowake"— prevents wake transition."flight","invisible","notarget","noattack","junk_fence","INLIMBO"— used inAOE_TARGET_CANT_TAGS."NPC_workable","CHOP_workable","HAMMER_workable","MINE_workable"— used inCOLLAPSIBLE_TAGS."FX","DECOR","blocker","junk_pile_big"— used inNON_COLLAPSIBLE_TAGS.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
| None identified |
Main functions
ChooseAttack(inst)
- Description: Selects and initiates the highest-priority attack based on available abilities (
canswing,cancannon,cantackle) and distance to target. Falls back to pounce if rooted or stuck. - Parameters:
inst— the entity instance.
- Returns:
trueif an attack state was initiated,falseornilotherwise. - Error states: Relies on
inst.components.combat.targetbeing valid.
hit_recovery_skip_cooldown_fn(inst, last_t, delay)
- Description: Determines whether hit recovery cooldown can be skipped. Skips only when hit recovery equals
DAYWALKER_HIT_RECOVERY, combat is on cooldown, and state is idle. - Parameters:
inst,last_t,delay— unused for compatibility.
- Returns:
trueif skip allowed,falseotherwise.
_transfer_statemem_to_electrocute(inst)
- Description: If currently rummaging, stores
inst.sg.statemem.dataintoinst.sg.mem.transfer_databefore electrocution. - Parameters:
inst.
- Returns:
nil.
_AOEAttack(inst, dist, radius, arc, heavymult, mult, forcelanded, targets, overridenontags)
- Description: Performs area-of-effect (AOE) combat attacks on nearby valid targets within given range, angle, and position. Uses combat component to execute attacks and applies knockback.
- Parameters:
inst,dist,radius,arc— spatial parameters.heavymult,mult— knockback multipliers for heavy vs light armor.forcelanded— passed to knockback event.targets— table tracking already-hit targets.overridenontags— overridesAOE_TARGET_CANT_TAGSif truthy.
- Returns:
trueif at least one target hit.
_DoAOEWork(inst, dist, radius, arc, targets, canblock, overridenontags, trampledelays)
- Description: Performs AOE work actions (e.g., destroy, work) on collapsible workables. Supports trampling logic with delays.
- Parameters:
inst,dist,radius,arc,targets,canblock,overridenontags,trampledelays.
- Returns:
hit(trueif any workable destroyed),blocked(trueif first blocker hit andcanblock=true).
TossLaunch(inst, launcher, basespeed, startheight)
- Description: Launches an item away from a launcher using physics velocity with slight random angle.
- Parameters:
inst— item to launch.launcher,basespeed,startheight.
- Returns:
nil.
TossItems(inst, dist, radius)
- Description: Finds and tosses nearby items in arc/distance. Deactivates mines first.
- Parameters:
inst,dist,radius.
- Returns:
nil.
DoArcAttack(inst, dist, radius, arc, heavymult, mult, forcelanded, targets)
- Description: Combo of
_DoAOEWork+_AOEAttackfor arc-shaped attacks. Resets stuck detection if anything hit. - Parameters: Same as
_AOEAttack/_DoAOEWork. - Returns:
trueif either hit or worked.
DoAOEAttack(inst, dist, radius, heavymult, mult, forcelanded, targets, canblock, ignoreblock)
- Description: Full AOE attack (no arc). Optionally blocks on front blocker. Resets stuck detection.
- Parameters: Same as
_AOEAttack/_DoAOEWorkwithcanblock,ignoreblock. - Returns:
trueif hit or worked,blocked(boolean).
DoPounceAOEAttack(inst, dist, radius, heavymult, mult, forcelanded, targets)
- Description: Pounce-specific AOE attack. Does not reset stuck detection.
- Parameters: Same as
_AOEAttack. - Returns:
hitstatus (trueif hit).
DoPounceAOEWork(inst, dist, radius, targets)
- Description: Pounce-specific AOE work. Does not reset stuck detection.
- Parameters: Same as
_DoAOEWork. - Returns:
worked(boolean),blocked.
DoFootstepAOE(inst)
- Description: Runs
_DoAOEWorkon footstep radius to enable trampling of small obstacles. Resets stuck detection if worked. - Parameters:
inst. - Returns:
nil.
TryChatter(inst, strtblname, index, ignoredelay, echotochatpriority)
- Description: Wrapper calling
SGDaywalkerCommon.TryChatterwith pre-definedCHATTER_DELAYS. - Parameters: Passed through from call site.
- Returns:
nil.
SpawnDroppedJunk(inst, offset)
- Description: Spawns
junk_break_fxat Daywalker2’s current facing position. - Parameters:
inst,offset(unused). - Returns:
nil.
SpawnSwipeFX(inst, offset, reverse)
- Description: Spawns
daywalker2_swipe_fx, parents toinst, positions offset, optionally reverses animation. - Parameters:
inst,offset,reverse. - Returns:
nil. Stores fx ininst.sg.statemem.fx.
KillSwipeFX(inst)
- Description: Removes
inst.sg.statemem.fxif valid. - Parameters:
inst. - Returns:
nil.
CalcKnockback(scale)
- Description: Returns knockback multiplier tuple. For
scale ≥ 1, returns(nil, Lerp(1, 1.5, scale-1)). Forscale < 1, returns(scale, scale * 1.3, true). - Parameters:
scale. - Returns:
knockback mult, optionallystrengthmult, andforcelanded(boolean) ifscale < 1.
CalcDamage(dist)
- Description: Calculates damage based on distance using
Remapbetween min/max tunings, clamped. Returns player damage percent. - Parameters:
dist. - Returns:
damage,playerdamagepercent.
SpawnLaserHitOnly(inst, dist, scale, targets)
- Description: Spawns
alterguardian_laserempty(no visual), calculates damage/knockback, and triggers it. - Parameters:
inst,dist,scale,targets. - Returns:
nil.
SpawnLaser(inst, dist, angle_offset, scale, scorchscale, targets)
- Description: Spawns
alterguardian_laser, calculates knockback/damage, sets anim scale (flips on alternate use). - Parameters:
inst,dist,angle_offset,scale,scorchscale,targets. - Returns:
dist + 0.4.
DoFootstep(inst, volume)
- Description: Records timestamp in
inst.sg.mem.lastfootstepand plays footstep sound. - Parameters:
inst,volume. - Returns:
nil.
TurnToTargetFromNoFaced(inst)
- Description: If
canrotateandbusyin last tags and target exists, forces facing toward target. - Parameters:
inst. - Returns:
nil.
rummage_ontimeout(inst)
- Description: Handles rummage completion: if loot is "ball", goes to throw; otherwise lifts new item (object/spike/cannon) and supports double rummage.
- Parameters:
inst. - Returns:
nil.
CleanupIfSleepInterrupted(inst)
- Description: Helper function: if sleep interrupted, restores four-faced orientation.
- Parameters:
inst. - Returns:
nil.
Events & listeners
- Listens to:
freeze— transitions to "frozen" state if not defeated. - Listens to:
gotosleep— setssg.mem.sleeping = true; if notdefeated,nosleep, orsleeping, goes to "sleep". - Listens to:
onwakeup— clearssg.mem.sleeping; if sleeping and notnowake, setscontinuesleeping = trueand goes to "wake". - Listens to:
ontalk— if not hostile/busy: goes to "angry_taunt" if_thieflevel > 2; else goes to "talk" or "angry". Setskeepsixfacedorkeepnofaced. - Listens to:
doattack— callsChooseAttackif not busy/defeated. - Listens to:
electrocute— callsCommonHandlers.TryElectrocuteOnEventwith_transfer_statemem_to_electrocutecallback. - Listens to:
attacked— tries electrocute, or handles hit/recovery based on state tags; goes to "rummage_hit" if rummaging, otherwise "hit". - Listens to:
roar— goes to "taunt" with optional target. - Listens to:
minhealth— ifdefeatedand not yet "defeated" state, goes to "defeat". - Listens to:
teleported— goes to "hit" unless busy/defeated (unlesscaninterrupt). - Listens to:
rummage— goes to "rummage" with data payload. - Listens to:
tackle— goes to "tackle_pre" with target if not busy/defeated and target valid. - Listens to:
animover— triggers state transition upon animation completion for multiple states:"laser_pre","cannon","throw_pre","throw_loop","throw","throw_pst","tackle_pre","tackle_loop","tackle_lift","tackle_collide","tackle_pst","attack_pounce_pre","attack_pounce","attack_pounce_pst","taunt","defeat","defeat_idle_pre","defeat_idle". - Listens to:
CommonHandlers.OnLocomote,CommonHandlers.OnSink,CommonHandlers.OnFallInVoid— provided viastategraphs/commonstates.
Note: Event names follow DST’s
inst:ListenForEvent()convention. Events likeontalk,roar,tackle, etc., are typically pushed externally by AI or player interactions.