summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/TuneRadioMinigame.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2020-12-30 20:59:04 +0800
committerchai <chaifix@163.com>2020-12-30 20:59:04 +0800
commite9ea621b93fbb58d9edfca8375918791637bbd52 (patch)
tree19ce3b1c1f2d51eda6878c9d0f2c9edc27f13650 /Client/Assembly-CSharp/TuneRadioMinigame.cs
+init
Diffstat (limited to 'Client/Assembly-CSharp/TuneRadioMinigame.cs')
-rw-r--r--Client/Assembly-CSharp/TuneRadioMinigame.cs104
1 files changed, 104 insertions, 0 deletions
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();
+ }
+}