RespawnSystem
A class in Root.Township, ATT.Respawn.
The networked object that tracks respawn shrines: which shrine each player is subscribed to, shrine fuel, and where a player respawns. The server burns fuel on a timer and syncs the model to clients. Get it as IRespawnSystem through dependency injection.
- Listed in ATT, Features and other game namespaces
- Inherits or implements
NetworkEntityBehaviour,IRespawnSystem,IPlayerRespawnPositionProvider,ISavable<RespawnSystemSaveData>,ISavableSave<RespawnSystemSaveData>,ISavableSaveBase - Derived types
RespawnSystemSaveData
Constructors
| Member | What it is |
|---|---|
RespawnSystem() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
7 private and internal fields
| Member | What it is |
|---|---|
private Timeline.IEntry decrementFuelEntry | Timeline entry for the repeating fuel tick. |
private static readonly Logger logger | NLog logger for this class. |
private IRespawnSystemModel model | The respawn system model with every shrine's fuel and subscribers. Saved and loaded with the entity. |
private MethodSync syncModelToClients | Method sync (SyncB) that sends the model to clients. |
private Action<IRespawnSystemModel> systemModelChanged | Listeners added with AddSystemModelChangedListener. |
private float timeOfPreviousFuelDecrement | Time of the last fuel tick, used to work out how much fuel to take. |
private Timeline.IEntry updateModelEntry | Timeline entry for the repeating model sync check. |
Properties
1 private and internal property
| Member | What it is |
|---|---|
private IRespawnSystemSettings SystemSettings { get; } | The global RespawnSystemSettings, with tick rates and per-shrine settings. |
Methods
| Member | What it is |
|---|---|
IRespawnSystemModel AddSystemModelChangedListener(Action<IRespawnSystemModel> onSystemModelChanged) | Adds a listener called whenever the model is synced, and returns the current model. |
Guid GetActiveShrineIdForPlayer(IPlayer player) | The GUID of the shrine the player is subscribed to. The global shrine if they have none. |
float GetRemainingPoweredTimeForShrineNormalized(Guid shrineId) | How much fuel time a shrine has left, 0 to 1. |
Vector3 GetRespawnPosition(IPlayer player, out bool isDefaultRespawn) | Where the player respawns: their shrine's spawn position. Also says whether that's the global (default) shrine. |
IEnumerable<int> GetShrineSubscriberIds(Guid shrineId) | The user IDs of players subscribed to a shrine. |
override void Initialize() | Sets up the network method that syncs the model. |
override void InitializeAsServer(SpawnData spawnData) | Server: starts the fuel consumption and model sync timers from RespawnSystemSettings. |
void Load(RespawnSystemSaveData data, ISerializeChildren childSerializer) | Rebuilds the model from save data. |
override void OnConnected(Player player) | Syncs the model when a player spawns this object. It sends to every nearby player, not only the new one. |
void RemoveSystemModelChangedListener(Action<IRespawnSystemModel> onSystemModelChanged) | Removes a listener added with AddSystemModelChangedListener. |
void ResetRespawnShrineForPlayer(IPlayer player) | Unsubscribes the player from their shrine and syncs straight away. |
RespawnSystemSaveData Save(ISerializeChildren childSerializer) | Returns the model's save data. |
void SetFuelForShrine(Guid shrineId, float value) | Server: sets a shrine's fuel and syncs straight away. |
void SetRespawnShrineForPlayer(Guid shrineId, IPlayer player) | Moves the player's subscription to a shrine. Synced on the next model tick, not straight away. |
6 private and internal methods
| Member | What it is |
|---|---|
private void OnDestroy() | Cancels the fuel and model update timers. |
private void RaiseModelChangedEvent() | Calls the model changed listeners with the current model. |
private void Start() | Creates an empty model if none was loaded. |
private void SyncModelToClients(IPlayer player, Stream stream) | Sync handler: the model writes or reads itself on the stream, then listeners are told it changed. |
private void TickFuelConsumption() | Server timer: takes fuel off shrines for the time since the last tick. |
private void TickUpdateModel() | Server timer: syncs the model to clients if it has changed. |
Used in
Members of other types that take, return or hold a RespawnSystem: