public override void Draw(GameTime gameTime) { if (this.GameState.Loading) { return; } TimeSpan elapsedGameTime = gameTime.ElapsedGameTime; if (!this.GameState.Paused && FezMath.IsOrthographic(this.CameraManager.Viewpoint) && (this.CameraManager.ActionRunning && !this.GameState.InMap)) { this.flashIn -= elapsedGameTime; this.distantIn -= elapsedGameTime; } if (!this.doThunder) { return; } if (this.distantIn.Ticks <= 0L) { this.distantIn = TimeSpan.FromSeconds((double)RandomHelper.Between(3.0, 6.0)); SoundEffectExtensions.EmitAt(RandomHelper.InList <SoundEffect>(this.thunderDistant), this.CameraManager.Center + this.LevelManager.Size / 2f * FezMath.ForwardVector(this.CameraManager.Viewpoint) + (float)((double)RandomHelper.Centered(1.0) * (double)this.CameraManager.Radius * 0.5) * FezMath.RightVector(this.CameraManager.Viewpoint) + this.CameraManager.Center * Vector3.UnitY, RandomHelper.Centered(0.0500000007450581), RandomHelper.Between(0.75, 1.0)).NoAttenuation = true; } if (this.flashIn.Ticks <= 0L) { this.flashes = RandomHelper.Random.Next(1, 3); this.sinceFlash = TimeSpan.FromSeconds(-0.200000002980232); this.flashSpeed = RandomHelper.Between(1.5, 3.5); this.flashOpacity = RandomHelper.Between(0.2, 0.4); this.flashIn = TimeSpan.FromSeconds((double)RandomHelper.Between(4.0, 6.0)); this.lightning.Rotation = this.CameraManager.Rotation; this.lightningSideOffset = RandomHelper.Centered(1.0); this.lightning.Position = this.CameraManager.Center + this.LevelManager.Size / 2f * FezMath.ForwardVector(this.CameraManager.Viewpoint) + (float)((double)this.lightningSideOffset * (double)this.CameraManager.Radius * 0.5) * FezMath.RightVector(this.CameraManager.Viewpoint) + RandomHelper.Centered(10.0) * Vector3.UnitY; if (this.ePreThunder != null) { this.ePreThunder.Cue.Stop(false); this.ePreThunder = (SoundEmitter)null; } (this.ePreThunder = SoundEffectExtensions.EmitAt(this.sPreThunder, this.lightning.Position * FezMath.XZMask + this.CameraManager.Center * Vector3.UnitY, RandomHelper.Centered(0.025000000372529))).NoAttenuation = true; } if (this.sinceFlash.TotalSeconds < 0.200000002980232) { float alpha = Easing.EaseOut((double)FezMath.Saturate(1f - (float)(this.sinceFlash.TotalSeconds / 0.200000002980232)), EasingType.Quadratic) * this.flashOpacity; GraphicsDeviceExtensions.SetBlendingMode(this.GraphicsDevice, BlendingMode.Alphablending); GraphicsDeviceExtensions.PrepareStencilRead(this.GraphicsDevice, CompareFunction.Equal, StencilMask.Sky); this.ImmediateRenderer.DrawFullscreen(new Color(1f, 1f, 1f, alpha)); GraphicsDeviceExtensions.PrepareStencilRead(this.GraphicsDevice, CompareFunction.Equal, StencilMask.Trails); this.ImmediateRenderer.DrawFullscreen(new Color(1f, 1f, 1f, alpha)); GraphicsDeviceExtensions.PrepareStencilRead(this.GraphicsDevice, CompareFunction.Equal, StencilMask.SkyLayer1); this.ImmediateRenderer.DrawFullscreen(new Color(0.9f, 0.9f, 0.9f, alpha)); GraphicsDeviceExtensions.PrepareStencilRead(this.GraphicsDevice, CompareFunction.Equal, StencilMask.SkyLayer2); this.ImmediateRenderer.DrawFullscreen(new Color(0.8f, 0.8f, 0.8f, alpha)); GraphicsDeviceExtensions.PrepareStencilRead(this.GraphicsDevice, CompareFunction.Equal, StencilMask.SkyLayer3); this.ImmediateRenderer.DrawFullscreen(new Color(0.7f, 0.7f, 0.7f, alpha)); GraphicsDeviceExtensions.PrepareStencilRead(this.GraphicsDevice, CompareFunction.Less, StencilMask.SkyLayer3); this.ImmediateRenderer.DrawFullscreen(new Color(0.0f, 0.0f, 0.0f, alpha)); this.sinceFlash += TimeSpan.FromTicks((long)((double)elapsedGameTime.Ticks * (double)this.flashSpeed)); if (this.flashes == 1 && (double)alpha / (double)this.flashOpacity < 0.5) { this.lightning.Material.Opacity = 1f; GraphicsDeviceExtensions.PrepareStencilRead(this.GraphicsDevice, CompareFunction.NotEqual, StencilMask.SkyLayer3); this.lightning.Draw(); } else if (this.flashes == 0 && this.sinceFlash.Ticks < 0L) { this.lightning.Material.Opacity = (float)(this.sinceFlash.TotalSeconds / -0.200000002980232); GraphicsDeviceExtensions.PrepareStencilRead(this.GraphicsDevice, CompareFunction.NotEqual, StencilMask.SkyLayer3); this.lightning.Draw(); } GraphicsDeviceExtensions.PrepareStencilWrite(this.GraphicsDevice, new StencilMask?(StencilMask.None)); } if (this.sinceFlash.TotalSeconds <= 0.200000002980232 || this.flashes == 0) { return; } --this.flashes; this.sinceFlash = TimeSpan.FromSeconds(-0.200000002980232); this.flashSpeed = this.flashes == 0 ? 1f : RandomHelper.Between(2.0, 4.0); this.flashOpacity = this.flashes == 0 ? 1f : RandomHelper.Between(0.2, 0.4); if (this.flashes != 0) { return; } if (this.ePreThunder != null && !this.ePreThunder.Dead) { this.ePreThunder.Cue.Stop(false); } this.ePreThunder = (SoundEmitter)null; SoundEmitter emitter = SoundEffectExtensions.EmitAt(RandomHelper.InList <SoundEffect>(this.lightningSounds), this.lightning.Position * FezMath.XZMask + this.CameraManager.Center * Vector3.UnitY, RandomHelper.Centered(0.025000000372529)); emitter.NoAttenuation = true; emitter.Persistent = true; Waiters.DoUntil((Func <bool>)(() => emitter.Dead), (Action <float>)(_ => emitter.Position = Vector3.Lerp(emitter.Position, this.CameraManager.Center, 0.025f))).AutoPause = true; }