Exemplo n.º 1
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var eggWalker = new EggWalker(1000, session);

            session.EventDispatcher.Send(new WarnEvent
            {
                Message = $"ForceMove to {session.ForceMoveTo.Latitude} - {session.ForceMoveTo.Longitude} Started!"
            });


            var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                   session.Client.CurrentLongitude, session.ForceMoveTo.Latitude, session.ForceMoveTo.Longitude);

            if (session.LogicSettings.Teleport)
            {
                await session.Client.Player.UpdatePlayerLocation(session.ForceMoveTo.Latitude, session.ForceMoveTo.Longitude,
                                                                 session.Client.Settings.DefaultAltitude);
            }
            else
            {
                await session.Navigation.HumanLikeWalking(new GeoCoordinate(session.ForceMoveTo.Latitude, session.ForceMoveTo.Longitude),
                                                          session.LogicSettings.WalkingSpeedInKilometerPerHour,
                                                          async() =>
                {
                    // Catch normal map Pokemon
                    await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
                    //Catch Incense Pokemon
                    await CatchIncensePokemonsTask.Execute(session, cancellationToken);
                    return(true);
                }, cancellationToken);
            }

            session.EventDispatcher.Send(new WarnEvent
            {
                Message = $"ForceMove Done!"
            });
            session.ForceMoveTo = null;
            session.EventDispatcher.Send(new ForceMoveDoneEvent());

            if (session.LogicSettings.Teleport)
            {
                await Task.Delay(session.LogicSettings.DelayPokestop);
            }
            else
            {
                await Task.Delay(1000, cancellationToken);
            }

            await eggWalker.ApplyDistance(distance, cancellationToken);


            if (session.LogicSettings.SnipeAtPokestops || session.LogicSettings.UseSnipeLocationServer)
            {
                await SnipePokemonTask.Execute(session, cancellationToken);
            }
        }
Exemplo n.º 2
0
        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(0).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 = session.MapCache.baseFortDatas.ToList()
                        });

                        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)
                            {
                                session.EventDispatcher.Send(new DebugEvent()
                                {
                                    Message = "This pokestop has a lure!"
                                });
                                await CatchLurePokemonsTask.Execute(session, pokeStop.BaseFortData, 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
                                });
                                session.MapCache.UsedPokestop(pokeStop, session);
                            }
                            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.SnipeAtPokestops || session.LogicSettings.UseSnipeLocationServer)
                            {
                                await SnipePokemonTask.Execute(session, cancellationToken);
                            }

                            if (session.LogicSettings.EvolveAllPokemonWithEnoughCandy ||
                                session.LogicSettings.EvolveAllPokemonAboveIv)
                            {
                                await EvolvePokemonTask.Execute(session, cancellationToken);
                            }

                            if (session.LogicSettings.TransferDuplicatePokemon)
                            {
                                await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
                            }

                            if (session.LogicSettings.RenamePokemon)
                            {
                                await RenamePokemonTask.Execute(session, cancellationToken);
                            }
                        }

                        var targetLocation = new GeoCoordinate(Convert.ToDouble(trackPoints.ElementAt(curTrkPt).Lat, CultureInfo.InvariantCulture),
                                                               Convert.ToDouble(trackPoints.ElementAt(curTrkPt).Lon, CultureInfo.InvariantCulture));

                        Navigation navi = new Navigation(session.Client);
                        navi.UpdatePositionEvent += (lat, lng, alt) =>
                        {
                            session.EventDispatcher.Send(new UpdatePositionEvent {
                                Latitude = lat, Longitude = lng, Altitude = alt
                            });
                        };
                        var nextMoveSpeed = session.Client.rnd.NextInRange(session.LogicSettings.WalkingSpeedMin, session.LogicSettings.WalkingSpeedMax) * session.Settings.MoveSpeedFactor;

                        session.State = BotState.Walk;
                        await navi.HumanPathWalking(
                            session,
                            targetLocation,
                            nextMoveSpeed,
                            async() =>
                        {
                            await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
                            //Catch Incense Pokemon
                            await CatchIncensePokemonsTask.Execute(session, cancellationToken);

                            return(true);
                        },
                            async() =>
                        {
                            await UseNearbyPokestopsTask.Execute(session, cancellationToken);
                            return(true);
                        },
                            cancellationToken
                            );

                        session.State = BotState.Idle;

                        await eggWalker.ApplyDistance(distance, cancellationToken);
                    } //end trkpts
                }     //end trksegs
            }         //end tracks
        }
