Beispiel #1
0
        public async Task LeavePendingGame()
        {
            if (PendingGameService.PendingGames.Count == 0)
            {
                await ReplyAsync(ErrorView.NotFound());
            }
            else
            {
                PendingGame game = PendingGameService.PendingGames.FirstOrDefault();
                IUser       user = game.Users.FirstOrDefault(u => u.Id == Context.User.Id);
                if (game.Active)
                {
                    _game.RemoveUserFromPlay(user);
                    await _game.NotifyPlayerLeft(Context.User);
                }
                else
                {
                    game.Users.Remove(user);
                    await ReplyAsync(InfoView.LeftLobby());

                    if (game.Users.Count == 0)
                    {
                        PendingGameService.PendingGames.Clear();
                        await ReplyAsync(InfoView.DeletedLobby());
                    }
                }
            }
        }
Beispiel #2
0
        public async Task <IActionResult> Create(PendingGameCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await userManager.GetUserAsync(User);

                if (user == null)
                {
                    return(View("NotFound"));
                }
                var uploadImage = new AmazonS3Bucket();

                string uniqueFileName = await uploadImage.UploadImage(model.Photo);

                var PendingGame = new PendingGame()
                {
                    Id          = model.Id,
                    Genres      = model.Genres,
                    Description = model.Description,
                    RelaseDate  = model.RelaseDate,
                    Rating      = model.Rating,
                    Name        = model.Name,
                    UserId      = user.Id,
                    PhotoUrl    = uniqueFileName
                };
                TempData["Added"] = "Thank you for adding a new game! It's now awaits aprroval by our team, once approved, you will get notified by an Email!";
                pendingGameRepository.AddGame(PendingGame);
                return(RedirectToAction("Games", "home"));
            }
            return(View());
        }
Beispiel #3
0
        private void StartGame(PendingGame game)
        {
            game.GameInfo.GameServerProcessCode = "LobbyQueueManager.StartGame";
            foreach (LobbyPlayerInfo playerInfo in game.TeamInfo.TeamPlayerInfo)
            {
                if (!playerInfo.IsNPCBot)
                {
                    LobbyServerConnection      player          = LobbyServer.GetPlayerByAccountId(playerInfo.AccountId);
                    GameAssignmentNotification assNotification = new GameAssignmentNotification
                    {
                        GameInfo          = game.GameInfo,
                        GameResult        = GameResult.NoResult,
                        GameplayOverrides = DummyLobbyData.CreateLobbyGameplayOverrides(),
                        PlayerInfo        = player.GetLobbyPlayerInfo().Clone(),
                        Reconnection      = false,
                        Observer          = false
                    };
                    assNotification.PlayerInfo.ControllingPlayerId = 0;
                    player.SendMessage(assNotification);;
                }
            }
            game.GameStatus = GameStatus.Launching; // Put in wait state until game server starts
            game.SendNotification();

            new Task(() => {
                //GameManagerHolder.CreateGameManager(game.GameInfo, game.TeamInfo, game.PlayerSessionTokens); // Launch new game
                game.GameStatus = GameStatus.Launched; // Put in wait state until game server starts
                game.SendNotification();

                PendingGames.Remove(game);
            }).Start();
        }
Beispiel #4
0
        public async Task CreateChannels(SocketCommandContext context, PendingGame pendingGame)
        {
            SocketGuild guild = GetGuildByContext(context);

            DayChannel = await CreatePrivateGroupTextChannel(
                guild,
                GameElement.Channel.Public(),
                GameElement.ChannelDescription.Public());

            NightChannel = await CreatePrivateGroupTextChannel(
                guild,
                GameElement.Channel.Private(),
                GameElement.ChannelDescription.Private(ActiveGame.Uninformed.ToList()));

            CommandChannel = await CreatePrivateGroupTextChannel(
                guild,
                GameElement.Channel.Command(),
                string.Empty);

            GameChannels = new List <GameChannel>(new[]
            {
                new GameChannel(DayChannel, new [] { "excommunicate" }),
                new GameChannel(NightChannel, new [] { "sacrifice" }),
                new GameChannel(CommandChannel, new [] { "start", "kill", "kick", "signs" })
            });
        }
