summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/SampleMinigame.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Client/Assembly-CSharp/SampleMinigame.cs')
-rw-r--r--Client/Assembly-CSharp/SampleMinigame.cs382
1 files changed, 382 insertions, 0 deletions
diff --git a/Client/Assembly-CSharp/SampleMinigame.cs b/Client/Assembly-CSharp/SampleMinigame.cs
new file mode 100644
index 0000000..fd60a67
--- /dev/null
+++ b/Client/Assembly-CSharp/SampleMinigame.cs
@@ -0,0 +1,382 @@
+using System;
+using System.Collections;
+using UnityEngine;
+
+public class SampleMinigame : Minigame
+{
+ private SampleMinigame.States State
+ {
+ get
+ {
+ return (SampleMinigame.States)this.MyNormTask.Data[0];
+ }
+ set
+ {
+ this.MyNormTask.Data[0] = (byte)value;
+ }
+ }
+
+ private int AnomalyId
+ {
+ get
+ {
+ return (int)this.MyNormTask.Data[1];
+ }
+ set
+ {
+ this.MyNormTask.Data[1] = (byte)value;
+ }
+ }
+
+ private static string[] ProcessingStrings = new string[]
+ {
+ "Take a break",
+ "Go grab a coffee",
+ "You dont need to wait",
+ "go do something else"
+ };
+
+ private const float PanelMoveDuration = 0.75f;
+
+ private const byte TubeMask = 15;
+
+ public TextRenderer UpperText;
+
+ public TextRenderer LowerText;
+
+ public float TimePerStep = 15f;
+
+ public FloatRange platformY = new FloatRange(-3.5f, -0.75f);
+
+ public FloatRange dropperX = new FloatRange(-1.25f, 1.25f);
+
+ public SpriteRenderer CenterPanel;
+
+ public SpriteRenderer Dropper;
+
+ public SpriteRenderer[] Tubes;
+
+ public SpriteRenderer[] Buttons;
+
+ public SpriteRenderer LowerButton;
+
+ public AudioClip ButtonSound;
+
+ public AudioClip PanelMoveSound;
+
+ public AudioClip FailSound;
+
+ public AudioClip[] DropSounds;
+
+ private RandomFill<AudioClip> dropSounds;
+
+ public enum States : byte
+ {
+ PrepareSample,
+ Complete = 16,
+ AwaitingStart = 32,
+ Selection = 64,
+ Processing = 128
+ }
+
+ public void Awake()
+ {
+ this.dropSounds = new RandomFill<AudioClip>();
+ this.dropSounds.Set(this.DropSounds);
+ }
+
+ public override void Begin(PlayerTask task)
+ {
+ base.Begin(task);
+ SampleMinigame.States state = this.State;
+ if (state <= SampleMinigame.States.AwaitingStart)
+ {
+ if (state != SampleMinigame.States.PrepareSample)
+ {
+ if (state != SampleMinigame.States.AwaitingStart)
+ {
+ return;
+ }
+ this.LowerText.Text = "Press To Begin -->";
+ this.SetPlatformTop();
+ return;
+ }
+ else
+ {
+ base.StartCoroutine(this.BringPanelUp(true));
+ }
+ }
+ else
+ {
+ if (state == SampleMinigame.States.Selection)
+ {
+ for (int i = 0; i < this.Tubes.Length; i++)
+ {
+ this.Tubes[i].color = Color.blue;
+ }
+ this.Tubes[this.AnomalyId].color = Color.red;
+ this.LowerText.Text = "Select Anomaly";
+ this.SetPlatformTop();
+ return;
+ }
+ if (state == SampleMinigame.States.Processing)
+ {
+ for (int j = 0; j < this.Tubes.Length; j++)
+ {
+ this.Tubes[j].color = Color.blue;
+ }
+ this.LowerText.Text = SampleMinigame.ProcessingStrings.Random<string>();
+ this.SetPlatformBottom();
+ return;
+ }
+ }
+ }
+
+ private void SetPlatformBottom()
+ {
+ Vector3 localPosition = this.CenterPanel.transform.localPosition;
+ localPosition.y = this.platformY.min;
+ this.CenterPanel.transform.localPosition = localPosition;
+ }
+
+ private void SetPlatformTop()
+ {
+ Vector3 localPosition = this.CenterPanel.transform.localPosition;
+ localPosition.y = this.platformY.max;
+ this.CenterPanel.transform.localPosition = localPosition;
+ }
+
+ public void FixedUpdate()
+ {
+ if (this.State == SampleMinigame.States.Processing)
+ {
+ if (this.MyNormTask.TaskTimer <= 0f)
+ {
+ this.State = SampleMinigame.States.Selection;
+ this.LowerText.Text = "Select Anomaly";
+ this.UpperText.Text = "";
+ this.AnomalyId = this.Tubes.RandomIdx<SpriteRenderer>();
+ this.Tubes[this.AnomalyId].color = Color.red;
+ this.LowerButton.color = Color.white;
+ base.StartCoroutine(this.BringPanelUp(false));
+ return;
+ }
+ this.UpperText.Text = "ETA: " + (int)this.MyNormTask.TaskTimer;
+ return;
+ }
+ else
+ {
+ if (this.State == SampleMinigame.States.Selection)
+ {
+ float num = Mathf.Cos(Time.time * 1.5f) - 0.2f;
+ Color color = new Color(num, 1f, num, 1f);
+ for (int i = 0; i < this.Buttons.Length; i++)
+ {
+ this.Buttons[i].color = color;
+ }
+ return;
+ }
+ if (this.State == SampleMinigame.States.AwaitingStart)
+ {
+ float num2 = Mathf.Cos(Time.time * 1.5f) - 0.2f;
+ Color color2 = new Color(num2, 1f, num2, 1f);
+ this.LowerButton.color = color2;
+ }
+ return;
+ }
+ }
+
+ public IEnumerator BringPanelUp(bool isBeginning)
+ {
+ if (Constants.ShouldPlaySfx())
+ {
+ SoundManager.Instance.PlaySound(this.PanelMoveSound, false, 1f);
+ }
+ WaitForFixedUpdate wait = new WaitForFixedUpdate();
+ Vector3 pos = this.CenterPanel.transform.localPosition;
+ for (float i = 0f; i < 0.75f; i += Time.deltaTime)
+ {
+ pos.y = this.platformY.Lerp(i / 0.75f);
+ this.CenterPanel.transform.localPosition = pos;
+ yield return wait;
+ }
+ if (isBeginning)
+ {
+ this.State = SampleMinigame.States.AwaitingStart;
+ this.LowerText.Text = "Press To Begin -->";
+ }
+ pos.y = this.platformY.max;
+ this.CenterPanel.transform.localPosition = pos;
+ yield break;
+ }
+
+ public IEnumerator BringPanelDown()
+ {
+ if (Constants.ShouldPlaySfx())
+ {
+ SoundManager.Instance.PlaySound(this.PanelMoveSound, false, 1f);
+ }
+ WaitForFixedUpdate wait = new WaitForFixedUpdate();
+ Vector3 pos = this.CenterPanel.transform.localPosition;
+ for (float i = 0f; i < 0.75f; i += Time.deltaTime)
+ {
+ pos.y = this.platformY.Lerp(1f - i / 0.75f);
+ this.CenterPanel.transform.localPosition = pos;
+ yield return wait;
+ }
+ pos.y = this.platformY.min;
+ this.CenterPanel.transform.localPosition = pos;
+ yield break;
+ }
+
+ private IEnumerator DropTube(int id)
+ {
+ if (Constants.ShouldPlaySfx())
+ {
+ SoundManager.Instance.PlaySound(this.dropSounds.Get(), false, 1f);
+ }
+ this.Tubes[id].color = Color.blue;
+ yield break;
+ }
+
+ public void SelectTube(int tubeId)
+ {
+ if (this.State != SampleMinigame.States.Selection)
+ {
+ return;
+ }
+ this.State = SampleMinigame.States.PrepareSample;
+ for (int i = 0; i < this.Buttons.Length; i++)
+ {
+ this.Buttons[i].color = Color.white;
+ }
+ base.StartCoroutine(this.CoSelectTube(this.AnomalyId, tubeId));
+ }
+
+ private IEnumerator CoSelectTube(int correctTube, int selectedTube)
+ {
+ if (selectedTube != correctTube)
+ {
+ if (Constants.ShouldPlaySfx())
+ {
+ SoundManager.Instance.PlaySound(this.FailSound, false, 1f);
+ }
+ this.UpperText.Text = "Bad Result";
+ this.LowerText.Text = "Bad Result";
+ for (int i = 0; i < this.Buttons.Length; i++)
+ {
+ this.Buttons[i].color = Color.red;
+ }
+ yield return new WaitForSeconds(0.25f);
+ for (int j = 0; j < this.Buttons.Length; j++)
+ {
+ this.Buttons[j].color = Color.white;
+ }
+ yield return new WaitForSeconds(0.25f);
+ for (int k = 0; k < this.Buttons.Length; k++)
+ {
+ this.Buttons[k].color = Color.red;
+ }
+ yield return new WaitForSeconds(0.25f);
+ for (int l = 0; l < this.Buttons.Length; l++)
+ {
+ this.Buttons[l].color = Color.white;
+ }
+ this.UpperText.Text = "";
+ }
+ else
+ {
+ if (Constants.ShouldPlaySfx())
+ {
+ SoundManager.Instance.PlaySound(this.ButtonSound, false, 0.6f);
+ }
+ this.UpperText.Text = "Thank you";
+ this.MyNormTask.NextStep();
+ if (this.MyNormTask.IsComplete)
+ {
+ this.State = SampleMinigame.States.Complete;
+ }
+ }
+ int num = this.MyNormTask.MaxStep - this.MyNormTask.taskStep;
+ if (num == 0)
+ {
+ this.LowerText.Text = "Tests Complete";
+ }
+ else
+ {
+ this.LowerText.Text = num + " more";
+ }
+ yield return this.BringPanelDown();
+ for (int m = 0; m < this.Tubes.Length; m++)
+ {
+ this.Tubes[m].color = Color.white;
+ }
+ if (!this.MyNormTask.IsComplete)
+ {
+ yield return this.BringPanelUp(true);
+ }
+ yield break;
+ }
+
+ public void NextStep()
+ {
+ if (this.State != SampleMinigame.States.AwaitingStart)
+ {
+ return;
+ }
+ this.State = SampleMinigame.States.Processing;
+ this.LowerButton.color = Color.white;
+ if (Constants.ShouldPlaySfx())
+ {
+ SoundManager.Instance.PlaySound(this.ButtonSound, false, 1f).volume = 0.6f;
+ }
+ base.StartCoroutine(this.CoStartProcessing());
+ }
+
+ private IEnumerator CoStartProcessing()
+ {
+ this.MyNormTask.TaskTimer = this.TimePerStep;
+ this.MyNormTask.TimerStarted = NormalPlayerTask.TimerState.Started;
+ yield return this.DropLiquid();
+ this.LowerText.Text = SampleMinigame.ProcessingStrings.Random<string>();
+ yield return this.BringPanelDown();
+ yield break;
+ }
+
+ private IEnumerator DropLiquid()
+ {
+ this.LowerText.Text = "Adding Reagent";
+ WaitForSeconds dropWait = new WaitForSeconds(0.25f);
+ WaitForFixedUpdate wait = new WaitForFixedUpdate();
+ Vector3 pos = this.Dropper.transform.localPosition;
+ yield return dropWait;
+ yield return this.DropTube(0);
+ int num;
+ for (int step = -2; step < 2; step = num)
+ {
+ float start = (float)step / 2f * 1.25f;
+ float xTarg = (float)(step + 1) / 2f * 1.25f;
+ for (float i = 0f; i < 0.15f; i += Time.deltaTime)
+ {
+ pos.x = Mathf.Lerp(start, xTarg, i / 0.15f);
+ this.Dropper.transform.localPosition = pos;
+ yield return wait;
+ }
+ pos.x = xTarg;
+ this.Dropper.transform.localPosition = pos;
+ yield return dropWait;
+ int id = step + 3;
+ yield return this.DropTube(id);
+ num = step + 1;
+ }
+ for (float xTarg = 0f; xTarg < 0.15f; xTarg += Time.deltaTime)
+ {
+ pos.x = this.dropperX.Lerp(1f - xTarg / 0.15f);
+ this.Dropper.transform.localPosition = pos;
+ yield return wait;
+ }
+ pos.x = this.dropperX.min;
+ this.Dropper.transform.localPosition = pos;
+ yield break;
+ }
+}