Beispiel #1
0
 /// <summary>
 ///     Starts this instance.
 /// </summary>
 public void Start()
 {
     if (_stateMachine.CanChangeState(ProcessorStatus.Started))
     {
         _stateMachine.ChangeState(ProcessorStatus.Started);
     }
 }
Beispiel #2
0
 /// <summary>
 ///     Starts this instance.
 /// </summary>
 public void Start()
 {
     if (_stateMachine.CanChangeState(ServiceStatus.StandBy))
     {
         _stateMachine.ChangeState(ServiceStatus.StandBy);
     }
 }
        public T StackState(T state)
        {
            if (!object.ReferenceEquals(state, null) && !_machine.Contains(state))
            {
                throw new System.ArgumentException("MovementStyle is not a member of the state machine.", "style");
            }

            _stateStack.Push(_machine.Current);
            return(_machine.ChangeState(state));
        }
Beispiel #4
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="RouterProcessor" /> class.
        /// </summary>
        /// <param name="identification">The identification.</param>
        /// <param name="inputGateway">The message receiver.</param>
        /// <param name="routerOutputHelper">The bus sender helper.</param>
        internal RouterProcessor(Identification identification, IInputGateway <byte[], RouterHeader> inputGateway,
                                 IRouterOutputHelper routerOutputHelper)
        {
            JoinedBusInfo = BusInfo.Create();

            ConfigureStateMachine();
            _inputGateway            = inputGateway;
            _identification          = identification;
            _routerOutputHelper      = routerOutputHelper;
            _inputGateway.OnMessage += MessageReceived;
            _stateMachine.ChangeState(ProcessorStatus.Configured);
            _serializer = new JsonDataContractSerializer();
        }
Beispiel #5
0
 /// <summary>
 /// Starts this instance.
 /// </summary>
 public void Start()
 {
     Logger.Debug(string.Format("Starting Channel..."));
     if (_endPointStateMachine.CanChangeState(EndPointStatus.Receiving))
     {
         _endPointStateMachine.ChangeState(EndPointStatus.Receiving);
         Logger.Debug(string.Format("Channel - Started"));
     }
     else
     {
         Logger.Debug(string.Format("Can't change state channel to Started, current state {0}", _endPointStateMachine.CurrentState));
     }
 }
Beispiel #6
0
 public void Update(T entity)
 {
     if (Player.mind.Timer >= 2000)
     {
         States.ChangeState("BaseState");
     }
 }
Beispiel #7
0
 protected virtual void GetHit()
 {
     if (Random.Range(0, 100) < 30 || Health.HealthAsPercentage <= 0)
     {
         stateMachine.ChangeState("GetHit");
     }
 }
Beispiel #8
0
 /// <summary>将状态机更改至任意状态</summary>
 public virtual void ChangeToState(int name, IStateParam param = null)
 {
     if (mFSM != null)
     {
         mFSM.ChangeState(name, param);
     }
 }
Beispiel #9
0
        public void Continue()
        {
            IStateMachine stateMachine = _context.Get <IStateMachine>();

            if (Party.CalamityDefeated)
            {
                stateMachine.ChangeState <CalamityDefeatedState>();
            }
            else if (Results.Success)
            {
                stateMachine.ChangeState <GameplayState>();
            }
            else
            {
                stateMachine.ChangeState <CreatePartyState>();
            }
        }
        private void Awake()
        {
            _stateMachine = new GameStateMachine(
                new GameStateFactory(session, this)
                );

            _stateMachine.ChangeState(typeof(GameStateLoading));
        }
Beispiel #11
0
 public static bool ChangeState(this IStateMachine stateMachine,
                                string jobId, IState toState, string[] fromStates)
 {
     using (var cts = new CancellationTokenSource())
     {
         cts.Cancel();
         return(stateMachine.ChangeState(jobId, toState, fromStates, cts.Token));
     }
 }
Beispiel #12
0
 /// <summary>
 /// 初始化状态机
 /// </summary>
 void InitStateMachine()
 {
     m_stateMachine = new IStateMachine <L_Judge_Network, PlayState>(this);
     m_stateMachine.Add(PlayState.PS_Initialize, new PlayState_Initilize());
     m_stateMachine.Add(PlayState.PS_Ready, new PlayState_Ready());
     m_stateMachine.Add(PlayState.PS_Playing, new PlayState_Playing());
     m_stateMachine.Add(PlayState.PS_End, new PlayState_End());
     // ...
     m_stateMachine.ChangeState(PlayState.PS_Initialize); // 设置默认状态
 }