Exemplo n.º 3
0
        public static async Task Teleport(ISession session, CancellationToken cancellationToken, Random random)
        {
            bool ShownSoftBanMessage = false;
            int  stopsToHit          = 20; //We should return to the main loop after some point, might as well limit this.
            //Not sure where else we could put this? Configs maybe if we incorporate
            //deciding how many pokestops in a row we want to hit before doing things like recycling?
            //might increase xp/hr not stopping every 5 stops. - Pocket


            //TODO: run through this with a fine-tooth comb and optimize it.
            var pokestopList = await GetPokeStops(session);

            for (int stopsHit = 0; stopsHit < stopsToHit; stopsHit++)
            {
                RuntimeSettings.BreakOutOfPathing = false;
                if (pokestopList.Count > 0)
                {
                    //start at 0 ends with 19 = 20 for the leechers{
                    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)
                    {
                        session.EventDispatcher.Send(new WarnEvent()
                        {
                            Message = session.Translation.GetTranslation(TranslationString.FarmPokestopsOutsideRadius, distanceFromStart)
                        });
                        await Task.Delay(1000, cancellationToken);

                        await session.Navigation.Move(
                            new GeoCoordinate(session.Settings.DefaultLatitude, session.Settings.DefaultLongitude),
                            session.LogicSettings.WalkingSpeedMin, session.LogicSettings.WalkingSpeedMax, null, null, cancellationToken, session);
                    }
                    if (session.ForceMoveJustDone)
                    {
                        session.ForceMoveJustDone = false;
                    }
                    if (session.ForceMoveTo != null)
                    {
                        await ForceMoveTask.Execute(session, cancellationToken);

                        pokestopList = await GetPokeStops(session);
                    }


                    var displayStatsHit = 0;
                    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 = session.MapCache.baseFortDatas.ToList()
                    });

                    cancellationToken.ThrowIfCancellationRequested();

                    //resort
                    pokestopList =
                        pokestopList.OrderBy(
                            i =>
                            LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                    session.Client.CurrentLongitude, i.Latitude, i.Longitude)).ToList();

                    if (session.LogicSettings.UsePokeStopLuckyNumber)
                    {
                        if (pokestopList.Count >= session.LogicSettings.PokestopSkipLuckyNumberMinUse)
                        {
                            int rng = random.Next(session.LogicSettings.PokestopSkipLuckyMin, session.LogicSettings.PokestopSkipLuckyMax);
#if DEBUG
                            Logger.Write("Skip Pokestop RNG: " + rng.ToString() + " against " + session.LogicSettings.PokestopSkipLuckyNumber.ToString(), LogLevel.Debug);
#endif
                            if (rng == session.LogicSettings.PokestopSkipLuckyNumber)
                            {
#if DEBUG
                                Logger.Write("Skipping Pokestop due to the rng god's will.", LogLevel.Debug);
#endif
                                pokestopList.RemoveAt(0);
                            }
                        }
                    }


                    var pokeStop = pokestopList[0];
                    pokestopList.RemoveAt(0);
                    RuntimeSettings.TargetStopID = pokeStop.Id;
                    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 {
                        Id = fortInfo.FortId, Name = fortInfo.Name, Distance = distance, Latitude = fortInfo.Latitude, Longitude = fortInfo.Longitude, Description = fortInfo.Description, url = fortInfo.ImageUrls[0]
                    });
                    if (session.LogicSettings.Teleport)
                    {
                        await session.Client.Player.UpdatePlayerLocation(fortInfo.Latitude, fortInfo.Longitude,
                                                                         session.Client.Settings.DefaultAltitude);
                    }

                    else
                    {
                        await session.Navigation.Move(new GeoCoordinate(pokeStop.Latitude, pokeStop.Longitude),
                                                      session.LogicSettings.WalkingSpeedMin, session.LogicSettings.WalkingSpeedMax,
                                                      async() =>
                        {
                            if (session.LogicSettings.CatchWildPokemon)
                            {
                                // Catch normal map Pokemon
                                await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
                                //Catch Incense Pokemon remove this for time contraints
                                //await CatchIncensePokemonsTask.Execute(session, cancellationToken);
                            }
                            return(true);
                        },
                                                      async() =>
                        {
                            await UseNearbyPokestopsTask.Execute(session, cancellationToken);
                            return(true);
                        },

                                                      cancellationToken, session);
                    }
                    if (!session.ForceMoveJustDone)
                    {
                        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
                        if (RuntimeSettings.BreakOutOfPathing)
                        {
                            continue;
                        }
                        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;

                                    if (!ShownSoftBanMessage)
                                    {
                                        session.EventDispatcher.Send(new FortFailedEvent
                                        {
                                            Name = fortInfo.Name,
                                            Try  = fortTry,
                                            Max  = retryNumber - zeroCheck
                                        });
                                        ShownSoftBanMessage = true;
                                    }
                                    await Task.Delay(session.LogicSettings.DelaySoftbanRetry);
                                }
                            }
                            else
                            {
                                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,
                                    Description   = fortInfo.Description,
                                    url           = fortInfo.ImageUrls[0]
                                });
                                session.MapCache.UsedPokestop(pokeStop);
                                session.EventDispatcher.Send(new InventoryNewItemsEvent()
                                {
                                    Items = fortSearch.ItemsAwarded.ToItemList()
                                });
                                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.

                        ShownSoftBanMessage = false;
                        await Task.Delay(session.LogicSettings.DelayPokestop);


                        //Catch Lure Pokemon

                        if (session.LogicSettings.CatchWildPokemon)
                        {
                            if (pokeStop.LureInfo != null)
                            {
                                await CatchLurePokemonsTask.Execute(session, pokeStop.BaseFortData, cancellationToken);
                            }
                            // Catch normal map Pokemon
                            if (session.LogicSettings.Teleport)
                            {
                                await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
                            }
                            //Catch Incense Pokemon
                            await CatchIncensePokemonsTask.Execute(session, cancellationToken);
                        }


                        await eggWalker.ApplyDistance(distance, cancellationToken);

                        if (++stopsHit % 5 == 0) //TODO: OR item/pokemon bag is full
                        {
                            // need updated stardust information for upgrading, so refresh your profile now
                            await DownloadProfile(session);

                            if (fortSearch.ItemsAwarded.Count > 0)
                            {
                                await session.Inventory.RefreshCachedInventory();
                            }
                            await RecycleItemsTask.Execute(session, cancellationToken);

                            if (session.LogicSettings.EvolveAllPokemonWithEnoughCandy ||
                                session.LogicSettings.EvolveAllPokemonAboveIv)
                            {
                                await EvolvePokemonTask.Execute(session, cancellationToken);
                            }
                            if (session.LogicSettings.AutomaticallyLevelUpPokemon)
                            {
                                await LevelUpPokemonTask.Execute(session, cancellationToken);
                            }
                            if (session.LogicSettings.TransferDuplicatePokemon)
                            {
                                await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
                            }
                            if (session.LogicSettings.RenamePokemon)
                            {
                                await RenamePokemonTask.Execute(session, cancellationToken);
                            }
                            if (++displayStatsHit >= 4)
                            {
                                await DisplayPokemonStatsTask.Execute(session);
                            }
                        }
                    }
                    if (session.LogicSettings.SnipeAtPokestops || session.LogicSettings.UseSnipeLocationServer)
                    {
                        await SnipePokemonTask.Execute(session, cancellationToken);
                    }
                }
            }
        }
