/// <summary>
        /// Interface for adding new FSMState to this FiniteStateMachine.
        /// </summary>
        /// <param name="state">Implementation of the FSMState.</param>
        /// <param name="id">An indentifier used to manage and transition between states.</param>
        protected void AddState(FSMState state, String id)
        {
            // The state will be expecting to access the Parent GameObject a lot.
            state.pParentGOH = mParentGOH;

            // Check for duplicate entries.
            if (mStates.ContainsKey(id))
            {
                System.Diagnostics.Debug.Assert(false, "Attempting to add two FSMState objects with the same ID to a FiniteStateMachine: " + id);

                return;
            }
            else
            {
                // Add it to our list of states.
                mStates.Add(id, state);
            }

            // If this is the first state to be added, use it as the initial FSMState to be run.
            if (mCurrentState == null)
            {
                mInitialState     = mCurrentState = mNextState = state;
                mCurrentFlowState = FlowStates.INITIAL_STATE;
            }
        }
示例#2
0
 private void Start()
 {
     currState = FlowStates.state_travelRestrictions;
     TTSManager.Instance.TextToSpeech("Hello, do you have any travel restrictions?");
     mWillingToTravel = -1;
     amHalal          = false;
     amountBought     = 0;
     itemsBought      = new List <baseGroceryItemSO>();
 }
        /// <summary>
        /// Called once per frame by the game object.
        /// </summary>
        /// <param name="gameTime">The amount of time that has passed this frame.</param>
        public override void Update(GameTime gameTime)
        {
            // The basic flow for every state machine:
            //  1) Run OnBegin (1 frame).
            //  2) Run OnUpdate (Indefinitly; until it returns a new state to transition to).
            //  3) Run OnEnd (1 frame).
            //
            switch (mCurrentFlowState)
            {
            case FlowStates.BEGIN:
            {
                // Transition directly to the UPDATE pass. Do it before calling OnBegin incase
                // OnBegin actually sets the current state through a message, in which case we
                // don't want to go to UPDATE.
                mCurrentFlowState = FlowStates.UPDATE;

                mCurrentState.OnBegin();

                break;
            }

            case FlowStates.UPDATE:
            {
                // Update the state which will potentially return a new state in which to transition to.
                String nextState = mCurrentState.OnUpdate();

                AdvanceToState(nextState);

                break;
            }

            case FlowStates.END:
            {
                mCurrentState.OnEnd();

                // Once the FlowStates.END has finished it is time to move onto the next FSMState.
                mCurrentState = mNextState;

                // On the next update pass we will be running a new FSMState, so we want to be sitting
                // in the BEGIN flow state.
                mCurrentFlowState = FlowStates.BEGIN;

                break;
            }

            default:
            {
                System.Diagnostics.Debug.Assert(false, "Unhandled FSM Flow State.");

                break;
            }
            }
        }
 /// <summary>
 /// Attempts to advance to a new state, checking for unknown and null states.
 /// </summary>
 /// <param name="nextState">The name of the state to go to (as sent to AddState).</param>
 protected void AdvanceToState(String nextState)
 {
     // If they passed a value state name...
     if (!String.IsNullOrEmpty(nextState))
     {
         // ...and it is one that we are managing.
         if (mStates.ContainsKey(nextState))
         {
             // Request a new state and move to the END pass of this flow.
             mNextState        = mStates[nextState];
             mCurrentFlowState = FlowStates.END;
         }
         else
         {
             System.Diagnostics.Debug.Assert(false, "FSMState returned a new state which is not managed by this state machine: " + nextState);
         }
     }
 }
 /// <summary>
 /// Called by GameObjectFactory when object is recycled.
 /// </summary>
 public override void Reset()
 {
     mCurrentState     = mNextState = mInitialState;
     mCurrentFlowState = FlowStates.INITIAL_STATE;
 }
