コード例 #1
0
ファイル: CommandTest.cs プロジェクト: chriscwej/robot
        public void TestCommandTurnExecuteValidateParameters()
        {
            Robot robot   = new Robot(2);
            var   command = new TurnCommand(true);

            command.Execute(robot, "A,B,C");
        }
コード例 #2
0
ファイル: TurnCommandUnitTests.cs プロジェクト: shoter/Robots
        public void Describe_ShouldWaryDependingOnAngle()
        {
            IProgramCommand firstCommand  = new TurnCommand(90);
            IProgramCommand secondCommand = new TurnCommand(123);

            Assert.NotEqual(firstCommand.Describe(), secondCommand.Describe());
        }
コード例 #3
0
ファイル: ToyBox.cs プロジェクト: Argent78/LibToyBot
        private static Robot GetRobot()
        {
            if (_robot != null)
            {
                return(_robot);
            }

            var callStack         = new Stack <Call>();
            var boundsEvaluator   = new BoundsEvaluator(new Table());
            var positionTracker   = new PositionTracker();
            var movementProcessor = new MovementProcessor(boundsEvaluator, positionTracker);
            var placeCommand      = new PlaceCommand(callStack, movementProcessor);
            var moveCommand       = new MoveCommand(callStack, movementProcessor);
            var turnCommand       = new TurnCommand(callStack, movementProcessor);
            var positionReporter  = new PositionReporter(positionTracker);
            var reportCommand     = new ReportCommand(callStack, positionReporter);
            var commandExecutor   = new CommandExecutor(
                callStack,
                placeCommand,
                moveCommand,
                turnCommand,
                reportCommand);

            _robot = new Robot(commandExecutor);

            return(_robot);
        }
コード例 #4
0
    public void HeadEnteredCell(int row, int col)
    {
        if (isAutoPilotMode)
        {
            // TODO Implement a 'Smarter' way to calculate the autoTurnCommand
            // Perhaps use AStar Algorithm or the longest path algorithm (also refer to hamiltonian circuit solver)
            // - avoid wall
            // - avoid self
            // - avoid red cube
            // - attracted to green cube
            // - attracted to blue cube
            // - attracted to non-activated tile

            // Set the autoTurnCommand using hard coded turn commands (works for levels 1-4 only)
            var turnChar = autoTurnCommands[row][col];
            if (turnChar.Equals('L'))
            {
                autoTurnCommand = TurnCommand.Left;
            }
            else if (turnChar.Equals('R'))
            {
                autoTurnCommand = TurnCommand.Right;
            }
            else if (turnChar.Equals(' '))
            {
                autoTurnCommand = TurnCommand.None;
            }
        }
    }
コード例 #5
0
        public IExecutable ManageCommand(string inputArgs)
        {
            IExecutable command = null;

            string commandType = inputArgs;

            switch (commandType)
            {
                case "top":
                    command = new StatusCommand(this.Engine);
                    break;
                case "restart":
                    command = new RestartCommand(this.Engine);
                    break;
                case "turn":
                    command = new TurnCommand(this.Engine);
                    break;
                case "exit":
                    command = new EndCommand(this.Engine);
                    break;
                default:
                    this.Engine.Writer.WriteLine("\nError! Invalid command\n");
                    break;
            }

            return command;
        }
コード例 #6
0
ファイル: GameEngine.cs プロジェクト: yuopgame/StackBattle
        public void Turn()
        {
            this.CommandInvoker.clearRedoStack();

            TurnCommand command = new TurnCommand(army1, army2);

            this.CommandInvoker.Execute(command);
        }
コード例 #7
0
ファイル: TurnCommandUnitTests.cs プロジェクト: shoter/Robots
        public void Execute_ShouldInvokeTurnOnRobot()
        {
            IProgramCommand command   = new TurnCommand(90);
            var             robotMock = new Mock <IRobot>();

            command.Execute(robotMock.Object);

            robotMock.Verify(x => x.Turn(90), Times.Once);
        }
コード例 #8
0
        public void WhenITurnTheRobot(string direction)
        {
            var robot  = scenarioContext.Get <Robot>("robot");
            var table  = scenarioContext.Get <Table>("table");
            var status = new TurnCommand(robot, direction.ToEnum <Direction>()).Execute(table);

            this.scenarioContext.Set(status, "status");
            this.scenarioContext.Set(status.Data, "table");
        }
コード例 #9
0
 private void AddTurnCommand(int facingDirection)
 {
     if (CanTurn(facingDirection))
     {
         TurnCommand command = new TurnCommand(gameObject, facingDirection, (int)m_FacingDirection);
         command.Execute();
         CommandStackProxy.Get().PushCommand(command);
     }
 }
コード例 #10
0
ファイル: CommandTest.cs プロジェクト: chriscwej/robot
        public void TestCommandTurnCanExecuteValid()
        {
            Robot robot = new Robot(2);

            robot.SetBearing("NORTH");

            var command = new TurnCommand(true);

            Assert.IsTrue(command.CanExecute(robot));
        }
コード例 #11
0
        public void Execute_CallsCorrectMethod()
        {
            const double TurnAngle   = -2.75D;
            var          robotMock   = new Mock <IRobot>();
            var          turnCommand = new TurnCommand(robotMock.Object, TurnAngle);

            turnCommand.Execute();

            robotMock.Verify(c => c.Turn(It.Is <double>(d => d == TurnAngle)), Times.Once());
        }
コード例 #12
0
ファイル: CommandTest.cs プロジェクト: chriscwej/robot
        public void TestCommandTurnCanExecuteInvalidBearing()
        {
            Robot robot = new Robot(2);

            robot.SetPosition(1, 2);

            var command = new TurnCommand(true);

            Assert.IsFalse(command.CanExecute(robot));
        }
コード例 #13
0
        public void WhenITurnTheRobot(string direction)
        {
            var scene = this.scenarioContext.Get <Scene>("scene");


            var status = new TurnCommand(direction.ToEnum <Direction>()).Execute(scene);

            this.scenarioContext.Set(status, "status");
            this.scenarioContext.Set(status.Data, "scene");
        }
