Ejemplo n.º 1
0
        public async Task <BattlesDto> GetBattlesDto(int userId)
        {
            var player = await _dbContext.Players
                         .Include(p => p.Army)
                         .ThenInclude(a => a.Squads)
                         .ThenInclude(s => s.SquadUnits)
                         .ThenInclude(su => su.Unit)
                         .Include(p => p.Army)
                         .ThenInclude(a => a.Squads)
                         .ThenInclude(s => s.City)
                         .Include(p => p.City)
                         .Where(p => p.UserId == userId)
                         .SingleOrDefaultAsync();

            var battlesDto = new BattlesDto {
                Battles = new List <BattleDto>()
            };

            var squads = player.Army.Squads.ToList();

            var city = player.City;

            foreach (var squad in squads)
            {
                if (squad.CityId != city.Id && squad.CityId != null)
                {
                    battlesDto.Battles.Add(new BattleDto
                    {
                        CityName       = squad.City.Name,
                        AttackingUnits = _squadService.GetUnitListDto(squad)
                    });
                }
            }

            return(battlesDto);
        }
Ejemplo n.º 2
0
        public async Task <PlayerDto> GetPlayerDto(int userId)
        {
            var player = await _dbContext.Players
                         .Include(p => p.Game)
                         .Include(p => p.Stock)
                         .Include(p => p.Laboratory)
                         .ThenInclude(l => l.LaboratoryInnovations)
                         .ThenInclude(li => li.Innovation)
                         .Include(p => p.Army)
                         .ThenInclude(a => a.Squads)
                         .ThenInclude(s => s.SquadUnits)
                         .ThenInclude(su => su.Unit)
                         .Include(p => p.City)
                         .ThenInclude(c => c.CityBuildings)
                         .ThenInclude(cb => cb.Building)
                         .Include(p => p.City)
                         .ThenInclude(c => c.CurrentBuilding)
                         .Where(p => p.UserId == userId)
                         .SingleOrDefaultAsync();

            var playerDto = new PlayerDto
            {
                Turn = player.Game.Turn,
                Rank = await GetPlayerRank(player),
            };

            var flowController = player.City.CityBuildings
                                 .Where(cb => cb.Building.Type == BuildingTypes.FlowController)
                                 .SingleOrDefault();

            var quarry = player.City.CityBuildings
                         .Where(cb => cb.Building.Type == BuildingTypes.Quarry)
                         .SingleOrDefault();

            playerDto.Stock = _stockService.GetStockDto(player.Stock, flowController, quarry, player.Laboratory);

            playerDto.Buildings = _cityService.GetBuildingsDto(player.City);

            var squad = player.Army.Squads
                        .Where(s => s.CityId == player.City.Id)
                        .SingleOrDefault();

            playerDto.UnitsNumbers = _squadService.GetUnitListDto(squad);

            return(playerDto);
        }