From e9ea621b93fbb58d9edfca8375918791637bbd52 Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 30 Dec 2020 20:59:04 +0800 Subject: +init --- Client/Assembly-CSharp/TuneRadioMinigame.cs | 104 ++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 Client/Assembly-CSharp/TuneRadioMinigame.cs (limited to 'Client/Assembly-CSharp/TuneRadioMinigame.cs') diff --git a/Client/Assembly-CSharp/TuneRadioMinigame.cs b/Client/Assembly-CSharp/TuneRadioMinigame.cs new file mode 100644 index 0000000..ac2eb58 --- /dev/null +++ b/Client/Assembly-CSharp/TuneRadioMinigame.cs @@ -0,0 +1,104 @@ +using System; +using UnityEngine; + +public class TuneRadioMinigame : Minigame +{ + public RadioWaveBehaviour actualSignal; + + public DialBehaviour dial; + + public SpriteRenderer redLight; + + public SpriteRenderer greenLight; + + public float Tolerance = 0.1f; + + public float targetAngle; + + public bool finished; + + private float steadyTimer; + + public AudioClip StaticSound; + + public AudioClip RadioSound; + + public override void Begin(PlayerTask task) + { + base.Begin(task); + this.targetAngle = this.dial.DialRange.Next(); + if (Constants.ShouldPlaySfx()) + { + SoundManager.Instance.PlayDynamicSound("CommsRadio", this.RadioSound, true, new DynamicSound.GetDynamicsFunction(this.GetRadioVolume), true); + SoundManager.Instance.PlayDynamicSound("RadioStatic", this.StaticSound, true, new DynamicSound.GetDynamicsFunction(this.GetStaticVolume), true); + } + } + + private void GetRadioVolume(AudioSource player, float dt) + { + player.volume = 1f - this.actualSignal.NoiseLevel; + } + + private void GetStaticVolume(AudioSource player, float dt) + { + player.volume = this.actualSignal.NoiseLevel; + } + + public void Update() + { + if (this.finished) + { + return; + } + float f = Mathf.Abs((this.targetAngle - this.dial.Value) / this.dial.DialRange.Width) * 2f; + this.actualSignal.NoiseLevel = Mathf.Clamp(Mathf.Sqrt(f), 0f, 1f); + if (this.actualSignal.NoiseLevel <= this.Tolerance) + { + this.redLight.color = new Color(0.35f, 0f, 0f); + if (!this.dial.Engaged) + { + this.FinishGame(); + return; + } + this.steadyTimer += Time.deltaTime; + if (this.steadyTimer > 1.5f) + { + this.FinishGame(); + return; + } + } + else + { + this.redLight.color = new Color(1f, 0f, 0f); + this.steadyTimer = 0f; + } + } + + private void FinishGame() + { + this.greenLight.color = Color.green; + this.finished = true; + this.dial.enabled = false; + this.dial.SetValue(this.targetAngle); + this.actualSignal.NoiseLevel = 0f; + if (PlayerControl.LocalPlayer) + { + ShipStatus.Instance.RpcRepairSystem(SystemTypes.Comms, 0); + } + base.StartCoroutine(base.CoStartClose(0.75f)); + try + { + ((SabotageTask)this.MyTask).MarkContributed(); + } + catch + { + } + } + + public override void Close() + { + SoundManager.Instance.StopSound(this.StaticSound); + SoundManager.Instance.StopSound(this.RadioSound); + base.Close(); + } +} -- cgit v1.1-26-g67d0