Skip to main content

RespawnSystemModel

A class in Root.Township, ATT.Respawn.

State of every respawn shrine (fuel and bound players), saved and sent to clients as JSON. Made from the shrine list in RespawnSystemSettings or from a save.

Constructors​

MemberWhat it is
RespawnSystemModel()Creates a RespawnSystemModel from saveData.
RespawnSystemModel(RespawnSystemSaveData saveData)Creates a RespawnSystemModel from saveData.

Fields​

2 private and internal fields
MemberWhat it is
private static Logger loggerClass logger.
private Dictionary<Guid, RespawnShrineModel> respawnShrineModelsShrine models by shrine ID. The global shrine is not in it.

Properties​

MemberWhat it is
Guid GlobalShrineGuid { get; }Id of the global (default) shrine everyone falls back to.
bool HasModelChanged { get; private set; }True when something changed since the last sync was written.
IRespawnShrineModel this[Guid id] { get; }The shrine model with this id. Throws for an unknown id.

Methods​

MemberWhat it is
bool AddSubscriber(Guid shrineId, int playerId)Binds a player id to a shrine. Always true for the global shrine, which has no list.
void DecrementFuel(float timeSinceLastDecrementInSeconds)Burns fuel for shrines that have players bound. A shrine that runs dry loses all its players.
Guid GetActiveShrineIdForPlayer(int playerId)The shrine a player id is bound to, or the global shrine's id.
IEnumerator<IRespawnShrineModel> GetEnumerator()Enumerates the shrine models (not including the global shrine).
float GetRemainingPoweredTimeForShrineNormalized(Guid shrineId)Fuel as a fraction of the shrine's capacity. 0 for the global shrine.
RespawnSystemSaveData GetSaveData()Save data with the global shrine id and the shrines as JSON.
IEnumerable<int> GetShrineSubscriberIds(Guid shrineId)Player ids bound to a shrine. Empty for the global shrine.
bool RemoveSubscriber(Guid shrineId, int playerId)Unbinds a player id from a shrine. Always true for the global shrine.
void SetFuel(Guid shrineId, float value)Sets a shrine's fuel.
void SyncToClients(IPlayer player, ref Stream stream)Writes or reads all shrines as a JSON string. Writing clears the changed and emptied flags.
4 private and internal methods
MemberWhat it is
private IEnumerator System.Collections.IEnumerable.GetEnumerator()Enumerates the shrine models (not including the global shrine).
private string GetShrineModelsAsJsonString()Serializes the shrine models dictionary to JSON. Used for both saving and the network sync.
private void LoadShrineModelsFromJsonString(string respawnShrineModelAsJsonString)Replaces the shrine models from JSON. Keeps the old ones and logs an error if it parses to null.
private void ResetEmptiedShrineFlags()Clears every shrine's ran-out-of-fuel flag. Called after the server writes a sync.