Пример #1
0
        private static async Task MoveToPokemon(WildPokemon pokemon, ISession session, CancellationToken cancellationToken)
        {
            //split the way in 5 steps
            var sourceLocation       = new GeoCoordinate(session.Client.CurrentLatitude, session.Client.CurrentLongitude);
            var targetLocation       = new GeoCoordinate(pokemon.Latitude, pokemon.Longitude);
            var distanceToTarget     = LocationUtils.CalculateDistanceInMeters(sourceLocation, new GeoCoordinate(pokemon.Latitude, pokemon.Longitude));
            var nextWaypointDistance = distanceToTarget / 5;
            var nextWaypointBearing  = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
            var waypoint             = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

            for (var i = 0; i < 5; i++)
            {
                if (session.MapCache.CheckPokemonCaught(pokemon.EncounterId) || session.ForceMoveJustDone)
                {
                    break;
                }
                await MoveTo(waypoint, session, cancellationToken);

                waypoint = LocationUtils.CreateWaypoint(waypoint, nextWaypointDistance, nextWaypointBearing);
            }
            if (!session.ForceMoveJustDone)
            {
                await MoveTo(sourceLocation, session, cancellationToken);
            }
        }
        private static async Task MoveToPokemon(WildPokemon pokemon, ISession session, CancellationToken cancellationToken)
        {
            //split the way in 5 steps
            var sourceLocation       = new GeoCoordinate(session.Client.CurrentLatitude, session.Client.CurrentLongitude);
            var targetLocation       = new GeoCoordinate(pokemon.Latitude, pokemon.Longitude);
            var distanceToTarget     = LocationUtils.CalculateDistanceInMeters(sourceLocation, new GeoCoordinate(pokemon.Latitude, pokemon.Longitude));
            var nextWaypointDistance = distanceToTarget / 5;
            var nextWaypointBearing  = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
            var waypoint             = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

            for (var i = 0; i < 5; i++)
            {
                await session.Navigation.Move(new GeoCoordinate(waypoint.Latitude, waypoint.Longitude),
                                              session.LogicSettings.WalkingSpeedMin, session.LogicSettings.WalkingSpeedMax,
                                              async() =>
                {
                    // Catch normal map Pokemon
                    await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
                    //Catch Incense Pokemon
                    await CatchIncensePokemonsTask.Execute(session, cancellationToken);
                    return(true);
                }, null, cancellationToken, session);

                if (session.MapCache.CheckPokemonCaught(pokemon.EncounterId))
                {
                    return;
                }
                waypoint = LocationUtils.CreateWaypoint(waypoint, nextWaypointDistance, nextWaypointBearing);
            }
        }
Пример #3
0
        public async Task <PlayerUpdateResponse> HumanLikeWalking(Location targetLocation, double walkingSpeedInKilometersPerHour, Func <Task> functionExecutedWhileWalking)
        {
            double speedInMetersPerSecond = walkingSpeedInKilometersPerHour / 3.6;

            Location sourceLocation   = new Location(_client.CurrentLat, _client.CurrentLng);
            var      distanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);

            Logger.Normal($"(NAVIGATION) Distance to target location: {distanceToTarget:0.##} meters. Will take {distanceToTarget / speedInMetersPerSecond:0.##} seconds!");

            double   nextWaypointBearing  = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
            double   nextWaypointDistance = speedInMetersPerSecond;
            Location waypoint             = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

            //Initial walking
            DateTime requestSendDateTime = DateTime.Now;
            var      result = await _client.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude, _client.Settings.DefaultAltitude);

            do
            {
                double millisecondsUntilGetUpdatePlayerLocationResponse = (DateTime.Now - requestSendDateTime).TotalMilliseconds;

                sourceLocation = new Location(_client.CurrentLat, _client.CurrentLng);
                var currentDistanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);

                if (currentDistanceToTarget < 40)
                {
                    if (speedInMetersPerSecond > speedDownTo)
                    {
                        Logger.Normal("(NAVIGATION) We are within 40 meters of the target. Speeding down to 10 km/h to not pass the target.");
                        speedInMetersPerSecond = speedDownTo;
                    }
                    else
                    {
                        Logger.Normal("(NAVIGATION) We are within 40 meters of the target, attempting to interact.");
                    }
                }
                else
                {
                    Logger.Normal($"(NAVIGATION) Distance to target location: {LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation):0.##} meters.");
                }

                nextWaypointDistance = Math.Min(currentDistanceToTarget, millisecondsUntilGetUpdatePlayerLocationResponse / 1000 * speedInMetersPerSecond);
                nextWaypointBearing  = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
                waypoint             = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

                requestSendDateTime = DateTime.Now;
                result = await _client.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude, _client.Settings.DefaultAltitude);

                if (functionExecutedWhileWalking != null)
                {
                    await functionExecutedWhileWalking();
                }

                await Task.Delay(Math.Min((int)(distanceToTarget / speedInMetersPerSecond * 1000), 3000));
            } while (LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation) >= 30);

            return(result);
        }
Пример #4
0
        public async Task <PlayerUpdateResponse> HumanLikeWalking(GeoCoordinate targetLocation, double walkingSpeedInKilometersPerHour, Action functionExecutedWhileWalking)
        {
            // todo:: gut initial logic and put everything in a loop correctly
            var speedInMetersPerSecond = walkingSpeedInKilometersPerHour / 3.6;

            var sourceLocation   = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
            var distanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);
            // Logger.Write($"Distance to target location: {distanceToTarget:0.##} meters. Will take {distanceToTarget/speedInMetersPerSecond:0.##} seconds!", LogLevel.Info);

            var nextWaypointBearing  = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
            var nextWaypointDistance = speedInMetersPerSecond;
            var waypoint             = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

            //Initial walking
            var requestSendDateTime = DateTime.Now;
            PlayerUpdateResponse result;
            await _player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude, _client.Settings.DefaultAltitude);

            do
            {
                var millisecondsUntilGetUpdatePlayerLocationResponse =
                    (DateTime.Now - requestSendDateTime).TotalMilliseconds;

                sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
                var currentDistanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);

                if (currentDistanceToTarget < 15)
                {
                    if (speedInMetersPerSecond > SpeedDownTo)
                    {
                        //Logger.Write("We are within 40 meters of the target. Speeding down to 10 km/h to not pass the target.", LogLevel.Info);
                        speedInMetersPerSecond = SpeedDownTo;
                    }
                }

                nextWaypointDistance = Math.Min(currentDistanceToTarget,
                                                millisecondsUntilGetUpdatePlayerLocationResponse / 1000 * speedInMetersPerSecond);
                nextWaypointBearing = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
                waypoint            = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

                requestSendDateTime = DateTime.Now;
                result =
                    await
                    _player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude,
                                                 _client.Settings.DefaultAltitude);

                //if (result.WildPokemons.Count > 0)
                functionExecutedWhileWalking.Invoke();

                if (_logicSettings.Teleport == false)
                {
                    await Task.Delay(Math.Min((int)(currentDistanceToTarget / speedInMetersPerSecond * 1000), 1500));
                }
            } while (LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation) >= 10);

            return(result);
        }
Пример #5
0
        public async Task <PlayerUpdateResponse> HumanLikeWalking(GeoCoordinate targetLocation,
                                                                  double walkingSpeedInKilometersPerHour, Func <Task> functionExecutedWhileWalking)
        {
            var speedInMetersPerSecond = walkingSpeedInKilometersPerHour / 3.6;

            var sourceLocation   = new GeoCoordinate(_client.CurrentLat, _client.CurrentLng);
            var distanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);
            // Logger.Write($"Distance to target location: {distanceToTarget:0.##} meters. Will take {distanceToTarget/speedInMetersPerSecond:0.##} seconds!", LogLevel.Info);

            var nextWaypointBearing  = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
            var nextWaypointDistance = speedInMetersPerSecond;
            var waypoint             = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

            //Initial walking
            var requestSendDateTime = DateTime.Now;
            var result =
                await
                _client.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude, _client.Settings.DefaultAltitude);

            do
            {
                var millisecondsUntilGetUpdatePlayerLocationResponse =
                    (DateTime.Now - requestSendDateTime).TotalMilliseconds;

                sourceLocation = new GeoCoordinate(_client.CurrentLat, _client.CurrentLng);
                var currentDistanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);

                if (currentDistanceToTarget < 40)
                {
                    if (speedInMetersPerSecond > SpeedDownTo)
                    {
                        //Logger.Write("We are within 40 meters of the target. Speeding down to 10 km/h to not pass the target.", LogLevel.Info);
                        speedInMetersPerSecond = SpeedDownTo;
                    }
                }

                nextWaypointDistance = Math.Min(currentDistanceToTarget,
                                                millisecondsUntilGetUpdatePlayerLocationResponse / 1000 * speedInMetersPerSecond);
                nextWaypointBearing = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
                waypoint            = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

                requestSendDateTime = DateTime.Now;
                result =
                    await
                    _client.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude,
                                                 _client.Settings.DefaultAltitude);

                if (functionExecutedWhileWalking != null)
                {
                    await functionExecutedWhileWalking(); // look for pokemon
                }
                await Task.Delay(Math.Min((int)(distanceToTarget / speedInMetersPerSecond * 1000), 3000));
            } while (LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation) >= 30);

            return(result);
        }
Пример #6
0
        public static async Task <PlayerUpdateResponse> HumanLikeWalking(GeoUtils targetLocation, Func <Task <bool> > functionExecutedWhileWalking)
        {
            double walkingSpeedInKilometersPerHour = RandomHelper.RandomWalkSpeed(Logic._client.Settings.WalkingSpeedInKilometerPerHour);
            var    speedInMetersPerSecond          = walkingSpeedInKilometersPerHour / 3.6;

            var sourceLocation   = new GeoUtils(Logic._client.CurrentLatitude, Logic._client.CurrentLongitude);
            var distanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);

            Logger.Write($"Distance to target location: {distanceToTarget:0.##} meters. Will take {distanceToTarget / speedInMetersPerSecond:0.##} seconds!", LogLevel.Navigation);

            var nextWaypointBearing  = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
            var nextWaypointDistance = speedInMetersPerSecond;
            var waypoint             = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

            //Initial walking
            var requestSendDateTime = DateTime.Now;
            PlayerUpdateResponse result;
            await Logic._client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude, Logic._client.Settings.DefaultAltitude);

            Gui.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude);
            Gui.UpdateRouteToTarget(sourceLocation, targetLocation);

            do
            {
                walkingSpeedInKilometersPerHour = RandomHelper.RandomWalkSpeed(Logic._client.Settings.WalkingSpeedInKilometerPerHour);
                speedInMetersPerSecond          = walkingSpeedInKilometersPerHour / 3.6;

                var millisecondsUntilGetUpdatePlayerLocationResponse = (DateTime.Now - requestSendDateTime).TotalMilliseconds;

                sourceLocation = new GeoUtils(Logic._client.CurrentLatitude, Logic._client.CurrentLongitude);
                var currentDistanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);
                Logger.Write($"Distance to target location: {currentDistanceToTarget:0.##} meters. Will take {currentDistanceToTarget / speedInMetersPerSecond:0.##} seconds with a speed of {walkingSpeedInKilometersPerHour}km/h!", LogLevel.Debug);

                nextWaypointDistance = Math.Min(currentDistanceToTarget,
                                                millisecondsUntilGetUpdatePlayerLocationResponse / 1000 * speedInMetersPerSecond);
                nextWaypointBearing = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
                waypoint            = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

                requestSendDateTime = DateTime.Now;
                result =
                    await
                    Logic._client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude,
                                                              Logic._client.Settings.DefaultAltitude);

                Gui.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude);

                if (functionExecutedWhileWalking != null)
                {
                    await functionExecutedWhileWalking();// look for pokemon
                }
            } while (LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation) >= 35);

            return(result);
        }
