From 6f58c9df8b6c8549e0f5051836aab84ba09914c0 Mon Sep 17 00:00:00 2001 From: mxyx0412 Date: Thu, 9 Jan 2025 12:31:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=83=A8=E5=88=86=E6=9B=B4?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .editorconfig | 6 +- TheOtherRoles/Helper/Helpers.cs | 14 ++ TheOtherRoles/Modules/KeyboardHandler.cs | 9 +- .../CreateModOptions.cs} | 90 +++++----- TheOtherRoles/Options/CustomOptionHolder.cs | 4 +- TheOtherRoles/Options/CustomOptions.cs | 61 +++++-- TheOtherRoles/Patches/EndGamePatch.cs | 165 +++++------------- TheOtherRoles/Patches/ExileControllerPatch.cs | 2 +- TheOtherRoles/Roles/RoleHelpers.cs | 1 - 9 files changed, 150 insertions(+), 202 deletions(-) rename TheOtherRoles/{Patches/ClientOptionsPatch.cs => Options/CreateModOptions.cs} (81%) diff --git a/.editorconfig b/.editorconfig index 8d356572..35b791f3 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,10 +1,12 @@ [*.cs] +charset = utf-8 dotnet_diagnostic.IDE0007.severity = silent dotnet_diagnostic.IDE0022.severity = silent dotnet_diagnostic.IDE0023.severity = silent dotnet_diagnostic.IDE0028.severity = none dotnet_diagnostic.IDE0031.severity = silent dotnet_diagnostic.IDE0046.severity = silent +dotnet_diagnostic.IDE0058.severity = silent dotnet_diagnostic.IDE0061.severity = silent dotnet_diagnostic.IDE0305.severity = silent dotnet_diagnostic.IDE1006.severity = silent @@ -16,10 +18,6 @@ dotnet_analyzer_diagnostic.severity = suggestion [*.cs] #### 命名样式 #### - -# IDE0058: -dotnet_diagnostic.IDE0058.severity = silent - # 命名规则 dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion diff --git a/TheOtherRoles/Helper/Helpers.cs b/TheOtherRoles/Helper/Helpers.cs index 95acdf3f..9e15aad4 100644 --- a/TheOtherRoles/Helper/Helpers.cs +++ b/TheOtherRoles/Helper/Helpers.cs @@ -598,6 +598,20 @@ public static bool Contains(this IEnumerable list, T item, Func keySelector(x).Equals(keySelector(item))); } + public static int Count(this Il2CppSystem.Collections.Generic.List list, Func func = null) + { + int count = 0; + foreach (T obj in list) + if (func == null || func(obj)) + count++; + return count; + } + public static Color HexToColor(string hex) + { + _ = ColorUtility.TryParseHtmlString("#" + hex, out var color); + return color; + } + public static string readTextFromResources(string path) { var assembly = Assembly.GetExecutingAssembly(); diff --git a/TheOtherRoles/Modules/KeyboardHandler.cs b/TheOtherRoles/Modules/KeyboardHandler.cs index f3657f3e..f1223c75 100644 --- a/TheOtherRoles/Modules/KeyboardHandler.cs +++ b/TheOtherRoles/Modules/KeyboardHandler.cs @@ -1,19 +1,16 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using TheOtherRoles.Buttons; using TheOtherRoles.Patches; using TheOtherRoles.Utilities; using UnityEngine; -using Random = System.Random; namespace TheOtherRoles.Modules; [HarmonyPatch(typeof(KeyboardJoystick), nameof(KeyboardJoystick.Update))] public class KeyboardHandler { - //private static readonly string passwordHash = "d1f51dfdfd8d38027fd2ca9dfeb299399b5bdee58e6c0b3b5e9a45cd4e502848"; - private static readonly Random random = new((int)DateTime.Now.Ticks); private static readonly List bots = new(); private static void Postfix(KeyboardJoystick __instance) @@ -35,7 +32,7 @@ private static void Postfix(KeyboardJoystick __instance) playerControl.GetComponent().enabled = true; playerControl.NetTransform.enabled = false; playerControl.SetName(RandomString(6)); - playerControl.SetColor((byte)random.Next(Palette.PlayerColors.Length)); + playerControl.SetColor((byte)rnd.Next(Palette.PlayerColors.Length)); GameData.Instance.RpcSetTasks(playerControl.PlayerId, Array.Empty()); } // 强制开始会议或结束会议 @@ -63,7 +60,7 @@ private static void Postfix(KeyboardJoystick __instance) public static string RandomString(int length) { const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; - return new string(Enumerable.Repeat(chars, length).Select(s => s[random.Next(s.Length)]).ToArray()); + return new string(Enumerable.Repeat(chars, length).Select(s => s[rnd.Next(s.Length)]).ToArray()); } } diff --git a/TheOtherRoles/Patches/ClientOptionsPatch.cs b/TheOtherRoles/Options/CreateModOptions.cs similarity index 81% rename from TheOtherRoles/Patches/ClientOptionsPatch.cs rename to TheOtherRoles/Options/CreateModOptions.cs index 96763efa..32b4b9f4 100644 --- a/TheOtherRoles/Patches/ClientOptionsPatch.cs +++ b/TheOtherRoles/Options/CreateModOptions.cs @@ -9,7 +9,7 @@ using static UnityEngine.UI.Button; using Object = UnityEngine.Object; -namespace TheOtherRoles.Patches; +namespace TheOtherRoles.Options; [HarmonyPatch(typeof(OptionsMenuBehaviour), nameof(OptionsMenuBehaviour.Start))] public static class StartOptionMenuPatch @@ -19,50 +19,42 @@ public static void UpdateCustomText(this ToggleButtonBehaviour button, Color col button.onState = false; button.Background.color = color; if (text != null) - { button.Text.text = text; - } if (button.Rollover) - { button.Rollover.ChangeOutColor(color); - } } public static void UpdateToggleText(this ToggleButtonBehaviour button, bool on, string text) { button.onState = on; - Color color = on ? new Color(0f, 1f, 0.16470589f, 1f) : Color.white; + var color = on ? new Color(0f, 1f, 0.16470589f, 1f) : Color.white; button.Background.color = color; button.Text.text = text + ": " + DestroyableSingleton.Instance.GetString(button.onState ? StringNames.SettingsOn : StringNames.SettingsOff, new Il2CppReferenceArray(0)); if (button.Rollover) - { button.Rollover.ChangeOutColor(color); - } } public static void UpdateButtonText(this ToggleButtonBehaviour button, string text, string state) { button.onState = false; - Color color = Color.white; + var color = Color.white; button.Background.color = color; button.Text.text = text + ": " + state; if (button.Rollover) - { button.Rollover.ChangeOutColor(color); - } } - private static ToggleButtonBehaviour AddButton(Vector2 pos, string name, Action onClicked, GameObject nebulaTab, GameObject toggleButtonTemplate) + private static ToggleButtonBehaviour AddButton(int index, string name, Action onClicked, GameObject nebulaTab, GameObject toggleButtonTemplate) { - GameObject button = Object.Instantiate(toggleButtonTemplate, null); + var button = Object.Instantiate(toggleButtonTemplate, null); button.transform.SetParent(nebulaTab.transform); button.transform.localScale = new Vector3(1f, 1f, 1f); - button.transform.localPosition = new Vector3(1.3f * ((pos.x * 2f) - 1f), 1.6f - (0.5f * pos.y), 0f); + button.transform.localPosition = new Vector3(1.3f * (index % 2 * 2 - 1), 1.6f - 0.5f * (index / 2), 0f); button.name = name; - ToggleButtonBehaviour result = button.GetComponent(); - PassiveButton passiveButton = button.GetComponent(); + var result = button.GetComponent(); + var passiveButton = button.GetComponent(); passiveButton.OnClick = new ButtonClickedEvent(); passiveButton.OnClick.AddListener((UnityAction)onClicked); return result; @@ -80,7 +72,7 @@ public static void Postfix(OptionsMenuBehaviour __instance) PassiveButton passiveButton; - //OĿ׷Ӥ + //設定項目を追加する GameObject nebulaTab = new("NebulaTab"); nebulaTab.transform.SetParent(__instance.transform); @@ -92,18 +84,20 @@ public static void Postfix(OptionsMenuBehaviour __instance) keyBindingTab.transform.localScale = new Vector3(1f, 1f, 1f); keyBindingTab.SetActive(false); - GameObject applyButtonTemplate = tabs[1].Content.transform.GetChild(0).FindChild("ApplyButton").gameObject; - GameObject toggleButtonTemplate = tabs[0].Content.transform.FindChild("MiscGroup").FindChild("StreamerModeButton").gameObject; + var applyButtonTemplate = tabs[1].Content.transform.GetChild(0).FindChild("ApplyButton").gameObject; + var toggleButtonTemplate = tabs[0].Content.transform.FindChild("MiscGroup").FindChild("StreamerModeButton").gameObject; + + var buttonIndex = 0; //EnableSoundEffects - enableSoundEffects = AddButton(new Vector2(0, 0), "EnableSoundEffects", () => + enableSoundEffects = AddButton(buttonIndex++, "EnableSoundEffects", () => { enableSoundEffects.UpdateToggleText(!enableSoundEffects.onState, GetString("EnableSoundEffectsText")); ModOption.enableSoundEffects = Main.EnableSoundEffects.Value = enableSoundEffects.onState; }, nebulaTab, toggleButtonTemplate); //ToggleCursor - toggleCursor = AddButton(new Vector2(0, 1), "ToggleCursor", () => + toggleCursor = AddButton(buttonIndex++, "ToggleCursor", () => { enableCursor(false); toggleCursor.UpdateToggleText(!toggleCursor.onState, GetString("ToggleCursorText")); @@ -112,33 +106,33 @@ public static void Postfix(OptionsMenuBehaviour __instance) }, nebulaTab, toggleButtonTemplate); //ShowFPS - showKeyReminder = AddButton(new Vector2(1, 0), "ShowKeyReminder", () => + showFPS = AddButton(buttonIndex++, "ShowFPS", () => { - showKeyReminder.UpdateToggleText(!showKeyReminder.onState, GetString("ShowKeyReminder")); - ModOption.showKeyReminder = Main.ShowKeyReminder.Value = showKeyReminder.onState; + showFPS.UpdateToggleText(!showFPS.onState, GetString("ShowFPS")); + ModOption.showFPS = Main.ShowFPS.Value = showFPS.onState; }, nebulaTab, toggleButtonTemplate); - //ShowFPS - showFPS = AddButton(new Vector2(1, 1), "ShowFPS", () => + //ShowKeyReminder + showKeyReminder = AddButton(buttonIndex++, "ShowKeyReminder", () => { - showFPS.UpdateToggleText(!showFPS.onState, GetString("ShowFPS")); - ModOption.showFPS = Main.ShowFPS.Value = showFPS.onState; + showKeyReminder.UpdateToggleText(!showKeyReminder.onState, GetString("ShowKeyReminder")); + ModOption.showKeyReminder = Main.ShowKeyReminder.Value = showKeyReminder.onState; }, nebulaTab, toggleButtonTemplate); //LocalHats - localHats = AddButton(new Vector2(0, 2), "LocalHats", () => + localHats = AddButton(buttonIndex++, "LocalHats", () => { localHats.UpdateToggleText(!localHats.onState, GetString("LocalHatsText")); ModOption.localHats = Main.LocalHats.Value = localHats.onState; }, nebulaTab, toggleButtonTemplate); - //`굱ƥܥ + //キー割り当てボタン GameObject TextObject; List allKeyBindingButtons = new(); - int selectedKeyBinding = -1; + var selectedKeyBinding = -1; - GameObject defaultButton = Object.Instantiate(applyButtonTemplate, null); + var defaultButton = Object.Instantiate(applyButtonTemplate, null); defaultButton.transform.SetParent(keyBindingTab.transform); defaultButton.transform.localScale = new Vector3(1f, 1f, 1f); defaultButton.transform.localPosition = new Vector3(0f, -2.5f, 0f); @@ -155,9 +149,9 @@ public static void Postfix(OptionsMenuBehaviour __instance) selectedKeyBinding = -1; //_ = SoundManager.Instance.PlaySound(Module.MetaScreen.getSelectClip(), false, 0.8f); - for (int i = 0; i < ModInputManager.allInputs.Count; i++) + for (var i = 0; i < ModInputManager.allInputs.Count; i++) { - ModInputManager.ModInput input = ModInputManager.allInputs[i]; + var input = ModInputManager.allInputs[i]; input.resetToDefault(); allKeyBindingButtons[i].UpdateCustomText(Color.white, GetString("keyBinding." + input.identifier) + ": " + ModInputManager.allKeyCodes[input.keyCode].displayKey); } @@ -166,14 +160,14 @@ public static void Postfix(OptionsMenuBehaviour __instance) foreach (var input in ModInputManager.allInputs) { - int index = allKeyBindingButtons.Count; + var index = allKeyBindingButtons.Count; - GameObject inputButton = Object.Instantiate(toggleButtonTemplate, null); + var inputButton = Object.Instantiate(toggleButtonTemplate, null); inputButton.transform.SetParent(keyBindingTab.transform); inputButton.transform.localScale = new Vector3(1f, 1f, 1f); - inputButton.transform.localPosition = new Vector3(1.3f * ((index % 2 * 2) - 1), 1.5f - (0.5f * (index / 2)), 0f); + inputButton.transform.localPosition = new Vector3(1.3f * (index % 2 * 2 - 1), 1.5f - 0.5f * (index / 2), 0f); inputButton.name = input.identifier; - ToggleButtonBehaviour inputToggleButton = inputButton.GetComponent(); + var inputToggleButton = inputButton.GetComponent(); inputToggleButton.BaseText = 0; inputToggleButton.Text.text = GetString("keyBinding." + input.identifier) + ": " + ModInputManager.allKeyCodes[input.keyCode].displayKey; passiveButton = inputButton.GetComponent(); @@ -197,7 +191,7 @@ public static void Postfix(OptionsMenuBehaviour __instance) allKeyBindingButtons.Add(inputToggleButton); } - GameObject keyBindingButton = Object.Instantiate(applyButtonTemplate, null); + var keyBindingButton = Object.Instantiate(applyButtonTemplate, null); keyBindingButton.transform.SetParent(nebulaTab.transform); keyBindingButton.transform.localScale = new Vector3(1f, 1f, 1f); keyBindingButton.transform.localPosition = new Vector3(0f, -1.5f, 0f); @@ -228,14 +222,12 @@ IEnumerator getEnumerator() if (keyBindingTab.gameObject.active && Input.anyKeyDown && selectedKeyBinding != -1) { - foreach (KeyValuePair entry in ModInputManager.allKeyCodes) + foreach (var entry in ModInputManager.allKeyCodes) { if (!Input.GetKeyDown(entry.Key)) - { continue; - } - ModInputManager.ModInput input = ModInputManager.allInputs[selectedKeyBinding]; + var input = ModInputManager.allInputs[selectedKeyBinding]; input.changeKeyCode(entry.Key); allKeyBindingButtons[selectedKeyBinding].UpdateCustomText(Color.white, GetString("keyBinding." + input.identifier) + ": " + ModInputManager.allKeyCodes[input.keyCode].displayKey); selectedKeyBinding = -1; @@ -256,20 +248,20 @@ IEnumerator getEnumerator() : __instance.StartCoroutine(getEnumerator().WrapToIl2Cpp()); - //֤׷Ӥ + //タブを追加する tabs[^1] = Object.Instantiate(tabs[1], null); - TabGroup nebulaButton = tabs[^1]; + var nebulaButton = tabs[^1]; nebulaButton.gameObject.name = "NebulaButton"; nebulaButton.transform.SetParent(tabs[0].transform.parent); nebulaButton.transform.localScale = new Vector3(1f, 1f, 1f); nebulaButton.Content = nebulaTab; - GameObject textObj = nebulaButton.transform.FindChild("Text_TMP").gameObject; + var textObj = nebulaButton.transform.FindChild("Text_TMP").gameObject; textObj.GetComponent().enabled = false; textObj.GetComponent().text = "modOptionsTitle".Translate(); tabs.Add(Object.Instantiate(tabs[1], null)); - TabGroup keyBindingTabButton = tabs[^1]; + var keyBindingTabButton = tabs[^1]; keyBindingTabButton.gameObject.name = "KeyBindingButton"; keyBindingTabButton.transform.SetParent(tabs[0].transform.parent); keyBindingTabButton.transform.localScale = new Vector3(1f, 1f, 1f); @@ -295,14 +287,14 @@ IEnumerator getEnumerator() float y = tabs[0].transform.localPosition.y, z = tabs[0].transform.localPosition.z; if (tabs.Count == 4) { - for (int i = 0; i < 3; i++) + for (var i = 0; i < 3; i++) { tabs[i].transform.localPosition = new Vector3(1.7f * (i - 1), y, z); } } else if (tabs.Count == 5) { - for (int i = 0; i < 4; i++) + for (var i = 0; i < 4; i++) { tabs[i].transform.localPosition = new Vector3(1.62f * (i - 1.5f), y, z); } diff --git a/TheOtherRoles/Options/CustomOptionHolder.cs b/TheOtherRoles/Options/CustomOptionHolder.cs index 053c383d..2a8d6937 100644 --- a/TheOtherRoles/Options/CustomOptionHolder.cs +++ b/TheOtherRoles/Options/CustomOptionHolder.cs @@ -828,7 +828,7 @@ public static void Load() eraserCanEraseAnyone = Create(10162, Types.Impostor, "eraserCanEraseAnyone", false, eraserSpawnRate); erasercanEraseGuess = Create(10163, Types.Impostor, "erasercanEraseGuess", false, eraserSpawnRate); - poucherSpawnRate = Create(10320, Types.Impostor, cs(Palette.ImpostorRed, "Poucher"), rates, null, true, () => + poucherSpawnRate = Create(10320, Types.Impostor, cs(Palette.ImpostorRed, "Poucher"), rates, null, true, false, () => { if (modifierPoucher.selection > 0) poucherSpawnRate.selection = 0; }); @@ -1272,7 +1272,7 @@ public static void Load() modifierDisperser = Create(40100, Types.Modifier, cs(Palette.ImpostorRed, "Disperser"), rates, null, true); modifierDisperserDispersesToVent = Create(40101, Types.Modifier, "modifierDisperserDispersesToVent", true, modifierDisperser); - modifierPoucher = Create(40370, Types.Modifier, cs(Palette.ImpostorRed, "Poucher"), rates, null, true, () => + modifierPoucher = Create(40370, Types.Modifier, cs(Palette.ImpostorRed, "Poucher"), rates, null, true, false, () => { poucherSpawnRate.selection = 0; }); diff --git a/TheOtherRoles/Options/CustomOptions.cs b/TheOtherRoles/Options/CustomOptions.cs index 64af1343..4def1d35 100644 --- a/TheOtherRoles/Options/CustomOptions.cs +++ b/TheOtherRoles/Options/CustomOptions.cs @@ -48,11 +48,12 @@ public enum CustomOptionType public int selection; public object[] selections; public CustomOptionType type; + public bool isHidden; // Option creation public CustomOption(int id, CustomOptionType type, string name, object[] selections, object defaultValue, - CustomOption parent, bool isHeader, Action onChange = null) + CustomOption parent, bool isHeader, bool isHidden = false, Action onChange = null) { this.id = id; //this.name = parent == null ? name : " - " + name; @@ -64,6 +65,7 @@ public CustomOption(int id, CustomOptionType type, string name, object[] selecti this.isHeader = isHeader; this.type = type; this.onChange = onChange; + this.isHidden = isHidden; selection = 0; if (id != 0) { @@ -75,23 +77,23 @@ public CustomOption(int id, CustomOptionType type, string name, object[] selecti } public static CustomOption Create(int id, CustomOptionType type, string name, string[] selections, - CustomOption parent = null, bool isHeader = false, Action onChange = null) + CustomOption parent = null, bool isHeader = false, bool isHidden = false, Action onChange = null) { - return new CustomOption(id, type, name, selections, "", parent, isHeader, onChange); + return new CustomOption(id, type, name, selections, "", parent, isHeader, isHidden, onChange); } public static CustomOption Create(int id, CustomOptionType type, string name, float defaultValue, float min, - float max, float step, CustomOption parent = null, bool isHeader = false, Action onChange = null) + float max, float step, CustomOption parent = null, bool isHeader = false, bool isHidden = false, Action onChange = null) { List selections = new(); for (var s = min; s <= max; s += step) selections.Add(s); - return new CustomOption(id, type, name, selections.ToArray(), defaultValue, parent, isHeader, onChange); + return new CustomOption(id, type, name, selections.ToArray(), defaultValue, parent, isHeader, isHidden, onChange); } public static CustomOption Create(int id, CustomOptionType type, string name, bool defaultValue, - CustomOption parent = null, bool isHeader = false, Action onChange = null) + CustomOption parent = null, bool isHeader = false, bool isHidden = false, Action onChange = null) { - return new CustomOption(id, type, name, ["optionOff", "optionOn"], defaultValue ? "optionOn" : "optionOff", parent, isHeader, onChange); + return new CustomOption(id, type, name, ["optionOff", "optionOn"], defaultValue ? "optionOn" : "optionOff", parent, isHeader, isHidden, onChange); } // Static behaviour @@ -256,6 +258,7 @@ public void updateSelection(int newSelection) switchPreset(selection); ShareOptionSelections(); // Share all selections } + if (AmongUsClient.Instance?.AmHost == true) GameOptionsMenuUpdatePatch.update = true; } public static byte[] serializeOptions() @@ -345,6 +348,27 @@ public static bool pasteFromClipboard() } } +public static class CustomOptionsExtensions +{ + public static bool IsHidden(this CustomOption option) + { + return option.isHidden; + } + + public static bool IsEnbaled(this CustomOption option) + { + var enabled = true; + var parent = option.parent; + while (parent != null && enabled) + { + enabled = parent.selection != 0; + parent = parent.parent; + } + + return !option.IsHidden() && enabled; + } +} + [HarmonyPatch(typeof(GameOptionsMenu), nameof(GameOptionsMenu.Start))] internal class GameOptionsMenuStartPatch { @@ -482,7 +506,11 @@ private static void createClassicTabs(GameOptionsMenu __instance) if (button == null) continue; var copiedIndex = i; button.OnClick = new Button.ButtonClickedEvent(); - button.OnClick.AddListener((Action)(() => { setListener(settingsHighlightMap, copiedIndex); })); + button.OnClick.AddListener((Action)(() => + { + GameOptionsMenuUpdatePatch.update = true; + setListener(settingsHighlightMap, copiedIndex); + })); } destroyOptions(new List> @@ -629,7 +657,11 @@ private static void createGuesserTabs(GameOptionsMenu __instance) if (button == null) continue; var copiedIndex = i; button.OnClick = new Button.ButtonClickedEvent(); - button.OnClick.AddListener((Action)(() => { setListener(settingsHighlightMap, copiedIndex); })); + button.OnClick.AddListener((Action)(() => + { + GameOptionsMenuUpdatePatch.update = true; + setListener(settingsHighlightMap, copiedIndex); + })); } destroyOptions(new List> @@ -862,8 +894,8 @@ public static void Postfix() [HarmonyPatch(typeof(GameOptionsMenu), nameof(GameOptionsMenu.Update))] internal class GameOptionsMenuUpdatePatch { - private static float timer = 1f; - + //private static float timer = 1f; + public static bool update; public static void Postfix(GameOptionsMenu __instance) { // Return Menu Update if in normal among us settings @@ -871,9 +903,9 @@ public static void Postfix(GameOptionsMenu __instance) if (gameSettingMenu.RegularGameSettings.active || gameSettingMenu.RolesSettings.gameObject.active) return; __instance.GetComponentInParent().ContentYBounds.max = -0.5F + (__instance.Children.Length * 0.55F); - timer += Time.deltaTime; - if (timer < 0.2f) return; - timer = 0f; + //timer += Time.deltaTime; + if (/*timer < 0.2f || */!update) return; + //timer = 0f; var offset = 2.75f; foreach (var option in options) @@ -908,6 +940,7 @@ public static void Postfix(GameOptionsMenu __instance) } } } + update = false; } } diff --git a/TheOtherRoles/Patches/EndGamePatch.cs b/TheOtherRoles/Patches/EndGamePatch.cs index c6ffdc88..9be7abc5 100644 --- a/TheOtherRoles/Patches/EndGamePatch.cs +++ b/TheOtherRoles/Patches/EndGamePatch.cs @@ -543,7 +543,39 @@ public static void Postfix(EndGameManager __instance) } } - // Additional code + // Create a dictionary for win conditions + var winConditionTexts = new Dictionary + { + { WinCondition.Canceled, (Color.gray, "CanceledEnd") }, + { WinCondition.EveryoneDied, (Palette.DisabledGrey, "EveryoneDied") }, + { WinCondition.JesterWin, (Jester.color, "JesterWin") }, + { WinCondition.DoomsayerWin, (Doomsayer.color, "DoomsayerWin") }, + { WinCondition.ArsonistWin, (Arsonist.color, "ArsonistWin") }, + { WinCondition.VultureWin, (Vulture.color, "VultureWin") }, + { WinCondition.LawyerSoloWin, (Lawyer.color, "LawyerSoloWin") }, + { WinCondition.WerewolfWin, (Werewolf.color, "WerewolfWin") }, + { WinCondition.WitnessWin, (Witness.color, "WitnessWin") }, + { WinCondition.JuggernautWin, (Juggernaut.color, "JuggernautWin") }, + { WinCondition.SwooperWin, (Swooper.color, "SwooperWin") }, + { WinCondition.ExecutionerWin, (Executioner.color, "ExecutionerWin") }, + { WinCondition.LoversTeamWin, (Lovers.color, "LoversTeamWin") }, + { WinCondition.LoversSoloWin, (Lovers.color, "LoversSoloWin") }, + { WinCondition.JackalWin, (Jackal.color, "JackalWin") }, + { WinCondition.PavlovsWin, (Pavlovsdogs.color, "PavlovsWin") }, + { WinCondition.AkujoSoloWin, (Akujo.color, "AkujoSoloWin") }, + { WinCondition.AkujoTeamWin, (Akujo.color, "AkujoTeamWin") }, + { WinCondition.MiniLose, (Mini.color, "MiniLose") }, + }; + + var winConditionMappings = new Dictionary + { + { WinCondition.AdditionalLawyerStolenWin, (Lawyer.color, "LawyerStolenWin") }, + { WinCondition.AdditionalLawyerBonusWin, (Lawyer.color, "LawyerBonusWin") }, + { WinCondition.AdditionalPartTimerWin, (PartTimer.color, "PartTimerWin") }, + { WinCondition.AdditionalAlivePursuerWin, (Pursuer.color, "起诉人存活") }, + { WinCondition.AdditionalAliveSurvivorWin, (Survivor.color, "幸存者存活") } + }; + var bonusText = Object.Instantiate(__instance.WinText.gameObject); var position1 = __instance.WinText.transform.position; bonusText.transform.position = new Vector3(position1.x, position1.y - 0.5f, position1.z); @@ -551,139 +583,22 @@ public static void Postfix(EndGameManager __instance) var textRenderer = bonusText.GetComponent(); textRenderer.text = ""; - switch (AdditionalTempData.winCondition) + if (winConditionTexts.TryGetValue(AdditionalTempData.winCondition, out var winText)) { - case WinCondition.Canceled: - textRenderer.text = "CanceledEnd".Translate(); - textRenderer.color = Color.gray; - __instance.BackgroundBar.material.SetColor("_Color", Color.gray); - break; - case WinCondition.EveryoneDied: - textRenderer.text = "EveryoneDied".Translate(); - textRenderer.color = Palette.DisabledGrey; - __instance.BackgroundBar.material.SetColor("_Color", Palette.DisabledGrey); - break; - case WinCondition.JesterWin: - textRenderer.text = "JesterWin".Translate(); - textRenderer.color = Jester.color; - __instance.BackgroundBar.material.SetColor("_Color", Jester.color); - break; - case WinCondition.DoomsayerWin: - textRenderer.text = "DoomsayerWin".Translate(); - textRenderer.color = Doomsayer.color; - __instance.BackgroundBar.material.SetColor("_Color", Doomsayer.color); - break; - case WinCondition.ArsonistWin: - textRenderer.text = "ArsonistWin".Translate(); - textRenderer.color = Arsonist.color; - __instance.BackgroundBar.material.SetColor("_Color", Arsonist.color); - break; - case WinCondition.VultureWin: - textRenderer.text = "VultureWin".Translate(); - textRenderer.color = Vulture.color; - __instance.BackgroundBar.material.SetColor("_Color", Vulture.color); - break; - case WinCondition.LawyerSoloWin: - textRenderer.text = "LawyerSoloWin".Translate(); - textRenderer.color = Lawyer.color; - __instance.BackgroundBar.material.SetColor("_Color", Lawyer.color); - break; - case WinCondition.WerewolfWin: - textRenderer.text = "WerewolfWin".Translate(); - textRenderer.color = Werewolf.color; - __instance.BackgroundBar.material.SetColor("_Color", Werewolf.color); - break; - case WinCondition.WitnessWin: - textRenderer.text = "WitnessWin".Translate(); - textRenderer.color = Witness.color; - __instance.BackgroundBar.material.SetColor("_Color", Witness.color); - break; - case WinCondition.JuggernautWin: - textRenderer.text = "JuggernautWin".Translate(); - textRenderer.color = Juggernaut.color; - __instance.BackgroundBar.material.SetColor("_Color", Juggernaut.color); - break; - case WinCondition.SwooperWin: - textRenderer.text = "SwooperWin".Translate(); - textRenderer.color = Swooper.color; - __instance.BackgroundBar.material.SetColor("_Color", Swooper.color); - break; - case WinCondition.ExecutionerWin: - textRenderer.text = "ExecutionerWin".Translate(); - textRenderer.color = Executioner.color; - __instance.BackgroundBar.material.SetColor("_Color", Executioner.color); - break; - case WinCondition.LoversTeamWin: - textRenderer.text = "LoversTeamWin".Translate(); - textRenderer.color = Lovers.color; - __instance.BackgroundBar.material.SetColor("_Color", Lovers.color); - break; - case WinCondition.LoversSoloWin: - textRenderer.text = "LoversSoloWin".Translate(); - textRenderer.color = Lovers.color; - __instance.BackgroundBar.material.SetColor("_Color", Lovers.color); - break; - case WinCondition.JackalWin: - textRenderer.text = "JackalWin".Translate(); - textRenderer.color = Jackal.color; - __instance.BackgroundBar.material.SetColor("_Color", Jackal.color); - break; - case WinCondition.PavlovsWin: - textRenderer.text = "PavlovsWin".Translate(); - textRenderer.color = Pavlovsdogs.color; - __instance.BackgroundBar.material.SetColor("_Color", Pavlovsdogs.color); - break; - case WinCondition.AkujoSoloWin: - textRenderer.text = "AkujoSoloWin".Translate(); - textRenderer.color = Akujo.color; - __instance.BackgroundBar.material.SetColor("_Color", Akujo.color); - break; - case WinCondition.AkujoTeamWin: - textRenderer.text = "AkujoTeamWin".Translate(); - textRenderer.color = Akujo.color; - __instance.BackgroundBar.material.SetColor("_Color", Akujo.color); - break; - case WinCondition.MiniLose: - textRenderer.text = "MiniLose".Translate(); - textRenderer.color = Mini.color; - break; + textRenderer.text = winText.Item2.Translate(); + textRenderer.color = winText.Item1; + __instance.BackgroundBar.material.SetColor("_Color", winText.Item1); } var winConditionsTexts = new List(); - var pursuerAlive = false; - var survivorAlive = false; foreach (var cond in AdditionalTempData.additionalWinConditions) { - switch (cond) + if (winConditionMappings.TryGetValue(cond, out var mapping)) { - case WinCondition.AdditionalLawyerStolenWin: - winConditionsTexts.Add(cs(Lawyer.color, "LawyerStolenWin".Translate())); - break; - case WinCondition.AdditionalLawyerBonusWin: - winConditionsTexts.Add(cs(Lawyer.color, "LawyerBonusWin".Translate())); - break; - case WinCondition.AdditionalPartTimerWin: - winConditionsTexts.Add(cs(PartTimer.color, "PartTimerWin".Translate())); - break; - case WinCondition.AdditionalAlivePursuerWin: - pursuerAlive = true; - break; - case WinCondition.AdditionalAliveSurvivorWin: - survivorAlive = true; - break; + winConditionsTexts.Add(cs(mapping.Item1, mapping.Item2.Translate())); } } - if (pursuerAlive && survivorAlive) - { - winConditionsTexts.Add($"{cs(Pursuer.color, "起诉人")} & {cs(Survivor.color, "幸存者存活")}"); - } - else - { - if (pursuerAlive) winConditionsTexts.Add(cs(Pursuer.color, "起诉人存活")); - if (survivorAlive) winConditionsTexts.Add(cs(Survivor.color, "幸存者存活")); - } - if (winConditionsTexts.Count == 1) { textRenderer.text += $"\n{winConditionsTexts[0]}"; @@ -1102,7 +1017,7 @@ internal class RPCEndGamePatch { public static void Postfix(ref GameOverReason endReason) { - Message($"游戏结束 {(CustomGameOverReason)endReason}", "RpcEndGame"); + Message($"游戏结束 {(CustomGameOverReason)endReason} {endReason}", "RpcEndGame"); } } diff --git a/TheOtherRoles/Patches/ExileControllerPatch.cs b/TheOtherRoles/Patches/ExileControllerPatch.cs index 9f5c286c..0f3da1c9 100644 --- a/TheOtherRoles/Patches/ExileControllerPatch.cs +++ b/TheOtherRoles/Patches/ExileControllerPatch.cs @@ -262,7 +262,7 @@ private static void WrapUpPostfix(GameData.PlayerInfo exiled) } Witness.target = Witness.killerTarget = null; - if (Vortox.Player.IsAlive()) + if (Vortox.Player.IsAlive() && exiled == null) { Vortox.skipCount++; if (Vortox.skipCount == Vortox.skipMeetingNum) Vortox.triggerImpWin = true; diff --git a/TheOtherRoles/Roles/RoleHelpers.cs b/TheOtherRoles/Roles/RoleHelpers.cs index a58510ce..6896665e 100644 --- a/TheOtherRoles/Roles/RoleHelpers.cs +++ b/TheOtherRoles/Roles/RoleHelpers.cs @@ -16,7 +16,6 @@ public static bool CanSeeRoleInfo { if (PlayerControl.LocalPlayer == Specter.Player) _CanSeeRoleInfo = false; else if (Specter.Player.isLover() && Lovers.otherLover(Specter.Player) == PlayerControl.LocalPlayer) _CanSeeRoleInfo = false; - else if (Akujo.isAkujoTeam(Specter.Player) && Akujo.otherLover(Specter.Player) == PlayerControl.LocalPlayer) _CanSeeRoleInfo = false; else _CanSeeRoleInfo = value; } }