Daywalkerspawner
Based on game build 714014 | Last updated: 2026-03-03
Overview
Daywalkerspawner is a server-only component responsible for triggering Daywalker boss arena spawns over time. It tracks the number of days remaining before the next spawn (days_to_spawn), maintains a list of registered spawning points, determines optimal spawn locations, constructs the arena with pillars, and spawns the Daywalker prefab. It coordinates with shard_daywalkerspawner to respect world/shard context (e.g., skip spawning in non-cavejail shards) and records boss defeat to increment power_level.
Usage example
local inst = CreateEntity()
inst:AddComponent("daywalkerspawner")
-- Optional: configure initial state before postinit
inst.components.daywalkerspawner.days_to_spawn = 3
-- Register spawning points
inst.components.daywalkerspawner:RegisterDayWalkerSpawningPoint(spawnpoint_entity)
-- Trigger spawning logic manually (e.g., mod hook or debug)
inst.components.daywalkerspawner:OnDayChange()
Dependencies & tags
Components used: workable, shard_daywalkerspawner (via TheWorld.shard.components)
Tags: Adds daywalker_spawner; listens for onremove on spawning points and daywalker entities; checks tags like NPC_workable, structure, plant, tree, locomotor, DECOR, INLIMBO, and action-based workables (CHOP_workable, DIG_workable, HAMMER_workable, MINE_workable).
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | — | The entity instance this component is attached to. |
days_to_spawn | number | 0 | Days remaining until the next Daywalker arena can spawn. Decrements each day. |
power_level | number | 1 | Current spawn difficulty tier (max 2). Increases on Daywalker defeat. |
spawnpoints | array of entities | {} | List of registered spawning point entities. |
daywalker | Entity or nil | nil | Reference to the currently active Daywalker entity. |
Main functions
TryToRegisterSpawningPoint(spawnpoint)
- Description: Registers a spawning point entity if not already registered. Internally calls
RegisterDayWalkerSpawningPoint. Meant for internal use and mod access. - Parameters:
spawnpoint(Entity) — Entity to register as a potential Daywalker spawn location. - Returns:
trueif successfully registered;falseif already present. - Error states: No error states.
UnregisterDayWalkerSpawningPoint(spawnpoint)
- Description: Removes a spawning point from the internal list.
- Parameters:
spawnpoint(Entity) — Spawning point to unregister. - Returns: Nothing.
RegisterDayWalkerSpawningPoint(spawnpoint)
- Description: Registers the spawning point and sets up an
onremovelistener to automatically unregister it when the spawning point entity is removed. - Parameters:
spawnpoint(Entity) — Spawning point to register. - Returns: Nothing.
- Error states: No error states.
IncrementPowerLevel()
- Description: Increases the
power_levelby1, capped at2. - Parameters: None.
- Returns: Nothing.
GetPowerLevel()
- Description: Returns the current power level.
- Parameters: None.
- Returns:
number— Current power level (1or2).
IsValidSpawningPoint(x, y, z)
- Description: Checks if the given world coordinates are valid for spawning (must be above ground within a 3×3 tile region).
- Parameters:
x,z(number) — World coordinates (y is ignored; assumed0).
- Returns:
boolean—trueif all 9 adjacent tiles are above ground;falseotherwise.
SpawnDayWalkerArena(x, y, z)
- Description: Spawns the Daywalker prefab and surrounding arena pillars, and clears nearby entities that can be destroyed (e.g., structures, plants) via
workable:Destroyor direct removal. - Parameters:
x,y,z(number) — World coordinates for center of the arena.
- Returns:
Entity— The spawned Daywalker entity. - Error states: None documented; assumes valid coordinates.
FindBestSpawningPoint()
- Description: Selects the best spawn point from
spawnpoints, prioritizing:- Valid ground, no players within
NO_PLAYER_RADIUS, and no blocking tags (CANT_SPAWN_NEAR_TAGS) and no structures. - If none ideal, picks the spawning point with fewest nearby structures.
- If still none, picks a random point and attempts to find a nearby walkable offset within
5..15tiles.
- Valid ground, no players within
- Parameters: None.
- Returns:
x,y,z(number?) — Coordinates of chosen spawn location, ornilif none found.
TryToSpawnDayWalkerArena()
- Description: Shuffles
spawnpoints, callsFindBestSpawningPoint, and if successful, converts the point to tile center and callsSpawnDayWalkerArena. - Parameters: None.
- Returns:
Entityornil— Spawned Daywalker ornilif no valid location.
OnDayChange()
- Description: Called daily (via
WatchWorldState). Decrementsdays_to_spawnuntil zero, then attempts to spawn. Skips if:- A Daywalker is already spawned.
- In a shard where
shard_daywalkerspawnerexists and location is not"cavejail".
- Parameters: None.
- Returns: Nothing.
WatchDaywalker(daywalker)
- Description: Stores reference to the spawned Daywalker and sets an
onremovelistener to incrementpower_leveland sync boss defeat upon its death. - Parameters:
daywalker(Entity) — Daywalker instance to track. - Returns: Nothing.
OnPostInit()
- Description: If
TUNING.SPAWN_DAYWALKERistrue, starts daily cycle listener and attempts immediate spawn ifdays_to_spawn <= 0. - Parameters: None.
- Returns: Nothing.
OnSave()
- Description: Returns serializable state for save file, including
days_to_spawn,power_level, anddaywalker_GUIDif active. - Parameters: None.
- Returns:
data(table),refs(table?ornil) — Save data and GUID references.
OnLoad(data)
- Description: Loads state on scene load, hydrating
days_to_spawn(capped byTUNING.DAYWALKER_RESPAWN_DAYS_COUNT) andpower_level. - Parameters:
data(table?) — Saved data. - Returns: Nothing.
LoadPostPass(ents, data)
- Description: After entities are loaded, reattaches
daywalkerreference via GUID. - Parameters:
ents(table) — Map ofGUID → entity.data(table) — Loaded save data.
- Returns: Nothing.
Events & listeners
- Listens to:
ms_registerdaywalkerspawningground— TriggersTryToRegisterSpawningPointon new spawning points. - Listens to:
onremove— Removed on spawning points (unregister) and Daywalker entity (updatepower_leveland cleardaywalkerreference). - Pushes: None.