public static async Task <FortData> GetNextPokeStop(ISession session)
        {
            var priorityTarget = await SetMoveToTargetTask.GetTarget(session);

            if (priorityTarget != null)
            {
                return(priorityTarget);
            }


            if (session.Forts == null ||
                session.Forts.Count == 0 ||
                session.Forts.Count(p => p.CooldownCompleteTimestampMs < DateTime.UtcNow.ToUnixTime()) == 0)
            {
                //TODO : A logic need to be add for handle this  case?
            }
            ;

            var forts = session.Forts.Where(p => p.CooldownCompleteTimestampMs < DateTime.UtcNow.ToUnixTime()).ToList();

            forts = forts.OrderBy(
                p =>
                session.Navigation.WalkStrategy.CalculateDistance(
                    session.Client.CurrentLatitude,
                    session.Client.CurrentLongitude,
                    p.Latitude,
                    p.Longitude,
                    session)
                ).ToList();

            if (session.LogicSettings.UseGpxPathing)
            {
                forts = forts.Where(p => LocationUtils.CalculateDistanceInMeters(p.Latitude, p.Longitude, session.Client.CurrentLatitude, session.Client.CurrentLongitude) < 40).ToList();
            }

            if (!session.LogicSettings.GymAllowed /*|| session.Inventory.GetPlayerStats().Result.FirstOrDefault().Level <= 5*/)
            {
                // Filter out the gyms
                forts = forts.Where(x => x.Type != FortType.Gym).ToList();
            }
            else if (session.LogicSettings.GymPrioritizeOverPokestop)
            {
                // Prioritize gyms over pokestops
                var gyms = forts.Where(x => x.Type == FortType.Gym &&
                                       LocationUtils.CalculateDistanceInMeters(x.Latitude, x.Longitude, session.Client.CurrentLatitude, session.Client.CurrentLongitude) < session.LogicSettings.GymMaxDistance);

                // Return the first gym in range.
                if (gyms.Count() > 0)
                {
                    return(gyms.FirstOrDefault());
                }
            }

            if (forts.Count == 1)
            {
                return(forts.FirstOrDefault());
            }

            return(forts.Skip((int)DateTime.Now.Ticks % 2).FirstOrDefault());
        }
Esempio n. 2
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            TinyIoC.TinyIoCContainer.Current.Resolve <MultiAccountManager>().ThrowIfSwitchAccountRequested();
            //request map objects to referesh data. keep all fort in session

            var mapObjectTupe = await GetPokeStops(session).ConfigureAwait(false);

            var pokeStop = await GetNextPokeStop(session).ConfigureAwait(false);

            while (pokeStop != null)
            {
                cancellationToken.ThrowIfCancellationRequested();
                // Exit this task if both catching and looting has reached its limits
                await CheckLimit(session).ConfigureAwait(false);

                var fortInfo = pokeStop.Id.StartsWith(SetMoveToTargetTask.TARGET_ID) ? SetMoveToTargetTask.FakeFortInfo(pokeStop) : await session.Client.Fort.GetFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude).ConfigureAwait(false);

                await WalkingToPokeStop(session, cancellationToken, pokeStop, fortInfo).ConfigureAwait(false);

                await DoActionAtPokeStop(session, cancellationToken, pokeStop, fortInfo).ConfigureAwait(false);

                await UseGymBattleTask.Execute(session, cancellationToken, pokeStop, fortInfo).ConfigureAwait(false);

                if (fortInfo.Type == FortType.Gym &&
                    (session.GymState.getGymDetails(session, pokeStop).GymState.FortData.OwnedByTeam == session.Profile.PlayerData.Team || session.GymState.capturedGymId.Equals(fortInfo.FortId)) &&
                    session.LogicSettings.GymConfig.Enable &&
                    session.LogicSettings.GymConfig.EnableGymTraining)
                {
                    if (string.IsNullOrEmpty(session.GymState.trainingGymId) || !session.GymState.trainingGymId.Equals(fortInfo.FortId))
                    {
                        session.GymState.trainingGymId = fortInfo.FortId;
                        session.GymState.trainingRound = 0;
                    }
                    session.GymState.trainingRound++;
                    if (session.GymState.trainingRound <= session.LogicSettings.GymConfig.MaxTrainingRoundsOnOneGym)
                    {
                        continue;
                    }
                }

                if (!await SetMoveToTargetTask.IsReachedDestination(pokeStop, session, cancellationToken).ConfigureAwait(false))
                {
                    pokeStop.CooldownCompleteTimestampMs = DateTime.UtcNow.ToUnixTime() + (pokeStop.Type == FortType.Gym ? session.LogicSettings.GymConfig.VisitTimeout : 5) * 60 * 1000; //5 minutes to cooldown
                    session.AddForts(new List <FortData>()
                    {
                        pokeStop
                    });                                                  //replace object in memory.
                }

                await MSniperServiceTask.Execute(session, cancellationToken).ConfigureAwait(false);

                if (session.LogicSettings.EnableHumanWalkingSnipe)
                {
                    await HumanWalkSnipeTask.Execute(session, cancellationToken, pokeStop, fortInfo).ConfigureAwait(false);
                }

                pokeStop = await GetNextPokeStop(session).ConfigureAwait(false);
            }
        }
