Ejemplo n.º 1
0
        public async Task JoinPendingGame()
        {
            if (!(await CanPayCostOfEntry(Context.User.Id)))
            {
                await ReplyAsync(ErrorView.NotEnoughFunds());
            }
            else if (PendingGameService.PendingGames.Count == 0)
            {
                await ReplyAsync(ErrorView.NotFound());
            }
            else if (PendingGameService.PendingGames.Any(g => g.Users.Any(u => u.Id == Context.User.Id)))
            {
                await ReplyAsync(ErrorView.AlreadyInLobby());
            }
            else
            {
                PendingGame game = PendingGameService.PendingGames.FirstOrDefault();
                if (game.Active)
                {
                    await ReplyAsync(ErrorView.InProgress());
                }
                else
                {
                    game.Users.Add(Context.User);
                    if (game.Users.Count == GameConfiguration.NumberOfPlayers)
                    {
                        game.Active = true;
                        await ReplyAsync(InfoView.GameStarting());

                        await _game.InitialiseGame(Context, game);
                    }
                    else
                    {
                        await ReplyAsync(InfoView.LobbyStatus(game.Users.Count));
                    }
                }
            }
        }