internal static bool PerformFinalDestinationTask(DirectBookmark bookmark, int warpDistance, ref DateTime nextAction, ref DirectBookmark undockBookmark) { // The bookmark no longer exists, assume we aren't there if (bookmark == null) { return(false); } if (Cache.Instance.DirectEve.Session.IsInStation) { // We have arived if (bookmark.ItemId.HasValue && bookmark.ItemId == Cache.Instance.DirectEve.Session.StationId) { return(true); } // We are apparently in a station that is incorrect Logging.Log("Traveler.BookmarkDestination: We're docked in the wrong station, undocking"); if (!string.IsNullOrEmpty(Settings.Instance.UndockPrefix)) { var bookmarks = Cache.Instance.DirectEve.Bookmarks.Where(b => b.Title.Contains(Cache.Instance.DirectEve.GetLocationName(Cache.Instance.DirectEve.Session.StationId ?? 0)) && b.Title.Contains(Settings.Instance.UndockPrefix)); if (bookmarks != null && bookmarks.Count() > 0) { undockBookmark = bookmarks.FirstOrDefault(); if (undockBookmark.X == null || undockBookmark.Y == null || undockBookmark.Z == null) { Logging.Log("Traveler.StationDestination: undock bookmark [" + undockBookmark.Title + "] is unusable: it has no coords"); undockBookmark = null; } else { Logging.Log("Traveler.StationDestination: undock bookmark [" + undockBookmark.Title + "] is usable: it has coords"); } } else { Logging.Log("Traveler.StationDestination: undock bookmark does not exist"); } } else { Logging.Log("Traveler.StationDestination: UndockPrefix is not configured"); } Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.CmdExitStation); nextAction = DateTime.Now.AddSeconds((int)Time.TravelerExitStationAmIInSpaceYet_seconds); return(false); } // Is this a station bookmark? if (bookmark.Entity != null && bookmark.Entity.GroupId == (int)Group.Station) { var arrived = StationDestination.PerformFinalDestinationTask(bookmark.Entity.Id, bookmark.Entity.Name, ref nextAction, ref undockBookmark); if (arrived) { Logging.Log("Traveler.BookmarkDestination: Arrived at bookmark [" + bookmark.Title + "]"); } return(arrived); } // Its not a station bookmark, make sure we are in space if (Cache.Instance.DirectEve.Session.IsInStation) { // We are in a station, but not the correct station! if (nextAction < DateTime.Now) { Logging.Log("Traveler.BookmarkDestination: We're docked but our destination is in space, undocking"); Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.CmdExitStation); nextAction = DateTime.Now.AddSeconds((int)Time.TravelerExitStationAmIInSpaceYet_seconds); } // We are not there yet return(false); } if (!Cache.Instance.InSpace) { // We are not in space and not in a station, wait a bit return(false); } if (undockBookmark != null) { if (Cache.Instance.DistanceFromMe(undockBookmark.X ?? 0, undockBookmark.Y ?? 0, undockBookmark.Z ?? 0) < (int)Distance.WarptoDistance) { Logging.Log("Traveler.BookmarkDestination: Arrived at undock bookmark [" + undockBookmark.Title + "]"); undockBookmark = null; } else { Logging.Log("Traveler.BookmarkDestination: Warping to undock bookmark [" + undockBookmark.Title + "]"); undockBookmark.WarpTo(); nextAction = DateTime.Now.AddSeconds((int)Time.TravelerInWarpedNextCommandDelay_seconds); //nextAction = DateTime.Now.AddSeconds(Settings.Instance.UndockDelay); return(false); } } // This bookmark has no x / y / z, assume we are there. if (bookmark.X == -1 || bookmark.Y == -1 || bookmark.Z == -1) { Logging.Log("Traveler.BookmarkDestination: Arrived at the bookmark [" + bookmark.Title + "][No XYZ]"); return(true); } var distance = Cache.Instance.DistanceFromMe(bookmark.X ?? 0, bookmark.Y ?? 0, bookmark.Z ?? 0); if (distance < warpDistance) { Logging.Log("Traveler.BookmarkDestination: Arrived at the bookmark [" + bookmark.Title + "]"); return(true); } if (nextAction > DateTime.Now) { return(false); } Logging.Log("Traveler.BookmarkDestination: Warping to bookmark [" + bookmark.Title + "]"); Cache.Instance.DoNotBreakInvul = false; bookmark.WarpTo(); nextAction = DateTime.Now.AddSeconds((int)Time.TravelerInWarpedNextCommandDelay_seconds); return(false); }
internal static bool PerformFinalDestinationTask(DirectBookmark bookmark, int warpDistance, ref DateTime nextAction) { // The bookmark no longer exists, assume we aren't there if (bookmark == null) { return(false); } if (Cache.Instance.DirectEve.Session.IsInStation) { // We have arived if (bookmark.ItemId.HasValue && bookmark.ItemId == Cache.Instance.DirectEve.Session.StationId) { return(true); } // We are apparently in a station that is incorrect Logging.Log("Traveler.BookmarkDestination: We're docked in the wrong station, undocking"); Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.CmdExitStation); nextAction = DateTime.Now.AddSeconds(30); return(false); } // Is this a station bookmark? if (bookmark.Entity != null && bookmark.Entity.GroupId == (int)Group.Station) { var arrived = StationDestination.PerformFinalDestinationTask(bookmark.Entity.Id, bookmark.Entity.Name, ref nextAction); if (arrived) { Logging.Log("Traveler.BookmarkDestination: Arrived at bookmark [" + bookmark.Title + "]"); } return(arrived); } // Its not a station bookmark, make sure we are in space if (Cache.Instance.DirectEve.Session.IsInStation) { // We are in a station, but not the correct station! if (nextAction < DateTime.Now) { Logging.Log("Traveler.BookmarkDestination: We're docked but our destination is in space, undocking"); Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.CmdExitStation); nextAction = DateTime.Now.AddSeconds(30); } // We are not there yet return(false); } if (!Cache.Instance.InSpace) { // We are not in space and not in a station, wait a bit return(false); } // This bookmark has no x / y / z, assume we are there. if (bookmark.X == -1 || bookmark.Y == -1 || bookmark.Z == -1) { Logging.Log("Traveler.BookmarkDestination: Arrived at the bookmark [" + bookmark.Title + "][No XYZ]"); return(true); } var distance = Cache.Instance.DistanceFromMe(bookmark.X ?? 0, bookmark.Y ?? 0, bookmark.Z ?? 0); if (distance < warpDistance) { Logging.Log("Traveler.BookmarkDestination: Arrived at the bookmark [" + bookmark.Title + "]"); return(true); } if (nextAction > DateTime.Now) { return(false); } Logging.Log("Traveler.BookmarkDestination: Warping to bookmark [" + bookmark.Title + "]"); bookmark.WarpTo(); nextAction = DateTime.Now.AddSeconds(30); return(false); }