summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/CardSlideGame.cs
blob: 3c423a5440d6e1f64ca893a342cbee58346b829a (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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
using System;
using System.Collections;
using UnityEngine;

public class CardSlideGame : Minigame
{
	private Color gray = new Color(0.45f, 0.45f, 0.45f);

	private Color green = new Color(0f, 0.8f, 0f);

	private CardSlideGame.TaskStages State;

	private Controller myController = new Controller();

	private FloatRange XRange = new FloatRange(-2.38f, 2.38f);

	public FloatRange AcceptedTime = new FloatRange(0.4f, 0.6f);

	public Collider2D col;

	public SpriteRenderer redLight;

	public SpriteRenderer greenLight;

	public TextRenderer StatusText;

	public AudioClip AcceptSound;

	public AudioClip[] CardMove;

	public AudioClip WalletOut;

	public float dragTime;

	private bool moving;

	private enum TaskStages
	{
		Before,
		Animating,
		Inserted,
		After
	}

	public void Update()
	{
		if (this.MyNormTask.IsComplete)
		{
			return;
		}
		this.myController.Update();
		Vector3 localPosition = this.col.transform.localPosition;
		switch (this.myController.CheckDrag(this.col, false))
		{
		case DragState.NoTouch:
			if (this.State == CardSlideGame.TaskStages.Inserted)
			{
				localPosition.x = Mathf.Lerp(localPosition.x, this.XRange.min, Time.deltaTime * 4f);
			}
			break;
		case DragState.TouchStart:
			this.dragTime = 0f;
			break;
		case DragState.Dragging:
			if (this.State == CardSlideGame.TaskStages.Inserted)
			{
				Vector2 vector = this.myController.DragPosition - base.transform.position;
				vector.x = this.XRange.Clamp(vector.x);
				if (vector.x - localPosition.x > 0.01f)
				{
					this.dragTime += Time.deltaTime;
					this.redLight.color = this.gray;
					this.greenLight.color = this.gray;
					if (!this.moving)
					{
						this.moving = true;
						if (Constants.ShouldPlaySfx())
						{
							SoundManager.Instance.PlaySound(this.CardMove.Random<AudioClip>(), false, 1f);
						}
					}
				}
				localPosition.x = vector.x;
			}
			break;
		case DragState.Released:
			this.moving = false;
			if (this.State == CardSlideGame.TaskStages.Before)
			{
				this.State = CardSlideGame.TaskStages.Animating;
				base.StartCoroutine(this.InsertCard());
			}
			else if (this.State == CardSlideGame.TaskStages.Inserted)
			{
				if (this.XRange.max - localPosition.x < 0.05f)
				{
					if (this.AcceptedTime.Contains(this.dragTime))
					{
						if (Constants.ShouldPlaySfx())
						{
							SoundManager.Instance.PlaySound(this.AcceptSound, false, 1f);
						}
						this.State = CardSlideGame.TaskStages.After;
						this.StatusText.Text = "Accepted. Thank you.";
						base.StartCoroutine(this.PutCardBack());
						if (this.MyNormTask)
						{
							this.MyNormTask.NextStep();
						}
						this.redLight.color = this.gray;
						this.greenLight.color = this.green;
					}
					else
					{
						if (this.AcceptedTime.max < this.dragTime)
						{
							this.StatusText.Text = "Too slow. Try again";
						}
						else
						{
							this.StatusText.Text = "Too fast. Try again.";
						}
						this.redLight.color = Color.red;
						this.greenLight.color = this.gray;
					}
				}
				else
				{
					this.StatusText.Text = "Bad read. Try again.";
					this.redLight.color = Color.red;
					this.greenLight.color = this.gray;
				}
			}
			break;
		}
		this.col.transform.localPosition = localPosition;
	}

	private IEnumerator PutCardBack()
	{
		if (Constants.ShouldPlaySfx())
		{
			SoundManager.Instance.PlaySound(this.WalletOut, false, 1f);
		}
		Vector3 pos = this.col.transform.localPosition;
		Vector3 targ = new Vector3(-1.11f, -1.9f, pos.z);
		float time = 0f;
		for (;;)
		{
			float t = Mathf.Min(1f, time / 0.6f);
			this.col.transform.localPosition = Vector3.Lerp(pos, targ, t);
			this.col.transform.localScale = Vector3.Lerp(Vector3.one, Vector3.one * 0.75f, t);
			if (time > 0.6f)
			{
				break;
			}
			yield return null;
			time += Time.deltaTime;
		}
		base.StartCoroutine(base.CoStartClose(0.75f));
		yield break;
	}

	private IEnumerator InsertCard()
	{
		if (Constants.ShouldPlaySfx())
		{
			SoundManager.Instance.PlaySound(this.WalletOut, false, 1f);
		}
		Vector3 pos = this.col.transform.localPosition;
		Vector3 targ = new Vector3(this.XRange.min, 0.75f, pos.z);
		float time = 0f;
		for (;;)
		{
			float t = Mathf.Min(1f, time / 0.6f);
			this.col.transform.localPosition = Vector3.Lerp(pos, targ, t);
			this.col.transform.localScale = Vector3.Lerp(Vector3.one * 0.75f, Vector3.one, t);
			if (time > 0.6f)
			{
				break;
			}
			yield return null;
			time += Time.deltaTime;
		}
		this.StatusText.Text = "Please swipe card";
		this.greenLight.color = this.green;
		this.State = CardSlideGame.TaskStages.Inserted;
		yield break;
	}
}