Exemple #1
0
        public void SetGame(Schotten2Game game)
        {
            var matchId = game.MatchId;

            lock (_gamesLock) {
                _games[matchId] = game;
            }
        }
        private Task AddGame(string matchId, string attackerId, string defenderId, GameState state)
        {
            var game = new Schotten2Game()
            {
                MatchId    = matchId,
                AttackerId = attackerId,
                DefenderId = defenderId,
                State      = state,
                CreatedAt  = DateTime.UtcNow,
                UpdatedAt  = DateTime.UtcNow,
            };

            _cache.SetGame(game);
            using (var scope = _scopeFactory.CreateScope()) {
                var dataContext = scope.ServiceProvider.GetRequiredService <DataContext>();
                dataContext.Schotten2Games.Add(game);
                dataContext.SaveChanges();
            }
            return(Task.CompletedTask);
        }
 public Task UpdateGame(Schotten2Game game)
 {
     game.UpdatedAt = DateTime.UtcNow;
     if (game.State.LastEvent == GameEvent.Destroy)
     {
         game.WinnerId = game.AttackerId;
     }
     if (game.State.LastEvent == GameEvent.Demolish)
     {
         game.WinnerId = game.AttackerId;
     }
     if (game.State.LastEvent == GameEvent.Defend)
     {
         game.WinnerId = game.DefenderId;
     }
     _cache.SetGame(game);
     using (var scope = _scopeFactory.CreateScope()) {
         var dataContext = scope.ServiceProvider.GetRequiredService <DataContext>();
         dataContext.Update(game);
         dataContext.SaveChanges();
     }
     return(Task.CompletedTask);
 }