summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/WireMinigame.cs
blob: 27d0ecc9497ca79ec92c2f856a0265c14defabd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
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();
		}
	}
}