コード例 #14
0
        /// <summary>
        /// Makes from a string and value a command
        /// </summary>
        /// <param name="command"></param>
        /// <param name="value"></param>
        /// <returns>Command</returns>
        public IDroneCommand makeCommand(string command, double value = 0)
        {
            IDroneCommand droneCommand = null;

            if (command.Equals("Start"))
            {
                droneCommand = new StartCommand(_droneController);
            }
            else if (command.Equals("Land"))
            {
                droneCommand = new LandCommand(_droneController);
            }
            else if (command.Equals("Rise"))
            {
                droneCommand = new RiseCommand(_droneController, value);
            }
            else if (command.Equals("Fall"))
            {
                droneCommand = new FallCommand(_droneController, value);
            }
            else if (command.Equals("Right"))
            {
                droneCommand = new RightCommand(_droneController, value);
            }
            else if (command.Equals("Left"))
            {
                droneCommand = new LeftCommand(_droneController, value);
            }
            else if (command.Equals("Forward"))
            {
                droneCommand = new ForwardCommand(_droneController, value);
            }
            else if (command.Equals("Backward"))
            {
                droneCommand = new BackwardCommand(_droneController, value);
            }
            else if (command.Equals("Turn"))
            {
                droneCommand = new TurnCommand(_droneController, (int)value);
            }
            else if (command.Equals("TakePicture"))
            {
                droneCommand = new TakePictureCommand(_droneController, (int)value);
            }
            else if (command.Equals("FollowLine"))
            {
                droneCommand = new FollowLineCommand(_droneController);
            }

            return(droneCommand);
        }
コード例 #15
0
        /// <summary>
        /// Method which process input commands
        /// </summary>
        /// <param name="command">inut command</param>
        public void ExecuteCommand(string command)
        {
            CommandInfo commandInfo    = (CommandInfo)this.commandParser.Parse(command);
            Command     currentCommand = null;

            switch (commandInfo.Name)
            {
            case "start":
                currentCommand = new StartCommand(this, this.matrix, this.player, this.director, this.builder, this.printer);
                break;

            case "turn":
                currentCommand = new TurnCommand(this, this.matrix, this.player, this.printer);
                break;

            case "menu":
                MainMenu.PrintMenu(this);
                break;

            case "exit":
                currentCommand = new ExitCommand(this.matrix, this.player, this.printer);
                break;

            case "save":
                currentCommand = new SaveCommand(this.matrix, this.player, this.printer);
                break;

            case "load":
                currentCommand = new LoadCommand(this.matrix, this.player, this.printer);
                break;

            case "mode":
                currentCommand = new ChangeModeCommand(this, this.matrix, this.player, this.printer);
                break;

            case "highscore":
                currentCommand = new HighScoreCommand(this, this.matrix, this.player, this.printer);
                break;

            default:
                currentCommand = new InvalidCommand(this.matrix, this.player, this.printer);
                currentCommand.Execute(commandInfo);
                this.Start();
                return;
            }

            currentCommand.Execute(commandInfo);
            this.printer.PrintMatrix(this.matrix, this.player);
            this.Start();
        }
コード例 #16
0
        public CommandExecutor(Stack <Call> callStack,
                               PlaceCommand placeCommand,
                               MoveCommand moveCommand,
                               TurnCommand turnCommand,
                               ReportCommand reportCommand)
        {
            _callStack     = callStack;
            _placeCommand  = placeCommand;
            _moveCommand   = moveCommand;
            _turnCommand   = turnCommand;
            _reportCommand = reportCommand;


//            _callStack = new Stack<Call>();
        }
コード例 #17
0
ファイル: CommandTest.cs プロジェクト: chriscwej/robot
        public void TestCommandTurnExecuteAntiClockwise()
        {
            Robot robot = new Robot(2);

            robot.SetPosition(1, 1);
            robot.SetBearing("NORTH");

            var command = new TurnCommand(false);

            command.Execute(robot, "");

            Assert.AreEqual(1, robot.xPos);
            Assert.AreEqual(1, robot.yPos);
            Assert.AreEqual("WEST", robot.bearing);
        }
コード例 #18
0
    protected virtual void Start()
    {
        boxCollider = GetComponent <BoxCollider2D>();
        rb2D        = GetComponent <Rigidbody2D>();

        moveTime        = GameManager.instance.turnDelay;
        inverseMoveTime = 1f / moveTime;

        logicalPos = transform.position;
        GameManager.instance.AddMovingObjectToList(this);
        direction = new Vector2(0, -1);
        Command   = TurnCommand.Undef;
        ActualActionCommandTime = Status.OriginalActionCommandTime;

        UpdateStatus();
        InitializeStatus();
    }
コード例 #19
0
        public virtual ICommand CreateCommand(IGameEngine gameEngine, string commandArgs)
        {
            int    row;
            int    col;
            string commandName = commandArgs;

            if (commandArgs.Length >= 3)
            {
                bool isRowSet     = int.TryParse(commandArgs[0].ToString(), out row);
                bool isColSet     = int.TryParse(commandArgs[2].ToString(), out col);
                bool isRowInRange = row <= gameEngine.GameField.GetLength(0);
                bool isColInRange = col <= gameEngine.GameField.GetLength(1);
                if ((isRowSet && isColSet) && isRowInRange && isColInRange)
                {
                    commandName = "turn";
                }
            }

            ICommand command = null;

            string[] inputArgs = commandArgs.Split(' ');
            switch (commandName.ToLower())
            {
            case "top":
                command = new TopCommand(gameEngine);
                break;

            case "restart":
                command = new RestartCommand(gameEngine);
                break;

            case "turn":
                command = new TurnCommand(gameEngine, inputArgs);
                break;

            case "exit":
                command = new ExitCommand(gameEngine);
                break;

            default:
                break;
            }

            return(command);
        }
コード例 #20
0
    void Update()
    {
        if (!turning && turnCommand == TurnCommand.None)
        {
            if (isAutoPilotMode)
            {
                // Set turn command from calculated auto turn command
                turnCommand = autoTurnCommand;
            }
            else
            {
                float horizontal = Input.GetAxisRaw("Horizontal");

                if (horizontal != 0)
                {
                    turnCommand = (horizontal == 1) ? TurnCommand.Right : TurnCommand.Left;
                }
            }
        }
    }
コード例 #21
0
        public void TestExecuteAllCommands()
        {
            var robot      = new Robot();
            var controller = new RobotController();

            var move = new MoveCommand(robot);

            move.Distance = 1000;
            controller.ExecuteCommand(move);

            var turn = new TurnCommand(robot);

            turn.Angle = 45;
            controller.ExecuteCommand(turn);

            var beep = new BeepCommand(robot);

            controller.ExecuteCommand(beep);

            Assert.AreEqual(controller.CommandCount, 3);
        }
