Пример #1
0
        public void LoadConfigs(bool isReload = false)
        {
            // Thread safe assignment
            var nowconfig = api.Assets.Get <WeatherSystemConfig>(new AssetLocation("config/weather.json"));

            if (isReload)
            {
                nowconfig.Init(api.World);
            }

            GeneralConfig = nowconfig;

            var dictWeatherPatterns    = api.Assets.GetMany <WeatherPatternConfig[]>(api.World.Logger, "config/weatherpatterns/");
            var orderedWeatherPatterns = dictWeatherPatterns.OrderBy(val => val.Key.ToString()).Select(val => val.Value).ToArray();

            WeatherConfigs = new WeatherPatternConfig[0];
            foreach (var val in orderedWeatherPatterns)
            {
                WeatherConfigs = WeatherConfigs.Append(val);
            }

            var dictWindPatterns    = api.Assets.GetMany <WindPatternConfig[]>(api.World.Logger, "config/windpatterns/");
            var orderedWindPatterns = dictWindPatterns.OrderBy(val => val.Key.ToString()).Select(val => val.Value).ToArray();

            WindConfigs = new WindPatternConfig[0];
            foreach (var val in orderedWindPatterns)
            {
                WindConfigs = WindConfigs.Append(val);
            }

            var dictweatherEventConfigs    = api.Assets.GetMany <WeatherEventConfig[]>(api.World.Logger, "config/weatherevents/");
            var orderedweatherEventConfigs = dictweatherEventConfigs.OrderBy(val => val.Key.ToString()).Select(val => val.Value).ToArray();

            WeatherEventConfigs = new WeatherEventConfig[0];
            foreach (var val in orderedweatherEventConfigs)
            {
                WeatherEventConfigs = WeatherEventConfigs.Append(val);
            }

            api.World.Logger.Notification("Reloaded {0} weather patterns, {1} wind patterns and {2} weather events", WeatherConfigs.Length, WindConfigs.Length, WeatherEventConfigs.Length);

            WeatherPatternAssets p = new WeatherPatternAssets()
            {
                GeneralConfig       = GeneralConfig,
                WeatherConfigs      = WeatherConfigs,
                WindConfigs         = WindConfigs,
                WeatherEventConfigs = WeatherEventConfigs
            };

            packetForClient = new WeatherPatternAssetsPacket()
            {
                Data = JsonUtil.ToString(p)
            };
        }
Пример #2
0
        private void OnAssetsPacket(WeatherPatternAssetsPacket networkMessage)
        {
            WeatherPatternAssets p = JsonUtil.FromString <WeatherPatternAssets>(networkMessage.Data);

            this.GeneralConfig = p.GeneralConfig;
            this.GeneralConfig.Init(api.World);

            this.WeatherConfigs      = p.WeatherConfigs;
            this.WindConfigs         = p.WindConfigs;
            this.WeatherEventConfigs = p.WeatherEventConfigs;

            foreach (var val in weatherSimByMapRegion)
            {
                val.Value.ReloadPatterns(api.World.Seed);
            }
        }