Skip to main content

PoweredRespawnShrine

A class in Root.Township, ATT.Respawn.

A respawn shrine that runs on fuel. Players toggle it as their spawn point, and it only works while it has power. Both sides: the server owns the respawn data, clients update glyphs, fuel display and sounds.

Constructors​

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

Fields​

7 private and internal fields
MemberWhat it is
private RespawnShrineFuelDisplay fuelDisplayShows the fuel item and amount above the shrine.
private FloatEvent powerStateChangedEvent raised with the normalised remaining power, for visuals.
private string shrineIdSaveDataThe shrine's id as a string. Saved, loaded and synced to clients.
private IRespawnShrineSettings shrineSettingsSettings for this shrine (id, fuel capacity, fuel item), looked up from the id.
private RespawnShrineStaticAudioController staticAudioControllerPlays the looping sound while the shrine has subscribers.
private RespawnShrineSubscriberMarkController subscriberMarkControllerDraws the orbiting marks that show how many players use this shrine.
private MethodSync syncShrineIdToClientMethod sync (SyncA) sent to each connecting player with the shrine id.

Properties​

MemberWhat it is
protected override Guid ShrineId { get; }The shrine's ID, taken from its settings.
1 private and internal property
MemberWhat it is
private bool IsLoaded { get; }True once the shrine settings have been looked up from the shrine id.

Methods​

MemberWhat it is
float GetCurrentFuel()Remaining fuel: the shrine's normalized powered time times its max fuel capacity.
int GetMaxFuel()The shrine's max fuel capacity from its settings.
void Load(PoweredRespawnShrineSaveData data, ISerializeChildren childSerializer)Loads the shrine ID from save data and looks up its settings.
override void OnConnected(Player player)Server: sends the shrine ID to the joining player so their copy can find its settings.
override void OnSetSpawnPointToggle(IPlayer player)Server: makes the shrine the player's respawn point, or clears it if it already was.
PoweredRespawnShrineSaveData Save(ISerializeChildren childSerializer)Saves the shrine ID.
void SetFuelForShrine(float fuelValue)Sets the shrine's fuel in the respawn system.
protected override void Awake()Sets up the shrine ID sync and, if the shrine shows subscriber marks, listens for players joining and leaving.
protected override void OnDestroy()Removes the player listeners and base listeners.
protected override void OnInteractionFilter(Interactor interactor, Interactable interactable, ref bool result)Lets the shrine be touched only while it has powered time left.
protected override void OnModelChanged(IRespawnSystemModel model)Client: refreshes glyph colour, power state, subscriber marks, fuel display and sounds from the respawn system model.
protected override async void Start()Waits until the shrine ID has arrived (from save or the server) before running the base start.
8 private and internal methods
MemberWhat it is
private void InitializeShrineSettings()Parses the saved shrine id and looks up its settings in the respawn system settings.
private void OnPlayerCountChanged(IPlayer player)Player join, leave or local player handler that refreshes the subscriber marks.
private void PlayEmptiedShrineSfx(bool hasConsumedAllFuel)Plays the shrine deactivation sound when the shrine has used up all its fuel.
private async void RefreshSubscriberMarks()Waits for the shrine id, then redraws the marks from the current subscriber count.
private void SyncShrineIdToClient(IPlayer player, Stream stream)Sync handler: the server sends the shrine id string and clients look up the shrine settings from it.
private void UpdatePowerState(float shrinePower)Raises powerStateChanged with the shrine's normalised remaining power.
private void UpdateShrine(int numberOfSubscribers, bool isSubscribedToShrine, float shrinePower, float currentFuel, bool hasConsumedAllFuel)Updates the glyph colour, power state, empty sound, subscriber marks, fuel display and audio in one go.
private async Task WaitForSaveData()Waits in 100 ms steps until the shrine settings are loaded.

Used in​

Members of other types that take, return or hold a PoweredRespawnShrine: