private void Start() { _rotateCoin = new Routine <int, bool>(RotateCoin, this); Coins.Assign(onInteract: i => _rotateCoin.Start(i, true, allowSimultaneousRuns: false)); coinStates = Helper.RandomBooleans(CoinCount); hammingCodes = Get <KMBombInfo>().GetSerialNumber() .Select(c => Chars.Contains(c)) .ToArray(); // This flips each coin if needed. for (int i = 0; i < CoinCount; i++) { ApplyRotation(i, 0, 0.6f); } Log("The hamming code is {0}.", hammingCodes.Select(b => b ? "1" : "0").Join("")); Log("The coins are arranged as {0}, making the answer {1}. (chess-coordinates)", CoinValues.Select(n => n % 2 == 1 ? "1" : "0").Join(""), ToCoordinate(GetExampleAnswer())); }
private IEnumerator RotateCoin(int arg, bool playSound) { if (playSound) { PlaySound(Coins[arg].transform, Sounds.Coin.Flip); } float f = 0; // Makes highlight invisible. CoinHighlightableTransforms[arg].localScale = new Vector3(0, 0, 0); while (f <= 1) { float angle = Easing.OutQuart(f, 0, 1, 1) * 180, distance = (Mathf.Sin(f * Mathf.PI) * Mathf.PI) + 0.55f; ApplyRotation(arg, angle, distance); f += 1 / 64f; yield return(new WaitForSecondsRealtime(0.01f)); } // Makes highlight visible again. CoinHighlightableTransforms[arg].localScale = new Vector3(1.1f, 1.1f, 0.1f); // Since we flip a coin, we naturally need to flip the boolean. coinStates[arg] = !coinStates[arg]; if (IsSolved) { yield break; } if (IsCorrect) { PlaySound(Coins[arg].transform, Sounds.Coin.Solve); Solve("The correct coin was flipped. Module solved!"); souvenirCoin = ToCoordinate(arg); Light.StartCoroutine(Light.Solve()); for (int i = 0; i < 64; i++) { int[] coinFlips = Enumerable.Range(0, 64).Where(j => (j % 8) + (j / 8) == i).ToArray(); foreach (int flip in coinFlips) { StartCoroutine(RotateCoin(flip, false)); yield return(new WaitForSecondsRealtime(1 / 32f)); } } } else { PlaySound(Coins[arg].transform, Sounds.Coin.Strike); Strike("Coin {0} was flipped, making the arrangement {1}, strike!".Form(ToCoordinate(arg), CoinValues.Select(n => n % 2 == 1 ? "1" : "0").Join("")), "One of the answers is now {1}. (chess-coordinates)".Form(CoinValues.Select(n => n % 2 == 1 ? "1" : "0").Join(""), ToCoordinate(GetExampleAnswer()))); } }