Beispiel #13
0
 public IAIState ChangeState(IAIState state)
 {
     if (_stateMachine == null)
     {
         return(null);
     }
     if (_stateMachine.Current == state)
     {
         return(state);
     }
     return(_stateMachine.ChangeState(state));
 }
Beispiel #14
0
    public bool CheckAll(IStateMachine machine)
    {
        foreach (var condition in conditions)
        {
            if (!condition.Check(machine.User))
            {
                return(false);
            }
        }

        machine.ChangeState(nextState);
        return(true);
    }
Beispiel #15
0
        /// <summary>
        ///     Configures the state machine.
        /// </summary>
        private void ConfigureStateMachine()
        {
            _stateMachine = StateMachineFactory.Create(ServiceStatus.Initializing)
                            .Permit(ServiceStatus.Initializing, ServiceStatus.StandBy, StartControl)
                            .Permit(ServiceStatus.StandBy, ServiceStatus.Started, StartProcessor)
                            .Permit(ServiceStatus.StandBy, ServiceStatus.Stopped, StopControl)
                            .Permit(ServiceStatus.Started, ServiceStatus.StandBy, StopProcessor)
                            .Permit(ServiceStatus.Started, ServiceStatus.Stopped, StopAll)
                            .Permit(ServiceStatus.Stopped, ServiceStatus.StandBy, StartControl);

            _controller.OnStart += (sender, args) =>
            {
                //El processor es un bus no un servicio, los servicios arrancan cuando el controller acaba de configurarlos
                if (_processor is ISubscriber)
                {
                    if (_stateMachine.CanChangeState(ServiceStatus.Started))
                    {
                        _stateMachine.ChangeState(ServiceStatus.Started);
                    }
                }
            };

            _processor.OnStart += (sender, args) =>
            {
                if (_stateMachine.CanChangeState(ServiceStatus.Started))
                {
                    _stateMachine.ChangeState(ServiceStatus.Started);
                }
            };

            _processor.OnStop += (sender, args) =>
            {
                if (_stateMachine.CanChangeState(ServiceStatus.StandBy))
                {
                    _stateMachine.ChangeState(ServiceStatus.StandBy);
                }
            };
        }
Beispiel #16
0
 public void collisionResults(IEntity Collision)
 {
     if (Collision.Tag == "Ladder")
     {
         canClimb = true;
     }
     if (Collision.Tag == "Enemy")
     {
         StateMachine.ChangeState("Damaged");
     }
     if (Collision.Tag != "Ladder")
     {
         canClimb = false;
     }
 }
Beispiel #17
0
 public void ChangeState(FSMState fsm, ICommand ev)
 {
     if (mMachine == null || this.CacheTransform == null)
     {
         return;
     }
     if (FSM == FSMState.FSM_DEAD && fsm != FSMState.FSM_REBORN)
     {
         return;
     }
     if (!mMachine.Contains(fsm))
     {
         return;
     }
     mMachine.GetState(fsm).SetCommand(ev);
     mMachine.ChangeState(fsm);
 }