Пример #7
0
        public async Task <PlayerUpdateResponse> HumanPathWalking(GpxReader.Trkpt trk,
                                                                  double walkingSpeedInKilometersPerHour, Action functionExecutedWhileWalking)
        {
            //PlayerUpdateResponse result = null;

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

            var speedInMetersPerSecond = walkingSpeedInKilometersPerHour / 3.6;

            var sourceLocation   = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
            var distanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);
            // Logger.Write($"Distance to target location: {distanceToTarget:0.##} meters. Will take {distanceToTarget/speedInMetersPerSecond:0.##} seconds!", LogLevel.Info);

            var nextWaypointBearing  = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
            var nextWaypointDistance = speedInMetersPerSecond;
            var waypoint             = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing,
                                                                    Convert.ToDouble(trk.Ele, CultureInfo.InvariantCulture));

            //Initial walking

            var requestSendDateTime = DateTime.Now;
            PlayerUpdateResponse result;
            await _player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude);

            do
            {
                var millisecondsUntilGetUpdatePlayerLocationResponse =
                    (DateTime.Now - requestSendDateTime).TotalMilliseconds;

                sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
                var currentDistanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);

                nextWaypointDistance = Math.Min(currentDistanceToTarget,
                                                millisecondsUntilGetUpdatePlayerLocationResponse / 1000 * speedInMetersPerSecond);
                nextWaypointBearing = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
                waypoint            = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

                requestSendDateTime = DateTime.Now;
                result =
                    await
                    _player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude,
                                                 waypoint.Altitude);

                functionExecutedWhileWalking?.Invoke(); // look for pokemon & hit stops

                await Task.Delay(Math.Min((int)(distanceToTarget / speedInMetersPerSecond * 1000), 3000));
            } while (LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation) >= 30);

            return(result);
        }
Пример #8
0
        private async Task <PlayerUpdateResponse> GoToWaypoint(GeoCoordinate targetLocation, Func <Task <bool> > functionExecutedWhileWalking, ISession session, CancellationToken cancellationToken, double distanceToTarget)
        {
            PlayerUpdateResponse result;

            var speedInMetersPerSecond = session.LogicSettings.UseWalkingSpeedVariant ? MajorWalkingSpeedVariant(session) :
                                         session.LogicSettings.WalkingSpeedInKilometerPerHour / 3.6;
            var sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);

            var requestSendDateTime = DateTime.Now;

            do
            {
                cancellationToken.ThrowIfCancellationRequested();

                var millisecondsUntilGetUpdatePlayerLocationResponse = (DateTime.Now - requestSendDateTime).TotalMilliseconds;

                sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
                var currentDistanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);

                if (distanceToTarget < 40)
                {
                    if (speedInMetersPerSecond > SpeedDownTo)
                    {
                        speedInMetersPerSecond = SpeedDownTo;
                    }
                }

                if (session.LogicSettings.UseWalkingSpeedVariant)
                {
                    speedInMetersPerSecond = MinorWalkingSpeedVariant(session);
                }

                var nextWaypointDistance = Math.Min(currentDistanceToTarget, millisecondsUntilGetUpdatePlayerLocationResponse / 1000 * speedInMetersPerSecond);
                var nextWaypointBearing  = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
                var waypoint             = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

                requestSendDateTime = DateTime.Now;
                result = await _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude);

                UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude);

                if (functionExecutedWhileWalking != null)
                {
                    await functionExecutedWhileWalking(); // look for pokemon
                }
            } while (LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation) >= 2);

            return(result);
        }
Пример #9
0
        /// <summary>
        /// Cell phones Gps systems can't generate accurate GEO, the average best they can is 5 meter.
        /// http://gis.stackexchange.com/questions/43617/what-is-the-maximum-theoretical-accuracy-of-gps
        /// </summary>
        public GeoCoordinate GenerateUnaccurateGeocoordinate(GeoCoordinate geo, double nextWaypointBearing)
        {
            var minBearing = Convert.ToInt32(nextWaypointBearing - 40);

            minBearing = minBearing > 0 ? minBearing : minBearing * -1;
            var maxBearing = Convert.ToInt32(nextWaypointBearing + 40);

            maxBearing = maxBearing < 360 ? maxBearing : 360 - maxBearing;

            var randomBearingDegrees = _randWalking.NextDouble() + _randWalking.Next(Math.Min(minBearing, maxBearing), Math.Max(minBearing, maxBearing));

            var randomDistance = _randWalking.NextDouble() * 3;

            return(LocationUtils.CreateWaypoint(geo, randomDistance, randomBearingDegrees));
        }
        public async Task <PlayerUpdateResponse> Walk(GeoCoordinate targetLocation, double walkingSpeedKmPerHr, Func <Task> funcionWhileWalking = null)
        {
            // Create Marker Overlay
            GMapOverlay markersOverlay = new GMapOverlay("markers");

            // Create Source Marker
            GMarkerGoogle sourceMarker = new GMarkerGoogle(new PointLatLng(_client.CurrentLat, _client.CurrentLng),
                                                           GMarkerGoogleType.green);

            markersOverlay.Markers.Add(sourceMarker);

            // Create Target Marker
            GMarkerGoogle targetMarker = new GMarkerGoogle(new PointLatLng(targetLocation.Latitude, targetLocation.Longitude),
                                                           GMarkerGoogleType.red);

            markersOverlay.Markers.Add(targetMarker);

            // Set the Marker on the Map
            if (_map != null)
            {
                _map.Overlays.Add(markersOverlay);
            }

            var speedInMetersPerSecond = walkingSpeedKmPerHr / 3.6;
            var sourceLocation         = new GeoCoordinate(_client.CurrentLat, _client.CurrentLng);
            var distance             = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);
            var nextWaypointBearing  = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
            var nextWaypointDistance = speedInMetersPerSecond;
            var waypoint             = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

            // Notify Distance
            Logger.Write($"Distance to target location: {distance:0.##} meters. Will take {distance / speedInMetersPerSecond:0.##} seconds!");
            Logger.Write("Walking...");

            //Initial walking
            var requestSendDateTime = DateTime.Now;
            var result =
                await
                _client.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude,
                                             _client.Settings.DefaultAltitude);

            // Update Map
            if (_map != null)
            {
                _map.Position = new GMap.NET.PointLatLng(waypoint.Latitude, waypoint.Longitude);
            }

            while (LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation) >= 30)
            {
                var millisecondsUntilGetUpdatePlayerLocationResponse =
                    (DateTime.Now - requestSendDateTime).TotalMilliseconds;

                sourceLocation = new GeoCoordinate(_client.CurrentLat, _client.CurrentLng);
                var currentDistanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);

                if (currentDistanceToTarget < 40)
                {
                    if (speedInMetersPerSecond > slowSpeed)
                    {
                        speedInMetersPerSecond = slowSpeed;
                    }
                }

                nextWaypointDistance = Math.Min(currentDistanceToTarget,
                                                millisecondsUntilGetUpdatePlayerLocationResponse / 1000 * speedInMetersPerSecond);
                nextWaypointBearing = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
                waypoint            = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

                requestSendDateTime = DateTime.Now;
                result =
                    await
                    _client.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude,
                                                 _client.Settings.DefaultAltitude);

                // Update Map
                if (_map != null)
                {
                    _map.Position = new GMap.NET.PointLatLng(waypoint.Latitude, waypoint.Longitude);
                }

                // Execute While Walking.
                if (funcionWhileWalking != null)
                {
                    DateTime startedPokemonCapture = DateTime.Now;
                    await funcionWhileWalking();

                    DateTime finishedPokemonCapture = DateTime.Now;
                    TimeSpan ts = finishedPokemonCapture - startedPokemonCapture;
                    requestSendDateTime = requestSendDateTime.Subtract(ts);
                }

                // Task Delay
                await Task.Delay(1000);
            }

            // Notify Arrival
            Logger.Write("Arrived.");

            // Remove the Markers on the Map
            if (_map != null)
            {
                _map.Overlays.Remove(markersOverlay);
            }

            // Return the Last Update
            return(result);
        }
Пример #11
0
        //     public async Task<PlayerUpdateResponse> HumanLikeWalking(GeoCoordinate targetLocation,
        //         double walkingSpeedInKilometersPerHour, Func<Task<bool>> functionExecutedWhileWalking,
        //         CancellationToken cancellationToken)
        //     {
        //         cancellationToken.ThrowIfCancellationRequested();

        //         var speedInMetersPerSecond = walkingSpeedInKilometersPerHour/3.6;

        //         var sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
        //         var distanceTo = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);
        //         // Logger.Write($"Distance to target location: {distanceToTarget:0.##} meters. Will take {distanceToTarget/speedInMetersPerSecond:0.##} seconds!", LogLevel.Info);

        //         //Randomizing next step, we don't like straight lines!
        //         var nextWaypointBearing = LocationUtils.DegreeBearing(sourceLocation, targetLocation) *(1 + _client.rnd.NextDouble() * 0.06 - 0.03);
        //         var nextWaypointDistance = speedInMetersPerSecond * (1 + _client.rnd.NextDouble() * 0.2 - 0.1);
        //         var waypoint = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

        //         var Waypoints = new List<GeoCoordinate>();

        //         //Initial walking
        //         var requestSendDateTime = DateTime.Now;
        //         var result =
        //             await
        //                 _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude,
        //                     _client.Settings.DefaultAltitude);

        //         UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude, _client.Settings.DefaultAltitude);

        ////TODO: min-max altitude variations
        //         var altitudeStep = (_client.rnd.NextDouble() * 10 - 5) * (nextWaypointDistance / distanceTo);
        //         var altitude = _client.Settings.DefaultAltitude + altitudeStep;
        //         do
        //         {
        //             cancellationToken.ThrowIfCancellationRequested();

        //             var millisecondsUntilGetUpdatePlayerLocationResponse =
        //                 (DateTime.Now - requestSendDateTime).TotalMilliseconds;

        //             sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
        //             var currentDistanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);

        //             if (currentDistanceToTarget < 40)
        //             {
        //                 if (speedInMetersPerSecond > SpeedDownTo)
        //                 {
        //                     //Logger.Write("We are within 40 meters of the target. Speeding down to 10 km/h to not pass the target.", LogLevel.Info);
        //                     speedInMetersPerSecond = SpeedDownTo;
        //                 }
        //             }

        //             nextWaypointDistance = Math.Min(currentDistanceToTarget,
        //                 (millisecondsUntilGetUpdatePlayerLocationResponse/1000*speedInMetersPerSecond) * (1 + _client.rnd.NextDouble() * 0.2 - 0.1) * _client.Settings.MoveSpeedFactor);
        //             nextWaypointBearing = LocationUtils.DegreeBearing(sourceLocation, targetLocation) * (1 + _client.rnd.NextDouble() * 0.06 - 0.03);
        //             waypoint = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

        //             requestSendDateTime = DateTime.Now;
        //             result =
        //                 await
        //                     _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude,
        //                         altitude);
        //             altitude += altitudeStep;

        //             UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude);


        //             if (functionExecutedWhileWalking != null)
        //                 await functionExecutedWhileWalking(); // look for pokemon
        //             await Task.Delay(500, cancellationToken);
        //         } while (LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation) >= 30);

        //         return result;
        //     }

        public async Task <PlayerUpdateResponse> HumanPathWalking(GeoCoordinate targetLocation,
                                                                  double walkingSpeedInKilometersPerHour, Func <Task <bool> > functionExecutedWhileWalking,
                                                                  Func <Task <bool> > functionExecutedWhileWalking2,
                                                                  CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            //PlayerUpdateResponse result = null;


            var speedInMetersPerSecond = walkingSpeedInKilometersPerHour / 3.6;

            var    sourceLocation   = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
            double distanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);

            Logger.Write($"Distance to target location: {distanceToTarget:0.##} meters. Will take {distanceToTarget/speedInMetersPerSecond:0.##} seconds!", LogLevel.Debug);

            var nextWaypointBearing = LocationUtils.DegreeBearing(sourceLocation, targetLocation);

            nextWaypointBearing += FuzzyFactorBearing();
            var           nextWaypointDistance = speedInMetersPerSecond;
            GeoCoordinate waypoint;
            double        altitudeStep;
            double        altitude;
            var           trueAlt = false;

            if (Math.Abs(targetLocation.Altitude) > 0.001)
            {
                trueAlt      = true;
                altitudeStep = (_client.Settings.DefaultAltitude - targetLocation.Altitude) / (distanceToTarget / (nextWaypointDistance > 1 ? nextWaypointDistance : 1));
                altitude     = _client.Settings.DefaultAltitude - altitudeStep;
                waypoint     = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing, altitude);
            }
            else
            {
                altitudeStep = (_client.Settings.DefaultAltitude - _client.rnd.NextInRange(_client.Settings.DefaultAltitudeMin, _client.Settings.DefaultAltitudeMax)) / (distanceToTarget / nextWaypointDistance);
                altitude     = _client.Settings.DefaultAltitude + altitudeStep;
                waypoint     = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing, _client.Settings.DefaultAltitude);
            }

            //Initial walking

            var requestSendDateTime = DateTime.Now;
            var result =
                await
                _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude);

            UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude);

            do
            {
                if (RuntimeSettings.BreakOutOfPathing)
                {
                    if (RuntimeSettings.lastPokeStopCoordinate.Latitude.Equals(targetLocation.Latitude) &&
                        RuntimeSettings.lastPokeStopCoordinate.Longitude.Equals(targetLocation.Latitude))
                    {
                        RuntimeSettings.BreakOutOfPathing = true;
                        break;
                    }
                }

                cancellationToken.ThrowIfCancellationRequested();

                var millisecondsUntilGetUpdatePlayerLocationResponse =
                    (DateTime.Now - requestSendDateTime).TotalMilliseconds;

                sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
                var currentDistanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);

                //if (currentDistanceToTarget < 40)
                //{
                //    if (speedInMetersPerSecond > SpeedDownTo)
                //    {
                //        //Logger.Write("We are within 40 meters of the target. Speeding down to 10 km/h to not pass the target.", LogLevel.Info);
                //        speedInMetersPerSecond = SpeedDownTo;
                //    }
                //}

                nextWaypointDistance = Math.Min(currentDistanceToTarget,
                                                millisecondsUntilGetUpdatePlayerLocationResponse / 1000 * speedInMetersPerSecond);
                nextWaypointBearing = LocationUtils.DegreeBearing(sourceLocation, targetLocation) + _client.rnd.NextInRange(-11.25, 11.25);
                waypoint            = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

                requestSendDateTime = DateTime.Now;
                result =
                    await
                    _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude,
                                                        altitude);

                UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude, altitude);
                altitude -= altitudeStep;
                if (!trueAlt && (altitude < _client.Settings.DefaultAltitudeMin && altitude > _client.Settings.DefaultAltitudeMax)) //Keep altitude in range
                {
                    if (altitude < _client.Settings.DefaultAltitudeMin)
                    {
                        altitude = _client.Settings.DefaultAltitudeMin + _client.rnd.NextInRange(0.3, 0.5);
                    }
                    else
                    {
                        altitude = _client.Settings.DefaultAltitudeMin - _client.rnd.NextInRange(0.3, 0.5);
                    }
                }
                else if (trueAlt) //Keep altitude in range
                {
                    if (altitudeStep < 0 && altitude <= targetLocation.Altitude)
                    {
                        altitudeStep = 0;
                        altitude     = targetLocation.Altitude;
                    }
                    else if (altitudeStep > 0 && altitude >= targetLocation.Altitude)
                    {
                        altitudeStep = 0;
                        altitude     = targetLocation.Altitude;
                    }
                }
                if (functionExecutedWhileWalking != null)
                {
                    await functionExecutedWhileWalking(); // look for pokemon & hit stops
                }
                if (functionExecutedWhileWalking2 != null)
                {
                    await functionExecutedWhileWalking2();
                }

                await Task.Delay(300, cancellationToken);
            } while (LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation) >= 2 && RuntimeSettings.BreakOutOfPathing == false);
            if (trueAlt)
            {
                altitude = targetLocation.Altitude;
            }
            _client.Settings.DefaultAltitude = altitude;
            return(result);
        }
