コード例 #1
0
        public BookmarkDestination2(DirectBookmark bookmark)
        {
            if (bookmark == null)
            {
                Logging.Log("QuestorManager.BookmarkDestination", "Invalid bookmark destination!", Logging.White);

                SolarSystemId = Cache.Instance.DirectEve.Session.SolarSystemId ?? -1;
                BookmarkId    = -1;
                return;
            }

            Logging.Log("QuestorManager.BookmarkDestination", "Destination set to bookmark [" + bookmark.Title + "]", Logging.White);
            DirectLocation location = GetBookmarkLocation(bookmark);

            if (location == null)
            {
                Logging.Log("QuestorManager.BookmarkDestination", "Invalid bookmark destination!", Logging.White);

                SolarSystemId = Cache.Instance.DirectEve.Session.SolarSystemId ?? -1;
                BookmarkId    = -1;
                return;
            }

            BookmarkId    = bookmark.BookmarkId ?? -1;
            SolarSystemId = location.SolarSystemId ?? Cache.Instance.DirectEve.Session.SolarSystemId ?? -1;
        }
コード例 #2
0
ファイル: Traveler.cs プロジェクト: seb1707/Questor
        /// <summary>
        ///   Set destination to a solar system
        /// </summary>
        public static bool SetStationDestination(long stationId)
        {
            _location = Cache.Instance.DirectEve.Navigation.GetLocation(stationId);
            if (Settings.Instance.DebugTraveler)
            {
                Logging.Log("Traveler", "Location = [" + Logging.Yellow + Cache.Instance.DirectEve.Navigation.GetLocationName(stationId) + Logging.Green + "]", Logging.Green);
            }
            if (_location.IsValid)
            {
                _locationErrors = 0;
                if (Settings.Instance.DebugTraveler)
                {
                    Logging.Log("Traveler", "Setting destination to [" + Logging.Yellow + _location.Name + Logging.Green + "]", Logging.Teal);
                }
                try
                {
                    _location.SetDestination();
                }
                catch (Exception)
                {
                    Logging.Log("Traveler", "SetStationDestination: set destination to [" + _location.ToString() + "] failed ", Logging.Debug);
                }
                return(true);
            }

            Logging.Log("Traveler", "Error setting station destination [" + Logging.Yellow + stationId + Logging.Green + "]", Logging.Green);
            _locationErrors++;
            if (_locationErrors > 20)
            {
                return(false);
            }
            return(false);
        }
コード例 #3
0
ファイル: Traveler.cs プロジェクト: seb1707/Questor
        public static void ProcessState()
        {
            // Only pulse state changes every 1.5s
            if (DateTime.UtcNow.Subtract(_lastPulse).TotalMilliseconds < 1200) //default: 1500ms
            {
                return;
            }

            _lastPulse = DateTime.UtcNow;

            switch (_States.CurrentTravelerState)
            {
            case TravelerState.Idle:
                _States.CurrentTravelerState = TravelerState.Traveling;
                break;

            case TravelerState.Traveling:
                if ((!Cache.Instance.InSpace && !Cache.Instance.InStation) || Cache.Instance.InWarp)     //if we are in warp, do nothing, as nothing can actually be done until we are out of warp anyway.
                {
                    return;
                }

                if (Destination == null)
                {
                    _States.CurrentTravelerState = TravelerState.Error;
                    break;
                }

                if (Destination.SolarSystemId != Cache.Instance.DirectEve.Session.SolarSystemId)
                {
                    //Logging.Log("traveler: NavigateToBookmarkSystem(Destination.SolarSystemId);");
                    NavigateToBookmarkSystem(Destination.SolarSystemId);
                }
                else if (Destination.PerformFinalDestinationTask())
                {
                    _destinationRoute = null;
                    _location         = null;
                    _locationName     = string.Empty;
                    _locationErrors   = 0;

                    //Logging.Log("traveler: _States.CurrentTravelerState = TravelerState.AtDestination;");
                    _States.CurrentTravelerState = TravelerState.AtDestination;
                }
                break;

            case TravelerState.AtDestination:

                //do nothing when at destination
                //Traveler sits in AtDestination when it has nothing to do, NOT in idle.
                break;

            default:
                break;
            }
        }
コード例 #4
0
ファイル: DirectLocation.cs プロジェクト: xelj/DirectEve
        /// <summary>
        ///     Get a location based on locationId
        /// </summary>
        /// <param name="directEve"></param>
        /// <param name="locationId"></param>
        /// <returns></returns>
        public static DirectLocation GetLocation(DirectEve directEve, long locationId)
        {
            var                 isValid       = false;
            string              name          = null;
            DirectRegion        region        = null;
            DirectConstellation constellation = null;
            DirectSolarSystem   solarSystem   = null;
            DirectStation       station       = null;

            if (directEve.Regions.TryGetValue(locationId, out region))
            {
                isValid = true;
                name    = region.Name;
            }
            else if (directEve.Constellations.TryGetValue(locationId, out constellation))
            {
                isValid = true;
                name    = constellation.Name;

                region = constellation.Region;
            }
            else if (directEve.SolarSystems.TryGetValue((int)locationId, out solarSystem))
            {
                isValid = true;
                name    = solarSystem.Name;

                constellation = solarSystem.Constellation;
                region        = constellation.Region;
            }
            else if (directEve.Stations.TryGetValue((int)locationId, out station))
            {
                isValid = true;
                name    = station.Name;

                solarSystem   = station.SolarSystem;
                constellation = solarSystem.Constellation;
                region        = constellation.Region;
            }

            var result = new DirectLocation(directEve);

            result.IsValid         = isValid;
            result.Name            = name;
            result.LocationId      = locationId;
            result.RegionId        = region != null ? region.Id : (long?)null;
            result.ConstellationId = constellation != null ? constellation.Id : (long?)null;
            result.SolarSystemId   = solarSystem != null ? solarSystem.Id : (long?)null;
            result.ItemId          = station != null ? station.Id : (long?)null;
            return(result);
        }
