Beispiel #1
0
        /// <summary>
        ///     Updates catcheable and nearby Pokemons + Pokestops.
        ///     We're using a single method so that we don't need two separate calls to the server, making things faster.
        /// </summary>
        /// <returns></returns>
        private static async Task UpdateMapObjects()
        {
            // Get all map objects from server
            var mapObjects = await GetMapObjects(Geoposition);

            _lastUpdate = DateTime.Now;

            // update catchable pokemons
            var newCatchablePokemons = mapObjects.Item1.MapCells.SelectMany(x => x.CatchablePokemons).Select(item => new MapPokemonWrapper(item)).ToArray();

            Logger.Write($"Found {newCatchablePokemons.Length} catchable pokemons");
            CatchablePokemons.UpdateWith(newCatchablePokemons, x => x,
                                         (x, y) => x.EncounterId == y.EncounterId);

            // update nearby pokemons
            var newNearByPokemons = mapObjects.Item1.MapCells.SelectMany(x => x.NearbyPokemons).ToArray();

            Logger.Write($"Found {newNearByPokemons.Length} nearby pokemons");
            // for this collection the ordering is important, so we follow a slightly different update mechanism
            NearbyPokemons.UpdateByIndexWith(newNearByPokemons, x => new NearbyPokemonWrapper(x));

            // update poke stops on map (gyms are ignored for now)
            var newPokeStops = mapObjects.Item1.MapCells
                               .SelectMany(x => x.Forts)
                               .Where(x => x.Type == FortType.Checkpoint)
                               .ToArray();

            Logger.Write($"Found {newPokeStops.Length} nearby PokeStops");
            NearbyPokestops.UpdateWith(newPokeStops, x => new FortDataWrapper(x), (x, y) => x.Id == y.Id);

            // Update LuredPokemon
            var newLuredPokemon = newPokeStops.Where(item => item.LureInfo != null).Select(item => new LuredPokemon(item.LureInfo, item.Latitude, item.Longitude)).ToArray();

            Logger.Write($"Found {newLuredPokemon.Length} lured Pokemon");
            LuredPokemons.UpdateByIndexWith(newLuredPokemon, x => x);
            Logger.Write("Finished updating map objects");

            // Update Hatched Eggs
            var hatchedEggResponse = mapObjects.Item2;

            if (hatchedEggResponse.Success)
            {
                //OnEggHatched?.Invoke(null, hatchedEggResponse);
                for (var i = 0; i < hatchedEggResponse.PokemonId.Count; i++)
                {
                    Logger.Write("Egg Hatched");
                    var currentPokemonId = PokemonsInventory.First(item => item.Id == hatchedEggResponse.PokemonId[i]).PokemonId;
                    await new MessageDialog(string.Format(Resources.CodeResources.GetString("EggHatchMessage"), currentPokemonId, hatchedEggResponse.StardustAwarded[i], hatchedEggResponse.CandyAwarded[i], hatchedEggResponse.ExperienceAwarded[i])).ShowAsyncQueue();
                }
            }
        }
Beispiel #2
0
        /// <summary>
        ///     Updates catcheable and nearby Pokemons + Pokestops.
        ///     We're using a single method so that we don't need two separate calls to the server, making things faster.
        /// </summary>
        /// <returns></returns>
        private static async Task UpdateMapObjects()
        {
            // Get all map objects from server
            var mapObjects = await GetMapObjects(Geoposition);

            _lastUpdate = DateTime.Now;

            // update catchable pokemons
            var newCatchablePokemons = mapObjects.Item1.MapCells.SelectMany(x => x.CatchablePokemons).Select(item => new MapPokemonWrapper(item)).ToArray();

            Logger.Write($"Found {newCatchablePokemons.Length} catchable pokemons");
            CatchablePokemons.UpdateWith(newCatchablePokemons, x => x,
                                         (x, y) => x.EncounterId == y.EncounterId);

            // update nearby pokemons
            var newNearByPokemons = mapObjects.Item1.MapCells.SelectMany(x => x.NearbyPokemons).ToArray();

            Logger.Write($"Found {newNearByPokemons.Length} nearby pokemons");
            // for this collection the ordering is important, so we follow a slightly different update mechanism
            NearbyPokemons.UpdateByIndexWith(newNearByPokemons, x => new NearbyPokemonWrapper(x));

            // update poke stops on map (gyms are ignored for now)
            var newPokeStops = mapObjects.Item1.MapCells
                               .SelectMany(x => x.Forts)
                               .Where(x => x.Type == FortType.Checkpoint)
                               .ToArray();

            Logger.Write($"Found {newPokeStops.Length} nearby PokeStops");
            NearbyPokestops.UpdateWith(newPokeStops, x => new FortDataWrapper(x), (x, y) => x.Id == y.Id);

            // Update LuredPokemon
            var newLuredPokemon = newPokeStops.Where(item => item.LureInfo != null).Select(item => new LuredPokemon(item.LureInfo, item.Latitude, item.Longitude)).ToArray();

            Logger.Write($"Found {newLuredPokemon.Length} lured Pokemon");
            LuredPokemons.UpdateByIndexWith(newLuredPokemon, x => x);
            Logger.Write("Finished updating map objects");
        }
