-
Notifications
You must be signed in to change notification settings - Fork 6
/
AdvancedSimon.cs
713 lines (663 loc) · 28.7 KB
/
AdvancedSimon.cs
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
/*
-- On the Subject of Simon Stated --
- I'm not sure this even qualifies as Simon Says... -
One or more colours will flash.
Using the tables below, press the correct response.
The sequence will extend by 1 for each correct answer.
Keep answering until the module is disarmed.
Stage 1:
- If one colour flashed, press that colour.
- Otherwise, if two colours flashed and one was blue, press the highest priority colour that flashed.
- Otherwise, if two colours flashed, press blue.
- Otherwise, if three colours flashed including red, press the lowest priority colour that flashed.
- Otherwise, if three colours flashed, press red.
- Otherwise, press the second highest priority colour.
Stage 2:
- If red and blue flashed, press the highest priority colour that didn't flash.
- Otherwise, if two colours flashed, press the lowest priority colour that flashed.
- Otherwise, if one colour flashed and it was not blue, press blue.
- Otherwise, if one colour flashed, press yellow.
- Otherwise, if all colours flashed, press the same colour as stage 1.
- Otherwise, press the colour that didn't flash.
Stage 3:
- If three colours flashed and at least one was pressed in a previous stage, press the highest priority colour that flashed that hasn't been pressed.
- Otherwise, if three colours flashed, press the highest priority colour that flashed.
- Otherwise, if two colours flashed and both have been pressed, press the lowest priority colour that didn't flash.
- Otherwise, if two colours flashed, press the same colour as stage 1.
- Otherwise, if one colour flashed, press that colour.
- Otherwise, press the second lowest priority colour.
Stage 4:
- If three unique colours have been pressed, press the fourth colour.
- Otherwise, if three colours flashed and exactly one hasn't been pressed, press that colour.
- Otherwise, if at least three colours flashed, press the lowest priority colour.
- Otherwise, if one colour flashed, press that colour.
- Otherwise, press green.
Stage 5:
- If three unique colours have been pressed, press the fourth colour.
- Otherwise, if two colours flashed and one was blue, press the other colour.
- Otherwise, if at two or three colours flashed and one was green, press yellow.
- Otherwise, if all colours that flashed have been pressed, press red.
- Otherwise, if four colours flashed and at least one colour hasn't been pressed, press the lowest priority colour that hasn't been pressed.
- Otherwise, press blue.
Stage 6:
- If three unique colours have been pressed, press the fourth colour.
- Otherwise, if two colours flashed and both have been pressed, press green.
- Otherwise, if three colours flashed and at least one hasn't been pressed, press the lowest priority colour.
- Otherwise, if one colour has been pressed more than all other colours, press that colour.
- Otherwise, press the highest priority colour.
*/
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class AdvancedSimon : FixedTicker
{
public static int loggingID = 1;
public int thisLoggingID;
public KMSelectable ButtonTL, ButtonTR, ButtonBL, ButtonBR;
public KMAudio Sound;
public KMBombInfo Info;
private static Color RED = new Color(1f, 0, 0, 0.4f), YELLOW = new Color(0.8f, 0.8f, 0, 0.4f), GREEN = new Color(0, 0.7f, 0, 0.4f), BLUE = new Color(0, 0.3f, 1f, 0.4f),
DARKRED = new Color(0.25f, 0, 0, 0), DARKYELLOW = new Color(0.27f, 0.27f, 0, 0), DARKGREEN = new Color(0, 0.23f, 0, 0), DARKBLUE = new Color(0, 0.1f, 0.33f, 0);
private KMSelectable ButtonRed, ButtonYellow, ButtonGreen, ButtonBlue;
private static int[][] PRIORITY = new int[][]{
new int[]{ 0, 3, 2, 1 }, //R-RBGY
new int[]{ 3, 1, 0, 2 }, //Y-BYRG
new int[]{ 2, 0, 1, 3 }, //G-GRYB
new int[]{ 1, 2, 3, 0 } //B-YGBR
};
private static string[] COL_LIST = new string[]{"R", "Y", "G", "B"};
private int PuzzleType;
private bool[][] PuzzleDisplay;
private int DisplayPos;
private int[] Answer;
private int Progress, SubProgress;
private bool soundActive = false;
void Awake()
{
thisLoggingID = loggingID++;
//transform.Find("Background").GetComponent<MeshRenderer>().material.color = new Color(1, 0.1f, 0.1f);
ButtonTL.GetComponent<MeshRenderer>().material.color = new Color(0, 0, 0);
ButtonTR.GetComponent<MeshRenderer>().material.color = new Color(0, 0, 0);
ButtonBL.GetComponent<MeshRenderer>().material.color = new Color(0, 0, 0);
ButtonBR.GetComponent<MeshRenderer>().material.color = new Color(0, 0, 0);
GetComponent<KMBombModule>().OnActivate += Init;
}
void Init()
{
ButtonTL.OnInteract += delegate() { ButtonTL.AddInteractionPunch(); return false; };
ButtonTR.OnInteract += delegate() { ButtonTR.AddInteractionPunch(); return false; };
ButtonBL.OnInteract += delegate() { ButtonBL.AddInteractionPunch(); return false; };
ButtonBR.OnInteract += delegate() { ButtonBR.AddInteractionPunch(); return false; };
List<KMSelectable> buttons = new List<KMSelectable>() { ButtonTL, ButtonTR, ButtonBL, ButtonBR };
int i = 0;
int TLtype = -1;
while (buttons.Count > 0)
{
int pos = Random.Range(0, buttons.Count);
if (pos == 0 && TLtype == -1)
{
Debug.Log("[Simon States #"+thisLoggingID+"] Dominant: "+COL_LIST[i]);
TLtype = i;
}
KMSelectable b = buttons[pos];
if (i == 0)
{
ButtonRed = b;
b.GetComponent<MeshRenderer>().material.color = DARKRED;
b.OnInteract += HandleRed;
}
else if (i == 1)
{
ButtonYellow = b;
b.GetComponent<MeshRenderer>().material.color = DARKYELLOW;
b.OnInteract += HandleYellow;
}
else if (i == 2)
{
ButtonGreen = b;
b.GetComponent<MeshRenderer>().material.color = DARKGREEN;
b.OnInteract += HandleGreen;
}
else
{
ButtonBlue = b;
b.GetComponent<MeshRenderer>().material.color = DARKBLUE;
b.OnInteract += HandleBlue;
}
i++;
buttons.RemoveAt(pos);
}
int len = 4;
PuzzleDisplay = new bool[len][];
for (int a = 0; a < len; a++)
{
PuzzleDisplay[a] = new bool[4];
int num = Random.Range(1, 5);
if (num > 2) num = Random.Range(2, 5);
List<int> posList = new List<int>() { 0, 1, 2, 3 };
while (num > 0)
{
num--;
int pos = Random.Range(0, posList.Count);
PuzzleDisplay[a][posList[pos]] = true;
posList.RemoveAt(pos);
}
string col = "";
if(PuzzleDisplay[a][0]) col += COL_LIST[0]; else col += "-";
if(PuzzleDisplay[a][1]) col += COL_LIST[1]; else col += "-";
if(PuzzleDisplay[a][2]) col += COL_LIST[2]; else col += "-";
if(PuzzleDisplay[a][3]) col += COL_LIST[3]; else col += "-";
Debug.Log("[Simon States #"+thisLoggingID+"] Stage "+(a+1)+" colours: "+col);
}
Answer = new int[len];
bool R = false, Y = false, B = false, G = false;
for (int a = 0; a < len; a++)
{
int numFlashed = 0;
for (int z = 0; z < 4; z++)
{
if (PuzzleDisplay[a][z]) numFlashed++;
}
int numUniquePressed = 0;
if (R) numUniquePressed++;
if (Y) numUniquePressed++;
if (G) numUniquePressed++;
if (B) numUniquePressed++;
if (a == 0)
{
if (numFlashed == 1)
{
if (PuzzleDisplay[0][0]) Answer[0] = 0;
else if (PuzzleDisplay[0][1]) Answer[0] = 1;
else if (PuzzleDisplay[0][2]) Answer[0] = 2;
else Answer[0] = 3;
Debug.Log("[Simon States #"+thisLoggingID+"] Stage 1: One flashed, press it (" + Answer[0] + ":" + COL_LIST[Answer[0]] + ")");
}
else if (numFlashed == 2)
{
if (PuzzleDisplay[0][3])
{
for (int z = 0; z < 4; z++)
{
if (PuzzleDisplay[0][PRIORITY[TLtype][z]])
{
Answer[0] = PRIORITY[TLtype][z];
break;
}
}
Debug.Log("[Simon States #"+thisLoggingID+"] Stage 1: Two flashed with blue, press highest (" + Answer[0] + ":" + COL_LIST[Answer[0]] + ")");
}
else
{
Answer[0] = 3;
Debug.Log("[Simon States #"+thisLoggingID+"] Stage 1: Two flashed without blue, press blue (3:B)");
}
}
else if (numFlashed == 3)
{
if (PuzzleDisplay[0][0])
{
for (int z = 3; z >= 0; z--)
{
if (PuzzleDisplay[0][PRIORITY[TLtype][z]])
{
Answer[0] = PRIORITY[TLtype][z];
break;
}
}
Debug.Log("[Simon States #"+thisLoggingID+"] Stage 1: Three flashed including red, press lowest (" + Answer[0] + ":" + COL_LIST[Answer[0]] + ")");
}
else
{
Answer[0] = 0;
Debug.Log("[Simon States #"+thisLoggingID+"] Stage 1: Three flashed excluding red, press red (0:R)");
}
}
else
{
Answer[0] = PRIORITY[TLtype][1];
Debug.Log("[Simon States #"+thisLoggingID+"] Stage 1: Four flashed, press second highest (" + Answer[0] + ":" + COL_LIST[Answer[0]] + ")");
}
}
else if (a == 1)
{
if (numFlashed == 2)
{
if (PuzzleDisplay[1][0] && PuzzleDisplay[1][3])
{
for (int z = 0; z < 4; z++)
{
if (!PuzzleDisplay[1][PRIORITY[TLtype][z]])
{
Answer[1] = PRIORITY[TLtype][z];
break;
}
}
Debug.Log("[Simon States #"+thisLoggingID+"] Stage 2: Red and blue flashed, press highest out of yellow and green (" + Answer[1] + ":" + COL_LIST[Answer[1]] + ")");
}
else
{
for (int z = 3; z >= 0; z--)
{
if (!PuzzleDisplay[1][PRIORITY[TLtype][z]])
{
Answer[1] = PRIORITY[TLtype][z];
break;
}
}
Debug.Log("[Simon States #"+thisLoggingID+"] Stage 2: Two flashed including yellow or green, press lowest that didn't flash (" + Answer[1] + ":" + COL_LIST[Answer[1]] + ")");
}
}
else if (numFlashed == 1)
{
if (!PuzzleDisplay[1][3])
{
Answer[1] = 3;
Debug.Log("[Simon States #"+thisLoggingID+"] Stage 2: One flashed but not blue, press blue (3:B)");
}
else
{
Answer[1] = 1;
Debug.Log("[Simon States #"+thisLoggingID+"] Stage 2: Blue flashed, press yellow (1:Y)");
}
}
else if (numFlashed == 4)
{
Answer[1] = Answer[0];
Debug.Log("[Simon States #"+thisLoggingID+"] Stage 2: Four flashed, press stage 1 (" + Answer[1] + ":" + COL_LIST[Answer[1]] + ")");
}
else
{
if (!PuzzleDisplay[1][0]) Answer[1] = 0;
else if (!PuzzleDisplay[1][1]) Answer[1] = 1;
else if (!PuzzleDisplay[1][2]) Answer[1] = 2;
else Answer[1] = 3;
Debug.Log("[Simon States #"+thisLoggingID+"] Stage 2: Three flashed, press whatever didn't flash (" + Answer[1] + ":" + COL_LIST[Answer[1]] + ")");
}
}
else if (a == 2)
{
if (numFlashed == 3)
{
if ((PuzzleDisplay[2][0] && R) || (PuzzleDisplay[2][1] && Y) ||
(PuzzleDisplay[2][2] && G) || (PuzzleDisplay[2][3] && B))
{
for (int z = 0; z < 4; z++)
{
int trueVal = PRIORITY[TLtype][z];
if (PuzzleDisplay[2][trueVal])
{
if (trueVal == 0 && !R)
{
Answer[2] = 0;
break;
}
else if (trueVal == 1 && !Y)
{
Answer[2] = 1;
break;
}
else if (trueVal == 2 && !G)
{
Answer[2] = 2;
break;
}
else if (trueVal == 3 && !B)
{
Answer[2] = 3;
break;
}
}
}
Debug.Log("[Simon States #"+thisLoggingID+"] Stage 3: Three flashed and one was pressed, press highest unpressed that flashed (" + Answer[2] + ":" + COL_LIST[Answer[2]] + ")");
}
else
{
for (int z = 0; z < 4; z++)
{
if (PuzzleDisplay[2][PRIORITY[TLtype][z]])
{
Answer[2] = PRIORITY[TLtype][z];
break;
}
}
Debug.Log("[Simon States #"+thisLoggingID+"] Stage 3: Three flashed and weren't pressed, press highest that flashes (" + Answer[2] + ":" + COL_LIST[Answer[2]] + ")");
}
}
else if (numFlashed == 2)
{
if ((PuzzleDisplay[2][0] && !R) || (PuzzleDisplay[2][1] && !Y) ||
(PuzzleDisplay[2][2] && !G) || (PuzzleDisplay[2][3] && !B))
{
Answer[2] = Answer[0];
Debug.Log("[Simon States #"+thisLoggingID+"] Stage 3: Two flashed and at least one unpressed, press stage 1 (" + Answer[2] + ":" + COL_LIST[Answer[2]] + ")");
}
else
{
for (int z = 3; z >= 0; z--)
{
if (!PuzzleDisplay[2][PRIORITY[TLtype][z]])
{
Answer[2] = PRIORITY[TLtype][z];
break;
}
}
Debug.Log("[Simon States #"+thisLoggingID+"] Stage 3: Two flashed and both pressed, press lowest no-flash (" + Answer[2] + ":" + COL_LIST[Answer[2]] + ")");
}
}
else if (numFlashed == 1)
{
if (PuzzleDisplay[2][0]) Answer[2] = 0;
else if (PuzzleDisplay[2][1]) Answer[2] = 1;
else if (PuzzleDisplay[2][2]) Answer[2] = 2;
else Answer[2] = 3;
Debug.Log("[Simon States #"+thisLoggingID+"] Stage 3: One flashed, press it (" + Answer[2] + ":" + COL_LIST[Answer[2]] + ")");
}
else
{
Answer[2] = PRIORITY[TLtype][2];
Debug.Log("[Simon States #"+thisLoggingID+"] Stage 3: Four flashed, press second lowest (" + Answer[2] + ":" + COL_LIST[Answer[2]] + ")");
}
}
else if (a == 3)
{
if (numUniquePressed == 3)
{
if (!R) Answer[3] = 0;
else if (!Y) Answer[3] = 1;
else if (!G) Answer[3] = 2;
else Answer[3] = 3;
Debug.Log("[Simon States #"+thisLoggingID+"] Stage 4: Three unique pressed, press other (" + Answer[3] + ":" + COL_LIST[Answer[3]] + ")");
}
else if (numFlashed == 3)
{
int unpressed = 4;
if (!R && PuzzleDisplay[3][0]) unpressed = 0;
if (!Y && PuzzleDisplay[3][1])
{
if (unpressed == 4) unpressed = 1;
else unpressed = -1;
}
if (unpressed != -1 && !G && PuzzleDisplay[3][2])
{
if (unpressed == 4) unpressed = 2;
else unpressed = -1;
}
if (unpressed != -1 && !B && PuzzleDisplay[3][3])
{
if (unpressed == 4) unpressed = 3;
else unpressed = -1;
}
if (unpressed >= 0 && unpressed < 4)
{
Answer[3] = unpressed;
Debug.Log("[Simon States #"+thisLoggingID+"] Stage 4: Three flashed and exactly one unpressed, press it (" + Answer[3] + ":" + COL_LIST[Answer[3]] + ")");
}
else
{
Answer[3] = PRIORITY[TLtype][3];
Debug.Log("[Simon States #"+thisLoggingID+"] Stage 4: Three flashed and not exactly one unpressed, press lowest (" + Answer[3] + ":" + COL_LIST[Answer[3]] + ")");
}
}
else if (numFlashed == 4)
{
Answer[3] = PRIORITY[TLtype][3];
Debug.Log("[Simon States #"+thisLoggingID+"] Stage 4: Four flashed, press lowest (" + Answer[3] + ":" + COL_LIST[Answer[3]] + ")");
}
else if (numFlashed == 1)
{
if (PuzzleDisplay[3][0]) Answer[3] = 0;
else if (PuzzleDisplay[3][1]) Answer[3] = 1;
else if (PuzzleDisplay[3][2]) Answer[3] = 2;
else Answer[3] = 3;
Debug.Log("[Simon States #"+thisLoggingID+"] Stage 4: One flashed, press it (" + Answer[3] + ":" + COL_LIST[Answer[3]] + ")");
}
else
{
Answer[3] = 2;
Debug.Log("[Simon States #"+thisLoggingID+"] Stage 4: Two flashed, press green (2:G)");
}
}
if (Answer[a] == 0) R = true;
if (Answer[a] == 1) Y = true;
if (Answer[a] == 2) G = true;
if (Answer[a] == 3) B = true;
}
}
private int ticker = 0;
private int pressTicker = 0;
public override void RealFixedTick()
{
if (pressTicker > 0)
{
pressTicker--;
if (pressTicker == 0)
{
ButtonRed.GetComponent<MeshRenderer>().material.color = DARKRED;
ButtonYellow.GetComponent<MeshRenderer>().material.color = DARKYELLOW;
ButtonGreen.GetComponent<MeshRenderer>().material.color = DARKGREEN;
ButtonBlue.GetComponent<MeshRenderer>().material.color = DARKBLUE;
}
}
if (PuzzleDisplay == null) return;
if (ticker == 0)
{
if(DisplayPos >= 0)
{
string tone = "";
if(PuzzleDisplay[DisplayPos][0]) {
ButtonRed.GetComponent<MeshRenderer>().material.color = RED;
tone += "R";
}
if(PuzzleDisplay[DisplayPos][1]) {
ButtonYellow.GetComponent<MeshRenderer>().material.color = YELLOW;
tone += "Y";
}
if(PuzzleDisplay[DisplayPos][2]) {
ButtonGreen.GetComponent<MeshRenderer>().material.color = GREEN;
tone += "G";
}
if(PuzzleDisplay[DisplayPos][3]) {
ButtonBlue.GetComponent<MeshRenderer>().material.color = BLUE;
tone += "B";
}
if(soundActive) PlaySound(tone, false);
}
}
else if(ticker == 15)
{
if(DisplayPos >= 0)
{
if (PuzzleDisplay[DisplayPos][0]) ButtonRed.GetComponent<MeshRenderer>().material.color = DARKRED;
if (PuzzleDisplay[DisplayPos][1]) ButtonYellow.GetComponent<MeshRenderer>().material.color = DARKYELLOW;
if (PuzzleDisplay[DisplayPos][2]) ButtonGreen.GetComponent<MeshRenderer>().material.color = DARKGREEN;
if (PuzzleDisplay[DisplayPos][3]) ButtonBlue.GetComponent<MeshRenderer>().material.color = DARKBLUE;
}
ticker = -20;
if (DisplayPos == Progress)
{
DisplayPos = -1;
ticker = -75;
}
else DisplayPos++;
}
ticker++;
}
private void PlaySound(string name, bool wasAns) {
if(bop) {
if(name.Equals("R") || name.Equals("RY") || name.Equals("RGB")) {
if(wasAns) Sound.PlaySoundAtTransform("PULL2", transform);
else Sound.PlaySoundAtTransform("PULL", transform);
}
else if(name.Equals("Y") || name.Equals("YG") || name.Equals("RYB")) {
if(wasAns) Sound.PlaySoundAtTransform("TWIST2", transform);
else Sound.PlaySoundAtTransform("TWIST", transform);
}
else if(name.Equals("G") || name.Equals("GB") || name.Equals("RYG")) {
if(wasAns) Sound.PlaySoundAtTransform("FLICK2", transform);
else Sound.PlaySoundAtTransform("FLICK", transform);
}
else if(name.Equals("B") || name.Equals("RB") || name.Equals("YGB")) {
if(wasAns) Sound.PlaySoundAtTransform("SPIN2", transform);
else Sound.PlaySoundAtTransform("SPIN", transform);
}
else if(name.Equals("RYGB") || name.Equals("RG") || name.Equals("YB")) {
Sound.PlaySoundAtTransform("BOP", transform);
}
else {
Debug.Log("Bop-it error with tone: " + name);
}
}
else Sound.PlaySoundAtTransform(name, transform);
}
private void bopsolve() { Sound.PlaySoundAtTransform("PASS", transform); }
private void Handle(int val)
{
if (PuzzleDisplay == null) return;
soundActive = true;
if (ticker >= 0 || pressTicker > 0)
{
ButtonRed.GetComponent<MeshRenderer>().material.color = DARKRED;
ButtonYellow.GetComponent<MeshRenderer>().material.color = DARKYELLOW;
ButtonGreen.GetComponent<MeshRenderer>().material.color = DARKGREEN;
ButtonBlue.GetComponent<MeshRenderer>().material.color = DARKBLUE;
}
ticker = -100;
DisplayPos = 0;
if (val == Answer[SubProgress])
{
if (SubProgress == Progress)
{
SubProgress = 0;
Progress++;
ticker = -50;
if (Progress == PuzzleDisplay.Length)
{
Debug.Log("[Simon States #"+thisLoggingID+"] Module solved.");
GetComponent<KMBombModule>().HandlePass();
if(bop) Invoke("bopsolve", 0.6f);
PuzzleDisplay = null;
}
else Debug.Log("[Simon States #"+thisLoggingID+"] Stage " + Progress + " complete.");
}
else SubProgress++;
}
else
{
string ans = Answer[0] + "";
string ans2 = COL_LIST[Answer[0]];
if(Progress >= 1) {
ans += Answer[1];
ans2 += COL_LIST[Answer[1]];
}
if(Progress >= 2) {
ans += Answer[2];
ans2 += COL_LIST[Answer[2]];
}
if(Progress >= 3) {
ans += Answer[3];
ans2 += COL_LIST[Answer[3]];
}
Debug.Log("[Simon States #"+thisLoggingID+"] Expected answer: " + ans + ":" + ans2);
ans = "";
ans2 = "";
for(int a = 0; a < SubProgress; a++)
{
ans += Answer[a];
ans2 += COL_LIST[Answer[a]];
}
ans += val;
ans2 += COL_LIST[val];
Debug.Log("[Simon States #"+thisLoggingID+"] Given answer: " + ans + ":" + ans2);
GetComponent<KMBombModule>().HandleStrike();
SubProgress = 0;
}
pressTicker = 15;
if (val == 0) {
ButtonRed.GetComponent<MeshRenderer>().material.color = RED;
PlaySound("R", true);
}
else if(val == 1) {
ButtonYellow.GetComponent<MeshRenderer>().material.color = YELLOW;
PlaySound("Y", true);
}
else if(val == 2) {
ButtonGreen.GetComponent<MeshRenderer>().material.color = GREEN;
PlaySound("G", true);
}
else {
ButtonBlue.GetComponent<MeshRenderer>().material.color = BLUE;
PlaySound("B", true);
}
}
private bool HandleRed()
{
Handle(0);
return false;
}
private bool HandleYellow()
{
Handle(1);
return false;
}
private bool HandleGreen()
{
Handle(2);
return false;
}
private bool HandleBlue()
{
Handle(3);
return false;
}
//Twitch Plays support
#pragma warning disable 0414
string TwitchHelpMessage = "Press buttons with 'press RYB'.";
#pragma warning restore 0414
public void TwitchHandleForcedSolve() {
Debug.Log("[Simon States #"+thisLoggingID+"] Module forcibly solved.");
StartCoroutine(Solver());
}
private IEnumerator Solver() {
while(PuzzleDisplay != null) {
Handle(Answer[SubProgress]);
yield return new WaitForSeconds(bop?0.4f:0.29f);
}
yield break;
}
private bool bop = false;
public IEnumerator ProcessTwitchCommand(string cmd) {
cmd = cmd.ToLowerInvariant();
if(cmd.StartsWith("press ")) cmd = cmd.Substring(6);
else if(cmd.StartsWith("submit ")) cmd = cmd.Substring(7);
else if(cmd.Equals("soundpack")) {
if(bop) {
yield return "sendtochaterror That is already on.";
yield break;
}
yield return "Simon States";
Sound.PlaySoundAtTransform("BOP", transform);
yield return "sendtochat Pull-it! Twist-it! Bop-it!";
bop = true;
yield break;
}
else throw new System.FormatException("Commands must start with 'press'.");
char[] buttons = cmd.ToCharArray();
List<KMSelectable> seq = new List<KMSelectable>();
foreach(char c in buttons) {
if(c == ' ' || c == ',') continue;
if(c == 'r') seq.Add(ButtonRed);
else if(c == 'y') seq.Add(ButtonYellow);
else if(c == 'g') seq.Add(ButtonGreen);
else if(c == 'b') seq.Add(ButtonBlue);
else throw new System.FormatException("Bad character: " + c);
}
yield return "Simon States";
foreach(KMSelectable s in seq) {
yield return s;
yield return new WaitForSeconds(bop?0.4f:0.29f);
yield return s;
}
yield break;
}
}