Vaultroom
Overview
The VaultRoom component handles virtual room generation and management for dungeon-like environments (e.g., the Vault level). It supports layout creation via predefined room definitions, entity persistence (save/load) during room transitions, and terrain reconfiguration. It ensures entities are properly preserved, skipped, or removed based on ownership, tags, and context during room unloading and loading.
Dependencies & Tags
- Uses
prefabs/vaultroom_defsmodule (defs) for room layout and terraforming functions. - Entities may rely on tags:
"INLIMBO","staysthroughvirtualrooms","irreplaceable". - Assumes entities may have components:
Transform,inventory,container,inventoryitem,spell,formationleader,follower,spelldata(indirect), andpersists.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | nil | The root entity this component is attached to (typically the vault door/wall representing the room). |
roomid | string or nil | nil | Identifier for the currently active vault room layout. nil indicates no room is active. |
Main Functions
GetCurrentRoomId()
- Description: Returns the ID of the currently loaded vault room layout.
- Parameters: None.
LayoutNewRoom(id)
- Description: Initializes a new vault room using the provided
idlayout. It applies terrain changes (viaTerraformRoomAtXZ), then spawns room contents (viaLayoutNewRoomAtXZ) if defined. Setsself.roomid. - Parameters:
id(string): The key indefsfor the desired room layout.
UnloadRoom(save)
- Description: Removes or saves entities within a radius of the room center, based on their relevance. Entities with tags or ownership chains outside the room are skipped; players or irreplaceable entities are kept; others are saved or removed. Returns a data table (if
save=true) with entity records and a list of remaining entities. - Parameters:
save(boolean): Iftrue, entity data is collected for persistence; iffalse, entities are removed immediately.
ResetRoom()
- Description: Unloads the current room without saving, then resets terrain to default using
ResetTerraformRoomAtXZ. - Parameters: None.
LoadRoom(id, data)
- Description: Loads a vault room either by generating a new one (
data == nil) or reconstructing it from persisted data (dataprovided). Handles entity spawning, post-pass linking, and time advancement for off-cycle entities. - Parameters:
id(string): The key indefsfor the room layout.data(table ornil): Optional saved room data. Ifnil, triggersLayoutNewRoom(id).
OnSave()
- Description: Returns a minimal table containing the active room ID for world persistence, or
nilif no room is active. - Parameters: None.
OnLoad(data)
- Description: Restores the active room ID from saved world data during load.
- Parameters:
data(table ornil): World save data containing theroomkey.
Events & Listeners
None.