コード例 #22
0
ファイル: Arena.cs プロジェクト: Nero-X/BattleBots
    List <Command> BuildCommandLists(GameObject player, Transform content)
    {
        Transform      _enemy = player == this.player ? enemy.transform : this.player.transform;
        List <Command> list   = new List <Command>();

        foreach (Transform headCmd in content)
        {
            List <Command> lst      = null;
            Transform      cmdObj   = headCmd;
            Command        cmdClass = null;
            while (true)
            {
                switch (cmdObj.name)
                {
                // Movement
                case "Move(Clone)": cmdClass = new MoveCommand(player, Convert.ToInt32(cmdObj.GetArgs()[0])); break;

                case "TurnR(Clone)": cmdClass = new TurnCommand(player, -Convert.ToSingle(cmdObj.GetArgs()[0])); break;

                case "TurnL(Clone)": cmdClass = new TurnCommand(player, Convert.ToSingle(cmdObj.GetArgs()[0])); break;

                // Actions
                case "Shoot(Clone)": cmdClass = new ShootCommand(player, bulletPrefab); break;

                case "Look at enemy(Clone)": cmdClass = new TurnCommand(player, _enemy); break;

                // Events

                /*case "OnStart(Clone)":
                 *  lst = new List<Command>();
                 *  player.GetComponent<Player>().OnStart += () => HandleEvent(player, new Thread(this, lst, false, Convert.ToInt32(headCmd.GetArgs()[0]), headCmd.name)); break;*/
                case "OnCollisionWithBullet(Clone)":
                    lst = new List <Command>();
                    player.GetComponent <Player>().OnCollisionWithBullet += () => HandleEvent(player, new Thread(this, lst, false, Convert.ToInt32(headCmd.GetArgs()[0]), headCmd.name)); break;

                case "OnCollisionWithPlayer(Clone)":
                    lst = new List <Command>();
                    player.GetComponent <Player>().OnCollisionWithPlayer += () => HandleEvent(player, new Thread(this, lst, false, Convert.ToInt32(headCmd.GetArgs()[0]), headCmd.name)); break;

                case "OnSuccessfulHit(Clone)":
                    lst = new List <Command>();
                    _enemy.GetComponent <Player>().OnCollisionWithBullet += () => HandleEvent(player, new Thread(this, lst, false, Convert.ToInt32(headCmd.GetArgs()[0]), headCmd.name)); break;

                case "OnTimer(Clone)":
                    lst = new List <Command>();
                    player.GetComponent <Player>().OnTimer += () =>
                    {
                        if (player.GetComponent <Player>().secondsAlive % Convert.ToInt32(headCmd.GetArgs()[1]) == 0)
                        {
                            HandleEvent(player, new Thread(this, lst, false, Convert.ToInt32(headCmd.GetArgs()[0]), headCmd.name));
                        }
                    }; break;

                case "OnChangeHP(Clone)":
                    lst = new List <Command>();
                    player.GetComponent <Player>().OnChangeHP += () =>
                    {
                        if (player.GetComponent <Player>().HP == Convert.ToInt32(headCmd.GetArgs()[1]))
                        {
                            HandleEvent(player, new Thread(this, lst, false, Convert.ToInt32(headCmd.GetArgs()[0]), headCmd.name));
                        }
                    }; break;

                case "OnCollisionWithBounds(Clone)":
                    lst = new List <Command>();
                    player.GetComponent <Bounds>().OnCollisionWithBounds += () => HandleEvent(player, new Thread(this, lst, false, Convert.ToInt32(headCmd.GetArgs()[0]), headCmd.name)); break;
                }
                if (lst == null)
                {
                    list.Add(cmdClass);
                }
                else if (cmdClass != null)
                {
                    lst.Add(cmdClass);
                }
                Transform next = cmdObj.Next();
                if (next == null)
                {
                    break;
                }
                else
                {
                    cmdObj = next;
                }
            }
        }
        return(list);
    }
コード例 #23
0
 public void SetCommand(TurnCommand c)
 {
     Command = c;
 }
