Shard Daywalkerspawner
Overview
This component tracks and synchronizes the Daywalker's current location (e.g., cavejail or forestjunkpile) across networked shards. It is only instantiated on the mastershard and uses a networked tinybyte variable (location) to persist and sync location state. On the mastershard, it automatically transitions the location upon receiving the master_shardbossdefeated event; on client shards, it merely syncs the value and updates the local state.
Dependencies & Tags
inst.GUIDis used to bind the network variable.- On the mastershard: listens for the
"master_shardbossdefeated"event onTheWorld. - On clients: listens for the
"locationdirty"event on the entity. - Tags: None explicitly added/removed.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | (passed to constructor) | The entity this component is attached to (typically a shard). |
DAYWALKERLOCATION | table | { cavejail = 0, forestjunkpile = 1 } | Enum mapping location names to integer IDs. |
DAYWALKERLOCATION_LOOKUP | table | { 0 = "cavejail", 1 = "forestjunkpile" } | Reverse lookup map (populated by UpdateLocationNames()). |
location | net_tinybyte | 0 | Networked variable storing the current location ID. Synced via locationdirty events. |
Main Functions
UpdateLocationNames()
- Description: Builds or rebuilds the reverse lookup table (
DAYWALKERLOCATION_LOOKUP) from theDAYWALKERLOCATIONenum for efficient name ↔ ID conversion. - Parameters: None.
GetLocation()
- Description: Returns the current integer location ID stored in the network variable.
- Parameters: None.
GetLocationName()
- Description: Returns the string name (e.g.,
"cavejail") corresponding to the current location ID. - Parameters: None.
SetLocation(location)
- Description: Sets the location by ID or name (supporting string input), updates the network variable, and triggers a
"locationdirty"event. - Parameters:
location(string or number): Location name (e.g.,"forestjunkpile") or enum ID (e.g.,1). Defaults to0if name is invalid.
GetNewLocationName(oldlocation)
- Description (mastershard only): Determines the next location based on the current one (currently only supports toggling between
"cavejail"and"forestjunkpile"). Returnsnilfor unrecognized locations. - Parameters:
oldlocation(string): Current location name.
OnLocationUpdate(src, data)
- Description (mastershard only): Handles the
master_shardbossdefeatedevent by advancing the Daywalker’s location whendata.bossprefab == "daywalker". - Parameters:
src(Entity): Source of the event.data(table?): Event payload; must containbossprefaband optionallyshardid. Ignored ifnil.
OnSave()
- Description (mastershard only): Returns a serializable table containing the current location name for save/load persistence.
- Parameters: None.
OnLoad(data)
- Description (mastershard only): Restores the location from saved data (e.g., after world load or shard respawn).
- Parameters:
data(table?): Saved component state; expectsdata.locationas a string.
GetDebugString()
- Description: Returns a debug string with mastershard status and current location name for logging.
- Parameters: None.
Events & Listeners
- Listens for
"master_shardbossdefeated"onTheWorld(mastershard only). - Listens for
"locationdirty"on the entity (client shard only). - Triggers
"locationdirty"whenSetLocation()updates the network variable.