Exemple #1
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var distanceFromStart = LocationUtils.CalculateDistanceInMeters(
                session.Settings.DefaultLatitude, session.Settings.DefaultLongitude,
                session.Client.CurrentLatitude, session.Client.CurrentLongitude);

            // Edge case for when the client somehow ends up outside the defined radius
            if (session.LogicSettings.MaxTravelDistanceInMeters != 0 &&
                distanceFromStart > session.LogicSettings.MaxTravelDistanceInMeters)
            {
                Logger.Write(
                    session.Translation.GetTranslation(TranslationString.FarmPokestopsOutsideRadius, distanceFromStart),
                    LogLevel.Warning);

                var eggWalker = new EggWalker(1000, session);

                await session.Navigation.Move(new GeoCoordinate(
                                                  session.Settings.DefaultLatitude,
                                                  session.Settings.DefaultLongitude,
                                                  LocationUtils.getElevation(session.Settings.DefaultLatitude,
                                                                             session.Settings.DefaultLongitude)),
                                              null,
                                              session,
                                              cancellationToken);

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

            // initialize the variables in UseNearbyPokestopsTask here, as this is a fresh start.
            UseNearbyPokestopsTask.Initialize();
            await UseNearbyPokestopsTask.Execute(session, cancellationToken);
        }
Exemple #2
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var distanceFromStart = LocationUtils.CalculateDistanceInMeters(
                session.Settings.DefaultLatitude, session.Settings.DefaultLongitude,
                session.Client.CurrentLatitude, session.Client.CurrentLongitude);

            var response = await session.Client.Player.UpdatePlayerLocation(session.Client.CurrentLatitude, session.Client.CurrentLongitude, session.Client.CurrentAltitude, 0);

            // Edge case for when the client somehow ends up outside the defined radius
            if (session.LogicSettings.MaxTravelDistanceInMeters != 0 && checkForMoveBackToDefault &&
                distanceFromStart > session.LogicSettings.MaxTravelDistanceInMeters)
            {
                checkForMoveBackToDefault = false;
                Logger.Write(
                    session.Translation.GetTranslation(TranslationString.FarmPokestopsOutsideRadius, distanceFromStart),
                    LogLevel.Warning);

                var eggWalker = new EggWalker(1000, session);

                var defaultLocation = new MapLocation(session.Settings.DefaultLatitude,
                                                      session.Settings.DefaultLongitude,
                                                      LocationUtils.getElevation(session.ElevationService, session.Settings.DefaultLatitude, session.Settings.DefaultLongitude)
                                                      );

                await session.Navigation.Move(defaultLocation,
                                              async() =>
                {
                    await MSniperServiceTask.Execute(session, cancellationToken);
                },
                                              session,
                                              cancellationToken);

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

            await CatchNearbyPokemonsTask.Execute(session, cancellationToken);

            // initialize the variables in UseNearbyPokestopsTask here, as this is a fresh start.
            UseNearbyPokestopsTask.Initialize();
            await UseNearbyPokestopsTask.Execute(session, cancellationToken);
        }
