//Logical initialization void Init() { //Randomize order of ordered int[] ordered = { 6, 2, 3, 4, 5, 1 }; for (int i = 5; i > 0; i--) { int j = Random.Range(0, i + 1); int tmp = ordered[i]; ordered[i] = ordered[j]; ordered[j] = tmp; } //Insert a sun int rng = Random.Range(0, 5); ordered[rng] = 0; sun = Instantiate(light); sun.transform.SetParent(buttons[System.Array.IndexOf(ordered, 0)].transform); sun.transform.localPosition = new Vector3(0f, 0f, 0f); float scalar = transform.lossyScale.x; sun.GetComponent <Light>().range *= scalar; planetPatterns = ordered; Debug.LogFormat("[Nomai #{0}] Initialised with planet order: #0: {1} #1: {2} #2: {4} #3: {3} #4: {5} #5(main): {6}", _moduleId, PATTERNS[ordered[0]], PATTERNS[ordered[1]], PATTERNS[ordered[3]], PATTERNS[ordered[2]], PATTERNS[ordered[4]], PATTERNS[ordered[5]]); //Render planets for (int x = 0; x < buttonRenderers.Length; x++) { buttonRenderers[x].material = buttonMats[planetPatterns[x]]; } mainButtonRenderer.material = buttonMats[planetPatterns[5]]; planetActions = new int[6][] { new int[6] { 1, 1, 1, 1, 1, 1 }, new int[6] { 1, 1, 1, 1, 1, 1 }, new int[6] { 1, 1, 1, 1, 1, 1 }, new int[6] { 1, 1, 1, 1, 1, 1 }, new int[6] { 1, 1, 1, 1, 1, 1 }, new int[6] { 1, 1, 1, 1, 1, 1 } }; //Make all actions valid, except for two per planet for (int i = 0; i < 6; i++) { int a = Random.Range(0, 6); int b = Random.Range(0, 5); if (b == a) { b = 5; } planetActions[i][a] = 0; planetActions[i][b] = 0; } //Make self-actions error for (int i = 0; i < 6; i++) { planetActions[i][i] = -1; } //Add sun int sunPos = -1; for (int i = 0; i < 6; i++) { if (planetPatterns[i] == 0) { sunPos = i; for (int x = 0; x < 6; x++) { planetActions[i][x] = -1; } } } for (int n = 0; n < 5; n++) { int j = n; if (n == sunPos) { j = 5; } planetActions[j][sunPos] = 0; } //Add sixth location int fromPlanet = Random.Range(0, 5); if (fromPlanet == sunPos) { fromPlanet = 5; } int toPlanet = Random.Range(0, 4); if (toPlanet == fromPlanet) { toPlanet = 5; } planetActions[fromPlanet][toPlanet] = 2; if (toPlanet == sunPos) { toPlanet = 4; } //Check each planet is visitable for (int i = 0; i < 5; i++) { int j = i; if (i == sunPos) { j = 5; } int goodNum = 0; for (int k = 0; k < 6; k++) { if (k == sunPos || k == j) { continue; } if (planetActions[k][j] == 1) { goodNum++; } } while (goodNum < 2) { for (int k = 0; k < 5; k++) { if (planetActions[k][j] == 0) { planetActions[k][j] = 1; goodNum++; break; } } } } Debug.LogFormat("[Nomai #{0}] Action table:", _moduleId); Debug.LogFormat("[Nomai #{0}] 0 1 2 3 4 5", _moduleId); int ct = 0; foreach (int[] x in planetActions) { Debug.LogFormat("[Nomai #{6}] {7} [{0} {1} {2} {3} {4} {5}]", x[0].ToString().Replace("-1", "x"), x[1].ToString().Replace("-1", "x"), x[2].ToString().Replace("-1", "x"), x[3].ToString().Replace("-1", "x"), x[4].ToString().Replace("-1", "x"), x[5].ToString().Replace("-1", "x"), _moduleId, ct); ct++; } Debug.LogFormat("[Nomai #{0}] (Row = Planet traveled from | Column = Planet traveled to | x = Not possible | 0 = Strike | 1 = Nothing | 2 = Sixth Location)", _moduleId); //Determine deactivation condition. redo: switch (ordered[5]) { case 1: Regex a = new Regex("[" + KMBombInfoExtensions.GetSerialNumberLetters(Info).Join("") + "]", RegexOptions.IgnoreCase); if (a.Match(KMBombInfoExtensions.GetIndicators(Info).Join("")).Success) { deactMethod = 1; addColorsRandom(-1); } else { deactMethod = 2; //Make sure this method is possible if it occurs. for (int i = 0; i < 6; i++) { if (planetActions[i][5] == 0) { planetActions[i][5] = 1; break; } } addColorsRandom(-1); } break; case 2: if (KMBombInfoExtensions.GetOffIndicators(Info).Count() >= 2) { deactMethod = 3; addColorsRandom(6); } else { deactMethod = 4; //Add colors int next = -1; int count = 0; for (int i = 0; i < 7; i++) { colorActionsLight[i] = Random.Range(0, 5) == 0 ? next++ % 3 + 1 : 0; count += Min(colorActionsLight[i], 1); if (count > 5) { break; } } while (count < 3) { int i = Random.Range(0, 7); if (colorActionsLight[i] == 0) { colorActionsLight[i] = next++ % 3 + 1; count++; } } } break; case 3: if (KMBombInfoExtensions.GetOnIndicators(Info).Count() >= 2) { deactMethod = 5; addColorsRandom(-1); } else { deactMethod = 6; addColorsRandom(-1); } break; case 4: if (KMBombInfoExtensions.GetBatteryCount(Info) >= 3) { deactMethod = 7; addColorsRandom(-1); } else { deactMethod = 8; addColorsRandom(-1); } break; case 5: if (KMBombInfoExtensions.GetBatteryHolderCount(Info) >= 2) { deactMethod = 9; addColorsRandom(sunPos); } else { deactMethod = 10; addColorsRandom(-1); } break; case 6: Regex b = new Regex("[aeiou]", RegexOptions.IgnoreCase); if (b.Match(KMBombInfoExtensions.GetSerialNumberLetters(Info).Join()).Success) { deactMethod = 11; addColorsRandom(6); } else { deactMethod = 12; //Add colors int next = -1; int count = 0; for (int i = 0; i < 7; i++) { colorActionsMain[i] = Random.Range(0, 5) == 0 ? next++ % 3 + 1 : 0; count += Min(colorActionsMain[i], 1); if (count > 5) { break; } } while (count < 3) { int i = Random.Range(0, 7); if (colorActionsMain[i] == 0) { colorActionsMain[i] = next++ % 3 + 1; count++; } } } break; } //Make sure the sun has no interactions which change colors if (colorActionsLight[sunPos] != 0 || colorActionsMain[sunPos] != 0) { goto redo; } //Make sure all colors are present only once bool[] present = new bool[3]; for (int i = 0; i < 7; i++) { if (colorActionsLight[i] != 0) { if (present[colorActionsLight[i] - 1]) { goto redo; } else { present[colorActionsLight[i] - 1] = true; } } if (colorActionsMain[i] != 0) { if (present[colorActionsMain[i] - 1]) { goto redo; } else { present[colorActionsMain[i] - 1] = true; } } } if (present.Contains(false)) { goto redo; } Debug.LogFormat("[Nomai #{0}] Deactivation method: {1}", _moduleId, DEACTMETHODS[deactMethod - 1]); goalColor = Random.Range(1, 4); Debug.LogFormat("[Nomai #{0}] Goal color: {1}", _moduleId, COLORS[goalColor]); Debug.LogFormat("[Nomai #{0}] Color interactions:", _moduleId); for (int i = 0; i < 7; i++) { if (colorActionsLight[i] != 0) { Debug.LogFormat("[Nomai #{0}] Interacting with the status light on {1} causes the timer to turn {2}.", _moduleId, i == 6 ? "the sixth location" : "planet " + i, COLORS[colorActionsLight[i]]); } if (colorActionsMain[i] != 0) { Debug.LogFormat("[Nomai #{0}] Interacting with the main planet on {1} causes the timer to turn {2}.", _moduleId, i == 6 ? "the sixth location" : "planet " + i, COLORS[colorActionsMain[i]]); } } }
// Use this for initialization void Start() { _id = idCounter++; speciesId = UnityEngine.Random.Range(0, CroppedMats.Length - 1); Debug.LogFormat("[Fursona #{0}] Selected species: {1}", _id, NAMES[speciesId]); CroppedRenderer.material = CroppedMats[speciesId]; HeadRenderer.material = HeadMats[speciesId]; EyesRenderer.material = EyesMats[speciesId]; FleshRenderer.material = FleshMats[speciesId]; PrimaryRenderer.material = PrimaryMats[speciesId]; SecondaryRenderer.material = SecondaryMats[speciesId]; TertiaryRenderer.material = TertiaryMats[speciesId]; UpdateColors(); PhysicalSlider[] Sliders = new PhysicalSlider[] { A1, A2, A3, B1, B2, B3, C1, C2, C3, D1, D2, D3, E1, E2, E3, F1, F2, F3 }; foreach (PhysicalSlider Slider in Sliders) { Slider.OnUpdate += UpdateColors; } KMBombInfo info = GetComponent <KMBombInfo>(); int ui = KMBombInfoExtensions.GetOffIndicators(info).Count(); int li = KMBombInfoExtensions.GetOnIndicators(info).Count(); int b = KMBombInfoExtensions.GetBatteryCount(info); int bh = KMBombInfoExtensions.GetBatteryHolderCount(info); int p = KMBombInfoExtensions.GetPortCount(info); int ep = KMBombInfoExtensions.GetPortPlates(info).Count(sa => sa.Length == 0); int s3 = int.Parse(KMBombInfoExtensions.GetSerialNumber(info)[2].ToString()); int s6 = int.Parse(KMBombInfoExtensions.GetSerialNumber(info)[5].ToString()); int pp = KMBombInfoExtensions.GetPortPlates(info).Count(); int sl = KMBombInfoExtensions.GetSerialNumberLetters(info).Count(); int sn = KMBombInfoExtensions.GetSerialNumberNumbers(info).Count(); int m = info.GetModuleIDs().Count; int R = -1, G = -1, B = -1, C = -1, M = -1, Y = -1; switch (speciesId) { case 0: R = li; G = ui; B = b; C = bh; M = p; Y = ep; break; case 1: R = s3; G = s6; B = pp; C = sl; M = sn; Y = m; break; case 2: R = ep; G = m; B = p; C = sn; M = bh; Y = sl; break; case 3: R = sl; G = s3; B = bh; C = li; M = sn; Y = s6; break; case 4: R = p; G = ui; B = m; C = pp; M = ep; Y = b; break; case 5: R = s6; G = b; B = sn; C = ep; M = li; Y = pp; break; case 6: R = bh; G = m; B = s3; C = ui; M = sl; Y = p; break; case 7: R = pp; G = p; B = li; C = sl; M = ep; Y = ui; break; case 8: R = sn; G = s3; B = b; C = m; M = s6; Y = bh; break; case 9: R = ui; G = bh; B = ep; C = s6; M = sl; Y = m; break; case 10: R = li; G = b; B = p; C = s3; M = pp; Y = sn; break; default: break; } int maxId = 0; int[] vals = new int[] { R, G, B, C, M, Y }; for (int i = 1; i < 6; i++) { if (vals[i] >= vals[maxId]) { maxId = i; } } TargetEyeColor = maxId; Debug.LogFormat("[Fursona #{0}] Eye color: {1}; Head color: {2}", _id, COLORNAMES[maxId], COLORNAMES[(maxId + 3) % 6]); }
void Init() { for (int i = 0; i < formulaShow.Length; i++) { formulaShow[i] = Random.value < .5 ? true : false; } AmountGroup.SetActive(false); readChar = (char)Random.Range(65, 91); readColor = Random.Range(0, 8); ReadText.text = "" + readChar; ReadText.color = readColors[readColor]; DebugLog("Displayed letter is " + readColorLogs[readColor] + " " + readChar); int serialSum = KMBombInfoExtensions.GetSerialNumberNumbers(Info).Sum(); int reactionNum = readChar - 65; if (reactionNum > serialSum) { reactionNum -= serialSum; } reactionNum %= 8; chosenReaction = reactions[reactionNum]; productAmount = readColorValues[readColor]; productAmount += KMBombInfoExtensions.GetOffIndicators(Info).Count(); int portCount = KMBombInfoExtensions.GetPortCount(Info); if (portCount > 1) { productAmount *= portCount; } productAmount %= 50; if (productAmount == 0) { productAmount = 50; } productAmount *= 10; productAmount -= KMBombInfoExtensions.GetOnIndicators(Info).Count(); if (productAmount <= 0) { DebugLog("That's a lot of lit indicators. I guess you deserve this."); SolveModule(); return; } if (chosenReaction.Solvent == null) { solventAdded = 100.000m; } DebugLog("Reaction: " + chosenReaction.Product.GetLogString()); DebugLog("Product amount: " + productAmount + "g"); DebugLog("Solvent: " + (chosenReaction.Solvent == null ? "None" : chosenReaction.Solvent.GetLogString())); DebugLog("Required reagents:"); foreach (Compound r in chosenReaction.Reagents) { DebugLog(" - " + chosenReaction.GetReagentAmount(r, productAmount) + r.GetUnit() + " of " + r.GetLogString()); } DebugLog("----------------------------------"); }