Пример #1
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);
            }
        }
Пример #2
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);
            }
        }
        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);
            }
        }
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var pokestopsTuple = await GetPokeStops(session);

            pokestopList = pokestopsTuple.Item2;

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

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

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

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

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

                // we only move to the PokeStop, and send the associated FortTargetEvent, when not using GPX
                // also, GPX pathing uses its own EggWalker and calls the CatchPokemon tasks internally.
                if (!session.LogicSettings.UseGpxPathing)
                {
                    var eggWalker = new EggWalker(1000, session);

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

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

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

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

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

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

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

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

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

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

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

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

                        var walkedDistance = LocationUtils.CalculateDistanceInMeters(nearestStop.Latitude, nearestStop.Longitude, session.Client.CurrentLatitude, session.Client.CurrentLongitude);
                        if (walkedDistance > session.LogicSettings.HumanWalkingSnipeWalkbackDistanceLimit)
                        {
                            await Task.Delay(3000);
                            var nearbyPokeStops = await UpdateFortsData(session);
                            var notexists       = nearbyPokeStops.Where(p => !pokestopList.Any(x => x.Id == p.Id)).ToList();
                            pokestopList.AddRange(notexists);
                            session.EventDispatcher.Send(new PokeStopListEvent {
                                Forts = pokestopList
                            });
                            session.EventDispatcher.Send(new HumanWalkSnipeEvent()
                            {
                                Type            = HumanWalkSnipeEventTypes.PokestopUpdated,
                                Pokestops       = notexists,
                                NearestDistance = walkedDistance
                            });
                        }
                    });
                }
            }
        }
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            //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();
                await SnipeMSniperTask.CheckMSniperLocation(session, cancellationToken);

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

                await SnipeMSniperTask.CheckMSniperLocation(session, cancellationToken);

                if (session.LogicSettings.EnableHumanWalkingSnipe)
                {
                    await HumanWalkSnipeTask.Execute(session, cancellationToken, pokeStop);
                }
                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.
                pokeStop = await GetNextPokeStop(session);
            }

            //await VisitNearByGymTask.UpdateGymList(session, mapObjectTupe.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);
            //    //samuraitruong: since we has duplication code for gym. I temporary comment this line to disable my feature. keep the code as reference, will remove later.

            //    //await VisitNearByGymTask.Execute(session, cancellationToken);

            //    if (session.LogicSettings.EnableHumanWalkingSnipe)
            //    {
            //        //refactore to move this code inside the task later.
            //        await HumanWalkSnipeTask.Execute(session, cancellationToken,
            //            async (lat, 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, cancellationToken);
            //                }
            //            },
            //            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);
            //                        },
            //                        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();

            //                if (nearestStop != null)
            //                {
            //                    var walkedDistance = LocationUtils.CalculateDistanceInMeters(nearestStop.Latitude, nearestStop.Longitude, session.Client.CurrentLatitude, session.Client.CurrentLongitude);
            //                    if (walkedDistance > session.LogicSettings.HumanWalkingSnipeWalkbackDistanceLimit)
            //                    {
            //                        await Task.Delay(3000, cancellationToken);
            //                        var nearbyPokeStops = await UpdateFortsData(session);
            //                        var notexists = nearbyPokeStops.Where(p => _pokestopList.All(x => x.Id != p.Id)).ToList();
            //                        _pokestopList.AddRange(notexists);
            //                        session.EventDispatcher.Send(new PokeStopListEvent { Forts = _pokestopList });
            //                        session.EventDispatcher.Send(new HumanWalkSnipeEvent
            //                        {
            //                            Type = HumanWalkSnipeEventTypes.PokestopUpdated,
            //                            Pokestops = notexists,
            //                            NearestDistance = walkedDistance
            //                        });
            //                    }
            //                }
            //            });
            //    }
            //}
        }
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var pokestopList = await GetPokeStops(session);

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

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

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

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

                await FortPokestop(session, cancellationToken, pokeStop);

                if (++stopsHit >= storeRI)     //TODO: OR item/pokemon bag is full //check stopsHit against storeRI random without dividing.
                {
                    storeRI  = rc.Next(6, 12); //set new storeRI for new random value
                    stopsHit = 0;

                    if (session.LogicSettings.UseNearActionRandom)
                    {
                        if (NearRandom.Next(1, 10) > 4)
                        {
                            await RecycleItemsTask.Execute(session, cancellationToken);
                        }
                    }
                    else
                    {
                        await RecycleItemsTask.Execute(session, cancellationToken);
                    }

                    if (session.LogicSettings.EvolveAllPokemonWithEnoughCandy ||
                        session.LogicSettings.EvolveAllPokemonAboveIv ||
                        session.LogicSettings.UseLuckyEggsWhileEvolving ||
                        session.LogicSettings.KeepPokemonsThatCanEvolve)
                    {
                        if (session.LogicSettings.UseNearActionRandom)
                        {
                            if (NearRandom.Next(1, 10) > 4)
                            {
                                await EvolvePokemonTask.Execute(session, cancellationToken);
                            }
                        }
                        else
                        {
                            await EvolvePokemonTask.Execute(session, cancellationToken);
                        }
                    }

                    if (session.LogicSettings.UseLuckyEggConstantly)
                    {
                        if (session.LogicSettings.UseNearActionRandom)
                        {
                            if (NearRandom.Next(1, 10) > 4)
                            {
                                await UseLuckyEggConstantlyTask.Execute(session, cancellationToken);
                            }
                        }
                        else
                        {
                            await UseLuckyEggConstantlyTask.Execute(session, cancellationToken);
                        }
                    }

                    if (session.LogicSettings.UseIncenseConstantly)
                    {
                        if (session.LogicSettings.UseNearActionRandom)
                        {
                            if (NearRandom.Next(1, 10) > 4)
                            {
                                await UseIncenseConstantlyTask.Execute(session, cancellationToken);
                            }
                        }
                        else
                        {
                            await UseIncenseConstantlyTask.Execute(session, cancellationToken);
                        }
                    }

                    if (session.LogicSettings.TransferDuplicatePokemon)
                    {
                        if (session.LogicSettings.UseNearActionRandom)
                        {
                            if (NearRandom.Next(1, 10) > 4)
                            {
                                await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
                            }
                        }
                        else
                        {
                            await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
                        }
                    }

                    if (session.LogicSettings.TransferWeakPokemon)
                    {
                        if (session.LogicSettings.UseNearActionRandom)
                        {
                            if (NearRandom.Next(1, 10) > 4)
                            {
                                await TransferWeakPokemonTask.Execute(session, cancellationToken);
                            }
                        }
                        else
                        {
                            await TransferWeakPokemonTask.Execute(session, cancellationToken);
                        }
                    }

                    if (session.LogicSettings.RenamePokemon)
                    {
                        if (session.LogicSettings.UseNearActionRandom)
                        {
                            if (NearRandom.Next(1, 10) > 4)
                            {
                                await RenamePokemonTask.Execute(session, cancellationToken);
                            }
                        }
                        else
                        {
                            await RenamePokemonTask.Execute(session, cancellationToken);
                        }
                    }

                    if (session.LogicSettings.AutoFavoritePokemon)
                    {
                        if (session.LogicSettings.UseNearActionRandom)
                        {
                            if (NearRandom.Next(1, 10) > 4)
                            {
                                await FavoritePokemonTask.Execute(session, cancellationToken);
                            }
                        }
                        else
                        {
                            await FavoritePokemonTask.Execute(session, cancellationToken);
                        }
                    }

                    if (session.LogicSettings.AutomaticallyLevelUpPokemon)
                    {
                        if (session.LogicSettings.UseNearActionRandom)
                        {
                            if (NearRandom.Next(1, 10) > 4)
                            {
                                await LevelUpPokemonTask.Execute(session, cancellationToken);
                            }
                        }
                        else
                        {
                            await LevelUpPokemonTask.Execute(session, cancellationToken);
                        }
                    }

                    await GetPokeDexCount.Execute(session, cancellationToken);
                }

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

                //samuraitruong: temoporary not allow human walk snipe until we implement a good logic to use.
                if (session.LogicSettings.EnableHumanWalkingSnipe && !session.LogicSettings.UseGpxPathing)
                {
                    //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) < 30.0)
                                                 .ToList();
                        reachablePokestops = reachablePokestops.OrderBy(i => LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                                                                     session.Client.CurrentLongitude, i.Latitude, i.Longitude))
                                             .ToList();
                        foreach (var ps in reachablePokestops)
                        {
                            pokestopList.Remove(ps);
                            await FortPokestop(session, cancellationToken, ps);
                        }
                    },
                                                     async() =>
                    {
                        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,
                                NearestDistane = walkedDistance
                            });
                        }
                    });
                }
            }
        }
