public IEnumerable <Command> Parse(IEnumerable <string> data_arr)
        {
            StateCommand command = null;

            switch (data_arr.ElementAt(4))
            {
            case "A":
                command = new AdditiveBlendCommand();
                break;

            case "H":
                command = new HorizonFlipCommand();
                break;

            case "V":
                command = new VerticalFlipCommand();
                break;

            default:
                throw new Exception($"unknown Parameter command type:" + data_arr.ElementAt(3));
            }

            command.StartTime = data_arr.ElementAt(2).ToInt();
            command.EndTime   = string.IsNullOrWhiteSpace(data_arr.ElementAt(3)) ? command.StartTime : data_arr.ElementAt(3).ToInt();

            yield return(command);
        }
        public async Task BattleProcess()
        {
            //Debug.LogError("对战开始");
            await StateCommand.BattleStart();

            for (int i = 0; i < 3; i++)
            {
                //Debug.LogError("小局开始");
                await StateCommand.RoundStart(i);

                //await StateCommand.WaitForSelectProperty();
                while (true)
                {
                    Debug.LogError("回合开始");
                    await StateCommand.TurnStart();

                    await StateCommand.WaitForPlayerOperation();

                    if (Info.AgainstInfo.isBoothPass)
                    {
                        break;
                    }
                    await StateCommand.TurnEnd();
                }
                await StateCommand.RoundEnd(i);
            }
            await StateCommand.BattleEnd();

            Debug.Log("结束对局");
        }
Exemplo n.º 3
0
        public ProcessState GetNext(StateCommand command)
        {
            StateTransition trans = new StateTransition(CurrentState, command);
            ProcessState    ret   = Transitions[trans];

            return(ret);
        }
Exemplo n.º 4
0
        public async Task BattleProcess()
        {
            Info.AllPlayerInfo.Player1Info = new NetInfoModel.PlayerInfo("gezi", "yaya", new List <CardDeck> {
                new CardDeck("gezi", 0, new List <int> {
                    1000, 1001, 1002, 1001, 1000, 1002, 1000, 1001, 1000, 1001, 1001, 1000, 1002
                })
            });
            Info.AllPlayerInfo.Player2Info = new NetInfoModel.PlayerInfo("gezi", "yaya", new List <CardDeck> {
                new CardDeck("gezi", 0, new List <int> {
                    1001, 1001, 1000, 1000, 1001, 1001, 1000, 1000, 1001, 1001, 1001, 1000, 1002
                })
            });
            await StateCommand.BattleStart();

            for (int i = 0; i < 3; i++)
            {
                await StateCommand.RoundStart(i);

                while (true)
                {
                    await StateCommand.TurnStart();

                    await StateCommand.WaitForPlayerOperation();

                    await StateCommand.TurnEnd();

                    if (Info.GlobalBattleInfo.IsBoothPass)
                    {
                        break;
                    }
                }
                await StateCommand.RoundEnd(i);
            }
            await StateCommand.BattleEnd();
        }