Beispiel #5
0
        public static Embed Info(PendingGame game)
        {
            IEnumerable <string> description = new[] {
                $"Attar has asked the broker to sell all of his {GameConfiguration.NumberOfRounds} {game.Collectable.ItemName}s. If he succeeds he'll get a bonus.",
                "Broker invites interested collectors to join free of charge.",
                $"You the {game.Collectable.Title}, who is missing {GameConfiguration.RoundsToVictory} {game.Collectable.ItemName}s from their most prized collection attend the auction with a budget of {GameConfiguration.GameCoins} coins.",
                $"Broker will auction {game.Collectable.ItemName}s one by one hoping to earn the bonus.",
            };

            IEnumerable <string> rules = new[]
            {
                $"You have {GameConfiguration.GameCoins} coins to spend.",
                $"Purchase {GameConfiguration.RoundsToVictory} {game.Collectable.ItemName}s and complete your collection.",
                "Each round make a better offer to secure the purchase.",
                $"Minimum offer is {GameConfiguration.MinimumBet} coins.",
                "You're unaware of other buyer offerings.",
                "Buyer is determined after the first offer.",
                "If your offer results in a tie, add coins to your initial offer.",
                "If a tie can't be broken, one who was faster to make the initial offer wins the tie."
            }.Select(s => $" -  {s}");

            string reward = "If you complete your collection you keep the coins you didn't spend.";

            return(new EmbedBuilder()
                   .WithTitle($"{game.Collectable.EmoteName}   A U C T I O N    G A M E   {game.Collectable.EmoteName}")
                   .WithDescription(string.Join("\n\n", description))
                   .AddField("# Rules", string.Join("\n", rules))
                   .AddField("# Reward", reward)
                   .WithColor(Color.Gold)
                   .Build());
        }
Beispiel #6
0
 public async Task InitialiseGame(SocketCommandContext context, PendingGame pendingGame)
 {
     ActiveGame = new GameObject(pendingGame.Users.ToList());
     await CreateChannels(context, pendingGame);
     await SendGameRules();
     await InitiateReadyPoll();
     await UnlockChannelForUsers(DayChannel, ActiveGame.Players.Select(p => p.User));
 }
Beispiel #7
0
 public void AddPending(PendingGame game)
 {
     if (game == null)
     {
         throw new ArgumentNullException(nameof(game));
     }
     pendingGames.Add(game);
     logger.Info($"Added pending game.", context: $"{game.GameId}:{game.UserName}");
 }
Beispiel #8
0
 public async Task CreatePendingGame()
 {
     if (!(await CanPayCostOfEntry(Context.User.Id)))
     {
         await ReplyAsync(ErrorView.NotEnoughFunds());
     }
     else if (PendingGameService.PendingGames.Any())
     {
         await ReplyAsync(ErrorView.MultipleGames());
     }
     else
     {
         PendingGame game = new PendingGame(Context.User);
         PendingGameService.PendingGames.Add(game);
         await ReplyAsync(InfoView.LobbyCreated(game.Id));
     }
 }
Beispiel #9
0
        public async Task CreateOrStartGameAsync(IUser commandIssuerUser, IUser referencedUser, string channelName)
        {
            #region Validation

            if (_module == null)
            {
                throw new ArgumentNullException($"{nameof(GameService)} requires control of {nameof(InteractiveBase<SocketCommandContext>)} module.");
            }

            if (IsUserInActiveGame(commandIssuerUser))
            {
                await commandIssuerUser.SendMessageAsync("You can't play two games at the same time.");

                return;
            }

            if (IsUserInActiveGame(referencedUser))
            {
                await commandIssuerUser.SendMessageAsync($"{referencedUser.Username} is already playing the game with another user.");

                return;
            }

            #endregion

            Optional <PendingGame> pendingGame = TryFindPendingGame(commandIssuerUser, referencedUser);

            if (pendingGame.IsSpecified)
            {
                try
                {
                    await StartAsync(pendingGame.Value);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    PendingGames.Remove(pendingGame.Value);
                }
            }
            else
            {
                PendingGame game = CreatePendingGame(commandIssuerUser, referencedUser);
                await Task.WhenAll(new[]
Beispiel #10
0
 public async Task PlayersInGameLobby()
 {
     if (PendingGameService.PendingGames.Count == 0)
     {
         await ReplyAsync(ErrorView.NotFound());
     }
     else
     {
         PendingGame game = PendingGameService.PendingGames.FirstOrDefault();
         if (game.Users.Any())
         {
             string message = string.Join(", ", game.Users.Select(u => MentionUtils.MentionUser(u.Id)));
             await ReplyAsync(message);
         }
         else
         {
             await ReplyAsync("Game lobby is empty.");
         }
     }
 }
Beispiel #11
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));
                    }
                }
            }
        }