Пример #12
0
        public override async Task Walk(IGeoLocation targetLocation,
                                        Func <Task> functionExecutedWhileWalking, ISession session, CancellationToken cancellationToken,
                                        double walkSpeed = 0.0)
        {
            base.OnStartWalking(session, targetLocation);

            var destinaionCoordinate = new GeoCoordinate(targetLocation.Latitude, targetLocation.Longitude);

            if (CurrentWalkingSpeed <= 0)
            {
                CurrentWalkingSpeed = session.LogicSettings.WalkingSpeedInKilometerPerHour;
            }
            if (session.LogicSettings.UseWalkingSpeedVariant && walkSpeed == 0)
            {
                CurrentWalkingSpeed = session.Navigation.VariantRandom(session, CurrentWalkingSpeed);
            }

            var rw = new Random();
            var speedInMetersPerSecond = (walkSpeed > 0 ? walkSpeed : CurrentWalkingSpeed) / 3.6;

            var sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);

            var nextWaypointBearing = LocationUtils.DegreeBearing(sourceLocation, destinaionCoordinate);


            var nextWaypointDistance   = speedInMetersPerSecond;
            var waypoint               = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);
            var requestSendDateTime    = DateTime.Now;
            var requestVariantDateTime = DateTime.Now;

            LocationUtils.UpdatePlayerLocationWithAltitude(session, waypoint, (float)speedInMetersPerSecond);

            double SpeedVariantSec = rw.Next(1000, 10000);

            base.DoUpdatePositionEvent(session, waypoint.Latitude, waypoint.Longitude, CurrentWalkingSpeed);

            do
            {
                cancellationToken.ThrowIfCancellationRequested();
                TinyIoC.TinyIoCContainer.Current.Resolve <MultiAccountManager>().ThrowIfSwitchAccountRequested();
                var millisecondsUntilGetUpdatePlayerLocationResponse =
                    (DateTime.Now - requestSendDateTime).TotalMilliseconds;
                var millisecondsUntilVariant =
                    (DateTime.Now - requestVariantDateTime).TotalMilliseconds;

                sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
                var currentDistanceToTarget = LocationUtils
                                              .CalculateDistanceInMeters(sourceLocation, destinaionCoordinate);

                if (currentDistanceToTarget < 40)
                {
                    if (speedInMetersPerSecond > SpeedDownTo)
                    {
                        speedInMetersPerSecond = SpeedDownTo;
                    }
                }

                if (session.LogicSettings.UseWalkingSpeedVariant && walkSpeed == 0)
                {
                    CurrentWalkingSpeed = session.Navigation.VariantRandom(session, CurrentWalkingSpeed);
                }

                speedInMetersPerSecond = (walkSpeed > 0 ? walkSpeed : CurrentWalkingSpeed) / 3.6;

                nextWaypointDistance = Math.Min(currentDistanceToTarget,
                                                millisecondsUntilGetUpdatePlayerLocationResponse / 1000 * speedInMetersPerSecond);
                nextWaypointBearing = LocationUtils.DegreeBearing(sourceLocation, destinaionCoordinate);
                var testeBear = LocationUtils.DegreeBearing(sourceLocation, new GeoCoordinate(40.780396, -73.974844));
                waypoint = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

                requestSendDateTime = DateTime.Now;
                LocationUtils.UpdatePlayerLocationWithAltitude(session, waypoint, (float)speedInMetersPerSecond);

                base.DoUpdatePositionEvent(session, waypoint.Latitude, waypoint.Longitude, CurrentWalkingSpeed);

                if (functionExecutedWhileWalking != null)
                {
                    await functionExecutedWhileWalking(); // look for pokemon
                }
            } while (LocationUtils.CalculateDistanceInMeters(sourceLocation, destinaionCoordinate) >= (new Random()).Next(1, 10));
        }
Пример #13
0
        public async Task <PlayerUpdateResponse> HumanLikeWalking(GeoCoordinate targetLocation,
                                                                  double walkingSpeedInKilometersPerHour, Func <Task> functionExecutedWhileWalking)
        {
            var randomFactor    = 0.5f;
            var randomMin       = (int)(walkingSpeedInKilometersPerHour * (1 - randomFactor));
            var randomMax       = (int)(walkingSpeedInKilometersPerHour * (1 + randomFactor));
            var RandomWalkSpeed = RandomDevice.Next(randomMin, randomMax);

            walkingSpeedInKilometersPerHour = RandomWalkSpeed;

            var speedInMetersPerSecond = walkingSpeedInKilometersPerHour / 3.6;

            var sourceLocation   = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
            var distanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);

            Logger.ColoredConsoleWrite(ConsoleColor.DarkCyan, $"Distance to target location: {distanceToTarget:0.##} meters. Will take {distanceToTarget / speedInMetersPerSecond:0.##} seconds!");

            var nextWaypointBearing  = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
            var nextWaypointDistance = speedInMetersPerSecond;
            var waypoint             = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

            //Initial walking
            var requestSendDateTime = DateTime.Now;
            var result =
                await
                _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude);

            if (functionExecutedWhileWalking != null)
            {
                await functionExecutedWhileWalking();
            }

            var locatePokemonWhileWalkingDateTime = DateTime.Now;

            do
            {
                var millisecondsUntilGetUpdatePlayerLocationResponse =
                    (DateTime.Now - requestSendDateTime).TotalMilliseconds;

                sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
                var currentDistanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);

                if (currentDistanceToTarget < 40)
                {
                    if (speedInMetersPerSecond > SpeedDownTo)
                    {
                        Logger.ColoredConsoleWrite(ConsoleColor.DarkCyan, $"We are within 40 meters of the target. Slowing down to ~10 km/h to not pass the target.");
                        speedInMetersPerSecond = SpeedDownTo;
                    }
                }

                nextWaypointDistance = Math.Min(currentDistanceToTarget, millisecondsUntilGetUpdatePlayerLocationResponse / 1000 * speedInMetersPerSecond);
                nextWaypointBearing  = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
                waypoint             = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

                requestSendDateTime = DateTime.Now;

                result =
                    await
                    _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude,
                                                        waypoint.Altitude);

                if (functionExecutedWhileWalking != null)
                {
                    await functionExecutedWhileWalking();// look for pokemon
                }
                await RandomHelper.RandomDelay(500, 600);
            } while (LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation) >= 30);
            return(result);
        }
