public WeatherSimulationLightning(ICoreAPI api, WeatherSystemBase weatherSys) { this.weatherSys = weatherSys; weatherSysc = weatherSys as WeatherSystemClient; this.capi = api as ICoreClientAPI; if (api.Side == EnumAppSide.Client) { LightningAmbient = new AmbientModifier().EnsurePopulated(); capi.Ambient.CurrentModifiers["lightningambient"] = LightningAmbient; capi.Event.ReloadShader += LoadShader; LoadShader(); capi.Event.RegisterRenderer(this, EnumRenderStage.Opaque, "lightning"); capi.RegisterCommand("lntest", "", "", onCmdLineTest); } else { api.Event.RegisterGameTickListener(OnServerTick, 40, 3); (api as ICoreServerAPI).RegisterCommand("lntest", "", "", onCmdLineTestServer); } }
public WeatherSimulationLightning(ICoreClientAPI capi, WeatherSystemClient weatherSys) { this.weatherSys = weatherSys; this.capi = capi; LightningAmbient = new AmbientModifier().EnsurePopulated(); capi.Ambient.CurrentModifiers["lightningambient"] = LightningAmbient; }
void ResetRainFog() { if (capi != null) { capi.Ambient.CurrentModifiers["brownrainandfog"] = rainfogAmbient = new AmbientModifier() { AmbientColor = new WeightedFloatArray(new float[] { 132 / 255f, 115 / 255f, 112f / 255f, 1 }, 0), FogColor = new WeightedFloatArray(new float[] { 132 / 255f, 115 / 255f, 112f / 255f, 1 }, 0), FogDensity = new WeightedFloat(0.035f, 0), }.EnsurePopulated(); } secondsPassedRainFogMode = 0; }
public WeatherSimulationParticles(ICoreClientAPI capi, WeatherSystemClient ws) { this.capi = capi; this.ws = ws; rand = new Random(capi.World.Seed + 223123123); rainParticleColor = waterColor; desertStormAmbient = new AmbientModifier().EnsurePopulated(); desertStormAmbient.FogDensity = new WeightedFloat(); desertStormAmbient.FogColor = new WeightedFloatArray() { Value = new float[3] }; desertStormAmbient.FogMin = new WeightedFloat(); capi.Ambient.CurrentModifiers["desertstorm"] = desertStormAmbient; }
void SendGlobalAmbient(bool enable = true) { AmbientModifier amb = capi.Ambient.CurrentModifiers["serverambient"]; float newWeight = enable ? 1 : 0; amb.AmbientColor.Weight = 0; amb.FogColor.Weight = newWeight; amb.FogDensity.Weight = newWeight; amb.FogMin.Weight = newWeight; amb.FlatFogDensity.Weight = newWeight; amb.FlatFogYPos.Weight = newWeight; amb.CloudBrightness.Weight = newWeight; amb.CloudDensity.Weight = newWeight; amb.CloudYPos.Weight = newWeight; string jsoncode = JsonConvert.SerializeObject(amb); capi.SendChatMessage("/setambient " + jsoncode); if (!beforeAmbientOverride) { settingsDialog.ReloadValues(); } if (!enable && beforeAmbientOverride) { capi.SendChatMessage("/weather setprecip auto"); } if (enable && !beforeAmbientOverride) { capi.SendChatMessage("/weather acp 0"); } if (!enable && beforeAmbientOverride) { capi.SendChatMessage("/weather acp 1"); } beforeAmbientOverride = enable; }
private string OnGetValueSettings(string elementCode) { AmbientModifier amb = capi.Ambient.CurrentModifiers["serverambient"]; switch (elementCode) { case "timeofday": return("" + (int)(capi.World.Calendar.FullHourOfDay / capi.World.Calendar.HoursPerDay * 24)); case "foglevel": return("" + (int)(amb.FogDensity.Value * 2000)); case "flatfoglevel": return("" + (int)(amb.FlatFogDensity.Value * 250)); case "flatfoglevelypos": return("" + (int)(amb.FlatFogYPos.Value)); case "fogred": return("" + (int)(amb.FogColor.Value[0] * 255)); case "foggreen": return("" + (int)(amb.FogColor.Value[1] * 255)); case "fogblue": return("" + (int)(amb.FogColor.Value[2] * 255)); case "cloudlevel": return("" + (int)(amb.CloudDensity.Value * 100)); case "cloudypos": return("" + (int)(1 * 255)); case "cloudbrightness": return("" + (int)(amb.CloudBrightness.Value * 100)); case "movespeed": return("" + capi.World.Player.WorldData.MoveSpeedMultiplier); case "axislock": return("" + (int)capi.World.Player.WorldData.FreeMovePlaneLock); case "pickingrange": return("" + (float)capi.World.Player.WorldData.PickingRange); case "liquidselectable": return(capi.World.ForceLiquidSelectable ? "1" : "0"); case "serveroverloadprotection": if (ownWorkspace == null) { return("1"); } return(ownWorkspace.serverOverloadProtection ? "1" : "0"); case "ambientparticles": return(capi.World.AmbientParticles ? "1" : "0"); case "flymode": bool fly = capi.World.Player.WorldData.FreeMove; bool noclip = capi.World.Player.WorldData.NoClip; if (fly && !noclip) { return("1"); } if (fly && noclip) { return("2"); } return("0"); case "overrideambient": return(amb.FogColor.Weight >= 0.99f ? "1" : "0"); case "tooloffsetmode": if (ownWorkspace == null) { return("0"); } return(((int)ownWorkspace.ToolOffsetMode) + ""); } return(""); }
private void OnSetValueSettings(string elementCode, string newValue) { AmbientModifier amb = capi.Ambient.CurrentModifiers["serverambient"]; // no longer used amb.CloudBrightness.Weight = 0; amb.CloudDensity.Weight = 0; switch (elementCode) { case "timeofday": float time = newValue.ToFloat(0); time = time / 24 * capi.World.Calendar.HoursPerDay; capi.SendChatMessage("/time set " + time + ":00"); break; case "foglevel": amb.FogDensity.Weight = 1; amb.FogDensity.Value = newValue.ToFloat(0) / 2000f; SendGlobalAmbient(); break; case "flatfoglevel": amb.FlatFogDensity.Weight = 1; amb.FlatFogDensity.Value = newValue.ToFloat() / 250f; SendGlobalAmbient(); break; case "flatfoglevelypos": amb.FlatFogYPos.Weight = 1; amb.FlatFogYPos.Value = newValue.ToFloat(); SendGlobalAmbient(); break; case "fogred": case "foggreen": case "fogblue": float[] color = amb.FogColor.Value; if (elementCode == "fogred") { color[0] = newValue.ToInt() / 255f; } if (elementCode == "foggreen") { color[1] = newValue.ToInt() / 255f; } if (elementCode == "fogblue") { color[2] = newValue.ToInt() / 255f; } amb.FogColor.Weight = 1; SendGlobalAmbient(); break; case "precipitation": capi.SendChatMessage("/weather setprecip " + newValue.ToFloat() / 100f); SendGlobalAmbient(); break; case "cloudypos": capi.SendChatMessage("/weather cloudypos " + newValue.ToFloat() / 255f); break; case "weatherpattern": capi.SendChatMessage("/weather seti " + newValue); break; case "movespeed": capi.World.Player.WorldData.MoveSpeedMultiplier = newValue.ToFloat(); break; case "axislock": capi.World.Player.WorldData.FreeMovePlaneLock = (EnumFreeMovAxisLock)newValue.ToInt(); clientChannel.SendPacket(new ChangePlayerModePacket() { axisLock = capi.World.Player.WorldData.FreeMovePlaneLock }); break; case "pickingrange": capi.World.Player.WorldData.PickingRange = newValue.ToFloat(); clientChannel.SendPacket(new ChangePlayerModePacket() { pickingRange = capi.World.Player.WorldData.PickingRange }); break; case "liquidselectable": capi.World.ForceLiquidSelectable = newValue == "1" || newValue == "true"; break; case "serveroverloadprotection": capi.SendChatMessage("/we sovp " + newValue); break; case "tooloffsetmode": int num; int.TryParse(newValue, out num); ownWorkspace.ToolOffsetMode = (EnumToolOffsetMode)num; capi.SendChatMessage("/we tom " + num); break; case "ambientparticles": capi.World.AmbientParticles = newValue == "1" || newValue == "true"; break; case "flymode": bool fly = newValue == "1" || newValue == "2"; bool noclip = newValue == "2"; capi.World.Player.WorldData.FreeMove = fly; capi.World.Player.WorldData.NoClip = noclip; clientChannel.SendPacket(new ChangePlayerModePacket() { fly = fly, noclip = noclip }); break; case "overrideambient": bool on = (newValue == "1" || newValue == "true"); SendGlobalAmbient(on); break; } }
public void OnRenderFrame(float dt, EnumRenderStage stage) { if (stage == EnumRenderStage.Done) { AmbientModifier sunGlowAmb = capi.Ambient.CurrentModifiers["sunglow"]; actualSunGlowAmb.FogColor.Weight = sunGlowAmb.FogColor.Weight; //actualSunGlowAmb.AmbientColor.Weight = sunGlowAmb.AmbientColor.Weight; dt = Math.Min(0.5f, dt); if (nearLightningCoolDown > 0) { nearLightningCoolDown -= dt; } return; } if (lightningTime > 0) { float mul = Math.Min(10 * lightningIntensity * lightningTime, 1.5f); WeatherDataSnapshot weatherData = weatherSys.BlendedWeatherData; LightningAmbient.CloudBrightness.Value = Math.Max(weatherData.Ambient.SceneBrightness.Value, mul); LightningAmbient.FogBrightness.Value = Math.Max(weatherData.Ambient.FogBrightness.Value, mul); LightningAmbient.CloudBrightness.Weight = Math.Min(1, mul); LightningAmbient.FogBrightness.Weight = Math.Min(1, mul); float sceneBrightIncrease = GameMath.Min(mul, GameMath.Max(0, lightningIntensity - 0.75f)); if (sceneBrightIncrease > 0) { LightningAmbient.SceneBrightness.Weight = Math.Min(1, sceneBrightIncrease); LightningAmbient.SceneBrightness.Value = 1; AmbientModifier sunGlowAmb = capi.Ambient.CurrentModifiers["sunglow"]; float nowWeight = GameMath.Clamp(1 - sceneBrightIncrease, 0, 1); sunGlowAmb.FogColor.Weight = Math.Min(sunGlowAmb.FogColor.Weight, nowWeight); sunGlowAmb.AmbientColor.Weight = Math.Min(sunGlowAmb.AmbientColor.Weight, nowWeight); } lightningTime -= dt / 1.7f; if (lightningTime <= 0) { // Restore previous values AmbientModifier sunGlowAmb = capi.Ambient.CurrentModifiers["sunglow"]; sunGlowAmb.FogColor.Weight = actualSunGlowAmb.FogColor.Weight; sunGlowAmb.AmbientColor.Weight = actualSunGlowAmb.AmbientColor.Weight; LightningAmbient.CloudBrightness.Weight = 0; LightningAmbient.FogBrightness.Weight = 0; LightningAmbient.SceneBrightness.Weight = 0; } } }
public WeatherSimulation(WeatherSystem ws) { this.ws = ws; rand = new Random(ws.api.World.Seed); BlendedAmbient = new AmbientModifier().EnsurePopulated(); if (ws.api.Side == EnumAppSide.Client) { ws.capi.Ambient.CurrentModifiers.InsertBefore("serverambient", "weather", BlendedAmbient); } WeatherPattern ClearSky = new WeatherPatternClearSky(ws, "ClearSky", 1); ClearSky.Ambient.FogDensity = new WeightedFloat(2 / 2000f, 1); WeatherPattern CumulusClouds = new WeatherPattern(ws, "Cumulus Clouds", 1) { CloudDensityNoise = new SimplexNoise(new double[] { 4 }, new double[] { 1.5 }, rand.Next()), CloudDensityOffsetNoise = new SimplexNoise(new double[] { 4 }, new double[] { 1.5 }, rand.Next()), CloudOffsetYNoise = new SimplexNoise(new double[] { 2 }, new double[] { 1.5 }, rand.Next()) }; WeatherPattern StratusClouds = CumulusClouds.Clone(); StratusClouds.Name = "Stratus Clouds"; StratusClouds.Ambient.FlatFogYPos = new WeightedFloat(25, 1); StratusClouds.Ambient.FlatFogDensity = new WeightedFloat(6 / 250f, 1); StratusClouds.Ambient.FogDensity = new WeightedFloat(10 / 2000f, 1); StratusClouds.Chance = 0.35f; WeatherPattern CumulusCloudsWithFlatMist = CumulusClouds.Clone(); CumulusCloudsWithFlatMist.Name = "Cumulus Clouds + Flat dense Mist"; CumulusCloudsWithFlatMist.Ambient.FlatFogYPos = new WeightedFloat(5, 1); CumulusCloudsWithFlatMist.Ambient.FlatFogDensity = new WeightedFloat(-100 / 250f, 1); CumulusCloudsWithFlatMist.BeginUse += () => { CumulusCloudsWithFlatMist.Ambient.FlatFogDensity.Value = (-50 - 100 * (float)(rand.NextDouble() * rand.NextDouble())) / 300f; CumulusCloudsWithFlatMist.Ambient.FlatFogYPos.Value = 1 + 7 * (float)rand.NextDouble(); }; CumulusCloudsWithFlatMist.ChanceOfWeatherChange = 0.008f; CumulusCloudsWithFlatMist.Chance = 0.1f; WeatherPattern CumulusCloudsWithTallMist = CumulusClouds.Clone(); CumulusCloudsWithTallMist.Name = "Cumulus Clouds + Tall dense Mist"; CumulusCloudsWithTallMist.Ambient.FlatFogYPos = new WeightedFloat(40, 1); CumulusCloudsWithTallMist.Ambient.FlatFogDensity = new WeightedFloat(-30 / 250f, 1); CumulusCloudsWithTallMist.BeginUse += () => { CumulusCloudsWithTallMist.Ambient.FlatFogDensity.Value = (-50 - 50 * (float)(rand.NextDouble() * rand.NextDouble())) / 2000f; CumulusCloudsWithTallMist.Ambient.FlatFogYPos.Value = 30 + 30 * (float)rand.NextDouble(); }; CumulusCloudsWithTallMist.ChanceOfWeatherChange = 0.008f; CumulusCloudsWithTallMist.Chance = 0.05f; WeatherPattern CumulusCloudsWithFog = CumulusClouds.Clone(); CumulusCloudsWithFog.Name = "Cumulus Clouds + Fog"; CumulusCloudsWithFog.Ambient.FogDensity = new WeightedFloat(40 / 2000f, 1); CumulusCloudsWithFog.BeginUse += () => { CumulusCloudsWithFog.Ambient.FogDensity.Value = (10 + 30 * (float)rand.NextDouble()) / 2000f; }; CumulusCloudsWithFog.Chance = 0.35f; WeatherPattern NimboStratusClouds = new WeatherPattern(ws, "Nimbostratus Clouds", 1) { CloudDensityNoise = new SimplexNoise(new double[] { 4 }, new double[] { 1.5 }, rand.Next()), CloudDensityOffsetNoise = new SimplexNoise(new double[] { 4 }, new double[] { 1.5 }, rand.Next()), CloudOffsetYNoise = new SimplexNoise(new double[] { 2 }, new double[] { 1.5 }, rand.Next()) }; WeatherPattern AltoCumulusClouds = new WeatherPattern(ws, "Altocumulus Clouds", 1) { CloudDensityNoise = new SimplexNoise(new double[] { 3 }, new double[] { 10 }, rand.Next()), CloudDensityOffsetNoise = new SimplexNoise(new double[] { 4 }, new double[] { 1.5 }, rand.Next()), CloudOffsetYNoise = new SimplexNoise(new double[] { 1 }, new double[] { 1.5 }, rand.Next()) }; WeatherPattern CirroCumulusClouds = new WeatherPattern(ws, "Cirrocumulus Clouds", 1) { CloudDensityNoise = new SimplexNoise(new double[] { 3 }, new double[] { 10 }, rand.Next()), CloudDensityOffsetNoise = new SimplexNoise(new double[] { 4 }, new double[] { 1.5 }, rand.Next()), CloudOffsetYNoise = new SimplexNoise(new double[] { 1 }, new double[] { 1.5 }, rand.Next()) }; CirroCumulusClouds.CloudYOffset = 100; Patterns = new WeatherPattern[] { ClearSky, CumulusClouds, CumulusCloudsWithFlatMist, CumulusCloudsWithTallMist, CumulusCloudsWithFog, StratusClouds, NimboStratusClouds, AltoCumulusClouds, CirroCumulusClouds }; }
void initSoundsAndEffects() { capi = entity.Api as ICoreClientAPI; isSelf = capi.World.Player.Entity.EntityId == entity.EntityId; if (!isSelf) { return; } // Effects fogNoise = NormalizedSimplexNoise.FromDefaultOctaves(4, 1, 0.9, 123); rustParticles = new SimpleParticleProperties() { Color = ColorUtil.ToRgba(150, 50, 25, 15), ParticleModel = EnumParticleModel.Quad, MinSize = 0.1f, MaxSize = 0.5f, GravityEffect = 0, LifeLength = 2f, WithTerrainCollision = false, ShouldDieInLiquid = false, RandomVelocityChange = true, MinVelocity = new Vec3f(-1f, -1f, -1f), AddVelocity = new Vec3f(2f, 2f, 2f), MinQuantity = 1, AddQuantity = 0, }; rustParticles.AddVelocity = new Vec3f(0f, 30f, 0); rustParticles.OpacityEvolve = EvolvingNatFloat.create(EnumTransformFunction.QUADRATIC, -8); float b = 0.25f; capi.Ambient.CurrentModifiers["brownrainandfog"] = rainfogAmbient = new AmbientModifier() { AmbientColor = new WeightedFloatArray(new float[] { 0.5f * 132 / 255f, 0.5f * 115 / 255f, 0.5f * 112f / 255f, 1 }, 0), FogColor = new WeightedFloatArray(new float[] { b * 132 / 255f, b * 115 / 255f, b * 112f / 255f, 1 }, 0), FogDensity = new WeightedFloat(0.05f, 0), }.EnsurePopulated(); // Sounds tempStabSoundDrain = capi.World.LoadSound(new SoundParams() { Location = new AssetLocation("sounds/effect/tempstab-drain.ogg"), ShouldLoop = true, RelativePosition = true, DisposeOnFinish = false, SoundType = EnumSoundType.SoundGlitchunaffected, Volume = 0f }); tempStabSoundLow = capi.World.LoadSound(new SoundParams() { Location = new AssetLocation("sounds/effect/tempstab-low.ogg"), ShouldLoop = true, RelativePosition = true, DisposeOnFinish = false, SoundType = EnumSoundType.SoundGlitchunaffected, Volume = 0f }); tempStabSoundVeryLow = capi.World.LoadSound(new SoundParams() { Location = new AssetLocation("sounds/effect/tempstab-verylow.ogg"), ShouldLoop = true, RelativePosition = true, DisposeOnFinish = false, SoundType = EnumSoundType.SoundGlitchunaffected, Volume = 0f }); }
public void OnRenderFrame(float dt, EnumRenderStage stage) { if (stage == EnumRenderStage.Opaque) { prog.Use(); prog.UniformMatrix("projection", capi.Render.CurrentProjectionMatrix); prog.UniformMatrix("view", capi.Render.CameraMatrixOriginf); for (int i = 0; i < lightningFlashes.Count; i++) { var lflash = lightningFlashes[i]; lflash.Render(dt); if (!lflash.Alive) { lflash.Dispose(); lightningFlashes.RemoveAt(i); i--; } } prog.Stop(); return; } if (stage == EnumRenderStage.Done) { AmbientModifier sunGlowAmb = capi.Ambient.CurrentModifiers["sunglow"]; actualSunGlowAmb.FogColor.Weight = sunGlowAmb.FogColor.Weight; dt = Math.Min(0.5f, dt); if (nearLightningCoolDown > 0) { nearLightningCoolDown -= dt; } return; } if (lightningTime > 0) { float mul = Math.Min(10 * lightningIntensity * lightningTime, 1.5f); WeatherDataSnapshot weatherData = weatherSysc.BlendedWeatherData; LightningAmbient.CloudBrightness.Value = Math.Max(weatherData.Ambient.SceneBrightness.Value, mul); LightningAmbient.FogBrightness.Value = Math.Max(weatherData.Ambient.FogBrightness.Value, mul); LightningAmbient.CloudBrightness.Weight = Math.Min(1, mul); LightningAmbient.FogBrightness.Weight = Math.Min(1, mul); float sceneBrightIncrease = GameMath.Min(mul, GameMath.Max(0, lightningIntensity - 0.75f)); if (sceneBrightIncrease > 0) { LightningAmbient.SceneBrightness.Weight = Math.Min(1, sceneBrightIncrease); LightningAmbient.SceneBrightness.Value = 1; AmbientModifier sunGlowAmb = capi.Ambient.CurrentModifiers["sunglow"]; float nowWeight = GameMath.Clamp(1 - sceneBrightIncrease, 0, 1); sunGlowAmb.FogColor.Weight = Math.Min(sunGlowAmb.FogColor.Weight, nowWeight); sunGlowAmb.AmbientColor.Weight = Math.Min(sunGlowAmb.AmbientColor.Weight, nowWeight); } lightningTime -= dt / 1.7f; if (lightningTime <= 0) { // Restore previous values AmbientModifier sunGlowAmb = capi.Ambient.CurrentModifiers["sunglow"]; sunGlowAmb.FogColor.Weight = actualSunGlowAmb.FogColor.Weight; sunGlowAmb.AmbientColor.Weight = actualSunGlowAmb.AmbientColor.Weight; LightningAmbient.CloudBrightness.Weight = 0; LightningAmbient.FogBrightness.Weight = 0; LightningAmbient.SceneBrightness.Weight = 0; } } }