internal KMSelectable.OnInteractHandler OnInteract(TheOctadecayottonScript octadecayotton, bool checkForTP, int dimension) { return(Init(octadecayotton, checkForTP, dimension) + (() => { _octadecayotton.ModuleSelectable.AddInteractionPunch(); _octadecayotton.PlaySound(Sounds.Oct.InteractInterrupt); if (!isActive || _octadecayotton.IsSolved) { return false; } if (isRotating) { isSubmitting = true; } return HandleSubmission(); })); }
internal KMSelectable.OnInteractHandler Init(TheOctadecayottonScript octadecayotton, bool checkForTP, int dimension) { return(() => { if (isStarting || isActive || octadecayotton.IsSolved || (checkForTP && octadecayotton.TwitchPlaysActive)) { return true; } isStarting = true; rotationProgress = 0; _octadecayotton = octadecayotton; _animate = new Animate(this, _octadecayotton); _moduleId = octadecayotton.moduleId; isUsingBounce = octadecayotton.isUsingBounce; if (octadecayotton.DimensionOverride != default(byte)) { octadecayotton.dimensionOverride = octadecayotton.DimensionOverride; } if (Dimension == 0) { TheOctadecayottonScript.Activated++; } Dimension = _octadecayotton.dimensionOverride == 0 ? dimension + TheOctadecayottonScript.Activated : octadecayotton.dimensionOverride; StartCoroutine(_animate.CreateHypercube(Dimension)); octadecayotton.PlaySound(Dimension > 9 ? Sounds.Oct.StartupHard : Sounds.Oct.Startup); octadecayotton.ModuleSelectable.AddInteractionPunch(Dimension > 9 ? 64 : 32); Rotations = !Application.isEditor || octadecayotton.ForceRotation.IsNullOrEmpty() ? TheOctadecayottonExtensions.GetRandomRotations(new RotationOptions(dimension: Dimension, rotationCount: octadecayotton.RotationOverride != default(byte) ? octadecayotton.RotationOverride : octadecayotton.rotation)) : octadecayotton.ForceRotation.ToRotations(); Debug.LogFormat("[The Octadecayotton #{0}]: Initializing with {1} dimensions and {2} rotation{3}.", _moduleId, Dimension, octadecayotton.rotation, octadecayotton.rotation == 1 ? "" : "s"); Debug.LogFormat("[The Octadecayotton #{0}]: NOTE: Rotations are cyclic, meaning that +X-Y+Z is the same as -Y+Z+X and +Z+X-Y! Commas (,) separate different subrotations, and ampersands (&) separate different rotations.", _moduleId); Debug.LogFormat("[The Octadecayotton #{0}]: The rotation{1} {2}.", _moduleId, octadecayotton.rotation == 1 ? " is" : "s are", Rotations.ToLog()); AnchorSphere = Rotations.Get(Dimension, _moduleId); Debug.LogFormat("[The Octadecayotton #{0}]: The anchor sphere is in {1}. ({2}-ordered)", _moduleId, AnchorSphere.Select(a => a.Value ? "+" : "-").Join(""), _allAxes.Substring(0, Dimension)); CreateStartingSphere(); Debug.LogFormat("[The Octadecayotton #{0}]: To solve this module, press anywhere to enter submission, submit the digits from left-to-right when the {1} matches the digit shown, then submit on every digit from {2} down to 0.", _moduleId, Dimension > 10 ? "timer modulo 20" : "last digit of the timer", Dimension - 1); Debug.LogFormat("[The Octadecayotton #{0}]: Example full solution (not knowing axes) => {1}.", _moduleId, startingSphere.GetAnswer(AnchorSphere, _axesUsed, _order, true).Select(i => i.Join(Dimension > 9 ? " " : "")).Join(", ")); Debug.LogFormat("[The Octadecayotton #{0}]: Quickest solution (knowing axes) => {1}.", _moduleId, startingSphere.GetAnswer(AnchorSphere, _axesUsed, _order, false).Select(i => i.Join(Dimension > 9 ? " " : "")).Join(", ")); return true; }); }
internal IEnumerator CreateHypercube(int dimension) { _interact.Spheres = new List <SphereScript>(); for (int i = 0; i < Math.Pow(2, dimension); i++) { var instance = UnityEngine.Object.Instantiate(_interact.Sphere, _interact.Polygon.transform, false).GetComponent <SphereScript>(); instance.gameObject.SetActive(true); instance.pos = new Position(deviations: new[] { Rnd.Range(-1f, 1f), Rnd.Range(-1f, 1f), Rnd.Range(-1f, 1f) }, stretchToFit: _octadecayotton.stretchToFit); instance.pos.SetDimensions(Convert.ToString(i, 2).PadLeft(dimension, '0').Select(c => float.Parse(c.ToString())).ToArray()); instance.Interact = _interact; float f = 100f / Mathf.Pow(dimension, 2); instance.Sphere.transform.localScale = new Vector3(f, f, f); _interact.Spheres.Add(instance); for (int j = 0; dimension > 9 ? i % (dimension - 8) == 0 && j == 0 && i > Math.Pow(2, dimension) / 3 : j < Math.Pow(2, 9 - dimension) && i > Math.Pow(2, dimension) / 4; j += 4) { float progress = 1 - ((i / (float)Math.Pow(2, dimension)) + (j / (float)Math.Pow(2, 9 - dimension) / (float)Math.Pow(2, dimension))); byte b = (byte)(progress * 255); _interact.ModuleRenderer.material.color = new Color32(b, b, b, 255); for (int k = 0; k < _interact.Spheres.Count; k++) { var sphere = _interact.Spheres[k]; sphere.transform.localPosition = sphere.pos.MergeDimensions(new Vector3( Rnd.Range(-0.01f, 0.01f) + 0.5f, Rnd.Range(-0.01f, 0.01f) + 0.5f, Rnd.Range(-0.01f, 0.01f) + 0.5f), progress.ElasticInOut()); } if (!(dimension == 8 && i % 2 != 0 || dimension == 9 && i % 4 != 0)) { yield return(new WaitForSecondsRealtime(0.02f)); } } } _interact.ModuleRenderer.material.mainTexture = _interact.EvilTexture; for (byte i = 5; i >= 5; i += 5) { _interact.ModuleRenderer.material.color = new Color32(i, i, i, 255); yield return(new WaitForSecondsRealtime(0.02f)); } _interact.isRotating = !(_interact.isSubmitting = _interact.Rotations.Length == 0); _interact.isActive = true; _interact.isStarting = false; foreach (var sphere in _interact.Spheres) { sphere.Light.enabled = false; if (_octadecayotton.colorAssist) { sphere.SphereRenderer.material.color = new Color(sphere.transform.localPosition.x, sphere.transform.localPosition.y, sphere.transform.localPosition.z); sphere.SphereRenderer.material.shader = _interact.AssistShader; } } if (_interact.isSubmitting) { _octadecayotton.PlaySound(Sounds.Oct.StartingSphere); for (int i = 0; i < _interact.Spheres.Count; i++) { _interact.Spheres[i].StartCoroutine(_interact.Spheres[i].UpdateValue()); } } }