private async Task ExecuteFarmingPokestopsAndPokemons(bool path) { if (!path) { await ExecuteFarmingPokestopsAndPokemons(); } else { var tracks = GetGpxTracks(); var curTrkPt = 0; var curTrk = 0; var maxTrk = tracks.Count - 1; var curTrkSeg = 0; while (curTrk <= maxTrk) { var track = tracks.ElementAt(curTrk); var trackSegments = track.Segments; var maxTrkSeg = trackSegments.Count - 1; while (curTrkSeg <= maxTrkSeg) { var trackPoints = track.Segments.ElementAt(0).TrackPoints; var maxTrkPt = trackPoints.Count - 1; while (curTrkPt <= maxTrkPt) { var nextPoint = trackPoints.ElementAt(curTrkPt); if ( LocationUtils.CalculateDistanceInMeters(_client.CurrentLat, _client.CurrentLng, Convert.ToDouble(nextPoint.Lat), Convert.ToDouble(nextPoint.Lon)) > 5000) { Logger.Write( $"Your desired destination of {nextPoint.Lat}, {nextPoint.Lon} is too far from your current position of {_client.CurrentLat}, {_client.CurrentLng}", LogLevel.Error); break; } Logger.Write( $"Your desired destination is {nextPoint.Lat}, {nextPoint.Lon} your location is {_client.CurrentLat}, {_client.CurrentLng}", LogLevel.Warning); // Wasn't sure how to make this pretty. Edit as needed. var mapObjects = await _client.GetMapObjects(); var pokeStops = mapObjects.MapCells.SelectMany(i => i.Forts) .Where( i => i.Type == FortType.Checkpoint && i.CooldownCompleteTimestampMs < DateTime.UtcNow.ToUnixTime() && ( // Make sure PokeStop is within 40 meters, otherwise we cannot hit them. LocationUtils.CalculateDistanceInMeters( _client.CurrentLat, _client.CurrentLng, i.Latitude, i.Longitude) < 40) ); var pokestopList = pokeStops.ToList(); while (pokestopList.Any()) { pokestopList = pokestopList.OrderBy( i => LocationUtils.CalculateDistanceInMeters(_client.CurrentLat, _client.CurrentLng, i.Latitude, i.Longitude)).ToList(); var pokeStop = pokestopList[0]; pokestopList.RemoveAt(0); var distance = LocationUtils.CalculateDistanceInMeters(_client.CurrentLat, _client.CurrentLng, pokeStop.Latitude, pokeStop.Longitude); var fortInfo = await _client.GetFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude); Logger.Write($"Name: {fortInfo.Name} in {distance:0.##} m distance", LogLevel.Pokestop); var fortSearch = await _client.SearchFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude); if (fortSearch.ExperienceAwarded > 0) { _stats.AddExperience(fortSearch.ExperienceAwarded); _stats.UpdateConsoleTitle(_client, _inventory); string EggReward = fortSearch.PokemonDataEgg != null ? "1" : "0"; Logger.Write($"XP: {fortSearch.ExperienceAwarded}, Gems: {fortSearch.GemsAwarded}, Eggs: {EggReward}, Items: {StringUtils.GetSummedFriendlyNameOfItemAwardList(fortSearch.ItemsAwarded)}", LogLevel.Pokestop); recycleCounter++; } await RandomHelper.RandomDelay(50, 200); if (recycleCounter >= 5) { await RecycleItems(); } } await _navigation.HumanPathWalking(trackPoints.ElementAt(curTrkPt), _clientSettings.WalkingSpeedInKilometerPerHour, ExecuteCatchAllNearbyPokemons); if (curTrkPt >= maxTrkPt) { curTrkPt = 0; } else { curTrkPt++; } } //end trkpts if (curTrkSeg >= maxTrkSeg) { curTrkSeg = 0; } else { curTrkSeg++; } } //end trksegs if (curTrk >= maxTrkSeg) { curTrk = 0; } else { curTrk++; } } //end tracks } }
private async Task ExecuteFarmingPokestopsAndPokemons(bool path) { if (!path) { await ExecuteFarmingPokestopsAndPokemons(); } else { var tracks = GetGpxTracks(); var curTrkPt = 0; var curTrk = 0; var maxTrk = tracks.Count - 1; var curTrkSeg = 0; while (curTrk <= maxTrk) { var track = tracks.ElementAt(curTrk); var trackSegments = track.Segments; var maxTrkSeg = trackSegments.Count - 1; while (curTrkSeg <= maxTrkSeg) { var trackPoints = track.Segments.ElementAt(0).TrackPoints; var maxTrkPt = trackPoints.Count - 1; while (curTrkPt <= maxTrkPt) { var nextPoint = trackPoints.ElementAt(curTrkPt); var distanceCheck = LocationUtils.CalculateDistanceInMeters(_client.CurrentLat, _client.CurrentLng, Convert.ToDouble(nextPoint.Lat), Convert.ToDouble(nextPoint.Lon)); if (distanceCheck > 5000) { Logger.Write( $"Your desired destination of {nextPoint.Lat}, {nextPoint.Lon} is too far from your current position of {_client.CurrentLat}, {_client.CurrentLng}", LogLevel.Error); break; } Logger.Write( $"Your desired destination is {nextPoint.Lat}, {nextPoint.Lon} your location is {_client.CurrentLat}, {_client.CurrentLng}", LogLevel.Warning); if (_clientSettings.UseLuckyEggs) { await UseLuckyEgg(); } if (_clientSettings.UseIncense) { await UseIncense(); } if (!_clientSettings.GPXIgnorePokemon) { await ExecuteCatchAllNearbyPokemons(); } if (!_clientSettings.GPXIgnorePokestops) { var pokeStops = await _inventory.GetPokestops(); var pokestopList = pokeStops.ToList(); while (pokestopList.Any()) { pokestopList = pokestopList.OrderBy( i => LocationUtils.CalculateDistanceInMeters(_client.CurrentLat, _client.CurrentLng, i.Latitude, i.Longitude)).ToList(); var pokeStop = pokestopList.First(); pokestopList.Remove(pokeStop); var distance = LocationUtils.CalculateDistanceInMeters(_client.CurrentLat, _client.CurrentLng, pokeStop.Latitude, pokeStop.Longitude); var fortInfo = await _client.GetFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude); Logger.Write($"Name: {fortInfo.Name} in {distance:0.##} m distance", LogLevel.Pokestop); if (_client.Settings.DebugMode) { Logger.Write($"Latitude: {pokeStop.Latitude} - Longitude: {pokeStop.Longitude}", LogLevel.Debug); } var timesZeroXPawarded = 0; var fortTry = 0; //Current check const int retryNumber = 50; //How many times it needs to check to clear softban const int zeroCheck = 5; //How many times it checks fort before it thinks it's softban do { var fortSearch = await _client.SearchFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude); if (fortSearch.ExperienceAwarded > 0 && timesZeroXPawarded > 0) { timesZeroXPawarded = 0; } if (fortSearch.ExperienceAwarded == 0) { timesZeroXPawarded++; if (timesZeroXPawarded <= zeroCheck) { continue; } if ((int)fortSearch.CooldownCompleteTimestampMs != 0) { break; // Check if successfully looted, if so program can continue as this was "false alarm". } fortTry += 1; if (_client.Settings.DebugMode) { Logger.Write($"Seems your Soft-Banned. Trying to Unban via Pokestop Spins. Retry {fortTry} of {retryNumber}", LogLevel.Warning); } await RandomHelper.RandomDelay(75, 100); } else { _stats.AddExperience(fortSearch.ExperienceAwarded); _stats.UpdateConsoleTitle(_client, _inventory); var eggReward = fortSearch.PokemonDataEgg != null ? "1" : "0"; Logger.Write($"XP: {fortSearch.ExperienceAwarded}, Gems: {fortSearch.GemsAwarded}, Eggs: {eggReward}, Items: {StringUtils.GetSummedFriendlyNameOfItemAwardList(fortSearch.ItemsAwarded)}", LogLevel.Pokestop); _recycleCounter++; break; //Continue with program as loot was succesfull. } } while (fortTry < retryNumber - zeroCheck); //Stop trying if softban is cleaned earlier or if 40 times fort looting failed. if (_recycleCounter >= 5) { await RecycleItems(); } } } if (!_clientSettings.GPXIgnorePokemon) { await _navigation.HumanPathWalking(trackPoints.ElementAt(curTrkPt), _clientSettings.WalkingSpeedInKilometerPerHour, ExecuteCatchAllNearbyPokemons); } else { await _navigation.HumanPathWalking(trackPoints.ElementAt(curTrkPt), _clientSettings.WalkingSpeedInKilometerPerHour, null); } if (curTrkPt >= maxTrkPt) { curTrkPt = 0; } else { curTrkPt++; } } //end trkpts if (curTrkSeg >= maxTrkSeg) { curTrkSeg = 0; } else { curTrkSeg++; } } //end trksegs if (curTrk >= maxTrkSeg) { curTrk = 0; } else { curTrk++; } } //end tracks } }