Skip to main content

CaveTeleporterManager

A class in Root.Township, Alta.Caves.

Singleton network entity that tracks the cave teleporter on each cave layer and its fuel, and moves players between them. The server saves and syncs it; it resets on a cave wipe.

Constructors​

MemberWhat it is
CaveTeleporterManager()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

5 private and internal fields
MemberWhat it is
private DateTime lastSoundEffectWhen the local teleport sound last played, for the cooldown.
private static Logger loggerLogger for this class.
private MethodSyncStruct<TeleportEffectArgument> syncEffectMessage sync for teleport effects.
private MethodSync syncFullMessage sync for the full layer list.
private MethodSyncStruct<int> syncProxyMessage sync for a single layer's fuel.

Properties​

MemberWhat it is
Dictionary<int, CaveTeleporterProxy> AvailableLayers { get; }Teleporter proxies by cave layer, each holding the destination position and fuel.
static CaveTeleporterManager Instance { get; private set; }The manager in the scene, set on Awake.

Events​

MemberWhat it is
static event Action<CaveTeleporterProxyData> OnProxyUpdatedfuelRaised when a layer's fuel changes.
static event Action OnSyncedFullClient: raised after the full layer list arrives, and on a cave wipe.

Methods​

MemberWhat it is
static void ConsumeFuel(int layer, int cost)Takes fuel from a layer's teleporter.
static Vector3 GetTeleportPosition(int layer)Where a teleport to a layer lands, or a random OutsideCave spawn point if that layer has no teleporter.
override void Initialize()Sets up the full, per-layer and effect syncs.
override void InitializeAsServer(SpawnData spawnData)Hooks the cave wipe, which clears every layer but 0.
override void OnConnected(Player player)Sends every layer's fuel to a joining player.
static void Register(int layer, CaveTeleporter teleporter)Adds a teleporter for a layer. If the layer already has one, the fuel is matched to the lower of the two.
static CaveTeleportConnection RequestConnection(int fromLayer, int toLayer)Works out a connection and fuel costs between two layers. Empty for the same layer or an unknown start layer.
static void TeleportPlayer(IPlayer player, Vector3 toPosition, int toLayer, Action<IPlayer> finished)Server: plays the departure effect, waits the teleport delay, then moves the player and briefly protects them from impacts.
9 private and internal methods
MemberWhat it is
private void Awake()Sets Instance to this.
private bool CheckForLocalSoundCooldown()Client: returns false if the local teleport sound played too recently, otherwise records the time and returns true.
private static void DelayTeleport(IPlayer player, TeleportEffectArgument argument, Action<IPlayer> finished)Server: after the teleport delay, moves the player to the chunk at the target, plays the arrival effect and grants impact invincibility.
private void OnDestroy()Unhooks from the server cave wipe event.
private static void ProxyUpdatedFuel(CaveTeleporterProxy proxy)Runs when a layer's fuel changes: raises OnProxyUpdatedfuel and, on the server, syncs that layer's fuel to clients.
private void SyncEffect(IPlayer player, Stream stream, TeleportEffectArgument effectArgument)Network message for teleport effects: on clients plays the effect and sound, and fades the screen for the teleporting player on departure.
private void SyncFull(IPlayer player, Stream stream)Network message that sends every layer's fuel; clients rebuild AvailableLayers and raise OnSyncedFull.
private void SyncProxy(IPlayer player, Stream stream, int layer)Network message that sends one layer's fuel; clients update it and raise OnProxyUpdatedfuel.
private void WipeCaves()Server: on a cave wipe, drops every layer except layer 0 and resyncs clients.