コード例 #24
0
        protected override void OnReceived(byte[] body)
        {
            ByteArrayArrayStream stream = new ByteArrayArrayStream(body);

            ByteArrayStreamReader reader = new ByteArrayStreamReader(stream);

            try
            {
                if (Adler32.Generate(body, 4) == reader.ReadUInt())
                {
                    if (Keys == null)
                    {
                        Rsa.DecryptAndReplace(body, 9);
                    }
                    else
                    {
                        Xtea.DecryptAndReplace(body, 4, 32, Keys);

                        stream.Seek(Origin.Current, 2);
                    }

                    Command command = null;

                    switch (reader.ReadByte())
                    {
                    case 0x0A:
                    {
                        var packet = server.PacketsFactory.Create <SelectedCharacterIncomingPacket>(reader);

                        command = new LogInCommand(this, packet);
                    }
                    break;

                    case 0x14:

                        command = new LogOutCommand(Client.Player);

                        break;

                    case 0x1E:

                        command = new PongCommand(Client.Player);

                        break;

                    case 0x64:
                    {
                        var packet = server.PacketsFactory.Create <WalkToIncomingPacket>(reader);

                        command = new WalkToKnownPathCommand(Client.Player, packet.MoveDirections);
                    }
                    break;

                    case 0x65:

                        command = new WalkCommand(Client.Player, MoveDirection.North);

                        break;

                    case 0x66:

                        command = new WalkCommand(Client.Player, MoveDirection.East);

                        break;

                    case 0x67:

                        command = new WalkCommand(Client.Player, MoveDirection.South);

                        break;

                    case 0x68:

                        command = new WalkCommand(Client.Player, MoveDirection.West);

                        break;

                    case 0x69:

                        command = new StopWalkCommand(Client.Player);

                        break;

                    case 0x6A:

                        command = new WalkCommand(Client.Player, MoveDirection.NorthEast);

                        break;

                    case 0x6B:

                        command = new WalkCommand(Client.Player, MoveDirection.SouthEast);

                        break;

                    case 0x6C:

                        command = new WalkCommand(Client.Player, MoveDirection.SouthWest);

                        break;

                    case 0x6D:

                        command = new WalkCommand(Client.Player, MoveDirection.NorthWest);

                        break;

                    case 0x6F:

                        command = new TurnCommand(Client.Player, Direction.North);

                        break;

                    case 0x70:

                        command = new TurnCommand(Client.Player, Direction.East);

                        break;

                    case 0x71:

                        command = new TurnCommand(Client.Player, Direction.South);

                        break;

                    case 0x72:

                        command = new TurnCommand(Client.Player, Direction.West);

                        break;

                    case 0x78:
                    {
                        var packet = server.PacketsFactory.Create <MoveItemIncomingPacket>(reader);

                        Position fromPosition = new Position(packet.FromX, packet.FromY, packet.FromZ);

                        Position toPosition = new Position(packet.ToX, packet.ToY, packet.ToZ);

                        if (fromPosition.IsContainer)
                        {
                            if (toPosition.IsContainer)
                            {
                                command = new MoveItemFromContainerToContainerCommand(Client.Player, fromPosition.ContainerId, fromPosition.ContainerIndex, packet.FromItemId, toPosition.ContainerId, toPosition.ContainerIndex, packet.Count);
                            }
                            else if (toPosition.IsInventory)
                            {
                                command = new MoveItemFromContainerToInventoryCommand(Client.Player, fromPosition.ContainerId, fromPosition.ContainerIndex, packet.FromItemId, toPosition.InventoryIndex, packet.Count);
                            }
                            else
                            {
                                command = new MoveItemFromContainerToTileCommand(Client.Player, fromPosition.ContainerId, fromPosition.ContainerIndex, packet.FromItemId, toPosition, packet.Count);
                            }
                        }
                        else if (fromPosition.IsInventory)
                        {
                            if (toPosition.IsContainer)
                            {
                                command = new MoveItemFromInventoryToContainerCommand(Client.Player, fromPosition.InventoryIndex, packet.FromItemId, toPosition.ContainerId, toPosition.ContainerIndex, packet.Count);
                            }
                            else if (toPosition.IsInventory)
                            {
                                command = new MoveItemFromInventoryToInventoryCommand(Client.Player, fromPosition.InventoryIndex, packet.FromItemId, toPosition.InventoryIndex, packet.Count);
                            }
                            else
                            {
                                command = new MoveItemFromInventoryToTileCommand(Client.Player, fromPosition.InventoryIndex, packet.FromItemId, toPosition, packet.Count);
                            }
                        }
                        else
                        {
                            if (toPosition.IsContainer)
                            {
                                command = new MoveItemFromTileToContainerCommand(Client.Player, fromPosition, packet.FromIndex, packet.FromItemId, toPosition.ContainerId, toPosition.ContainerIndex, packet.Count);
                            }
                            else if (toPosition.IsInventory)
                            {
                                command = new MoveItemFromTileToInventoryCommand(Client.Player, fromPosition, packet.FromIndex, packet.FromItemId, toPosition.InventoryIndex, packet.Count);
                            }
                            else
                            {
                                command = new MoveItemFromTileToTileCommand(Client.Player, fromPosition, packet.FromIndex, packet.FromItemId, toPosition, packet.Count);
                            }
                        }
                    }
                    break;

                    case 0x79:
                    {
                        var packet = server.PacketsFactory.Create <LookItemNpcTradeIncommingPacket>(reader);

                        command = new LookFromNpcTradeCommand(Client.Player, packet.ItemId, packet.Type);
                    }
                    break;

                    case 0x7A:
                    {
                        var packet = server.PacketsFactory.Create <BuyNpcTradeIncommingPacket>(reader);

                        command = new BuyNpcTradeCommand(Client.Player, packet);
                    }
                    break;

                    case 0x7B:
                    {
                        var packet = server.PacketsFactory.Create <SellNpcTradeIncommingPacket>(reader);

                        command = new SellNpcTradeCommand(Client.Player, packet);
                    }
                    break;

                    case 0x7C:

                        command = new CloseNpcTradeCommand(Client.Player);

                        break;

                    case 0x7D:
                    {
                        var packet = server.PacketsFactory.Create <TradeWithIncommingPacket>(reader);

                        Position fromPosition = new Position(packet.X, packet.Y, packet.Z);

                        if (fromPosition.IsContainer)
                        {
                            command = new TradeWithFromContainerCommand(Client.Player, fromPosition.ContainerId, fromPosition.ContainerIndex, packet.ItemId, packet.CreatureId);
                        }
                        else if (fromPosition.IsInventory)
                        {
                            command = new TradeWithFromInventoryCommand(Client.Player, fromPosition.InventoryIndex, packet.ItemId, packet.CreatureId);
                        }
                        else
                        {
                            command = new TradeWithFromTileCommand(Client.Player, fromPosition, packet.Index, packet.ItemId, packet.CreatureId);
                        }
                    }
                    break;

                    case 0x7E:
                    {
                        var packet = server.PacketsFactory.Create <LookItemTradeIncommingPacket>(reader);

                        command = new LookFromTradeCommand(Client.Player, packet.WindowId, packet.Index);
                    }
                    break;

                    case 0x7F:

                        command = new AcceptTradeCommand(Client.Player);

                        break;

                    case 0x80:

                        command = new CancelTradeCommand(Client.Player);

                        break;

                    case 0x82:
                    {
                        var packet = server.PacketsFactory.Create <UseItemIncomingPacket>(reader);

                        Position fromPosition = new Position(packet.X, packet.Y, packet.Z);

                        if (fromPosition.IsContainer)
                        {
                            command = new UseItemFromContainerCommand(Client.Player, fromPosition.ContainerId, fromPosition.ContainerIndex, packet.ItemId, packet.ContainerId);
                        }
                        else if (fromPosition.IsInventory)
                        {
                            command = new UseItemFromInventoryCommand(Client.Player, fromPosition.InventoryIndex, packet.ItemId);
                        }
                        else
                        {
                            command = new UseItemFromTileCommand(Client.Player, fromPosition, packet.Index, packet.ItemId);
                        }
                    }
                    break;

                    case 0x83:
                    {
                        var packet = server.PacketsFactory.Create <UseItemWithItemIncomingPacket>(reader);

                        Position fromPosition = new Position(packet.FromX, packet.FromY, packet.FromZ);

                        Position toPosition = new Position(packet.ToX, packet.ToY, packet.ToZ);

                        if (fromPosition.IsContainer)
                        {
                            if (toPosition.IsContainer)
                            {
                                command = new UseItemWithItemFromContainerToContainerCommand(Client.Player, fromPosition.ContainerId, fromPosition.ContainerIndex, packet.FromItemId, toPosition.ContainerId, toPosition.ContainerIndex, packet.ToItemId);
                            }
                            else if (toPosition.IsInventory)
                            {
                                command = new UseItemWithItemFromContainerToInventoryCommand(Client.Player, fromPosition.ContainerId, fromPosition.ContainerIndex, packet.FromItemId, toPosition.InventoryIndex, packet.ToItemId);
                            }
                            else
                            {
                                command = new UseItemWithItemFromContainerToTileCommand(Client.Player, fromPosition.ContainerId, fromPosition.ContainerIndex, packet.FromItemId, toPosition, packet.ToIndex, packet.ToItemId);
                            }
                        }
                        else if (fromPosition.IsInventory)
                        {
                            if (toPosition.IsContainer)
                            {
                                command = new UseItemWithItemFromInventoryToContainerCommand(Client.Player, fromPosition.InventoryIndex, packet.FromItemId, toPosition.ContainerId, toPosition.ContainerIndex, packet.ToItemId);
                            }
                            else if (toPosition.IsInventory)
                            {
                                command = new UseItemWithItemFromInventoryToInventoryCommand(Client.Player, fromPosition.InventoryIndex, packet.FromItemId, toPosition.InventoryIndex, packet.ToItemId);
                            }
                            else
                            {
                                command = new UseItemWithItemFromInventoryToTileCommand(Client.Player, fromPosition.InventoryIndex, packet.FromItemId, toPosition, packet.ToIndex, packet.ToItemId);
                            }
                        }
                        else
                        {
                            if (toPosition.IsContainer)
                            {
                                command = new UseItemWithItemFromTileToContainerCommand(Client.Player, fromPosition, packet.FromIndex, packet.FromItemId, toPosition.ContainerId, toPosition.ContainerIndex, packet.ToItemId);
                            }
                            else if (toPosition.IsInventory)
                            {
                                command = new UseItemWithItemFromTileToInventoryCommand(Client.Player, fromPosition, packet.FromIndex, packet.FromItemId, toPosition.InventoryIndex, packet.ToItemId);
                            }
                            else
                            {
                                command = new UseItemWithItemFromTileToTileCommand(Client.Player, fromPosition, packet.FromIndex, packet.FromItemId, toPosition, packet.ToIndex, packet.ToItemId);
                            }
                        }
                    }
                    break;

                    case 0x84:
                    {
                        var packet = server.PacketsFactory.Create <UseItemWithCreatureIncomingPacket>(reader);

                        Position fromPosition = new Position(packet.X, packet.Y, packet.Z);

                        if (fromPosition.IsContainer)
                        {
                            command = new UseItemWithCreatureFromContainerCommand(Client.Player, fromPosition.ContainerId, fromPosition.ContainerIndex, packet.ItemId, packet.CreatureId);
                        }
                        else if (fromPosition.IsInventory)
                        {
                            command = new UseItemWithCreatureFromInventoryCommand(Client.Player, fromPosition.InventoryIndex, packet.ItemId, packet.CreatureId);
                        }
                        else
                        {
                            command = new UseItemWithCreatureFromTileCommand(Client.Player, fromPosition, packet.Index, packet.ItemId, packet.CreatureId);
                        }
                    }
                    break;

                    case 0x85:
                    {
                        var packet = server.PacketsFactory.Create <RotateItemIncomingPacket>(reader);

                        var fromPosition = new Position(packet.X, packet.Y, packet.Z);

                        if (fromPosition.IsContainer)
                        {
                            command = new RotateItemFromContainerCommand(Client.Player, fromPosition.ContainerId, fromPosition.ContainerIndex, packet.ItemId);
                        }
                        else if (fromPosition.IsInventory)
                        {
                            command = new RotateItemFromInventoryCommand(Client.Player, fromPosition.InventoryIndex, packet.ItemId);
                        }
                        else
                        {
                            command = new RotateItemFromTileCommand(Client.Player, fromPosition, packet.Index, packet.ItemId);
                        }
                    }
                    break;

                    case 0x87:
                    {
                        var packet = server.PacketsFactory.Create <CloseContainerIncommingPacket>(reader);

                        command = new CloseContainerCommand(Client.Player, packet.ContainerId);
                    }
                    break;

                    case 0x88:
                    {
                        var packet = server.PacketsFactory.Create <OpenParentIncommingPacket>(reader);

                        command = new OpenParentContainerCommand(Client.Player, packet.ContainerId);
                    }
                    break;

                    case 0x8C:
                    {
                        var packet = server.PacketsFactory.Create <LookIncomingPacket>(reader);

                        var fromPosition = new Position(packet.X, packet.Y, packet.Z);

                        if (fromPosition.IsContainer)
                        {
                            command = new LookFromContainerCommand(Client.Player, fromPosition.ContainerId, fromPosition.ContainerIndex, packet.ItemId);
                        }
                        else if (fromPosition.IsInventory)
                        {
                            command = new LookFromInventoryCommand(Client.Player, fromPosition.InventoryIndex, packet.ItemId);
                        }
                        else
                        {
                            command = new LookFromTileCommand(Client.Player, fromPosition, packet.Index, packet.ItemId);
                        }
                    }
                    break;

                    case 0x96:
                    {
                        var packet = server.PacketsFactory.Create <TalkIncommingPacket>(reader);

                        switch (packet.TalkType)
                        {
                        case TalkType.Say:

                            command = new SayCommand(Client.Player, packet.Message);

                            break;

                        case TalkType.Whisper:

                            command = new WhisperCommand(Client.Player, packet.Message);

                            break;

                        case TalkType.Yell:

                            command = new YellCommand(Client.Player, packet.Message);

                            break;

                        case TalkType.Private:

                            command = new SendMessageToPlayerCommand(Client.Player, packet.Name, packet.Message);

                            break;

                        case TalkType.ChannelYellow:

                            command = new SendMessageToChannel(Client.Player, packet.ChannelId, packet.Message);

                            break;

                        case TalkType.ReportRuleViolationOpen:

                            command = new CreateReportRuleViolationCommand(Client.Player, packet.Message);

                            break;

                        case TalkType.ReportRuleViolationAnswer:

                            command = new AnswerInReportRuleViolationChannelCommand(Client.Player, packet.Name, packet.Message);

                            break;

                        case TalkType.ReportRuleViolationQuestion:

                            command = new AskInReportRuleViolationChannelCommand(Client.Player, packet.Message);

                            break;

                        case TalkType.Broadcast:

                            command = new BroadcastMessageCommand(Client.Player, packet.Message);

                            break;
                        }
                    }
                    break;

                    case 0x97:

                        command = new OpenNewChannelCommand(Client.Player);

                        break;

                    case 0x98:
                    {
                        var packet = server.PacketsFactory.Create <OpenedNewChannelIncomingPacket>(reader);

                        command = new OpenedNewChannelCommand(Client.Player, packet.ChannelId);
                    }
                    break;

                    case 0x99:
                    {
                        var packet = server.PacketsFactory.Create <CloseChannelIncommingPacket>(reader);

                        command = new CloseChannelCommand(Client.Player, packet.ChannelId);
                    }
                    break;

                    case 0x9A:
                    {
                        var packet = server.PacketsFactory.Create <OpenedPrivateChannelIncomingPacket>(reader);

                        command = new OpenedPrivateChannelCommand(Client.Player, packet.Name);
                    }
                    break;

                    case 0x9B:
                    {
                        var packet = server.PacketsFactory.Create <ProcessReportRuleViolationIncommingPacket>(reader);

                        command = new ProcessReportRuleViolationCommand(Client.Player, packet.Name);
                    }
                    break;

                    case 0x9C:
                    {
                        var packet = server.PacketsFactory.Create <CloseReportRuleViolationChannelAnswerIncommingPacket>(reader);

                        command = new CloseReportRuleViolationChannelAnswerCommand(Client.Player, packet.Name);
                    }
                    break;

                    case 0x9D:

                        command = new CloseReportRuleViolationChannelQuestionCommand(Client.Player);

                        break;

                    case 0x9E:

                        command = new CloseNpcsChannelCommand(Client.Player);

                        break;

                    case 0xA0:
                    {
                        var packet = server.PacketsFactory.Create <CombatControlsIncommingPacket>(reader);

                        command = new CombatControlsCommand(Client.Player, packet.FightMode, packet.ChaseMode, packet.SafeMode);
                    }
                    break;

                    case 0xA1:
                    {
                        var packet = server.PacketsFactory.Create <AttackIncommingPacket>(reader);

                        if (packet.CreatureId == 0)
                        {
                            command = new StopAttackCommand(Client.Player);
                        }
                        else
                        {
                            command = new StartAttackCommand(Client.Player, packet.CreatureId, packet.Nonce);
                        }
                    }
                    break;

                    case 0xA2:
                    {
                        var packet = server.PacketsFactory.Create <FollowIncommingPacket>(reader);

                        if (packet.CreatureId == 0)
                        {
                            command = new StopFollowCommand(Client.Player);
                        }
                        else
                        {
                            command = new StartFollowCommand(Client.Player, packet.CreatureId, packet.Nonce);
                        }
                    }
                    break;

                    case 0xA3:
                    {
                        var packet = server.PacketsFactory.Create <InviteToPartyIncomingPacket>(reader);

                        command = new InviteToPartyCommand(Client.Player, packet.CreatureId);
                    }
                    break;

                    case 0xA4:
                    {
                        var packet = server.PacketsFactory.Create <JoinPartyIncomingPacket>(reader);

                        command = new JoinPartyCommand(Client.Player, packet.CreatureId);
                    }
                    break;

                    case 0xA5:
                    {
                        var packet = server.PacketsFactory.Create <RevokePartyIncomingPacket>(reader);

                        command = new RevokePartyCommand(Client.Player, packet.CreatureId);
                    }
                    break;

                    case 0xA6:
                    {
                        var packet = server.PacketsFactory.Create <PassLeadershipToIncomingPacket>(reader);

                        command = new PassLeaderShipToCommand(Client.Player, packet.CreatureId);
                    }
                    break;

                    case 0xA7:

                        command = new LeavePartyCommand(Client.Player);

                        break;

                    case 0xA8:
                    {
                        var packet = server.PacketsFactory.Create <SharedExperienceIncomingPacket>(reader);

                        command = new SharedExperienceCommand(Client.Player, packet.Enabled);
                    }
                    break;

                    case 0xAA:

                        command = new OpenedMyPrivateChannelCommand(Client.Player);

                        break;

                    case 0xAB:
                    {
                        var packet = server.PacketsFactory.Create <InvitePlayerIncommingPacket>(reader);

                        command = new InvitePlayerCommand(Client.Player, packet.Name);
                    }
                    break;

                    case 0xAC:
                    {
                        var packet = server.PacketsFactory.Create <ExcludePlayerIncommingPacket>(reader);

                        command = new ExcludePlayerCommand(Client.Player, packet.Name);
                    }
                    break;

                    case 0xBE:

                        command = new StopCommand(Client.Player);

                        break;

                    case 0xD2:

                        command = new SelectOutfitCommand(Client.Player);

                        break;

                    case 0xD3:
                    {
                        var packet = server.PacketsFactory.Create <SelectedOutfitIncomingPacket>(reader);

                        command = new SelectedOutfitCommand(Client.Player, packet.Outfit);
                    }
                    break;

                    case 0xDC:
                    {
                        var packet = server.PacketsFactory.Create <AddVipIncommingPacket>(reader);

                        command = new AddVipCommand(Client.Player, packet.Name);
                    }
                    break;

                    case 0xDD:
                    {
                        var packet = server.PacketsFactory.Create <RemoveVipIncommingPacket>(reader);

                        command = new RemoveVipCommand(Client.Player, packet.CreatureId);
                    }
                    break;

                    case 0xE6:
                    {
                        var packet = server.PacketsFactory.Create <ReportBugIncomingPacket>(reader);

                        command = new ReportBugCommand(Client.Player, packet.Message);
                    }
                    break;

                    case 0xF0:

                        command = new OpenQuestsCommand(Client.Player);

                        break;

                    case 0xF1:
                    {
                        var packet = server.PacketsFactory.Create <OpenQuestIncomingPacket>(reader);

                        command = new OpenQuestCommand(Client.Player, packet.QuestId);
                    }
                    break;
                    }

                    if (command != null)
                    {
                        server.QueueForExecution(command);
                    }
                }
            }
            catch (Exception ex)
            {
                server.Logger.WriteLine(ex.ToString());
            }

            base.OnReceived(body);
        }