コード例 #5
0
        private static DirectLocation GetBookmarkLocation(DirectBookmark bookmark)
        {
            DirectLocation location = Cache.Instance.DirectEve.Navigation.GetLocation(bookmark.ItemId ?? -1);

            if (!location.IsValid)
            {
                location = Cache.Instance.DirectEve.Navigation.GetLocation(bookmark.LocationId ?? -1);
            }
            if (!location.IsValid)
            {
                return(null);
            }

            return(location);
        }
コード例 #6
0
        public StationDestination(long stationId)
        {
            DirectLocation station = Cache.Instance.DirectEve.Navigation.GetLocation(stationId);

            if (station == null || !station.ItemId.HasValue || !station.SolarSystemId.HasValue)
            {
                Logging.Log("TravelerDestination.StationDestination", "Invalid station id [" + Logging.Yellow + StationId + Logging.Green + "]", Logging.Red);
                SolarSystemId = Cache.Instance.DirectEve.Session.SolarSystemId ?? -1;
                StationId     = -1;
                StationName   = "";
                return;
            }

            Logging.Log("TravelerDestination.StationDestination", "Destination set to [" + Logging.Yellow + station.Name + Logging.Green + "]", Logging.Green);
            StationId     = stationId;
            StationName   = station.Name;
            SolarSystemId = station.SolarSystemId.Value;
        }
コード例 #7
0
        public StationDestination2(long stationId)
        {
            DirectLocation station = Cache.Instance.DirectEve.Navigation.GetLocation(stationId);

            if (station == null || !station.ItemId.HasValue || !station.SolarSystemId.HasValue)
            {
                Logging.Log("QuestorManager.StationDestination", "Invalid station id [" + stationId + "]", Logging.Red);

                SolarSystemId = Cache.Instance.DirectEve.Session.SolarSystemId ?? -1;
                StationId     = -1;
                StationName   = "";
                return;
            }

            Logging.Log("QuestorManager.StationDestination", "Destination set to [" + station.Name + "]", Logging.White);

            StationId     = stationId;
            StationName   = station.Name;
            SolarSystemId = station.SolarSystemId.Value;
            //Logging.Log(station.SolarSystemId.Value + " " + stationId + " " + station.Name);
        }
コード例 #8
0
        internal static bool PerformFinalDestinationTask2(DirectBookmark bookmark, int warpDistance, ref DateTime nextAction)
        {
            // The bookmark no longer exists, assume we are there
            if (bookmark == null)
            {
                return(true);
            }

            DirectLocation location = GetBookmarkLocation(bookmark);

            if (Cache.Instance.DirectEve.Session.IsInStation)
            {
                // We have arrived
                if (location != null && location.ItemId == Cache.Instance.DirectEve.Session.StationId)
                {
                    return(true);
                }

                if (DateTime.UtcNow > Cache.Instance.LastInSpace.AddSeconds(45)) //do not try to leave the station until you have been docked for at least 45seconds! (this gives some overhead to load the station env + session change timer)
                {
                    // We are apparently in a station that is incorrect
                    Logging.Log("QuestorManager.BookmarkDestination", "We're docked in the wrong station, undocking", Logging.White);

                    Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.CmdExitStation);
                    nextAction = DateTime.UtcNow.AddSeconds(30);
                    return(false);
                }

                return(false);
            }

            // Is this a station bookmark?
            if (bookmark.Entity != null && bookmark.Entity.GroupId == (int)Group.Station)
            {
                bool arrived = StationDestination2.PerformFinalDestinationTask(bookmark.Entity.Id, bookmark.Entity.Name, ref nextAction);
                if (arrived)
                {
                    Logging.Log("QuestorManager.BookmarkDestination", "Arrived at bookmark [" + bookmark.Title + "]", Logging.White);
                }
                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.UtcNow)
                {
                    if (DateTime.UtcNow > Cache.Instance.LastInSpace.AddSeconds(45)) //do not try to leave the station until you have been docked for at least 45seconds! (this gives some overhead to load the station env + session change timer)
                    {
                        Logging.Log("QuestorManager.BookmarkDestination", "We're docked but our destination is in space, undocking", Logging.White);
                        Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.CmdExitStation);
                        nextAction = DateTime.UtcNow.AddSeconds(30);
                    }
                }

                // We are not there yet
                return(false);
            }

            if (!Cache.Instance.DirectEve.Session.IsInSpace)
            {
                // 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("QuestorManager.BookmarkDestination", "Arrived at the bookmark [" + Logging.Yellow + bookmark.Title + Logging.White + "][No XYZ]", Logging.White);
                return(true);
            }

            double distance = Cache.Instance.DistanceFromMe(bookmark.X ?? 0, bookmark.Y ?? 0, bookmark.Z ?? 0);

            if (distance < warpDistance)
            {
                Logging.Log("QuestorManager.BookmarkDestination", "Arrived at the bookmark [" + Logging.Yellow + bookmark.Title + Logging.White + "]", Logging.White);
                return(true);
            }

            if (nextAction > DateTime.UtcNow)
            {
                return(false);
            }

            if (Cache.Instance.GateInGrid() && (distance / 1000) < (int)Distances.MaxPocketsDistanceKm)
            {
                Logging.Log("QuestorManager.BookmarkDestination", "Bookmark [" + Logging.Yellow + bookmark.Title + Logging.White + "][" + Logging.Yellow + Math.Round((distance / 1000) / 149598000, 2) + Logging.White + "] AU away. Which is [" + Logging.Yellow + Math.Round((distance / 1000), 2) + Logging.White + "].", Logging.White);
            }

            if (bookmark.WarpTo())
            {
                Logging.Log("QuestorManager.BookmarkDestination", "Warping to bookmark [" + Logging.Yellow + bookmark.Title + Logging.White + "][" + Math.Round((distance / 1000) / 149598000, 2) + "] AU away. Which is [" + Math.Round((distance / 1000), 2) + "]", Logging.White);
                nextAction = DateTime.UtcNow.AddSeconds(30);
                return(false);
            }

            return(false);
        }