Exemplo n.º 4
0
        public static async Task NoTeleport(ISession session, CancellationToken cancellationToken, Random random)
        {
            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)
            {
                session.EventDispatcher.Send(new WarnEvent()
                {
                    Message = session.Translation.GetTranslation(TranslationString.FarmPokestopsOutsideRadius, distanceFromStart)
                });
                await Task.Delay(1000, cancellationToken);

                await session.Navigation.Move(
                    new GeoCoordinate(session.Settings.DefaultLatitude, session.Settings.DefaultLongitude),
                    session.LogicSettings.WalkingSpeedMin, session.LogicSettings.WalkingSpeedMax, null, null, cancellationToken, session);
            }

            var pokestopList = await GetPokeStops(session);

            //var stopsHit = 0; //Replaced with RuntimeSettings.stopsHit;
            //var displayStatsHit = 0;
            var eggWalker = new EggWalker(1000, session);

            if (pokestopList.Count <= 0)
            {
                session.EventDispatcher.Send(new WarnEvent
                {
                    Message = session.Translation.GetTranslation(TranslationString.FarmPokestopsNoUsableFound)
                });
            }

            while (pokestopList.Any())
            {
                RuntimeSettings.BreakOutOfPathing = false;
                cancellationToken.ThrowIfCancellationRequested();
                if (session.ForceMoveJustDone)
                {
                    session.ForceMoveJustDone = false;
                }
                if (session.ForceMoveTo != null)
                {
                    await ForceMoveTask.Execute(session, cancellationToken);

                    pokestopList = await GetPokeStops(session);
                }

                //resort
                pokestopList =
                    pokestopList.OrderBy(
                        i =>
                        LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                session.Client.CurrentLongitude, i.Latitude, i.Longitude)).ToList();

                if (session.LogicSettings.UsePokeStopLuckyNumber)
                {
                    if (pokestopList.Count >= session.LogicSettings.PokestopSkipLuckyNumberMinUse)
                    {
                        int rng = random.Next(session.LogicSettings.PokestopSkipLuckyMin, session.LogicSettings.PokestopSkipLuckyMax);
#if DEBUG
                        Logger.Write("Skip Pokestop RNG: " + rng.ToString() + " against " + session.LogicSettings.PokestopSkipLuckyNumber.ToString(), LogLevel.Debug);
#endif
                        if (rng == session.LogicSettings.PokestopSkipLuckyNumber)
                        {
#if DEBUG
                            Logger.Write("Skipping Pokestop due to the rng god's will.", LogLevel.Debug);
#endif
                            pokestopList.RemoveAt(0);
                        }
                    }
                }

                var pokeStop = pokestopList[0];
                pokestopList.RemoveAt(0);
                RuntimeSettings.TargetStopID = pokeStop.Id;
                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 {
                    Id = fortInfo.FortId, Name = fortInfo.Name, Distance = distance, Latitude = fortInfo.Latitude, Longitude = fortInfo.Longitude, Description = fortInfo.Description, url = fortInfo.ImageUrls?.Count > 0 ? fortInfo.ImageUrls[0] : ""
                });

                await session.Navigation.Move(new GeoCoordinate(pokeStop.Latitude, pokeStop.Longitude),
                                              session.LogicSettings.WalkingSpeedMin, session.LogicSettings.WalkingSpeedMax,
                                              async() =>
                {
                    if (session.LogicSettings.CatchWildPokemon)
                    {
                        // Catch normal map Pokemon
                        await CatchNearbyPokemonsTask.Execute(session, cancellationToken);

                        //Catch Incense Pokemon remove this for time constraints
                        //await CatchIncensePokemonsTask.Execute(session, cancellationToken);
                    }
                    return(true);
                },
                                              async() =>
                {
                    await UseNearbyPokestopsTask.Execute(session, cancellationToken);
                    return(true);
                },
                                              cancellationToken, session);

                if (!session.ForceMoveJustDone)
                {
                    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
                    if (RuntimeSettings.BreakOutOfPathing)
                    {
                        continue;
                    }
                    do
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        if (pokeStop.CooldownCompleteTimestampMS < DateTime.UtcNow.ToUnixTime())
                        {
                            break;                                                                      //already looted somehow
                        }
                        var fortSearch = await session.Client.Fort.SearchFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude);

                        if (fortSearch.Result == FortSearchResponse.Types.Result.InventoryFull)
                        {
                            await RecycleItemsTask.Execute(session, cancellationToken);
                        }
                        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;


                                if (session.LogicSettings.Teleport)
                                {
                                    session.EventDispatcher.Send(new FortFailedEvent
                                    {
                                        Name = fortInfo.Name,
                                        Try  = fortTry,
                                        Max  = retryNumber - zeroCheck
                                    });
                                    await Task.Delay(session.LogicSettings.DelaySoftbanRetry, cancellationToken);
                                }
                                else
                                {
                                    await DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 400);
                                }
                            }
                        }
                        else
                        {
                            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,
                                Description   = fortInfo.Description,
                                url           = fortInfo.ImageUrls?[0]
                            });
                            RuntimeSettings.StopsHit++;
                            session.EventDispatcher.Send(new InventoryNewItemsEvent()
                            {
                                Items = fortSearch.ItemsAwarded.ToItemList()
                            });
                            session.MapCache.UsedPokestop(pokeStop);
                            break; //Continue with program as loot was succesfull.
                        }
                    } while (fortTry < 1);
                    //retryNumber - zeroCheck && fortSearch.CooldownCompleteTimestampMs < DateTime.UtcNow.ToUnixTime());
                    //Stop trying if softban is cleaned earlier or if 40 times fort looting failed.


                    await Task.Delay(session.LogicSettings.DelayPokestop, cancellationToken);


                    //Catch Lure Pokemon

                    if (session.LogicSettings.CatchWildPokemon)
                    {
                        if (pokeStop.LureInfo != null)
                        {
                            await CatchLurePokemonsTask.Execute(session, pokeStop.BaseFortData, cancellationToken);
                        }
                        if (session.LogicSettings.Teleport)
                        {
                            await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
                        }
                    }
                    await eggWalker.ApplyDistance(distance, cancellationToken);
                }
                if (session.LogicSettings.SnipeAtPokestops || session.LogicSettings.UseSnipeLocationServer)
                {
                    await SnipePokemonTask.Execute(session, cancellationToken);
                }
            }
        }