Пример #14
0
        public void HumanLikeWalking(GeoCoordinate targetLocation, double walkingSpeedInKilometersPerHour, Func <bool> functionExecutedWhileWalking, bool fromgoogle = false, bool log = true)
        {
            /* removing random factors*/

            /*const float randomFactor = 0.5f;
             * var randomMin = (int)(walkingSpeedInKilometersPerHour * (1 - randomFactor));
             * var randomMax = (int)(walkingSpeedInKilometersPerHour * (1 + randomFactor));
             * walkingSpeedInKilometersPerHour = RandomDevice.Next(randomMin, randomMax);*/

            var speedInMetersPerSecond = walkingSpeedInKilometersPerHour / 3.6;

            Logger.Debug("speed In Meters Per Seconds to use: " + speedInMetersPerSecond);
            var sourceLocation   = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
            var distanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);

            Logger.Debug($"Distance to target location: {distanceToTarget:0.##} meters. Will take {distanceToTarget / speedInMetersPerSecond:0.##} seconds!");
            var nextWaypointBearing  = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
            var nextWaypointDistance = speedInMetersPerSecond;
            var waypoint             = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

            //Initial walking
            var requestSendDateTime = DateTime.Now;

            LocationUtils.updatePlayerLocation(_client, waypoint.Latitude, waypoint.Longitude, waypoint.Altitude);

            if (functionExecutedWhileWalking != null)
            {
                functionExecutedWhileWalking();
            }

            do
            {
                //update user location on map
                Task.Factory.StartNew(() => Logic.Instance.infoObservable.PushNewGeoLocations(new GeoCoordinate(waypoint.Latitude, waypoint.Longitude)));

                var millisecondsUntilGetUpdatePlayerLocationResponse =
                    (DateTime.Now - requestSendDateTime).TotalMilliseconds;

                sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
                var currentDistanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);

                if (currentDistanceToTarget < 40)
                {
                    if (speedInMetersPerSecond > SpeedDownTo)
                    {
                        Logger.Warning("We are within 40 meters of the target. Slowing down to ~10 km/h to not pass the target.");
                        speedInMetersPerSecond = SpeedDownTo;
                    }
                }

                nextWaypointDistance = Math.Min(currentDistanceToTarget, millisecondsUntilGetUpdatePlayerLocationResponse / 1000 * speedInMetersPerSecond);
                nextWaypointBearing  = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
                waypoint             = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);
                requestSendDateTime  = DateTime.Now;

                SetCoordinates(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude);

                if (functionExecutedWhileWalking != null && !_botSettings.PauseTheWalking)
                {
                    functionExecutedWhileWalking(); // look for pokemon
                }
                if (GlobalVars.SnipeOpts.Enabled)
                {
                    Logic.Instance.sniperLogic.Execute((PokemonId)GlobalVars.SnipeOpts.ID, GlobalVars.SnipeOpts.Location);
                }

                RandomHelper.RandomSleep(500, 600);
            }while ((LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation) >= 30 && !fromgoogle) || LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation) >= 2);
        }
        public async Task <PlayerUpdateResponse> Walk(GeoCoordinate targetLocation, Func <Task <bool> > functionExecutedWhileWalking, ISession session, CancellationToken cancellationToken, double walkSpeed = 0.0)
        {
            cancellationToken.ThrowIfCancellationRequested();

            //PlayerUpdateResponse result = null;

            if (CurrentWalkingSpeed <= 0)
            {
                CurrentWalkingSpeed = session.LogicSettings.WalkingSpeedInKilometerPerHour;
            }
            if (session.LogicSettings.UseWalkingSpeedVariant)
            {
                CurrentWalkingSpeed = session.Navigation.VariantRandom(session, CurrentWalkingSpeed);
            }

            var rw = new Random();
            var speedInMetersPerSecond = CurrentWalkingSpeed / 3.6;
            var sourceLocation         = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);

            LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);
            var nextWaypointBearing    = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
            var nextWaypointDistance   = speedInMetersPerSecond;
            var waypoint               = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);
            var requestSendDateTime    = DateTime.Now;
            var requestVariantDateTime = DateTime.Now;

            var result = await LocationUtils.UpdatePlayerLocationWithAltitude(session, waypoint);

            double SpeedVariantSec = rw.Next(1000, 10000);

            UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude);

            do
            {
                cancellationToken.ThrowIfCancellationRequested();

                var millisecondsUntilGetUpdatePlayerLocationResponse =
                    (DateTime.Now - requestSendDateTime).TotalMilliseconds;
                var millisecondsUntilVariant =
                    (DateTime.Now - requestVariantDateTime).TotalMilliseconds;

                sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
                var currentDistanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);

                //if (currentDistanceToTarget < 40)
                //{
                //    if (speedInMetersPerSecond > SpeedDownTo)
                //    {
                //        //Logger.Write("We are within 40 meters of the target. Speeding down to 10 km/h to not pass the target.", LogLevel.Info);
                //        speedInMetersPerSecond = SpeedDownTo;
                //    }
                //}

                if (session.LogicSettings.UseWalkingSpeedVariant)
                {
                    CurrentWalkingSpeed    = session.Navigation.VariantRandom(session, CurrentWalkingSpeed);
                    speedInMetersPerSecond = CurrentWalkingSpeed / 3.6;
                }

                nextWaypointDistance = Math.Min(currentDistanceToTarget, millisecondsUntilGetUpdatePlayerLocationResponse / 1000 * speedInMetersPerSecond);
                nextWaypointBearing  = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
                waypoint             = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

                requestSendDateTime = DateTime.Now;
                result = await LocationUtils.UpdatePlayerLocationWithAltitude(session, waypoint);

                UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude);

                if (functionExecutedWhileWalking != null)
                {
                    await functionExecutedWhileWalking(); // look for pokemon & hit stops
                }
            } while (LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation) >= 2);

            return(result);
        }
Пример #16
0
        public async Task <PlayerUpdateResponse> HumanPathWalking(GpxReader.Trkpt trk,
                                                                  double walkingSpeedInKilometersPerHour, Func <Task <bool> > functionExecutedWhileWalking)
        {
            //PlayerUpdateResponse result = null;

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

            var speedInMetersPerSecond = walkingSpeedInKilometersPerHour / 3.6;

            var sourceLocation   = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
            var distanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);
            // Logger.Write($"Distance to target location: {distanceToTarget:0.##} meters. Will take {distanceToTarget/speedInMetersPerSecond:0.##} seconds!", LogLevel.Info);

            var nextWaypointBearing  = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
            var nextWaypointDistance = speedInMetersPerSecond;
            var waypoint             = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing,
                                                                    Convert.ToDouble(trk.Ele, CultureInfo.InvariantCulture));

            //Initial walking

            var requestSendDateTime = DateTime.Now;
            var result =
                await
                _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude);

            UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude);

            do
            {
                var millisecondsUntilGetUpdatePlayerLocationResponse =
                    (DateTime.Now - requestSendDateTime).TotalMilliseconds;

                sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
                var currentDistanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);

                //if (currentDistanceToTarget < 40)
                //{
                //    if (speedInMetersPerSecond > SpeedDownTo)
                //    {
                //        //Logger.Write("We are within 40 meters of the target. Speeding down to 10 km/h to not pass the target.", LogLevel.Info);
                //        speedInMetersPerSecond = SpeedDownTo;
                //    }
                //}

                nextWaypointDistance = Math.Min(currentDistanceToTarget,
                                                millisecondsUntilGetUpdatePlayerLocationResponse / 1000 * speedInMetersPerSecond);
                nextWaypointBearing = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
                waypoint            = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

                requestSendDateTime = DateTime.Now;
                result =
                    await
                    _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude,
                                                        waypoint.Altitude);

                UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude);

                if (functionExecutedWhileWalking != null)
                {
                    await functionExecutedWhileWalking(); // look for pokemon & hit stops
                }
                await Task.Delay(500);
            } while (LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation) >= 30);

            return(result);
        }
Пример #17
0
        public async Task <PlayerUpdateResponse> DoWalk(List <GeoCoordinate> points, ISession session, Func <Task> functionExecutedWhileWalking, GeoCoordinate sourceLocation, GeoCoordinate targetLocation, CancellationToken cancellationToken, double walkSpeed = 0.0)
        {
            PlayerUpdateResponse result = null;
            var currentLocation         = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude, _client.CurrentAltitude);

            //filter google defined waypoints and remove those that are too near to the previous ones
            var waypointsDists       = new Dictionary <Tuple <GeoCoordinate, GeoCoordinate>, double>();
            var minWaypointsDistance = RandomizeStepLength(_minStepLengthInMeters);

            for (var i = 0; i < points.Count; i++)
            {
                if (i > 0)
                {
                    var dist = LocationUtils.CalculateDistanceInMeters(points[i - 1], points[i]);
                    waypointsDists[new Tuple <GeoCoordinate, GeoCoordinate>(points[i - 1], points[i])] = dist;
                }
            }

            var tooNearPoints = waypointsDists.Where(kvp => kvp.Value < minWaypointsDistance).Select(kvp => kvp.Key.Item1).ToList();

            foreach (var tooNearPoint in tooNearPoints)
            {
                points.Remove(tooNearPoint);
            }
            if (points.Any()) //check if first waypoint is the current location (this is what google returns), in such case remove it!
            {
                var firstStep = points.First();
                if (firstStep == currentLocation)
                {
                    points.Remove(points.First());
                }
            }

            var walkedPointsList = new List <GeoCoordinate>();

            foreach (var nextStep in points)
            {
                currentLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
                if (_currentWalkingSpeed <= 0)
                {
                    _currentWalkingSpeed = session.LogicSettings.WalkingSpeedInKilometerPerHour;
                }
                if (session.LogicSettings.UseWalkingSpeedVariant && walkSpeed == 0)
                {
                    _currentWalkingSpeed = session.Navigation.VariantRandom(session, _currentWalkingSpeed);
                }

                var speedInMetersPerSecond = (walkSpeed > 0 ? walkSpeed : _currentWalkingSpeed) / 3.6;
                var nextStepBearing        = LocationUtils.DegreeBearing(currentLocation, nextStep);
                //particular steps are limited by minimal length, first step is calculated from the original speed per second (distance in 1s)
                var nextStepDistance = Math.Max(RandomizeStepLength(_minStepLengthInMeters), speedInMetersPerSecond);

                var waypoint = LocationUtils.CreateWaypoint(currentLocation, nextStepDistance, nextStepBearing);
                walkedPointsList.Add(waypoint);

                var previousLocation    = currentLocation; //store the current location for comparison and correction purposes
                var requestSendDateTime = DateTime.Now;
                result = await LocationUtils.UpdatePlayerLocationWithAltitude(session, waypoint, (float)speedInMetersPerSecond);

                var realDistanceToTarget = LocationUtils.CalculateDistanceInMeters(currentLocation, targetLocation);
                if (realDistanceToTarget < 30)
                {
                    break;
                }

                do
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    var msToPositionChange = (DateTime.Now - requestSendDateTime).TotalMilliseconds;
                    currentLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
                    var currentDistanceToWaypoint = LocationUtils.CalculateDistanceInMeters(currentLocation, nextStep);
                    realDistanceToTarget = LocationUtils.CalculateDistanceInMeters(currentLocation, targetLocation);

                    var realSpeedinMperS   = nextStepDistance / (msToPositionChange / 1000);
                    var realDistanceWalked = LocationUtils.CalculateDistanceInMeters(previousLocation, currentLocation);
                    //if the real calculated speed is lower than the one expected, we will raise the speed for the following step
                    double speedRaise = 0;
                    if (realSpeedinMperS < speedInMetersPerSecond)
                    {
                        speedRaise = speedInMetersPerSecond - realSpeedinMperS;
                    }
                    double distanceRaise = 0;
                    if (realDistanceWalked < nextStepDistance)
                    {
                        distanceRaise = nextStepDistance - realDistanceWalked;
                    }

                    var realDistanceToTargetSpeedDown = LocationUtils.CalculateDistanceInMeters(currentLocation, targetLocation);
                    if (realDistanceToTargetSpeedDown < 40)
                    {
                        if (speedInMetersPerSecond > SpeedDownTo)
                        {
                            speedInMetersPerSecond = SpeedDownTo;
                        }
                    }

                    if (session.LogicSettings.UseWalkingSpeedVariant && walkSpeed == 0)
                    {
                        _currentWalkingSpeed   = session.Navigation.VariantRandom(session, _currentWalkingSpeed);
                        speedInMetersPerSecond = _currentWalkingSpeed / 3.6;
                    }
                    speedInMetersPerSecond += speedRaise;
                    if (walkSpeed > 0)
                    {
                        speedInMetersPerSecond = walkSpeed / 3.6;
                    }
                    nextStepBearing = LocationUtils.DegreeBearing(currentLocation, nextStep);

                    //setting next step distance is limited by the target and the next waypoint distance (we don't want to miss them)
                    //also the minimal step length is used as we don't want to spend minutes jumping by cm lengths
                    nextStepDistance = Math.Min(Math.Min(realDistanceToTarget, currentDistanceToWaypoint),
                                                //also add the distance raise (bot overhead corrections) to the normal step length
                                                Math.Max(RandomizeStepLength(_minStepLengthInMeters) + distanceRaise, (msToPositionChange / 1000) * speedInMetersPerSecond) + distanceRaise);

                    waypoint = LocationUtils.CreateWaypoint(currentLocation, nextStepDistance, nextStepBearing);
                    walkedPointsList.Add(waypoint);

                    previousLocation    = currentLocation; //store the current location for comparison and correction purposes
                    requestSendDateTime = DateTime.Now;
                    result = await LocationUtils.UpdatePlayerLocationWithAltitude(session, waypoint, (float)speedInMetersPerSecond);

                    UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude);

                    if (functionExecutedWhileWalking != null)
                    {
                        await functionExecutedWhileWalking(); // look for pokemon
                    }
                } while (LocationUtils.CalculateDistanceInMeters(currentLocation, nextStep) >= 2);

                UpdatePositionEvent?.Invoke(nextStep.Latitude, nextStep.Longitude);
            }

            return(result);
        }