Beispiel #18
0
        public void Continue()
        {
            IStateMachine stateMachine = _context.Get <IStateMachine>();

            stateMachine.ChangeState <CreatePartyState>();
        }
        public object HandlePacket(PacketBlockBulkTransfer packet, IPropertyBag propertyBag = null, IStateMachine gameInstance = null)
        {
            if (propertyBag == null)
            {
                return(null);
            }

            var blockEngine = propertyBag.GetEngine <IBlockEngine>("blockEngine");

            try
            {
                // TODO: Make compression code work
                if (packet.IsCompressed)
                {
                    /*var compressed = msgBuffer.ReadBytes(msgBuffer.LengthBytes - (int)(msgBuffer.Position / 8));
                     * var compressedstream = new System.IO.MemoryStream(compressed);
                     * var decompresser = new System.IO.Compression.GZipStream(compressedstream, System.IO.Compression.CompressionMode.Decompress);
                     *
                     * x = (byte)decompresser.ReadByte();
                     * y = (byte)decompresser.ReadByte();
                     * propertyBag.mapLoadProgress[x, y] = true;
                     * for (byte dy = 0; dy < 16; dy++)
                     *  for (byte z = 0; z < 64; z++)
                     *  {
                     *      BlockType blockType = (BlockType)decompresser.ReadByte();
                     *      if (blockType != BlockType.None)
                     *          blockEngine.downloadList[x, y + dy, z] = blockType;
                     *  }*/
                }

                else
                {
                    propertyBag.MapLoadProgress[packet.X, packet.Y] = true;
                    for (byte dy = 0; dy < 16; dy++)
                    {
                        for (byte z = 0; z < 64; z++)
                        {
                            var blockType = (BlockType)packet.BlockList[dy, z];
                            if (blockType != BlockType.None)
                            {
                                blockEngine.DownloadList[packet.X, packet.Y + dy, z] = blockType;
                            }
                        }
                    }
                }

                var downloadComplete = true;

                for (var x = 0; x < 64; x++)
                {
                    for (var y = 0; y < 64; y += 16)
                    {
                        if (propertyBag.MapLoadProgress[x, y])
                        {
                            continue;
                        }

                        downloadComplete = false;
                        break;
                    }
                }

                if (downloadComplete)
                {
                    gameInstance?.ChangeState("Infiniminer.States.TeamSelectionState");
                    if (!propertyBag.SettingsContainer.NoSound)
                    {
                        MediaPlayer.Stop();
                    }
                    blockEngine.DownloadComplete();
                }
            }
            catch (Exception e)
            {
                Console.OpenStandardError();
                Console.Error.WriteLine(e.Message);
                Console.Error.WriteLine(e.StackTrace);
                Console.Error.Close();
            }

            return(null);
        }
Beispiel #20
0
 private void OnRestEventSelected()
 {
     _stateMachine.ChangeState <RestState>();
 }
Beispiel #21
0
        // Transition to running state or waiting state depending on the transition that casued the action
        public void Action(IStateMachine stateMachine)
        {
            Console.WriteLine("Action: Cleaning for next run");

            if (transition is Run)
            {
                stateMachine.ChangeState(new Run {TestTransition = (transition as Run).TestTransition}); // Transition
            }
            else if (transition is Reset)
            {
                stateMachine.ChangeState(new Waiting()); // No-Transition - Just go directly to waiting
            }
        }
Beispiel #22
0
 // Transition state using whatever transition is being tested e.g. Success, Failure, Pause, Cancel
 public void Action(IStateMachine stateMachine)
 {
     Console.WriteLine("Action: Running");
     stateMachine.ChangeState(testTransition);
 }
Beispiel #23
0
 // Go directly to Waiting state
 public void Action(IStateMachine stateMachine)
 {
     Console.WriteLine("Action: Initializing");
     stateMachine.ChangeState(new Waiting());
 }
Beispiel #24
0
 protected virtual void CharacterDead()
 {
     stateMachine.ChangeState(typeof(Dead));
 }
Beispiel #25
0
        /// <summary>
        ///     Configures the state machine.
        /// </summary>
        private void ConfigureStateMachine()
        {
            _stateMachine = StateMachineFactory.Create(ServiceStatus.Initializing)
                                               .Permit(ServiceStatus.Initializing, ServiceStatus.StandBy, StartControl)
                                               .Permit(ServiceStatus.StandBy, ServiceStatus.Started, StartProcessor)
                                               .Permit(ServiceStatus.StandBy, ServiceStatus.Stopped, StopControl)
                                               .Permit(ServiceStatus.Started, ServiceStatus.StandBy, StopProcessor)
                                               .Permit(ServiceStatus.Started, ServiceStatus.Stopped, StopAll)
                                               .Permit(ServiceStatus.Stopped, ServiceStatus.StandBy, StartControl);

            _controller.OnStart += (sender, args) =>
                {
                    //El processor es un bus no un servicio, los servicios arrancan cuando el controller acaba de configurarlos
                    if (_processor is ISubscriber)
                    {
                        if (_stateMachine.CanChangeState(ServiceStatus.Started))
                        {
                            _stateMachine.ChangeState(ServiceStatus.Started);
                        }
                    }
                };

            _processor.OnStart += (sender, args) =>
                {
                    if (_stateMachine.CanChangeState(ServiceStatus.Started))
                    {
                        _stateMachine.ChangeState(ServiceStatus.Started);
                    }
                };

            _processor.OnStop += (sender, args) =>
                {
                    if (_stateMachine.CanChangeState(ServiceStatus.StandBy))
                    {
                        _stateMachine.ChangeState(ServiceStatus.StandBy);
                    }
                };
        }
 private void OnLoadingFinished()
 {
     _stateMachine.ChangeState(typeof(GameStatePlaying));
 }