Exemplo n.º 1
0
        private async Task DecrementDieFromPlayer(GamePlayer player, int penalty)
        {
            player.NumberOfDice -= penalty;
            player.CurrentGamePlayerRound.Penalty = penalty;

            var game = await GetGameAsync(GameState.InProgress);

            if (player.NumberOfDice < 0)
            {
                player.NumberOfDice = 0;
            }

            if (player.NumberOfDice <= 0)
            {
                player.CurrentGamePlayerRound.IsEliminated = true;

                await SendMessageAsync($":wood::axe: {player.Player.Nickname} was cut down :wood::axe:");

                var deathrattle = _db.Rattles.SingleOrDefault(x => x.Username == player.Player.Username);
                if (deathrattle != null)
                {
                    await SendMessageAsync(deathrattle.Deathrattle);
                }

                if (game.CanCallExactToJoinAgain)
                {
                    if (_perudoGameService.GetGamePlayers(game).Where(x => x.NumberOfDice > 0).Count() > 2)
                    {
                        if (player.GhostAttemptsLeft != -1)
                        {
                            player.GhostAttemptsLeft = 3;
                            _db.SaveChanges();
                            await SendMessageAsync($":hourglass::hourglass: {GetUserNickname(player.Player.Username)} you have `3` attempts at an `!exact` call to win your way back into the game (3+ players).");
                        }
                    }
                }
            }

            if (player.NumberOfDice == 1 && game.Palifico)
            {
                game.NextRoundIsPalifico = true;
            }
            else
            {
                game.NextRoundIsPalifico = false;
            }
            _db.SaveChanges();

            var gameService = new PerudoGameService(_db);
            await gameService.UpdateGamePlayerRanksAsync(game.Id);
        }
Exemplo n.º 2
0
        public async Task UpdateRanksAsync(int gameId)
        {
            var gamesWithGamePlayerRounds =
                _db.Rounds.AsQueryable()
                .Where(r => r.GamePlayerRounds.Any())
                .Where(r => r.Game.State == 3)
                .Where(r => r.GameId == gameId || gameId == 0)
                .Select(r => r.Game)
                .Distinct()
                .ToList();

            var perudoGameService = new PerudoGameService(_db);

            await Context.Channel.SendMessageAsync("Updating ranks for games with GamePlayerRounds...");

            foreach (var game in gamesWithGamePlayerRounds)
            {
                Console.WriteLine($"Updating ranks for game {game.Id}");
                await perudoGameService.UpdateGamePlayerRanksAsync(game.Id);
            }

            await Context.Channel.SendMessageAsync("Done.");
        }
Exemplo n.º 3
0
 public ReactionCommands(GameBotDbContext db)
 {
     _db = db;
     _perudoGameService = new PerudoGameService(_db);
 }
Exemplo n.º 4
0
 public Commands()
 {
     //TODO: Let DI handle instantiation
     _db = new GameBotDbContext();
     _perudoGameService = new PerudoGameService(_db);
 }
Exemplo n.º 5
0
 public void Setup()
 {
     _factory = new GameBotDbContextFactory();
     _context = _factory.CreateContext();
     _service = new PerudoGameService(_context);
 }