Пример #1
0
        protected void SetState(GameState state, float transitionTime)
        {
            if (CurrentState != null)
            {
                CurrentState.OnEnd -= EndState;
            }

            if (!States.ContainsKey(state))
            {
                Logger.Warn(this, "State {0} does not exist.", state.ToString());
                return;
            }

            CurrentState = States[state];

            // Add transition before moving onto next state
            TransitionTimer = new GameTimer("Transition", transitionTime, () =>
            {
                Logger.Log(this, "{0}: {1}", "Change state to", CurrentState.Type.ToString());

                // Notify clients of state change
                GameData.Players.ForEach(x => x.SendMessage(new ServerMessage.Game.ChangeState(CurrentState.Type)));

                CurrentState.OnEnd += EndState;
                CurrentState.Begin(GameData);
            });

            GameData.Players.ForEach(x => x.SendTransitionPeriod(TransitionTimer.Duration));
        }
Пример #2
0
        /// <summary>
        /// hanges the active state to the given state type. An instance of that type should
        /// already had been registered to use this method.
        /// </summary>
        /// <typeparam name="TState">The State you want to change to</typeparam>
        /// <returns></returns>
        public TState ChangeState <TState>() where TState : IFsmState <T>
        {
            PreviousState = CurrentState;

            CurrentState = stateDictionary[typeof(TState)];

            PreviousState.End();
            CurrentState.Begin();

            return((TState)CurrentState);
        }
Пример #3
0
        //-----------------------------------------------------------------------------
        // Overridden methods
        //-----------------------------------------------------------------------------

        public override void OnBegin()
        {
            stateIndex = 0;

            if (CurrentState != null)
            {
                CurrentState.Begin(gameControl);
                if (!CurrentState.IsActive)
                {
                    NextState();
                }
            }
            else
            {
                End();
            }
        }
Пример #4
0
        public void NextState()
        {
            stateIndex++;

            if (CurrentState != null)
            {
                CurrentState.Begin(gameControl);
                if (!CurrentState.IsActive)
                {
                    NextState();
                }
            }
            else
            {
                End();
            }
        }
Пример #5
0
        /// <summary>
        /// Changes the active state to a specific state instance. This will (if not null)
        /// also register the state.
        /// </summary>
        /// <typeparam name="TState">The State you want to change to</typeparam>
        /// <param name="state">The State you want to change to and it value</param>
        /// <returns></returns>
        public TState ChangeState <TState>(TState state) where TState : IFsmState <T>
        {
            if (CurrentState != null)
            {
                CurrentState.End();
            }

            PreviousState = CurrentState;
            CurrentState  = state;

            if (CurrentState != null)
            {
                AddState(state);
                CurrentState.Machine = this;
                CurrentState.Context = Context;
                CurrentState.Begin();
            }

            return(state);
        }