コード例 #9
0
ファイル: Traveler.cs プロジェクト: Grafalck/Questor
        public static void ProcessState()
        {
            // Only pulse state changes every 1.5s
            if (DateTime.UtcNow.Subtract(_lastPulse).TotalMilliseconds < 1200) //default: 1500ms
                return;

            _lastPulse = DateTime.UtcNow;

            switch (_States.CurrentTravelerState)
            {
                case TravelerState.Idle:
                    _States.CurrentTravelerState = TravelerState.Traveling;
                    break;

                case TravelerState.Traveling:
                    if (Cache.Instance.InWarp || (!Cache.Instance.InSpace && !Cache.Instance.InStation)) //if we are in warp, do nothing, as nothing can actually be done until we are out of warp anyway.
                        return;

                    if (Destination == null)
                    {
                        _States.CurrentTravelerState = TravelerState.Error;
                        break;
                    }

                    if (Destination.SolarSystemId != Cache.Instance.DirectEve.Session.SolarSystemId)
                    {
                        //Logging.Log("traveler: NavigateToBookmarkSystem(Destination.SolarSystemId);");
                        NavigateToBookmarkSystem(Destination.SolarSystemId);
                    }
                    else if (Destination.PerformFinalDestinationTask())
                    {
                        _destinationRoute = null;
                        _location = null;
                        _locationName = string.Empty;
                        _locationErrors = 0;

                        //Logging.Log("traveler: _States.CurrentTravelerState = TravelerState.AtDestination;");
                        _States.CurrentTravelerState = TravelerState.AtDestination;
                    }
                    break;

                case TravelerState.AtDestination:

                    //do nothing when at destination
                    //Traveler sits in AtDestination when it has nothing to do, NOT in idle.
                    break;

                default:
                    break;
            }
        }