示例#6
0
    public void ChangeState(FlowStates state)
    {
        string temp;

        switch (currState) //OnStateExit
        {
        case FlowStates.state_travelRestrictions:
        case FlowStates.state_whatTravelRestrictions:
        case FlowStates.state_dietryRestrictions:
        case FlowStates.state_confirmSettings:
        case FlowStates.state_addItems:
        case FlowStates.state_verifyItems:
        case FlowStates.state_continueOrCheckout:
        case FlowStates.state_verifyCart:
        case FlowStates.state_addOrRemove:
        case FlowStates.state_removeItems:
        case FlowStates.state_verifyRemoveItems:
        case FlowStates.state_storeSuggestion:
        case FlowStates.state_planRoute:
            speechToText.text = "default";
            waitingOnResponse = true;
            break;

        default:
            break;
        }
        currState = state;
        switch (currState) //OnStateEnter
        {
        case FlowStates.state_travelRestrictions:
            TTSManager.Instance.TextToSpeech("Hello, do you have any travel restrictions?");
            break;

        case FlowStates.state_whatTravelRestrictions:
            TTSManager.Instance.TextToSpeech("How far in meters are you willing to travel?");
            break;

        case FlowStates.state_dietryRestrictions:
            TTSManager.Instance.TextToSpeech("What dietry restrictions do you have? If you don't have any, say no");
            break;

        case FlowStates.state_confirmSettings:
            temp = "So you are willing to travel ";
            if (mWillingToTravel == -1)
            {
                temp += "any amount of";
            }
            else
            {
                temp += mWillingToTravel.ToString();
            }
            temp += " meters and you ";
            if (amHalal)
            {
                temp += "are halal. ";
            }
            else
            {
                temp += "have no dietry restrictions. ";
            }
            temp += "Did I get that right?";
            TTSManager.Instance.TextToSpeech(temp);
            break;

        case FlowStates.state_addItems:
            TTSManager.Instance.TextToSpeech("What would you like to buy?");
            break;

        case FlowStates.state_verifyItems:
            temp  = "The item I found is ";
            temp += itemSearched.GetItemName();
            temp += " and it costs ";
            temp += itemSearched.GetDollars().ToString();
            temp += " dollars and ";
            temp += itemSearched.GetCents().ToString();
            temp += " cents. How many would you like to buy? If you do not want it, say no.";
            TTSManager.Instance.TextToSpeech(temp);
            break;

        case FlowStates.state_continueOrCheckout:
            TTSManager.Instance.TextToSpeech("Would you like to continue shopping?");
            break;

        case FlowStates.state_verifyCart:
            temp = "Currently, your cart has";
            foreach (baseGroceryItemSO item in itemsBought)
            {
                temp += ". ";
                temp += item.GetAmountInCart().ToString();
                temp += " ";
                temp += item.GetItemName();
            }
            temp += ". Would you like to change anything in your cart?";
            TTSManager.Instance.TextToSpeech(temp);
            break;

        case FlowStates.state_addOrRemove:
            TTSManager.Instance.TextToSpeech("Would you like to add or remove items?");
            break;

        case FlowStates.state_removeItems:
            TTSManager.Instance.TextToSpeech("What would you like to remove?");
            break;

        case FlowStates.state_verifyRemoveItems:
            temp  = "The item I found is ";
            temp += itemSearched.GetItemName();
            temp += " and it costs ";
            temp += itemSearched.GetDollars().ToString();
            temp += " dollars and ";
            temp += itemSearched.GetCents().ToString();
            temp += " cents and you have ";
            temp += itemSearched.GetAmountInCart().ToString();
            temp += " amount in your cart. How many would you like to remove? If you do not want to remove it, say no.";
            TTSManager.Instance.TextToSpeech(temp);
            break;

        case FlowStates.state_storeSuggestion:
            //Hardcode
            if (milkBought)
            {
                TTSManager.Instance.TextToSpeech("One supermarket I can suggest is Nex Supermarket. It is 200 meters away, is crowded and does not have milk. Another suggestion is Prime Supermarket, It is 3500 meters away, is not crowded and has everything you want. Which one would you prefer?");
            }
            else
            {
                TTSManager.Instance.TextToSpeech("One supermarket I can suggest is Nex Supermarket. It is 200 meters away, is crowded and has everything you want. Another suggestion is Prime Supermarket, It is 3500 meters away, is not crowded and has everything you want. Which one would you prefer?");
            }
            break;

        case FlowStates.state_planRoute:
            //Hardcode
            if (nexChosen)
            {
                TTSManager.Instance.TextToSpeech("Ok, I have planned a route to nex supermarket. Thank you for using my assistance!");
            }
            else
            {
                TTSManager.Instance.TextToSpeech("Ok, I have planned a route to prime supermarket. Thank you for using my assistance!");
            }
            break;

        default:
            break;
        }
    }
 /// <summary>
 /// Attempts to advance to a new state, checking for unknown and null states.
 /// </summary>
 /// <param name="nextState">The name of the state to go to (as sent to AddState).</param>
 protected void AdvanceToState(String nextState)
 {
     // If they passed a value state name...
     if (!String.IsNullOrEmpty(nextState))
     {
         // ...and it is one that we are managing.
         if (mStates.ContainsKey(nextState))
         {
             // Request a new state and move to the END pass of this flow.
             mNextState = mStates[nextState];
             mCurrentFlowState = FlowStates.END;
         }
         else
         {
             System.Diagnostics.Debug.Assert(false, "FSMState returned a new state which is not managed by this state machine: " + nextState);
         }
     }
 }
        /// <summary>
        /// Interface for adding new FSMState to this FiniteStateMachine.
        /// </summary>
        /// <param name="state">Implementation of the FSMState.</param>
        /// <param name="id">An indentifier used to manage and transition between states.</param>
        protected void AddState(FSMState state, String id)
        {
            // The state will be expecting to access the Parent GameObject a lot.
            state.pParentGOH = mParentGOH;

            // Check for duplicate entries.
            if (mStates.ContainsKey(id))
            {
                System.Diagnostics.Debug.Assert(false, "Attempting to add two FSMState objects with the same ID to a FiniteStateMachine: " + id);

                return;
            }
            else
            {
                // Add it to our list of states.
                mStates.Add(id, state);
            }

            // If this is the first state to be added, use it as the initial FSMState to be run.
            if (mCurrentState == null)
            {
                mInitialState = mCurrentState = mNextState = state;
                mCurrentFlowState = FlowStates.INITIAL_STATE;
            }
        }
 /// <summary>
 /// Called by GameObjectFactory when object is recycled.
 /// </summary>
 public override void Reset()
 {
     mCurrentState = mNextState = mInitialState;
     mCurrentFlowState = FlowStates.INITIAL_STATE;
 }
        /// <summary>
        /// Called once per frame by the game object.
        /// </summary>
        /// <param name="gameTime">The amount of time that has passed this frame.</param>
        public override void Update(GameTime gameTime)
        {
            // The basic flow for every state machine:
            //  1) Run OnBegin (1 frame).
            //  2) Run OnUpdate (Indefinitly; until it returns a new state to transition to).
            //  3) Run OnEnd (1 frame).
            //
            switch (mCurrentFlowState)
            {
            case FlowStates.BEGIN:
                {
                    // Transition directly to the UPDATE pass. Do it before calling OnBegin incase
                    // OnBegin actually sets the current state through a message, in which case we
                    // don't want to go to UPDATE.
                    mCurrentFlowState = FlowStates.UPDATE;

                    mCurrentState.OnBegin();

                    break;
                }
            case FlowStates.UPDATE:
                {
                    // Update the state which will potentially return a new state in which to transition to.
                    String nextState = mCurrentState.OnUpdate();

                    AdvanceToState(nextState);

                    break;
                }
            case FlowStates.END:
                {
                    mCurrentState.OnEnd();

                    // Once the FlowStates.END has finished it is time to move onto the next FSMState.
                    mCurrentState = mNextState;

                    // On the next update pass we will be running a new FSMState, so we want to be sitting
                    // in the BEGIN flow state.
                    mCurrentFlowState = FlowStates.BEGIN;

                    break;
                }
            default:
                {
                    System.Diagnostics.Debug.Assert(false, "Unhandled FSM Flow State.");

                    break;
                }
            }

            // Keep going until we get to an update state. This is to avoid objects popping out and
            // in between states.
            if (mCurrentFlowState != FlowStates.UPDATE)
            {
                Update(gameTime);
            }
        }