Ejemplo n.º 1
0
        public void TestSystemsCube()
        {
            // Setup
            string         resource = "api-v1/cube-systems";
            string         json     = Encoding.UTF8.GetString(Resources.cubeSystemsAroundSol);
            List <JObject> data     = new List <JObject>();

            fakeEdsmRestClient.Expect(resource, json, data);
            string systemName = "Sol";

            List <StarSystem> starSystems = fakeEdsmService.GetStarMapSystemsCube(systemName, 15, false, false, false, false);

            Assert.AreEqual(9, starSystems.Count);
        }
Ejemplo n.º 2
0
        public void TestSystemsCube()
        {
            string            systemName  = "Sol";
            List <StarSystem> starSystems = StarMapService.GetStarMapSystemsCube(systemName, 15, false, false, false, false);

            Assert.AreEqual(9, starSystems.Count);
        }
Ejemplo n.º 3
0
        public void TestSystemsCubeUnknown()
        {
            string systemName = "No such system";

            try
            {
                List <StarSystem> starSystems = StarMapService.GetStarMapSystemsCube(systemName, 15, false, false, false, false);
                Assert.IsNull(starSystems);
            }
            catch (System.Exception)
            {
                Assert.Fail();
            }
        }
Ejemplo n.º 4
0
        public StarSystem GetServiceSystem(string serviceType, int maxStationDistance, bool prioritizeOrbitalStations)
        {
            StarSystem currentSystem = EDDI.Instance?.CurrentStarSystem;

            if (currentSystem != null)
            {
                // Get the filter parameters
                string shipSize = EDDI.Instance?.CurrentShip?.size ?? "Large";
                ServiceFilter.TryGetValue(serviceType, out dynamic filter);
                int cubeLy = filter.cubeLy;

                //
                List <string> checkedSystems = new List <string>();
                string        ServiceSystem  = null;
                int           maxTries       = 5;

                while (ServiceSystem == null && maxTries > 0)
                {
                    List <StarSystem> cubeSystems = StarMapService.GetStarMapSystemsCube(currentSystem.systemname, cubeLy);
                    if (cubeSystems?.Any() ?? false)
                    {
                        // Filter systems using search parameters
                        cubeSystems = cubeSystems.Where(s => s.population >= filter.population).ToList();
                        cubeSystems = cubeSystems.Where(s => filter.security.Contains(s.security)).ToList();
                        if (serviceType != "facilitator")
                        {
                            cubeSystems = cubeSystems
                                          .Where(s => filter.econ.Contains(s.Economies.FirstOrDefault(e => e.invariantName != "None")?.invariantName))
                                          .ToList();
                        }

                        // Retreive systems in current radius which have not been previously checked
                        List <string> systemNames = cubeSystems.Select(s => s.systemname).Except(checkedSystems).ToList();
                        if (systemNames.Count > 0)
                        {
                            List <StarSystem> StarSystems = StarSystemSqLiteRepository.Instance.GetOrFetchStarSystems(systemNames.ToArray(), true, false);
                            checkedSystems.AddRange(systemNames);

                            SortedList <decimal, string> nearestList = new SortedList <decimal, string>();
                            foreach (StarSystem starsystem in StarSystems)
                            {
                                // Filter stations within the system which meet the station type prioritization,
                                // max distance from the main star, game version, and landing pad size requirements
                                List <Station> stations = !prioritizeOrbitalStations && EDDI.Instance.inHorizons ? starsystem.stations : starsystem.orbitalstations
                                                          .Where(s => s.stationservices.Count > 0).ToList();
                                stations = stations.Where(s => s.distancefromstar <= maxStationDistance).ToList();
                                if (serviceType == "facilitator")
                                {
                                    stations = stations.Where(s => s.LandingPadCheck(shipSize)).ToList();
                                }
                                int stationCount = stations.Where(s => s.stationservices.Contains(filter.service)).Count();

                                // Build list to find the 'service' system nearest to the current system, meeting station requirements
                                if (stationCount > 0)
                                {
                                    decimal distance = CalculateDistance(currentSystem, starsystem);
                                    if (!nearestList.ContainsKey(distance))
                                    {
                                        nearestList.Add(distance, starsystem.systemname);
                                    }
                                }
                            }

                            // Nearest 'service' system
                            ServiceSystem = nearestList.Values.FirstOrDefault();
                            if (ServiceSystem != null)
                            {
                                return(StarSystems.FirstOrDefault(s => s.systemname == ServiceSystem));
                            }
                        }
                    }

                    // Increase search radius in 10 Ly increments (up to 50 Ly)
                    // until the required 'service' is found
                    cubeLy += 10;
                    maxTries--;
                }
            }
            return(null);
        }