コード例 #10
0
ファイル: Traveler.cs プロジェクト: Grafalck/Questor
        /// <summary>
        ///   Navigate to a solar system
        /// </summary>
        /// <param name = "solarSystemId"></param>
        private static void NavigateToBookmarkSystem(long solarSystemId)
        {
            if (_nextTravelerAction > DateTime.UtcNow)
            {
                //Logging.Log("Traveler: will continue in [ " + Math.Round(_nextTravelerAction.Subtract(DateTime.UtcNow).TotalSeconds, 0) + " ]sec");
                return;
            }

            Cache.Instance.NextTravelerAction = DateTime.UtcNow.AddSeconds(1);
            if (Settings.Instance.DebugTraveler) Logging.Log("Traveler", "NavigateToBookmarkSystem - Iterating- next iteration should be in no less than [1] second ", Logging.Teal);

            _destinationRoute = Cache.Instance.DirectEve.Navigation.GetDestinationPath();

            if (_destinationRoute.Count == 0 || _destinationRoute.All(d => d != solarSystemId))
            {
                if (Settings.Instance.DebugTraveler) if (_destinationRoute.Count == 0) Logging.Log("Traveler", "We have no destination", Logging.Teal);
                if (Settings.Instance.DebugTraveler) if (_destinationRoute.All(d => d != solarSystemId)) Logging.Log("Traveler", "the destination is not currently set to solarsystemId [" + solarSystemId + "]", Logging.Teal);

                // We do not have the destination set
                if (DateTime.UtcNow > _nextGetLocation || _location == null)
                {
                    if (Settings.Instance.DebugTraveler) Logging.Log("Traveler", "NavigateToBookmarkSystem: getting Location of solarSystemId [" + solarSystemId + "]", Logging.Teal);
                    _nextGetLocation = DateTime.UtcNow.AddSeconds(10);
                    _location = Cache.Instance.DirectEve.Navigation.GetLocation(solarSystemId);
                    Cache.Instance.NextTravelerAction = DateTime.UtcNow.AddSeconds(2);
                    return;
                }

                if (_location.IsValid)
                {
                    _locationErrors = 0;
                    Logging.Log("Traveler", "Setting destination to [" + Logging.Yellow + _location.Name + Logging.Green + "]", Logging.Green);
                    if (Settings.Instance.DebugTraveler) Logging.Log("Traveler", "Setting destination to [" + Logging.Yellow + _location.Name + Logging.Green + "]", Logging.Teal);
                    try
                    {
                        _location.SetDestination();
                    }
                    catch (Exception)
                    {
                        Logging.Log("Traveler", "NavigateToBookmarkSystem: set destination to [" + _location.ToString() + "] failed ", Logging.Debug);
                    }
                    Cache.Instance.NextTravelerAction = DateTime.UtcNow.AddSeconds(3);
                    return;
                }

                Logging.Log("Traveler", "Error setting solar system destination [" + Logging.Yellow + solarSystemId + Logging.Green + "]", Logging.Green);
                _locationErrors++;
                if (_locationErrors > 100)
                {
                    _States.CurrentTravelerState = TravelerState.Error;
                    return;
                }
                return;
            }

            _locationErrors = 0;
            if (!Cache.Instance.InSpace)
            {
                if (Cache.Instance.InStation)
                {
                    Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.CmdExitStation);
                    _nextTravelerAction = DateTime.UtcNow.AddSeconds(Time.Instance.TravelerExitStationAmIInSpaceYet_seconds);
                }
                Cache.Instance.NextActivateSupportModules = DateTime.UtcNow.AddSeconds(Cache.Instance.RandomNumber(1, 2));

                // We are not yet in space, wait for it
                return;
            }

            // We are apparently not really in space yet...
            if (Cache.Instance.DirectEve.ActiveShip.Entity == null)
                return;

            //if (Settings.Instance.DebugTraveler) Logging.Log("Traveler", "Destination is set: processing...", Logging.Teal);

            // Find the first waypoint
            long waypoint = _destinationRoute.FirstOrDefault();

            //if (Settings.Instance.DebugTraveler) Logging.Log("Traveler", "NavigateToBookmarkSystem: getting next waypoints locationname", Logging.Teal);
            _locationName = Cache.Instance.DirectEve.Navigation.GetLocationName(waypoint);
            if (Settings.Instance.DebugTraveler) Logging.Log("Traveler", "NavigateToBookmarkSystem: Next Waypoint is: [" + _locationName + "]", Logging.Teal);

            // Find the stargate associated with it

            if (!Cache.Instance.Stargates.Any())
            {
                // not found, that cant be true?!?!?!?!
                Logging.Log("Traveler", "Error [" + Logging.Yellow + _locationName + Logging.Green + "] not found, most likely lag waiting [" + Time.Instance.TravelerNoStargatesFoundRetryDelay_seconds + "] seconds.", Logging.Red);
                _nextTravelerAction = DateTime.UtcNow.AddSeconds(Time.Instance.TravelerNoStargatesFoundRetryDelay_seconds);
                return;
            }

            // Warp to, approach or jump the stargate
            EntityCache MyNextStargate = Cache.Instance.Stargates.FirstOrDefault(e => e.Name == _locationName);
            if (MyNextStargate != null && (MyNextStargate.Distance < (int)Distance.DecloakRange && !Cache.Instance.DirectEve.ActiveShip.Entity.IsCloaked))
            {
                Logging.Log("Traveler", "Jumping to [" + Logging.Yellow + _locationName + Logging.Green + "]", Logging.Green);
                MyNextStargate.Jump();
                Cache.Instance.NextInSpaceorInStation = DateTime.UtcNow;
                _nextTravelerAction = DateTime.UtcNow.AddSeconds(Time.Instance.TravelerJumpedGateNextCommandDelay_seconds);
                Cache.Instance.NextActivateSupportModules = DateTime.UtcNow.AddSeconds(Time.Instance.TravelerJumpedGateNextCommandDelay_seconds);
                return;
            }

            if (MyNextStargate != null && MyNextStargate.Distance < (int)Distance.WarptoDistance)
            {
                if (DateTime.UtcNow > Cache.Instance.NextApproachAction && !Cache.Instance.IsApproaching)
                {
                    if (Settings.Instance.DebugTraveler) Logging.Log("Traveler", "NavigateToBookmarkSystem: approaching the stargate named [" + MyNextStargate.Name + "]", Logging.Teal);
                    MyNextStargate.Approach(); //you could use a negative approach distance here but ultimately that is a bad idea.. Id like to go toward the entity without approaching it so we would end up inside the docking ring (eventually)
                    return;
                }
                if (Settings.Instance.DebugTraveler) Logging.Log("Traveler", "NavigateToBookmarkSystem: we are already approaching the stargate named [" + MyNextStargate.Name + "]", Logging.Teal);
                return;
            }

            if (DateTime.UtcNow > Cache.Instance.NextWarpTo)
            {
                if (Cache.Instance.InSpace && !Cache.Instance.TargetedBy.Any(t => t.IsWarpScramblingMe))
                {
                    if (MyNextStargate != null)
                    {
                        Logging.Log("Traveler",
                                    "Warping to [" + Logging.Yellow + _locationName + Logging.Green + "][" + Logging.Yellow +
                                    Math.Round((MyNextStargate.Distance / 1000) / 149598000, 2) + Logging.Green + " AU away]", Logging.Green);
                        MyNextStargate.WarpTo();
                    }
                    return;
                }
                return;
            }
            if (!Combat.ReloadAll(Cache.Instance.MyShipEntity)) return;
            return;
        }