Esempio n. 3
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            //request map objects to referesh data. keep all fort in session

            var mapObjectTupe = await GetPokeStops(session);

            _pokestopList = mapObjectTupe.Item2;
            var pokeStop = await GetNextPokeStop(session);

            while (pokeStop != null)
            {
                cancellationToken.ThrowIfCancellationRequested();
                // Exit this task if both catching and looting has reached its limits
                if ((UseNearbyPokestopsTask._pokestopLimitReached || UseNearbyPokestopsTask._pokestopTimerReached) &&
                    (CatchPokemonTask._catchPokemonLimitReached || CatchPokemonTask._catchPokemonTimerReached))
                {
                    return;
                }
                if (session.LogicSettings.ActivateMSniper)
                {
                    await MSniperServiceTask.CheckMSniper(session, cancellationToken);
                }
                var fortInfo = pokeStop.Id == SetMoveToTargetTask.TARGET_ID ? SetMoveToTargetTask.FortInfo : await session.Client.Fort.GetFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude);

                await WalkingToPokeStop(session, cancellationToken, pokeStop, fortInfo);

                await DoActionAtPokeStop(session, cancellationToken, pokeStop, fortInfo);

                await UseGymBattleTask.Execute(session, cancellationToken, pokeStop, fortInfo);

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

                if (!await SetMoveToTargetTask.IsReachedDestination(pokeStop, session, cancellationToken))
                {
                    pokeStop.CooldownCompleteTimestampMs = DateTime.UtcNow.ToUnixTime() + (pokeStop.Type == FortType.Gym ? session.LogicSettings.GymVisitTimeout : 5) * 60 * 1000; //5 minutes to cooldown
                    session.AddForts(new List <FortData>()
                    {
                        pokeStop
                    });                                                  //replace object in memory.
                }

                if (session.LogicSettings.EnableHumanWalkingSnipe)
                {
                    await HumanWalkSnipeTask.Execute(session, cancellationToken, pokeStop);
                }
                pokeStop = await GetNextPokeStop(session);
            }
        }
        private static async Task WalkingToPokeStop(ISession session, CancellationToken cancellationToken, FortData pokeStop, FortDetailsResponse fortInfo)
        {
            var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                   session.Client.CurrentLongitude, pokeStop.Latitude, pokeStop.Longitude);

            // we only move to the PokeStop, and send the associated FortTargetEvent, when not using GPX
            // also, GPX pathing uses its own EggWalker and calls the CatchPokemon tasks internally.
            if (!session.LogicSettings.UseGpxPathing)
            {
                // Will modify Lat,Lng and Name to fake position
                //Need refactor it to speparate from pokestop logic -> samuraitruong will do it.
                SetMoveToTargetTask.CheckSetMoveToTargetStatus(ref fortInfo, ref pokeStop);

                var eggWalker = new EggWalker(1000, session);

                cancellationToken.ThrowIfCancellationRequested();

                if (!session.LogicSettings.UseGoogleWalk && !session.LogicSettings.UseYoursWalk)
                {
                    session.EventDispatcher.Send(new FortTargetEvent {
                        Name = fortInfo.Name, Distance = distance, Route = "NecroBot"
                    });
                }
                else
                {
                    BaseWalkStrategy.FortInfo = fortInfo;
                }
                var pokeStopDestination = new GeoCoordinate(pokeStop.Latitude, pokeStop.Longitude,
                                                            LocationUtils.getElevation(session, pokeStop.Latitude, pokeStop.Longitude));

                if (pokeStop.Type == FortType.Gym)
                {
                    session.EventDispatcher.Send(new GymWalkToTargetEvent()
                    {
                        Name      = fortInfo.Name,
                        Distance  = distance,
                        Latitude  = fortInfo.Latitude,
                        Longitude = fortInfo.Longitude
                    });
                }

                await session.Navigation.Move(pokeStopDestination,
                                              async() =>
                {
                    await OnWalkingToPokeStopOrGym(session, pokeStop, cancellationToken);
                },
                                              session,
                                              cancellationToken);

                // we have moved this distance, so apply it immediately to the egg walker.
                await eggWalker.ApplyDistance(distance, cancellationToken);
            }
        }
