private static async Task WalkingToPokeStop(ISession session, CancellationToken cancellationToken, FortData pokeStop, FortDetailsResponse fortInfo) { var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude, session.Client.CurrentLongitude, pokeStop.Latitude, pokeStop.Longitude); // we only move to the PokeStop, and send the associated FortTargetEvent, when not using GPX // also, GPX pathing uses its own EggWalker and calls the CatchPokemon tasks internally. if (!session.LogicSettings.UseGpxPathing) { var eggWalker = new EggWalker(1000, session); cancellationToken.ThrowIfCancellationRequested(); // Always set the fort info in base walk strategy. var pokeStopDestination = new FortLocation(pokeStop.Latitude, pokeStop.Longitude, LocationUtils.getElevation(session.ElevationService, pokeStop.Latitude, pokeStop.Longitude), pokeStop, fortInfo); await session.Navigation.Move(pokeStopDestination, async() => { await MSniperServiceTask.Execute(session, cancellationToken); await OnWalkingToPokeStopOrGym(session, pokeStop, cancellationToken); }, session, cancellationToken); // we have moved this distance, so apply it immediately to the egg walker. await eggWalker.ApplyDistance(distance, 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); var eggWalker = new EggWalker(1000, session); await session.Navigation.Move(new GeoCoordinate( session.Settings.DefaultLatitude, session.Settings.DefaultLongitude, LocationUtils.getElevation(session.Settings.DefaultLatitude, session.Settings.DefaultLongitude)), null, session, cancellationToken); // we have moved this distance, so apply it immediately to the egg walker. await eggWalker.ApplyDistance(distanceFromStart, cancellationToken); } // initialize the variables in UseNearbyPokestopsTask here, as this is a fresh start. UseNearbyPokestopsTask.Initialize(); await UseNearbyPokestopsTask.Execute(session, cancellationToken); }
private static async Task WalkingToPokeStop(ISession session, CancellationToken cancellationToken, FortData pokeStop, FortDetailsResponse fortInfo) { var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude, session.Client.CurrentLongitude, pokeStop.Latitude, pokeStop.Longitude); // we only move to the PokeStop, and send the associated FortTargetEvent, when not using GPX // also, GPX pathing uses its own EggWalker and calls the CatchPokemon tasks internally. if (!session.LogicSettings.UseGpxPathing) { // Will modify Lat,Lng and Name to fake position //Need refactor it to speparate from pokestop logic -> samuraitruong will do it. SetMoveToTargetTask.CheckSetMoveToTargetStatus(ref fortInfo, ref pokeStop); var eggWalker = new EggWalker(1000, session); cancellationToken.ThrowIfCancellationRequested(); if (!session.LogicSettings.UseGoogleWalk && !session.LogicSettings.UseYoursWalk) { session.EventDispatcher.Send(new FortTargetEvent { Name = fortInfo.Name, Distance = distance, Route = "NecroBot" }); } else { BaseWalkStrategy.FortInfo = fortInfo; } var pokeStopDestination = new GeoCoordinate(pokeStop.Latitude, pokeStop.Longitude, LocationUtils.getElevation(session, pokeStop.Latitude, pokeStop.Longitude)); if (pokeStop.Type == FortType.Gym) { session.EventDispatcher.Send(new GymWalkToTargetEvent() { Name = fortInfo.Name, Distance = distance, Latitude = fortInfo.Latitude, Longitude = fortInfo.Longitude }); } await session.Navigation.Move(pokeStopDestination, async() => { await OnWalkingToPokeStopOrGym(session, pokeStop, cancellationToken); }, session, cancellationToken); // we have moved this distance, so apply it immediately to the egg walker. await eggWalker.ApplyDistance(distance, cancellationToken); } }
private static async Task WalkingBackGPXPath(ISession session, CancellationToken cancellationToken, FortData originalPokestop) { var destination = new GeoCoordinate(originalPokestop.Latitude, originalPokestop.Longitude, LocationUtils.getElevation(session, originalPokestop.Latitude, originalPokestop.Longitude)); await session.Navigation.Move(destination, async() => { await CatchNearbyPokemonsTask.Execute(session, cancellationToken); await UseNearbyPokestopsTask.SpinPokestopNearBy(session, cancellationToken); }, session, cancellationToken); }
private static async Task WalkingBackGPXPath(ISession session, CancellationToken cancellationToken, FortData originalPokestop, FortDetailsResponse fortInfo) { var destination = new FortLocation(originalPokestop.Latitude, originalPokestop.Longitude, LocationUtils.getElevation(session.ElevationService, originalPokestop.Latitude, originalPokestop.Longitude), originalPokestop, fortInfo); await session.Navigation.Move(destination, async() => { await MSniperServiceTask.Execute(session, cancellationToken); await CatchNearbyPokemonsTask.Execute(session, cancellationToken); await UseNearbyPokestopsTask.SpinPokestopNearBy(session, cancellationToken); }, session, cancellationToken); }
private static async Task WalkingBackGPXPath(ISession session, CancellationToken cancellationToken, FortData originalPokestop) { var destination = new FortLocation(originalPokestop.Latitude, originalPokestop.Longitude, LocationUtils.getElevation(session, originalPokestop.Latitude, originalPokestop.Longitude), originalPokestop, null); await session.Navigation.Move(destination, async() => { if (session.LogicSettings.ActivateMSniper) { await MSniperServiceTask.Execute(session, cancellationToken); } await CatchNearbyPokemonsTask.Execute(session, cancellationToken); await UseNearbyPokestopsTask.SpinPokestopNearBy(session, cancellationToken); }, session, 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); var response = await session.Client.Player.UpdatePlayerLocation(session.Client.CurrentLatitude, session.Client.CurrentLongitude, session.Client.CurrentAltitude, 0); // Edge case for when the client somehow ends up outside the defined radius if (session.LogicSettings.MaxTravelDistanceInMeters != 0 && checkForMoveBackToDefault && distanceFromStart > session.LogicSettings.MaxTravelDistanceInMeters) { checkForMoveBackToDefault = false; Logger.Write( session.Translation.GetTranslation(TranslationString.FarmPokestopsOutsideRadius, distanceFromStart), LogLevel.Warning); var eggWalker = new EggWalker(1000, session); var defaultLocation = new MapLocation(session.Settings.DefaultLatitude, session.Settings.DefaultLongitude, LocationUtils.getElevation(session.ElevationService, session.Settings.DefaultLatitude, session.Settings.DefaultLongitude) ); await session.Navigation.Move(defaultLocation, async() => { await MSniperServiceTask.Execute(session, cancellationToken); }, session, cancellationToken); // we have moved this distance, so apply it immediately to the egg walker. await eggWalker.ApplyDistance(distanceFromStart, cancellationToken); } checkForMoveBackToDefault = false; await CatchNearbyPokemonsTask.Execute(session, cancellationToken); // initialize the variables in UseNearbyPokestopsTask here, as this is a fresh start. UseNearbyPokestopsTask.Initialize(); await UseNearbyPokestopsTask.Execute(session, cancellationToken); }
private static async Task WalkingToPokeStop(ISession session, CancellationToken cancellationToken, FortData pokeStop, FortDetailsResponse fortInfo) { var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude, session.Client.CurrentLongitude, pokeStop.Latitude, pokeStop.Longitude); // we only move to the PokeStop, and send the associated FortTargetEvent, when not using GPX // also, GPX pathing uses its own EggWalker and calls the CatchPokemon tasks internally. if (!session.LogicSettings.UseGpxPathing) { var eggWalker = new EggWalker(1000, session); cancellationToken.ThrowIfCancellationRequested(); // Always set the fort info in base walk strategy. BaseWalkStrategy.FortInfo = fortInfo; var pokeStopDestination = new GeoCoordinate(pokeStop.Latitude, pokeStop.Longitude, LocationUtils.getElevation(session, pokeStop.Latitude, pokeStop.Longitude)); if (pokeStop.Type == FortType.Gym) { session.EventDispatcher.Send(new GymWalkToTargetEvent() { Name = fortInfo.Name, Distance = distance, Latitude = fortInfo.Latitude, Longitude = fortInfo.Longitude }); } await session.Navigation.Move(pokeStopDestination, async() => { await OnWalkingToPokeStopOrGym(session, pokeStop, cancellationToken); }, session, cancellationToken); // we have moved this distance, so apply it immediately to the egg walker. await eggWalker.ApplyDistance(distance, cancellationToken); } }
public static async Task Execute(ISession session, CancellationToken cancellationToken, Func <double, double, Task> actionWhenWalking = null, Func <Task> afterCatchFunc = null) { pokestopCount++; pokestopCount = pokestopCount % 3; if (pokestopCount > 0) { return; } _session = session; _setting = session.LogicSettings; cancellationToken.ThrowIfCancellationRequested(); if (!_setting.CatchPokemon) { return; } pokemonToBeSnipedIds = _setting.PokemonToSnipe.Pokemon; pokemonToBeSnipedIds.AddRange(_setting.HumanWalkSnipeFilters.Where(x => !pokemonToBeSnipedIds.Any(t => t == x.Key)).Select(x => x.Key).ToList()); //this will combine with pokemon snipe filter if (_setting.HumanWalkingSnipeTryCatchEmAll) { var checkBall = await CheckPokeballsToSnipe(_setting.HumanWalkingSnipeCatchEmAllMinBalls, session, cancellationToken); if (!checkBall) { return; } } bool keepWalking = true; bool caughtAnyPokemonInThisWalk = false; while (keepWalking) { var pokemons = GetRarePokemons(session.Client.CurrentLatitude, session.Client.CurrentLongitude, !caughtAnyPokemonInThisWalk); foreach (var pokemon in pokemons) { caughtAnyPokemonInThisWalk = true; CalculateDistanceAndEstTime(pokemon); var remainTimes = (pokemon.expired - DateTime.Now).TotalSeconds * 0.9; //just use 90% times var catchPokemonTimeEST = (pokemon.distance / 100) * 10; //assume that 100m we catch 1 pokemon and it took 10 second for each. string strPokemon = session.Translation.GetPokemonTranslation(pokemon.Id); var spinPokestopEST = (pokemon.distance / 100) * 5; bool catchPokemon = (pokemon.estimateTime + catchPokemonTimeEST) < remainTimes && pokemon.FilterSetting.CatchPokemonWhileWalking; bool spinPokestop = pokemon.FilterSetting.SpinPokestopWhileWalking && (pokemon.estimateTime + catchPokemonTimeEST + spinPokestopEST) < remainTimes; session.EventDispatcher.Send(new HumanWalkSnipeEvent() { PokemonId = pokemon.Id, Latitude = pokemon.latitude, Longitude = pokemon.longitude, Distance = pokemon.distance, Expires = (pokemon.expired - DateTime.Now).TotalSeconds, Estimate = (int)pokemon.estimateTime, Setting = pokemon.FilterSetting, CatchPokemon = catchPokemon, SpinPokeStop = pokemon.FilterSetting.SpinPokestopWhileWalking, Type = HumanWalkSnipeEventTypes.StartWalking }); await session.Navigation.Move(new GeoCoordinate(pokemon.latitude, pokemon.longitude, LocationUtils.getElevation(pokemon.latitude, pokemon.longitude)), async() => { var distance = LocationUtils.CalculateDistanceInMeters(pokemon.latitude, pokemon.longitude, session.Client.CurrentLatitude, session.Client.CurrentLongitude); if (catchPokemon && distance > 50) { // Catch normal map Pokemon await CatchNearbyPokemonsTask.Execute(session, cancellationToken); } if (actionWhenWalking != null && spinPokestop) { await actionWhenWalking(session.Client.CurrentLatitude, session.Client.CurrentLongitude); } return(await Task.FromResult <bool>(true)); }, session, cancellationToken); session.EventDispatcher.Send(new HumanWalkSnipeEvent() { Latitude = pokemon.latitude, Longitude = pokemon.longitude, Type = HumanWalkSnipeEventTypes.DestinationReached }); await CatchNearbyPokemonsTask.Execute(session, cancellationToken); await CatchIncensePokemonsTask.Execute(session, cancellationToken); } keepWalking = _setting.HumanWalkingSnipeTryCatchEmAll && pokemons.Count > 0; } if (caughtAnyPokemonInThisWalk && !_setting.HumanWalkingSnipeAlwaysWalkBack) { await afterCatchFunc?.Invoke(); } }
public static async Task Execute(ISession session, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var pokestopList = await GetPokeStops(session); while (pokestopList.Any()) { cancellationToken.ThrowIfCancellationRequested(); await SnipeMSniperTask.CheckMSniperLocation(session, cancellationToken); pokestopList = pokestopList.OrderBy( i => LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude, session.Client.CurrentLongitude, i.Latitude, i.Longitude)).ToList(); // randomize next pokestop between first and second by distance var pokestopListNum = 0; if (pokestopList.Count > 1) { pokestopListNum = rc.Next(0, 2); } var pokeStop = pokestopList[pokestopListNum]; pokestopList.RemoveAt(pokestopListNum); var fortInfo = await session.Client.Fort.GetFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude); // we only move to the PokeStop, and send the associated FortTargetEvent, when not using GPX // also, GPX pathing uses its own EggWalker and calls the CatchPokemon tasks internally. if (!session.LogicSettings.UseGpxPathing) { var eggWalker = new EggWalker(1000, session); var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude, session.Client.CurrentLongitude, pokeStop.Latitude, pokeStop.Longitude); cancellationToken.ThrowIfCancellationRequested(); if (!session.LogicSettings.UseGoogleWalk && !session.LogicSettings.UseYoursWalk) { session.EventDispatcher.Send(new FortTargetEvent { Name = fortInfo.Name, Distance = distance, Route = "NecroBot" }); } else { BaseWalkStrategy.FortInfo = fortInfo; } await session.Navigation.Move(new GeoCoordinate(pokeStop.Latitude, pokeStop.Longitude, LocationUtils.getElevation(pokeStop.Latitude, pokeStop.Longitude)), async() => { // Catch normal map Pokemon await CatchNearbyPokemonsTask.Execute(session, cancellationToken); //Catch Incense Pokemon await CatchIncensePokemonsTask.Execute(session, cancellationToken); return(true); }, session, cancellationToken); // we have moved this distance, so apply it immediately to the egg walker. await eggWalker.ApplyDistance(distance, cancellationToken); } //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(); if (SearchThresholdExceeds(session)) { break; } 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; } session.Stats.PokeStopTimestamps.Add(DateTime.Now.Ticks); 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 (session.LogicSettings.RandomlyPauseAtStops) { if (++RandomStop >= RandomNumber) { RandomNumber = rc.Next(4, 11); RandomStop = 0; int RandomWaitTime = rc.Next(30, 120); Thread.Sleep(RandomWaitTime); } } 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 (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) { cancellationToken.ThrowIfCancellationRequested(); var pokestopsTuple = await GetPokeStops(session); var allPokestops = pokestopsTuple.Item1; var pokestopList = pokestopsTuple.Item2; while (pokestopList.Any()) { cancellationToken.ThrowIfCancellationRequested(); await SnipeMSniperTask.CheckMSniperLocation(session, cancellationToken); pokestopList = pokestopList.OrderBy( i => LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude, session.Client.CurrentLongitude, i.Latitude, i.Longitude)).ToList(); // randomize next pokestop between first and second by distance var pokestopListNum = 0; if (pokestopList.Count > 1) { pokestopListNum = rc.Next(0, 2); } var pokeStop = pokestopList[pokestopListNum]; pokestopList.RemoveAt(pokestopListNum); // this logic should only be called when we reach a pokestop either via GPX path or normal walking // as when walk-sniping, we want to get to the snipe ASAP rather than stop for lured pokemon upon // calling FarmPokestop; in that situation we are also always within 40m of the pokestop, so no // need to walk to it var fortInfo = await session.Client.Fort.GetFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude); // we only move to the PokeStop, and send the associated FortTargetEvent, when not using GPX // also, GPX pathing uses its own EggWalker and calls the CatchPokemon tasks internally. if (!session.LogicSettings.UseGpxPathing) { var eggWalker = new EggWalker(1000, session); var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude, session.Client.CurrentLongitude, pokeStop.Latitude, pokeStop.Longitude); cancellationToken.ThrowIfCancellationRequested(); if (!session.LogicSettings.UseGoogleWalk && !session.LogicSettings.UseYoursWalk) { session.EventDispatcher.Send(new FortTargetEvent { Name = fortInfo.Name, Distance = distance, Route = "NecroBot" }); } else { BaseWalkStrategy.FortInfo = fortInfo; } await session.Navigation.Move(new GeoCoordinate(pokeStop.Latitude, pokeStop.Longitude, LocationUtils.getElevation(session, pokeStop.Latitude, pokeStop.Longitude)), async() => { // Catch normal map Pokemon await CatchNearbyPokemonsTask.Execute(session, cancellationToken); //Catch Incense Pokemon await CatchIncensePokemonsTask.Execute(session, cancellationToken); return(true); }, session, cancellationToken); // we have moved this distance, so apply it immediately to the egg walker. await eggWalker.ApplyDistance(distance, cancellationToken); } //Catch Lure Pokemon if (pokeStop.LureInfo != null) { // added for cooldowns await Task.Delay(Math.Min(session.LogicSettings.DelayBetweenPlayerActions, 3000)); await CatchLurePokemonsTask.Execute(session, pokeStop, cancellationToken); } await FarmPokestop(session, pokeStop, fortInfo, 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; if (session.LogicSettings.UseNearActionRandom) { await HumanRandomActionTask.Execute(session, cancellationToken); } else { await RecycleItemsTask.Execute(session, cancellationToken); 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); } if (session.LogicSettings.EnableHumanWalkingSnipe) { //refactore to move this code inside the task later. await HumanWalkSnipeTask.Execute(session, cancellationToken, async (double lat, double lng) => { //idea of this function is to spin pokestop on way. maybe risky. var reachablePokestops = allPokestops.Where(i => LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude, session.Client.CurrentLongitude, i.Latitude, i.Longitude) < 40).ToList(); reachablePokestops = reachablePokestops.OrderBy(i => LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude, session.Client.CurrentLongitude, i.Latitude, i.Longitude)).ToList(); foreach (var ps in reachablePokestops) { if (!session.LogicSettings.UseGpxPathing || pokestopList.Contains(ps)) { pokestopList.Remove(ps); } var fi = await session.Client.Fort.GetFort(ps.Id, ps.Latitude, ps.Longitude); await FarmPokestop(session, ps, fi, cancellationToken); } }, async() => { // if using GPX we have to move back to the original pokestop, to resume the path. // we do not try to use pokestops on the way back, as we will have used them getting // here. if (session.LogicSettings.UseGpxPathing) { var eggWalker = new EggWalker(1000, session); var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude, session.Client.CurrentLongitude, pokeStop.Latitude, pokeStop.Longitude); var geo = new GeoCoordinate(pokeStop.Latitude, pokeStop.Longitude); await session.Navigation.Move(geo, async() => { await CatchNearbyPokemonsTask.Execute(session, cancellationToken); //Catch Incense Pokemon await CatchIncensePokemonsTask.Execute(session, cancellationToken); return(true); }, session, cancellationToken); await eggWalker.ApplyDistance(distance, cancellationToken); return; } var nearestStop = pokestopList.OrderBy(i => LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude, session.Client.CurrentLongitude, i.Latitude, i.Longitude)).FirstOrDefault(); var walkedDistance = LocationUtils.CalculateDistanceInMeters(nearestStop.Latitude, nearestStop.Longitude, session.Client.CurrentLatitude, session.Client.CurrentLongitude); if (walkedDistance > session.LogicSettings.HumanWalkingSnipeWalkbackDistanceLimit) { await Task.Delay(3000); var nearbyPokeStops = await UpdateFortsData(session); var notexists = nearbyPokeStops.Where(p => !pokestopList.Any(x => x.Id == p.Id)).ToList(); pokestopList.AddRange(notexists); session.EventDispatcher.Send(new PokeStopListEvent { Forts = pokestopList }); session.EventDispatcher.Send(new HumanWalkSnipeEvent() { Type = HumanWalkSnipeEventTypes.PokestopUpdated, Pokestops = notexists, NearestDistance = walkedDistance }); } }); } } }
public async Task <PlayerUpdateResponse> Move(GeoCoordinate targetLocation, Func <Task <bool> > functionExecutedWhileWalking, ISession session, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); if (!session.LogicSettings.DisableHumanWalking) { PlayerUpdateResponse result = null; List <GeoCoordinate> points = new List <GeoCoordinate>(); var route = Route(session, new GeoCoordinate( _client.CurrentLatitude, _client.CurrentLongitude, _client.CurrentAltitude), targetLocation); foreach (var item in route) { points.Add(new GeoCoordinate(item.ToArray()[1], item.ToArray()[0])); } for (int i = 0; i < points.Count; i++) { var speedInMetersPerSecond = session.LogicSettings.UseWalkingSpeedVariant ? MajorWalkingSpeedVariant(session) : session.LogicSettings.WalkingSpeedInKilometerPerHour / 3.6; var sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude); var nextWaypointBearing = LocationUtils.DegreeBearing(sourceLocation, points.ToArray()[i]); var nextWaypointDistance = speedInMetersPerSecond; var waypoint = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing); var requestSendDateTime = DateTime.Now; result = await _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude); UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude); var realDistanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation); if (realDistanceToTarget < 30) { break; } do { cancellationToken.ThrowIfCancellationRequested(); var millisecondsUntilGetUpdatePlayerLocationResponse = (DateTime.Now - requestSendDateTime).TotalMilliseconds; sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude); var currentDistanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, points.ToArray()[i]); var realDistanceToTargetSpeedDown = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation); if (realDistanceToTargetSpeedDown < 40) { if (speedInMetersPerSecond > SpeedDownTo) { speedInMetersPerSecond = SpeedDownTo; } } if (session.LogicSettings.UseWalkingSpeedVariant) { speedInMetersPerSecond = MinorWalkingSpeedVariant(session); } nextWaypointDistance = Math.Min(currentDistanceToTarget, millisecondsUntilGetUpdatePlayerLocationResponse / 1000 * speedInMetersPerSecond); nextWaypointBearing = LocationUtils.DegreeBearing(sourceLocation, points.ToArray()[i]); waypoint = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing); requestSendDateTime = DateTime.Now; result = await _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude); UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude); if (functionExecutedWhileWalking != null) { await functionExecutedWhileWalking(); // look for pokemon } } while (LocationUtils.CalculateDistanceInMeters(sourceLocation, points.ToArray()[i]) >= 2); UpdatePositionEvent?.Invoke(points.ToArray()[i].Latitude, points.ToArray()[i].Longitude); } return(result); } var curLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude); var dist = LocationUtils.CalculateDistanceInMeters(curLocation, targetLocation); if (dist >= 100) { var nextWaypointDistance = dist * 70 / 100; var nextWaypointBearing = LocationUtils.DegreeBearing(curLocation, targetLocation); var waypoint = LocationUtils.CreateWaypoint(curLocation, nextWaypointDistance, nextWaypointBearing); var sentTime = DateTime.Now; var result = await _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude); UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude); do { cancellationToken.ThrowIfCancellationRequested(); var millisecondsUntilGetUpdatePlayerLocationResponse = (DateTime.Now - sentTime).TotalMilliseconds; curLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude); var currentDistanceToTarget = LocationUtils.CalculateDistanceInMeters(curLocation, targetLocation); dist = LocationUtils.CalculateDistanceInMeters(curLocation, targetLocation); if (dist >= 100) { nextWaypointDistance = dist * 70 / 100; } else { nextWaypointDistance = dist; } nextWaypointBearing = LocationUtils.DegreeBearing(curLocation, targetLocation); waypoint = LocationUtils.CreateWaypoint(curLocation, nextWaypointDistance, nextWaypointBearing); sentTime = DateTime.Now; result = await _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude); UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude); if (functionExecutedWhileWalking != null) { await functionExecutedWhileWalking(); // look for pokemon } } while (LocationUtils.CalculateDistanceInMeters(curLocation, targetLocation) >= 10); return(result); } else { var result = await _client.Player.UpdatePlayerLocation(targetLocation.Latitude, targetLocation.Longitude, LocationUtils.getElevation(targetLocation.Latitude, targetLocation.Longitude)); UpdatePositionEvent?.Invoke(targetLocation.Latitude, targetLocation.Longitude); if (functionExecutedWhileWalking != null) { await functionExecutedWhileWalking(); // look for pokemon } return(result); } }
public async Task<PlayerUpdateResponse> Move(GeoCoordinate targetLocation, double walkingSpeedInKilometersPerHour, Func<Task<bool>> functionExecutedWhileWalking, CancellationToken cancellationToken, bool disableHumanLikeWalking) { cancellationToken.ThrowIfCancellationRequested(); if (!disableHumanLikeWalking) { var speedInMetersPerSecond = walkingSpeedInKilometersPerHour/3.6; var sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude); var nextWaypointBearing = LocationUtils.DegreeBearing(sourceLocation, targetLocation); var nextWaypointDistance = speedInMetersPerSecond; var waypoint = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing); //Initial walking var requestSendDateTime = DateTime.Now; var result = await _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude); UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude); do { cancellationToken.ThrowIfCancellationRequested(); var millisecondsUntilGetUpdatePlayerLocationResponse = (DateTime.Now - requestSendDateTime).TotalMilliseconds; sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude); var currentDistanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation); if (currentDistanceToTarget < 40) { if (speedInMetersPerSecond > SpeedDownTo) { //Logger.Write("We are within 40 meters of the target. Speeding down to 10 km/h to not pass the target.", LogLevel.Info); speedInMetersPerSecond = SpeedDownTo; } } nextWaypointDistance = Math.Min(currentDistanceToTarget, millisecondsUntilGetUpdatePlayerLocationResponse/1000*speedInMetersPerSecond); nextWaypointBearing = LocationUtils.DegreeBearing(sourceLocation, targetLocation); waypoint = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing); requestSendDateTime = DateTime.Now; result = await _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude); UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude); if (functionExecutedWhileWalking != null) await functionExecutedWhileWalking(); // look for pokemon } while (LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation) >= 30); return result; } var curLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude); var dist = LocationUtils.CalculateDistanceInMeters(curLocation, targetLocation); if (dist >= 100) { var nextWaypointDistance = dist*70/100; var nextWaypointBearing = LocationUtils.DegreeBearing(curLocation, targetLocation); var waypoint = LocationUtils.CreateWaypoint(curLocation, nextWaypointDistance, nextWaypointBearing); var sentTime = DateTime.Now; var result = await _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude); UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude); do { cancellationToken.ThrowIfCancellationRequested(); var millisecondsUntilGetUpdatePlayerLocationResponse = (DateTime.Now - sentTime).TotalMilliseconds; curLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude); var currentDistanceToTarget = LocationUtils.CalculateDistanceInMeters(curLocation, targetLocation); dist = LocationUtils.CalculateDistanceInMeters(curLocation, targetLocation); if (dist >= 100) { nextWaypointDistance = dist*70/100; } else { nextWaypointDistance = dist; } nextWaypointBearing = LocationUtils.DegreeBearing(curLocation, targetLocation); waypoint = LocationUtils.CreateWaypoint(curLocation, nextWaypointDistance, nextWaypointBearing); sentTime = DateTime.Now; result = await _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude); UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude); if (functionExecutedWhileWalking != null) await functionExecutedWhileWalking(); // look for pokemon } while (LocationUtils.CalculateDistanceInMeters(curLocation, targetLocation) >= 10); return result; } else { var result = await _client.Player.UpdatePlayerLocation(targetLocation.Latitude, targetLocation.Longitude, LocationUtils.getElevation(targetLocation.Latitude,targetLocation.Longitude)); UpdatePositionEvent?.Invoke(targetLocation.Latitude, targetLocation.Longitude); if (functionExecutedWhileWalking != null) await functionExecutedWhileWalking(); // look for pokemon return result; } }
public static async Task Execute(ISession session, CancellationToken cancellationToken) { var tracks = GetGpxTracks(session); var eggWalker = new EggWalker(1000, session); if (!_resumeTrack.HasValue || !_resumeTrackSeg.HasValue || !_resumeTrackPt.HasValue) { _resumeTrack = session.LogicSettings.ResumeTrack; _resumeTrackSeg = session.LogicSettings.ResumeTrackSeg; _resumeTrackPt = session.LogicSettings.ResumeTrackPt; // initialize the variables in UseNearbyPokestopsTask here, as this is a fresh start. UseNearbyPokestopsTask.Initialize(); } for (var curTrk = _resumeTrack.Value; curTrk < tracks.Count; curTrk++) { _resumeTrack = curTrk; cancellationToken.ThrowIfCancellationRequested(); var track = tracks.ElementAt(curTrk); var trackSegments = track.Segments; for (var curTrkSeg = _resumeTrackSeg.Value; curTrkSeg < trackSegments.Count; curTrkSeg++) { _resumeTrackSeg = curTrkSeg; cancellationToken.ThrowIfCancellationRequested(); var trackPoints = trackSegments.ElementAt(curTrkSeg).TrackPoints; for (var curTrkPt = _resumeTrackPt.Value; curTrkPt < trackPoints.Count; curTrkPt++) { _resumeTrackPt = 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 lat = Convert.ToDouble(trackPoints.ElementAt(curTrkPt).Lat, CultureInfo.InvariantCulture); var lng = Convert.ToDouble(trackPoints.ElementAt(curTrkPt).Lon, CultureInfo.InvariantCulture); IGeoLocation destination = new GPXPointLocation(lat, lng, LocationUtils.getElevation(session.ElevationService, lat, lng)); await session.Navigation.Move(destination, async() => { await MSniperServiceTask.Execute(session, cancellationToken); await CatchNearbyPokemonsTask.Execute(session, cancellationToken); //Catch Incense Pokemon await CatchIncensePokemonsTask.Execute(session, cancellationToken); await UseNearbyPokestopsTask.Execute(session, cancellationToken); }, session, cancellationToken); await eggWalker.ApplyDistance(distance, cancellationToken); // Return to FarmState/StateMachine if we have reached both user defined limits if ((UseNearbyPokestopsTask._pokestopLimitReached || UseNearbyPokestopsTask._pokestopTimerReached) && (CatchPokemonTask._catchPokemonLimitReached || CatchPokemonTask._catchPokemonTimerReached)) { return; } } //end trkpts _resumeTrackPt = 0; } //end trksegs _resumeTrackSeg = 0; } //end tracks _resumeTrack = 0; }
public static async Task Execute(ISession session, CancellationToken cancellationToken, Func <double, double, Task> actionWhenWalking = null, Func <Task> afterCatchFunc = null) { pokestopCount++; pokestopCount = pokestopCount % 3; if (pokestopCount > 0 && !prioritySnipeFlag) { return; } InitSession(session); if (!_setting.CatchPokemon && !prioritySnipeFlag) { return; } cancellationToken.ThrowIfCancellationRequested(); if (_setting.HumanWalkingSnipeTryCatchEmAll) { var checkBall = await CheckPokeballsToSnipe(_setting.HumanWalkingSnipeCatchEmAllMinBalls, session, cancellationToken); if (!checkBall && !prioritySnipeFlag) { return; } } bool keepWalking = true; bool caughtAnyPokemonInThisWalk = false; while (keepWalking) { prioritySnipeFlag = false; var pokemons = GetRarePokemons(session.Client.CurrentLatitude, session.Client.CurrentLongitude, !caughtAnyPokemonInThisWalk); foreach (var pokemon in pokemons) { caughtAnyPokemonInThisWalk = true; CalculateDistanceAndEstTime(pokemon); var remainTimes = (pokemon.expired - DateTime.Now).TotalSeconds * 0.95; //just use 90% times var catchPokemonTimeEST = (pokemon.distance / 100) * 10; //assume that 100m we catch 1 pokemon and it took 10 second for each. string strPokemon = session.Translation.GetPokemonTranslation(pokemon.Id); var spinPokestopEST = (pokemon.distance / 100) * 5; bool catchPokemon = (pokemon.estimateTime + catchPokemonTimeEST) < remainTimes && pokemon.FilterSetting.CatchPokemonWhileWalking; bool spinPokestop = pokemon.FilterSetting.SpinPokestopWhileWalking && (pokemon.estimateTime + catchPokemonTimeEST + spinPokestopEST) < remainTimes; pokemon.catching = true; session.EventDispatcher.Send(new HumanWalkSnipeEvent() { PokemonId = pokemon.Id, Latitude = pokemon.latitude, Longitude = pokemon.longitude, Distance = pokemon.distance, Expires = (pokemon.expired - DateTime.Now).TotalSeconds, Estimate = (int)pokemon.estimateTime, Setting = pokemon.FilterSetting, CatchPokemon = catchPokemon, Pokemons = rarePokemons, SpinPokeStop = pokemon.FilterSetting.SpinPokestopWhileWalking, WalkSpeedApplied = pokemon.FilterSetting.AllowSpeedUp ? pokemon.FilterSetting.MaxSpeedUpSpeed : _session.LogicSettings.WalkingSpeedInKilometerPerHour, Type = HumanWalkSnipeEventTypes.StartWalking }); await session.Navigation.Move(new GeoCoordinate(pokemon.latitude, pokemon.longitude, LocationUtils.getElevation(session, pokemon.latitude, pokemon.longitude)), async() => { var distance = LocationUtils.CalculateDistanceInMeters(pokemon.latitude, pokemon.longitude, session.Client.CurrentLatitude, session.Client.CurrentLongitude); if (catchPokemon && distance > 80.0) { // Catch normal map Pokemon await CatchNearbyPokemonsTask.Execute(session, cancellationToken); } if (actionWhenWalking != null && spinPokestop) { await actionWhenWalking(session.Client.CurrentLatitude, session.Client.CurrentLongitude); } return(true); }, session, cancellationToken, pokemon.FilterSetting.AllowSpeedUp?pokemon.FilterSetting.MaxSpeedUpSpeed : 0); session.EventDispatcher.Send(new HumanWalkSnipeEvent() { Latitude = pokemon.latitude, Longitude = pokemon.longitude, Type = HumanWalkSnipeEventTypes.DestinationReached }); await Task.Delay(2000); await CatchNearbyPokemonsTask.Execute(session, cancellationToken, pokemon.Id); await CatchIncensePokemonsTask.Execute(session, cancellationToken); pokemon.visited = true; pokemon.catching = false; } keepWalking = _setting.HumanWalkingSnipeTryCatchEmAll && pokemons.Count > 0; } if (caughtAnyPokemonInThisWalk && !_setting.HumanWalkingSnipeAlwaysWalkBack) { await afterCatchFunc?.Invoke(); } }
public static async Task Execute(ISession session, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var pokestopsTuple = await GetPokeStops(session); pokestopList = pokestopsTuple.Item2; while (pokestopList.Any()) { cancellationToken.ThrowIfCancellationRequested(); await SnipeMSniperTask.CheckMSniperLocation(session, cancellationToken); pokestopList = pokestopList.OrderBy( i => LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude, session.Client.CurrentLongitude, i.Latitude, i.Longitude)).ToList(); // randomize next pokestop between first and second by distance var pokestopListNum = 0; if (pokestopList.Count > 1) { pokestopListNum = rc.Next(0, 2); } var pokeStop = pokestopList[pokestopListNum]; pokestopList.RemoveAt(pokestopListNum); // this logic should only be called when we reach a pokestop either via GPX path or normal walking // as when walk-sniping, we want to get to the snipe ASAP rather than stop for lured pokemon upon // calling FarmPokestop; in that situation we are also always within 40m of the pokestop, so no // need to walk to it var fortInfo = await session.Client.Fort.GetFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude); // we only move to the PokeStop, and send the associated FortTargetEvent, when not using GPX // also, GPX pathing uses its own EggWalker and calls the CatchPokemon tasks internally. if (!session.LogicSettings.UseGpxPathing) { var eggWalker = new EggWalker(1000, session); var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude, session.Client.CurrentLongitude, pokeStop.Latitude, pokeStop.Longitude); cancellationToken.ThrowIfCancellationRequested(); if (!session.LogicSettings.UseGoogleWalk && !session.LogicSettings.UseYoursWalk) { session.EventDispatcher.Send(new FortTargetEvent { Name = fortInfo.Name, Distance = distance, Route = "NecroBot" }); } else { BaseWalkStrategy.FortInfo = fortInfo; } await session.Navigation.Move(new GeoCoordinate(pokeStop.Latitude, pokeStop.Longitude, LocationUtils.getElevation(session, pokeStop.Latitude, pokeStop.Longitude)), async() => { // Catch normal map Pokemon await CatchNearbyPokemonsTask.Execute(session, cancellationToken); //Catch Incense Pokemon await CatchIncensePokemonsTask.Execute(session, cancellationToken); // Minor fix google route ignore pokestop await LookPokestops(session, pokeStop, cancellationToken); return(true); }, session, cancellationToken); // we have moved this distance, so apply it immediately to the egg walker. await eggWalker.ApplyDistance(distance, cancellationToken); } await FortAction(session, pokeStop, fortInfo, cancellationToken); if (session.LogicSettings.SnipeAtPokestops || session.LogicSettings.UseSnipeLocationServer) { await SnipePokemonTask.Execute(session, cancellationToken); } if (session.LogicSettings.EnableHumanWalkingSnipe) { //refactore to move this code inside the task later. await HumanWalkSnipeTask.Execute(session, cancellationToken, async (double lat, double lng) => { //idea of this function is to spin pokestop on way. maybe risky. var reachablePokestops = pokestopList.Where(i => LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude, session.Client.CurrentLongitude, i.Latitude, i.Longitude) < 40 && i.CooldownCompleteTimestampMs == 0 ).ToList(); reachablePokestops = reachablePokestops.OrderBy(i => LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude, session.Client.CurrentLongitude, i.Latitude, i.Longitude)).ToList(); foreach (var ps in reachablePokestops) { if (!session.LogicSettings.UseGpxPathing) { pokestopList.Remove(ps); } var fi = await session.Client.Fort.GetFort(ps.Id, ps.Latitude, ps.Longitude); await FarmPokestop(session, ps, fi, cancellationToken, true); await Task.Delay(2000); } }, async() => { // if using GPX we have to move back to the original pokestop, to resume the path. // we do not try to use pokest;ops on the way back, as we will have used them getting // here. if (session.LogicSettings.UseGpxPathing) { var eggWalker = new EggWalker(1000, session); var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude, session.Client.CurrentLongitude, pokeStop.Latitude, pokeStop.Longitude); var geo = new GeoCoordinate(pokeStop.Latitude, pokeStop.Longitude); await session.Navigation.Move(geo, async() => { await CatchNearbyPokemonsTask.Execute(session, cancellationToken); //Catch Incense Pokemon await CatchIncensePokemonsTask.Execute(session, cancellationToken); return(true); }, session, cancellationToken); await eggWalker.ApplyDistance(distance, cancellationToken); return; } var nearestStop = pokestopList.OrderBy(i => LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude, session.Client.CurrentLongitude, i.Latitude, i.Longitude)).FirstOrDefault(); var walkedDistance = LocationUtils.CalculateDistanceInMeters(nearestStop.Latitude, nearestStop.Longitude, session.Client.CurrentLatitude, session.Client.CurrentLongitude); if (walkedDistance > session.LogicSettings.HumanWalkingSnipeWalkbackDistanceLimit) { await Task.Delay(3000); var nearbyPokeStops = await UpdateFortsData(session); var notexists = nearbyPokeStops.Where(p => !pokestopList.Any(x => x.Id == p.Id)).ToList(); pokestopList.AddRange(notexists); session.EventDispatcher.Send(new PokeStopListEvent { Forts = pokestopList }); session.EventDispatcher.Send(new HumanWalkSnipeEvent() { Type = HumanWalkSnipeEventTypes.PokestopUpdated, Pokestops = notexists, NearestDistance = walkedDistance }); } }); } } }
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)), session.LogicSettings.WalkingSpeedInKilometerPerHour, null, cancellationToken, session.LogicSettings.DisableHumanWalking); } var pokestopList = await GetPokeStops(session); 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 }); while (pokestopList.Any()) { cancellationToken.ThrowIfCancellationRequested(); //resort var pokestopListWithDetails = pokestopList .Select(p => { Boolean useNav = session.LogicSettings.UseOsmNavigation && LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude, session.Client.CurrentLongitude, p.Latitude, p.Longitude) > session.LogicSettings.OsmMinDistanceInMeter; String uri = useNav ? string.Format(_CultureEnglish, "http://www.yournavigation.org/api/1.0/gosmore.php?flat={0:0.000000}&flon={1:0.000000}&tlat={2:0.000000}&tlon={3:0.000000}&v=foot", session.Client.CurrentLatitude, session.Client.CurrentLongitude, p.Latitude, p.Longitude) : null; XDocument doc = useNav ? XDocument.Load(uri) : null; XNamespace kmlns = useNav ? XNamespace.Get("http://earth.google.com/kml/2.0") : null; var points = !useNav ? null : doc.Element(kmlns + "kml") .Element(kmlns + "Document") .Element(kmlns + "Folder") .Element(kmlns + "Placemark") .Element(kmlns + "LineString") .Element(kmlns + "coordinates") .Value .Trim() .Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries) .Select(pp => { String[] parts = pp.Split(','); return(new { Latitude = double.Parse(parts[1], _CultureEnglish), Longitude = double.Parse(parts[0], _CultureEnglish), }); }) .ToArray(); Double dist = useNav ? new Func <double>(() => { Double d = 0d; for (int i = 1; i < points.Length; i++) { d += LocationUtils.CalculateDistanceInMeters ( points[i - 1].Latitude, points[i - 1].Longitude, points[i].Latitude, points[i].Longitude ); } return(d); })() : LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude, session.Client.CurrentLongitude, p.Latitude, p.Longitude); return(new { PokeStop = p, UseOSM = useNav, Distance = dist, NavigationDocumentUri = uri, NavigationDocument = doc, NavigationDocumentNamespace = kmlns, Points = points }); }) .OrderBy(p => p.Distance) .ToList(); // randomize next pokestop between first and second by distance var pokestopListNum = 0; if (pokestopList.Count > 1) { pokestopListNum = rc.Next(0, 2); } var pokeStop = pokestopListWithDetails[pokestopListNum]; pokestopList.Remove(pokeStop.PokeStop); var distance = pokeStop.Distance; var fortInfo = await session.Client.Fort.GetFort(pokeStop.PokeStop.Id, pokeStop.PokeStop.Latitude, pokeStop.PokeStop.Longitude); session.EventDispatcher.Send(new FortTargetEvent { Name = fortInfo.Name, Distance = distance }); if (pokeStop.UseOSM) { var points = pokeStop.Points; if (points.Any()) { foreach (var step in points) { await MoveToLocationAsync(session, cancellationToken, step.Latitude, step.Longitude); } } } //Why no else? Just to be sure =) await MoveToLocationAsync(session, cancellationToken, pokeStop.PokeStop.Latitude, pokeStop.PokeStop.Longitude); //Catch Lure Pokemon if (pokeStop.PokeStop.LureInfo != null) { await CatchLurePokemonsTask.Execute(session, pokeStop.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.PokeStop.Id, pokeStop.PokeStop.Latitude, pokeStop.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.PokeStop.Id, Name = fortInfo.Name, Exp = fortSearch.ExperienceAwarded, Gems = fortSearch.GemsAwarded, Items = StringUtils.GetSummedFriendlyNameOfItemAwardList(fortSearch.ItemsAwarded), Latitude = pokeStop.PokeStop.Latitude, Longitude = pokeStop.PokeStop.Longitude, InventoryFull = fortSearch.Result == FortSearchResponse.Types.Result.InventoryFull }); if (fortSearch.Result == FortSearchResponse.Types.Result.InventoryFull) { storeRI = 1; } 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 (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); } } }
private static async Task FortPokestop(ISession session, CancellationToken cancellationToken, FortData pokeStop) { var fortInfo = await session.Client.Fort.GetFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude); // we only move to the PokeStop, and send the associated FortTargetEvent, when not using GPX // also, GPX pathing uses its own EggWalker and calls the CatchPokemon tasks internally. if (!session.LogicSettings.UseGpxPathing) { var eggWalker = new EggWalker(1000, session); var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude, session.Client.CurrentLongitude, pokeStop.Latitude, pokeStop.Longitude); cancellationToken.ThrowIfCancellationRequested(); if (!session.LogicSettings.UseGoogleWalk && !session.LogicSettings.UseYoursWalk) { session.EventDispatcher.Send(new FortTargetEvent { Name = fortInfo.Name, Distance = distance, Route = "NecroBot" }); } else { BaseWalkStrategy.FortInfo = fortInfo; } await session.Navigation.Move(new GeoCoordinate(pokeStop.Latitude, pokeStop.Longitude, LocationUtils.getElevation(pokeStop.Latitude, pokeStop.Longitude)), async() => { // Catch normal map Pokemon await CatchNearbyPokemonsTask.Execute(session, cancellationToken); //Catch Incense Pokemon await CatchIncensePokemonsTask.Execute(session, cancellationToken); return(true); }, session, cancellationToken); // we have moved this distance, so apply it immediately to the egg walker. await eggWalker.ApplyDistance(distance, cancellationToken); } //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(); if (SearchThresholdExceeds(session)) { break; } 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; } session.Stats.PokeStopTimestamps.Add(DateTime.Now.Ticks); 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 (session.LogicSettings.RandomlyPauseAtStops) { if (++RandomStop >= RandomNumber) { RandomNumber = rc.Next(4, 11); RandomStop = 0; int RandomWaitTime = rc.Next(30, 120); Thread.Sleep(RandomWaitTime); } } }
public async Task <PlayerUpdateResponse> Walk(GeoCoordinate targetLocation, Func <Task <bool> > functionExecutedWhileWalking, ISession session, CancellationToken cancellationToken) { var curLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude); var dist = LocationUtils.CalculateDistanceInMeters(curLocation, targetLocation); if (dist >= 100) { var nextWaypointDistance = dist * 70 / 100; var nextWaypointBearing = LocationUtils.DegreeBearing(curLocation, targetLocation); var waypoint = LocationUtils.CreateWaypoint(curLocation, nextWaypointDistance, nextWaypointBearing); var sentTime = DateTime.Now; var result = await _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude); UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude); do { cancellationToken.ThrowIfCancellationRequested(); var millisecondsUntilGetUpdatePlayerLocationResponse = (DateTime.Now - sentTime).TotalMilliseconds; curLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude); var currentDistanceToTarget = LocationUtils.CalculateDistanceInMeters(curLocation, targetLocation); dist = LocationUtils.CalculateDistanceInMeters(curLocation, targetLocation); if (dist >= 100) { nextWaypointDistance = dist * 70 / 100; } else { nextWaypointDistance = dist; } nextWaypointBearing = LocationUtils.DegreeBearing(curLocation, targetLocation); waypoint = LocationUtils.CreateWaypoint(curLocation, nextWaypointDistance, nextWaypointBearing); sentTime = DateTime.Now; result = await _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude); UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude); if (functionExecutedWhileWalking != null) { await functionExecutedWhileWalking(); // look for pokemon } } while (LocationUtils.CalculateDistanceInMeters(curLocation, targetLocation) >= 10); return(result); } else { var result = await _client.Player.UpdatePlayerLocation(targetLocation.Latitude, targetLocation.Longitude, LocationUtils.getElevation(targetLocation.Latitude, targetLocation.Longitude)); UpdatePositionEvent?.Invoke(targetLocation.Latitude, targetLocation.Longitude); if (functionExecutedWhileWalking != null) { await functionExecutedWhileWalking(); // look for pokemon } return(result); } }