public static async Task <PlayerUpdateResponse> HumanPathWalking(GpxReader.Trkpt trk, 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 targetLocation = new GeoUtils(Convert.ToDouble(trk.Lat), Convert.ToDouble(trk.Lon)); 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, Convert.ToDouble(trk.Ele)); //Initial walking var requestSendDateTime = DateTime.Now; PlayerUpdateResponse result; await Logic._client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude, Logic._client.Settings.DefaultAltitude); 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, waypoint.Altitude); if (functionExecutedWhileWalking != null) { await functionExecutedWhileWalking();// look for pokemon } } while (LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation) >= 35); return(result); }
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); }
public async Task <PlayerUpdateResponse> HumanPathWalking(GpxReader.Trkpt trk, double walkingSpeedInKilometersPerHour, Func <Task> functionExecutedWhileWalking) { //PlayerUpdateResponse result = null; var targetLocation = new GeoCoordinate(Convert.ToDouble(trk.Lat), Convert.ToDouble(trk.Lon)); 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, Convert.ToDouble(trk.Ele)); //Initial walking var requestSendDateTime = DateTime.Now; var result = await _client.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude); 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, waypoint.Altitude); 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); }
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); }