private void ApplyWeatherState(RockWeatherState state) { Layer.Game.colorMul = state.multiply * Layer.Game.fade; Layer.Background.colorMul = state.multiply * Layer.Background.fade; this._board.fieldMulColor = state.multiply * Layer.Game.fade; Layer.Game.colorAdd = state.add * Layer.Game.fade; Layer.Background.colorAdd = state.add * Layer.Background.fade; this._board.fieldAddColor = state.add * Layer.Game.fade; Level.current.backgroundColor = new Color(state.sky.x, state.sky.y, state.sky.z) * Layer.Game.fade; RockWeather.lightOpacity = state.lightOpacity; RockWeather.sunPos = state.sunPos; RockWeather.sunGlow = state.sunGlow; RockWeather.sunOpacity = state.sunOpacity; this._lastAppliedState = state; }
public override void Update() { if (RockWeather.alwaysRainbow) { RockWeather.rainbowFade = 1f; RockWeather.rainbowTime = 1f; } RockWeather.rainbowFade = Lerp.Float(RockWeather.rainbowFade, (double)RockWeather.rainbowTime > 0.0 ? 1f : 0.0f, 1f / 1000f); RockWeather.rainbowTime -= Maths.IncFrameTimer(); if (RockWeather._weather != Weather.Sunny) { RockWeather.rainbowTime -= Maths.IncFrameTimer() * 8f; } if ((double)RockWeather.rainbowTime < 0.0) { RockWeather.rainbowTime = 0.0f; } if (RockWeather.neverRainbow) { RockWeather.rainbowFade = 0.0f; } RockWeatherState weatherState = this.GetWeatherState(RockWeather._timeOfDay); this.rainbowLight = weatherState.rainbowLight * RockWeather.rainbowFade; this.rainbowLight2 = weatherState.rainbowLight2 * RockWeather.rainbowFade; this.ApplyWeatherState(weatherState); RockWeather._prevWeatherLerp = Lerp.Float(RockWeather._prevWeatherLerp, 0.0f, 0.05f); if (Network.isServer) { this.wait += 3f / 1000f; if ((double)this.wait > 1.0) { this.wait = 0.0f; if ((double)RockWeather._weatherTime > 0.100000001490116) { if ((double)RockWeather.snowChance > 0.0 && RockWeather._weather != Weather.Snowing && (double)Rando.Float(1f) > 1.0 - (double)RockWeather.snowChance) { RockWeather._prevWeatherLerp = 1f; RockWeather.sunshowers = 0.0f; RockWeather._prevWeather = RockWeather._weather; RockWeather._weather = Weather.Snowing; if (Network.isActive) { Send.Message((NetMessage) new NMChangeWeather((byte)RockWeather._weather)); } RockWeather._weatherTime = 0.0f; } if ((double)RockWeather.rainChance > 0.0 && RockWeather._weather != Weather.Raining && (double)Rando.Float(1f) > 1.0 - (double)RockWeather.rainChance) { RockWeather._prevWeatherLerp = 1f; RockWeather.sunshowers = 0.0f; RockWeather._prevWeather = RockWeather._weather; RockWeather._weather = Weather.Raining; if (Network.isActive) { Send.Message((NetMessage) new NMChangeWeather((byte)RockWeather._weather)); } RockWeather._weatherTime = 0.0f; } if (RockWeather._weather != Weather.Sunny && (double)Rando.Float(1f) > 0.980000019073486) { RockWeather._prevWeatherLerp = 1f; if (RockWeather._weather == Weather.Raining) { if ((double)RockWeather._timeRaining > 900.0 && (double)Rando.Float(1f) > 0.850000023841858 || (double)Rando.Float(1f) > 0.949999988079071) { RockWeather.rainbowTime = Rando.Float(30f, 240f); } if ((double)Rando.Float(1f) > 0.300000011920929) { RockWeather.sunshowers = Rando.Float(0.1f, 60f); } } RockWeather._timeRaining = 0.0f; RockWeather._prevWeather = RockWeather._weather; RockWeather._weather = Weather.Sunny; if (Network.isActive) { Send.Message((NetMessage) new NMChangeWeather((byte)RockWeather._weather)); } RockWeather._weatherTime = 0.0f; } } } } RockWeather.sunshowers -= Maths.IncFrameTimer(); if ((double)RockWeather.sunshowers <= 0.0) { RockWeather.sunshowers = 0.0f; } switch (RockWeather._weather) { case Weather.Snowing: while ((double)this._particleWait <= 0.0) { ++this._particleWait; SnowParticle snowParticle = new SnowParticle(new Vec2(Rando.Float(-100f, 400f), Rando.Float(-500f, -550f))); snowParticle.z = Rando.Float(0.0f, 200f); this._particles.Add((WeatherParticle)snowParticle); } this._particleWait -= 0.5f; break; case Weather.Raining: while ((double)this._particleWait <= 0.0) { ++this._particleWait; RainParticle rainParticle = new RainParticle(new Vec2(Rando.Float(-100f, 900f), Rando.Float(-500f, -550f))); rainParticle.z = Rando.Float(0.0f, 200f); this._particles.Add((WeatherParticle)rainParticle); } --this._particleWait; break; default: if ((double)RockWeather.sunshowers <= 0.0) { break; } goto case Weather.Raining; } List <WeatherParticle> weatherParticleList = new List <WeatherParticle>(); foreach (WeatherParticle particle in this._particles) { particle.Update(); if ((double)particle.position.y > 0.0) { particle.die = true; } switch (particle) { case RainParticle _ when(double) particle.z <70.0 && (double)particle.position.y> -62.0: particle.die = true; particle.position.y = -58f; break; case RainParticle _ when(double) particle.z <40.0 && (double)particle.position.y> -98.0: particle.die = true; particle.position.y = -98f; break; case RainParticle _ when(double) particle.z < 25.0 && ((double)particle.position.x > 175.0 && (double)particle.position.x < 430.0) && ((double)particle.position.y > -362.0 && (double)particle.position.y < -352.0): particle.die = true; particle.position.y = -362f; break; } if ((double)particle.alpha < 0.00999999977648258) { weatherParticleList.Add(particle); } } foreach (WeatherParticle weatherParticle in weatherParticleList) { this._particles.Remove(weatherParticle); } }
private RockWeatherState GetWeatherState(float time, bool lerp = true) { RockWeatherState rockWeatherState1 = (RockWeatherState)null; RockWeatherState rockWeatherState2 = (RockWeatherState)null; float num1 = 0.0f; int index = 0; switch (RockWeather._weather) { case Weather.Sunny: num1 = 1f / (float)this.timeOfDayColorMultMap.Count; index = (int)((double)RockWeather._timeOfDay * (double)this.timeOfDayColorMultMap.Count); if (index >= this.timeOfDayColorMultMap.Count) { index = this.timeOfDayColorMultMap.Count - 1; } rockWeatherState1 = this.timeOfDayColorMultMap[index]; rockWeatherState2 = index + 1 <= this.timeOfDayColorMultMap.Count - 1 ? this.timeOfDayColorMultMap[index + 1] : this.timeOfDayColorMultMap[0]; break; case Weather.Snowing: num1 = 1f / (float)this.timeOfDayColorMultMapWinter.Count; index = (int)((double)RockWeather._timeOfDay * (double)this.timeOfDayColorMultMapWinter.Count); if (index >= this.timeOfDayColorMultMapWinter.Count) { index = this.timeOfDayColorMultMapWinter.Count - 1; } rockWeatherState1 = this.timeOfDayColorMultMapWinter[index]; rockWeatherState2 = index + 1 <= this.timeOfDayColorMultMapWinter.Count - 1 ? this.timeOfDayColorMultMapWinter[index + 1] : this.timeOfDayColorMultMapWinter[0]; break; case Weather.Raining: num1 = 1f / (float)this.timeOfDayColorMultMapRaining.Count; index = (int)((double)RockWeather._timeOfDay * (double)this.timeOfDayColorMultMapRaining.Count); if (index >= this.timeOfDayColorMultMapRaining.Count) { index = this.timeOfDayColorMultMapRaining.Count - 1; } rockWeatherState1 = this.timeOfDayColorMultMapRaining[index]; rockWeatherState2 = index + 1 <= this.timeOfDayColorMultMapRaining.Count - 1 ? this.timeOfDayColorMultMapRaining[index + 1] : this.timeOfDayColorMultMapRaining[0]; break; } float num2 = Maths.NormalizeSection(RockWeather._timeOfDay, num1 * (float)index, num1 * (float)(index + 1)); RockWeatherState rockWeatherState3 = new RockWeatherState(); if (this._lastAppliedState == null) { this._lastAppliedState = rockWeatherState1.Copy(); } if (lerp) { float amount = 1f / 1000f; rockWeatherState3.add = Lerp.Vec3(this._lastAppliedState.add, rockWeatherState1.add + (rockWeatherState2.add - rockWeatherState1.add) * num2, amount); rockWeatherState3.multiply = Lerp.Vec3(this._lastAppliedState.multiply, rockWeatherState1.multiply + (rockWeatherState2.multiply - rockWeatherState1.multiply) * num2, amount); rockWeatherState3.sky = Lerp.Vec3(this._lastAppliedState.sky, rockWeatherState1.sky + (rockWeatherState2.sky - rockWeatherState1.sky) * num2, amount); rockWeatherState3.lightOpacity = Lerp.Float(this._lastAppliedState.lightOpacity, rockWeatherState1.lightOpacity + (rockWeatherState2.lightOpacity - rockWeatherState1.lightOpacity) * num2, amount); rockWeatherState3.sunPos = Lerp.Vec2(this._lastAppliedState.sunPos, rockWeatherState1.sunPos + (rockWeatherState2.sunPos - rockWeatherState1.sunPos) * num2, amount); rockWeatherState3.sunGlow = Lerp.Float(this._lastAppliedState.sunGlow, rockWeatherState1.sunGlow + (rockWeatherState2.sunGlow - rockWeatherState1.sunGlow) * num2, amount); rockWeatherState3.sunOpacity = Lerp.Float(this._lastAppliedState.sunOpacity, rockWeatherState1.sunOpacity + (rockWeatherState2.sunOpacity - rockWeatherState1.sunOpacity) * num2, amount); rockWeatherState3.rainbowLight = Lerp.Float(this._lastAppliedState.rainbowLight, rockWeatherState1.rainbowLight + (rockWeatherState2.rainbowLight - rockWeatherState1.rainbowLight) * num2, amount); rockWeatherState3.rainbowLight2 = Lerp.Float(this._lastAppliedState.rainbowLight2, rockWeatherState1.rainbowLight2 + (rockWeatherState2.rainbowLight2 - rockWeatherState1.rainbowLight2) * num2, amount); } else { rockWeatherState3.add = rockWeatherState1.add + (rockWeatherState2.add - rockWeatherState1.add) * num2; rockWeatherState3.multiply = rockWeatherState1.multiply + (rockWeatherState2.multiply - rockWeatherState1.multiply) * num2; rockWeatherState3.sky = rockWeatherState1.sky + (rockWeatherState2.sky - rockWeatherState1.sky) * num2; rockWeatherState3.lightOpacity = rockWeatherState1.lightOpacity + (rockWeatherState2.lightOpacity - rockWeatherState1.lightOpacity) * num2; rockWeatherState3.sunPos = rockWeatherState1.sunPos + (rockWeatherState2.sunPos - rockWeatherState1.sunPos) * num2; rockWeatherState3.sunGlow = rockWeatherState1.sunGlow + (rockWeatherState2.sunGlow - rockWeatherState1.sunGlow) * num2; rockWeatherState3.sunOpacity = rockWeatherState1.sunOpacity + (rockWeatherState2.sunOpacity - rockWeatherState1.sunOpacity) * num2; rockWeatherState3.rainbowLight = rockWeatherState1.rainbowLight + (rockWeatherState2.rainbowLight - rockWeatherState1.rainbowLight) * num2; rockWeatherState3.rainbowLight2 = rockWeatherState1.rainbowLight2 + (rockWeatherState2.rainbowLight2 - rockWeatherState1.rainbowLight2) * num2; } this._lastAppliedState = rockWeatherState3; return(rockWeatherState3); }