コード例 #11
0
ファイル: Traveler.cs プロジェクト: Grafalck/Questor
        /// <summary>
        ///   Set destination to a solar system
        /// </summary>
        public static bool SetStationDestination(long stationId)
        {
            _location = Cache.Instance.DirectEve.Navigation.GetLocation(stationId);
            if (Settings.Instance.DebugTraveler) Logging.Log("Traveler", "Location = [" + Logging.Yellow + Cache.Instance.DirectEve.Navigation.GetLocationName(stationId) + Logging.Green + "]", Logging.Green);
            if (_location.IsValid)
            {
                _locationErrors = 0;
                if (Settings.Instance.DebugTraveler) Logging.Log("Traveler", "Setting destination to [" + Logging.Yellow + _location.Name + Logging.Green + "]", Logging.Teal);
                try
                {
                    _location.SetDestination();
                }
                catch (Exception)
                {
                    Logging.Log("Traveler", "NavigateToBookmarkSystem: set destination to [" + _location.ToString() + "] failed ", Logging.Debug);
                }
                return true;
            }

            Logging.Log("Traveler", "Error setting solar system destination [" + Logging.Yellow + stationId + Logging.Green + "]", Logging.Green);
            _locationErrors++;
            if (_locationErrors > 100)
            {
                return false;
            }
            return false;
        }
