public void Run(CancellationToken cancellationToken) { if (_session.LogicSettings.EvolveAllPokemonAboveIv || _session.LogicSettings.EvolveAllPokemonWithEnoughCandy || _session.LogicSettings.UseLuckyEggsWhileEvolving || _session.LogicSettings.KeepPokemonsThatCanEvolve) { EvolvePokemonTask.Execute(_session, cancellationToken).Wait(cancellationToken); } if (_session.LogicSettings.AutomaticallyLevelUpPokemon) { LevelUpPokemonTask.Execute(_session, cancellationToken).Wait(cancellationToken); } if (_session.LogicSettings.UseLuckyEggConstantly) { UseLuckyEggConstantlyTask.Execute(_session, cancellationToken).Wait(cancellationToken); } if (_session.LogicSettings.UseIncenseConstantly) { UseIncenseConstantlyTask.Execute(_session, cancellationToken).Wait(cancellationToken); } if (_session.LogicSettings.TransferDuplicatePokemon) { TransferDuplicatePokemonTask.Execute(_session, cancellationToken).Wait(cancellationToken); } if (_session.LogicSettings.TransferWeakPokemon) { TransferWeakPokemonTask.Execute(_session, cancellationToken).Wait(cancellationToken); } if (_session.LogicSettings.RenamePokemon) { RenamePokemonTask.Execute(_session, cancellationToken).Wait(cancellationToken); } if (_session.LogicSettings.AutoFavoritePokemon) { FavoritePokemonTask.Execute(_session, cancellationToken).Wait(cancellationToken); } RecycleItemsTask.Execute(_session, cancellationToken).Wait(cancellationToken); if (_session.LogicSettings.UseEggIncubators) { UseIncubatorsTask.Execute(_session, cancellationToken).Wait(cancellationToken); } if (_session.LogicSettings.UseGpxPathing) { FarmPokestopsGpxTask.Execute(_session, cancellationToken).Wait(cancellationToken); } else { FarmPokestopsTask.Execute(_session, cancellationToken).Wait(cancellationToken); } GetPokeDexCount.Execute(_session, cancellationToken).Wait(cancellationToken); }
public static async Task Execute(ISession session, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var distanceFromStart = LocationUtils.CalculateDistanceInMeters( session.Settings.DefaultLatitude, session.Settings.DefaultLongitude, session.Client.CurrentLatitude, session.Client.CurrentLongitude); // Edge case for when the client somehow ends up outside the defined radius if (session.LogicSettings.MaxTravelDistanceInMeters != 0 && distanceFromStart > session.LogicSettings.MaxTravelDistanceInMeters) { Logger.Write( session.Translation.GetTranslation(TranslationString.FarmPokestopsOutsideRadius, distanceFromStart), LogLevel.Warning); await session.Navigation.Move(new GeoCoordinate( session.Settings.DefaultLatitude, session.Settings.DefaultLongitude, LocationUtils.getElevation(session.Settings.DefaultLatitude, session.Settings.DefaultLongitude)), null, session, cancellationToken); } var pokestopList = await GetPokeStops(session); //get optimized route var pokeStops = RouteOptimizeUtil.Optimize(pokestopList.ToArray(), session.Client.CurrentLatitude, session.Client.CurrentLongitude); var stopsHit = 0; var rc = new Random(); //initialize pokestop random cleanup counter first time _storeRi = rc.Next(8, 15); var eggWalker = new EggWalker(1000, session); if (pokestopList.Count <= 0) { session.EventDispatcher.Send(new WarnEvent { Message = session.Translation.GetTranslation(TranslationString.FarmPokestopsNoUsableFound) }); } session.EventDispatcher.Send(new PokeStopListEvent { Forts = pokestopList }); foreach (var pokeStop in pokeStops) { cancellationToken.ThrowIfCancellationRequested(); var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude, session.Client.CurrentLongitude, pokeStop.Latitude, pokeStop.Longitude); var fortInfo = await session.Client.Fort.GetFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude); session.EventDispatcher.Send(new FortTargetEvent { Name = fortInfo.Name, Distance = distance }); var targetLocation = new GeoCoordinate(pokeStop.Latitude, pokeStop.Longitude, LocationUtils.getElevation(pokeStop.Latitude, pokeStop.Longitude)); await session.Navigation.Move(targetLocation, async() => { // Catch normal map Pokemon await CatchNearbyPokemonsTask.Execute(session, cancellationToken); //Catch Incense Pokemon await CatchIncensePokemonsTask.Execute(session, cancellationToken); return(true); }, session, cancellationToken); //Check if pokestop is in range, if not, move to pokestop without google routing if ( LocationUtils.CalculateDistanceInMeters(targetLocation, new GeoCoordinate(session.Client.CurrentLatitude, session.Client.CurrentLongitude)) >= 30) { await session.Navigation.Move(targetLocation, null, session, cancellationToken, true); } //Catch Lure Pokemon if (pokeStop.LureInfo != null) { await CatchLurePokemonsTask.Execute(session, pokeStop, cancellationToken); } FortSearchResponse fortSearch; 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 { cancellationToken.ThrowIfCancellationRequested(); fortSearch = await session.Client.Fort.SearchFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude); if (fortSearch.ExperienceAwarded > 0 && timesZeroXPawarded > 0) { timesZeroXPawarded = 0; } if (fortSearch.ExperienceAwarded == 0) { timesZeroXPawarded++; if (timesZeroXPawarded > zeroCheck) { if ((int)fortSearch.CooldownCompleteTimestampMs != 0) { break; // Check if successfully looted, if so program can continue as this was "false alarm". } fortTry += 1; session.EventDispatcher.Send(new FortFailedEvent { Name = fortInfo.Name, Try = fortTry, Max = retryNumber - zeroCheck, Looted = false }); if (!session.LogicSettings.FastSoftBanBypass) { DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 0); } } } else { if (fortTry != 0) { session.EventDispatcher.Send(new FortFailedEvent { Name = fortInfo.Name, Try = fortTry + 1, Max = retryNumber - zeroCheck, Looted = true }); } session.EventDispatcher.Send(new FortUsedEvent { Id = pokeStop.Id, Name = fortInfo.Name, Exp = fortSearch.ExperienceAwarded, Gems = fortSearch.GemsAwarded, Items = StringUtils.GetSummedFriendlyNameOfItemAwardList(fortSearch.ItemsAwarded), Latitude = pokeStop.Latitude, Longitude = pokeStop.Longitude, InventoryFull = fortSearch.Result == FortSearchResponse.Types.Result.InventoryFull }); if (fortSearch.Result == FortSearchResponse.Types.Result.InventoryFull) { _storeRi = 1; } OnLootPokestopEvent(pokeStop); 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. await eggWalker.ApplyDistance(distance, cancellationToken); if (++stopsHit >= _storeRi) //TODO: OR item/pokemon bag is full //check stopsHit against storeRI random without dividing. { _storeRi = rc.Next(6, 12); //set new storeRI for new random value stopsHit = 0; await RecycleItemsTask.Execute(session, cancellationToken); if (fortSearch.ItemsAwarded.Count > 0) { await session.Inventory.RefreshCachedInventory(); } if (session.LogicSettings.EvolveAllPokemonWithEnoughCandy || session.LogicSettings.EvolveAllPokemonAboveIv || session.LogicSettings.UseLuckyEggsWhileEvolving || session.LogicSettings.KeepPokemonsThatCanEvolve) { await EvolvePokemonTask.Execute(session, cancellationToken); } if (session.LogicSettings.UseLuckyEggConstantly) { await UseLuckyEggConstantlyTask.Execute(session, cancellationToken); } if (session.LogicSettings.UseIncenseConstantly) { await UseIncenseConstantlyTask.Execute(session, cancellationToken); } if (session.LogicSettings.TransferDuplicatePokemon) { await TransferDuplicatePokemonTask.Execute(session, cancellationToken); } if (session.LogicSettings.TransferWeakPokemon) { await TransferWeakPokemonTask.Execute(session, cancellationToken); } if (session.LogicSettings.RenamePokemon) { await RenamePokemonTask.Execute(session, cancellationToken); } if (session.LogicSettings.AutoFavoritePokemon) { await FavoritePokemonTask.Execute(session, cancellationToken); } if (session.LogicSettings.AutomaticallyLevelUpPokemon) { await LevelUpPokemonTask.Execute(session, cancellationToken); } await GetPokeDexCount.Execute(session, cancellationToken); } if (session.LogicSettings.SnipeAtPokestops || session.LogicSettings.UseSnipeLocationServer) { await SnipePokemonTask.Execute(session, cancellationToken); } } }
public static async Task Execute(ISession session, CancellationToken cancellationToken) { var tracks = GetGpxTracks(session); var eggWalker = new EggWalker(1000, session); for (var curTrk = 0; curTrk < tracks.Count; curTrk++) { cancellationToken.ThrowIfCancellationRequested(); var track = tracks.ElementAt(curTrk); var trackSegments = track.Segments; for (var curTrkSeg = 0; curTrkSeg < trackSegments.Count; curTrkSeg++) { cancellationToken.ThrowIfCancellationRequested(); var trackPoints = track.Segments.ElementAt(curTrkSeg).TrackPoints; for (var curTrkPt = 0; curTrkPt < trackPoints.Count; curTrkPt++) { cancellationToken.ThrowIfCancellationRequested(); var nextPoint = trackPoints.ElementAt(curTrkPt); var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude, session.Client.CurrentLongitude, Convert.ToDouble(nextPoint.Lat, CultureInfo.InvariantCulture), Convert.ToDouble(nextPoint.Lon, CultureInfo.InvariantCulture)); if (distance > 5000) { session.EventDispatcher.Send(new ErrorEvent { Message = session.Translation.GetTranslation(TranslationString.DesiredDestTooFar, nextPoint.Lat, nextPoint.Lon, session.Client.CurrentLatitude, session.Client.CurrentLongitude) }); break; } var pokestopList = await GetPokeStops(session); session.EventDispatcher.Send(new PokeStopListEvent { Forts = pokestopList }); while (pokestopList.Any()) // warning: this is never entered due to ps cooldowns from UseNearbyPokestopsTask { cancellationToken.ThrowIfCancellationRequested(); pokestopList = pokestopList.OrderBy( i => LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude, session.Client.CurrentLongitude, i.Latitude, i.Longitude)).ToList(); var pokeStop = pokestopList[0]; pokestopList.RemoveAt(0); var fortInfo = await session.Client.Fort.GetFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude); if (pokeStop.LureInfo != null) { await CatchLurePokemonsTask.Execute(session, pokeStop, cancellationToken); } var fortSearch = await session.Client.Fort.SearchFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude); if (fortSearch.ExperienceAwarded > 0) { session.EventDispatcher.Send(new FortUsedEvent { Id = pokeStop.Id, Name = fortInfo.Name, Exp = fortSearch.ExperienceAwarded, Gems = fortSearch.GemsAwarded, Items = StringUtils.GetSummedFriendlyNameOfItemAwardList(fortSearch.ItemsAwarded), Latitude = pokeStop.Latitude, Longitude = pokeStop.Longitude }); } else { await RecycleItemsTask.Execute(session, cancellationToken); } if (fortSearch.ItemsAwarded.Count > 0) { await session.Inventory.RefreshCachedInventory(); } } if (DateTime.Now > _lastTasksCall) { _lastTasksCall = DateTime.Now.AddMilliseconds(Math.Min(session.LogicSettings.DelayBetweenPlayerActions, 3000)); await RecycleItemsTask.Execute(session, cancellationToken); if (session.LogicSettings.EvolveAllPokemonWithEnoughCandy || session.LogicSettings.EvolveAllPokemonAboveIv || session.LogicSettings.UseLuckyEggsWhileEvolving || session.LogicSettings.KeepPokemonsThatCanEvolve) { await EvolvePokemonTask.Execute(session, cancellationToken); } await GetPokeDexCount.Execute(session, cancellationToken); if (session.LogicSettings.AutomaticallyLevelUpPokemon) { await LevelUpPokemonTask.Execute(session, cancellationToken); } if (session.LogicSettings.UseLuckyEggConstantly) { await UseLuckyEggConstantlyTask.Execute(session, cancellationToken); } if (session.LogicSettings.UseIncenseConstantly) { await UseIncenseConstantlyTask.Execute(session, cancellationToken); } if (session.LogicSettings.TransferDuplicatePokemon) { await TransferDuplicatePokemonTask.Execute(session, cancellationToken); } if (session.LogicSettings.TransferWeakPokemon) { await TransferWeakPokemonTask.Execute(session, cancellationToken); } if (session.LogicSettings.RenamePokemon) { await RenamePokemonTask.Execute(session, cancellationToken); } if (session.LogicSettings.AutoFavoritePokemon) { await FavoritePokemonTask.Execute(session, cancellationToken); } if (session.LogicSettings.SnipeAtPokestops || session.LogicSettings.UseSnipeLocationServer) { await SnipePokemonTask.Execute(session, cancellationToken); } } await session.Navigation.HumanPathWalking( trackPoints.ElementAt(curTrkPt), async() => { await CatchNearbyPokemonsTask.Execute(session, cancellationToken); //Catch Incense Pokemon await CatchIncensePokemonsTask.Execute(session, cancellationToken); await UseNearbyPokestopsTask.Execute(session, cancellationToken); return(true); }, session, cancellationToken); await eggWalker.ApplyDistance(distance, cancellationToken); } //end trkpts } //end trksegs } //end tracks }