コード例 #1
0
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='id'>
 /// </param>
 /// <param name='model'>
 /// </param>
 public static object Accepted(this IGame operations, string id, GameAcceptedModel model)
 {
     return(operations.AcceptedAsync(id, model).GetAwaiter().GetResult());
 }
コード例 #2
0
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='id'>
 /// </param>
 /// <param name='model'>
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <object> AcceptedAsync(this IGame operations, string id, GameAcceptedModel model, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.AcceptedWithHttpMessagesAsync(id, model, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
コード例 #3
0
        public async Task <IHttpActionResult> Accepted(string id, GameAcceptedModel model)
        {
            GameModel game = await _gameService.GetByIdAsync(id);

            if (game == null)
            {
                return(NotFound());
            }
            if (game.Status != GameStatus.Requesting)
            {
                return(BadRequest("Game status must be requesting"));
            }
            // get castles
            List <PositionModel> curList = new List <PositionModel>();
            List <PositionModel> result  = await GetNearByPlaces(curList, game.Position.Lat, game.Position.Lng, string.Empty);

            if (result == null)
            {
                return(InternalServerError(new Exception("Can not contact to map service")));
            }
            if (result.Count < 20)
            {
                curList = new List <PositionModel>();
                result  = await GetNearByPlaces(curList, game.Position.Lat, game.Position.Lng, string.Empty, 0, 1000);
            }
            if (result.Count < 20)
            {
                return(InternalServerError(new Exception("Error.NotEnoughVincityPlaceToPlay")));
            }



            var opponentArmySetting = game.SelfPlaying
                ? await GetOpponentArmySettingForSelfPlayingGame(game) : model.ArmySetting;

            await _gameService.SetOpponentArmySettingAsync(id, opponentArmySetting);

            game.OpponentArmySetting = opponentArmySetting;
            var castlesData = game.SelfPlaying ?
                              await GenerateCastleForSelfPlayingGame(result, game) :
                              await GenerateCastleForNormalGame(result, game);

            // get user info & accept game
            string userId = User.Identity.GetUserId();

            if (game.CreatedBy != userId)
            {
                UserDto opponent = await _userService.GetByIdAsync(userId);

                if (opponent == null)
                {
                    return(Unauthorized());
                }
                if (opponent.Heroes == null || opponent.Heroes.Count == 0)
                {
                    return(NotFound());
                }
                game.OpponentId     = opponent.Id;
                game.OpponentHeroId = opponent.Heroes[0].Id;
                await _gameService.AcceptedAsync(id, userId, game.OpponentHeroId);
            }
            else
            {
                if (!game.SelfPlaying)
                {
                    return(BadRequest("This game is not self-playing mode"));
                }
                await _gameService.AcceptedSelfPlayingGameAsync(id);
            }
            // save castle
            await _gameService.GenerateCastlesAsync(id, castlesData);

            return(Ok(game.Id));
        }