public void RegisterPosition(float x, float y, float rot, long timeStamp) { var shipPositionEvent = new UpdatePositionEvent { X = x, Y = y, Rotation = rot, TimeStamp = timeStamp }; this.InsertInHistory(shipPositionEvent); }
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); }
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); }
public void HandleEvent(UpdatePositionEvent evt, ISession session) { // _stats = stats; }
private static void HandleEvent(UpdatePositionEvent event1, ISession session) { //uncomment for more info about locations //Logger.Write(event1.Latitude.ToString("0.0000000000") + "," + event1.Longitude.ToString("0.0000000000"), LogLevel.Debug, force: true); }
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); } }
public async Task <PlayerUpdateResponse> DoWalk(List <GeoCoordinate> points, ISession session, Func <Task <bool> > functionExecutedWhileWalking, GeoCoordinate sourceLocation, GeoCoordinate targetLocation, CancellationToken cancellationToken) { 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) { _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); 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); 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) { _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); 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); 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); }
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); }
public void HandleEvent(UpdatePositionEvent evt, ISession session) { Logger.PushToUi("p_loc", session, evt.Latitude, evt.Longitude, evt.Altitude); }
public async Task <PlayerUpdateResponse> Move(GeoCoordinate targetLocation, Func <Task <bool> > functionExecutedWhileWalking, ISession session, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); if (!session.LogicSettings.DisableHumanWalking) { PlayerUpdateResponse result = null; List <GeoCoordinate> points = new List <GeoCoordinate>(); var route = Route(session, new GeoCoordinate( _client.CurrentLatitude, _client.CurrentLongitude, _client.CurrentAltitude), targetLocation); foreach (var item in route) { points.Add(new GeoCoordinate(item.ToArray()[1], item.ToArray()[0])); } for (int i = 0; i < points.Count; i++) { var speedInMetersPerSecond = session.LogicSettings.UseWalkingSpeedVariant ? MajorWalkingSpeedVariant(session) : session.LogicSettings.WalkingSpeedInKilometerPerHour / 3.6; var sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude); var nextWaypointBearing = LocationUtils.DegreeBearing(sourceLocation, points.ToArray()[i]); 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 < 30) { break; } do { cancellationToken.ThrowIfCancellationRequested(); var millisecondsUntilGetUpdatePlayerLocationResponse = (DateTime.Now - requestSendDateTime).TotalMilliseconds; sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude); var currentDistanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, points.ToArray()[i]); 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, points.ToArray()[i]); 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, points.ToArray()[i]) >= 2); UpdatePositionEvent?.Invoke(points.ToArray()[i].Latitude, points.ToArray()[i].Longitude); } 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); } }
/*private void HandleEvent(DisplayHighestsPokemonEvent displayEvent, ISession session) * { * * }*/ private void HandleEvent(UpdatePositionEvent posEvent, ISession session) { Logger.Write($"Position changed. lat={posEvent.Latitude.ToString("0.00000")}, lng={posEvent.Longitude.ToString("0.00000")}", LogLevel.Debug); }
private static void HandleEvent(UpdatePositionEvent event1, ISession session) { //uncomment to set what happen to the character's location (during snipe double teleport) //Logger.Write(Event1.Latitude.ToString("0.0000") + "," + Event1.Longitude.ToString("0.0000"), LogLevel.Info, force: true); }
public async Task <PlayerUpdateResponse> HumanPathWalking(ISession session, 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; var round = rand.Next(5) == 0 ? 6 : 1; if (Math.Abs(targetLocation.Altitude) > 0.001) { trueAlt = true; altitudeStep = (_client.Settings.DefaultAltitude - targetLocation.Altitude) / (distanceToTarget / (nextWaypointDistance > 1 ? nextWaypointDistance : 1)); altitude = Math.Round(_client.Settings.DefaultAltitude - altitudeStep, round); altitudeStep = Math.Round(altitudeStep, round); waypoint = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing, altitude); } else { var altDiff = _client.Settings.DefaultAltitude - RandomExtensions.NextInRange(_client.Rnd, _client.Settings.DefaultAltitudeMin, _client.Settings.DefaultAltitudeMax); altitudeStep = altDiff / (distanceToTarget / nextWaypointDistance); if (Math.Abs(altDiff) < Math.Abs(altitudeStep)) { altitudeStep = altDiff; } altitude = Math.Round(_client.Settings.DefaultAltitude - altitudeStep, round); altitudeStep = Math.Round(altitudeStep, round); waypoint = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing, altitude); } //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); long actionQueueTimeStamp = 0; do { var factoredSpeed = speedInMetersPerSecond * session.Settings.MoveSpeedFactor; if (session.Runtime.BreakOutOfPathing) { if (session.Runtime.lastPokeStopCoordinate.Latitude.Equals(targetLocation.Latitude) && session.Runtime.lastPokeStopCoordinate.Longitude.Equals(targetLocation.Latitude)) { session.Runtime.BreakOutOfPathing = true; break; } } if (session.ForceMoveJustDone) { break; } cancellationToken.ThrowIfCancellationRequested(); 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 * factoredSpeed); nextWaypointBearing = LocationUtils.DegreeBearing(sourceLocation, targetLocation) + RandomExtensions.NextInRange(_client.Rnd, -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 + RandomExtensions.NextInRange(_client.Rnd, 0.3, 0.5); } else { altitude = _client.Settings.DefaultAltitudeMin - RandomExtensions.NextInRange(_client.Rnd, 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(); } if (actionQueueTimeStamp < DateTime.UtcNow.ToUnixTime()) { actionQueueTimeStamp = DateTime.UtcNow.AddMinutes(2).ToUnixTime(); await ActionQueueTask.Execute(session, cancellationToken); } await Task.Delay(300, cancellationToken); } while (LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation) >= 2 && session.Runtime.BreakOutOfPathing == false); if (trueAlt) { altitude = targetLocation.Altitude; } _client.Settings.DefaultAltitude = altitude; return(result); }
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); } }
public async Task <PlayerUpdateResponse> HumanPathWalking(ISession session, 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; var round = rand.Next(5) == 0 ? 6 : 1; if (Math.Abs(targetLocation.Altitude) > 0.001) { trueAlt = true; altitudeStep = (_client.Settings.DefaultAltitude - targetLocation.Altitude) / (distanceToTarget / (nextWaypointDistance > 1 ? nextWaypointDistance : 1)); altitude = Math.Round(_client.Settings.DefaultAltitude - altitudeStep, round); altitudeStep = Math.Round(altitudeStep, round); waypoint = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing, altitude); } else { altitudeStep = (_client.Settings.DefaultAltitude - _client.rnd.NextInRange(_client.Settings.DefaultAltitudeMin, _client.Settings.DefaultAltitudeMax)) / (distanceToTarget / nextWaypointDistance); altitude = Math.Round(_client.Settings.DefaultAltitude - altitudeStep, round); altitudeStep = Math.Round(altitudeStep, round); 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 (session.Runtime.BreakOutOfPathing) { if (session.Runtime.lastPokeStopCoordinate.Latitude.Equals(targetLocation.Latitude) && session.Runtime.lastPokeStopCoordinate.Longitude.Equals(targetLocation.Latitude)) { session.Runtime.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 && session.Runtime.BreakOutOfPathing == false); if (trueAlt) { altitude = targetLocation.Altitude; } _client.Settings.DefaultAltitude = altitude; return(result); }
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); }
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); }
/// <summary> /// /// </summary> /// <param name="destination">Desired location to move</param> /// <param name="walkingSpeedMin">Minimal walking speed during the move</param> /// <param name="walkingSpeedMax">Maximal walking speed during the move</param> /// <param name="functionExecutedWhileWalking">Functions #1 to be exec while walking, like task or smth</param> /// <param name="functionExecutedWhileWalking2">Functions #1 to be exec while walking, like task or smth</param> /// <param name="cancellationToken">regular session cancelation token</param> /// <param name="session">ISession param of the bot, to detect which bot started it</param> /// <param name="direct">Directly move to the point, skip routing services</param> /// <param name="waypointsToVisit">Waypoints to visit during the move, required to redure Google Directions API usage</param> /// <returns></returns> public async Task <PlayerUpdateResponse> Move(GeoCoordinate destination, double walkingSpeedMin, double walkingSpeedMax, Func <Task <bool> > functionExecutedWhileWalking, Func <Task <bool> > functionExecutedWhileWalking2, CancellationToken cancellationToken, ISession session, bool direct = false, List <GeoCoordinate> waypointsToVisit = null) { var currentLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude, _client.CurrentAltitude); var result = new PlayerUpdateResponse(); if (session.LogicSettings.UseHumanPathing) { var waypoints = new List <GeoCoordinate>(); if (!direct) { RoutingResponse routingResponse = null; try { switch (session.LogicSettings.RoutingService) { case RoutingService.MobBot: routingResponse = Routing.GetRoute(currentLocation, destination); break; case RoutingService.OpenLs: routingResponse = OsmRouting.GetRoute(currentLocation, destination, session); break; case RoutingService.GoogleDirections: routingResponse = GoogleRouting.GetRoute(currentLocation, destination, session, waypointsToVisit); break; } } catch (NullReferenceException ex) { session.EventDispatcher.Send(new DebugEvent { Message = ex.ToString() }); routingResponse = new RoutingResponse(); } if (routingResponse?.Coordinates != null) { foreach (var item in routingResponse.Coordinates) { if (item == null) { continue; } //0 = lat, 1 = long (MAYBE NOT THO?) switch (session.LogicSettings.RoutingService) { case RoutingService.MobBot: waypoints.Add(new GeoCoordinate(item[1], item[0])); break; case RoutingService.OpenLs: waypoints.Add(new GeoCoordinate(item.ToArray()[1], item.ToArray()[0], item.ToArray()[2])); break; case RoutingService.GoogleDirections: waypoints.Add(new GeoCoordinate(item[0], item[1])); break; } } if ((session.LogicSettings.RoutingService == RoutingService.GoogleDirections || session.LogicSettings.RoutingService == RoutingService.MobBot) && session.LogicSettings.UseMapzenApiElevation) { waypoints = await session.MapzenApi.FillAltitude(waypoints); } } } if (waypoints.Count == 0) { waypoints.Add(destination); } else if (waypoints.Count > 1) { var nextPath = waypoints.Select(item => Tuple.Create(item.Latitude, item.Longitude)).ToList(); session.EventDispatcher.Send(new NextRouteEvent { Coords = nextPath }); destination = waypoints.Last(); } Navigation navi = new Navigation(_client, UpdatePositionEvent); var waypointsArr = waypoints.ToArray(); //MILD REWRITE TO USE HUMANPATHWALKING; foreach (var t in waypointsArr) { if (session.ForceMoveTo != null) { return(await ForceMoveTask.Execute(session, cancellationToken)); } // skip waypoints under 5 meters var sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude); var distanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, t); if (distanceToTarget <= 5) { continue; } var nextSpeed = session.Client.rnd.NextInRange(walkingSpeedMin, walkingSpeedMax) * session.Settings.MoveSpeedFactor; result = await navi.HumanPathWalking(session, t, nextSpeed, functionExecutedWhileWalking, functionExecutedWhileWalking2, cancellationToken); if (session.Runtime.BreakOutOfPathing) { return(result); } UpdatePositionEvent?.Invoke(t.Latitude, t.Longitude, t.Altitude); //Console.WriteLine("Hit waypoint " + x); } var curcoord = new GeoCoordinate(session.Client.CurrentLatitude, session.Client.CurrentLongitude); if (LocationUtils.CalculateDistanceInMeters(curcoord, destination) > 40) { var nextSpeed = session.Client.rnd.NextInRange(walkingSpeedMin, walkingSpeedMax) * session.Settings.MoveSpeedFactor; result = await navi.HumanPathWalking(session, destination, nextSpeed, functionExecutedWhileWalking, functionExecutedWhileWalking2, cancellationToken); } } else { if (destination.Latitude.Equals(session.Runtime.lastPokeStopCoordinate.Latitude) && destination.Longitude.Equals(session.Runtime.lastPokeStopCoordinate.Longitude)) { session.Runtime.BreakOutOfPathing = true; } if (session.Runtime.BreakOutOfPathing) { await MaintenanceTask.Execute(session, cancellationToken); return(result); } var navi = new Navigation(_client, UpdatePositionEvent); var curcoord = new GeoCoordinate(session.Client.CurrentLatitude, session.Client.CurrentLongitude); if (LocationUtils.CalculateDistanceInMeters(curcoord, destination) > 40) { var nextSpeed = session.Client.rnd.NextInRange(walkingSpeedMin, walkingSpeedMax) * session.Settings.MoveSpeedFactor; result = await navi.HumanPathWalking(session, destination, nextSpeed, functionExecutedWhileWalking, functionExecutedWhileWalking2, cancellationToken); } } await MaintenanceTask.Execute(session, cancellationToken); return(result); }
internal void DoUpdatePositionEvent(ISession session, double latitude, double longitude, double speed, double variant = 0) { UpdatePositionEvent?.Invoke(session, latitude, longitude, speed); }
internal void DoUpdatePositionEvent(double latitude, double longitude) { UpdatePositionEvent?.Invoke(latitude, longitude); }
public async Task <PlayerUpdateResponse> HumanPathWalking(GpxReader.Trkpt trk, double walkingSpeedInKilometersPerHour, Func <Task <bool> > functionExecutedWhileWalking, 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 = walkingSpeedInKilometersPerHour / 3.6; var sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude); 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 { 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 & hit stops } } while (LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation) >= 30); return(result); }
public async Task <PlayerUpdateResponse> Move(GeoCoordinate targetLocation, Func <Task <bool> > functionExecutedWhileWalking, ISession session, CancellationToken cancellationToken, bool forceDisableHumanWalking = false) { cancellationToken.ThrowIfCancellationRequested(); if (!session.LogicSettings.DisableHumanWalking && !forceDisableHumanWalking) { PlayerUpdateResponse result = null; var points = new List <GeoCoordinate>(); var route = Route(session, new GeoCoordinate( _client.CurrentLatitude, _client.CurrentLongitude, _client.CurrentAltitude), targetLocation); foreach (var item in route) { points.Add(new GeoCoordinate(item.ToArray()[1], item.ToArray()[0])); } OnGetHumanizeRouteEvent(points, targetLocation); for (var i = 0; i < points.Count; i++) { var speedInMetersPerSecond = session.LogicSettings.UseWalkingSpeedVariant ? MajorWalkingSpeedVariant(session) : session.LogicSettings.WalkingSpeedInKilometerPerHour / 3.6; var sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude); var nextWaypointBearing = LocationUtils.DegreeBearing(sourceLocation, points.ToArray()[i]); 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, (float)waypoint.Speed); UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude); var realDistanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation); if (realDistanceToTarget < 30) { break; } do { cancellationToken.ThrowIfCancellationRequested(); var millisecondsUntilGetUpdatePlayerLocationResponse = (DateTime.Now - requestSendDateTime).TotalMilliseconds; sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude); var currentDistanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, points.ToArray()[i]); 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, points.ToArray()[i]); 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 } } while (LocationUtils.CalculateDistanceInMeters(sourceLocation, points.ToArray()[i]) >= 2); UpdatePositionEvent?.Invoke(points.ToArray()[i].Latitude, points.ToArray()[i].Longitude); } return(result); } else { var sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude); var nextWaypointBearing = LocationUtils.DegreeBearing(sourceLocation, targetLocation); var nextWaypointDistance = session.LogicSettings.UseWalkingSpeedVariant ? MajorWalkingSpeedVariant(session) : session.LogicSettings.WalkingSpeedInKilometerPerHour / 3.6; ; ; 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, (float)waypoint.Speed); UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude); do { var speedInMetersPerSecond = session.LogicSettings.UseWalkingSpeedVariant ? MajorWalkingSpeedVariant(session) : session.LogicSettings.WalkingSpeedInKilometerPerHour / 3.6; 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, (float)waypoint.Speed); UpdatePositionEvent?.Invoke(waypoint.Latitude, waypoint.Longitude); if (functionExecutedWhileWalking != null) { await functionExecutedWhileWalking(); // look for pokemon } } while (LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation) >= 30); return(result); } }
public void OnBotEvent(UpdatePositionEvent ev) { this.botMap.UpdatePlayerPosition(ev.Latitude, ev.Longitude); this.datacontext.PlayerInfo.UpdateSpeed(ev.Speed); }
public void HandleEvent(UpdatePositionEvent evt, ISession session) { }
public void OnBotEvent(UpdatePositionEvent ev) { this.botMap.UpdatePlayerPosition(ev.Latitude, ev.Longitude); }
public async Task <PlayerUpdateResponse> Move(GeoCoordinate destination, double walkingSpeedMin, double walkingSpeedMax, Func <Task <bool> > functionExecutedWhileWalking, Func <Task <bool> > functionExecutedWhileWalking2, CancellationToken cancellationToken, ISession session, bool direct = false) { var currentLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude, _client.CurrentAltitude); var result = new PlayerUpdateResponse(); if (session.LogicSettings.UseHumanPathing) { ////initial coordinate generaton ////prepare the result object for further manipulation + return ////initial time //var requestSendDateTime = DateTime.Now; //var distanceToDest = LocationUtils.CalculateDistanceInMeters(currentLocation, destination); //double metersPerInterval = 0.5; //approximate meters for each interval/waypoint to be spaced from the last. //////get distance ofc //////create segments //var segments = Math.Floor(distanceToDest / metersPerInterval); List <GeoCoordinate> waypoints = new List <GeoCoordinate>(); ////get differences in lat / long //var latDiff = Math.Abs(currentLocation.Latitude - destination.Latitude); //var lonDiff = Math.Abs(currentLocation.Longitude - destination.Longitude); //var latAdd = latDiff / segments; //var lonAdd = latDiff / segments; //var lastLat = currentLocation.Latitude; //var lastLon = currentLocation.Longitude; ////generate waypoints old code -goes in straight line basically //for (int i = 0; i < segments; i++) //{ // //TODO: add altitude calculations into everything // lastLat += latAdd; // lastLon += lonAdd; // waypoints.Add(new GeoCoordinate(lastLat, lastLon, currentLocation.Altitude)); //} //TODO: refactor the generation of waypoint code to break the waypoints given to us by the routing information down into segements like above. //generate waypoints new code if (!direct) { //var routingResponse = OsmRouting.GetRoute(currentLocation, destination, session); //waypoints = routingResponse.Coordinates; RoutingResponse routingResponse; try { routingResponse = !session.LogicSettings.UseOpenLsRouting ? Routing.GetRoute(currentLocation, destination) : OsmRouting.GetRoute(currentLocation, destination, session); } catch (NullReferenceException ex) { session.EventDispatcher.Send(new DebugEvent { Message = ex.ToString() }); routingResponse = new RoutingResponse(); } var nextPath = routingResponse?.Coordinates?.Select(item => Tuple.Create(item[1], item[0])).ToList(); session.EventDispatcher.Send(new NextRouteEvent { Coords = nextPath }); if (routingResponse?.Coordinates != null) { foreach (var item in routingResponse.Coordinates) { //0 = lat, 1 = long (MAYBE NOT THO?) waypoints.Add(!session.LogicSettings.UseOpenLsRouting ? new GeoCoordinate(item.ToArray()[1], item.ToArray()[0], session.LogicSettings.UseMapzenApiElevation ? session.MapzenApi.GetAltitude(item.ToArray()[1], item.ToArray()[0]) : 0) : new GeoCoordinate(item.ToArray()[1], item.ToArray()[0], item.ToArray()[2])); } } } if (waypoints.Count == 0) { waypoints.Add(destination); } //var timeSinceMoveStart = DateTime.Now.Ticks; //double curAcceleration = 1.66; //Lets assume we accelerate at 1.66 m/s ish. TODO: Fuzz this a bit //double curWalkingSpeed = 0; //double maxWalkingSpeed = (session.LogicSettings.WalkingSpeedInKilometerPerHour / 3.6); //Get movement speed in meters ////TODO: Maybe update SensorInfo to replicate/mimic movement, or is it fine as is? //bool StopWalking = false; //double TimeToAccelerate = GetAccelerationTime(curWalkingSpeed, maxWalkingSpeed, curAcceleration); ////double InitialMove = getDistanceTraveledAccelerating(TimeToAccelerate, curAcceleration, curWalkingSpeed); //double MoveLeft = curWalkingSpeed; //bool NeedMoreMove = false; //bool StopMove = false; //int UpdateInterval = 1; // in seconds - any more than this breaks the calculations for distance and such. It all relys on taking ~1 second to perform the actions needed, pretty much. //makes you appear to move slower if you're catching pokemon, hitting stops, etc. //This feels like more human behavior. Dunnomateee Navigation navi = new Navigation(_client, UpdatePositionEvent); var waypointsArr = waypoints.ToArray(); //MILD REWRITE TO USE HUMANPATHWALKING; foreach (var t in waypointsArr) { if (session.ForceMoveTo != null) { return(await ForceMoveTask.Execute(session, cancellationToken)); } // skip waypoints under 5 meters var sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude); var distanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, t); if (distanceToTarget <= 5) { continue; } var nextSpeed = session.Client.rnd.NextInRange(walkingSpeedMin, walkingSpeedMax) * session.Settings.MoveSpeedFactor; result = await navi.HumanPathWalking(t, nextSpeed, functionExecutedWhileWalking, functionExecutedWhileWalking2, cancellationToken); if (RuntimeSettings.BreakOutOfPathing) { return(result); } UpdatePositionEvent?.Invoke(t.Latitude, t.Longitude, t.Altitude); //Console.WriteLine("Hit waypoint " + x); } var curcoord = new GeoCoordinate(session.Client.CurrentLatitude, session.Client.CurrentLongitude); if (LocationUtils.CalculateDistanceInMeters(curcoord, destination) > 40) { var nextSpeed = session.Client.rnd.NextInRange(walkingSpeedMin, walkingSpeedMax) * session.Settings.MoveSpeedFactor; result = await navi.HumanPathWalking(destination, nextSpeed, functionExecutedWhileWalking, functionExecutedWhileWalking2, cancellationToken); } } else { if (destination.Latitude.Equals(RuntimeSettings.lastPokeStopCoordinate.Latitude) && destination.Longitude.Equals(RuntimeSettings.lastPokeStopCoordinate.Longitude)) { RuntimeSettings.BreakOutOfPathing = true; } if (RuntimeSettings.BreakOutOfPathing) { await MaintenanceTask.Execute(session, cancellationToken); return(result); } var navi = new Navigation(_client, UpdatePositionEvent); var curcoord = new GeoCoordinate(session.Client.CurrentLatitude, session.Client.CurrentLongitude); if (LocationUtils.CalculateDistanceInMeters(curcoord, destination) > 40) { var nextSpeed = session.Client.rnd.NextInRange(walkingSpeedMin, walkingSpeedMax) * session.Settings.MoveSpeedFactor; result = await navi.HumanPathWalking(destination, nextSpeed, functionExecutedWhileWalking, functionExecutedWhileWalking2, cancellationToken); } } await MaintenanceTask.Execute(session, cancellationToken); return(result); }