Forestdaywalkerspawner
Overview
This component orchestrates the delayed spawning of the Day Walker in the Forest biome. It tracks respawn timing via a countdown of in-game days, interacts with a junk pile (bigjunk) to trigger the burial/spawn sequence, and responds to the Day Walker’s defeat to increment power levels. It only exists on the master simulation and synchronizes spawn readiness with the shard-level shard_daywalkerspawner.
Dependencies & Tags
- Required Components on
inst: None directly added by this component (assumesinstis a valid world or worldroot entity with appropriate tags). - External Components Used:
TheWorld.components.wagpunk_managerTheWorld.shard.components.shard_daywalkerspawner
- Entity Tags: None explicitly added or removed.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
days_to_spawn | number | TUNING.DAYWALKER_RESPAWN_DAYS_COUNT | Number of days remaining before the Forest can spawn the Day Walker. Decrements on each OnDayChange. |
power_level | number | 1 | Current power level of the Forest (1 or 2). Incremented on Day Walker defeat. |
bigjunk | Entity or nil | nil | Reference to the junk pile entity used to bury/spawn the Day Walker. Set during spawn attempt. |
daywalker | Entity or nil | nil | Reference to the currently active Day Walker entity, if spawned. |
Main Functions
IncrementPowerLevel()
- Description: Increases the
power_levelby 1, up to a maximum of 2. - Parameters: None.
GetPowerLevel()
- Description: Returns the current
power_level. - Parameters: None.
TryToSetDayWalkerJunkPile()
- Description: Attempts to retrieve and assign the
bigjunkentity fromwagpunk_manager. Returnstrueon success,falseotherwise. - Parameters: None.
ShouldShakeJunk()
- Description: Returns
trueif abigjunkentity is currently assigned. - Parameters: None.
CanSpawnFromJunk()
- Description: Determines whether the Forest can currently spawn the Day Walker. Requires either:
(a) an assignedbigjunk(burial-in-progress state), or
(b) a matching shard spawner location ("forestjunkpile"), anddays_to_spawn≤ 0.
Returnsfalseif a Day Walker is already active. - Parameters: None.
OnDayChange()
- Description: Called at the start of each new day. Decrements
days_to_spawnwhile > 0. When reaching 0, initiates the spawn sequence ifTryToSetDayWalkerJunkPilesucceeds, by callingStartDaywalkerBuried()on the junk pile. - Parameters: None.
WatchDaywalker(daywalker)
- Description: Registers the given Day Walker entity for tracking. Sets up an
onremoveevent listener to incrementpower_leveland notify the shard on defeat, then clears the reference. - Parameters:
daywalker(Entity): The Day Walker entity to monitor.
HasDaywalker()
- Description: Returns
trueif a Day Walker is currently spawned and tracked. - Parameters: None.
OnPostInit()
- Description: Initializes event listening for world
cycles(day changes) ifTUNING.SPAWN_DAYWALKERis enabled. Immediately triggersOnDayChange()ifdays_to_spawn≤ 0. - Parameters: None.
OnSave()
- Description: Prepares data and entity references for serialization. Includes
days_to_spawn,power_level, and optional GUIDs fordaywalkerandbigjunk. - Parameters: None.
- Returns:
data(table),refs(table of GUIDs ornil).
OnLoad(data)
- Description: Restores saved state (
days_to_spawn,power_level) from serialized data. - Parameters:
data(table): Data dictionary fromOnSave.
LoadPostPass(ents, data)
- Description: After all entities are loaded, restores references to
daywalkerandbigjunkusing stored GUIDs. CallsWatchDaywalker()on the Day Walker to reattach listeners. - Parameters:
ents(table): Loaded entities map by GUID.data(table): Loaded data dictionary (same as passed toOnLoad).
Events & Listeners
- Listens to:
"onremove"on thedaywalkerentity (set viaWatchDaywalker) — triggers power-level increment and shard sync on defeat."cycles"onTheWorld(set inOnPostInit) — callsOnDayChange()at the start of each day.