public void Awake() { Bomb = GetComponent <Bomb>(); holdable = Bomb.GetComponentInChildren <FloatingHoldable>(); timerComponent = Bomb.GetTimer(); widgetManager = Bomb.WidgetManager; holdable.OnLetGo += () => BombStatus.Instance.currentBomb = null; Color modeColor = ModeColors[Tweaks.CurrentMode]; BombStatus.Instance.TimerPrefab.color = modeColor; timerComponent.text.color = modeColor; timerComponent.StrikeIndicator.RedColour = modeColor; if (Tweaks.CurrentMode == Mode.Zen) { ZenModeTimePenalty = Mathf.Abs(Modes.settings.ZenModeTimePenalty); ZenModeTimerRate = -timerComponent.GetRate(); timerComponent.SetRateModifier(ZenModeTimerRate); Modes.initialTime = timerComponent.TimeRemaining; //This was in the original code to make sure the bomb didn't explode on the first strike Bomb.NumStrikesToLose++; } realTimeStart = Time.unscaledTime; BombEvents.OnBombDetonated += OnDetonate; BombEvents.OnBombSolved += OnSolve; foreach (BombComponent component in Bomb.BombComponents) { Dictionary <string, object> makeEventInfo(string type) { Dictionary <string, object> eventInfo = new Dictionary <string, object>() { { "type", type }, { "moduleID", Modes.GetModuleID(component) }, { "bombTime", CurrentTimer }, { "realTime", Time.unscaledTime - realTimeStart }, }; if (componentIDs.TryGetValue(component, out int loggingID)) { eventInfo["loggingID"] = loggingID; } return(eventInfo); } component.OnPass += delegate { BombStatus.Instance.UpdateSolves(); var eventInfo = makeEventInfo("PASS"); if (Tweaks.CurrentMode == Mode.Time) { if ( !Modes.settings.ComponentValues.TryGetValue(Modes.GetModuleID(component), out double ComponentValue) && !Modes.DefaultComponentValues.TryGetValue(Modes.GetModuleID(component), out ComponentValue) ) { ComponentValue = 10; } if ( !Modes.settings.TotalModulesMultiplier.TryGetValue(Modes.GetModuleID(component), out double totalModulesMultiplier) && !Modes.DefaultTotalModulesMultiplier.TryGetValue(Modes.GetModuleID(component), out totalModulesMultiplier) ) { totalModulesMultiplier = 0; } var modules = Bomb.GetSolvableComponentCount(); var points = ComponentValue + modules * totalModulesMultiplier; float finalMultiplier = Mathf.Min(Modes.Multiplier, Modes.settings.TimeModeMaxMultiplier); float time = (float)(points * finalMultiplier * Modes.settings.TimeModePointMultiplier); float finalTime = Math.Max(Modes.settings.TimeModeMinimumTimeGained, time); // Show the alert string alertText = ""; if (Math.Round(totalModulesMultiplier, 3) != 0) { alertText += $"{ComponentValue} + {totalModulesMultiplier:0.###} <size=36>x</size> {modules} mods = {points:0}\n"; } string multiplierText = Math.Round(Modes.settings.TimeModePointMultiplier, 3) == 1 ? "" : $"<size=36>x</size> {Modes.settings.TimeModePointMultiplier:0.###} "; alertText += $"{points:0} points <size=36>x</size> {finalMultiplier:0.#} {multiplierText}= {(time > 0 ? "+" : "")}{time.FormatTime()}\n"; if (time < Modes.settings.TimeModeMinimumTimeGained) { alertText += $"Min Time Added = {(finalTime > 0 ? "+" : "")}{finalTime.FormatTime()}\n"; } eventInfo["timeMode"] = alertText.TrimEnd('\n').Replace("<size=36>x</size>", "×"); // Build the logging information for time mode. alertText += component.GetModuleDisplayName(); AddAlert(alertText.Replace(' ', ' '), Color.green); // Replace all spaces with nbsp since we don't want the line to wrap. CurrentTimer += finalTime; Modes.Multiplier += Modes.settings.TimeModeSolveBonus; BombStatus.Instance.UpdateMultiplier(); } Tweaks.LogJSON("LFAEvent", eventInfo); return(false); }; var OnStrike = component.OnStrike; component.OnStrike = (BombComponent source) => { var eventInfo = makeEventInfo("STRIKE"); if (Tweaks.CurrentMode == Mode.Time) { float multiplier = Modes.Multiplier - Modes.settings.TimeModeMultiplierStrikePenalty; float finalMultiplier = Math.Max(multiplier, Modes.settings.TimeModeMinMultiplier); // Show the alert string alertText = $"TIME LOST = {Modes.settings.TimeModeTimerStrikePenalty:0.###} <size=36>x</size> {CurrentTimer.FormatTime()} = {(CurrentTimer * Modes.settings.TimeModeTimerStrikePenalty).FormatTime()}\n"; alertText += $"MULTIPIER = {Modes.Multiplier:0.#} - {Modes.settings.TimeModeMultiplierStrikePenalty:0.#} = {multiplier:0.#}\n"; if (multiplier < Modes.settings.TimeModeMinMultiplier) { alertText += $"REDUCED TO MIN = {finalMultiplier}\n"; } eventInfo["timeMode"] = alertText.TrimEnd('\n').Replace("<size=36>x</size>", "×"); // Build the logging information for time mode. alertText += component.GetModuleDisplayName(); AddAlert(alertText.Replace(' ', ' '), Color.red); Modes.Multiplier = finalMultiplier; BombStatus.Instance.UpdateMultiplier(); if (CurrentTimer < (Modes.settings.TimeModeMinimumTimeLost / Modes.settings.TimeModeTimerStrikePenalty)) { CurrentTimer -= Modes.settings.TimeModeMinimumTimeLost; } else { CurrentTimer -= CurrentTimer * Modes.settings.TimeModeTimerStrikePenalty; } // We can safely set the number of strikes to -1 since it's going to be increased by the game after us. Bomb.NumStrikes = -1; } OnStrike(source); // These mode modifications need to happen after the game handles the strike since they change the timer rate. if (Tweaks.CurrentMode == Mode.Zen) { Bomb.NumStrikesToLose++; ZenModeTimerRate = Mathf.Max(ZenModeTimerRate - Mathf.Abs(Modes.settings.ZenModeTimerSpeedUp), -Mathf.Abs(Modes.settings.ZenModeTimerMaxSpeed)); timerComponent.SetRateModifier(ZenModeTimerRate); CurrentTimer += ZenModeTimePenalty * 60; ZenModeTimePenalty += Mathf.Abs(Modes.settings.ZenModeTimePenaltyIncrease); } if (Tweaks.CurrentMode == Mode.Steady) { timerComponent.SetRateModifier(1); CurrentTimer -= Modes.settings.SteadyModeFixedPenalty * 60 - Modes.settings.SteadyModePercentPenalty * BombStartingTimer; } BombStatus.Instance.UpdateStrikes(); Tweaks.LogJSON("LFAEvent", eventInfo); return(false); }; } var moduleTweaks = new Dictionary <string, Func <BombComponent, ModuleTweak> >() { { "Emoji Math", bombComponent => new EmojiMathLogging(bombComponent) }, { "Probing", bombComponent => new ProbingLogging(bombComponent) }, { "SeaShells", bombComponent => new SeaShellsLogging(bombComponent) }, { "WordScrambleModule", bombComponent => new WordScramblePatch(bombComponent) }, { "Color Decoding", bombComponent => new ColorDecodingTweak(bombComponent) }, { "TurnTheKeyAdvanced", bombComponent => new TTKSTweak(bombComponent) }, { "Wires", bombComponent => new WiresLogging(bombComponent) }, { "Keypad", bombComponent => new KeypadLogging(bombComponent) } }; modules = new string[Bomb.Faces.Sum(face => face.Anchors.Count)]; anchors = new decimal[Bomb.Faces.Sum(face => face.Anchors.Count)][]; bombLogInfo = new Dictionary <string, object>() { { "serial", JsonConvert.DeserializeObject <Dictionary <string, string> >(Bomb.WidgetManager.GetWidgetQueryResponses(KMBombInfo.QUERYKEY_GET_SERIAL_NUMBER, null)[0])["serial"] }, { "displayNames", displayNames }, { "ids", ids }, { "anchors", anchors }, { "modules", modules }, { "timestamp", DateTime.Now.ToString("O") } }; modulesUnactivated = Bomb.BombComponents.Count; foreach (BombComponent component in Bomb.BombComponents) { KMBombModule bombModule = component.GetComponent <KMBombModule>(); if (bombModule != null && (bombModule.ModuleType == "TurnTheKey" || Tweaks.settings.ModuleTweaks)) { switch (bombModule.ModuleType) { // TTK is our favorite Zen mode compatible module // Of course, everything here is repurposed from Twitch Plays. case "TurnTheKey": new TTKComponentSolver(component, bombModule, Tweaks.CurrentMode.Equals(Mode.Zen) ? Modes.initialTime : timerComponent.TimeRemaining); break; // Correct some mispositioned objects in older modules case "ForeignExchangeRates": case "resistors": case "CryptModule": case "LEDEnc": // This fixes the position of the module itself (but keeps the status light in its original location, which fixes it) component.transform.Find("Model").transform.localPosition = new Vector3(0.004f, 0, 0); break; case "Listening": // This fixes the Y-coordinate of the position of the status light component.transform.Find("StatusLight").transform.localPosition = new Vector3(-0.0761f, 0.01986f, 0.075f); break; case "TwoBits": case "errorCodes": case "primeEncryption": case "memorableButtons": case "babaIsWho": case "colorfulDials": case "scalarDials": // This fixes the position of the status light component.GetComponentInChildren <StatusLightParent>().transform.localPosition = new Vector3(0.075167f, 0.01986f, 0.076057f); break; case "tWords": case "moon": case "sun": case "jewelVault": // This fixes the scale of the light components component.GetComponentInChildren <Light>().range *= component.transform.lossyScale.x; break; } // This fixes the position of the highlight switch (bombModule.ModuleType) { case "babaIsWho": case "needlesslyComplicatedButton": component.GetComponent <Selectable>().Highlight.transform.localPosition = Vector3.zero; break; } } ModuleTweak moduleTweak = null; string moduleType = bombModule != null ? bombModule.ModuleType : component.ComponentType.ToString(); if (moduleTweaks.ContainsKey(moduleType) && (moduleType != "WordScrambleModule" || Tweaks.settings.ModuleTweaks)) { moduleTweak = moduleTweaks[moduleType](component); } component.StartCoroutine(GetModuleInformation(component, moduleTweak)); if (component.ComponentType == ComponentTypeEnum.Mod || component.ComponentType == ComponentTypeEnum.NeedyMod) { ReflectedTypes.FindModeBoolean(component); } else if (Tweaks.settings.ModuleTweaks) { switch (component.ComponentType) { case ComponentTypeEnum.Keypad: Tweaks.FixKeypadButtons(((KeypadComponent)component).buttons); break; case ComponentTypeEnum.Simon: Tweaks.FixKeypadButtons(((SimonComponent)component).buttons); break; case ComponentTypeEnum.Password: Tweaks.FixKeypadButtons(component.GetComponentsInChildren <KeypadButton>()); break; case ComponentTypeEnum.NeedyVentGas: Tweaks.FixKeypadButtons(((NeedyVentComponent)component).YesButton, ((NeedyVentComponent)component).NoButton); break; } } } }
public BombWrapper(Bomb bomb) { Bomb = bomb; holdable = bomb.GetComponentInChildren <FloatingHoldable>(); timerComponent = bomb.GetTimer(); widgetManager = bomb.WidgetManager; Color modeColor = ModeColors[Tweaks.CurrentMode]; BombStatus.Instance.TimerPrefab.color = modeColor; timerComponent.text.color = modeColor; timerComponent.StrikeIndicator.RedColour = modeColor; if (Tweaks.CurrentMode == Mode.Zen) { ZenModeTimePenalty = Mathf.Abs(Modes.settings.ZenModeTimePenalty); ZenModeTimerRate = -timerComponent.GetRate(); timerComponent.SetRateModifier(ZenModeTimerRate); Modes.initialTime = timerComponent.TimeRemaining; //This was in the original code to make sure the bomb didn't explode on the first strike bomb.NumStrikesToLose++; } foreach (BombComponent component in Bomb.BombComponents) { component.OnPass += delegate { BombStatus.Instance.UpdateSolves(); if (Tweaks.CurrentMode == Mode.Time) { if (!Modes.settings.ComponentValues.TryGetValue(Modes.GetModuleID(component), out double ComponentValue)) { ComponentValue = 6; } Modes.settings.TotalModulesMultiplier.TryGetValue(Modes.GetModuleID(component), out double totalModulesMultiplier); float time = (float)(Mathf.Min(Modes.Multiplier, Modes.settings.TimeModeMaxMultiplier) * (ComponentValue + Bomb.BombComponents.Count * totalModulesMultiplier)); CurrentTimer += Math.Max(Modes.settings.TimeModeMinimumTimeGained, time); Modes.Multiplier += Modes.settings.TimeModeSolveBonus; BombStatus.Instance.UpdateMultiplier(); } return(false); }; var OnStrike = component.OnStrike; component.OnStrike = (BombComponent source) => { if (Tweaks.CurrentMode == Mode.Time) { Modes.Multiplier = Math.Max(Modes.Multiplier - Modes.settings.TimeModeMultiplierStrikePenalty, Modes.settings.TimeModeMinMultiplier); BombStatus.Instance.UpdateMultiplier(); if (CurrentTimer < (Modes.settings.TimeModeMinimumTimeLost / Modes.settings.TimeModeTimerStrikePenalty)) { CurrentTimer -= Modes.settings.TimeModeMinimumTimeLost; } else { CurrentTimer -= CurrentTimer * Modes.settings.TimeModeTimerStrikePenalty; } // We can safely set the number of strikes to -1 since it's going to be increased by the game after us. Bomb.NumStrikes = -1; } OnStrike(source); // These mode modifications need to happen after the game handles the strike since they change the timer rate. if (Tweaks.CurrentMode == Mode.Zen) { bomb.NumStrikesToLose++; ZenModeTimerRate = Mathf.Max(ZenModeTimerRate - Mathf.Abs(Modes.settings.ZenModeTimerSpeedUp), -Mathf.Abs(Modes.settings.ZenModeTimerMaxSpeed)); timerComponent.SetRateModifier(ZenModeTimerRate); CurrentTimer += ZenModeTimePenalty * 60; ZenModeTimePenalty += Mathf.Abs(Modes.settings.ZenModeTimePenaltyIncrease); } if (Tweaks.CurrentMode == Mode.Steady) { timerComponent.SetRateModifier(1); CurrentTimer -= Modes.settings.SteadyModeFixedPenalty * 60 - Modes.settings.SteadyModePercentPenalty * bombStartingTimer; } BombStatus.Instance.UpdateStrikes(); return(false); }; } var moduleTweaks = new Dictionary <string, Func <BombComponent, ModuleTweak> >() { { "Emoji Math", bombComponent => new EmojiMathLogging(bombComponent) }, { "Probing", bombComponent => new ProbingLogging(bombComponent) }, { "SeaShells", bombComponent => new SeaShellsLogging(bombComponent) }, { "switchModule", bombComponent => new SwitchesLogging(bombComponent) }, { "WordScrambleModule", bombComponent => new WordScramblePatch(bombComponent) }, { "Wires", bombComponent => new WiresLogging(bombComponent) }, { "Keypad", bombComponent => new KeypadLogging(bombComponent) }, }; modules = new string[bomb.Faces.Sum(face => face.Anchors.Count)]; bombLogInfo = new Dictionary <string, object>() { { "serial", JsonConvert.DeserializeObject <Dictionary <string, string> >(bomb.WidgetManager.GetWidgetQueryResponses(KMBombInfo.QUERYKEY_GET_SERIAL_NUMBER, null)[0])["serial"] }, { "displayNames", displayNames }, { "ids", ids }, { "case", bomb.gameObject.name.Replace("(Clone)", "") }, { "modules", modules } }; modulesUnactivated = bomb.BombComponents.Count; foreach (BombComponent component in bomb.BombComponents) { component.StartCoroutine(GetModuleInformation(component)); KMBombModule bombModule = component.GetComponent <KMBombModule>(); if (bombModule != null) { switch (bombModule.ModuleType) { //TTK is our favorite Zen mode compatible module //Of course, everything here is repurposed from Twitch Plays. case "TurnTheKey": new TTKComponentSolver(bombModule, bomb, Tweaks.CurrentMode.Equals(Mode.Zen) ? Modes.initialTime : timerComponent.TimeRemaining); break; // Correct some mispositioned objects in older modules case "ForeignExchangeRates": case "resistors": case "CryptModule": case "LEDEnc": // This fixes the position of the module itself (but keeps the status light in its original location, which fixes it) component.transform.Find("Model").transform.localPosition = new Vector3(0.004f, 0, 0); break; case "Listening": // This fixes the Y-coordinate of the position of the status light component.transform.Find("StatusLight").transform.localPosition = new Vector3(-0.0761f, 0.01986f, 0.075f); break; case "TwoBits": case "errorCodes": // This fixes the position of the status light component.GetComponentInChildren <StatusLightParent>().transform.localPosition = new Vector3(0.075167f, 0.01986f, 0.076057f); break; } } string moduleType = bombModule != null ? bombModule.ModuleType : component.ComponentType.ToString(); if (moduleTweaks.ContainsKey(moduleType)) { moduleTweaks[moduleType](component); } if (component.ComponentType == ComponentTypeEnum.Mod) { ReflectedTypes.FindModeBoolean(component); } } }