using ODMO.Commons.DTOs.Config; using ODMO.Commons.DTOs.Config.Events; using ODMO.Commons.Interfaces; using Microsoft.EntityFrameworkCore; namespace ODMO.Infrastructure.Repositories.Config { public class ConfigQueriesRepository : IConfigQueriesRepository { private readonly DatabaseContext _context; public ConfigQueriesRepository(DatabaseContext context) { _context = context; } public async Task> GetMapMobsConfigAsync(long configId) { return await _context.MobConfig .AsNoTracking() .AsSplitQuery() .Include(y => y.Location) .Include(y => y.ExpReward) .Include(y => y.DropReward) .ThenInclude(z => z.Drops) .Include(y => y.DropReward) .ThenInclude(z => z.BitsDrop) .Where(x => x.GameMapConfigId == configId) .ToListAsync(); } public async Task> GetGameMapConfigsAsync() { return await _context.MapConfig .AsSplitQuery() .AsNoTracking() .Include(x => x.Mobs) .ThenInclude(y => y.Location) .Include(x => x.Mobs) .ThenInclude(y => y.ExpReward) .Include(x => x.Mobs) .ThenInclude(y => y.DropReward) .ThenInclude(z => z.Drops) .Include(x => x.Mobs) .ThenInclude(y => y.DropReward) .ThenInclude(z => z.BitsDrop) .ToListAsync(); } public async Task GetGameMapConfigByMapIdAsync(int mapId) { return await _context.MapConfig .AsNoTracking() .FirstOrDefaultAsync(x => x.MapId == mapId); } public async Task GetGameMapConfigByIdAsync(long id) { return await _context.MapConfig .AsNoTracking() .FirstOrDefaultAsync(x => x.Id == id); } public async Task> GetMapMobsByIdAsync(int mapId) { var mapDto = await _context.MapConfig.FirstOrDefaultAsync(x => x.MapId == mapId); if (mapDto != null) { return await _context.MobConfig .AsNoTracking() .AsSplitQuery() .Include(y => y.Location) .Include(y => y.ExpReward) .Include(y => y.DropReward) .ThenInclude(z => z.Drops) .Include(y => y.DropReward) .ThenInclude(z => z.BitsDrop) .Where(x => x.GameMapConfigId == mapDto.Id) .ToListAsync(); } else return default; } public async Task> GetEventsConfigAsync() { return await _context.EventConfig .AsNoTracking() .AsSplitQuery() .Include(x => x.EventMaps) .ThenInclude(y => y.Map) .Include(x => x.EventMaps) .ThenInclude(y => y.Mobs) .ThenInclude(y => y.Location) .Include(x => x.EventMaps) .ThenInclude(y => y.Mobs) .ThenInclude(y => y.ExpReward) .Include(x => x.EventMaps) .ThenInclude(y => y.Mobs) .ThenInclude(y => y.DropReward) .ThenInclude(z => z.Drops) .Include(x => x.EventMaps) .ThenInclude(y => y.Mobs) .ThenInclude(y => y.DropReward) .ThenInclude(z => z.BitsDrop) .ToListAsync(); } public async Task> GetEventsConfigAsync(bool isEnabled) { return await _context.EventConfig .AsNoTracking() .AsSplitQuery() .Include(x => x.EventMaps) .ThenInclude(y => y.Map) .Include(x => x.EventMaps) .ThenInclude(y => y.Mobs) .ThenInclude(y => y.Location) .Include(x => x.EventMaps) .ThenInclude(y => y.Mobs) .ThenInclude(y => y.ExpReward) .Include(x => x.EventMaps) .ThenInclude(y => y.Mobs) .ThenInclude(y => y.DropReward) .ThenInclude(z => z.Drops) .Include(x => x.EventMaps) .ThenInclude(y => y.Mobs) .ThenInclude(y => y.DropReward) .ThenInclude(z => z.BitsDrop) .Where(x => x.IsEnabled == isEnabled) .ToListAsync(); } } }