Skip to main content

DownedState

A class in Root.Township, Alta.PlayerStates.

The player state between being knocked down and dying, used when the server's downed state duration is above 0. The server spawns a gravestone and runs a revive activity and a countdown to death; the downed player gets a respawn orb.

Constructors​

MemberWhat it is
DownedState(PlayingState playingState, DownedStateDebuffManager newDebuffManager)Creates a DownedState from playingState and newDebuffManager.

Fields​

19 private and internal fields
MemberWhat it is
private ReviveCompletableActivity activityThe ReviveCompletableActivity other players complete to revive this one.
private AltaCoroutine deathCountdownRoutineServer: the running death countdown.
private DownedStateDebuffManager debuffManagerApplies and removes the respawn debuffs.
private Gravestone gravestoneThe Gravestone component on the spawned gravestone.
private NetworkEntity gravestoneEntityThe gravestone entity spawned at the downed spot.
private NetworkEntity leftInteractorEntityItem respawned for the left hand when the state ends.
private SavedDynamicObject leftInteractorSaveSave of what the left hand held when the player went down.
private static readonly Logger loggerClass logger.
private RespawnOrb respawnOrbThe local player's RespawnOrb.
private PooledObject respawnOrbObjectThe pooled object behind the respawn orb.
private NetworkEntity rightInteractorEntityItem respawned for the right hand when the state ends.
private SavedDynamicObject rightInteractorSaveSave of what the right hand held when the player went down.
private Vector3 spawnPositionThe ground point where the player went down. Gravestone, effects and orb are placed from it.
private MethodSync syncActivateActionsNetwork sync sent when the downed state starts.
private MethodSync syncDeactivateActionsNetwork sync sent when the downed state ends.
private MethodSync syncRespawnEarlyNetwork sync the downed client sends to give up and respawn.
private MethodSyncStruct<float> syncTimerIncreaseToDownedPlayerNetwork sync for extra countdown time.
private float timeToReviveSeconds the player stays downed. Starts at the server's DownedStateDuration and grows as the activity adds time.
private bool wasRevivedSet when the revive activity completes. Decides health restore, debuffs and whether items go back in hand.

Properties​

MemberWhat it is
DamageData KillingImpact { get; set; }The damage that downed the player.
override string Name { get; set; }"Downed State".
DownedStateSettings Settings { get; }The downed state settings: timers, effects, gravestone, orbs, health returned and debuffs.
override PlayerStateType StateType { get; }PlayerStateType.Downed.

Methods​

