StateTransition<TFrom, TTo>
An abstract class in Root.Township, Alta.PlayerStates.Transitions.
Base for a rule that moves a player from one player state to another. Subclasses hook up listeners while the transition is active and call TransitionToDestinationState when their condition is met.
- Listed in Players and characters
- Inherits or implements
IPlayerStateTransition - Derived types
PlayingToSpiritTransition,SpiritToPlayingTransition,CustomizationToPlayingTransition,DeadToPlayingTransition,DownedToDeadTransition,DownedToPlayingTransition,EquipmentTransition<TFrom, TTo>,FirstJoinToCustomizationTransition,FirstJoinToPlayingTransition,PlayingToCustomizationTransition,PlayingToDeadTransition,PlayingToDownedTransition,ToCombatTransition<TFrom>
Constructors
| Member | What it is |
|---|---|
protected StateTransition(PlayerStateType destinationStateType) | Creates a StateTransition from destinationStateType. |
Fields
| Member | What it is |
|---|---|
protected static Logger logger | Shared logger for transitions. |
2 private and internal fields
| Member | What it is |
|---|---|
private bool isActive | Backing field for IsActive. |
private IPlayerState sourceState | Backing field for SourceState. |
Properties
| Member | What it is |
|---|---|
PlayerStateType DestinationStateType { get; } | The state type this transition leads to. |
IPlayerState SourceState { get; } | The state this transition belongs to. |
IStateTransitionsManager StateTransitionsManager { get; set; } | Manager used to switch states. |
protected Player Player { get; private set; } | The player whose state this is, taken from the source state. |
protected PlayerController PlayerController { get; private set; } | The player's controller. Filled in later if the player had none when the source state was set. |
protected PlayerStateManager StateManager { get; private set; } | The player's state manager, taken from the source state. |
2 private and internal properties
| Member | What it is |
|---|---|
private bool Alta.PlayerStates.Transitions.IPlayerStateTransition.IsActive { get; set; } | Turning it on calls AddListeners, off calls RemoveListeners. Setting the same value again only logs a warning. |
private IPlayerState Alta.PlayerStates.Transitions.IPlayerStateTransition.SourceState { set; } | Sets the source state and picks up its state manager, player and player controller (waiting for the controller if it isn't set yet). |
Methods
| Member | What it is |
|---|---|
protected abstract void AddListeners() | Called when the transition becomes active; subscribe to whatever triggers it here. |
protected virtual void DestinationPreActivationCallback(IPlayerState activatedState) | Called on the new state just before it activates. Does nothing by default. |
protected void OnTransitionComplete(IPlayerState transitionedState) | Called after the switch with the new current state. Empty. |
protected abstract void RemoveListeners() | Called when the transition becomes inactive; undo AddListeners here. |
protected virtual IPlayerState TransitionToDestinationState() | Switches the player to the destination state and returns it. |
3 private and internal methods
| Member | What it is |
|---|---|
private void Alta.PlayerStates.Transitions.IPlayerStateTransition.Clear() | Clears the source state. |
private void Alta.PlayerStates.Transitions.IPlayerStateTransition.TransitionToDestinationStateExternal() | Runs the transition from outside; used by the transitions manager's TriggerTransition. |
private void UpdatePlayerController(Player player, PlayerController playerController) | Picks up the player controller once the player gets one, then unhooks. |