/// <summary> /// Determines if a location is inside a circle with given center point and radius /// </summary> /// <param name="locationToCheck">location to check</param> /// <param name="centerPoint">center point of circle</param> /// <param name="radiusInMeter">circle radius in meter</param> /// <returns>true when the point is inside the circle, or false when not</returns> private static bool FilterLocationByRange( Location locationToCheck, MapPoint centerPoint, double radiusInMeter) { return(centerPoint.DistanceTo(locationToCheck.MapLocation) < radiusInMeter); }
/// <summary> /// Calculates distance and speed statistics /// </summary> /// <param name="track">track to update</param> /// <param name="trackPoint">current track point</param> /// <param name="previousPoint">previous track point</param> /// <param name="averageSpeedTrackPointCount"> /// reference to current track point could for calculating average speed /// </param> private static void CalcDistanceAndSpeedStatistics(Track track, TrackPoint trackPoint, TrackPoint previousPoint, ref int averageSpeedTrackPointCount) { var point1 = new MapPoint(previousPoint.Latitude, previousPoint.Longitude); var point2 = new MapPoint(trackPoint.Latitude, trackPoint.Longitude); double distanceInMeter = point1.DistanceTo(point2); track.LengthInMeter += distanceInMeter; double timeInSeconds = 1.0; if (previousPoint.Time.HasValue && trackPoint.Time.HasValue) { timeInSeconds = (trackPoint.Time.Value - previousPoint.Time.Value).TotalSeconds; } double speedInKmh = distanceInMeter / timeInSeconds * Constants.FactorMeterPerSecondToKilometerPerHour; if (Math.Abs(timeInSeconds) < 1e-6) { speedInKmh = 0.0; } track.MaxSpeed = Math.Max(track.MaxSpeed, speedInKmh); track.AverageSpeed += speedInKmh; averageSpeedTrackPointCount++; }
public void TestPolarOffset() { // set up var centerPoint = new MapPoint(48.2, 11.5); var distanceInMeter = 1000; // run var northPoint = centerPoint.PolarOffset(distanceInMeter, 0, 0.0); var eastPoint = centerPoint.PolarOffset(distanceInMeter, 90, 0.0); var southPoint = centerPoint.PolarOffset(distanceInMeter, 180, 0.0); var westPoint = centerPoint.PolarOffset(distanceInMeter, 270, 0.0); var anglePoint = centerPoint.PolarOffset(distanceInMeter, 71, 0.0); // check Assert.AreEqual(distanceInMeter, centerPoint.DistanceTo(northPoint), 1e-6, "distance must match"); Assert.AreEqual(distanceInMeter, centerPoint.DistanceTo(eastPoint), 1e-6, "distance must match"); Assert.AreEqual(distanceInMeter, centerPoint.DistanceTo(southPoint), 1e-6, "distance must match"); Assert.AreEqual(distanceInMeter, centerPoint.DistanceTo(westPoint), 1e-6, "distance must match"); Assert.AreEqual(distanceInMeter, centerPoint.DistanceTo(anglePoint), 1e-6, "distance must match"); }
private int GetRessourceDistance(int Id) { MapPoint CharacterMapPoint = new MapPoint(account.Map.Character.CellId); StatedElement StatedRessource = account.Map.StatedElements.FirstOrDefault((se) => se.Value.Id == Id).Value; if (StatedRessource != null) { MapPoint RessourceMapPoint = new MapPoint((int)StatedRessource.CellId); return(CharacterMapPoint.DistanceTo(RessourceMapPoint)); } return(-1); }
/// <summary> /// Get the distance between the character and the ressource. /// </summary> /// <param name="Id"> /// The id of the ressource. /// </param> public int GetRessourceDistance(int Id) { MapPoint CharacterMapPoint = new MapPoint(account.MapData.Character.disposition.cellId); StatedElement StatedRessource = account.MapData.StatedElements.FirstOrDefault((se) => se.Id == Id); if (StatedRessource != null) { MapPoint RessourceMapPoint = new MapPoint((int)StatedRessource.CellId); return(CharacterMapPoint.DistanceTo(RessourceMapPoint)); } return(-1); }
/// <summary> /// Creates a new view model object based on the given location object /// </summary> /// <param name="parentViewModel">parent view model</param> /// <param name="location">location object</param> /// <param name="myCurrentPosition">the user's current position; may be null</param> public LocationListEntryViewModel(LocationListViewModel parentViewModel, Location location, MapPoint myCurrentPosition) { this.parentViewModel = parentViewModel; this.location = location; this.Distance = myCurrentPosition != null?myCurrentPosition.DistanceTo(this.location.MapLocation) : 0.0; this.TypeImageSource = SvgImageCache.GetImageSource(this.location, "#000000"); this.SetupBindings(); }
private int GetRessourceDistance(int id) { var characterMapPoint = new MapPoint(_account.Character.CellId); var statedRessource = _account.Character.Map.StatedElements.FirstOrDefault(se => se.Value.Id == id).Value; if (statedRessource == null) { return(-1); } var ressourceMapPoint = new MapPoint((int)statedRessource.CellId); return(characterMapPoint.DistanceTo(ressourceMapPoint)); }
public ICellMovement MoveToCellWithDistance(int cellId, int maxDistance, bool bool1) { MovementPath path = null; var savDistance = -1; var characterPoint = new MapPoint(_account.Character.CellId); var targetPoint = new MapPoint(cellId); foreach (var point in GetListPointAtGoodDistance(characterPoint, targetPoint, maxDistance)) { Pathfinder pathFinding = null; if (targetPoint.DistanceToCell(point) > maxDistance || targetPoint.X != point.X && targetPoint.Y != point.Y) { continue; } var distance = characterPoint.DistanceTo(point); if (savDistance != -1 && distance >= savDistance) { continue; } if (bool1) { if (Data.IsWalkable(point.CellId)) { goto Label_00A8; } continue; } if (!NothingOnCell(point.CellId)) { continue; } Label_00A8: pathFinding = new Pathfinder(_account.Character.Map); var path2 = pathFinding.FindPath(_account.Character.CellId, point.CellId); if (path2 == null) { continue; } path = path2; savDistance = distance; } if (path == null) { return(null); } var move = new CellMovement(_account, path); return(move); }
public void TestOffset() { // set up var point1 = new MapPoint(48.2, 11.5); var distanceInMeterNorth = 3000; var distanceInMeterEast = 4000; // run var point2 = point1.Offset(distanceInMeterNorth, distanceInMeterEast, 0.0); double distance = point1.DistanceTo(point2); // check Assert.AreEqual(5000.0, distance, 0.1, "calculated distance must be correct"); }
public void TestDistanceTo() { // set up var point1 = new MapPoint(48.2, 11.5); var point2 = new MapPoint(48.2 + 0.1, 11.5); var distanceInMeter = 1000; var point3 = point2.PolarOffset(distanceInMeter, 321.0, 0.0); // run double distance12 = point1.DistanceTo(point2); double distance23 = point2.DistanceTo(point3); // check Assert.AreEqual(11132.0, distance12, 1.0, "distance from point 1 to point 2 must be correct"); Assert.AreEqual(distanceInMeter, distance23, 0.1, "distance from point 2 to point 3 must be correct"); }
public bool MoveToCellWithDistance(int cellId, int maxDistance, bool bool1) { m_Account.SetStatus(Status.Moving); MovementPath path = null; int savDistance = -1; MapPoint characterPoint = new MapPoint(Character.CellId); MapPoint targetPoint = new MapPoint(cellId); foreach (MapPoint point in GetListPointAtGoodDistance(characterPoint, targetPoint, maxDistance)) { Pathfinder pathFinding = null; if ((targetPoint.DistanceToCell(point) > maxDistance) || ((targetPoint.X != point.X) && (targetPoint.Y != point.Y))) { continue; } int distance = characterPoint.DistanceTo(point); if ((savDistance != -1) && (distance >= savDistance)) { continue; } if (bool1) { if (Data.IsWalkable(point.CellId)) { goto Label_00A8; } continue; } if (!(NothingOnCell(point.CellId))) { continue; } Label_00A8: pathFinding = new Pathfinder(m_Account.Map.Data, m_Account.Map); MovementPath path2 = pathFinding.FindPath(Character.CellId, point.CellId); if (path2 != null) { path = path2; savDistance = distance; } } if (path == null) { return(false); } //if (AutoTimeout) // m_Account.Game.Character.State.SetTimeout(StateEnum.Moving, false, TimeoutMin, TimeoutMax); List <UInt32> serverMovement = MapMovementAdapter.GetServerMovement(path); int timetowait; if (serverMovement.Count() < 3) { timetowait = serverMovement.Count() * 500; } else { timetowait = serverMovement.Count() * 300; } //m_Account.Network.SendToServer(new GameMapMovementRequestMessage(serverMovement.Select<uint, short>(ui => (short)ui).ToArray(), Id)); using (BigEndianWriter writer = new BigEndianWriter()) { GameMapMovementRequestMessage msg = new GameMapMovementRequestMessage(serverMovement.Select <uint, short>(ui => (short)ui).ToArray(), Id); msg.Serialize(writer); writer.Content = m_Account.HumanCheck.hash_function(writer.Content); MessagePackaging pack = new MessagePackaging(writer); pack.Pack((int)msg.ProtocolID); m_Account.SocketManager.Send(pack.Writer.Content); if (m_Account.DebugMode.Checked) { m_Account.Log(new BotTextInformation("[SND] 950 (GameMapMovementRequestMessage)"), 0); } } m_Account.Wait(timetowait, timetowait + 100); using (BigEndianWriter writer = new BigEndianWriter()) { GameMapMovementConfirmMessage newmsg = new GameMapMovementConfirmMessage(); newmsg.Serialize(writer); MessagePackaging pack = new MessagePackaging(writer); pack.Pack((int)newmsg.ProtocolID); if (m_Account.Fight != null && m_Account.Fight.IsFollowingGroup() && m_Account.Fight.followinggroup.m_cellId == cellId) { m_Account.SocketManager.Send(pack.Writer.Content); m_Account.Fight.LaunchFight(m_Account.Fight.followinggroup.m_contextualId); //m_Account.Wait(3000, 4000); //if (m_Account.StatusLb.Text != "Combat") //{ // m_Account.Fight.SearchFight(); //} } else if (m_Account.Fight != null && m_Account.Fight.IsFollowingGroup()) { m_Account.Fight.SearchFight(); } else if (m_Account.Gather.Id != -1) { m_Account.SocketManager.Send(pack.Writer.Content); UseElement(m_Account.Gather.Id, m_Account.Gather.SkillInstanceUid); } else { m_Account.SocketManager.Send(pack.Writer.Content); } m_Account.SetStatus(Status.None); } return(true); }
public bool MoveToCellWithDistance(int cellId, int maxDistance, bool bool1) { MovementPath path = null; int savDistance = -1; MapPoint characterPoint = new MapPoint(m_Account.MapData.Character.Disposition.CellId); MapPoint targetPoint = new MapPoint(cellId); foreach (MapPoint point in m_Account.MapData.GetListPointAtGoodDistance(characterPoint, targetPoint, maxDistance)) { Pathfinder pathFinding = null; if ((targetPoint.DistanceToCell(point) > maxDistance) || ((targetPoint.X != point.X) && (targetPoint.Y != point.Y))) { continue; } int distance = characterPoint.DistanceTo(point); if ((savDistance != -1) && (distance >= savDistance)) { continue; } if (bool1) { if (m_Account.MapData.Data.IsWalkable(point.CellId)) { goto Label_00A8; } continue; } if (!(m_Account.MapData.NothingOnCell(point.CellId))) { continue; } Label_00A8: pathFinding = new Pathfinder(m_Account.MapData); MovementPath path2 = pathFinding.FindPath(m_Account.MapData.Character.Disposition.CellId, point.CellId); if (path2 != null) { path = path2; savDistance = distance; } } if (path == null) { return(false); } List <UInt32> serverMovement = MapMovementAdapter.GetServerMovement(path); if (serverMovement[serverMovement.Count - 1] == m_Account.MapData.Character.Disposition.CellId) { Moving = false; ConfirmMove(); return(true); } int timetowait; if (serverMovement.Count() < 3) { timetowait = serverMovement.Count() * 514; } else { timetowait = serverMovement.Count() * 320; } m_time = timetowait; using (BigEndianWriter writer = new BigEndianWriter()) { GameMapMovementRequestMessage msg = new GameMapMovementRequestMessage(serverMovement.Select(ui => (short)ui).ToList(), m_Account.MapData.Id); msg.Serialize(writer); writer.Content = m_Account.HumanCheck.hash_function(writer.Content); MessagePackaging pack = new MessagePackaging(writer); pack.Pack((int)msg.MessageID); m_Account.SocketManager.Send(pack.Writer.Content); m_Account.SetStatus(Status.Moving); Moving = true; if (m_Account.DebugMode.Checked) { m_Account.Log(new DebugTextInformation("[SND] 950 (GameMapMovementRequestMessage)"), 0); } } return(true); }