Example #1
0
        public void Clear(string planetName)
        {
            var planets = MyEntities.GetEntities().OfType <MyPlanet>().ToList();
            ListReader <MyWeatherEffectDefinition> weatherDefinitions = MyDefinitionManager.Static.GetWeatherDefinitions();
            var weatherDef = weatherDefinitions.FirstOrDefault(x => x.Id.SubtypeName.Equals("Clear"));

            if (planets.Count == 0)
            {
                Context.Respond("No Planet Found");
                return;
            }

            var count = 0;

            foreach (var planet in planets)
            {
                if (planet.Name != planetName)
                {
                    continue;
                }
                count++;
                WeatherGenerator.SetWeatherOnPlanet(planet, weatherDef);
            }

            Context.Respond($"Clearing up the weather on {count} planets");
        }
Example #2
0
        public void RequestWeather(string planetName, string weather)
        {
            var foundPlanets = MyEntities.GetEntities().OfType <MyPlanet>();
            var planets      = foundPlanets.Where(x => x.Name.Contains(planetName, StringComparison.OrdinalIgnoreCase)).ToList();

            if (planets.Count == 0)
            {
                Context.Respond("Can't find that planet on the server");
                return;
            }

            if (weather.Equals("random", StringComparison.OrdinalIgnoreCase))
            {
                weather = WeatherGenerator.GetRandomWeather().Id.SubtypeName;
            }

            if (!WeatherGenerator.TryGetWeather(weather, out var weatherDef))
            {
                Context.Respond("Weather type not found");
                return;
            }

            var count = 0;

            foreach (var planet in planets)
            {
                WeatherGenerator.SetWeatherOnPlanet(planet, weatherDef);
                count++;
            }
            Context.Respond($"Setting {weather} for {count} planets with the name {planetName}");
        }
Example #3
0
        public void GetWeather(string planetName = null)
        {
            var foundPlanets = MyEntities.GetEntities().OfType <MyPlanet>();

            var planets = string.IsNullOrEmpty(planetName)? foundPlanets.ToList():foundPlanets.Where(x => x.Name.Contains(planetName, StringComparison.OrdinalIgnoreCase)).ToList();

            if (planets.Count == 0)
            {
                Context.Respond("Can't find requested planet on the server");
                return;
            }
            var sb = new StringBuilder();

            sb.AppendLine("PlanetName [Id]: WeatherSubtypeId");
            foreach (var planet in planets)
            {
                var weather = string.IsNullOrEmpty(WeatherGenerator.GetWeather(planet))? "None Set" : WeatherGenerator.GetWeather(planet);
                sb.AppendLine($"{planet.Name} [{planet.EntityId}]: {weather}");
            }

            Context.Respond(sb.ToString());
            RandomWeatherPluginCore.Log.Info(sb.ToString);
        }
Example #4
0
        private void SpawnWeathers()
        {
            if (MySession.Static.Players.GetOnlinePlayerCount() == 0 || _planets.Count == 0)
            {
                return;
            }

            var rules = new HashSet <CustomWeatherRule>();

            rules.UnionWith(RandomWeatherConfig.Instance.CustomWeatherRules);

            foreach (var planet in _planets)
            {
                if (!planet.HasAtmosphere)
                {
                    continue;
                }
                var removeWeather = new List <string>();
                if (planet.Storage.MarkedForClose || planet.Storage == null)
                {
                    continue;
                }
                CustomWeatherRule foundRule = null;

                foreach (var rule in rules)
                {
                    if (!rule.PlanetId.Equals(planet.EntityId))
                    {
                        continue;
                    }
                    foundRule = rule;
                    break;
                }
                var interval = foundRule?.Interval ?? RandomWeatherConfig.Instance.WeatherInterval;

                if (!_lastRun.TryGetValue(planet, out var time))
                {
                    float    planetRadius   = planet.MaximumRadius;
                    Vector3D pos            = planet.PositionLeftBottomCorner + new Vector3D(planetRadius, planetRadius, planetRadius);
                    var      currentWeather = WeatherGenerator.GetWeather(pos);
                    MyWeatherEffectDefinition weatherToSpawn;
                    if (_lastChoice != null)
                    {
                        removeWeather.Add(_lastChoice.Id.SubtypeName);
                    }

                    if (string.IsNullOrEmpty(currentWeather) || currentWeather.Equals("clear", StringComparison.OrdinalIgnoreCase))
                    {
                        weatherToSpawn = foundRule == null
                            ? WeatherGenerator.GetRandomWeather(removeWeather)
                            : WeatherGenerator.GetRandomWeatherFromList(foundRule.WeatherList, currentWeather);
                    }
                    else
                    {
                        weatherToSpawn = WeatherGenerator.GetWeatherDefinition("Clear");
                    }
                    if (weatherToSpawn == null)
                    {
                        continue;
                    }
                    _lastChoice = weatherToSpawn;
                    WeatherGenerator.SetWeatherOnPlanet(planet, weatherToSpawn);
                    _lastRun[planet] = DateTime.Now;

                    break;
                }
                if (Math.Abs((DateTime.Now - time).TotalMilliseconds) < interval * 60000)
                {
                    continue;
                }
                _lastRun.Remove(planet);
                break;
            }
        }