コード例 #1
0
        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)));
        }
コード例 #2
0
        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));
        }