コード例 #25
0
    void FixedUpdate()
    {
        if (isPosingForTitleScreen || isKilled)
        {
            return;
        }

        if (isShrinking)
        {
            if (Time.time - shrinkStartTime > shrinkDuration)
            {
                isShrinking = false;
                RemoveLastTailPart();
            }
        }

        if (isShielded)
        {
            // Update shield status bar
            var shieldTimeRemainingPercentage = 1 - ((Time.time - shieldStartTime) / shieldDuration);
            main.UpdateShieldStatusBar(shieldTimeRemainingPercentage);

            if (Time.time - shieldStartTime > shieldDuration)
            {
                isShielded = false;
                // Clear shield status bar
                main.UpdateShieldStatusBar(0);
                // Clear body metallic
                SetBodyMetallic(0);
            }
        }

        Vector3 direction = Vector3.Normalize(headRigidbody.velocity);

        if (!turning)
        {
            if (turnCommand != TurnCommand.None)
            {
                float   diff;
                Vector3 gridPos1;
                Vector3 gridPos2;

                // TODO Extract method getSnappedGridPositionWithinThreshold(Vector3 position, Vector3 direction, float threshold)


                // Determine whether head is allowed to turn at its current position
                if (direction == Vector3.forward || direction == Vector3.back)
                {
                    var zPos1 = Mathf.Floor(head.transform.position.z / gridSpacing) * gridSpacing;
                    var zPos2 = zPos1 + gridSpacing;
                    gridPos1 = new Vector3(head.transform.position.x, head.transform.position.y, zPos1);
                    gridPos2 = new Vector3(head.transform.position.x, head.transform.position.y, zPos2);
                }
                else
                {
                    var xPos1 = Mathf.Floor(head.transform.position.x / gridSpacing) * gridSpacing;
                    var xPos2 = xPos1 + gridSpacing;
                    gridPos1 = new Vector3(xPos1, head.transform.position.y, head.transform.position.z);
                    gridPos2 = new Vector3(xPos2, head.transform.position.y, head.transform.position.z);
                }
                var distanceToGridPos1 = Vector3.Distance(head.transform.position, gridPos1);
                var distanceToGridPos2 = Vector3.Distance(head.transform.position, gridPos2);
                diff = Mathf.Min(distanceToGridPos1, distanceToGridPos2);

                var incomingDirection = direction;

                // Rotate head towards the intended turn direction
                if (turnCommand == TurnCommand.Right)
                {
                    // Turn Right
                    direction = Quaternion.Euler(0, 90, 0) * direction;
                }
                else
                {
                    // Turn Left;
                    direction = Quaternion.Euler(0, -90, 0) * direction;
                }

                // TODO the threshold needs to take into account the velocity
                var threshold = 0.01F;
                if (diff < threshold)
                {
                    // -- TURN --
                    turning = true;

                    // Snap head position to grid
                    var snapGridPos = (distanceToGridPos1 < distanceToGridPos2) ? gridPos1 : gridPos2;
                    head.transform.position = snapGridPos;

                    // Prevent turning again for a short time
                    turningStartTime = Time.time;

                    // Track new turning point
                    turningPoints.AssignNewlyCreatedTurningPoint(lastTail.GetComponent <Tail>(), head.transform.position, incomingDirection, direction);

                    // Update Head Velocity
                    headRigidbody.velocity = direction * speed;

                    // Reset turn command
                    turnCommand = TurnCommand.None;
                }
            }
        }
        else
        {
            // Prevent turning again for a short time
            float timePassed = (Time.time - turningStartTime);
            if (timePassed > 0.2)
            {
                turning = false;
            }
        }

        if (head != null)
        {
            // Update Head Rotation
            head.transform.rotation = Quaternion.Lerp(head.transform.rotation, Quaternion.LookRotation(direction), 0.07f);
        }

        // Grow when 'G' pressed
        if (Input.GetKeyDown(KeyCode.G))
        {
            Grow();
        }
    }
