/// <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(); } } }
/// <summary> /// Updates inventory data /// </summary> public static async Task UpdateInventory() { // Get ALL the items var response = await GetInventory(); var fullInventory = response.InventoryDelta?.InventoryItems; // Update items ItemsInventory.AddRange(fullInventory.Where(item => item.InventoryItemData.Item != null) .GroupBy(item => item.InventoryItemData.Item) .Select(item => item.First().InventoryItemData.Item), true); CatchItemsInventory.AddRange( fullInventory.Where( item => item.InventoryItemData.Item != null && CatchItemIds.Contains(item.InventoryItemData.Item.ItemId)) .GroupBy(item => item.InventoryItemData.Item) .Select(item => item.First().InventoryItemData.Item), true); AppliedItems.AddRange( fullInventory .Where(item => item.InventoryItemData.AppliedItems != null) .SelectMany(item => item.InventoryItemData.AppliedItems.Item) .Select(item => new AppliedItemWrapper(item)), true); // Update incbuators IncubatorsInventory.AddRange(fullInventory.Where(item => item.InventoryItemData.EggIncubators != null) .SelectMany(item => item.InventoryItemData.EggIncubators.EggIncubator) .Where(item => item != null), true); // Update Pokedex PokedexInventory.AddRange(fullInventory.Where(item => item.InventoryItemData.PokedexEntry != null) .Select(item => item.InventoryItemData.PokedexEntry), true); // Update Pokemons PokemonsInventory.AddRange(fullInventory.Select(item => item.InventoryItemData.PokemonData) .Where(item => item != null && item.PokemonId > 0), true); EggsInventory.AddRange(fullInventory.Select(item => item.InventoryItemData.PokemonData) .Where(item => item != null && item.IsEgg), true); // Update candies CandyInventory.AddRange(from item in fullInventory where item.InventoryItemData?.Candy != null where item.InventoryItemData?.Candy.FamilyId != PokemonFamilyId.FamilyUnset group item by item.InventoryItemData?.Candy.FamilyId into family select new Candy { FamilyId = family.FirstOrDefault().InventoryItemData.Candy.FamilyId, Candy_ = family.FirstOrDefault().InventoryItemData.Candy.Candy_ }, true); }
/// <summary> /// Updates inventory data /// </summary> public static async Task UpdateInventory() { // Get ALL the items var fullInventory = (await GetInventory()).InventoryDelta.InventoryItems; // Update items var tmpItemsInventory = fullInventory.Where(item => item.InventoryItemData.Item != null).GroupBy(item => item.InventoryItemData.Item); ItemsInventory.Clear(); foreach (var item in tmpItemsInventory) { ItemsInventory.Add(item.First().InventoryItemData.Item); } // Update Pokemons var tmpPokemonsInventory = fullInventory.Where(item => item.InventoryItemData.PokemonData != null).Select(itemt => itemt.InventoryItemData.PokemonData); PokemonsInventory.Clear(); foreach (var pokemon in tmpPokemonsInventory) { PokemonsInventory.Add(pokemon); } }
/// <summary> /// Updates inventory data /// </summary> public static async Task UpdateInventory() { // Get ALL the items var fullInventory = (await GetInventory()).InventoryDelta.InventoryItems; // Update items ItemsInventory.AddRange(fullInventory.Where(item => item.InventoryItemData.Item != null) .GroupBy(item => item.InventoryItemData.Item) .Select(item => item.First().InventoryItemData.Item), true); CatchItemsInventory.AddRange( fullInventory.Where( item => item.InventoryItemData.Item != null && CatchItemIds.Contains(item.InventoryItemData.Item.ItemId)) .GroupBy(item => item.InventoryItemData.Item) .Select(item => item.First().InventoryItemData.Item), true); // Update incbuators FreeIncubatorsInventory.AddRange(fullInventory.Where(item => item.InventoryItemData.EggIncubators != null) .SelectMany(item => item.InventoryItemData.EggIncubators.EggIncubator) .Where(item => item != null && item.PokemonId == 0), true); UsedIncubatorsInventory.AddRange(fullInventory.Where(item => item.InventoryItemData.EggIncubators != null) .SelectMany(item => item.InventoryItemData.EggIncubators.EggIncubator) .Where(item => item != null && item.PokemonId != 0), true); // Update Pokemons PokemonsInventory.AddRange(fullInventory.Select(item => item.InventoryItemData.PokemonData) .Where(item => item != null && item.PokemonId > 0), true); EggsInventory.AddRange(fullInventory.Select(item => item.InventoryItemData.PokemonData) .Where(item => item != null && item.IsEgg), true); // Update Pokedex PokedexInventory.AddRange(fullInventory.Where(item => item.InventoryItemData.PokedexEntry != null) .Select(item => item.InventoryItemData.PokedexEntry), true); // Update Player stats PlayerStats = fullInventory.First(item => item.InventoryItemData.PlayerStats != null).InventoryItemData.PlayerStats; }
/// <summary> /// Updates inventory data /// </summary> public static async Task UpdateInventory() { // Get ALL the items var fullInventory = (await GetInventory()).InventoryDelta.InventoryItems; // Update items var tmpItemsInventory = fullInventory.Where(item => item.InventoryItemData.Item != null).GroupBy(item => item.InventoryItemData.Item); ItemsInventory.Clear(); foreach (var item in tmpItemsInventory) { ItemsInventory.Add(item.First().InventoryItemData.Item); } // Update incbuators //var tmpIncubatorsInventory = fullInventory.Where(item => item.InventoryItemData.EggIncubators != null).GroupBy(item => item.InventoryItemData.EggIncubators); //IncubatorsInventory.Clear(); //foreach (var item in tmpIncubatorsInventory) //{ // IncubatorsInventory.Add(item.First().InventoryItemData.Item); //} // Update Pokemons var tmpPokemonsInventory = fullInventory.Where(item => item.InventoryItemData.PokemonData != null).Select(itemt => itemt.InventoryItemData.PokemonData); PokemonsInventory.Clear(); EggsInventory.Clear(); foreach (var pokemon in tmpPokemonsInventory) { if (pokemon.IsEgg) { EggsInventory.Add(pokemon); } else { PokemonsInventory.Add(pokemon); } } }
/// <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)); } } }