PlayerStateBase
An abstract class in Root.Township, Alta.PlayerStates.
Base for a player state (alive, downed, dead, customising and so on). The player's PlayerStateManager switches between them; a state can sit on top of a base state as a decorator. The server runs OnActivate, clients run OnActivateRemote.
- Listed in Players and characters
- Inherits or implements
IPlayerState - Derived types
CustomizationState,DeadState,FirstJoinState,PlayerStateBase<T>,PlayingState - Documented in Player states
Constructors
| Member | What it is |
|---|---|
PlayerStateBase() | Creates a PlayerStateBase with default values. |
Fields
| Member | What it is |
|---|---|
const int MaxPlayerStateDepth | Most states that can be stacked: 9. |
const int MaxPlayerStateTypes | Most state types: 32. |
protected MethodSync sync | Network message for the state's own sync, set up when it activates. |
6 private and internal fields
| Member | What it is |
|---|---|
private SerializeMethod baseSyncHandler | The state sync handler that was set before this state took over. |
private SerializeMethod baseTransitionRequestHandler | The transition request handler that was set before this state took over. |
private static Logger logger | Class logger. |
private Player player | Backing field for Player. |
private MethodSyncStruct<PlayerStateType> requestStateChange | Network sync for transition requests sent to the server. |
private PlayerStateManager stateManager | Backing field for StateManager. |
Properties
| Member | What it is |
|---|---|
AllTransitions AllTransitions { get; } | The transitions that can leave this state. |
IPlayerState BaseState { get; set; } | The state underneath this one, which EndState returns to. Null for a root state. |
IPlayerState Decorator { get; set; } | The state currently decorating this one, or null. |
bool IsActive { get; private set; } | True between activation and deactivation. |
bool IsDecorated { get; } | Returns true when Decorator is null, which is the opposite of what the name says. |
virtual string Name { get; set; } | Display name for logs. |
Player Player { get; set; } | The player this state belongs to. Setting it creates the right transitions manager for the side. |
IPlayerStateSettings Settings { get; } | Settings for this state type from PlayerStateSettingsManager. |
PlayerStateManager StateManager { get; set; } | The player's state manager. |
abstract PlayerStateType StateType { get; } | Which PlayerStateType this is. |
protected virtual bool IsClearingAllTransitionsOnDeactivation { get; } | If true (default), the transitions manager clears this state's transitions when it deactivates. |
protected bool IsLocalPlayer { get; } | True if the state belongs to the local player. |
protected bool IsRemote { get; } | True on a client (anything that is not the server). |
protected bool IsServer { get; } | True on the server. |
protected PlayerCharacter PlayerCharacter { get; } | The player's controller as a PlayerCharacter, or null. |
protected IStateTransitionsManager TransitionsManager { get; private set; } | Manages this state's transitions: a local one on the server, a remote one on clients. |
1 private and internal property
| Member | What it is |
|---|---|
private bool IsPlayerCharacterSpawned { get; } | Whether the player currently has a PlayerCharacter. |
Methods
| Member | What it is |
|---|---|
virtual void EditorDrawInspectorGUI() | Editor hook for drawing debug UI. Empty by default. |
virtual void SerializeDisk(Stream stream) | Hook for saving and loading state data. Only logs by default. |
void SerializeToRemote(Stream stream) | Only logs; it does not call anything else. |
virtual void SyncStateEnter(Stream stream) | Hook to read or write extra data when the state is entered over the network. |
virtual void SyncStateLeave(Stream stream) | Hook to read or write extra data when the state is left over the network. |
virtual bool ValidateStateActivation(bool isDuringLoading) | Whether the state may activate now. True by default. |
protected void EndState() | Returns the player to the base state. Logs an error if there is none. |
protected virtual void OnActivate() | Server: called when the state becomes active. |
protected virtual void OnActivateRemote(bool isPlayerCharacterSpawned) | Client: called when the state becomes active, with whether the player's character is spawned. |
protected virtual void OnDeactivate() | Server: called when the state ends. |
protected virtual void OnDeactivateRemote(bool isPlayerCharacterSpawned) | Client: called when the state ends. |
protected virtual void OnDecorated(IPlayerState baseState, IPlayerState decorator) | Server: called when a state is put on top of this one or one below it. |
protected virtual void OnDecoratedRemote(IPlayerState baseState, IPlayerState decorator) | Client (and the local player): called when a state is put on top. |
protected virtual void OnPlayerControllerFound(PlayerController playerController, bool isFromOnActivate) | Called when the player has a controller, at activation or when one spawns later. |
protected virtual void OnPlayerControllerLost(bool isFromOnDeactivate) | Called when the controller is destroyed or the state deactivates. |
protected virtual void OnUndecorated(IPlayerState baseState, IPlayerState decorator) | Server: called when a decorating state comes off. |
protected virtual void OnUndecoratedRemote(IPlayerState baseState, IPlayerState decorator) | Client (and the local player): called when a decorating state comes off. |
protected virtual void Sync(IPlayer player, Stream stream) | Handler for this state's sync message while it is active. Empty by default. |
11 private and internal methods
| Member | What it is |
|---|---|
private void Alta.PlayerStates.IPlayerState.Activate() | Sets up the state's message handlers, marks it active, runs OnActivate (server) or OnActivateRemote (client), and waits for the player controller. |
private void ClearNetworking() | Removes this state's message handlers and puts back the ones that were there before. |
private void Alta.PlayerStates.IPlayerState.Deactivate() | Marks inactive, undecorates the base state, runs the deactivate hooks, restores message handlers and calls OnPlayerControllerLost. |
private void Alta.PlayerStates.IPlayerState.Decorate(IPlayerState baseState, IPlayerState decorator) | Sets Decorator when this is the base, runs the decorated hooks, and passes the call down the base state chain. |
private void InitializeNetworking() | Swaps in this state's handlers for the player's state sync and transition request messages. |
private void PlayerControllerAlreadyExists() | Calls OnPlayerControllerFound at activation and watches the controller for destruction. |
private void PlayerControllerDestroyed(NetworkEntity entity, bool isUnload) | Calls OnPlayerControllerLost and waits for the next controller. |
private void PlayerControllerOnPlayerSet(Player player, PlayerController playerController) | When the player gets a controller, calls OnPlayerControllerFound and watches it for destruction. |
private void Alta.PlayerStates.IPlayerState.RequestStateChange(PlayerStateType destinationStateType) | Sends a request to move to a state type. The server handler calls SetState on the state manager with it. |
private void RequestStateChange(IPlayer player, Stream stream, PlayerStateType stateType) | Sends a request to move to a state type. The server handler calls SetState on the state manager with it. |
private void Alta.PlayerStates.IPlayerState.Undecorate(IPlayerState baseState, IPlayerState decorator) | Clears Decorator when this is the base, runs the undecorated hooks, and passes the call down the base state chain. |