public async Task UpdateGameState(int id) { var game = await _dbContext.Games .Include(g => g.Players) .ThenInclude(p => p.Incident) .Include(g => g.Players) .ThenInclude(p => p.Stock) .Include(g => g.Players) .ThenInclude(p => p.Laboratory) .ThenInclude(l => l.CurrentInnovation) .Include(g => g.Players) .ThenInclude(p => p.Laboratory) .ThenInclude(l => l.LaboratoryInnovations) .ThenInclude(li => li.Innovation) .Include(g => g.Players) .ThenInclude(p => p.City) .ThenInclude(c => c.CurrentBuilding) .Include(g => g.Players) .ThenInclude(p => p.City) .ThenInclude(c => c.CityBuildings) .ThenInclude(cb => cb.Building) .Include(g => g.Players) .ThenInclude(p => p.Army) .ThenInclude(a => a.Squads) .ThenInclude(s => s.SquadUnits) .ThenInclude(su => su.Unit) .Where(g => g.Id == id) .SingleOrDefaultAsync(); var incidents = await _dbContext.Incidents.ToListAsync(); if (game == null) { throw new NotFoundException($"{id} játék nem létezik."); } Random random = new Random(); var playerNumber = game.Players.Count(); var players = game.Players.OrderBy(_ => random.Next(playerNumber)).ToList(); foreach (var player in players) { if (random.Next(3) == 1) { var incidentNumber = random.Next(incidents.Count()); var incident = incidents.ElementAt(incidentNumber); player.IncidentId = incident.Id; } else { player.IncidentId = incidents.Count(); } } await _dbContext.SaveChangesAsync(); foreach (var player in players) { _playerService.UpdatePlayerIncident(player); } await _dbContext.SaveChangesAsync(); foreach (var player in players) { //Pearl Tax var flowController = player.City.CityBuildings .Where(cb => cb.Building.Type == BuildingTypes.FlowController) .SingleOrDefault(); await _stockService.Taxation(player.Stock, flowController, player.Laboratory); } foreach (var player in players) { //Coral Harvest var flowController = player.City.CityBuildings .Where(cb => cb.Building.Type == BuildingTypes.FlowController) .SingleOrDefault(); await _stockService.CoralHarvesting(player.Stock, flowController, player.Laboratory, player.Incident.Type); } foreach (var player in players) { //Stone Quarrying var quarry = player.City.CityBuildings .Where(cb => cb.Building.Type == BuildingTypes.Quarry) .SingleOrDefault(); await _stockService.Quarrying(player.Stock, quarry, player.Laboratory); } foreach (var player in players) { //Paying the army await _stockService.PayMercenary(player); } foreach (var player in players) { //Upkeeping the army await _stockService.UpkeepMercenary(player); } foreach (var player in players) { //Research continue if (player.Laboratory.CurrentInnovation != null) { await _currentInnovationService.UpdateCurrentInnovation(player.Laboratory, player.Laboratory.CurrentInnovation); } } foreach (var player in players) { //Building continue if (player.City.CurrentBuilding != null) { await _currentBuildingService.UpdateCurrentBuilding(player.City, player.City.CurrentBuilding); } } foreach (var player in players) { //Fight Battles await _armyService.FightBattles(player); } foreach (var player in players) { } foreach (var player in players) { //Return squads to defending army await _armyService.ReturnSquadsToBase(player); } foreach (var player in players) { //Calculate Points await _playerService.UpdatePlayer(player); } game.Turn++; await _dbContext.SaveChangesAsync(); await _hubContext.Clients.Group(game.Id.ToString()).SendAsync("RequestRefresh"); //await _hubContext.Clients.All.SendAsync("RequestRefresh"); }