Esempio n. 5
0
        public static async Task <FortData> GetNextPokeStop(ISession session)
        {
            var priorityTarget = await SetMoveToTargetTask.GetTarget(session);

            if (priorityTarget != null)
            {
                return(priorityTarget);
            }


            if (session.Forts == null ||
                session.Forts.Count == 0 ||
                session.Forts.Count(p => p.CooldownCompleteTimestampMs < DateTime.UtcNow.ToUnixTime()) == 0)
            {
                //non pokestop . should we init or return nul?
            }
            ;

            var pokeStopes = session.Forts.Where(p => p.CooldownCompleteTimestampMs < DateTime.UtcNow.ToUnixTime()).ToList();

            pokeStopes = pokeStopes.OrderBy(
                p =>
                session.Navigation.WalkStrategy.CalculateDistance(
                    session.Client.CurrentLatitude,
                    session.Client.CurrentLongitude,
                    p.Latitude,
                    p.Longitude,
                    session)
                ).ToList();
            if (session.LogicSettings.UseGpxPathing)
            {
                pokeStopes = pokeStopes.Where(p => LocationUtils.CalculateDistanceInMeters(p.Latitude, p.Longitude, session.Client.CurrentLatitude, session.Client.CurrentLongitude) < 40).ToList();
            }
            if (pokeStopes.Count == 1)
            {
                return(pokeStopes.FirstOrDefault());
            }

            if (session.LogicSettings.GymAllowed)
            {
                var gyms = pokeStopes.Where(x => x.Type == FortType.Gym &&
                                            LocationUtils.CalculateDistanceInMeters(x.Latitude, x.Longitude, session.Client.CurrentLatitude, session.Client.CurrentLongitude) < session.LogicSettings.GymMaxDistance &&
                                            x.CooldownCompleteTimestampMs < DateTime.UtcNow.ToUnixTime());

                if (gyms.Count() > 0)
                {
                    return(gyms.FirstOrDefault());
                }
            }
            return(pokeStopes.Skip((int)DateTime.Now.Ticks % 2).FirstOrDefault());
        }
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            TinyIoC.TinyIoCContainer.Current.Resolve <MultiAccountManager>().ThrowIfSwitchAccountRequested();
            //request map objects to referesh data. keep all fort in session

            var mapObjectTupe = await GetPokeStops(session).ConfigureAwait(false);

            var pokeStop = await GetNextPokeStop(session).ConfigureAwait(false);

            while (pokeStop != null)
            {
                cancellationToken.ThrowIfCancellationRequested();
                // Exit this task if both catching and looting has reached its limits
                await CheckLimit(session).ConfigureAwait(false);

                var fortInfo = pokeStop.Id.StartsWith(SetMoveToTargetTask.TARGET_ID) ? SetMoveToTargetTask.FakeFortInfo(pokeStop) : await session.Client.Fort.GetFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude).ConfigureAwait(false);
                await WalkingToPokeStop(session, cancellationToken, pokeStop, fortInfo).ConfigureAwait(false);
                await DoActionAtPokeStop(session, cancellationToken, pokeStop, fortInfo).ConfigureAwait(false);

                if (pokeStop.Type == FortType.Gym)
                {
                    var fortDetails = await session.Client.Fort.GymGetInfo(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude).ConfigureAwait(false);

                    if (fortDetails.Result == GymGetInfoResponse.Types.Result.Success)
                    {
                        await UseGymBattleTask.Execute(session, cancellationToken, pokeStop, fortInfo, fortDetails).ConfigureAwait(false);
                    }
                }

                if (!await SetMoveToTargetTask.IsReachedDestination(pokeStop, session, cancellationToken).ConfigureAwait(false))
                {
                    pokeStop.CooldownCompleteTimestampMs = DateTime.UtcNow.ToUnixTime() + 5 * 60 * 1000; //5 minutes to cooldown
                    session.AddForts(new List <FortData>()
                    {
                        pokeStop
                    });                                                  //replace object in memory.
                }

                if (session.LogicSettings.EnableHumanWalkingSnipe)
                {
                    await MSniperServiceTask.Execute(session, cancellationToken).ConfigureAwait(false);

                    await HumanWalkSnipeTask.Execute(session, cancellationToken, pokeStop, fortInfo).ConfigureAwait(false);
                }

                pokeStop = await GetNextPokeStop(session).ConfigureAwait(false);
            }
        }
        private static async Task OnWalkingToPokeStopOrGym(ISession session, FortData pokeStop, CancellationToken cancellationToken)
        {
            //TODO - refactore this call to somewhere else
            if (SetMoveToTargetTask.CheckStopforSetMoveToTarget())
            {
                return;
            }

            // Catch normal map Pokemon
            await CatchNearbyPokemonsTask.Execute(session, cancellationToken);

            //Catch Incense Pokemon
            await CatchIncensePokemonsTask.Execute(session, cancellationToken);

            // Minor fix google route ignore pokestop
            if (session.LogicSettings.UseGoogleWalk && !session.LogicSettings.UseYoursWalk && !session.LogicSettings.UseGpxPathing)
            {
                await SpinPokestopNearBy(session, cancellationToken, pokeStop);
            }
        }