Exemplo n.º 5
0
        public IDevice NodesTate(out int data)
        {
            data = 0;
            byte[]       result;
            StateCommand cmd = new StateCommand(4);

            lock (this)
            {
                lock (this)
                {
                    _port.Write(_serialize.Serialize <StateCommand>(cmd))
                    .Read(out result);
                }
            }
            if (null != result)
            {
                if (result.Length > 2)
                {
                    if (0xFF == result[1])
                    {
                        var res = _serialize.Deserialize <ErrorReportingResult>(result);
                        Logger.LogInfo("节点号bug" + "------" + res.ErrorCode.ToString());
                    }
                    else
                    {
                        var res = _serialize.Deserialize <StateResult>(result);
                        data = res.NodeNumber;
                        Logger.LogInfo("节点号" + "------" + res.NodeNumber.ToString());
                    }
                }
            }
            Thread.Sleep(100);
            return(this);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 输入状态监测
        /// </summary>
        /// <returns></returns>

        public IDevice SetMonitor()
        {
            byte[]        result;
            OutputCommand cmd = new OutputCommand(0x04, eSwitchNumber.SpareOutput_1, AGV.eSwitchStates.Open);

            _port.Write(_serialize.Serialize <OutputCommand>(cmd))
            .Read(out result);
            bool isopen = true;

            while (isopen)
            {
                byte[]       resultStue;
                StateCommand cmd1 = new StateCommand(0x04);
                _port.Write(_serialize.Serialize <StateCommand>(cmd1))
                .Read(out resultStue);
                Logger.LogInfo(resultStue.ToString());

                if (null != resultStue)
                {
                    byte[] resultStuestop;
                    var    res = _serialize.Deserialize <StateResult>(resultStue);
                    Logger.LogInfo(res.State.ToString());
                    switch (res.State)
                    {
                    case eAGVState.BackupOff:
                    {
                        OutputCommand cmd2 = new OutputCommand(0x04, eSwitchNumber.SpareOutput_1, AGV.eSwitchStates.Shut);
                        _port.Write(_serialize.Serialize <OutputCommand>(cmd2))
                        .Read(out resultStuestop);
                        Logger.LogInfo("BackupOff");
                        isopen = false;
                    }
                    break;

                    case eAGVState.BackupFPatrol: {
                        OutputCommand cmd2 = new OutputCommand(0x04, eSwitchNumber.SpareOutput_1, AGV.eSwitchStates.Shut);
                        _port.Write(_serialize.Serialize <OutputCommand>(cmd2))
                        .Read(out resultStuestop);
                        Logger.LogInfo("BackupFPatrol");
                        isopen = false;
                    }
                    break;

                    case eAGVState.BackupBPatrol: {
                        OutputCommand cmd2 = new OutputCommand(0x04, eSwitchNumber.SpareOutput_1, AGV.eSwitchStates.Shut);
                        _port.Write(_serialize.Serialize <OutputCommand>(cmd2))
                        .Read(out resultStuestop);
                        Logger.LogInfo("BackupBPatrol");
                        isopen = false;
                    }
                    break;
                    }
                }
                Thread.Sleep(5000);
            }

            return(this);
        }
Exemplo n.º 7
0
    public override void Trigger2DExit(ref Rigidbody2D r, ref Collider2D collider, ref StateCommand c)
    {
        Debug.Log("TriggerExit being called");
        Player_State_Base.isCollidingHeld     = false;
        Player_State_Base.isCollidingAffected = false;

        Player_State_Base.heldDetected       = null;
        Player_State_Base.affectableDetected = null;
    }
Exemplo n.º 8
0
        public void MoveNext(StateCommand command)
        {
            if (CurrentState == ProcessState.Terminated)
            {
                return;
            }

            CurrentState = GetNext(command);
        }
 private static void OnSimulateInput(this UnitSimulateComponent self)
 {
     while (self.SimulateQueue.Count > 0)
     {
         StateCommand command = self.SimulateQueue.Dequeue();
         self.ExecuteCommand(command);
         self.ExecuteQueue.Enqueue(command);
     }
 }
Exemplo n.º 10
0
        private void ClientWebSocketConnectionOnStateCommandReceived(object sender, SimpleEventArgs <StateCommand> simpleEventArgs)
        {
            Invoke(new Action(() =>
            {
                StateCommand stateCommand = simpleEventArgs.Value;
                if (string.IsNullOrEmpty(stateCommand.ConferenceId))
                {
                    MessageBox.Show(this, "Unable create or join conference! Retry later!");
                    Close();
                }
                else
                {
                    ConferenceId     = stateCommand.ConferenceId;
                    _isPresenter     = stateCommand.IsPresenter;
                    _presenterWidth  = stateCommand.PresenterWidth;
                    _presenterHeight = stateCommand.PresenterHeight;
                    _id = stateCommand.ParticipantId;

                    _paintControl.Mode        = PaintControlModes.Silent;
                    silentRadioButton.Checked = true;

                    if (_isPresenter)
                    {
                        silentRadioButton.Visible = true;
                        drawRadioButton.Visible   = true;
                        inputRadioButton.Visible  = false;
                    }
                    else
                    {
                        silentRadioButton.Visible = true;
                        drawRadioButton.Visible   = true;
                        inputRadioButton.Visible  = true;
                    }

                    if (_isPresenter)
                    {
                        StartDiffDetectThread();
                        _paintControl.Init(_presenterWidth, _presenterHeight, Color.Black, _topMostForm);
                        _topMostForm.Show();
                        _topMostForm.SetClickThrough(true);
                    }
                    else
                    {
                        _paintControl.Init(_presenterWidth, _presenterHeight, Color.Black, null);
                    }

                    conferenceIdValueLabel.Text = ConferenceId;

                    _diffFrame = new Bitmap(_presenterWidth, _presenterHeight);

                    roleValueLabel.Text = _isPresenter ? "Presenter" : "Viewer";

                    StartProcessCommandsThread();
                }
            }));
        }
Exemplo n.º 11
0
    private State GetNext(Command command)
    {
        StateCommand transition = new StateCommand(currentState, command);
        State        nextState;

        if (!transitions.TryGetValue(transition, out nextState))
        {
            throw new System.Exception("Invalid transition: " + currentState + " -> " + command);
        }

        return(nextState);
    }
        public void SendState(string conferenceId, string id, bool isPresenter, int presenterWidth, int presenterHeight)
        {
            var command = new StateCommand(conferenceId)
            {
                ParticipantId   = id,
                IsPresenter     = isPresenter,
                PresenterWidth  = presenterWidth,
                PresenterHeight = presenterHeight
            };

            SendCommand(command);
        }
Exemplo n.º 13
0
        /// <summary>
        /// 获取AGV状态信息    ok
        /// </summary>
        /// <returns></returns>
        public IDevice GetState()
        {
            byte[]       result;
            StateCommand cmd = new StateCommand(0x02);

            _port.Write(_serialize.Serialize <StateCommand>(cmd))
            .Read(out result);
            if (null != result)
            {
                var res = _serialize.Deserialize <StateResult>(result);
            }

            return(this);
        }
Exemplo n.º 14
0
 public override void Trigger2DStay(ref Rigidbody2D r, ref Collider2D collider, ref StateCommand c)
 {
     if (collider.gameObject.tag == "Grabable")
     {
         Player_State_Base.isCollidingHeld = true;
         Player_State_Base.heldDetected    = collider.gameObject;
     }
     if (collider.gameObject.tag == "Affectable")
     {
         Debug.Log("TriggerEnter:  Affectable Object Nearby");
         Player_State_Base.isCollidingAffected = true;
         Player_State_Base.affectableDetected  = collider.gameObject;
     }
 }
Exemplo n.º 15
0
 private void CheckPassState()
 {
     //当pass状态发生改变时
     if (IsLastPlay1Pass ^ Info.GlobalBattleInfo.IsPlayer1Pass)
     {
         IsLastPlay1Pass = Info.GlobalBattleInfo.IsPlayer1Pass;
         StateCommand.SetPassState(Info.GlobalBattleInfo.IsPlayer1, Info.GlobalBattleInfo.IsPlayer1Pass);
     }
     if (IsLastPlay2Pass ^ Info.GlobalBattleInfo.IsPlayer2Pass)
     {
         IsLastPlay2Pass = Info.GlobalBattleInfo.IsPlayer2Pass;
         StateCommand.SetPassState(!Info.GlobalBattleInfo.IsPlayer1, Info.GlobalBattleInfo.IsPlayer2Pass);
     }
 }
        private static void ExecuteCommand(this UnitSimulateComponent self, StateCommand command)
        {
            UnitStateComponent unitStateComponent = self.Entity.GetComponent <UnitStateComponent>();
            UnitState          newState           = unitStateComponent.State;

            newState.Rotate   = self.CalculaAngle(command.input.axisX, command.input.axisY);
            newState.Velocity = VelocityConst.Accelerate;

            unitStateComponent.State = newState;

            StateResult result = new StateResult();

            result.rotate   = newState.Rotate;
            result.velocity = newState.Velocity;

            command.result = result;
            command.frame  = newState.Frame;
        }
Exemplo n.º 17
0
        public static Command ToCommand(this StateCommand stateCommand)
        {
            Command command = new Command();

            command.Frame    = stateCommand.frame;
            command.Sequence = stateCommand.sequence;
            command.Input    = new CommandInput
            {
                AxisX = stateCommand.input.axisX,
                AxisY = stateCommand.input.axisY
            };
            command.Result = new CommandResult
            {
                Rotate   = stateCommand.result.rotate,
                Velocity = stateCommand.result.velocity
            };

            return(command);
        }
Exemplo n.º 18
0
        public static StateCommand ToState(this Command command)
        {
            StateCommand stateCommand = new StateCommand();

            stateCommand.frame    = command.Frame;
            stateCommand.sequence = command.Sequence;
            stateCommand.input    = new StateInput
            {
                axisX = command.Input.AxisX,
                axisY = command.Input.AxisY
            };
            stateCommand.result = new StateResult
            {
                rotate   = command.Result.Rotate,
                velocity = command.Result.Velocity
            };

            return(stateCommand);
        }
Exemplo n.º 19
0
        private void DrillNode(ref GameData gameData, ref StateCommand movement)
        {
            var currentState = Core.CurrentState;

            // if our state is terminated, exit
            if (currentState == ProcessState.Terminated)
            {
                this.IsFinished = true;
            }

            // do our work here
            var thingToDo = Map.GetValues(currentState);

            Console.WriteLine(thingToDo.NextCommand.ToString() + ' ' + String.Join(", ", thingToDo.Values) + ' ' + Core.CurrentState);
            movement = thingToDo.NextCommand;

            // tell the state machine to transition, and run our method again
            Core.MoveNext(movement);
            DrillNode(ref gameData, ref movement);
        }
Exemplo n.º 20
0
 public override void UpdatePlayer(ref Rigidbody2D r, ref StateCommand c)
 {
     if (Input.GetKeyDown(KeyCode.Y))
     {
         Debug.Log("Y is clicked");
         if (Player_State_Base.isCollidingHeld == true)
         {
             c = Player_State_Base.pGrab;
             Debug.Log("State changed to Grab");
         }
         else if (Player_State_Base.isCollidingAffected == true && (Player_State_Base.currentHeldObject is torchHeldObjectCommand))
         {
             c = Player_State_Base.pMelt;
         }
         else if (Player_State_Base.isCollidingHeld == false && (Player_State_Base.currentHeldObject is torchHeldObjectCommand))
         {
             c = Player_State_Base.pDrop;
         }
     }
 }
        private static void OnSimulateAfter(this UnitSimulateComponent self)
        {
            ActorMessageSenderComponent actorLocationSenderComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>();
            UnitGateComponent           unitGateComponent            = self.Entity.GetComponent <UnitGateComponent>();
            ActorMessageSender          actorMessageSender           = actorLocationSenderComponent.Get(unitGateComponent.GateSessionActorId);

            if (unitGateComponent.IsDisconnect)
            {
                return;
            }

            if (self.ExecuteQueue.Count > 0)
            {
                Actor_ServerCommond serverCommond = new Actor_ServerCommond();
                while (self.ExecuteQueue.Count > 0)
                {
                    StateCommand stateCommand = self.ExecuteQueue.Dequeue();
                    serverCommond.Result.Add(stateCommand.ToCommand());
                }

                actorMessageSender.Send(serverCommond);
            }

            if (self.Frame % UnitStateComponent.SyncFrame == 1)
            {
                Actor_StateSync stateSync = new Actor_StateSync();

                Unit[] units = Game.Scene.GetComponent <UnitComponent>().GetAll();
                foreach (Unit unit in units)
                {
                    UnitStateComponent unitStateComponent = unit.GetComponent <UnitStateComponent>();
                    UnitState          state = unitStateComponent.State;
                    UnitStateInfo      info  = state.Pack(unit.Id, state.Frame);
                    stateSync.States.Add(info);
                }

                actorMessageSender.Send(stateSync);
            }
        }
Exemplo n.º 22
0
 public MapItem(StateCommand com, string[] values)
 {
     this.NextCommand = com;
     this.Values      = values;
 }
Exemplo n.º 23
0
            //初始化接收响应
            private static void InitAsyncConnection()
            {
                AsyncConnect = new WebSocket($"ws://{ip}/AsyncInfo");
                AsyncConnect.Connect();
                AsyncConnect.OnMessage += (sender, e) =>
                {
                    try
                    {
                        Debug.Log("收到信息" + e.Data);
                        object[]     receiveInfo = e.Data.ToObject <GeneralCommand>().Datas;
                        NetAcyncType Type        = (NetAcyncType)int.Parse(receiveInfo[0].ToString());
                        switch (Type)
                        {
                        case NetAcyncType.FocusCard:
                        {
                            int X = int.Parse(receiveInfo[2].ToString());
                            int Y = int.Parse(receiveInfo[3].ToString());
                            Info.AgainstInfo.OpponentFocusCard = Info.RowsInfo.GetCard(X, Y);
                            break;
                        }

                        case NetAcyncType.PlayCard:
                        {
                            //Debug.Log("触发卡牌同步");
                            int X = int.Parse(receiveInfo[2].ToString());
                            int Y = int.Parse(receiveInfo[3].ToString());
                            //Command.CardCommand.PlayCard(Info.RowsInfo.GetCard(X, Y), false).Wait();
                            Card targetCard = Info.RowsInfo.GetCard(X, Y);
                            Task.Run(async() =>
                                {
                                    await GameSystem.TransSystem.PlayCard(new TriggerInfo(targetCard, targetCard), false);
                                    Info.AgainstInfo.IsCardEffectCompleted = true;
                                });
                            break;
                        }

                        case NetAcyncType.SelectRegion:
                        {
                            //Debug.Log("触发区域同步");
                            int X = int.Parse(receiveInfo[2].ToString());
                            Info.AgainstInfo.SelectRegion = Info.RowsInfo.GetSingleRowInfoById(X);
                            break;
                        }

                        case NetAcyncType.SelectUnites:
                        {
                            //Debug.Log("收到同步单位信息为" + rawData);
                            List <Location> Locations = receiveInfo[2].ToString().ToObject <List <Location> >();
                            Info.AgainstInfo.SelectUnits.AddRange(Locations.Select(location => Info.RowsInfo.GetCard(location.x, location.y)));
                            break;
                        }

                        case NetAcyncType.SelectLocation:
                        {
                            Debug.Log("触发坐标同步");
                            int X = int.Parse(receiveInfo[2].ToString());
                            int Y = int.Parse(receiveInfo[3].ToString());
                            //Info.RowsInfo.SingleRowInfos.First(infos => infos.ThisRowCard == Info.RowsInfo.GlobalCardList[X]);
                            Info.AgainstInfo.SelectRegion   = Info.RowsInfo.GetSingleRowInfoById(X);
                            Info.AgainstInfo.SelectLocation = Y;
                            Debug.Log($"坐标为:{X}:{Y}");
                            Debug.Log($"信息为:{"gezi"}:{Info.AgainstInfo.SelectLocation}");
                            break;
                        }

                        case NetAcyncType.Pass:
                        {
                            GameUI.UiCommand.SetCurrentPass();
                            break;
                        }

                        case NetAcyncType.Surrender:
                        {
                            Task.Run(async() =>
                                {
                                    Debug.Log("收到结束指令");
                                    await StateCommand.BattleEnd(true, true);
                                });
                            break;
                        }

                        case NetAcyncType.ExchangeCard:
                        {
                            Debug.Log("交换卡牌信息");
                            // Debug.Log("收到信息" + rawData);
                            Location location   = receiveInfo[2].ToString().ToObject <Location>();
                            int      randomRank = int.Parse(receiveInfo[3].ToString());
                            _ = CardCommand.ExchangeCard(Info.RowsInfo.GetCard(location), false, RandomRank: randomRank);
                            break;
                        }

                        case NetAcyncType.RoundStartExchangeOver:
                            if (Info.AgainstInfo.isPlayer1)
                            {
                                Info.AgainstInfo.isPlayer2RoundStartExchangeOver = true;
                            }
                            else
                            {
                                Info.AgainstInfo.isPlayer1RoundStartExchangeOver = true;
                            }
                            break;

                        case NetAcyncType.SelectProperty:
                        {
                            Info.AgainstInfo.SelectProperty = (Region)int.Parse(receiveInfo[2].ToString());
                            Debug.Log("通过网络同步当前属性为" + Info.AgainstInfo.SelectProperty);
                            break;
                        }

                        case NetAcyncType.SelectBoardCard:
                            Info.AgainstInfo.selectBoardCardRanks    = receiveInfo[2].ToString().ToObject <List <int> >();;
                            Info.AgainstInfo.IsFinishSelectBoardCard = (bool)receiveInfo[3];
                            break;

                        case NetAcyncType.Init:
                            break;

                        default:
                            break;
                        }
                    }
                    catch (System.Exception ex)
                    {
                        Debug.Log(ex);
                        throw;
                    }
                };
                AsyncConnect.OnError += (sender, e) =>
                {
                    Debug.Log("连接失败" + e.Message);
                    Debug.Log("连接失败" + e.Exception);
                };
                Debug.LogError("初始化数据" + new GeneralCommand(NetAcyncType.Init, Info.AgainstInfo.RoomID, Info.AgainstInfo.isPlayer1).ToJson());
                AsyncConnect.Send(new GeneralCommand(NetAcyncType.Init, Info.AgainstInfo.RoomID, Info.AgainstInfo.isPlayer1).ToJson());
            }
Exemplo n.º 24
0
 public StateTransition(ProcessState currentState, StateCommand command)
 {
     this.CurrentState = currentState;
     this.Command      = command;
 }
Exemplo n.º 25
0
 public override void Collide2DExit(ref Rigidbody2D r, ref Collision2D collision, ref StateCommand c)
 {
 }
Exemplo n.º 26
0
 public override void Trigger2DEnter(ref Rigidbody2D r, ref Collider2D collider, ref StateCommand c)
 {
     Debug.Log("TriggerEnter being called");
 }
Exemplo n.º 27
0
        public override bool Equals(object obj)
        {
            StateCommand other = obj as StateCommand;

            return(other != null && this.CurrentState == other.CurrentState && this.Command == other.Command);
        }
 internal override void BuildAction(string action)
 {
     base.BuildAction(action);
     this.stateCommand = new StateCommand(this.CommandArguments, this.SessionService.Object, this.FilterService.Object);
 }
Exemplo n.º 29
0
 public CommandExecutionContext(StateCommand cmd
     ,StateManager StateMgr)
 {
     m_cmd = cmd;
     m_StateMgr = StateMgr;
 }
Exemplo n.º 30
0
 public async Task PlayerSurrender()
 {
     await StateCommand.Surrender();
 }
Exemplo n.º 31
0
 public void Next(StateCommand previousState)
 {
     _stateFlow.Next(previousState);
 }