Esempio n. 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)).Item1;

            // update catchable pokemons
            var newCatchablePokemons = mapObjects.MapCells.SelectMany(x => x.CatchablePokemons).ToArray();

            Logger.Write($"Found {newCatchablePokemons.Length} catchable pokemons");
            if (newCatchablePokemons.Length != CatchablePokemons.Count)
            {
                MapPokemonUpdated?.Invoke(null, null);
            }
            CatchablePokemons.UpdateWith(newCatchablePokemons, x => new MapPokemonWrapper(x), (x, y) => x.EncounterId == y.EncounterId);

            // update nearby pokemons
            var newNearByPokemons = mapObjects.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.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);

            Logger.Write("Finished updating map objects");
        }
Esempio n. 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)).Item1;
            // Replace data with the new ones
            var catchableTmp = new List <MapPokemon>(mapObjects.MapCells.SelectMany(i => i.CatchablePokemons));

            Logger.Write($"Found {catchableTmp.Count} catchable pokemons");
            if (catchableTmp.Count != CatchablePokemons.Count)
            {
                MapPokemonUpdated?.Invoke(null, null);
            }
            CatchablePokemons.Clear();
            foreach (var pokemon in catchableTmp)
            {
                CatchablePokemons.Add(new MapPokemonWrapper(pokemon));
            }
            var nearbyTmp = new List <NearbyPokemon>(mapObjects.MapCells.SelectMany(i => i.NearbyPokemons));

            Logger.Write($"Found {nearbyTmp.Count} nearby pokemons");
            NearbyPokemons.Clear();
            foreach (var pokemon in nearbyTmp)
            {
                NearbyPokemons.Add(pokemon);
            }
            // Retrieves PokeStops but not Gyms
            var pokeStopsTmp =
                new List <FortData>(mapObjects.MapCells.SelectMany(i => i.Forts)
                                    .Where(i => i.Type == FortType.Checkpoint));

            Logger.Write($"Found {pokeStopsTmp.Count} nearby PokeStops");
            NearbyPokestops.Clear();
            foreach (var pokestop in pokeStopsTmp)
            {
                NearbyPokestops.Add(new FortDataWrapper(pokestop));
            }
            Logger.Write("Finished updating map objects");
        }