コード例 #26
0
ファイル: TurnCommandUnitTests.cs プロジェクト: shoter/Robots
        public void Describe_ShouldBeNotEmpty()
        {
            IProgramCommand command = new TurnCommand(123);

            Assert.False(string.IsNullOrWhiteSpace(command.Describe()));
        }
コード例 #27
0
    void Start()
    {
        // -- Turning Points --
        turningPoints = InitTurningPoints();

        // Direction
        var initialHeadDirection = startingDirection;

        // Turn command
        turnCommand = TurnCommand.None;

        var lowPolySphereMesh = gameObject.AddComponent <LowPolySphere>().GetLowPolySphereMesh();

        // Head
        head = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        Destroy(head.GetComponent <MeshFilter>().mesh);
        head.GetComponent <MeshFilter>().mesh = lowPolySphereMesh;
        head.name                 = "Head";
        head.transform.parent     = transform;
        head.transform.localScale = new Vector3(playerWidth, playerHeight, playerWidth);
        head.transform.position   = new Vector3(0, yPos, 0);
        head.GetComponent <Renderer>().material.color = bodyColor;
        head.GetComponent <Renderer>().material.SetInt("_SmoothnessTextureChannel", 1);
        head.GetComponent <Renderer>().material.SetFloat("_Glossiness", 0.93f);
        head.AddComponent <Rigidbody>();

        headRigidbody             = head.GetComponent <Rigidbody>();
        headRigidbody.isKinematic = false;
        headRigidbody.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionY;
        if (!isPosingForTitleScreen)
        {
            headRigidbody.velocity = initialHeadDirection * speed;
        }

        // Left Eye
        GameObject leftEye = GameObject.CreatePrimitive(PrimitiveType.Sphere);

        Destroy(leftEye.GetComponent <MeshFilter>().mesh);
        leftEye.GetComponent <MeshFilter>().mesh = lowPolySphereMesh;
        leftEye.name = "Left Eye";
        leftEye.transform.localScale = new Vector3(2, 3, 2);
        leftEye.GetComponent <Renderer>().material.color = eyeColor;
        leftEye.transform.parent   = head.transform;
        leftEye.transform.position = head.transform.position;
        leftEye.transform.Translate(1, 1, 1.5f);
        leftEye.GetComponent <Collider>().isTrigger = true; // Making a trigger to avoid altering the head's center-of-mass

        // Left Pupil
        GameObject leftPupil = GameObject.CreatePrimitive(PrimitiveType.Sphere);

        Destroy(leftPupil.GetComponent <MeshFilter>().mesh);
        leftPupil.GetComponent <MeshFilter>().mesh = lowPolySphereMesh;
        leftPupil.name = "Left Pupil";
        leftPupil.transform.localScale = new Vector3(1, 2, 1);
        leftPupil.GetComponent <Renderer>().material.color = pupilColor;
        leftPupil.transform.parent   = head.transform;
        leftPupil.transform.position = head.transform.position;
        leftPupil.transform.Translate(1, 1.5f, 2.25f);
        leftPupil.GetComponent <Collider>().isTrigger = true; // Making a trigger to avoid altering the head's center-of-mass

        // Right Eye
        GameObject rightEye = GameObject.CreatePrimitive(PrimitiveType.Sphere);

        Destroy(rightEye.GetComponent <MeshFilter>().mesh);
        rightEye.GetComponent <MeshFilter>().mesh = lowPolySphereMesh;
        rightEye.name = "Right Eye";
        rightEye.transform.localScale = new Vector3(2, 3, 2);
        rightEye.GetComponent <Renderer>().material.color = eyeColor;
        rightEye.transform.parent   = head.transform;
        rightEye.transform.position = head.transform.position;
        rightEye.transform.Translate(-1, 1, 1.5f);
        rightEye.GetComponent <Collider>().isTrigger = true; // Making a trigger to avoid altering the head's center-of-mass

        // Right Pupil
        GameObject rightPupil = GameObject.CreatePrimitive(PrimitiveType.Sphere);

        Destroy(rightPupil.GetComponent <MeshFilter>().mesh);
        rightPupil.GetComponent <MeshFilter>().mesh = lowPolySphereMesh;
        rightPupil.name = "Right Pupil";
        rightPupil.transform.localScale = new Vector3(1, 2, 1);
        rightPupil.GetComponent <Renderer>().material.color = pupilColor;
        rightPupil.transform.parent   = head.transform;
        rightPupil.transform.position = head.transform.position;
        rightPupil.transform.Translate(-1, 1.5f, 2.25f);
        rightPupil.GetComponent <Collider>().isTrigger = true; // Making a trigger to avoid altering the head's center-of-mass

        // Nose
        GameObject nose = GameObject.CreatePrimitive(PrimitiveType.Sphere);

        Destroy(nose.GetComponent <MeshFilter>().mesh);
        nose.GetComponent <MeshFilter>().mesh = lowPolySphereMesh;
        nose.name = "Nose";
        nose.transform.localScale = new Vector3(3, 2, 2);
        nose.GetComponent <Renderer>().material.color = noseColor;
        nose.transform.parent   = head.transform;
        nose.transform.position = head.transform.position;
        nose.transform.Translate(0, 0, 2.5f);
        nose.GetComponent <Collider>().isTrigger = true; // Making a trigger to avoid altering the head's center-of-mass

        // Mouth
        GameObject mouth = GameObject.CreatePrimitive(PrimitiveType.Sphere);

        Destroy(mouth.GetComponent <MeshFilter>().mesh);
        mouth.GetComponent <MeshFilter>().mesh = lowPolySphereMesh;
        mouth.name = "Mouth";
        mouth.transform.localScale = new Vector3(3, 0.5f, 2);
        mouth.GetComponent <Renderer>().material.color = mouthColor;
        mouth.transform.parent   = head.transform;
        mouth.transform.position = head.transform.position;
        mouth.transform.Translate(0, -1.5f, 1f);
        mouth.transform.rotation = Quaternion.AngleAxis(90, Vector3.up);
        mouth.GetComponent <Collider>().isTrigger = true; // Making a trigger to avoid altering the head's center-of-mass

        // Rotate Head (Note: Doing this AFTER adding children)
        head.transform.rotation = Quaternion.LookRotation(initialHeadDirection);

        // Trigger head created event
        if (!isPosingForTitleScreen)
        {
            main.HandleHeadCreated(head);
        }

        // Tail
        GameObject tail = GameObject.CreatePrimitive(PrimitiveType.Sphere);

        Destroy(tail.GetComponent <MeshFilter>().mesh);
        tail.GetComponent <MeshFilter>().mesh = lowPolySphereMesh;
        tail.transform.parent     = transform;
        tail.transform.localScale = new Vector3(playerWidth, playerHeight, playerWidth);
        tail.GetComponent <Renderer>().material.color = bodyColor;
        tail.GetComponent <Renderer>().material.SetInt("_SmoothnessTextureChannel", 1);
        tail.GetComponent <Renderer>().material.SetFloat("_Glossiness", 0.93f);
        tail.GetComponent <Collider>().isTrigger = true; // Making a trigger to avoid bumping the head while moving
        tail.AddComponent <Rigidbody>();
        tail.AddComponent <Tail>();
        var tailRigidbody = tail.GetComponent <Rigidbody>();

        tailRigidbody.isKinematic = false;
        tailRigidbody.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionY;

        tail.GetComponent <Tail>().Init(main, turningPoints, tailLength++, speed, head, tailMinDistance);

        lastTail = tail;


        if (isPosingForTitleScreen)
        {
            // -- Setup Pose For Title Screen --
            Grow();
            Grow();
            Grow();

            // Position Head
            head.transform.position = new Vector3(-6, -0.6f, -6);
            head.transform.rotation = Quaternion.Euler(-6, 125, 0);

            var direction = head.transform.rotation * Vector3.forward;

            // Position Tail
            var t = lastTail.GetComponent <Tail>();
            var i = 1;
            while (t != null)
            {
                t.transform.position = head.transform.position + (i * -5 * direction);

                t = t.GetLeader().GetComponent <Tail>();
                i++;
            }
        }
    }