コード例 #12
0
ファイル: Traveler.cs プロジェクト: quleebeen/Questor
        /// <summary>
        ///   Navigate to a solar system
        /// </summary>
        /// <param name = "solarSystemId"></param>
        private static void NavigateToBookmarkSystem(long solarSystemId)
        {
            if (_nextTravelerAction > DateTime.UtcNow)
            {
                //Logging.Log("Traveler: will continue in [ " + Math.Round(_nextTravelerAction.Subtract(DateTime.UtcNow).TotalSeconds, 0) + " ]sec");
                return;
            }

            if (DateTime.UtcNow < Cache.Instance.LastSessionChange.AddSeconds(10))
            {
                if (Settings.Instance.DebugTraveler) Logging.Log("Traveler", "We just session changed less than 10 sec go, wait.", Logging.Teal);
                _nextTravelerAction = Cache.Instance.LastSessionChange.AddSeconds(12);
                return;
            }

            Cache.Instance.NextTravelerAction = DateTime.UtcNow.AddSeconds(2);
            if (Settings.Instance.DebugTraveler) Logging.Log("Traveler", "NavigateToBookmarkSystem - Iterating- next iteration should be in no less than [1] second ", Logging.Teal);

            _destinationRoute = Cache.Instance.DirectEve.Navigation.GetDestinationPath();

            if (_destinationRoute.Count == 0 || _destinationRoute.All(d => d != solarSystemId))
            {
                if (Settings.Instance.DebugTraveler) if (_destinationRoute.Count == 0) Logging.Log("Traveler", "We have no destination", Logging.Teal);
                if (Settings.Instance.DebugTraveler) if (_destinationRoute.All(d => d != solarSystemId)) Logging.Log("Traveler", "the destination is not currently set to solarsystemId [" + solarSystemId + "]", Logging.Teal);

                // We do not have the destination set
                if (DateTime.UtcNow > _nextGetLocation || _location == null)
                {
                    if (Settings.Instance.DebugTraveler) Logging.Log("Traveler", "NavigateToBookmarkSystem: getting Location of solarSystemId [" + solarSystemId + "]", Logging.Teal);
                    _nextGetLocation = DateTime.UtcNow.AddSeconds(10);
                    _location = Cache.Instance.DirectEve.Navigation.GetLocation(solarSystemId);
                    Cache.Instance.NextTravelerAction = DateTime.UtcNow.AddSeconds(2);
                    return;
                }

                if (_location.IsValid)
                {
                    _locationErrors = 0;
                    Logging.Log("Traveler", "Setting destination to [" + Logging.Yellow + _location.Name + Logging.Green + "]", Logging.Green);
                    if (Settings.Instance.DebugTraveler) Logging.Log("Traveler", "Setting destination to [" + Logging.Yellow + _location.Name + Logging.Green + "]", Logging.Teal);
                    try
                    {
                        _location.SetDestination();
                    }
                    catch (Exception)
                    {
                        Logging.Log("Traveler", "NavigateToBookmarkSystem: set destination to [" + _location.ToString() + "] failed ", Logging.Debug);
                    }
                    Cache.Instance.NextTravelerAction = DateTime.UtcNow.AddSeconds(3);
                    return;
                }

                Logging.Log("Traveler", "Error setting solar system destination [" + Logging.Yellow + solarSystemId + Logging.Green + "]", Logging.Green);
                _locationErrors++;
                if (_locationErrors > 20)
                {
                    _States.CurrentTravelerState = TravelerState.Error;
                    return;
                }
                return;
            }

            _locationErrors = 0;
            if (!Cache.Instance.InSpace)
            {
                if (Cache.Instance.InStation)
                {
                    if (DateTime.UtcNow > Cache.Instance.LastInSpace.AddSeconds(45)) //do not try to leave the station until you have been docked for at least 45seconds! (this gives some overhead to load the station env + session change timer)
                    {
                        Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.CmdExitStation);
                        _nextTravelerAction = DateTime.UtcNow.AddSeconds(Time.Instance.TravelerExitStationAmIInSpaceYet_seconds);
                    }
                }
                Cache.Instance.NextActivateSupportModules = DateTime.UtcNow.AddSeconds(Cache.Instance.RandomNumber(2, 3));

                // We are not yet in space, wait for it
                return;
            }

            // We are apparently not really in space yet...
            if (Cache.Instance.ActiveShip == null || Cache.Instance.ActiveShip.Entity == null)
                return;

            //if (Settings.Instance.DebugTraveler) Logging.Log("Traveler", "Destination is set: processing...", Logging.Teal);

            // Find the first waypoint
            int waypoint = _destinationRoute.FirstOrDefault();

            //if (Settings.Instance.DebugTraveler) Logging.Log("Traveler", "NavigateToBookmarkSystem: getting next waypoints locationname", Logging.Teal);
            _locationName = Cache.Instance.DirectEve.Navigation.GetLocationName(waypoint);
            if (Settings.Instance.DebugTraveler) Logging.Log("Traveler", "NavigateToBookmarkSystem: Next Waypoint is: [" + _locationName + "]", Logging.Teal);

            if (waypoint > 6000000) // this MUST be a station
            {
                //insert code to handle station destinations here
            }

            if (waypoint < 6000000) // this is not a station, probably a system
            {
                //useful?a
            }
            DirectSolarSystem solarSystemInRoute = Cache.Instance.DirectEve.SolarSystems[waypoint];

            if (_States.CurrentQuestorState == QuestorState.CombatMissionsBehavior || _States.CurrentQuestorState == QuestorState.DedicatedBookmarkSalvagerBehavior)
            {
                if (solarSystemInRoute.Security < 0.45 && (Cache.Instance.ActiveShip.GroupId != (int)Group.Shuttle || Cache.Instance.ActiveShip.GroupId != (int)Group.Frigate || Cache.Instance.ActiveShip.GroupId != (int)Group.Interceptor))
                {
                    Logging.Log("Traveler", "NavigateToBookmarkSystem: Next Waypoint is: [" + _locationName + "] which is LOW SEC! This should never happen. Turning off AutoStart and going home.", Logging.Teal);
                    Settings.Instance.AutoStart = false;
                    if (_States.CurrentQuestorState == QuestorState.CombatMissionsBehavior)
                    {
                        _States.CurrentCombatMissionBehaviorState = CombatMissionsBehaviorState.GotoBase;
                    }
                    if (_States.CurrentQuestorState == QuestorState.DedicatedBookmarkSalvagerBehavior)
                    {
                        _States.CurrentDedicatedBookmarkSalvagerBehaviorState = DedicatedBookmarkSalvagerBehaviorState.GotoBase;
                    }
                    //if (_States.CurrentQuestorState == QuestorState.CombatHelperBehavior)
                    //{
                    //    _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.GotoBase;
                    //}
                    return;
                }
            }

            // Find the stargate associated with it

            if (!Cache.Instance.Stargates.Any())
            {
                // not found, that cant be true?!?!?!?!
                Logging.Log("Traveler", "Error [" + Logging.Yellow + _locationName + Logging.Green + "] not found, most likely lag waiting [" + Time.Instance.TravelerNoStargatesFoundRetryDelay_seconds + "] seconds.", Logging.Red);
                _nextTravelerAction = DateTime.UtcNow.AddSeconds(Time.Instance.TravelerNoStargatesFoundRetryDelay_seconds);
                return;
            }

            // Warp to, approach or jump the stargate
            EntityCache MyNextStargate = Cache.Instance.StargateByName(_locationName);
            if (MyNextStargate != null)
            {
                if (MyNextStargate.Distance < (int)Distances.DecloakRange && !Cache.Instance.ActiveShip.Entity.IsCloaked)
                {
                    Logging.Log("Traveler", "Jumping to [" + Logging.Yellow + _locationName + Logging.Green + "]", Logging.Green);
                    MyNextStargate.Jump();
                    Cache.Instance.NextInSpaceorInStation = DateTime.UtcNow;
                    _nextTravelerAction = DateTime.UtcNow.AddSeconds(Time.Instance.TravelerJumpedGateNextCommandDelay_seconds);
                    Cache.Instance.NextActivateSupportModules = DateTime.UtcNow.AddSeconds(Time.Instance.TravelerJumpedGateNextCommandDelay_seconds);
                    return;
                }

                if (MyNextStargate.Distance < (int)Distances.WarptoDistance && MyNextStargate.Distance != 0)
                {
                    if (DateTime.UtcNow > Cache.Instance.NextApproachAction && !Cache.Instance.IsApproaching(MyNextStargate.Id))
                    {
                        if (Settings.Instance.DebugTraveler) Logging.Log("Traveler", "NavigateToBookmarkSystem: approaching the stargate named [" + MyNextStargate.Name + "]", Logging.Teal);
                        MyNextStargate.Approach(); //you could use a negative approach distance here but ultimately that is a bad idea.. Id like to go toward the entity without approaching it so we would end up inside the docking ring (eventually)
                        return;
                    }

                    if (Settings.Instance.DebugTraveler) Logging.Log("Traveler", "NavigateToBookmarkSystem: we are already approaching the stargate named [" + MyNextStargate.Name + "]", Logging.Teal);
                    return;
                }

                if (DateTime.UtcNow > Cache.Instance.NextWarpTo)
                {
                    if (Cache.Instance.InSpace && !Cache.Instance.TargetedBy.Any(t => t.IsWarpScramblingMe))
                    {
                        Logging.Log("Traveler", "Warping to [" + Logging.Yellow + _locationName + Logging.Green + "][" + Logging.Yellow + Math.Round((MyNextStargate.Distance / 1000) / 149598000, 2) + Logging.Green + " AU away]", Logging.Green);
                        MyNextStargate.WarpTo();
                        return;
                    }

                    return;
                }
            }

            _nextTravelerAction = DateTime.UtcNow.AddSeconds(Time.Instance.WarptoDelay_seconds); //this should probably use a different Time definition, but this works for now. (5 seconds)
            if (!Combat.ReloadAll(Cache.Instance.MyShipEntity)) return;
            return;
        }