Пример #18
0
        private async Task ExecutePurePokemonMode()
        {
            var distanceFromStart = LocationUtils.CalculateDistanceInMeters(
                _clientSettings.DefaultLatitude, _clientSettings.DefaultLongitude,
                _client.CurrentLatitude, _client.CurrentLongitude);

            // Edge case for when the client somehow ends up outside the defined radius
            if (_clientSettings.MaxTravelDistanceInMeters != 0 &&
                distanceFromStart > _clientSettings.MaxTravelDistanceInMeters)
            {
                Logger.Write(
                    $"You're outside of your defined radius! Walking to start ({distanceFromStart}m away) in 5 seconds. Is your Coords.ini file correct?",
                    LogLevel.Warning);
                await Task.Delay(5000);

                Logger.Write("Moving to start location now.");
                await _navigation.HumanLikeWalking(
                    new GeoCoordinate(_clientSettings.DefaultLatitude, _clientSettings.DefaultLongitude),
                    _clientSettings.WalkingSpeedInKilometerPerHour, null);
            }

            var mapObjects = await _client.Map.GetMapObjects();

            // Wasn't sure how to make this pretty. Edit as needed.
            var spawnPoints =
                mapObjects.MapCells.SelectMany(i => i.SpawnPoints)
                .Where(
                    i =>
                    (         // Make sure PokeStop is within max travel distance, unless it's set to 0.
                        LocationUtils.CalculateDistanceInMeters(
                            _clientSettings.DefaultLatitude, _clientSettings.DefaultLongitude,
                            i.Latitude, i.Longitude) < _clientSettings.MaxTravelDistanceInMeters) ||
                    _clientSettings.MaxTravelDistanceInMeters == 0
                    );

            var spawnPointList = spawnPoints.ToList();
            var stopsHit       = 0;

            if (spawnPointList.Count <= 0)
            {
                Logger.Write("No spawn points found in your area. Is your maximum distance too small?",
                             LogLevel.Warning);

                await ExecuteCatchAllNearbyPokemons();

                var bearing   = _client.CurrentLatitude > _clientSettings.DefaultLatitude ? 180 : 0;
                var direction = bearing == 180 ? "south" : "north";

                Logger.Write($"Heading {direction} to look for pokemon",
                             LogLevel.Warning);

                await _navigation.HumanLikeWalking(
                    LocationUtils.CreateWaypoint(new GeoCoordinate(_clientSettings.DefaultLatitude, _clientSettings.DefaultLongitude), _clientSettings.MaxTravelDistanceInMeters, bearing),
                    _clientSettings.WalkingSpeedInKilometerPerHour, ExecuteCatchAllNearbyPokemons);
            }
            while (spawnPointList.Any())
            {
                //resort
                spawnPointList =
                    spawnPointList.OrderBy(
                        i =>
                        LocationUtils.CalculateDistanceInMeters(_client.CurrentLatitude, _client.CurrentLongitude, i.Latitude,
                                                                i.Longitude)).ToList();
                var spawnPoint = spawnPointList[0];
                spawnPointList.RemoveAt(0);

                var distance = LocationUtils.CalculateDistanceInMeters(_client.CurrentLatitude, _client.CurrentLongitude,
                                                                       spawnPoint.Latitude, spawnPoint.Longitude);

                //Logger.Write($"Spawn point in ({Math.Round(distance)}m)", LogLevel.Info, ConsoleColor.DarkCyan);
                await
                _navigation.HumanLikeWalking(new GeoCoordinate(spawnPoint.Latitude, spawnPoint.Longitude),
                                             _clientSettings.WalkingSpeedInKilometerPerHour, ExecuteCatchAllNearbyPokemons);

                await ExecuteCatchAllNearbyPokemons();

                await Task.Delay(1000);

                if (++stopsHit % 5 == 0) //TODO: OR item/pokemon bag is full
                {
                    stopsHit = 0;
                    await RecycleItems();

                    if (_clientSettings.EvolveAllPokemonWithEnoughCandy || _clientSettings.EvolveAllPokemonAboveIV)
                    {
                        await EvolveAllPokemonWithEnoughCandy(_clientSettings.PokemonsToEvolve);
                    }
                    if (_clientSettings.TransferDuplicatePokemon)
                    {
                        await TransferDuplicatePokemon();
                    }
                }
            }
        }
Пример #19
0
        private async Task ExecuteFarmingPokestopsAndPokemons()
        {
            var distanceFromStart = LocationUtils.CalculateDistanceInMeters(
                _clientSettings.DefaultLatitude, _clientSettings.DefaultLongitude,
                _client.CurrentLatitude, _client.CurrentLongitude);

            // Edge case for when the client somehow ends up outside the defined radius
            if (_clientSettings.MaxTravelDistanceInMeters != 0 &&
                distanceFromStart > _clientSettings.MaxTravelDistanceInMeters)
            {
                Logger.Write(
                    $"You're outside of your defined radius! Walking to start ({distanceFromStart}m away) in 5 seconds. Is your Coords.ini file correct?",
                    LogLevel.Warning);
                await Task.Delay(5000);

                Logger.Write("Moving to start location now.");
                await _navigation.HumanLikeWalking(
                    new GeoCoordinate(_clientSettings.DefaultLatitude, _clientSettings.DefaultLongitude),
                    _clientSettings.WalkingSpeedInKilometerPerHour, null);
            }

            var mapObjects = await _client.Map.GetMapObjects();

            // Wasn't sure how to make this pretty. Edit as needed.
            var pokeStops =
                mapObjects.MapCells.SelectMany(i => i.Forts)
                .Where(
                    i =>
                    i.Type == FortType.Checkpoint &&
                    i.CooldownCompleteTimestampMs < DateTime.UtcNow.ToUnixTime() &&
                    (         // Make sure PokeStop is within max travel distance, unless it's set to 0.
                        LocationUtils.CalculateDistanceInMeters(
                            _clientSettings.DefaultLatitude, _clientSettings.DefaultLongitude,
                            i.Latitude, i.Longitude) < _clientSettings.MaxTravelDistanceInMeters) ||
                    _clientSettings.MaxTravelDistanceInMeters == 0
                    );


            var pokestopList = pokeStops.ToList();
            var stopsHit     = 0;

            if (pokestopList.Count <= 0)
            {
                Logger.Write("No usable PokeStops found in your area. Is your maximum distance too small?",
                             LogLevel.Warning);

                await ExecuteCatchAllNearbyPokemons();

                var bearing   = _client.CurrentLatitude > _clientSettings.DefaultLatitude ? 180 : 0;
                var direction = bearing == 180 ? "south" : "north";

                Logger.Write($"Heading {direction} to look for pokemon",
                             LogLevel.Warning);

                await _navigation.HumanLikeWalking(
                    LocationUtils.CreateWaypoint(new GeoCoordinate(_clientSettings.DefaultLatitude, _clientSettings.DefaultLongitude), _clientSettings.MaxTravelDistanceInMeters, bearing),
                    _clientSettings.WalkingSpeedInKilometerPerHour, ExecuteCatchAllNearbyPokemons);
            }
            while (pokestopList.Any())
            {
                //resort
                try
                {
                    pokestopList =
                        pokestopList.OrderBy(
                            i =>
                            LocationUtils.CalculateDistanceInMeters(_client.CurrentLatitude, _client.CurrentLongitude, i.Latitude,
                                                                    i.Longitude)).ToList();
                    var pokeStop = pokestopList[0];
                    pokestopList.RemoveAt(0);


                    var distance = LocationUtils.CalculateDistanceInMeters(_client.CurrentLatitude, _client.CurrentLongitude,
                                                                           pokeStop.Latitude, pokeStop.Longitude);


                    var fortInfo = await _client.Fort.GetFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude);

                    Logger.Write($"{fortInfo.Name} in ({Math.Round(distance)}m)", LogLevel.Info, ConsoleColor.DarkCyan);
                    await
                    _navigation.HumanLikeWalking(new GeoCoordinate(pokeStop.Latitude, pokeStop.Longitude),
                                                 _clientSettings.WalkingSpeedInKilometerPerHour, ExecuteCatchAllNearbyPokemons);

                    var fortSearch = await _client.Fort.SearchFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude);

                    if (fortSearch.ExperienceAwarded > 0)
                    {
                        _stats.AddExperience(fortSearch.ExperienceAwarded);
                        _stats.UpdateConsoleTitle(_inventory);
                        //todo: fix egg crash

                        _narrator.Speak($"Arrived at {fortInfo.Name}");

                        Logger.Write(
                            $"{fortInfo.Name} || XP: {fortSearch.ExperienceAwarded}, Eggs: {fortSearch.PokemonDataEgg}, Items: {StringUtils.GetSummedFriendlyNameOfItemAwardList(fortSearch)}",
                            LogLevel.Pokestop);
                    }

                    await Task.Delay(1000);

                    if (++stopsHit % 5 == 0) //TODO: OR item/pokemon bag is full
                    {
                        stopsHit = 0;
                        await RecycleItems();

                        if (_clientSettings.EvolveAllPokemonWithEnoughCandy || _clientSettings.EvolveAllPokemonAboveIV)
                        {
                            await EvolveAllPokemonWithEnoughCandy(_clientSettings.PokemonsToEvolve);
                        }
                        if (_clientSettings.TransferDuplicatePokemon)
                        {
                            await TransferDuplicatePokemon();
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            }
        }
Пример #20
0
        public async Task <PlayerUpdateResponse> Walk(GeoCoordinate targetLocation, Func <Task <bool> > functionExecutedWhileWalking, ISession session, CancellationToken cancellationToken)
        {
            if (LastWalkingSpeed <= 0)
            {
                LastWalkingSpeed = session.LogicSettings.WalkingSpeedInKilometerPerHour;
            }

            var rw = new Random();
            var speedInMetersPerSecond = LastWalkingSpeed / 3.6;
            var sourceLocation         = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);

            var nextWaypointBearing = LocationUtils.DegreeBearing(sourceLocation, targetLocation);


            var nextWaypointDistance   = speedInMetersPerSecond;
            var waypoint               = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);
            var requestSendDateTime    = DateTime.Now;
            var requestVariantDateTime = DateTime.Now;

            var result = await _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude);

            double SpeedVariantSec = rw.Next(1000, 10000);

            UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude);

            do
            {
                cancellationToken.ThrowIfCancellationRequested();

                var millisecondsUntilGetUpdatePlayerLocationResponse = (DateTime.Now - requestSendDateTime).TotalMilliseconds;
                var millisecondsUntilVariant = (DateTime.Now - requestVariantDateTime).TotalMilliseconds;

                sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
                var currentDistanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);

                if (currentDistanceToTarget < 40)
                {
                    if (speedInMetersPerSecond > SpeedDownTo)
                    {
                        speedInMetersPerSecond = SpeedDownTo;
                    }
                }

                if (session.LogicSettings.UseWalkingSpeedVariant)
                {
                    if (millisecondsUntilVariant >= SpeedVariantSec)
                    {
                        var randomMin       = session.LogicSettings.WalkingSpeedInKilometerPerHour - session.LogicSettings.WalkingSpeedVariant;
                        var randomMax       = session.LogicSettings.WalkingSpeedInKilometerPerHour + session.LogicSettings.WalkingSpeedVariant;
                        var RandomWalkSpeed = rw.NextDouble() * (randomMax - randomMin) + randomMin;

                        session.EventDispatcher.Send(new HumanWalkingEvent
                        {
                            OldWalkingSpeed     = LastWalkingSpeed,
                            CurrentWalkingSpeed = RandomWalkSpeed
                        });

                        LastWalkingSpeed       = RandomWalkSpeed;
                        speedInMetersPerSecond = RandomWalkSpeed / 3.6;
                        SpeedVariantSec       += rw.Next(5000, 15000);
                    }
                }

                nextWaypointDistance = Math.Min(currentDistanceToTarget, millisecondsUntilGetUpdatePlayerLocationResponse / 1000 * speedInMetersPerSecond);
                nextWaypointBearing  = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
                var testeBear = LocationUtils.DegreeBearing(sourceLocation, new GeoCoordinate(40.780396, -73.974844));
                waypoint = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

                requestSendDateTime = DateTime.Now;
                result = await _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude);

                UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude);

                if (functionExecutedWhileWalking != null)
                {
                    await functionExecutedWhileWalking(); // look for pokemon
                }
            } while (LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation) >= 30);

            return(result);
        }
