Пример #1
0
 /// <summary>
 /// Dumps everything on server closure
 /// </summary>
 public override void Dispose()
 {
     base.Dispose();
     _planets.Clear();
     _lastRun.Clear();
     _lastChoice = null;
 }
Пример #2
0
        public static void PrepareWeatherDefinition(MyDefinitionManager __instance, ref MyWeatherEffectDefinition __result, ref string subtype)
        {
            if (__result != null)
            {
                var weatherDefinition = __result;

                if (LightningManagerPlugin.Config.LightningCharacterHitIntervalMax != -1)
                {
                    weatherDefinition.LightningCharacterHitIntervalMax = LightningManagerPlugin.Config.LightningCharacterHitIntervalMax;
                }
                if (LightningManagerPlugin.Config.LightningCharacterHitIntervalMin != -1)
                {
                    weatherDefinition.LightningCharacterHitIntervalMin = LightningManagerPlugin.Config.LightningCharacterHitIntervalMin;
                }
                if (LightningManagerPlugin.Config.LightningGridHitIntervalMax != -1)
                {
                    weatherDefinition.LightningGridHitIntervalMax = LightningManagerPlugin.Config.LightningGridHitIntervalMax;
                }
                if (LightningManagerPlugin.Config.LightningGridHitIntervalMin != -1)
                {
                    weatherDefinition.LightningGridHitIntervalMin = LightningManagerPlugin.Config.LightningGridHitIntervalMin;
                }
                if (LightningManagerPlugin.Config.LightningIntervalMax != -1)
                {
                    weatherDefinition.LightningIntervalMax = LightningManagerPlugin.Config.LightningIntervalMax;
                }
                if (LightningManagerPlugin.Config.LightningIntervalMin != -1)
                {
                    weatherDefinition.LightningIntervalMin = LightningManagerPlugin.Config.LightningIntervalMin;
                }
            }
        }
Пример #3
0
        public static bool TryGetWeather(string weather, out MyWeatherEffectDefinition weatherDef)
        {
            weatherDef = null;
            ListReader <MyWeatherEffectDefinition> weatherDefinitions = MyDefinitionManager.Static.GetWeatherDefinitions();

            foreach (var def in weatherDefinitions)
            {
                if (!def.Id.SubtypeName.Equals(weather, StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                weatherDef = def;
                break;
            }

            return(weatherDef != null);
        }
Пример #4
0
        public static MyWeatherEffectDefinition GetWeatherDefinition(string weatherName)
        {
            MyWeatherEffectDefinition weatherDef = null;
            ListReader <MyWeatherEffectDefinition> weatherDefinitions = MyDefinitionManager.Static.GetWeatherDefinitions();

            foreach (var weather in weatherDefinitions)
            {
                if (!weather.Id.SubtypeName.Equals(weatherName, StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                weatherDef = weather;
                break;
            }

            return(weatherDef);
        }
Пример #5
0
        public static void SetWeatherOnPlanet(MyPlanet planet, MyWeatherEffectDefinition weather)
        {
            float    planetRadius   = planet.MaximumRadius;
            Vector3D pos            = planet.PositionLeftBottomCorner + new Vector3D(planetRadius, planetRadius, planetRadius);
            var      currentWeather = string.IsNullOrEmpty(GetWeather(pos))? "Clear" : GetWeather(pos);
            var      weatherToSpawn = weather;

            if (weatherToSpawn == null)
            {
                Log.Warn("Can't find weather");
                return;
            }
            var radius = (planetRadius + planetRadius * 0.5f) * 2f;

            SpawnWeather(weatherToSpawn, radius, planet);
            Log.Info($"Changing weather on {planet.Name} from {currentWeather} to {weatherToSpawn.Id.SubtypeName}");
        }
Пример #6
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;
            }
        }
Пример #7
0
        public static bool SpawnWeather(MyWeatherEffectDefinition weather, Vector3D position, float radius)
        {
            MyPlanet closestPlanet = MyGamePruningStructure.GetClosestPlanet(position);

            if (closestPlanet == null)
            {
                return(false);
            }

            var sessionWeather           = MySession.Static.GetComponent <MySectorWeatherComponent>();
            var sessionWeatherPlanetData = _planetWeatherGet(sessionWeather);

            if (Math.Abs((double)radius) < 1)
            {
                radius = 0.1122755f * closestPlanet.AtmosphereRadius;
            }
            var weatherPosition = new Vector3D?(closestPlanet.GetClosestSurfacePointGlobal(ref position));

            MyObjectBuilder_WeatherEffect builderWeatherEffect1 = new MyObjectBuilder_WeatherEffect()
            {
                Weather  = weather.Id.SubtypeName,
                Position = weatherPosition.Value,
                Radius   = radius
            };
            List <MyObjectBuilder_WeatherEffect> builderWeatherEffectList = new List <MyObjectBuilder_WeatherEffect>();

            BoundingSphereD boundingSphereD = new BoundingSphereD(weatherPosition.Value, (double)radius);

            for (int index1 = 0; index1 < sessionWeatherPlanetData.Count; ++index1)
            {
                if (sessionWeatherPlanetData[index1].PlanetId == closestPlanet.EntityId)
                {
                    builderWeatherEffectList.Clear();
                    for (int index2 = 0; index2 < sessionWeatherPlanetData[index1].Weathers.Count; ++index2)
                    {
                        BoundingSphereD sphere = new BoundingSphereD(sessionWeatherPlanetData[index1].Weathers[index2].Position, (double)sessionWeatherPlanetData[index1].Weathers[index2].Radius);
                        if (boundingSphereD.Intersects(sphere))
                        {
                            builderWeatherEffectList.Add(sessionWeatherPlanetData[index1].Weathers[index2]);
                        }
                    }
                    foreach (MyObjectBuilder_WeatherEffect builderWeatherEffect in builderWeatherEffectList)
                    {
                        sessionWeatherPlanetData[index1].Weathers.Remove(builderWeatherEffect);
                    }
                }
            }

            bool flag = false;

            for (int index = 0; index < sessionWeatherPlanetData.Count; ++index)
            {
                if (sessionWeatherPlanetData[index].PlanetId == closestPlanet.EntityId)
                {
                    sessionWeatherPlanetData[index].Weathers.Add(builderWeatherEffect1);
                    flag = true;
                    break;
                }
            }

            if (!flag)
            {
                var weatherPlanetData = new MyObjectBuilder_WeatherPlanetData()
                {
                    PlanetId = closestPlanet.EntityId
                };
                weatherPlanetData.Weathers.Add(builderWeatherEffect1);
                sessionWeatherPlanetData.Add(weatherPlanetData);
            }

            SyncWeather();

            return(true);
        }