Пример #1
0
        private CommandResult ProcessDestinationCoordinate(Context context, Board board, Coordinate destinationCoordinate)
        {
            Coordinate currentCoordinate = context.Player.Coordinate;
            BoardExitDirection boardExitDirection = GetBoardExitDirection(currentCoordinate, destinationCoordinate);
            BoardExit boardExit = board.Exits.SingleOrDefault(arg => arg.Coordinate == currentCoordinate && arg.Direction == boardExitDirection);

            if (boardExit != null)
            {
                Board destinationBoard = context.GetBoardById(boardExit.DestinationBoardId);

                context.EnqueueCommand(new BoardChangeCommand(destinationBoard, boardExit.DestinationCoordinate));

                return CommandResult.Succeeded;
            }

            if (!board.CoordinateIntersects(destinationCoordinate))
            {
                return CommandResult.Failed;
            }

            ActorInstance targetActorInstance = board.ActorInstanceLayer[destinationCoordinate];

            if (targetActorInstance != null)
            {
                TouchDirection? touchDirection = GetTouchDirection(currentCoordinate, destinationCoordinate);

                if (touchDirection != null)
                {
                    context.RaiseEvent(targetActorInstance.OnTouchedByPlayer, new PlayerTouchedActorInstanceEvent(targetActorInstance, touchDirection.Value));
                }
            }

            return context.Player.ChangeLocation(context.CurrentBoard, destinationCoordinate) ? CommandResult.Succeeded : CommandResult.Failed;
        }