Пример #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).ToArray();

            Logger.Write($"Found {newCatchablePokemons.Length} catchable pokemons");
            CatchablePokemons.UpdateWith(newCatchablePokemons, x => new MapPokemonWrapper(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);

            Logger.Write("Finished updating map objects");
        }
Пример #2
0
 /// <summary>
 /// When new items are added to the Pokedex, reset the Nearby Pokemon so their state can be re-run.
 /// </summary>
 /// <remarks>
 /// This exists because the Nearby Pokemon are Map objects, and are loaded before Inventory. If you don't do this,
 /// the first Nearby items are always shown as "new to the Pokedex" until they disappear, regardless of if they are
 /// ACTUALLY new.
 /// </remarks>
 private static void PokedexInventory_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     if (e.Action == NotifyCollectionChangedAction.Add)
     {
         // advancedrei: This is a total order-of-operations hack.
         var nearby = NearbyPokemons.ToList();
         NearbyPokemons.Clear();
         NearbyPokemons.AddRange(nearby);
     }
 }
Пример #3
0
 /// <summary>
 /// Logs the user out by clearing data and timers
 /// </summary>
 public static void DoLogout()
 {
     // Clear stored token
     SettingsService.Instance.PtcAuthToken    = null;
     SettingsService.Instance.GoogleAuthToken = null;
     _mapUpdateTimer?.Stop();
     _mapUpdateTimer = null;
     _geolocator     = null;
     CatchablePokemons.Clear();
     NearbyPokemons.Clear();
     NearbyPokestops.Clear();
 }
Пример #4
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();
                }
            }
        }
Пример #5
0
 /// <summary>
 ///     Logs the user out by clearing data and timers
 /// </summary>
 public static void DoLogout()
 {
     // Clear stored token
     SettingsService.Instance.AccessTokenString = null;
     if (!SettingsService.Instance.RememberLoginData)
     {
         SettingsService.Instance.UserCredentials = null;
     }
     _heartbeat?.StopDispatcher();
     if (_geolocator != null)
     {
         _geolocator.PositionChanged -= GeolocatorOnPositionChanged;
     }
     _geolocator = null;
     _lastGeopositionMapObjectsRequest = null;
     CatchablePokemons?.Clear();
     NearbyPokemons?.Clear();
     NearbyPokestops?.Clear();
 }
Пример #6
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");
        }
Пример #7
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));
                }
            }
        }