Exemplo n.º 5
0
        public static async Task NoTeleport(ISession session, CancellationToken cancellationToken, Random random)
        {
            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)
            {
                session.EventDispatcher.Send(new WarnEvent
                {
                    Message = session.Translation.GetTranslation(TranslationString.FarmPokestopsOutsideRadius, distanceFromStart)
                });
                await Task.Delay(1000, cancellationToken);

                await session.Navigation.Move(
                    new GeoCoordinate(session.Settings.DefaultLatitude, session.Settings.DefaultLongitude),
                    session.LogicSettings.WalkingSpeedMin, session.LogicSettings.WalkingSpeedMax, null, null, cancellationToken, session);
            }

            var pokestopList = await GetPokeStops(session);

            //var stopsHit = 0; //Replaced with RuntimeSettings.stopsHit;
            //var displayStatsHit = 0;

            session.EventDispatcher.Send(new PokeStopListEvent {
                Forts = pokestopList.Select(x => x.BaseFortData).ToList()
            });

            if (session.LogicSettings.UseEggIncubators && !session.EggWalker.Inited)
            {
                await session.EggWalker.InitEggWalker(cancellationToken);
            }

            if (pokestopList.Count <= 0)
            {
                if (!pokestopList.Any())
                {
                    await CheckChallengeDoneTask.Execute(session, cancellationToken);

                    await CheckChallengeTask.Execute(session, cancellationToken);
                }
                session.EventDispatcher.Send(new WarnEvent
                {
                    Message = session.Translation.GetTranslation(TranslationString.FarmPokestopsNoUsableFound)
                });
            }


            if (session.ForceMoveToResume != null && session.ForceMoveTo == null)
            {
                session.EventDispatcher.Send(new NoticeEvent
                {
                    Message = session.Translation.GetTranslation(TranslationString.UnDoneForceMove, session.ForceMoveToResume.Latitude, session.ForceMoveToResume.Longitude)
                });
                session.ForceMoveTo = session.ForceMoveToResume;
            }

            var bestRoute = new List <GeoCoordinate>();

            while (pokestopList.Any())
            {
                session.Runtime.BreakOutOfPathing = false;
                cancellationToken.ThrowIfCancellationRequested();

                if (session.ForceMoveTo != null)
                {
                    await ForceMoveTask.Execute(session, cancellationToken);
                }

                if (session.ForceMoveJustDone)
                {
                    session.ForceMoveJustDone = false;
                    pokestopList = await GetPokeStops(session);

                    session.Client.Player.SetInitial(session.Client.CurrentLatitude, session.Client.CurrentLongitude, session.Client.CurrentAltitude);
                    session.EventDispatcher.Send(new PokeStopListEvent {
                        Forts = pokestopList.Select(x => x.BaseFortData).ToList()
                    });
                }


                if (session.LogicSettings.UseCustomRoute && session.LogicSettings.CustomRoute != null &&
                    session.LogicSettings.CustomRoute.RoutePoints.Count > 2)
                {
                    session.EventDispatcher.Send(new NoticeEvent
                    {
                        Message = session.Translation.GetTranslation(TranslationString.CustomRouteEnabled)
                    });
                    break;
                }

                await ActionQueueTask.Execute(session, cancellationToken);

                //resort
                pokestopList =
                    pokestopList.OrderBy(
                        i =>
                        LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                session.Client.CurrentLongitude, i.Latitude, i.Longitude)).ToList();

                if (session.LogicSettings.UsePokeStopLuckyNumber)
                {
                    if (pokestopList.Count >= session.LogicSettings.PokestopSkipLuckyNumberMinUse)
                    {
                        int rng = random.Next(session.LogicSettings.PokestopSkipLuckyMin, session.LogicSettings.PokestopSkipLuckyMax);
#if DEBUG
                        Logger.Write("Skip Pokestop RNG: " + rng + " against " + session.LogicSettings.PokestopSkipLuckyNumber, LogLevel.Debug);
#endif
                        if (rng == session.LogicSettings.PokestopSkipLuckyNumber)
                        {
#if DEBUG
                            Logger.Write("Skipping Pokestop due to the rng god's will.", LogLevel.Debug);
#endif
                            if (pokestopList.Count > 0)
                            {
                                pokestopList.RemoveAt(0);
                            }
                        }
                    }
                }
                if (pokestopList.Count == 0)
                {
                    break;
                }

                var pokeStop = pokestopList[0];
                pokestopList.RemoveAt(0);

                //prolly no longer needed since MobBot Routing is dead. //Lunatiq
                //if (session.LogicSettings.RoutingService == RoutingService.GoogleDirections || session.LogicSettings.RoutingService == RoutingService.MapzenValhalla)
                //{

                bestRoute = RoutingUtils.GetBestRoute(pokeStop, pokestopList.Where(x => !session.MapCache.CheckPokestopUsed(x)), 20);
                session.EventDispatcher.Send(new PokestopsOptimalPathEvent
                {
                    Coords = bestRoute.Select(x => Tuple.Create(x.Latitude, x.Longitude)).ToList()
                });

                //}

                session.Runtime.TargetStopID = pokeStop.Id;
                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 {
                    Id = fortInfo.FortId, Name = fortInfo.Name, Distance = distance, Latitude = fortInfo.Latitude, Longitude = fortInfo.Longitude, Description = fortInfo.Description, url = fortInfo.ImageUrls?.Count > 0 ? fortInfo.ImageUrls[0] : ""
                });

                await session.Navigation.Move(new GeoCoordinate(pokeStop.Latitude, pokeStop.Longitude),
                                              session.LogicSettings.WalkingSpeedMin, session.LogicSettings.WalkingSpeedMax,
                                              async() =>
                {
                    if (session.LogicSettings.CatchWildPokemon)
                    {
                        // Catch normal map Pokemon
                        await CatchNearbyPokemonsTask.Execute(session, cancellationToken);

                        //Catch Incense Pokemon remove this for time constraints
                        //await CatchIncensePokemonsTask.Execute(session, cancellationToken);
                    }
                    return(true);
                },
                                              async() =>
                {
                    await UseNearbyPokestopsTask.Execute(session, cancellationToken);
                    return(true);
                },
                                              cancellationToken, session, waypointsToVisit : bestRoute);

                if (!session.ForceMoveJustDone)
                {
                    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
                    if (session.Runtime.BreakOutOfPathing)
                    {
                        continue;
                    }
                    do
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        if (pokeStop.CooldownCompleteTimestampMS < DateTime.UtcNow.ToUnixTime())
                        {
                            break;                                                                      //already looted somehow
                        }
                        var fortSearch = await session.Client.Fort.SearchFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude);

                        if (fortSearch.Result == FortSearchResponse.Types.Result.InventoryFull)
                        {
                            await RecycleItemsTask.Execute(session, cancellationToken);
                        }
                        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;


                                if (session.LogicSettings.Teleport)
                                {
                                    session.EventDispatcher.Send(new FortFailedEvent
                                    {
                                        Name = fortInfo.Name,
                                        Try  = fortTry,
                                        Max  = retryNumber - zeroCheck
                                    });
                                    await Task.Delay(session.LogicSettings.DelaySoftbanRetry, cancellationToken);
                                }
                                else
                                {
                                    await DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 400);
                                }
                            }
                        }
                        else
                        {
                            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,
                                Description   = fortInfo.Description,
                                url           = fortInfo.ImageUrls?[0]
                            });
                            session.Runtime.StopsHit++;
                            session.EventDispatcher.Send(new InventoryNewItemsEvent
                            {
                                Items = fortSearch.ItemsAwarded.ToItemList()
                            });

                            if (fortSearch.PokemonDataEgg != null)
                            {
                                session.EventDispatcher.Send(new EggFoundEvent
                                {
                                    Distance     = fortSearch.PokemonDataEgg.EggKmWalkedTarget,
                                    PokeStopName = fortInfo.Name
                                });
                            }
                            if (session.Runtime.PokeBallsToCollect > 0)
                            {
                                session.Runtime.PokeBallsToCollect -= fortSearch.ItemsAwarded.ToItemList()
                                                                      .Where(x => x.Item1 == ItemId.ItemPokeBall ||
                                                                             x.Item1 == ItemId.ItemGreatBall || x.Item1 == ItemId.ItemUltraBall ||
                                                                             x.Item1 == ItemId.ItemMasterBall).Sum(x => x.Item2);
                            }
                            session.MapCache.UsedPokestop(pokeStop, session);
                            break; //Continue with program as loot was succesfull.
                        }
                    } while (fortTry < 1);
                    //retryNumber - zeroCheck && fortSearch.CooldownCompleteTimestampMs < DateTime.UtcNow.ToUnixTime());
                    //Stop trying if softban is cleaned earlier or if 40 times fort looting failed.


                    await Task.Delay(session.LogicSettings.DelayPokestop, cancellationToken);


                    //Catch Lure Pokemon

                    if (session.LogicSettings.CatchWildPokemon)
                    {
                        if (pokeStop.LureInfo != null)
                        {
                            await CatchLurePokemonsTask.Execute(session, pokeStop.BaseFortData, cancellationToken);
                        }
                        if (session.LogicSettings.Teleport)
                        {
                            await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
                        }
                    }
                }
                if (session.LogicSettings.SnipeAtPokestops || session.LogicSettings.UseSnipeLocationServer)
                {
                    await SnipePokemonTask.Execute(session, cancellationToken);
                }
            }
        }