Пример #21
0
        public async Task <PlayerUpdateResponse> Walk(GeoCoordinate targetLocation, Func <Task <bool> > functionExecutedWhileWalking, ISession session, CancellationToken cancellationToken)
        {
            GetGoogleInstance(session);
            var sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude, _client.CurrentAltitude);
            var googleResult   = _googleDirectionsService.GetDirections(sourceLocation, new List <GeoCoordinate>(), targetLocation);

            if (googleResult.Directions.status.Equals("OVER_QUERY_LIMIT"))
            {
                return(await RedirectToHumanStrategy(targetLocation, functionExecutedWhileWalking, session, cancellationToken));
            }
            session.EventDispatcher.Send(new NewPathToDestinyEvent {
                GoogleData = googleResult
            });

            var googleWalk = GoogleWalk.Get(googleResult);

            PlayerUpdateResponse result = null;
            List <GeoCoordinate> points = googleWalk.Waypoints;

            foreach (var nextStep in points)
            {
                var speedInMetersPerSecond = session.LogicSettings.UseWalkingSpeedVariant ? MajorWalkingSpeedVariant(session) :
                                             session.LogicSettings.WalkingSpeedInKilometerPerHour / 3.6;
                sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);

                var nextWaypointBearing  = LocationUtils.DegreeBearing(sourceLocation, nextStep);
                var nextWaypointDistance = speedInMetersPerSecond;
                var waypoint             = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

                var requestSendDateTime = DateTime.Now;
                result = await _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude);

                UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude);

                var realDistanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);
                if (realDistanceToTarget < 10)
                {
                    break;
                }

                do
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    var millisecondsUntilGetUpdatePlayerLocationResponse = (DateTime.Now - requestSendDateTime).TotalMilliseconds;

                    sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
                    var currentDistanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, nextStep);

                    var realDistanceToTargetSpeedDown = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);
                    if (realDistanceToTargetSpeedDown < 40)
                    {
                        if (speedInMetersPerSecond > SpeedDownTo)
                        {
                            speedInMetersPerSecond = SpeedDownTo;
                        }
                    }

                    if (session.LogicSettings.UseWalkingSpeedVariant)
                    {
                        speedInMetersPerSecond = MinorWalkingSpeedVariant(session);
                    }

                    nextWaypointDistance = Math.Min(currentDistanceToTarget, millisecondsUntilGetUpdatePlayerLocationResponse / 1000 * speedInMetersPerSecond);
                    nextWaypointBearing  = LocationUtils.DegreeBearing(sourceLocation, nextStep);
                    waypoint             = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

                    requestSendDateTime = DateTime.Now;
                    result = await _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude);

                    UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude);

                    if (functionExecutedWhileWalking != null)
                    {
                        await functionExecutedWhileWalking(); // look for pokemon
                    }
                } while (LocationUtils.CalculateDistanceInMeters(sourceLocation, nextStep) >= 2);

                UpdatePositionEvent?.Invoke(nextStep.Latitude, nextStep.Longitude);
            }

            return(result);
        }
Пример #22
0
        public override async Task Walk(IGeoLocation targetLocation,
                                        Func <Task> functionExecutedWhileWalking, ISession session, CancellationToken cancellationToken,
                                        double walkSpeed = 0.0)
        {
            var curLocation          = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
            var destinaionCoordinate = new GeoCoordinate(targetLocation.Latitude, targetLocation.Longitude);

            var dist = LocationUtils.CalculateDistanceInMeters(curLocation, destinaionCoordinate);

            if (dist >= 100)
            {
                var nextWaypointDistance = dist * 70 / 100;
                var nextWaypointBearing  = LocationUtils.DegreeBearing(curLocation, destinaionCoordinate);

                var waypoint = LocationUtils.CreateWaypoint(curLocation, nextWaypointDistance, nextWaypointBearing);
                var sentTime = DateTime.Now;

                // We are setting speed to 0, so it will be randomly generated speed.
                LocationUtils.UpdatePlayerLocationWithAltitude(session, waypoint, 0);
                base.DoUpdatePositionEvent(session, waypoint.Latitude, waypoint.Longitude, walkSpeed, 0);

                do
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    TinyIoC.TinyIoCContainer.Current.Resolve <MultiAccountManager>().ThrowIfSwitchAccountRequested();
                    var millisecondsUntilGetUpdatePlayerLocationResponse =
                        (DateTime.Now - sentTime).TotalMilliseconds;

                    curLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
                    var currentDistanceToTarget = LocationUtils.CalculateDistanceInMeters(curLocation, destinaionCoordinate);

                    dist = LocationUtils.CalculateDistanceInMeters(curLocation, destinaionCoordinate);

                    if (dist >= 100)
                    {
                        nextWaypointDistance = dist * 70 / 100;
                    }
                    else
                    {
                        nextWaypointDistance = dist;
                    }

                    nextWaypointBearing = LocationUtils.DegreeBearing(curLocation, destinaionCoordinate);
                    waypoint            = LocationUtils.CreateWaypoint(curLocation, nextWaypointDistance, nextWaypointBearing);
                    sentTime            = DateTime.Now;
                    // We are setting speed to 0, so it will be randomly generated speed.
                    LocationUtils.UpdatePlayerLocationWithAltitude(session, waypoint, 0);
                    base.DoUpdatePositionEvent(session, waypoint.Latitude, waypoint.Longitude, walkSpeed);


                    if (functionExecutedWhileWalking != null)
                    {
                        await functionExecutedWhileWalking(); // look for pokemon
                    }
                } while (LocationUtils.CalculateDistanceInMeters(curLocation, destinaionCoordinate) >= 10);
            }
            else
            {
                // We are setting speed to 0, so it will be randomly generated speed.
                LocationUtils.UpdatePlayerLocationWithAltitude(session, targetLocation.ToGeoCoordinate(), 0);
                base.DoUpdatePositionEvent(session, targetLocation.Latitude, targetLocation.Longitude, walkSpeed);
                if (functionExecutedWhileWalking != null)
                {
                    await functionExecutedWhileWalking(); // look for pokemon
                }
            }
        }
Пример #23
0
        //public PlayerUpdateResponse HumanLikeWalking(GeoCoordinate targetLocation, double walkingSpeedInKilometersPerHour, Func<bool> functionExecutedWhileWalking, bool fromgoogle = false, bool log = true)
        public void HumanLikeWalking(GeoCoordinate targetLocation, double walkingSpeedInKilometersPerHour, Func <bool> functionExecutedWhileWalking, bool fromgoogle = false, bool log = true)
        {
            var randomFactor    = 0.5f;
            var randomMin       = (int)(walkingSpeedInKilometersPerHour * (1 - randomFactor));
            var randomMax       = (int)(walkingSpeedInKilometersPerHour * (1 + randomFactor));
            var RandomWalkSpeed = RandomDevice.Next(randomMin, randomMax);

            walkingSpeedInKilometersPerHour = RandomWalkSpeed + RandomDevice.NextDouble();
            var speedInMetersPerSecond = walkingSpeedInKilometersPerHour / 3.6;
            var sourceLocation         = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
            var distanceToTarget       = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);

            if (log)
            {
                Logger.ColoredConsoleWrite(ConsoleColor.DarkCyan, $"Distance to target location: {distanceToTarget:0.##} meters. Will take {distanceToTarget / speedInMetersPerSecond:0.##} seconds!");
            }

            var nextWaypointBearing  = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
            var nextWaypointDistance = speedInMetersPerSecond;
            var waypoint             = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

            //Initial walking
            var requestSendDateTime = DateTime.Now;

            LocationUtils.updatePlayerLocation(_client, waypoint.Latitude, waypoint.Longitude, waypoint.Altitude);
            //var result =_client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude).Result;

            if (functionExecutedWhileWalking != null)
            {
                functionExecutedWhileWalking();
            }

            var locatePokemonWhileWalkingDateTime = DateTime.Now;

            do
            {
                //update user location on map
                Task.Factory.StartNew(() => Logic.Instance.infoObservable.PushNewGeoLocations(new GeoCoordinate(waypoint.Latitude, waypoint.Longitude)));

                var millisecondsUntilGetUpdatePlayerLocationResponse =
                    (DateTime.Now - requestSendDateTime).TotalMilliseconds;

                sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
                var currentDistanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);

                if (currentDistanceToTarget < 40)
                {
                    if (speedInMetersPerSecond > SpeedDownTo)
                    {
                        if (log)
                        {
                            Logger.ColoredConsoleWrite(ConsoleColor.DarkCyan, "We are within 40 meters of the target. Slowing down to ~10 km/h to not pass the target.");
                        }
                        speedInMetersPerSecond = SpeedDownTo;
                    }
                }

                nextWaypointDistance = Math.Min(currentDistanceToTarget, millisecondsUntilGetUpdatePlayerLocationResponse / 1000 * speedInMetersPerSecond);
                nextWaypointBearing  = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
                waypoint             = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);
                requestSendDateTime  = DateTime.Now;

                if (_botSettings.PauseTheWalking)
                {
                    //result = _client.Player.UpdatePlayerLocation(_client.CurrentLatitude, _client.CurrentLongitude, _client.CurrentAltitude).Result;
                    SetCoordinates(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude);
                }
                else
                {
                    try
                    {
                        //result = _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude).Result;
                        SetCoordinates(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude);
                    }
                    catch (Exception e)
                    {
                        Logger.ColoredConsoleWrite(ConsoleColor.DarkRed, "Sending exception info to Logger");
                        Logger.AddLog("Exception Updating player Location:" + e.ToString());
                    }
                }

                if (functionExecutedWhileWalking != null && !_botSettings.PauseTheWalking)
                {
                    functionExecutedWhileWalking(); // look for pokemon
                }

                if (GlobalVars.SnipeOpts.Enabled)
                {
                    Logic.Instance.sniperLogic.Execute((PokemonId)GlobalVars.SnipeOpts.ID, GlobalVars.SnipeOpts.Location);
                    //_botSettings.SnipeOpts.Enabled = false;
                }

                RandomHelper.RandomSleep(500, 600);
            }while ((LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation) >= 30 && !fromgoogle) || LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation) >= 2);
            //return result;
        }
Пример #24
0
        public async Task <PlayerUpdateResponse> HumanLikeWalking(GeoCoordinate targetLocation,
                                                                  double walkingSpeedInKilometersPerHour, Func <Task <bool> > functionExecutedWhileWalking,
                                                                  CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var speedInMetersPerSecond = walkingSpeedInKilometersPerHour / 3.6;

            var sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
            var distanceTo     = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);
            // Logger.Write($"Distance to target location: {distanceToTarget:0.##} meters. Will take {distanceToTarget/speedInMetersPerSecond:0.##} seconds!", LogLevel.Info);

            //Randomizing next step, we don't like straight lines!
            var nextWaypointBearing  = LocationUtils.DegreeBearing(sourceLocation, targetLocation) * (1 + _client.rnd.NextDouble() * 0.06 - 0.03);
            var nextWaypointDistance = speedInMetersPerSecond * (1 + _client.rnd.NextDouble() * 0.2 - 0.1);
            var waypoint             = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

            //Initial walking
            var requestSendDateTime = DateTime.Now;
            var result =
                await
                _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude,
                                                    _client.Settings.DefaultAltitude);

            UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude);

            var altitudeStep = (_client.rnd.NextDouble() * 10 - 5) * (nextWaypointDistance / distanceTo);
            var altitude     = _client.Settings.DefaultAltitude + altitudeStep;

            do
            {
                cancellationToken.ThrowIfCancellationRequested();

                var millisecondsUntilGetUpdatePlayerLocationResponse =
                    (DateTime.Now - requestSendDateTime).TotalMilliseconds;

                sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
                var currentDistanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);

                if (currentDistanceToTarget < 40)
                {
                    if (speedInMetersPerSecond > SpeedDownTo)
                    {
                        //Logger.Write("We are within 40 meters of the target. Speeding down to 10 km/h to not pass the target.", LogLevel.Info);
                        speedInMetersPerSecond = SpeedDownTo;
                    }
                }

                nextWaypointDistance = Math.Min(currentDistanceToTarget,
                                                (millisecondsUntilGetUpdatePlayerLocationResponse / 1000 * speedInMetersPerSecond) * (1 + _client.rnd.NextDouble() * 0.2 - 0.1));
                nextWaypointBearing = LocationUtils.DegreeBearing(sourceLocation, targetLocation) * (1 + _client.rnd.NextDouble() * 0.06 - 0.03);
                waypoint            = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

                requestSendDateTime = DateTime.Now;
                result =
                    await
                    _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude,
                                                        altitude);

                altitude += altitudeStep;

                UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude);


                if (functionExecutedWhileWalking != null)
                {
                    await functionExecutedWhileWalking(); // look for pokemon
                }
                await Task.Delay(500, cancellationToken);
            } while (LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation) >= 30);

            return(result);
        }
