Example #1
0
        public async Task SimulateRound()
        {
            var countryList = await _dbContext.Countries
                              .Include(c => c.Buildings).ThenInclude(b => b.BuildingData)
                              .Include(c => c.Upgrades).ThenInclude(u => u.UpgradeData)
                              .Include(c => c.Units).ThenInclude(u => u.UnitData)
                              .Include(c => c.Resources).ThenInclude(r => r.ResourceData)
                              .ToListAsync();

            // változások az egyes országokban
            foreach (var country in countryList)
            {
                GeneratePearlIncome(country);
                GenerateCoralIncome(country);
                GenerateStoneIncome(country);
                PaySoldiers(country);
                FeedSoldiers(country);
                ProceedWithUpgrade(country);
                ProceedWithBuilding(country);
            }

            //Harc
            var BattleIDs = await _dbContext.Battles.Select(b => b.ID).ToListAsync();

            foreach (var battleID in BattleIDs)
            {
                await _battleService.CommenceBattle(battleID);
            }
            //felfedezés
            var explorationIDs = await _dbContext.Explorations.Select(e => e.ID).ToListAsync();

            foreach (var expID in explorationIDs)
            {
                await _battleService.SimulateExploration(expID);
            }

            //pont számolás
            foreach (var country in countryList)
            {
                country.Score = country.Buildings.Sum(b => b.Count * 50) + country.Upgrades.Sum(u => u.Progress > 0 ? 0 : 100) + country.Population + country.Units.Sum(u => u.UnitData.PointValue * u.Count);
            }

            //csaták törlése
            _dbContext.AttackingUnits.RemoveRange(_dbContext.AttackingUnits);
            _dbContext.Battles.RemoveRange(_dbContext.Battles);
            _dbContext.Explorations.RemoveRange(_dbContext.Explorations);
            _dbContext.Round.SingleOrDefault().RoundNumber++;


            await _dbContext.SaveChangesAsync();



            //Klienseken frissítés
            await _roundHubContext.Clients.All.RefreshInfo();
        }