MemberWhat it is
void ForceDeactivateActions()Runs the server leave logic straight away (gravestone, held items, health and debuffs).
protected override void OnActivate()Server: stores held items, spawns the gravestone and starts the revive countdown. If the downed duration is 0 the player dies at once.
protected override void OnActivateRemote(bool isPlayerCharacterSpawned)Clients: hides the body and docks and limits the hands to downed interactions. The downed player always sees ghost hands.
protected override void OnDeactivate()Server: removes the gravestone and revive objects and gives back held items. A revived player gets some health back and respawn debuffs.
protected override void OnDeactivateRemote(bool isPlayerCharacterSpawned)Clients: shows the body again, restores hand interactions and removes the respawn orb.
44 private and internal methods
MemberWhat it is
private void ApplyRespawnDebuffs()Server: if the player was revived, applies the settings' respawn debuffs for RespawnDebuffDurationInSeconds.
private void CalculateSpawnPosition()Server: sets the downed spot to the ground under the player's feet (raycast down up to about 10 m).
private bool CanPlayPooledParticleEffect(PooledObjectDefinition pooledObjectDefinition)True when not headless and the effect definition is set.
private bool CanPlaySfx(SoundEffectSet downedStateSfx)True when the sound set exists and the player has a controller.
private void ClearActivityListeners()Unhooks the revive activity's time increased and completed events.
private void DestroyGravestone()Server: destroys the gravestone entity, if one was spawned.
private void DestroyRespawnOrb()Local player: force drops the respawn orb if held and returns it to the pool.
private void DropDownedStateEntity(Interactor interactor)Makes a hand let go if it holds the revive orb or respawn orb.
private void ForceDropLocalEntities(Interactor interactor)Makes a hand let go of anything that isn't networked.
private void ForceGrabEntity(Interactor interactor, NetworkEntity entity)Puts a restored held item back into a hand, dropping any downed state orb first.
private async Task<Result<RespawnOrb>> GetRespawnOrb()Gets a respawn orb from the pool in front of the player at the settings' height and distance.
private void GrabInteractables()Puts the restored left and right held items back into the hands.
private void IncreaseTime(float timeIncreaseInSeconds)Server: adds time to the downed countdown (from the revive activity) and tells the downed player.
private bool IsHoldingDownedStateEntity(Interactor interactor)Whether a hand holds the revive orb or respawn orb, matched by prefab name.
private bool IsHoldingLocalEntity(Interactor interactor)Whether a hand holds a non networked interactable.
private void LoadInteractables()Server: respawns the items the hands held when the player went down.
private void LoadInteractablesOnStateExit()Server: respawns held items and puts them back in hand if revived or drop on death is off.
private void OnActivateActions()Server: starts the downed state, or kills the player at once if DownedStateDuration is 0. Saves held items, spawns the gravestone and starts the countdown.
private void OnActivateRemoteActions()Client: hides the body and docks, disables body colliders and limits the hands to the downed interaction channel.
private void OnActivityCompleted()Server: when the revive activity completes, stops the countdown and moves the player back to playing.
private void OnPlayerControllerSetRemote(PlayerController setPlayerController)Client: runs the remote setup once this player's controller links.
private void OnPlayerControllerSetServer(PlayerController controller)Server: runs the downed setup once the player's controller has loaded.
private async void PlayParticleEffectForPlayer(PooledObjectDefinition pooledObjectDefinition)Plays a pooled particle effect at half the player's height above the downed spot, then releases it.
private void PlaySoundEffectForPlayer(SoundEffectSet downedStateSfx)Plays a sound on the player's head.
private void SaveHeldInteractables()Server: saves and despawns what each hand holds so it can come back when the state ends.
private void SetBodyCollidersAndParticlesActiveState(bool isActive)Turns the player's body colliders and on death effect controllers on or off.
private void SetBodyVisibility(bool isVisible)Shows or hides the body. The head shows only for other players who aren't downed.
private void SetDockVisibility(bool isVisible)Shows or hides the belt and back docks.
private void SetNaturalHealthRegenerationEnabledState(bool isEnabled)Turns the hunger stat (the settings' HungerStat) on or off, which stops natural regeneration while downed.
private void SetPlayerVisibility(bool isVisible)Sets body and dock visibility together.
private void SharedSetup()Creates the four network syncs on the player character entity, if not made yet.
private void SpawnGravestone()Server: spawns the gravestone at the downed spot, facing the player's look direction, and assigns the player to it.
private void SpawnInteractableFromSave(SavedDynamicObject saveData, out NetworkEntity entity)Spawns an entity from a saved held item, or returns null when there's no save.
private async void SpawnRespawnOrb()Local player: spawns the respawn orb with the countdown. Releasing it asks the server to respawn early.
private async void StartPlayerDeath()Server: starts the revive activity and the death countdown.
private IEnumerator StartPlayerDeathCountdown() (iterator)Server coroutine: waits timeToRevive seconds, then kills the player.
private void StartReviveActivity()Server: creates or restarts the revive activity and hooks its events.
private void StopParticleEffect(PooledParticleSystem particleSystem)Hides and releases a pooled particle effect.
private void SyncActivateActions(IPlayer player, Stream stream)Sends the countdown and downed spot to clients, which play the enter effects. The local player also gets the respawn orb.
private void SyncDeactivateActions(IPlayer player, Stream stream)Tells clients to play the exit effects.
private void SyncRespawnEarly(IPlayer player, Stream stream)Network handler: when the server reads it (the player released the respawn orb), the player is killed.
private void SyncTimerIncreaseToDownedPlayer(IPlayer player, Stream stream, float timeIncreaseInSeconds)Network handler that adds the extra seconds to the downed player's respawn orb timer.
private void TryRestoreHealthToPlayer()Server: if revived, sets health to PercentageOfHealthToReturnToRevivedPlayers of the maximum.
private void TrySaveInteractable(Interactor interactor, out SavedDynamicObject save)Saves and despawns a held item if it's a prefab root that saves. Otherwise outputs null.