Пример #25
0
        public async Task <PlayerUpdateResponse> HumanPathWalking(GpxReader.Trkpt trk,
                                                                  Func <Task <bool> > functionExecutedWhileWalking,
                                                                  ISession session,
                                                                  CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            //PlayerUpdateResponse result = null;

            var targetLocation = new GeoCoordinate(Convert.ToDouble(trk.Lat, CultureInfo.InvariantCulture),
                                                   Convert.ToDouble(trk.Lon, CultureInfo.InvariantCulture));
            var speedInMetersPerSecond = session.LogicSettings.UseWalkingSpeedVariant
                ? MajorWalkingSpeedVariant(session)
                : session.LogicSettings.WalkingSpeedInKilometerPerHour / 3.6;
            var sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);

            LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);
            var nextWaypointBearing  = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
            var nextWaypointDistance = speedInMetersPerSecond;
            var waypoint             = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing,
                                                                    Convert.ToDouble(trk.Ele, CultureInfo.InvariantCulture));
            var requestSendDateTime = DateTime.Now;
            var result =
                await
                _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude, (float)waypoint.Speed);

            UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude);

            do
            {
                cancellationToken.ThrowIfCancellationRequested();

                var millisecondsUntilGetUpdatePlayerLocationResponse =
                    (DateTime.Now - requestSendDateTime).TotalMilliseconds;

                sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
                var currentDistanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);

                //if (currentDistanceToTarget < 40)
                //{
                //    if (speedInMetersPerSecond > SpeedDownTo)
                //    {
                //        //Logger.Write("We are within 40 meters of the target. Speeding down to 10 km/h to not pass the target.", LogLevel.Info);
                //        speedInMetersPerSecond = SpeedDownTo;
                //    }
                //}

                if (session.LogicSettings.UseWalkingSpeedVariant)
                {
                    speedInMetersPerSecond = MinorWalkingSpeedVariant(session);
                }

                nextWaypointDistance = Math.Min(currentDistanceToTarget,
                                                millisecondsUntilGetUpdatePlayerLocationResponse / 1000 * speedInMetersPerSecond);
                nextWaypointBearing = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
                waypoint            = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

                requestSendDateTime = DateTime.Now;
                result =
                    await
                    _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude,
                                                        waypoint.Altitude, (float)waypoint.Speed);

                UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude);

                if (functionExecutedWhileWalking != null)
                {
                    await functionExecutedWhileWalking(); // look for pokemon & hit stops
                }
            } while (LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation) >= 30);

            return(result);
        }
Пример #26
0
        public async Task <PlayerUpdateResponse> HumanLikeWalking(GeoCoordinate targetLocation,
                                                                  double walkingSpeedInKilometersPerHour, Func <Task> functionExecutedWhileWalking)
        {
            var speedInMetersPerSecond = walkingSpeedInKilometersPerHour / 3.6;

            var sourceLocation   = new GeoCoordinate(_client.CurrentLat, _client.CurrentLng);
            var distanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);

            Logger.ColoredConsoleWrite(ConsoleColor.DarkCyan, $"Distance to target location: {distanceToTarget:0.##} meters. Will take {distanceToTarget / speedInMetersPerSecond:0.##} seconds!");

            var nextWaypointBearing  = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
            var nextWaypointDistance = speedInMetersPerSecond;
            var waypoint             = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

            //Initial walking
            var requestSendDateTime = DateTime.Now;
            var result =
                await
                _client.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude, _client.getSettingHandle().DefaultAltitude);

            if (functionExecutedWhileWalking != null)
            {
                await functionExecutedWhileWalking();
            }

            var locatePokemonWhileWalkingDateTime = DateTime.Now;

            do
            {
                var millisecondsUntilGetUpdatePlayerLocationResponse =
                    (DateTime.Now - requestSendDateTime).TotalMilliseconds;

                sourceLocation = new GeoCoordinate(_client.CurrentLat, _client.CurrentLng);
                var currentDistanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);

                if (currentDistanceToTarget < 35)
                {
                    if (speedInMetersPerSecond > SpeedDownTo)
                    {
                        Logger.ColoredConsoleWrite(ConsoleColor.DarkCyan, $"We are within 35 meters of the target. Speeding down to ~10 km/h to not pass the target.");
                        speedInMetersPerSecond = SpeedDownTo;
                    }
                }

                nextWaypointDistance = Math.Min(currentDistanceToTarget,
                                                millisecondsUntilGetUpdatePlayerLocationResponse / 1000 * speedInMetersPerSecond);
                nextWaypointBearing = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
                waypoint            = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

                requestSendDateTime = DateTime.Now;
                result =
                    await
                    _client.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude,
                                                 _client.getSettingHandle().DefaultAltitude);

                // Look for pokemon's nearby while walking to destination.
                var millisecondsSinceLocatePokemonWhileWalking = (DateTime.Now - locatePokemonWhileWalkingDateTime).TotalMilliseconds;
                if (functionExecutedWhileWalking != null && (millisecondsSinceLocatePokemonWhileWalking >= 30000))
                {
                    //var timeInSeconds = millisecondsSinceLocatePokemonWhileWalking / 1000;
                    //Logger.ColoredConsoleWrite(ConsoleColor.White, $"Searched for pokemons! Last request was done {timeInSeconds} seconds ago");
                    locatePokemonWhileWalkingDateTime = DateTime.Now;
                    await functionExecutedWhileWalking();
                }

                await Task.Delay(Math.Min((int)(distanceToTarget / speedInMetersPerSecond * 1000), 3000));
            } while (LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation) >= 30);

            return(result);
        }
Пример #27
0
        public async Task<PlayerUpdateResponse> Move(GeoCoordinate targetLocation,
            double walkingSpeedInKilometersPerHour, Func<Task<bool>> functionExecutedWhileWalking,
            CancellationToken cancellationToken, bool disableHumanLikeWalking)
        {
            cancellationToken.ThrowIfCancellationRequested();
            if (!disableHumanLikeWalking)
            {
                var speedInMetersPerSecond = walkingSpeedInKilometersPerHour/3.6;

                var sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);

                var nextWaypointBearing = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
                var nextWaypointDistance = speedInMetersPerSecond;
                var waypoint = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

                //Initial walking
                var requestSendDateTime = DateTime.Now;
                var result = 
                    await
                        _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude,
                            waypoint.Altitude);

                UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude);

                do
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    var millisecondsUntilGetUpdatePlayerLocationResponse =
                        (DateTime.Now - requestSendDateTime).TotalMilliseconds;

                    sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
                    var currentDistanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);

                    if (currentDistanceToTarget < 40)
                    {
                        if (speedInMetersPerSecond > SpeedDownTo)
                        {
                            //Logger.Write("We are within 40 meters of the target. Speeding down to 10 km/h to not pass the target.", LogLevel.Info);
                            speedInMetersPerSecond = SpeedDownTo;
                        }
                    }

                    nextWaypointDistance = Math.Min(currentDistanceToTarget,
                        millisecondsUntilGetUpdatePlayerLocationResponse/1000*speedInMetersPerSecond);
                    nextWaypointBearing = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
                    waypoint = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

                    requestSendDateTime = DateTime.Now;
                    result =
                        await
                            _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude,
                                waypoint.Altitude);

                    UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude);


                    if (functionExecutedWhileWalking != null)
                        await functionExecutedWhileWalking(); // look for pokemon
                } while (LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation) >= 30);

                return result;
            }

            var curLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
            var dist = LocationUtils.CalculateDistanceInMeters(curLocation, targetLocation);
            if (dist >= 100)
            {
                var nextWaypointDistance = dist*70/100;
                var nextWaypointBearing = LocationUtils.DegreeBearing(curLocation, targetLocation);

                var waypoint = LocationUtils.CreateWaypoint(curLocation, nextWaypointDistance, nextWaypointBearing);
                var sentTime = DateTime.Now;

                var result =
                    await
                        _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude,
                            waypoint.Altitude);
                UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude);

                do
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    var millisecondsUntilGetUpdatePlayerLocationResponse =
                        (DateTime.Now - sentTime).TotalMilliseconds;

                    curLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
                    var currentDistanceToTarget = LocationUtils.CalculateDistanceInMeters(curLocation, targetLocation);

                    dist = LocationUtils.CalculateDistanceInMeters(curLocation, targetLocation);
                    if (dist >= 100)
                    {
                        nextWaypointDistance = dist*70/100;
                    }
                    else
                    {
                        nextWaypointDistance = dist;
                    }
                    nextWaypointBearing = LocationUtils.DegreeBearing(curLocation, targetLocation);
                    waypoint = LocationUtils.CreateWaypoint(curLocation, nextWaypointDistance, nextWaypointBearing);
                    sentTime = DateTime.Now;
                    result =
                        await
                            _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude,
                                waypoint.Altitude);

                    UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude);


                    if (functionExecutedWhileWalking != null)
                        await functionExecutedWhileWalking(); // look for pokemon
                } while (LocationUtils.CalculateDistanceInMeters(curLocation, targetLocation) >= 10);
                return result;
            }
            else
            {
                var result =
                    await
                        _client.Player.UpdatePlayerLocation(targetLocation.Latitude, targetLocation.Longitude,
                            LocationUtils.getElevation(targetLocation.Latitude,targetLocation.Longitude));
                UpdatePositionEvent?.Invoke(targetLocation.Latitude, targetLocation.Longitude);
                if (functionExecutedWhileWalking != null)
                    await functionExecutedWhileWalking(); // look for pokemon
                return result;
            }
        }
Пример #28
0
        public async Task <PlayerUpdateResponse> Walk(GeoCoordinate targetLocation, Func <Task <bool> > functionExecutedWhileWalking, ISession session, CancellationToken cancellationToken, double walkSpeed = 0.0)
        {
            if (CurrentWalkingSpeed <= 0)
            {
                CurrentWalkingSpeed = session.LogicSettings.WalkingSpeedInKilometerPerHour;
            }
            if (session.LogicSettings.UseWalkingSpeedVariant)
            {
                CurrentWalkingSpeed = session.Navigation.VariantRandom(session, CurrentWalkingSpeed);
            }

            var rw = new Random();
            var speedInMetersPerSecond = CurrentWalkingSpeed / 3.6;

            if (walkSpeed != 0)
            {
                speedInMetersPerSecond = walkSpeed / 3.6;
            }
            var sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);

            var nextWaypointBearing = LocationUtils.DegreeBearing(sourceLocation, targetLocation);


            var nextWaypointDistance   = speedInMetersPerSecond;
            var waypoint               = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);
            var requestSendDateTime    = DateTime.Now;
            var requestVariantDateTime = DateTime.Now;

            var result = await LocationUtils.UpdatePlayerLocationWithAltitude(session, waypoint);

            double SpeedVariantSec = rw.Next(1000, 10000);

            UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude);

            do
            {
                cancellationToken.ThrowIfCancellationRequested();

                var millisecondsUntilGetUpdatePlayerLocationResponse = (DateTime.Now - requestSendDateTime).TotalMilliseconds;
                var millisecondsUntilVariant = (DateTime.Now - requestVariantDateTime).TotalMilliseconds;

                sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
                var currentDistanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);

                if (currentDistanceToTarget < 40)
                {
                    if (speedInMetersPerSecond > SpeedDownTo)
                    {
                        speedInMetersPerSecond = SpeedDownTo;
                    }
                }

                if (session.LogicSettings.UseWalkingSpeedVariant)
                {
                    CurrentWalkingSpeed    = session.Navigation.VariantRandom(session, CurrentWalkingSpeed);
                    speedInMetersPerSecond = CurrentWalkingSpeed / 3.6;
                }

                if (walkSpeed != 0)
                {
                    speedInMetersPerSecond = walkSpeed / 3.6;
                }

                nextWaypointDistance = Math.Min(currentDistanceToTarget, millisecondsUntilGetUpdatePlayerLocationResponse / 1000 * speedInMetersPerSecond);
                nextWaypointBearing  = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
                var testeBear = LocationUtils.DegreeBearing(sourceLocation, new GeoCoordinate(40.780396, -73.974844));
                waypoint = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

                requestSendDateTime = DateTime.Now;
                result = await LocationUtils.UpdatePlayerLocationWithAltitude(session, waypoint);

                UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude);

                if (functionExecutedWhileWalking != null)
                {
                    await functionExecutedWhileWalking(); // look for pokemon
                }
            } while (LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation) >= (new Random()).Next(1, 10));

            return(result);
        }
