Пример #1
0
        /// <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);
        }
Пример #2
0
        /// <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;
        }