Exemplo n.º 6
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var pokestopList = await GetPokeStops(session);

            var eggWalker = new EggWalker(1000, session);

            if (pokestopList.Count <= 0)
            {
                session.EventDispatcher.Send(new WarnEvent
                {
                    Message = session.Translation.GetTranslation(TranslationString.FarmPokestopsNoUsableFound)
                });
                if (session.ForceMoveJustDone)
                {
                    session.ForceMoveJustDone = false;
                }
                if (session.ForceMoveTo != null)
                {
                    await ForceMoveTask.Execute(session, cancellationToken);
                }
                await Task.Delay(60000, cancellationToken);

                await session.Navigation.Move(new GeoCoordinate(session.Client.CurrentLatitude + session.Client.rnd.NextInRange(-0.0001, 0.0001),
                                                                session.Client.CurrentLongitude + session.Client.rnd.NextInRange(-0.0001, 0.0001)),
                                              session.LogicSettings.WalkingSpeedMin, session.LogicSettings.WalkingSpeedMax,
                                              async() =>
                {
                    // Catch normal map Pokemon
                    await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
                    //Catch Incense Pokemon
                    await CatchIncensePokemonsTask.Execute(session, cancellationToken);
                    return(true);
                },
                                              async() =>
                {
                    await UseNearbyPokestopsTask.Execute(session, cancellationToken);
                    return(true);
                }, cancellationToken, session);

                pokestopList = await GetPokeStops(session);
            }

            session.EventDispatcher.Send(new PokeStopListEvent {
                Forts = pokestopList.Select(x => x.BaseFortData)
            });

            var bestRoute = new List <GeoCoordinate>();

            session.Runtime.PokestopsToCheckGym = 13 + session.Client.rnd.Next(15);

            while (pokestopList.Any())
            {
                cancellationToken.ThrowIfCancellationRequested();

                if (session.Runtime.PokestopsToCheckGym <= 0)
                {
                    session.Runtime.PokestopsToCheckGym = 0;
                    var gymsNear = (await GetGyms(session)).OrderBy(i =>
                                                                    LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                                                            session.Client.CurrentLongitude, i.Latitude, i.Longitude))
                                   .ToList();
                    if (gymsNear.Count > 0)
                    {
                        session.Runtime.PokestopsToCheckGym = 13 + session.Client.rnd.Next(15);
                        var nearestGym = gymsNear.FirstOrDefault();
                        if (nearestGym != null)
                        {
                            var gymInfo = await session.Client.Fort.GetGymDetails(nearestGym.Id, nearestGym.Latitude, nearestGym.Longitude);

                            var gymDistance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                                      session.Client.CurrentLongitude, nearestGym.Latitude, nearestGym.Longitude);
                            session.EventDispatcher.Send(new GymPokeEvent {
                                Name = gymInfo.Name, Distance = gymDistance, Description = gymInfo.Description, GymState = gymInfo.GymState
                            });
                        }
                    }
                }
                if (session.ForceMoveJustDone)
                {
                    session.ForceMoveJustDone = false;
                }

                if (session.ForceMoveTo != null)
                {
                    await ForceMoveTask.Execute(session, cancellationToken);
                }

                var newPokestopList = (await GetPokeStops(session)).OrderBy(i =>
                                                                            LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                                                                    session.Client.CurrentLongitude, i.Latitude, i.Longitude)).Where(x => pokestopList.All(i => i.Id != x.Id) && LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                                                                                                                                                                                                                         session.Client.CurrentLongitude, x.Latitude, x.Longitude) < session.LogicSettings.MaxTravelDistanceInMeters).ToList();
                session.EventDispatcher.Send(new PokeStopListEvent {
                    Forts = newPokestopList.Select(x => x.BaseFortData)
                });
                pokestopList.AddRange(newPokestopList);

                var pokeStop = pokestopList.OrderBy(i => LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                                                 session.Client.CurrentLongitude, i.Latitude, i.Longitude)).FirstOrDefault(x => !session.MapCache.CheckPokestopUsed(x));

                if (pokeStop == null)
                {
                    await Task.Delay(60000, cancellationToken);

                    continue;
                }

                if (session.LogicSettings.RoutingService == RoutingService.GoogleDirections || session.LogicSettings.RoutingService == RoutingService.MapzenValhalla)
                {
//#if DEBUG
//                    bestRoute = RoutingUtils.GetBestRoute(pokeStop, pokestopList.Where(x => !session.MapCache.CheckPokestopUsed(x)), 10);
//#else
                    bestRoute = RoutingUtils.GetBestRoute(pokeStop, pokestopList.Where(x => !session.MapCache.CheckPokestopUsed(x)), 20);
//#endif
                    session.EventDispatcher.Send(new PokestopsOptimalPathEvent()
                    {
                        Coords = bestRoute.Select(x => Tuple.Create(x.Latitude, x.Longitude)).ToList()
                    });
                }


                var tooFarPokestops = pokestopList.Where(i => LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                                                      session.Client.CurrentLongitude, i.Latitude, i.Longitude) > session.LogicSettings.MaxTravelDistanceInMeters).ToList();

                foreach (var tooFar in tooFarPokestops)
                {
                    pokestopList.Remove(tooFar);
                }

                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
                });
                if (session.LogicSettings.Teleport)
                {
                    await session.Client.Player.UpdatePlayerLocation(fortInfo.Latitude, fortInfo.Longitude,
                                                                     session.Client.Settings.DefaultAltitude);
                }
                else
                {
                    await MoveToPokestop(session, cancellationToken, pokeStop, bestRoute, eggWalker);
                }

                bestRoute.Clear();

                if (!session.LogicSettings.LootPokestops)
                {
                    session.MapCache.UsedPokestop(pokeStop, session);
                    continue;
                }

                if (!session.ForceMoveJustDone)
                {
                    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
                    //var shownSoftBanMessage = false;
                    do
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        if (session.MapCache.CheckPokestopUsed(pokeStop))
                        {
                            break;                                               //already used somehow
                        }
                        var fortSearch = await session.Client.Fort.SearchFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude);

                        if (fortSearch.ExperienceAwarded > 0 && timesZeroXPawarded > 0)
                        {
                            timesZeroXPawarded = 0;
                        }
                        if (fortSearch.ExperienceAwarded == 0)
                        {
                            if (TimesZeroXPawarded == 0)
                            {
                                await MoveToPokestop(session, cancellationToken, pokeStop, null, eggWalker);
                            }
                            timesZeroXPawarded++;
                            if ((int)fortSearch.CooldownCompleteTimestampMs != 0)
                            {
                                break;
                                // Check if successfully looted, if so program can continue as this was "false alarm".
                            }
                            if (timesZeroXPawarded <= zeroCheck)
                            {
                                continue;
                            }

                            session.MapCache.UsedPokestop(pokeStop, session); //f**k that pokestop - skip it

                            break;
                        }
                        else
                        {
                            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
                            });
                            session.EventDispatcher.Send(new InventoryNewItemsEvent()
                            {
                                Items = fortSearch.ItemsAwarded.ToItemList()
                            });
                            session.MapCache.UsedPokestop(pokeStop, session);
                            session.Runtime.StopsHit++;
                            pokeStop.CooldownCompleteTimestampMS = DateTime.UtcNow.AddMinutes(5).ToUnixTime();
                            if (session.LogicSettings.CatchWildPokemon)
                            {
                                await CatchWildPokemonsTask.Execute(session, cancellationToken);
                            }
                            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.Teleport)
                    {
                        await Task.Delay(session.LogicSettings.DelayPokestop, cancellationToken);
                    }
                    else
                    {
                        await Task.Delay(1000, cancellationToken);
                    }


                    //Catch Lure Pokemon


                    if (pokeStop.LureInfo != null && session.LogicSettings.CatchWildPokemon)
                    {
                        await CatchLurePokemonsTask.Execute(session, pokeStop.BaseFortData, cancellationToken);
                    }
                    if (session.LogicSettings.Teleport && session.LogicSettings.CatchWildPokemon)
                    {
                        await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
                    }

                    await eggWalker.ApplyDistance(distance, cancellationToken);
                }
                session.Runtime.PokestopsToCheckGym--;
                if (session.LogicSettings.SnipeAtPokestops || session.LogicSettings.UseSnipeLocationServer)
                {
                    await SnipePokemonTask.Execute(session, cancellationToken);
                }
            }
        }
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var pokestopList = await GetPokeStops(session);

            var stopsHit  = 0;
            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();

                if (session.ForceMoveTo != null)
                {
                    await ForceMoveTask.Execute(session, cancellationToken);
                }

                var newPokestopList = (await GetPokeStops(session)).OrderBy(i =>
                                                                            LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                                                                    session.Client.CurrentLongitude, i.Latitude, i.Longitude)).Where(x => pokestopList.All(i => i.Id != x.Id) && LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                                                                                                                                                                                                                         session.Client.CurrentLongitude, x.Latitude, x.Longitude) < session.LogicSettings.MaxTravelDistanceInMeters).ToList();
                session.EventDispatcher.Send(new PokeStopListEvent {
                    Forts = newPokestopList
                });
                pokestopList.AddRange(newPokestopList);

                var pokeStop = pokestopList.OrderBy(i => LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                                                 session.Client.CurrentLongitude, i.Latitude, i.Longitude)).First(x => x.CooldownCompleteTimestampMs < DateTime.UtcNow.ToUnixTime());
                pokeStop.CooldownCompleteTimestampMs = DateTime.UtcNow.ToUnixTime() + 300 * 1000;

                var tooFarPokestops = pokestopList.Where(i => LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                                                      session.Client.CurrentLongitude, i.Latitude, i.Longitude) > session.LogicSettings.MaxTravelDistanceInMeters).ToList();

                foreach (var tooFar in tooFarPokestops)
                {
                    pokestopList.Remove(tooFar);
                }

                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
                });
                if (session.LogicSettings.Teleport)
                {
                    await session.Client.Player.UpdatePlayerLocation(fortInfo.Latitude, fortInfo.Longitude,
                                                                     session.Client.Settings.DefaultAltitude);
                }
                else
                {
                    await moveToPokestop(session, cancellationToken, pokeStop);
                }

                await CatchWildPokemonsTask.Execute(session, 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)
                    {
                        if (TimesZeroXPawarded == 0)
                        {
                            await moveToPokestop(session, cancellationToken, pokeStop);
                        }
                        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
                            });
                            if (session.LogicSettings.Teleport)
                            {
                                await Task.Delay(session.LogicSettings.DelaySoftbanRetry);
                            }
                            else
                            {
                                await DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 400);
                            }
                        }
                    }
                    else
                    {
                        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
                        });

                        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.Teleport)
                {
                    await Task.Delay(session.LogicSettings.DelayPokestop);
                }
                else
                {
                    await Task.Delay(1000, cancellationToken);
                }


                //Catch Lure Pokemon


                if (pokeStop.LureInfo != null)
                {
                    await CatchLurePokemonsTask.Execute(session, pokeStop, cancellationToken);
                }
                if (session.LogicSettings.Teleport)
                {
                    await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
                }

                await eggWalker.ApplyDistance(distance, cancellationToken);

                if (stopsHit++ == 5 + session.Client.rnd.Next(5)) //TODO: OR item/pokemon bag is full
                {
                    stopsHit = 0;
                    if (fortSearch.ItemsAwarded.Count > 0)
                    {
                        await session.Inventory.RefreshCachedInventory();
                    }
                    await RecycleItemsTask.Execute(session, cancellationToken);

                    if (session.LogicSettings.EvolveAllPokemonWithEnoughCandy ||
                        session.LogicSettings.EvolveAllPokemonAboveIv)
                    {
                        await EvolvePokemonTask.Execute(session, cancellationToken);
                    }
                    if (session.LogicSettings.AutomaticallyLevelUpPokemon)
                    {
                        await LevelUpPokemonTask.Execute(session, cancellationToken);
                    }
                    if (session.LogicSettings.TransferDuplicatePokemon)
                    {
                        await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
                    }
                    if (session.LogicSettings.RenamePokemon)
                    {
                        await RenamePokemonTask.Execute(session, cancellationToken);
                    }
                }

                if (session.LogicSettings.SnipeAtPokestops || session.LogicSettings.UseSnipeLocationServer)
                {
                    await SnipePokemonTask.Execute(session, cancellationToken);
                }
            }
        }
