summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/WireMinigame.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Client/Assembly-CSharp/WireMinigame.cs')
-rw-r--r--Client/Assembly-CSharp/WireMinigame.cs157
1 files changed, 157 insertions, 0 deletions
diff --git a/Client/Assembly-CSharp/WireMinigame.cs b/Client/Assembly-CSharp/WireMinigame.cs
new file mode 100644
index 0000000..27d0ecc
--- /dev/null
+++ b/Client/Assembly-CSharp/WireMinigame.cs
@@ -0,0 +1,157 @@
+using System;
+using UnityEngine;
+
+public class WireMinigame : Minigame
+{
+ private static readonly Color[] colors = new Color[]
+ {
+ Color.red,
+ Color.blue,
+ Color.yellow,
+ Color.magenta
+ };
+
+ public Wire[] LeftNodes;
+
+ public WireNode[] RightNodes;
+
+ public SpriteRenderer[] LeftLights;
+
+ public SpriteRenderer[] RightLights;
+
+ private Controller myController = new Controller();
+
+ private sbyte[] ExpectedWires = new sbyte[4];
+
+ private sbyte[] ActualWires = new sbyte[4];
+
+ public AudioClip[] WireSounds;
+
+ private bool TaskIsForThisPanel()
+ {
+ return this.MyNormTask.taskStep < this.MyNormTask.Data.Length && !this.MyNormTask.IsComplete && (int)this.MyNormTask.Data[this.MyNormTask.taskStep] == base.ConsoleId;
+ }
+
+ public override void Begin(PlayerTask task)
+ {
+ base.Begin(task);
+ IntRange.FillRandomRange(this.ExpectedWires);
+ for (int i = 0; i < this.LeftNodes.Length; i++)
+ {
+ this.ActualWires[i] = -1;
+ int num = (int)this.ExpectedWires[i];
+ Wire wire = this.LeftNodes[i];
+ wire.SetColor(WireMinigame.colors[num]);
+ wire.WireId = (sbyte)i;
+ this.RightNodes[i].SetColor(WireMinigame.colors[i]);
+ this.RightNodes[i].WireId = (sbyte)i;
+ int num2 = (int)this.ActualWires[i];
+ if (num2 > -1)
+ {
+ wire.ConnectRight(this.RightNodes[num2]);
+ }
+ else
+ {
+ wire.ResetLine(Vector3.zero, true);
+ }
+ }
+ this.UpdateLights();
+ }
+
+ public void Update()
+ {
+ if (!this.TaskIsForThisPanel())
+ {
+ return;
+ }
+ this.myController.Update();
+ base.transform.position;
+ for (int i = 0; i < this.LeftNodes.Length; i++)
+ {
+ Wire wire = this.LeftNodes[i];
+ DragState dragState = this.myController.CheckDrag(wire.hitbox, false);
+ if (dragState != DragState.Dragging)
+ {
+ if (dragState == DragState.Released)
+ {
+ if (this.ActualWires[(int)wire.WireId] == -1)
+ {
+ wire.ResetLine(wire.BaseWorldPos, true);
+ }
+ else if (Constants.ShouldPlaySfx())
+ {
+ SoundManager.Instance.PlaySound(this.WireSounds.Random<AudioClip>(), false, 1f);
+ }
+ this.CheckTask();
+ }
+ }
+ else
+ {
+ Vector2 vector = this.myController.DragPosition;
+ WireNode wireNode = this.CheckRightSide(vector);
+ if (wireNode)
+ {
+ vector = wireNode.transform.position;
+ this.ActualWires[(int)wire.WireId] = wireNode.WireId;
+ }
+ else
+ {
+ vector -= wire.BaseWorldPos.normalized * 0.05f;
+ this.ActualWires[(int)wire.WireId] = -1;
+ }
+ wire.ResetLine(vector, false);
+ }
+ }
+ this.UpdateLights();
+ }
+
+ private void UpdateLights()
+ {
+ for (int i = 0; i < this.ActualWires.Length; i++)
+ {
+ Color color = Color.yellow;
+ color *= 1f - Mathf.PerlinNoise((float)i, Time.time * 35f) * 0.3f;
+ color.a = 1f;
+ if (this.ActualWires[i] != this.ExpectedWires[i])
+ {
+ this.RightLights[(int)this.ExpectedWires[i]].color = new Color(0.2f, 0.2f, 0.2f);
+ }
+ else
+ {
+ this.RightLights[(int)this.ExpectedWires[i]].color = color;
+ }
+ this.LeftLights[i].color = color;
+ }
+ }
+
+ private WireNode CheckRightSide(Vector2 pos)
+ {
+ for (int i = 0; i < this.RightNodes.Length; i++)
+ {
+ WireNode wireNode = this.RightNodes[i];
+ if (wireNode.hitbox.OverlapPoint(pos))
+ {
+ return wireNode;
+ }
+ }
+ return null;
+ }
+
+ private void CheckTask()
+ {
+ bool flag = true;
+ for (int i = 0; i < this.ActualWires.Length; i++)
+ {
+ if (this.ActualWires[i] != this.ExpectedWires[i])
+ {
+ flag = false;
+ break;
+ }
+ }
+ if (flag)
+ {
+ this.MyNormTask.NextStep();
+ this.Close();
+ }
+ }
+}