Exemple #3
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            var tracks    = GetGpxTracks(session);
            var eggWalker = new EggWalker(1000, session);

            if (!_resumeTrack.HasValue || !_resumeTrackSeg.HasValue || !_resumeTrackPt.HasValue)
            {
                _resumeTrack    = session.LogicSettings.ResumeTrack;
                _resumeTrackSeg = session.LogicSettings.ResumeTrackSeg;
                _resumeTrackPt  = session.LogicSettings.ResumeTrackPt;

                // initialize the variables in UseNearbyPokestopsTask here, as this is a fresh start.
                UseNearbyPokestopsTask.Initialize();
            }

            for (var curTrk = _resumeTrack.Value; curTrk < tracks.Count; curTrk++)
            {
                _resumeTrack = curTrk;
                cancellationToken.ThrowIfCancellationRequested();

                var track         = tracks.ElementAt(curTrk);
                var trackSegments = track.Segments;

                for (var curTrkSeg = _resumeTrackSeg.Value; curTrkSeg < trackSegments.Count; curTrkSeg++)
                {
                    _resumeTrackSeg = curTrkSeg;
                    cancellationToken.ThrowIfCancellationRequested();

                    var trackPoints = trackSegments.ElementAt(curTrkSeg).TrackPoints;

                    for (var curTrkPt = _resumeTrackPt.Value; curTrkPt < trackPoints.Count; curTrkPt++)
                    {
                        _resumeTrackPt = curTrkPt;
                        cancellationToken.ThrowIfCancellationRequested();

                        var nextPoint = trackPoints.ElementAt(curTrkPt);
                        var distance  = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                                session.Client.CurrentLongitude,
                                                                                Convert.ToDouble(nextPoint.Lat, CultureInfo.InvariantCulture),
                                                                                Convert.ToDouble(nextPoint.Lon, CultureInfo.InvariantCulture));

                        if (distance > 5000)
                        {
                            session.EventDispatcher.Send(new ErrorEvent
                            {
                                Message =
                                    session.Translation.GetTranslation(TranslationString.DesiredDestTooFar,
                                                                       nextPoint.Lat, nextPoint.Lon, session.Client.CurrentLatitude,
                                                                       session.Client.CurrentLongitude)
                            });
                            break;
                        }
                        var lat = Convert.ToDouble(trackPoints.ElementAt(curTrkPt).Lat, CultureInfo.InvariantCulture);
                        var lng = Convert.ToDouble(trackPoints.ElementAt(curTrkPt).Lon, CultureInfo.InvariantCulture);

                        IGeoLocation destination = new GPXPointLocation(lat, lng, LocationUtils.getElevation(session.ElevationService, lat, lng));

                        await session.Navigation.Move(destination,
                                                      async() =>
                        {
                            await MSniperServiceTask.Execute(session, cancellationToken);

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

                        await eggWalker.ApplyDistance(distance, cancellationToken);

                        // Return to FarmState/StateMachine if we have reached both user defined limits
                        if ((UseNearbyPokestopsTask._pokestopLimitReached || UseNearbyPokestopsTask._pokestopTimerReached) &&
                            (CatchPokemonTask._catchPokemonLimitReached || CatchPokemonTask._catchPokemonTimerReached))
                        {
                            return;
                        }
                    } //end trkpts
                    _resumeTrackPt = 0;
                }     //end trksegs
                _resumeTrackSeg = 0;
            }         //end tracks
            _resumeTrack = 0;
        }
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            var tracks    = GetGpxTracks(session);
            var eggWalker = new EggWalker(1000, session);

            if (_resumeTrack + _resumeTrackSeg + _resumeTrackPt == 0)
            {
                _resumeTrack    = session.LogicSettings.ResumeTrack;
                _resumeTrackSeg = session.LogicSettings.ResumeTrackSeg;
                _resumeTrackPt  = session.LogicSettings.ResumeTrackPt;

                // initialize the variables in UseNearbyPokestopsTask here, as this is a fresh start.
                UseNearbyPokestopsTask.Initialize();
            }

            for (var curTrk = _resumeTrack; curTrk < tracks.Count; curTrk++)
            {
                _resumeTrack = curTrk;
                cancellationToken.ThrowIfCancellationRequested();

                var track         = tracks.ElementAt(curTrk);
                var trackSegments = track.Segments;

                for (var curTrkSeg = _resumeTrackSeg; curTrkSeg < trackSegments.Count; curTrkSeg++)
                {
                    _resumeTrackSeg = curTrkSeg;
                    cancellationToken.ThrowIfCancellationRequested();

                    var trackPoints = trackSegments.ElementAt(curTrkSeg).TrackPoints;

                    for (var curTrkPt = _resumeTrackPt; curTrkPt < trackPoints.Count; curTrkPt++)
                    {
                        _resumeTrackPt = curTrkPt;
                        cancellationToken.ThrowIfCancellationRequested();

                        var nextPoint = trackPoints.ElementAt(curTrkPt);
                        var distance  = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                                session.Client.CurrentLongitude,
                                                                                Convert.ToDouble(nextPoint.Lat, CultureInfo.InvariantCulture),
                                                                                Convert.ToDouble(nextPoint.Lon, CultureInfo.InvariantCulture));

                        if (distance > 5000)
                        {
                            session.EventDispatcher.Send(new ErrorEvent
                            {
                                Message =
                                    session.Translation.GetTranslation(TranslationString.DesiredDestTooFar,
                                                                       nextPoint.Lat, nextPoint.Lon, session.Client.CurrentLatitude,
                                                                       session.Client.CurrentLongitude)
                            });
                            break;
                        }

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

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

                        await eggWalker.ApplyDistance(distance, cancellationToken);
                    } //end trkpts
                    _resumeTrackPt = 0;
                }     //end trksegs
                _resumeTrackSeg = 0;
            }         //end tracks
            _resumeTrack = 0;
        }