Exemplo n.º 8
0
        public static async Task NoTeleport(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)
            {
                session.EventDispatcher.Send(new WarnEvent()
                {
                    Message = session.Translation.GetTranslation(TranslationString.FarmPokestopsOutsideRadius, distanceFromStart)
                });
                await Task.Delay(1000, cancellationToken);

                await session.Navigation.HumanLikeWalking(
                    new GeoCoordinate(session.Settings.DefaultLatitude, session.Settings.DefaultLongitude),
                    session.LogicSettings.WalkingSpeedInKilometerPerHour, null, cancellationToken);
            }

            var pokestopList = await GetPokeStops(session);

            var stopsHit        = 0;
            var displayStatsHit = 0;
            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
                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 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 {
                    Id = fortInfo.FortId, Name = fortInfo.Name, Distance = distance, Latitude = fortInfo.Latitude, Longitude = fortInfo.Longitude, Description = fortInfo.Description, url = fortInfo.ImageUrls[0]
                });
                if (session.LogicSettings.Teleport)
                {
                    await session.Client.Player.UpdatePlayerLocation(fortInfo.Latitude, fortInfo.Longitude,
                                                                     session.Client.Settings.DefaultAltitude);
                }

                else
                {
                    await session.Navigation.HumanLikeWalking(new GeoCoordinate(pokeStop.Latitude, pokeStop.Longitude),
                                                              session.LogicSettings.WalkingSpeedInKilometerPerHour,
                                                              async() =>
                    {
                        // Catch normal map Pokemon
                        await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
                        //Catch Incense Pokemon
                        await CatchIncensePokemonsTask.Execute(session, cancellationToken);
                        return(true);
                    }, 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
                            });
                            if (session.LogicSettings.Teleport)
                            {
                                await Task.Delay(session.LogicSettings.DelaySoftbanRetry);
                            }
                            else
                            {
                                await DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 400);
                            }
                        }
                    }
                    else
                    {
                        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,
                            Description   = fortInfo.Description,
                            url           = fortInfo.ImageUrls[0]
                        });

                        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.Teleport)
                {
                    await Task.Delay(session.LogicSettings.DelayPokestop);
                }
                else
                {
                    await Task.Delay(1000, cancellationToken);
                }


                //Catch Lure Pokemon


                if (pokeStop.LureInfo != null)
                {
                    await CatchLurePokemonsTask.Execute(session, pokeStop, cancellationToken);
                }
                if (session.LogicSettings.Teleport)
                {
                    await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
                }

                await eggWalker.ApplyDistance(distance, cancellationToken);

                if (++stopsHit % 5 == 0) //TODO: OR item/pokemon bag is full
                {
                    stopsHit = 0;
                    // need updated stardust information for upgrading, so refresh your profile now
                    await DownloadProfile(session);

                    if (fortSearch.ItemsAwarded.Count > 0)
                    {
                        await session.Inventory.RefreshCachedInventory();
                    }
                    await RecycleItemsTask.Execute(session, cancellationToken);

                    if (session.LogicSettings.EvolveAllPokemonWithEnoughCandy ||
                        session.LogicSettings.EvolveAllPokemonAboveIv)
                    {
                        await EvolvePokemonTask.Execute(session, cancellationToken);
                    }
                    if (session.LogicSettings.AutomaticallyLevelUpPokemon)
                    {
                        await LevelUpPokemonTask.Execute(session, cancellationToken);
                    }
                    if (session.LogicSettings.TransferDuplicatePokemon)
                    {
                        await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
                    }
                    if (session.LogicSettings.RenamePokemon)
                    {
                        await RenamePokemonTask.Execute(session, cancellationToken);
                    }
                    if (++displayStatsHit >= 4)
                    {
                        await DisplayPokemonStatsTask.Execute(session);

                        displayStatsHit = 0;
                    }
                }

                if (session.LogicSettings.SnipeAtPokestops || session.LogicSettings.UseSnipeLocationServer)
                {
                    await SnipePokemonTask.Execute(session, cancellationToken);
                }
            }
        }