Beispiel #3
0
        /// <summary>
        ///     Updates catcheable and nearby Pokemons + Pokestops.
        ///     We're using a single method so that we don't need two separate calls to the server, making things faster.
        /// </summary>
        /// <returns></returns>
        private static async Task UpdateMapObjects()
        {
            // Get all map objects from server
            var mapObjects = await GetMapObjects(Geoposition);

            _lastUpdate = DateTime.Now;

            // update catchable pokemons
            var newCatchablePokemons = mapObjects.Item1.MapCells.SelectMany(x => x.CatchablePokemons).Select(item => new MapPokemonWrapper(item)).ToArray();

            Logger.Write($"Found {newCatchablePokemons.Length} catchable pokemons");
            CatchablePokemons.UpdateWith(newCatchablePokemons, x => x,
                                         (x, y) => x.EncounterId == y.EncounterId);

            // update nearby pokemons
            var newNearByPokemons = mapObjects.Item1.MapCells.SelectMany(x => x.NearbyPokemons).ToArray();

            Logger.Write($"Found {newNearByPokemons.Length} nearby pokemons");
            // for this collection the ordering is important, so we follow a slightly different update mechanism
            NearbyPokemons.UpdateByIndexWith(newNearByPokemons, x => new NearbyPokemonWrapper(x));

            // update poke stops on map
            var newPokeStops = mapObjects.Item1.MapCells
                               .SelectMany(x => x.Forts)
                               .Where(x => x.Type == FortType.Checkpoint)
                               .ToArray();

            Logger.Write($"Found {newPokeStops.Length} nearby PokeStops");
            NearbyPokestops.UpdateWith(newPokeStops, x => new FortDataWrapper(x), (x, y) => x.Id == y.Id);

            // update gyms on map
            var newGyms = mapObjects.Item1.MapCells
                          .SelectMany(x => x.Forts)
                          .Where(x => x.Type == FortType.Gym)
                          .ToArray();

            Logger.Write($"Found {newGyms.Length} nearby Gyms");
            // For now, we do not show the gyms on the map, as they are not complete yet. Code remains, so we can still work on it.
            //NearbyGyms.UpdateWith(newGyms, x => new FortDataWrapper(x), (x, y) => x.Id == y.Id);

            // Update LuredPokemon
            var newLuredPokemon = newPokeStops.Where(item => item.LureInfo != null).Select(item => new LuredPokemon(item.LureInfo, item.Latitude, item.Longitude)).ToArray();

            Logger.Write($"Found {newLuredPokemon.Length} lured Pokemon");
            LuredPokemons.UpdateByIndexWith(newLuredPokemon, x => x);
            Logger.Write("Finished updating map objects");

            // Update Hatched Eggs
            var hatchedEggResponse = mapObjects.Item2;

            if (hatchedEggResponse.Success)
            {
                //OnEggHatched?.Invoke(null, hatchedEggResponse);

                for (var i = 0; i < hatchedEggResponse.PokemonId.Count; i++)
                {
                    Logger.Write("Egg Hatched");
                    await UpdateInventory();

                    //TODO: Fix hatching of more than one pokemon at a time
                    var currentPokemon = PokemonsInventory
                                         .FirstOrDefault(item => item.Id == hatchedEggResponse.PokemonId[i]);

                    if (currentPokemon == null)
                    {
                        continue;
                    }

                    await
                    new MessageDialog(string.Format(
                                          Resources.CodeResources.GetString("EggHatchMessage"),
                                          currentPokemon.PokemonId, hatchedEggResponse.StardustAwarded[i], hatchedEggResponse.CandyAwarded[i],
                                          hatchedEggResponse.ExperienceAwarded[i])).ShowAsyncQueue();

                    NavigationHelper.NavigationState["CurrentPokemon"] =
                        new PokemonDataWrapper(currentPokemon);
                    BootStrapper.Current.NavigationService.Navigate(typeof(PokemonDetailPage));
                }
            }
        }