private CharacterCreationSubState AdvanceState(CharacterCreationSubState current) { // This character creation state machine can return actual creation state objects - if someone // were to expand and add new creation state(s) that are not MUD-agnostic, then they should also // add and use their own CreationStateMachine handling those states instead of this default one; // they could of course reuse some/all of the states below in addition to their own. if (current is ConfirmCreationEntryState) { return new GetNameState(this.Session); } else if (current is GetNameState) { return new GetDescriptionState(this.Session); } else if (current is GetDescriptionState) { return new GetPasswordState(this.Session); } else if (current is GetPasswordState) { return new ConfirmPasswordState(this.Session); } else if (current is ConfirmPasswordState) { // We are done with character creation! return null; } throw new InvalidOperationException("The character state machine does not know how to calculate the next step after '" + current.GetType().Name + "' succeeds"); }
private CharacterCreationSubState AdvanceState(CharacterCreationSubState current) { // This character creation state machine can return actual creation state objects - if someone // were to expand and add new creation state(s) that are not MUD-agnostic, then they should also // add and use their own CreationStateMachine handling those states instead of this default one; // they could of course reuse some/all of the states below in addition to their own. if (current is ConfirmCreationEntryState) { return(new GetNameState(Session)); } else if (current is GetNameState) { return(new GetPasswordState(Session)); } else if (current is GetPasswordState) { return(new ConfirmPasswordState(Session)); } else if (current is ConfirmPasswordState) { return(new GetDescriptionState(Session)); } else if (current is GetDescriptionState) { // We are done with character creation! return(null); } throw new InvalidOperationException("The character state machine does not know how to calculate the next step after '" + current.GetType().Name + "' succeeds"); }
private CharacterCreationSubState RegressState(CharacterCreationSubState current) { if (current is ConfirmPasswordState) { // If password confirmation failed, try selecting a new password. return(new GetPasswordState(Session)); } throw new InvalidOperationException("The character state machine does not know how to calculate the next step after '" + current.GetType().Name + "' fails"); }
/// <summary>Gets the next step in the creation process.</summary> /// <param name="current">The current (just executed step)</param> /// <param name="previousStatus">Whether the current step passed or failed</param> /// <returns>The next step in the character creation process, or null if it is finished</returns> public override CharacterCreationSubState GetNextStep(CharacterCreationSubState current, StepStatus previousStatus) { // If there is no state yet, set up the initial character creation state. if (current == null) { return(new ConfirmCreationEntryState(Session)); } // Otherwise either go forward to the next state, or back to the previous state if requested. return(previousStatus == StepStatus.Success ? AdvanceState(current) : RegressState(current)); }
/// <summary> /// Gets the next step in the creation process. /// </summary> /// <param name="current">The current (just executed step)</param> /// <param name="previousStatus">Whether the current step passed or failed</param> /// <returns>The next step in the character creation process, or null if it is finished</returns> public override CharacterCreationSubState GetNextStep(CharacterCreationSubState current, StepStatus previousStatus) { // If there is no state yet, set up the initial character creation state. if (current == null) { return new ConfirmCreationEntryState(this.Session); } // Otherwise either go forward to the next state, or back to the previous state if requested. return previousStatus == StepStatus.Success ? this.AdvanceState(current) : this.RegressState(current); }
/// <summary>Processes the next step in the character creation chain, or completes the process if there are no more steps.</summary> /// <param name="step">The current step</param> /// <param name="result">The result of the current step</param> public void HandleNextStep(CharacterCreationSubState step, StepStatus result) { this.CurrentStep = this.GetNextStep(step, result); // If there were no remaining steps found, we're done. if (this.CurrentStep == null) { this.OnCreationComplete(); return; } this.CurrentStep.StateMachine = this; this.Session.WritePrompt(); }
/// <summary> /// Processes the next step in the character creation chain, or completes /// the process if there are no more steps. /// </summary> /// <param name="step">The current step</param> /// <param name="result">The result of the current step</param> public void HandleNextStep(CharacterCreationSubState step, StepStatus result) { this.CurrentStep = this.GetNextStep(step, result); // If there were no remaining steps found, we're done. if (this.CurrentStep == null) { this.OnCreationComplete(); return; } this.CurrentStep.StateMachine = this; this.Session.WritePrompt(); }
/// <summary>Processes the next step in the character creation chain, or completes the process if there are no more steps.</summary> /// <param name="step">The current step.</param> /// <param name="result">The result of the current step.</param> public void HandleNextStep(CharacterCreationSubState step, StepStatus result) { CurrentStep = GetNextStep(step, result); // If there were no remaining steps found, we're done. if (CurrentStep == null) { OnCreationComplete(); return; } else { CurrentStep.Begin(); } CurrentStep.StateMachine = this; }
/// <summary> /// Gets the next step in the creation process. /// </summary> /// <param name="current"> /// The current (just executed step) /// </param> /// <param name="previousStatus"> /// Whether the current step passed or failed /// </param> /// <returns> /// The next step in the character creation process, or null if it is finished /// </returns> public override CharacterCreationSubState GetNextStep(CharacterCreationSubState current, StepStatus previousStatus) { // entry point of the state machine if (current == null) { return new ConfirmCreationEntryState(this.Session); } if (previousStatus == StepStatus.Success) { return this.AdvanceState(current); } else { return this.RegressState(current); } }
/// <summary>Gets the next step.</summary> /// <param name="current">The current.</param> /// <param name="previousStatus">The previous status.</param> /// <returns>The next character creation state.</returns> public abstract CharacterCreationSubState GetNextStep(CharacterCreationSubState current, StepStatus previousStatus);
private CharacterCreationSubState RegressState(CharacterCreationSubState current) { if (current is ConfirmPasswordState) { // If password confirmation failed, try selecting a new password. return new GetPasswordState(this.Session); } throw new InvalidOperationException("The character state machine does not know how to calculate the next step after '" + current.GetType().Name + "' fails"); }
/// <summary> /// Gets the next step. /// </summary> /// <param name="current">The current.</param> /// <param name="previousStatus">The previous status.</param> /// <returns></returns> public abstract CharacterCreationSubState GetNextStep(CharacterCreationSubState current, StepStatus previousStatus);