Exemplo n.º 9
0
        public static async Task <PlayerUpdateResponse> Execute(ISession session, CancellationToken cancellationToken,
                                                                bool silent = false)
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (session.LogicSettings.UseEggIncubators && !session.EggWalker.Inited)
            {
                await session.EggWalker.InitEggWalker(cancellationToken);
            }

            var moveToCoords = session.ForceMoveTo;
            var distance     = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                       session.Client.CurrentLongitude, moveToCoords.Latitude, moveToCoords.Longitude);

            if (!silent)
            {
                session.EventDispatcher.Send(new WarnEvent
                {
                    Message =
                        session.Translation.GetTranslation(TranslationString.ForceMove, session.ForceMoveTo.Latitude,
                                                           session.ForceMoveTo.Longitude, distance.ToString("N1"))
                });
            }

            PlayerUpdateResponse result;

            session.ForceMoveToResume = session.ForceMoveTo;
            session.ForceMoveTo       = null;
            session.State             = BotState.Walk;
            if (session.LogicSettings.Teleport)
            {
                result = await session.Client.Player.UpdatePlayerLocation(moveToCoords.Latitude, moveToCoords.Longitude,
                                                                          session.Client.Settings.DefaultAltitude);
            }
            else
            {
                result = await session.Navigation.Move(new GeoCoordinate(moveToCoords.Latitude, moveToCoords.Longitude),
                                                       session.LogicSettings.WalkingSpeedMin, session.LogicSettings.WalkingSpeedMax,
                                                       async() =>
                {
                    // Catch normal map Pokemon
                    await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
                    //Catch Incense Pokemon
                    await CatchIncensePokemonsTask.Execute(session, cancellationToken);
                    return(true);
                },
                                                       async() =>
                {
                    await UseNearbyPokestopsTask.Execute(session, cancellationToken, true);
                    return(true);
                }, cancellationToken, session);
            }

            if (!silent)
            {
                session.EventDispatcher.Send(new WarnEvent
                {
                    Message = session.Translation.GetTranslation(TranslationString.ForceMoveDone)
                });
            }
            session.State             = BotState.Idle;
            session.ForceMoveJustDone = true;
            session.ForceMoveTo       = null;
            session.ForceMoveToResume = null;
            session.EventDispatcher.Send(new ForceMoveDoneEvent());

            if (session.LogicSettings.Teleport)
            {
                await Task.Delay(session.LogicSettings.DelayPokestop, cancellationToken);
            }
            else
            {
                await Task.Delay(1000, cancellationToken);
            }

            if (session.LogicSettings.SnipeAtPokestops || session.LogicSettings.UseSnipeLocationServer)
            {
                await SnipePokemonTask.Execute(session, cancellationToken);
            }
            return(result);
        }
Exemplo n.º 10
0
        public static async Task <PlayerUpdateResponse> Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var eggWalker = new EggWalker(1000, session);


            var moveToCoords = session.ForceMoveTo;
            var distance     = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                       session.Client.CurrentLongitude, moveToCoords.Latitude, moveToCoords.Longitude);

            session.EventDispatcher.Send(new WarnEvent
            {
                Message = $"ForceMove to {session.ForceMoveTo.Latitude} - {session.ForceMoveTo.Longitude} Started! Distance: {distance.ToString("N1")}m"
            });
            session.ForceMoveTo = null;
            PlayerUpdateResponse result;

            if (session.LogicSettings.Teleport)
            {
                result = await session.Client.Player.UpdatePlayerLocation(moveToCoords.Latitude, moveToCoords.Longitude,
                                                                          session.Client.Settings.DefaultAltitude);
            }
            else
            {
                result = await session.Navigation.Move(new GeoCoordinate(moveToCoords.Latitude, moveToCoords.Longitude),
                                                       session.LogicSettings.WalkingSpeedMin, session.LogicSettings.WalkingSpeedMax,
                                                       async() =>
                {
                    // Catch normal map Pokemon
                    await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
                    //Catch Incense Pokemon
                    await CatchIncensePokemonsTask.Execute(session, cancellationToken);
                    return(true);
                },
                                                       async() =>
                {
                    await UseNearbyPokestopsTask.Execute(session, cancellationToken, true);
                    return(true);
                }, cancellationToken, session, eggWalker : eggWalker);
            }

            session.EventDispatcher.Send(new WarnEvent
            {
                Message = "ForceMove Done!"
            });
            session.ForceMoveJustDone = true;
            session.ForceMoveTo       = null;
            session.EventDispatcher.Send(new ForceMoveDoneEvent());

            if (session.LogicSettings.Teleport)
            {
                await Task.Delay(session.LogicSettings.DelayPokestop, cancellationToken);
            }
            else
            {
                await Task.Delay(1000, cancellationToken);
            }

            await eggWalker.ApplyDistance(distance, cancellationToken);


            if (session.LogicSettings.SnipeAtPokestops || session.LogicSettings.UseSnipeLocationServer)
            {
                await SnipePokemonTask.Execute(session, cancellationToken);
            }
            return(result);
        }
