Example #1
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 #2
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;
            }
        }