public static OcrService GetOcrService(IConfigurationService configurationService, Hydro74000Context context) { IGymRepository gymRepository = new GymRepository(context); IRaidRepository raidRepository = new RaidRepository(context); var localizationService = new LocalizationService(); var gymService = new GymService(gymRepository, localizationService, configurationService); var raidbossService = new RaidbossService(); var fileWatcherService = new FileWatcherService(); var pokemonService = new PokemonService(raidbossService, localizationService, fileWatcherService); var raidService = new RaidService(raidRepository, gymService, pokemonService, raidbossService, localizationService); return(new OcrService(configurationService, gymService, pokemonService, raidService, localizationService)); }
public async Task <ServiceResponse> HatchSaveAsync(Type textResource, IGym gym, IPokemon pokemon, IRaidboss raidboss, int interactiveLimit) { var beforeSpawnTime = SystemClock.Instance.GetCurrentInstant().Minus(Duration.FromMinutes(90)).ToUnixTimeSeconds(); var raid = await RaidRepository.FindAsync(e => e.FortId == gym.Id && e.TimeSpawn > beforeSpawnTime); if (raid == null) { return(new ServiceResponse(false, LocalizationService.Get(textResource, "Raids_Errors_Hatch_NoEntryFound", gym.Name))); } raid.PokemonId = (short)raidboss.Id; await RaidRepository.SaveAsync(); return(new ServiceResponse(true, LocalizationService.Get(textResource, "Raids_Messages_BossHatched", pokemon.Name, gym.Name))); }
private async Task <ServiceResponse> AddSaveAsync(Type textResource, ZonedDateTime requestStartInUtc, DateTimeZone userZone, IGym gym, byte level, IPokemon pokemon, IRaidboss raidboss, TimeSpan timeSpan) { var utcNowAfterProcessing = SystemClock.Instance.GetCurrentInstant().InUtc(); var processingTime = utcNowAfterProcessing.Minus(requestStartInUtc); var durationMinusProcessing = Duration.FromTimeSpan(timeSpan).Minus(processingTime); var expiry = utcNowAfterProcessing.Plus(durationMinusProcessing).ToInstant(); // Create the raid entry var beforeSpawnTime = utcNowAfterProcessing.Minus(Duration.FromMinutes(105)).ToInstant().ToUnixTimeSeconds(); var raid = await RaidRepository.FindAsync(e => e.FortId == gym.Id && e.TimeSpawn > beforeSpawnTime); if (raid == null) { raid = RaidRepository.CreateInstance(); raid.ExternalId = ThreadLocalRandom.NextLong(); raid.FortId = gym.Id; RaidRepository.Add(raid); } string message; if (raidboss == null) { raid.Level = level; raid.TimeSpawn = (int)expiry.Minus(_eggDuration).ToUnixTimeSeconds(); raid.TimeBattle = (int)expiry.ToUnixTimeSeconds(); raid.TimeEnd = (int)expiry.Plus(_raidDuration).ToUnixTimeSeconds(); message = LocalizationService.Get(textResource, "Raids_Messages_EggAdded", level, gym.Name, FormatExpiry(expiry, userZone)); } else { raid.PokemonId = (short)raidboss.Id; raid.Level = level; raid.TimeSpawn = (int)expiry.Minus(Duration.FromMinutes(105)).ToUnixTimeSeconds(); raid.TimeBattle = (int)expiry.Minus(Duration.FromMinutes(45)).ToUnixTimeSeconds(); raid.TimeEnd = (int)expiry.ToUnixTimeSeconds(); message = LocalizationService.Get(textResource, "Raids_Messages_BossAdded", pokemon.Name, gym.Name, FormatExpiry(expiry, userZone)); } await RaidRepository.SaveAsync(); await GymService.UpdateGymAsync(gym); return(new ServiceResponse(true, message)); }
public async Task <ServiceResponse> GetRaidList(Type textResource, ZonedDateTime requestStartInUtc, DateTimeZone userZone, string pokemonNameOrLevel, FenceConfiguration[] fences, string orderType, int interactiveLimit, Func <RaidListInfo, string> formatResult) { var order = GetRaidListOrder(orderType); var startTime = Instant.FromDateTimeUtc(new DateTime(2018, 5, 1, 0, 0, 0).ToUniversalTime()).ToUnixTimeSeconds(); if (int.TryParse(pokemonNameOrLevel, out int raidLevel)) { if (raidLevel < 1) { return(new ServiceResponse <RaidListInfo>(false, LocalizationService.Get(textResource, "Raids_Errors_LevelToLow"), null)); } if (raidLevel > 5) { return(new ServiceResponse <RaidListInfo>(false, LocalizationService.Get(textResource, "Raids_Errors_LevelToHigh"), null)); } // Query Level var raids = await RaidRepository.FindAllWithGymsAsync(e => e.TimeSpawn > startTime && e.Level == raidLevel); return(await GetListResult(raidLevel, null, raids, order, formatResult)); } else { var pokemonResponse = await PokemonService.GetPokemonAndRaidbossAsync(textResource, pokemonNameOrLevel, interactiveLimit, (selectedPokemonName) => GetRaidList(textResource, requestStartInUtc, userZone, selectedPokemonName, fences, orderType, interactiveLimit, formatResult)); if (!pokemonResponse.IsSuccess) { return(pokemonResponse); } var pokemonAndRaidboss = pokemonResponse.Result; var raidboss = pokemonAndRaidboss.Raidboss; // Query Raidboss var raids = await RaidRepository.FindAllWithGymsAsync(e => e.TimeSpawn > startTime && e.PokemonId == raidboss.Id); return(await GetListResult(raidboss.Level, pokemonAndRaidboss, raids, order, formatResult)); } }