Esempio n. 8
0
        public static async Task <FortData> GetNextPokeStop(ISession session)
        {
            var priorityTarget = await SetMoveToTargetTask.GetTarget(session).ConfigureAwait(false);

            if (priorityTarget != null)
            {
                return(priorityTarget);
            }

            if (session.Forts == null ||
                session.Forts.Count == 0 ||
                session.Forts.Count(p => p.CooldownCompleteTimestampMs < DateTime.UtcNow.ToUnixTime()) == 0)
            {
                //TODO : A logic need to be add for handle this  case?
            }
            ;

            //NOTE : This code is killing perfomance of BOT if GYM is turn on, need to refactor to avoid this hummer call API

            var forts = session.Forts.Where(p => p.CooldownCompleteTimestampMs < DateTime.UtcNow.ToUnixTime())
                        .Where(x => x.Id != string.Empty).ToList();

            forts = forts.OrderBy(
                p =>
                session.Navigation.WalkStrategy.CalculateDistance(
                    session.Client.CurrentLatitude,
                    session.Client.CurrentLongitude,
                    p.Latitude,
                    p.Longitude,
                    session)
                ).ToList();

            if (session.LogicSettings.UseGpxPathing)
            {
                forts = forts.Where(p => LocationUtils.CalculateDistanceInMeters(p.Latitude, p.Longitude, session.Client.CurrentLatitude, session.Client.CurrentLongitude) < 40).ToList();
            }

            var reviveCount = (await session.Inventory.GetItems().ConfigureAwait(false)).Where(w => w.ItemId == POGOProtos.Inventory.Item.ItemId.ItemRevive || w.ItemId == POGOProtos.Inventory.Item.ItemId.ItemMaxRevive).Select(s => s.Count).Sum();

            if (session.LogicSettings.GymConfig.Enable && session.LogicSettings.GymConfig.MinRevivePotions > reviveCount)
            {
                // Filter out the gyms
                forts = forts.Where(p => p.CooldownCompleteTimestampMs < DateTime.UtcNow.ToUnixTime())
                        .Where(x => x.Type == FortType.Gym).ToList();
            }

            if (session.LogicSettings.GymConfig.PrioritizeGymOverPokestop)
            {
                // Prioritize gyms over pokestops
                var gyms = forts.Where(x => x.Type == FortType.Gym &&
                                       LocationUtils.CalculateDistanceInMeters(x.Latitude, x.Longitude, session.Client.CurrentLatitude, session.Client.CurrentLongitude) < session.LogicSettings.GymConfig.MaxDistance);
                //.OrderBy(x => LocationUtils.CalculateDistanceInMeters(x.Latitude, x.Longitude, session.Client.CurrentLatitude, session.Client.CurrentLongitude));

                if (session.LogicSettings.GymConfig.PrioritizeGymWithFreeSlot)
                {
                    var freeSlots = new List <FortData>();
                    foreach (var gym in gyms)
                    {
                        if (gym.OwnedByTeam == session.Profile.PlayerData.Team)
                        {
                            var task = await session.Client.Fort.GymGetInfo(gym.Id, gym.Latitude, gym.Longitude).ConfigureAwait(false);

                            if (task.Result == GymGetInfoResponse.Types.Result.Success)
                            {
                                if (task.GymStatusAndDefenders.GymDefender.Count() < UseGymBattleTask.MaxPlayers)
                                {
                                    freeSlots.Add(gym);
                                }
                            }
                        }
                    }

                    if (freeSlots.Count() > 0)
                    {
                        return(freeSlots.FirstOrDefault());
                    }
                }

                // Return the first gym in range.
                if (gyms.Count() > 0)
                {
                    return(gyms.FirstOrDefault());
                }
            }

            return(forts.FirstOrDefault());
        }
        public static async Task <FortData> GetNextPokeStop(ISession session)
        {
            var priorityTarget = await SetMoveToTargetTask.GetTarget(session);

            if (priorityTarget != null)
            {
                return(priorityTarget);
            }


            if (session.Forts == null ||
                session.Forts.Count == 0 ||
                session.Forts.Count(p => p.CooldownCompleteTimestampMs < DateTime.UtcNow.ToUnixTime()) == 0)
            {
                //TODO : A logic need to be add for handle this  case?
            }
            ;

            var deployedPokemons = session.Inventory.GetDeployedPokemons();

            //NOTE : This code is killing perfomance of BOT if GYM is turn on, need to refactor to avoid this hummer call API

            var forts = session.Forts
                        .Where(p => p.CooldownCompleteTimestampMs < DateTime.UtcNow.ToUnixTime())
                        .Where(f => f.Type == FortType.Checkpoint ||
                               (session.LogicSettings.GymConfig.Enable && (
                                    UseGymBattleTask.CanAttackGym(session, f, deployedPokemons) ||
                                    UseGymBattleTask.CanTrainGym(session, f, deployedPokemons) ||
                                    UseGymBattleTask.CanDeployToGym(session, f, deployedPokemons))))
                        .ToList();

            if (session.LogicSettings.GymConfig.Enable &&
                ((session.LogicSettings.GymConfig.EnableAttackGym && forts.Where(w => w.Type == FortType.Gym && UseGymBattleTask.CanAttackGym(session, w, deployedPokemons)).Count() == 0) ||
                 (session.LogicSettings.GymConfig.EnableGymTraining && forts.Where(w => w.Type == FortType.Gym && UseGymBattleTask.CanTrainGym(session, w, deployedPokemons)).Count() == 0)
                ))
            {
                //Logger.Write("No usable gym found. Trying to refresh list.", LogLevel.Gym, ConsoleColor.Magenta);
                await GetPokeStops(session);
            }

            forts = forts.OrderBy(
                p =>
                session.Navigation.WalkStrategy.CalculateDistance(
                    session.Client.CurrentLatitude,
                    session.Client.CurrentLongitude,
                    p.Latitude,
                    p.Longitude,
                    session)
                ).ToList();

            if (session.LogicSettings.UseGpxPathing)
            {
                forts = forts.Where(p => LocationUtils.CalculateDistanceInMeters(p.Latitude, p.Longitude, session.Client.CurrentLatitude, session.Client.CurrentLongitude) < 40).ToList();
            }

            var reviveCount = session.Inventory.GetItems().Where(w => w.ItemId == POGOProtos.Inventory.Item.ItemId.ItemRevive || w.ItemId == POGOProtos.Inventory.Item.ItemId.ItemMaxRevive).Select(s => s.Count).Sum();

            if (!session.LogicSettings.GymConfig.Enable ||
                session.LogicSettings.GymConfig.MinRevivePotions > reviveCount
                /*|| session.Inventory.GetPlayerStats().FirstOrDefault().Level <= 5*/
                )
            {
                // Filter out the gyms
                forts = forts.Where(x => x.Type != FortType.Gym).ToList();
            }
            else if (session.LogicSettings.GymConfig.PrioritizeGymOverPokestop)
            {
                // Prioritize gyms over pokestops
                var gyms = forts.Where(x => x.Type == FortType.Gym &&
                                       LocationUtils.CalculateDistanceInMeters(x.Latitude, x.Longitude, session.Client.CurrentLatitude, session.Client.CurrentLongitude) < session.LogicSettings.GymConfig.MaxDistance);
                //.OrderBy(x => LocationUtils.CalculateDistanceInMeters(x.Latitude, x.Longitude, session.Client.CurrentLatitude, session.Client.CurrentLongitude));

                if (session.LogicSettings.GymConfig.PrioritizeGymWithFreeSlot)
                {
                    var freeSlots = gyms.Where(w => w.OwnedByTeam == session.Profile.PlayerData.Team && UseGymBattleTask.CanDeployToGym(session, w, deployedPokemons));
                    if (freeSlots.Count() > 0)
                    {
                        return(freeSlots.First());
                    }
                }

                // Return the first gym in range.
                if (gyms.Count() > 0)
                {
                    return(gyms.FirstOrDefault());
                }
            }

            return(forts.FirstOrDefault());
        }