Пример #7
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var pokestopsTuple = await GetPokeStops(session);

            var allPokestops = pokestopsTuple.Item1;
            var pokestopList = pokestopsTuple.Item2;

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

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

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

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

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

                // we only move to the PokeStop, and send the associated FortTargetEvent, when not using GPX
                // also, GPX pathing uses its own EggWalker and calls the CatchPokemon tasks internally.
                if (!session.LogicSettings.UseGpxPathing)
                {
                    var eggWalker = new EggWalker(1000, session);

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

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

                    await session.Navigation.Move(new GeoCoordinate(pokeStop.Latitude, pokeStop.Longitude,
                                                                    LocationUtils.getElevation(session, pokeStop.Latitude, pokeStop.Longitude)),
                                                  async() =>
                    {
                        // Catch normal map Pokemon
                        await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
                        //Catch Incense Pokemon
                        await CatchIncensePokemonsTask.Execute(session, cancellationToken);
                        return(true);
                    },
                                                  session,
                                                  cancellationToken);

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

                //Catch Lure Pokemon
                if (pokeStop.LureInfo != null)
                {
                    // added for cooldowns
                    await Task.Delay(Math.Min(session.LogicSettings.DelayBetweenPlayerActions, 3000));

                    await CatchLurePokemonsTask.Execute(session, pokeStop, cancellationToken);
                }

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

                if (++stopsHit >= storeRI)     //TODO: OR item/pokemon bag is full //check stopsHit against storeRI random without dividing.
                {
                    storeRI  = rc.Next(6, 12); //set new storeRI for new random value
                    stopsHit = 0;

                    if (session.LogicSettings.UseNearActionRandom)
                    {
                        await HumanRandomActionTask.Execute(session, cancellationToken);
                    }
                    else
                    {
                        await RecycleItemsTask.Execute(session, cancellationToken);

                        if (session.LogicSettings.EvolveAllPokemonWithEnoughCandy ||
                            session.LogicSettings.EvolveAllPokemonAboveIv ||
                            session.LogicSettings.UseLuckyEggsWhileEvolving ||
                            session.LogicSettings.KeepPokemonsThatCanEvolve)
                        {
                            await EvolvePokemonTask.Execute(session, cancellationToken);
                        }
                        if (session.LogicSettings.UseLuckyEggConstantly)
                        {
                            await UseLuckyEggConstantlyTask.Execute(session, cancellationToken);
                        }
                        if (session.LogicSettings.UseIncenseConstantly)
                        {
                            await UseIncenseConstantlyTask.Execute(session, cancellationToken);
                        }
                        if (session.LogicSettings.TransferDuplicatePokemon)
                        {
                            await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
                        }
                        if (session.LogicSettings.TransferWeakPokemon)
                        {
                            await TransferWeakPokemonTask.Execute(session, cancellationToken);
                        }
                        if (session.LogicSettings.RenamePokemon)
                        {
                            await RenamePokemonTask.Execute(session, cancellationToken);
                        }
                        if (session.LogicSettings.AutoFavoritePokemon)
                        {
                            await FavoritePokemonTask.Execute(session, cancellationToken);
                        }
                        if (session.LogicSettings.AutomaticallyLevelUpPokemon)
                        {
                            await LevelUpPokemonTask.Execute(session, cancellationToken);
                        }

                        await GetPokeDexCount.Execute(session, cancellationToken);
                    }
                }

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

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

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

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

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

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

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

                        var walkedDistance = LocationUtils.CalculateDistanceInMeters(nearestStop.Latitude, nearestStop.Longitude, session.Client.CurrentLatitude, session.Client.CurrentLongitude);
                        if (walkedDistance > session.LogicSettings.HumanWalkingSnipeWalkbackDistanceLimit)
                        {
                            await Task.Delay(3000);
                            var nearbyPokeStops = await UpdateFortsData(session);
                            var notexists       = nearbyPokeStops.Where(p => !pokestopList.Any(x => x.Id == p.Id)).ToList();
                            pokestopList.AddRange(notexists);
                            session.EventDispatcher.Send(new PokeStopListEvent {
                                Forts = pokestopList
                            });
                            session.EventDispatcher.Send(new HumanWalkSnipeEvent()
                            {
                                Type            = HumanWalkSnipeEventTypes.PokestopUpdated,
                                Pokestops       = notexists,
                                NearestDistance = walkedDistance
                            });
                        }
                    });
                }
            }
        }