Exemplo n.º 11
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var pokestopList = await GetPokeStops(session);

            if (session.LogicSettings.UseEggIncubators && !session.EggWalker.Inited)
            {
                await session.EggWalker.InitEggWalker(cancellationToken);
            }

            if (pokestopList.Count <= 0)
            {
                if (!pokestopList.Any())
                {
                    await CheckChallengeDoneTask.Execute(session, cancellationToken);

                    await CheckChallengeTask.Execute(session, cancellationToken);
                }
                session.EventDispatcher.Send(new WarnEvent
                {
                    Message = session.Translation.GetTranslation(TranslationString.FarmPokestopsNoUsableFound)
                });
                if (session.ForceMoveJustDone)
                {
                    session.ForceMoveJustDone = false;
                }
                if (session.ForceMoveTo != null)
                {
                    await ForceMoveTask.Execute(session, cancellationToken);
                }
                await Task.Delay(60000, cancellationToken);

                await session.Navigation.Move(new GeoCoordinate(session.Client.CurrentLatitude + session.Client.Rnd.NextInRange(-0.0001, 0.0001),
                                                                session.Client.CurrentLongitude + session.Client.Rnd.NextInRange(-0.0001, 0.0001)),
                                              session.LogicSettings.WalkingSpeedMin, session.LogicSettings.WalkingSpeedMax,
                                              async() =>
                {
                    // Catch normal map Pokemon
                    await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
                    //Catch Incense Pokemon
                    await CatchIncensePokemonsTask.Execute(session, cancellationToken);
                    return(true);
                },
                                              async() =>
                {
                    await UseNearbyPokestopsTask.Execute(session, cancellationToken);
                    return(true);
                }, cancellationToken, session);

                pokestopList = await GetPokeStops(session);
            }

            session.EventDispatcher.Send(new PokeStopListEvent {
                Forts = pokestopList.Select(x => x.BaseFortData)
            });


            if (session.ForceMoveToResume != null && session.ForceMoveTo == null)
            {
                session.EventDispatcher.Send(new NoticeEvent
                {
                    Message = session.Translation.GetTranslation(TranslationString.UnDoneForceMove, session.ForceMoveToResume.Latitude, session.ForceMoveToResume.Longitude)
                });
                session.ForceMoveTo = session.ForceMoveToResume;
            }

            var bestRoute = new List <GeoCoordinate>();

            session.Runtime.PokestopsToCheckGym = 13 + session.Client.Rnd.Next(15);

            while (pokestopList.Any())
            {
                if (session.ForceMoveJustDone)
                {
                    session.ForceMoveJustDone = false;
                }

                if (session.LogicSettings.UseCustomRoute && session.LogicSettings.CustomRoute != null &&
                    session.LogicSettings.CustomRoute.RoutePoints.Count > 2)
                {
                    session.EventDispatcher.Send(new NoticeEvent
                    {
                        Message = session.Translation.GetTranslation(TranslationString.CustomRouteEnabled)
                    });
                    break;
                }

                if (session.ForceMoveTo != null)
                {
                    await ForceMoveTask.Execute(session, cancellationToken);
                }

                var newPokestopList = (await GetPokeStops(session)).OrderBy(i =>
                                                                            LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                                                                    session.Client.CurrentLongitude, i.Latitude, i.Longitude)).Where(x => pokestopList.All(i => i.Id != x.Id) && LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                                                                                                                                                                                                                         session.Client.CurrentLongitude, x.Latitude, x.Longitude) < session.LogicSettings.MaxTravelDistanceInMeters).ToList();
                session.EventDispatcher.Send(new PokeStopListEvent {
                    Forts = newPokestopList.Select(x => x.BaseFortData)
                });
                pokestopList.AddRange(newPokestopList);

                var pokeStop = pokestopList.OrderBy(i => LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                                                 session.Client.CurrentLongitude, i.Latitude, i.Longitude)).FirstOrDefault(x => !session.MapCache.CheckPokestopUsed(x));

                if (pokeStop == null)
                {
                    await Task.Delay(60000, cancellationToken);

                    continue;
                }

                //No Longer Usable, MobBot is dead - Lunatiq
                //if (session.LogicSettings.RoutingService == RoutingService.GoogleDirections || session.LogicSettings.RoutingService == RoutingService.MapzenValhalla )
                //{
                bestRoute = RoutingUtils.GetBestRoute(pokeStop, pokestopList.Where(x => !session.MapCache.CheckPokestopUsed(x)), 20);
                session.EventDispatcher.Send(new PokestopsOptimalPathEvent
                {
                    Coords = bestRoute.Select(x => Tuple.Create(x.Latitude, x.Longitude)).ToList()
                });
                //}


                var tooFarPokestops = pokestopList.Where(i => LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                                                      session.Client.CurrentLongitude, i.Latitude, i.Longitude) > session.LogicSettings.MaxTravelDistanceInMeters).ToList();

                foreach (var tooFar in tooFarPokestops)
                {
                    pokestopList.Remove(tooFar);
                }

                //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});

                if (session.LogicSettings.Teleport)
                {
                    await session.Client.Player.UpdatePlayerLocation(fortInfo.Latitude, fortInfo.Longitude,
                                                                     session.Client.Settings.DefaultAltitude);
                }
                else
                {
                    await MoveToPokestop(session, cancellationToken, pokeStop, bestRoute);
                }

                bestRoute.Clear();

                await ActionQueueTask.Execute(session, cancellationToken);

                if (!session.LogicSettings.LootPokestops)
                {
                    session.MapCache.UsedPokestop(pokeStop, session);
                    continue;
                }

                #region old fort logic
                //if (!session.ForceMoveJustDone)
                //{
                //    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
                //    //var shownSoftBanMessage = false;
                //    do
                //    {
                //        cancellationToken.ThrowIfCancellationRequested();
                //        if (session.MapCache.CheckPokestopUsed(pokeStop)) break; //already used somehow
                //        var fortSearch =
                //            await session.Client.Fort.SearchFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude);
                //        if (fortSearch.ExperienceAwarded > 0 && timesZeroXPawarded > 0) timesZeroXPawarded = 0;
                //        if (fortSearch.ExperienceAwarded == 0)
                //        {
                //            if (TimesZeroXPawarded == 0)
                //                await MoveToPokestop(session, cancellationToken, pokeStop, null);
                //            timesZeroXPawarded++;
                //            if ((int) fortSearch.CooldownCompleteTimestampMs != 0)
                //            {
                //                break;
                //                // Check if successfully looted, if so program can continue as this was "false alarm".
                //            }
                //            if (timesZeroXPawarded <= zeroCheck) continue;

                //            session.MapCache.UsedPokestop(pokeStop, session); //f**k that pokestop - skip it

                //            break;
                //        }
                //        else
                //        {
                //            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,
                //                Description = fortInfo.Description,
                //                url = fortInfo.ImageUrls.FirstOrDefault()
                //            });

                //            if (fortSearch.PokemonDataEgg != null)
                //            {
                //                session.EventDispatcher.Send(new EggFoundEvent
                //                {
                //                    Distance = fortSearch.PokemonDataEgg.EggKmWalkedTarget,
                //                    PokeStopName = fortInfo.Name
                //                });
                //            }
                //            session.EventDispatcher.Send(new InventoryNewItemsEvent
                //            {
                //                Items = fortSearch.ItemsAwarded.ToItemList()
                //            });
                //            if (session.Runtime.PokeBallsToCollect > 0)
                //            {
                //                session.Runtime.PokeBallsToCollect -= fortSearch.ItemsAwarded.ToItemList()
                //                    .Where(x => x.Item1 == ItemId.ItemPokeBall ||
                //                                x.Item1 == ItemId.ItemGreatBall || x.Item1 == ItemId.ItemUltraBall ||
                //                                x.Item1 == ItemId.ItemMasterBall).Sum(x => x.Item2);
                //            }
                //            session.MapCache.UsedPokestop(pokeStop, session);
                //            session.Runtime.StopsHit++;
                //            pokeStop.CooldownCompleteTimestampMS = DateTime.UtcNow.AddMinutes(5).ToUnixTime();
                //            if (session.LogicSettings.CatchWildPokemon)
                //            {
                //                await CatchWildPokemonsTask.Execute(session, cancellationToken);
                //            }
                //            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.Teleport)
                //        await Task.Delay(session.LogicSettings.DelayPokestop, cancellationToken);
                //    else
                //        await Task.Delay(1000, cancellationToken);


                //    //Catch Lure Pokemon


                //    if (pokeStop.LureInfo != null && session.LogicSettings.CatchWildPokemon)
                //    {
                //        await CatchLurePokemonsTask.Execute(session, pokeStop.BaseFortData, cancellationToken);
                //    }
                //    if (session.LogicSettings.Teleport && session.LogicSettings.CatchWildPokemon)
                //        await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
                //}
                #endregion

                session.Runtime.PokestopsToCheckGym--;
                if (session.LogicSettings.SnipeAtPokestops || session.LogicSettings.UseSnipeLocationServer)
                {
                    await SnipePokemonTask.Execute(session, cancellationToken);
                }
            }
        }