Esempio n. 10
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var pokestopsTuple = await GetPokeStops(session);

            pokestopList = pokestopsTuple.Item2;

            while (pokestopList.Any())
            {
                cancellationToken.ThrowIfCancellationRequested();
                await SnipeMSniperTask.CheckMSniperLocation(session, cancellationToken);

                pokestopList =
                    pokestopList.OrderBy(
                        i =>
                        session.Navigation.WalkStrategy.CalculateDistance(
                            session.Client.CurrentLatitude, session.Client.CurrentLongitude, i.Latitude, i.Longitude, session)).ToList();

                // randomize next pokestop between first and second by distance
                var pokestopListNum = 0;
                if (pokestopList.Count > 1)
                {
                    pokestopListNum = rc.Next(0, 2);
                }

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

                // this logic should only be called when we reach a pokestop either via GPX path or normal walking
                // as when walk-sniping, we want to get to the snipe ASAP rather than stop for lured pokemon upon
                // calling FarmPokestop; in that situation we are also always within 40m of the pokestop, so no
                // need to walk to it
                var fortInfo = await session.Client.Fort.GetFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude);

                // we only move to the PokeStop, and send the associated FortTargetEvent, when not using GPX
                // also, GPX pathing uses its own EggWalker and calls the CatchPokemon tasks internally.
                if (!session.LogicSettings.UseGpxPathing)
                {
                    // Will modify Lat,Lng and Name to fake position
                    SetMoveToTargetTask.CheckSetMoveToTargetStatus(ref fortInfo, ref pokeStop);

                    var eggWalker = new EggWalker(1000, session);

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

                    if (!session.LogicSettings.UseGoogleWalk && !session.LogicSettings.UseYoursWalk)
                    {
                        session.EventDispatcher.Send(new FortTargetEvent {
                            Name = fortInfo.Name, Distance = distance, Route = "NecroBot"
                        });
                    }
                    else
                    {
                        BaseWalkStrategy.FortInfo = fortInfo;
                    }

                    await session.Navigation.Move(new GeoCoordinate(pokeStop.Latitude, pokeStop.Longitude,
                                                                    LocationUtils.getElevation(session, pokeStop.Latitude, pokeStop.Longitude)),
                                                  async() =>
                    {
                        if (SetMoveToTargetTask.CheckStopforSetMoveToTarget())
                        {
                            return(false);
                        }
                        // Catch normal map Pokemon
                        await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
                        //Catch Incense Pokemon
                        await CatchIncensePokemonsTask.Execute(session, cancellationToken);
                        // Minor fix google route ignore pokestop
                        await LookPokestops(session, pokeStop, cancellationToken);
                        return(true);
                    },
                                                  session,
                                                  cancellationToken);

                    // we have moved this distance, so apply it immediately to the egg walker.
                    await eggWalker.ApplyDistance(distance, cancellationToken);
                }
                if (SetMoveToTargetTask.CheckReachTarget(session))
                {
                    return;
                }

                await FortAction(session, pokeStop, fortInfo, cancellationToken);

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

                if (session.LogicSettings.EnableHumanWalkingSnipe)
                {
                    //refactore to move this code inside the task later.
                    await HumanWalkSnipeTask.Execute(session, cancellationToken,
                                                     async (double lat, double lng) =>
                    {
                        //idea of this function is to spin pokestop on way. maybe risky.
                        var reachablePokestops = pokestopList.Where(i =>
                                                                    LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                                                            session.Client.CurrentLongitude, i.Latitude, i.Longitude) < 40 &&
                                                                    i.CooldownCompleteTimestampMs == 0
                                                                    ).ToList();
                        reachablePokestops = reachablePokestops.OrderBy(i =>
                                                                        LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                                                                session.Client.CurrentLongitude, i.Latitude, i.Longitude)).ToList();

                        foreach (var ps in reachablePokestops)
                        {
                            if (!session.LogicSettings.UseGpxPathing)
                            {
                                pokestopList.Remove(ps);
                            }
                            var fi = await session.Client.Fort.GetFort(ps.Id, ps.Latitude, ps.Longitude);
                            await FarmPokestop(session, ps, fi, cancellationToken, true);
                            await Task.Delay(2000);
                        }
                    },
                                                     async() =>
                    {
                        // if using GPX we have to move back to the original pokestop, to resume the path.
                        // we do not try to use pokest;ops on the way back, as we will have used them getting
                        // here.
                        if (session.LogicSettings.UseGpxPathing)
                        {
                            var eggWalker = new EggWalker(1000, session);

                            var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                                   session.Client.CurrentLongitude, pokeStop.Latitude, pokeStop.Longitude);
                            var geo = new GeoCoordinate(pokeStop.Latitude, pokeStop.Longitude);

                            await session.Navigation.Move(geo,
                                                          async() =>
                            {
                                await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
                                //Catch Incense Pokemon
                                await CatchIncensePokemonsTask.Execute(session, cancellationToken);
                                return(true);
                            },
                                                          session,
                                                          cancellationToken);

                            await eggWalker.ApplyDistance(distance, cancellationToken);
                            return;
                        }

                        var nearestStop = pokestopList.OrderBy(i =>
                                                               LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                                                       session.Client.CurrentLongitude, i.Latitude, i.Longitude)).FirstOrDefault();

                        var walkedDistance = LocationUtils.CalculateDistanceInMeters(nearestStop.Latitude, nearestStop.Longitude, session.Client.CurrentLatitude, session.Client.CurrentLongitude);
                        if (walkedDistance > session.LogicSettings.HumanWalkingSnipeWalkbackDistanceLimit)
                        {
                            await Task.Delay(3000);
                            var nearbyPokeStops = await UpdateFortsData(session);
                            var notexists       = nearbyPokeStops.Where(p => !pokestopList.Any(x => x.Id == p.Id)).ToList();
                            pokestopList.AddRange(notexists);
                            session.EventDispatcher.Send(new PokeStopListEvent {
                                Forts = pokestopList
                            });
                            session.EventDispatcher.Send(new HumanWalkSnipeEvent()
                            {
                                Type            = HumanWalkSnipeEventTypes.PokestopUpdated,
                                Pokestops       = notexists,
                                NearestDistance = walkedDistance
                            });
                        }
                    });
                }
            }
        }