コード例 #13
0
ファイル: Traveler.cs プロジェクト: Chryst/Questor
        /// <summary>
        ///   Set destination to a solar system
        /// </summary>
        public static bool SetStationDestination(long stationId)
        {
            _location = Cache.Instance.DirectEve.Navigation.GetLocation(stationId);
            if (Settings.Instance.DebugTraveler) Logging.Log("Traveler", "Location = [" + Logging.Yellow + Cache.Instance.DirectEve.Navigation.GetLocationName(stationId) + Logging.Green + "]", Logging.Green);
            if (_location.IsValid)
            {
                _locationErrors = 0;
                if (Settings.Instance.DebugTraveler) Logging.Log("Traveler", "Setting destination to [" + Logging.Yellow + _location.Name + Logging.Green + "]", Logging.Teal);
                _location.SetDestination();
                return true;
            }

            Logging.Log("Traveler", "Error setting solar system destination [" + Logging.Yellow + stationId + Logging.Green + "]", Logging.Green);
            _locationErrors++;
            if (_locationErrors > 100)
            {
                return false;
            }
            return false;
        }
コード例 #14
0
ファイル: Traveler.cs プロジェクト: seb1707/Questor
        /// <summary>
        ///   Navigate to a solar system
        /// </summary>
        /// <param name = "solarSystemId"></param>
        private static void NavigateToBookmarkSystem(long solarSystemId)
        {
            if (_nextTravelerAction > DateTime.UtcNow)
            {
                //Logging.Log("Traveler: will continue in [ " + Math.Round(_nextTravelerAction.Subtract(DateTime.UtcNow).TotalSeconds, 0) + " ]sec");
                return;
            }

            if (DateTime.UtcNow < Cache.Instance.LastSessionChange.AddSeconds(10))
            {
                if (Settings.Instance.DebugTraveler)
                {
                    Logging.Log("Traveler", "We just session changed less than 10 sec go, wait.", Logging.Teal);
                }
                _nextTravelerAction = Cache.Instance.LastSessionChange.AddSeconds(12);
                return;
            }

            Cache.Instance.NextTravelerAction = DateTime.UtcNow.AddSeconds(2);
            if (Settings.Instance.DebugTraveler)
            {
                Logging.Log("Traveler", "NavigateToBookmarkSystem - Iterating- next iteration should be in no less than [1] second ", Logging.Teal);
            }

            _destinationRoute = Cache.Instance.DirectEve.Navigation.GetDestinationPath();

            if (_destinationRoute.Count == 0 || _destinationRoute.All(d => d != solarSystemId))
            {
                if (Settings.Instance.DebugTraveler)
                {
                    if (_destinationRoute.Count == 0)
                    {
                        Logging.Log("Traveler", "We have no destination", Logging.Teal);
                    }
                }
                if (Settings.Instance.DebugTraveler)
                {
                    if (_destinationRoute.All(d => d != solarSystemId))
                    {
                        Logging.Log("Traveler", "the destination is not currently set to solarsystemId [" + solarSystemId + "]", Logging.Teal);
                    }
                }

                // We do not have the destination set
                if (DateTime.UtcNow > _nextGetLocation || _location == null)
                {
                    if (Settings.Instance.DebugTraveler)
                    {
                        Logging.Log("Traveler", "NavigateToBookmarkSystem: getting Location of solarSystemId [" + solarSystemId + "]", Logging.Teal);
                    }
                    _nextGetLocation = DateTime.UtcNow.AddSeconds(10);
                    _location        = Cache.Instance.DirectEve.Navigation.GetLocation(solarSystemId);
                    Cache.Instance.NextTravelerAction = DateTime.UtcNow.AddSeconds(2);
                    return;
                }

                if (_location.IsValid)
                {
                    _locationErrors = 0;
                    Logging.Log("Traveler", "Setting destination to [" + Logging.Yellow + _location.Name + Logging.Green + "]", Logging.Green);
                    if (Settings.Instance.DebugTraveler)
                    {
                        Logging.Log("Traveler", "Setting destination to [" + Logging.Yellow + _location.Name + Logging.Green + "]", Logging.Teal);
                    }
                    try
                    {
                        _location.SetDestination();
                    }
                    catch (Exception)
                    {
                        Logging.Log("Traveler", "NavigateToBookmarkSystem: set destination to [" + _location.ToString() + "] failed ", Logging.Debug);
                    }
                    Cache.Instance.NextTravelerAction = DateTime.UtcNow.AddSeconds(3);
                    return;
                }

                Logging.Log("Traveler", "Error setting solar system destination [" + Logging.Yellow + solarSystemId + Logging.Green + "]", Logging.Green);
                _locationErrors++;
                if (_locationErrors > 20)
                {
                    _States.CurrentTravelerState = TravelerState.Error;
                    return;
                }
                return;
            }

            _locationErrors = 0;
            if (!Cache.Instance.InSpace)
            {
                if (Cache.Instance.InStation)
                {
                    if (DateTime.UtcNow > Cache.Instance.LastInSpace.AddSeconds(45)) //do not try to leave the station until you have been docked for at least 45seconds! (this gives some overhead to load the station env + session change timer)
                    {
                        Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.CmdExitStation);
                        _nextTravelerAction = DateTime.UtcNow.AddSeconds(Time.Instance.TravelerExitStationAmIInSpaceYet_seconds);
                    }
                }
                Cache.Instance.NextActivateSupportModules = DateTime.UtcNow.AddSeconds(Cache.Instance.RandomNumber(2, 3));

                // We are not yet in space, wait for it
                return;
            }

            // We are apparently not really in space yet...
            if (Cache.Instance.ActiveShip == null || Cache.Instance.ActiveShip.Entity == null)
            {
                return;
            }

            //if (Settings.Instance.DebugTraveler) Logging.Log("Traveler", "Destination is set: processing...", Logging.Teal);

            // Find the first waypoint
            int waypoint = _destinationRoute.FirstOrDefault();

            //if (Settings.Instance.DebugTraveler) Logging.Log("Traveler", "NavigateToBookmarkSystem: getting next way-points locationName", Logging.Teal);
            _locationName = Cache.Instance.DirectEve.Navigation.GetLocationName(waypoint);
            if (Settings.Instance.DebugTraveler)
            {
                Logging.Log("Traveler", "NavigateToBookmarkSystem: Next Waypoint is: [" + _locationName + "]", Logging.Teal);
            }

            if (waypoint > 60000000) // this MUST be a station
            {
                //insert code to handle station destinations here
            }

            if (waypoint < 60000000) // this is not a station, probably a system
            {
                //useful?a
            }
            DirectSolarSystem solarSystemInRoute = Cache.Instance.DirectEve.SolarSystems[waypoint];

            if (_States.CurrentQuestorState == QuestorState.CombatMissionsBehavior || _States.CurrentQuestorState == QuestorState.DedicatedBookmarkSalvagerBehavior)
            {
                if (solarSystemInRoute.Security < 0.45 && (Cache.Instance.ActiveShip.GroupId != (int)Group.Shuttle || Cache.Instance.ActiveShip.GroupId != (int)Group.Frigate || Cache.Instance.ActiveShip.GroupId != (int)Group.Interceptor))
                {
                    Logging.Log("Traveler", "NavigateToBookmarkSystem: Next Waypoint is: [" + _locationName + "] which is LOW SEC! This should never happen. Turning off AutoStart and going home.", Logging.Teal);
                    Settings.Instance.AutoStart = false;
                    if (_States.CurrentQuestorState == QuestorState.CombatMissionsBehavior)
                    {
                        _States.CurrentCombatMissionBehaviorState = CombatMissionsBehaviorState.GotoBase;
                    }
                    if (_States.CurrentQuestorState == QuestorState.DedicatedBookmarkSalvagerBehavior)
                    {
                        _States.CurrentDedicatedBookmarkSalvagerBehaviorState = DedicatedBookmarkSalvagerBehaviorState.GotoBase;
                    }
                    //if (_States.CurrentQuestorState == QuestorState.CombatHelperBehavior)
                    //{
                    //    _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.GotoBase;
                    //}
                    return;
                }
            }

            // Find the stargate associated with it

            if (!Cache.Instance.Stargates.Any())
            {
                // not found, that cant be true?!?!?!?!
                Logging.Log("Traveler", "Error [" + Logging.Yellow + _locationName + Logging.Green + "] not found, most likely lag waiting [" + Time.Instance.TravelerNoStargatesFoundRetryDelay_seconds + "] seconds.", Logging.Red);
                _nextTravelerAction = DateTime.UtcNow.AddSeconds(Time.Instance.TravelerNoStargatesFoundRetryDelay_seconds);
                return;
            }

            // Warp to, approach or jump the stargate
            EntityCache MyNextStargate = Cache.Instance.StargateByName(_locationName);

            if (MyNextStargate != null)
            {
                if (MyNextStargate.Distance < (int)Distances.DecloakRange && !Cache.Instance.ActiveShip.Entity.IsCloaked)
                {
                    if (MyNextStargate.Jump())
                    {
                        Logging.Log("Traveler", "Jumping to [" + Logging.Yellow + _locationName + Logging.Green + "]", Logging.Green);
                        return;
                    }

                    return;
                }

                if (MyNextStargate.Distance < (int)Distances.WarptoDistance && MyNextStargate.Distance != 0)
                {
                    if (DateTime.UtcNow > Cache.Instance.NextApproachAction && !Cache.Instance.IsApproaching(MyNextStargate.Id))
                    {
                        if (Settings.Instance.DebugTraveler)
                        {
                            Logging.Log("Traveler", "NavigateToBookmarkSystem: approaching the stargate named [" + MyNextStargate.Name + "]", Logging.Teal);
                        }
                        MyNextStargate.Approach(); //you could use a negative approach distance here but ultimately that is a bad idea.. Id like to go toward the entity without approaching it so we would end up inside the docking ring (eventually)
                        return;
                    }

                    if (Settings.Instance.DebugTraveler)
                    {
                        Logging.Log("Traveler", "NavigateToBookmarkSystem: we are already approaching the stargate named [" + MyNextStargate.Name + "]", Logging.Teal);
                    }
                    return;
                }

                if (Cache.Instance.InSpace && !Cache.Instance.TargetedBy.Any(t => t.IsWarpScramblingMe))
                {
                    if (MyNextStargate.WarpTo())
                    {
                        Logging.Log("Traveler", "Warping to [" + Logging.Yellow + _locationName + Logging.Green + "][" + Logging.Yellow + Math.Round((MyNextStargate.Distance / 1000) / 149598000, 2) + Logging.Green + " AU away]", Logging.Green);
                        return;
                    }

                    return;
                }
            }

            _nextTravelerAction = DateTime.UtcNow.AddSeconds(Time.Instance.WarptoDelay_seconds); //this should probably use a different Time definition, but this works for now. (5 seconds)
            if (!Combat.ReloadAll(Cache.Instance.MyShipEntity))
            {
                return;
            }
            return;
        }