Skip to main content

SpiritState

A class in Root.Township, Alta.PlayerStates.

Player state for spirit mode during a climbing challenge (a PlayerUnlock with orbs to collect). Hunger and docks are off, weight comes from the orbs, and falls send you back to the checkpoint. Sits on PlayingState.

Constructors​

MemberWhat it is
SpiritState(PlayingState playingState)Creates a SpiritState from playingState.

Fields​

4 private and internal fields
MemberWhat it is
private Dictionary<uint, GameObject> beltOrbsOrb objects shown on the player's body, by orb index.
private LocomotionController locomotionThe controller's locomotion, watched for position changes on the server.
private PlayerHealth playerHealthThe player's health, whose damage is handled by this state.
private PlayerWeight weightThe player's PlayerWeight. Its weight is overridden and its docks hidden while in spirit mode.

Properties​

MemberWhat it is
override string Name { get; set; }"Spirit State".
SpiritStateSettings Settings { get; }The SpiritStateSettings asset (hunger stat, snap distance, sounds, fall damage threshold).
override PlayerStateType StateType { get; }PlayerStateType.Spirit.

Methods​

MemberWhat it is
protected override void OnActivate()Server: adds the spirit-to-playing transition.
protected override void OnActivateRemote(bool isPlayerCharacterSpawned)Client: plays the enter-spirit sound and glow on the player.
protected override void OnDeactivateRemote(bool isPlayerCharacterSpawned)Client: plays the exit-spirit sound and glow.
protected override void OnPlayerControllerFound(PlayerController playerController, bool isFromOnActivate)Marks the character as a spirit, turns off hunger and docks, hooks damage and unlock changes. On the server, moving too far from the checkpoint cancels the unlock.
protected override void OnPlayerControllerLost(bool isFromOnDeactivate)Undoes the spirit setup: hunger, docks and weight back to normal, belt orbs removed.
8 private and internal methods
MemberWhat it is
private bool CanPlaySfx(SoundEffectSet spiritModeStateSfx)True when the sound set exists and the player has a controller.
private void HandleDamage(DamageState damageState)Swallows all damage. Big command or fall damage ends the state if no unlock is running, or teleports to the checkpoint.
private void MovedOutOfBounds(PlayerController player, Vector3 oldPosition, Vector3 newPosition, LocomotionFunction function)Server: cancels the unlock when the player moves further than SnapDistance from the unlock checkpoint.
private void PlaySoundEffectForPlayer(SoundEffectSet spiritModeStateSfx)Plays a sound on the player's head.
private void PlaySpiritModeGlow(bool isEnteringSpiritMode)Plays the enter or exit spirit mode effect, except on headless builds.
private void RemoveSpiritMode(PlayerController player)Cancels the player's current unlock, which ends spirit mode.
private void ResetPlayerToLastCheckpoint()Teleports the player back to the unlock's checkpoint.
private void UnlocksModified()Spawns and removes the orbs on the player's belt and sets carried weight from them. Server ends the state when no unlock is active.