Esempio n. 11
0
        public static async Task <FortData> GetNextPokeStop(ISession session)
        {
            var priorityTarget = await SetMoveToTargetTask.GetTarget(session);

            if (priorityTarget != null)
            {
                return(priorityTarget);
            }


            if (session.Forts == null ||
                session.Forts.Count == 0 ||
                session.Forts.Count(p => p.CooldownCompleteTimestampMs < DateTime.UtcNow.ToUnixTime()) == 0)
            {
                //TODO : A logic need to be add for handle this  case?
            }
            ;

            var deployedPokemons = await session.Inventory.GetDeployedPokemons();

            var forts = session.Forts
                        .Where(p => p.CooldownCompleteTimestampMs < DateTime.UtcNow.ToUnixTime())
                        .Where(f => f.Type == FortType.Checkpoint ||
                               UseGymBattleTask.CanAttackGym(session, f, ref deployedPokemons) ||
                               UseGymBattleTask.CanTrainGym(session, f, null, ref deployedPokemons))
                        .ToList();

            if ((session.LogicSettings.GymConfig.EnableAttackGym && forts.Where(w => w.Type == FortType.Gym && UseGymBattleTask.CanAttackGym(session, w, ref deployedPokemons)).Count() == 0) ||
                (session.LogicSettings.GymConfig.EnableGymTraining && forts.Where(w => w.Type == FortType.Gym && UseGymBattleTask.CanTrainGym(session, w, null, ref deployedPokemons)).Count() == 0)
                )
            {
                //Logger.Write("No usable gym found. Trying to refresh list.", LogLevel.Gym, ConsoleColor.Magenta);
                await GetPokeStops(session);
            }

            forts = forts.OrderBy(
                p =>
                session.Navigation.WalkStrategy.CalculateDistance(
                    session.Client.CurrentLatitude,
                    session.Client.CurrentLongitude,
                    p.Latitude,
                    p.Longitude,
                    session)
                ).ToList();

            if (session.LogicSettings.UseGpxPathing)
            {
                forts = forts.Where(p => LocationUtils.CalculateDistanceInMeters(p.Latitude, p.Longitude, session.Client.CurrentLatitude, session.Client.CurrentLongitude) < 40).ToList();
            }

            if (!session.LogicSettings.GymConfig.Enable /*|| session.Inventory.GetPlayerStats().Result.FirstOrDefault().Level <= 5*/)
            {
                // Filter out the gyms
                forts = forts.Where(x => x.Type != FortType.Gym).ToList();
            }
            else if (session.LogicSettings.GymConfig.PrioritizeGymOverPokestop)
            {
                // Prioritize gyms over pokestops
                var gyms = forts.Where(x => x.Type == FortType.Gym &&
                                       LocationUtils.CalculateDistanceInMeters(x.Latitude, x.Longitude, session.Client.CurrentLatitude, session.Client.CurrentLongitude) < session.LogicSettings.GymConfig.MaxDistance);

                // Return the first gym in range.
                if (gyms.Count() > 0)
                {
                    return(gyms.FirstOrDefault());
                }
            }

            if (forts.Count == 1)
            {
                return(forts.FirstOrDefault());
            }

            return(forts.Skip((int)DateTime.Now.Ticks % 2).FirstOrDefault());
        }