Пример #29
0
        public async Task <PlayerUpdateResponse> Walk(GeoCoordinate targetLocation, Func <Task <bool> > functionExecutedWhileWalking, ISession session, CancellationToken cancellationToken, double walkSpeed = 0.0)
        {
            var curLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
            var dist        = LocationUtils.CalculateDistanceInMeters(curLocation, targetLocation);

            if (dist >= 100)
            {
                var nextWaypointDistance = dist * 70 / 100;
                var nextWaypointBearing  = LocationUtils.DegreeBearing(curLocation, targetLocation);

                var waypoint = LocationUtils.CreateWaypoint(curLocation, nextWaypointDistance, nextWaypointBearing);
                var sentTime = DateTime.Now;

                var result = await LocationUtils.UpdatePlayerLocationWithAltitude(session, waypoint);

                UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude);

                do
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    var millisecondsUntilGetUpdatePlayerLocationResponse =
                        (DateTime.Now - sentTime).TotalMilliseconds;

                    curLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
                    var currentDistanceToTarget = LocationUtils.CalculateDistanceInMeters(curLocation, targetLocation);

                    dist = LocationUtils.CalculateDistanceInMeters(curLocation, targetLocation);

                    if (dist >= 100)
                    {
                        nextWaypointDistance = dist * 70 / 100;
                    }
                    else
                    {
                        nextWaypointDistance = dist;
                    }

                    nextWaypointBearing = LocationUtils.DegreeBearing(curLocation, targetLocation);
                    waypoint            = LocationUtils.CreateWaypoint(curLocation, nextWaypointDistance, nextWaypointBearing);
                    sentTime            = DateTime.Now;
                    result = await LocationUtils.UpdatePlayerLocationWithAltitude(session, waypoint);

                    UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude);


                    if (functionExecutedWhileWalking != null)
                    {
                        await functionExecutedWhileWalking(); // look for pokemon
                    }
                } while (LocationUtils.CalculateDistanceInMeters(curLocation, targetLocation) >= 10);
                return(result);
            }
            else
            {
                var result = await LocationUtils.UpdatePlayerLocationWithAltitude(session, targetLocation);

                UpdatePositionEvent?.Invoke(targetLocation.Latitude, targetLocation.Longitude);
                if (functionExecutedWhileWalking != null)
                {
                    await functionExecutedWhileWalking(); // look for pokemon
                }
                return(result);
            }
        }
Пример #30
0
        public async Task <PlayerUpdateResponse> Walk(GeoCoordinate targetLocation, Func <Task <bool> > functionExecutedWhileWalking, ISession session, CancellationToken cancellationToken)
        {
            GetGoogleInstance(session);

            _minStepLengthInMeters = session.LogicSettings.DefaultStepLength;
            var currentLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude, _client.CurrentAltitude);
            var googleResult    = _googleDirectionsService.GetDirections(currentLocation, new List <GeoCoordinate>(), targetLocation);

            if (googleResult.Directions.status.Equals("OVER_QUERY_LIMIT"))
            {
                return(await RedirectToHumanStrategy(targetLocation, functionExecutedWhileWalking, session, cancellationToken));
            }

            var googleWalk = GoogleWalk.Get(googleResult);

            PlayerUpdateResponse result = null;
            var points = googleWalk.Waypoints;

            //filter google defined waypoints and remove those that are too near to the previous ones
            var waypointsDists       = new Dictionary <Tuple <GeoCoordinate, GeoCoordinate>, double>();
            var minWaypointsDistance = RandomizeStepLength(_minStepLengthInMeters);

            Logger.Write($"Generating waypoints, will remove those with distance form previous less than: {minWaypointsDistance.ToString("0.000")}", LogLevel.Debug, force: true);
            for (var i = 0; i < points.Count; i++)
            {
                if (i > 0)
                {
                    var dist = LocationUtils.CalculateDistanceInMeters(points[i - 1], points[i]);
                    waypointsDists[new Tuple <GeoCoordinate, GeoCoordinate>(points[i - 1], points[i])] = dist;
                    Logger.Write($"WP{i-1}-{i}: {{{points[i-1].Latitude},{points[i-1].Longitude}}} -{{{points[i].Latitude},{points[i].Longitude}}}, dist: {dist.ToString("0.000")}", LogLevel.Debug, force: true);
                }
            }

            var tooNearPoints = waypointsDists.Where(kvp => kvp.Value < minWaypointsDistance).Select(kvp => kvp.Key.Item1).ToList();

            foreach (var tooNearPoint in tooNearPoints)
            {
                points.Remove(tooNearPoint);
            }
            if (points.Any()) //check if first waypoint is the current location (this is what google returns), in such case remove it!
            {
                var firstStep = points.First();
                if (firstStep == currentLocation)
                {
                    points.Remove(points.First());
                }
            }
            var stringifiedPath = string.Join(",\n", points.Select(point => $"{{lat: {point.Latitude}, lng: {point.Longitude}}}"));

            session.EventDispatcher.Send(new PathEvent
            {
                IsCalculated    = true,
                StringifiedPath = stringifiedPath
            });

            var walkedPointsList = new List <GeoCoordinate>();

            foreach (var nextStep in points)
            {
                Logger.Write($"Leading to a next google waypoint: {{lat: {nextStep.Latitude}, lng: {nextStep.Longitude}}}", LogLevel.Debug, force: true);
                currentLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
                if (_currentWalkingSpeed <= 0)
                {
                    _currentWalkingSpeed = session.LogicSettings.WalkingSpeedInKilometerPerHour;
                }
                if (session.LogicSettings.UseWalkingSpeedVariant)
                {
                    _currentWalkingSpeed = session.Navigation.VariantRandom(session, _currentWalkingSpeed);
                }

                var speedInMetersPerSecond = _currentWalkingSpeed / 3.6;
                var nextStepBearing        = LocationUtils.DegreeBearing(currentLocation, nextStep);
                //particular steps are limited by minimal length, first step is calculated from the original speed per second (distance in 1s)
                var nextStepDistance = Math.Max(RandomizeStepLength(_minStepLengthInMeters), speedInMetersPerSecond);
                Logger.Write($"Distance to walk in the next position update: {nextStepDistance.ToString("0.00")}m bearing: {nextStepBearing.ToString("0.00")}", LogLevel.Debug, force: true);

                var waypoint = LocationUtils.CreateWaypoint(currentLocation, nextStepDistance, nextStepBearing);
                walkedPointsList.Add(waypoint);

                var previousLocation    = currentLocation; //store the current location for comparison and correction purposes
                var requestSendDateTime = DateTime.Now;
                result = await _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude);

                var realDistanceToTarget = LocationUtils.CalculateDistanceInMeters(currentLocation, targetLocation);
                Logger.Write($"Real remaining distance to target: {realDistanceToTarget.ToString("0.00")}m", LogLevel.Debug, force: true);
                if (realDistanceToTarget < 10)
                {
                    break;
                }

                do
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    var msToPositionChange = (DateTime.Now - requestSendDateTime).TotalMilliseconds;
                    currentLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
                    var currentDistanceToWaypoint = LocationUtils.CalculateDistanceInMeters(currentLocation, nextStep);
                    realDistanceToTarget = LocationUtils.CalculateDistanceInMeters(currentLocation, targetLocation);
                    Logger.Write($"Actual position: {{lat: {currentLocation.Latitude}, lng: {currentLocation.Longitude}}}, reached in {msToPositionChange.ToString("0.00")}ms, distance from the next waypoint: {currentDistanceToWaypoint.ToString("0.000")}m, distance from the target: {realDistanceToTarget.ToString("0.000")}m", LogLevel.Debug, force: true);

                    var realSpeedinMperS   = nextStepDistance / (msToPositionChange / 1000);
                    var realDistanceWalked = LocationUtils.CalculateDistanceInMeters(previousLocation, currentLocation);
                    //if the real calculated speed is lower than the one expected, we will raise the speed for the following step
                    double speedRaise = 0;
                    if (realSpeedinMperS < speedInMetersPerSecond)
                    {
                        speedRaise = speedInMetersPerSecond - realSpeedinMperS;
                    }
                    double distanceRaise = 0;
                    if (realDistanceWalked < nextStepDistance)
                    {
                        distanceRaise = nextStepDistance - realDistanceWalked;
                    }
                    Logger.Write($"Actual/Expected speed: {realSpeedinMperS.ToString("0.00")}/{speedInMetersPerSecond.ToString("0.00")}m/s, actual/expected distance: {realDistanceWalked.ToString("0.00")}/{nextStepDistance.ToString("0.00")}m, next speed and dist raise by {speedRaise.ToString("0.00")}m/s and {distanceRaise.ToString("0.00")}m", LogLevel.Debug, force: true);

                    var realDistanceToTargetSpeedDown = LocationUtils.CalculateDistanceInMeters(currentLocation, targetLocation);
                    if (realDistanceToTargetSpeedDown < 40)
                    {
                        if (speedInMetersPerSecond > SpeedDownTo)
                        {
                            speedInMetersPerSecond = SpeedDownTo;
                        }
                    }

                    if (session.LogicSettings.UseWalkingSpeedVariant)
                    {
                        _currentWalkingSpeed   = session.Navigation.VariantRandom(session, _currentWalkingSpeed);
                        speedInMetersPerSecond = _currentWalkingSpeed / 3.6;
                    }
                    speedInMetersPerSecond += speedRaise;

                    nextStepBearing = LocationUtils.DegreeBearing(currentLocation, nextStep);

                    //setting next step distance is limited by the target and the next waypoint distance (we don't want to miss them)
                    //also the minimal step length is used as we don't want to spend minutes jumping by cm lengths
                    nextStepDistance = Math.Min(Math.Min(realDistanceToTarget, currentDistanceToWaypoint),
                                                //also add the distance raise (bot overhead corrections) to the normal step length
                                                Math.Max(RandomizeStepLength(_minStepLengthInMeters) + distanceRaise, (msToPositionChange / 1000) * speedInMetersPerSecond) + distanceRaise);

                    // After a correct waypoint, get a random imprecise point in 5 meters around player - more realistic
                    //var impreciseLocation = GenerateUnaccurateGeocoordinate(waypoint, nextWaypointBearing);
                    Logger.Write($"Distance to walk in the next position update: {nextStepDistance.ToString("0.00")}, bearing: {nextStepBearing.ToString("0.00")}, speed: {speedInMetersPerSecond.ToString("0.00")}", LogLevel.Debug, force: true);

                    waypoint = LocationUtils.CreateWaypoint(currentLocation, nextStepDistance, nextStepBearing);
                    walkedPointsList.Add(waypoint);

                    previousLocation    = currentLocation; //store the current location for comparison and correction purposes
                    requestSendDateTime = DateTime.Now;
                    result = await _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude);

                    UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude);

                    if (functionExecutedWhileWalking != null)
                    {
                        await functionExecutedWhileWalking(); // look for pokemon
                    }
                } while (LocationUtils.CalculateDistanceInMeters(currentLocation, nextStep) >= 2);

                UpdatePositionEvent?.Invoke(nextStep.Latitude, nextStep.Longitude);
            }

            stringifiedPath = string.Join(",\n", walkedPointsList.Select(point => $"{{lat: {point.Latitude}, lng: {point.Longitude}}}"));
            session.EventDispatcher.Send(new PathEvent
            {
                IsCalculated    = false,
                StringifiedPath = stringifiedPath
            });

            return(result);
        }