コード例 #28
0
        /*
         * 1. Двигаемся вперед пока не наткнемся на препятствие
         * 2. Сканируем, поворачиваем на направление с максимальной дистанцией
         * 2.1 Если повсюду препятствия, поворачиваемся на случайный угол(25-180). Переход к пункту 2.
         * 3. Двигаемся по новому направлению. Переход к п.1.
         */
        public BasicMetaCommandResult ProcessResponce(BasicResponce rsp)
        {
            switch (_status)
            {
            case Status.Start:
                Console.WriteLine(_status.ToString());
                var startCmd = new RangeScanCommand(MinScanDegree, MaxScanDegree, 200);
                _status = Status.WaitingForScanResults;
                return(new BasicMetaCommandResult(MetaCommandAction.Command, startCmd));

            case Status.StartScanning:
                var answer = rsp as AnswerResponce;
                if (answer != null && answer.Code == Commands.Move)
                {
                    Console.WriteLine(_status.ToString());
                    var cmd = new RangeScanCommand(MinScanDegree, MaxScanDegree, 200);
                    _status = Status.WaitingForScanResults;
                    return(new BasicMetaCommandResult(MetaCommandAction.Command, cmd));
                }
                break;

            case Status.WaitingForScanResults:
                var responce = rsp as RangeScanResponce;
                if (responce != null)
                {
                    Console.WriteLine(_status.ToString());
                    var degree = FindNewDirection(responce);
                    Console.WriteLine(" Selected degree: " + degree);
                    var rnd = new Random();
                    if (degree == null)
                    {
                        _turnDirection = (TurnDirection)rnd.Next((int)TurnDirection.Left, (int)TurnDirection.Right + 1);
                        _turnDegree    = (byte)rnd.Next(90, 180);
                        _status        = Status.StartTurning;
                        break;
                    }

                    if (degree == 0xFF)
                    {
                        _status = Status.StartMoving;
                        break;
                    }

                    if (degree > RangeScanCommand.CenterDegree)
                    {
                        _turnDirection = TurnDirection.Right;
                        _turnDegree    = (byte)(degree - RangeScanCommand.CenterDegree);
                    }
                    else
                    {
                        _turnDirection = TurnDirection.Left;
                        _turnDegree    = (byte)(RangeScanCommand.CenterDegree - degree);
                    }

                    _status = Status.StartTurning;
                }

                break;

            case Status.StartMoving:
                Console.WriteLine(_status.ToString());
                _status = Status.Moving;
                var moveCmd = new MoveCommand(MoveDirection.Forward, Speed, 500);
                return(new BasicMetaCommandResult(MetaCommandAction.Command, moveCmd));

            case Status.Moving:
                if (rsp == null)
                {
                    var statusCmd = new StatusCommand(RangeScanCommand.CenterDegree, 500);
                    return(new BasicMetaCommandResult(MetaCommandAction.Command, statusCmd));
                }

                Console.WriteLine(_status.ToString());
                var status = rsp as StatusResponce;
                if (status == null)
                {
                    break;
                }

                if (status.DistanceToObstacle < MinDistance)
                {
                    _status = Status.StartScanning;
                    var stopCmd = new MoveCommand(MoveDirection.Stopped, Speed, 500);
                    return(new BasicMetaCommandResult(MetaCommandAction.Command, stopCmd));
                }

                break;

            case Status.StartTurning:
                Console.WriteLine(_status.ToString());
                _status = Status.StartScanning;
                var turnCmd = new TurnCommand(_turnDirection, _turnDegree, 255, true, 500);
                return(new BasicMetaCommandResult(MetaCommandAction.Command, turnCmd));

            case Status.None:
                break;

            default:
                Console.WriteLine("ERROR! Unknown status!");
                break;
            }

            return(new BasicMetaCommandResult(MetaCommandAction.Idle));
        }