From f1b05d35b0973e9d949121ca490ff4ca815b45b1 Mon Sep 17 00:00:00 2001 From: Gurge44 Date: Thu, 16 May 2024 19:49:35 +0200 Subject: [PATCH] Finish everything & fix stuff with Rogue --- EHR.csproj | 2 +- EHR.sln.DotSettings | 2 +- Modules/CustomTeamManager.cs | 34 ++++++++------------ Modules/DisableDevice.cs | 53 +++++++++++++++--------------- Modules/OptionItem/OptionItem.cs | 12 ++----- Modules/Utils.cs | 6 ++-- Patches/ControlPatch.cs | 5 --- Patches/IntroPatch.cs | 4 +-- Patches/OnGameStartedPatch.cs | 1 - Resources/Lang/en_US.json | 5 +-- Roles/Neutral/Rogue.cs | 55 +++++++++++++++++++++----------- 11 files changed, 91 insertions(+), 88 deletions(-) diff --git a/EHR.csproj b/EHR.csproj index c8b480084..8293250d8 100644 --- a/EHR.csproj +++ b/EHR.csproj @@ -7,7 +7,7 @@ EHR Gurge44 preview - E:\Program Files\AmongUs + D:\Epic Games\AmongUs true True $(MSBuildProjectName) diff --git a/EHR.sln.DotSettings b/EHR.sln.DotSettings index 6cb2b2d76..e06d7de04 100644 --- a/EHR.sln.DotSettings +++ b/EHR.sln.DotSettings @@ -1,7 +1,7 @@  - VISIBLE_FILES + SOLUTION AU CD CK diff --git a/Modules/CustomTeamManager.cs b/Modules/CustomTeamManager.cs index f5dadedc9..06c37c243 100644 --- a/Modules/CustomTeamManager.cs +++ b/Modules/CustomTeamManager.cs @@ -20,13 +20,7 @@ namespace EHR.Modules try { if (!File.Exists("./EHR_DATA/CTA_Data.txt")) return; - - CustomTeams.Clear(); - // ReSharper disable once ObjectCreationAsStatement -#pragma warning disable CA1806 - File.ReadAllLines("./EHR_DATA/CTA_Data.txt").Do(x => new CustomTeam(x)); -#pragma warning restore CA1806 - + CustomTeams = File.ReadAllLines("./EHR_DATA/CTA_Data.txt").Select(x => new CustomTeam(x)).ToHashSet(); RefreshCustomOptions(); } catch (Exception e) @@ -35,23 +29,21 @@ namespace EHR.Modules } } - public static void RefreshCustomOptions() + private static void RefreshCustomOptions() { - CustomTeamOptions.ForEach(x => x.AllOptions.ForEach(o => OptionItem.Remove(o.Id))); CustomTeamOptions.Clear(); EnabledCustomTeams.Clear(); - const int startId = 649000; + const int startId = 647000; const TabGroup tab = TabGroup.GameSettings; CustomTeamOptions = CustomTeams.Select((x, i) => CreateSetting(x, startId + (6 * i))).ToList(); - OptionSaver.Load(); - EnabledCustomTeams = CustomTeamOptions.Where(x => x.Enabled.GetBool()).Select(x => x.Team).ToHashSet(); + UpdateEnabledTeams(); return; static CustomTeamOptionGroup CreateSetting(CustomTeam team, int id) { - var enabled = BooleanOptionItem.Create(id++, "CTA.TeamEnabled", true, tab); + var enabled = BooleanOptionItem.Create(id++, "CTA.FLAG" + team.TeamName, true, tab); var knowRoles = BooleanOptionItem.Create(id++, "CTA.KnowRoles", true, tab); var winWithOriginalTeam = BooleanOptionItem.Create(id++, "CTA.WinWithOriginalTeam", false, tab); var killEachOther = BooleanOptionItem.Create(id++, "CTA.KillEachOther", false, tab); @@ -59,12 +51,19 @@ namespace EHR.Modules var arrows = BooleanOptionItem.Create(id, "CTA.Arrows", true, tab); CustomTeamOptionGroup group = new(team, enabled, knowRoles, winWithOriginalTeam, killEachOther, guessEachOther, arrows); - group.AllOptions.Skip(1).Do(x => x.SetParent(group.Enabled)); + group.AllOptions.Skip(1).Do(x => x.SetParent(enabled)); group.AllOptions.ForEach(x => x.SetColor(new Color32(215, 227, 84, byte.MaxValue))); + if (ColorUtility.TryParseHtmlString(team.RoleRevealScreenBackgroundColor, out var color)) enabled.SetColor(color); + enabled.RegisterUpdateValueEvent((_, _) => UpdateEnabledTeams()); return group; } } + private static void UpdateEnabledTeams() + { + EnabledCustomTeams = CustomTeamOptions.Where(x => x.Enabled.GetBool()).Select(x => x.Team).ToHashSet(); + } + public static void InitializeCustomTeamPlayers() { if (EnabledCustomTeams.Count == 0) return; @@ -158,11 +157,6 @@ namespace EHR.Modules return setting.GetValue(optionsGroup) as bool? ?? false; } - public static string GetTeamEnabledSettingDisplay(int id) - { - // INCOMPLETE - DO NOT FREAK OUT MR PHGAMING - } - internal class CustomTeam { public readonly string RoleRevealScreenBackgroundColor; @@ -193,7 +187,7 @@ namespace EHR.Modules } } - public List TeamMembers { get; set; } = []; + public List TeamMembers { get; } = []; public override bool Equals(object obj) { diff --git a/Modules/DisableDevice.cs b/Modules/DisableDevice.cs index 80e84fcf1..919bc52dc 100644 --- a/Modules/DisableDevice.cs +++ b/Modules/DisableDevice.cs @@ -155,19 +155,22 @@ public class RemoveDisableDevicesPatch { public static void Postfix() { - if (!Options.DisableDevices.GetBool()) return; + var rogueForce = Rogue.On && Main.PlayerStates.Values.Any(x => x.Role is Rogue { DisableDevices: true }); + if (!Options.DisableDevices.GetBool() && !rogueForce) return; UpdateDisableDevices(); } public static void UpdateDisableDevices() { var player = PlayerControl.LocalPlayer; + var rogueForce = Rogue.On && Main.PlayerStates.Values.Any(x => x.Role is Rogue { DisableDevices: true }); bool ignore = player.Is(CustomRoles.GM) || !player.IsAlive() || (Options.DisableDevicesIgnoreImpostors.GetBool() && player.Is(CustomRoleTypes.Impostor)) || (Options.DisableDevicesIgnoreNeutrals.GetBool() && player.Is(CustomRoleTypes.Neutral)) || (Options.DisableDevicesIgnoreCrewmates.GetBool() && player.Is(CustomRoleTypes.Crewmate)) || (Options.DisableDevicesIgnoreAfterAnyoneDied.GetBool() && GameStates.AlreadyDied); + ignore &= !rogueForce; var admins = Object.FindObjectsOfType(true); var consoles = Object.FindObjectsOfType(true); if (admins == null || consoles == null) return; @@ -175,42 +178,42 @@ public class RemoveDisableDevicesPatch { case 3: case 0: - if (Options.DisableSkeldAdmin.GetBool()) - admins[0].gameObject.GetComponent().enabled = false || ignore; - if (Options.DisableSkeldCamera.GetBool()) - consoles.DoIf(x => x.name == "SurvConsole", x => x.gameObject.GetComponent().enabled = false || ignore); + if (Options.DisableSkeldAdmin.GetBool() || rogueForce) + admins[0].gameObject.GetComponent().enabled = ignore; + if (Options.DisableSkeldCamera.GetBool() || rogueForce) + consoles.DoIf(x => x.name == "SurvConsole", x => x.gameObject.GetComponent().enabled = ignore); break; case 1: - if (Options.DisableMiraHQAdmin.GetBool()) - admins[0].gameObject.GetComponent().enabled = false || ignore; - if (Options.DisableMiraHQDoorLog.GetBool()) - consoles.DoIf(x => x.name == "SurvLogConsole", x => x.gameObject.GetComponent().enabled = false || ignore); + if (Options.DisableMiraHQAdmin.GetBool() || rogueForce) + admins[0].gameObject.GetComponent().enabled = ignore; + if (Options.DisableMiraHQDoorLog.GetBool() || rogueForce) + consoles.DoIf(x => x.name == "SurvLogConsole", x => x.gameObject.GetComponent().enabled = ignore); break; case 2: - if (Options.DisablePolusAdmin.GetBool()) - admins.Do(x => x.gameObject.GetComponent().enabled = false || ignore); - if (Options.DisablePolusCamera.GetBool()) - consoles.DoIf(x => x.name == "Surv_Panel", x => x.gameObject.GetComponent().enabled = false || ignore); - if (Options.DisablePolusVital.GetBool()) - consoles.DoIf(x => x.name == "panel_vitals", x => x.gameObject.GetComponent().enabled = false || ignore); + if (Options.DisablePolusAdmin.GetBool() || rogueForce) + admins.Do(x => x.gameObject.GetComponent().enabled = ignore); + if (Options.DisablePolusCamera.GetBool() || rogueForce) + consoles.DoIf(x => x.name == "Surv_Panel", x => x.gameObject.GetComponent().enabled = ignore); + if (Options.DisablePolusVital.GetBool() || rogueForce) + consoles.DoIf(x => x.name == "panel_vitals", x => x.gameObject.GetComponent().enabled = ignore); break; case 4: admins.Do(x => { if ((Options.DisableAirshipCockpitAdmin.GetBool() && x.name == "panel_cockpit_map") || - (Options.DisableAirshipRecordsAdmin.GetBool() && x.name == "records_admin_map")) - x.gameObject.GetComponent().enabled = false || ignore; + (Options.DisableAirshipRecordsAdmin.GetBool() && x.name == "records_admin_map") || rogueForce) + x.gameObject.GetComponent().enabled = ignore; }); - if (Options.DisableAirshipCamera.GetBool()) - consoles.DoIf(x => x.name == "task_cams", x => x.gameObject.GetComponent().enabled = false || ignore); - if (Options.DisableAirshipVital.GetBool()) - consoles.DoIf(x => x.name == "panel_vitals", x => x.gameObject.GetComponent().enabled = false || ignore); + if (Options.DisableAirshipCamera.GetBool() || rogueForce) + consoles.DoIf(x => x.name == "task_cams", x => x.gameObject.GetComponent().enabled = ignore); + if (Options.DisableAirshipVital.GetBool() || rogueForce) + consoles.DoIf(x => x.name == "panel_vitals", x => x.gameObject.GetComponent().enabled = ignore); break; case 5: - if (Options.DisableFungleCamera.GetBool()) - consoles.DoIf(x => x.name == "BinocularsSecurityConsole", x => x.gameObject.GetComponent().enabled = false || ignore); - if (Options.DisableFungleCamera.GetBool()) - consoles.DoIf(x => x.name == "VitalsConsole", x => x.gameObject.GetComponent().enabled = false || ignore); + if (Options.DisableFungleCamera.GetBool() || rogueForce) + consoles.DoIf(x => x.name == "BinocularsSecurityConsole", x => x.gameObject.GetComponent().enabled = ignore); + if (Options.DisableFungleCamera.GetBool() || rogueForce) + consoles.DoIf(x => x.name == "VitalsConsole", x => x.gameObject.GetComponent().enabled = ignore); break; } } diff --git a/Modules/OptionItem/OptionItem.cs b/Modules/OptionItem/OptionItem.cs index ddd23f6b2..8398b293e 100644 --- a/Modules/OptionItem/OptionItem.cs +++ b/Modules/OptionItem/OptionItem.cs @@ -143,9 +143,9 @@ public abstract class OptionItem // Getter public virtual string GetName(bool disableColor = false, bool console = false) { - if (Name.Contains("CTA.TeamEnabled")) + if (Name.Contains("CTA.FLAG")) { - return Utils.ColorString(NameColor, Translator.GetString(Name, ReplacementDictionary)); + return Utils.ColorString(NameColor, Translator.GetString("CTA.TeamEnabled.Prefix") + Name[8..] + Translator.GetString("CTA.TeamEnabled.Suffix")); } return disableColor ? Translator.GetString(Name, ReplacementDictionary, console) : Utils.ColorString(NameColor, Translator.GetString(Name, ReplacementDictionary)); @@ -275,13 +275,7 @@ public abstract class OptionItem private static readonly List Options = new(1024); public static IReadOnlyDictionary FastOptions => FastOpts; private static readonly Dictionary FastOpts = new(1024); - public static int CurrentPreset { get; set; } - - public static void Remove(int id) - { - Options.RemoveAll(x => x.Id == id); - FastOpts.Remove(id); - } + private static int CurrentPreset { get; set; } #endregion } diff --git a/Modules/Utils.cs b/Modules/Utils.cs index 054396b8f..03808bc88 100644 --- a/Modules/Utils.cs +++ b/Modules/Utils.cs @@ -1835,15 +1835,15 @@ public static class Utils Logger.Info($" Seers: {string.Join(", ", seerList.Select(x => x.GetRealName()))} ---- Targets: {string.Join(", ", targetList.Select(x => x.GetRealName()))}", "NR"); - //seer: Players who can see changes made here - //target: Players subject to changes that seer can see + // seer: Players who can see changes made here + // target: Players subject to changes that seer can see foreach (PlayerControl seer in seerList) { try { if (seer == null || seer.Data.Disconnected || seer.IsModClient()) continue; - string fontSize = "1.6"; + string fontSize = "1.7"; if (isForMeeting && (seer.GetClient().PlatformData.Platform == Platforms.Playstation || seer.GetClient().PlatformData.Platform == Platforms.Switch)) fontSize = "70%"; //Logger.Info("NotifyRoles-Loop1-" + seer.GetNameWithRole().RemoveHtmlTags() + ":START", "NotifyRoles"); diff --git a/Patches/ControlPatch.cs b/Patches/ControlPatch.cs index c07b4d1c3..f03efac7b 100644 --- a/Patches/ControlPatch.cs +++ b/Patches/ControlPatch.cs @@ -33,11 +33,6 @@ internal class ControllerManagerUpdatePatch if (OrGetKeysDown(KeyCode.Alpha1 + i, KeyCode.Keypad1 + i) && OptionShower.Pages.Count >= i + 1) OptionShower.CurrentPage = i; } - - if (GetKeysDown(KeyCode.LeftShift, KeyCode.LeftControl, KeyCode.T)) - { - CustomTeamManager.RefreshCustomOptions(); - } } if (GetKeysDown(KeyCode.LeftShift, KeyCode.LeftControl, KeyCode.X) && Main.CurrentMap == MapNames.Airship) diff --git a/Patches/IntroPatch.cs b/Patches/IntroPatch.cs index 53d12366f..f349225ef 100644 --- a/Patches/IntroPatch.cs +++ b/Patches/IntroPatch.cs @@ -178,7 +178,7 @@ class BeginCrewmatePatch return false; } - if (CustomTeamManager.CustomTeams.Count > 0) + if (CustomTeamManager.EnabledCustomTeams.Count > 0) { var team = CustomTeamManager.GetCustomTeam(PlayerControl.LocalPlayer.PlayerId); if (team != null) @@ -420,7 +420,7 @@ class BeginCrewmatePatch __instance.ImpostorText.text = GetString("SubText.Madmate"); } - if (CustomTeamManager.CustomTeams.Count > 0) + if (CustomTeamManager.EnabledCustomTeams.Count > 0) { var team = CustomTeamManager.GetCustomTeam(PlayerControl.LocalPlayer.PlayerId); if (team != null) diff --git a/Patches/OnGameStartedPatch.cs b/Patches/OnGameStartedPatch.cs index 61d1daf06..fd506d328 100644 --- a/Patches/OnGameStartedPatch.cs +++ b/Patches/OnGameStartedPatch.cs @@ -214,7 +214,6 @@ internal class ChangeRoleSettings SabotageSystemTypeRepairDamagePatch.Initialize(); DoorsReset.Initialize(); GhostRolesManager.Initialize(); - CustomTeamManager.LoadCustomTeams(); RoleBlockManager.Reset(); IRandom.SetInstanceById(Options.RoleAssigningAlgorithm.GetValue()); diff --git a/Resources/Lang/en_US.json b/Resources/Lang/en_US.json index a7edc944e..da724bd1c 100644 --- a/Resources/Lang/en_US.json +++ b/Resources/Lang/en_US.json @@ -78,7 +78,8 @@ "ROT.AddonType.Helpful": "★ Helpful Add-ons", "ROT.AddonType.Harmful": "★ Harmful Add-ons", "ROT.AddonType.Mixed": "★ Mixed Add-ons", - "CTA.TeamEnabled": "Enable {0} Team", + "CTA.TeamEnabled.Prefix": "Enable ", + "CTA.TeamEnabled.Suffix": " ", "CTA.KnowRoles": "Players Know Each Others' Roles", "CTA.WinWithOriginalTeam": "Players Can Win With Their Original Team", "CTA.KillEachOther": "Players Can Kill Each Other", @@ -3415,7 +3416,7 @@ "Rogue.Objective.KillInSpecificRoom": "Kill someone in {0}", "Rogue.Objective.VentXTimes": "Vent {0} times", "Rogue.Objective.CallEmergencyMeeting": "Call an emergency meeting", - "Rogue.Objective.KillSpecificPlayer": " Kill {0}", + "Rogue.Objective.KillSpecificPlayer": "Kill {0}", "Rogue.Objective.KillXTimes": "Kill {0} times", "Rogue.Objective.DontStopWalking": "Don't stop walking", "Rogue.Objective.FixSabotage": "Fix a sabotage", diff --git a/Roles/Neutral/Rogue.cs b/Roles/Neutral/Rogue.cs index 17a334881..ba053d16c 100644 --- a/Roles/Neutral/Rogue.cs +++ b/Roles/Neutral/Rogue.cs @@ -66,7 +66,7 @@ namespace EHR.Neutral } public override void SetKillCooldown(byte id) => Main.AllPlayerKillCooldown[id] = GotRewards.Contains(Reward.DecreasedKillCooldown) ? KillCooldown.GetFloat() / 2f : KillCooldown.GetFloat(); - public override bool CanUseImpostorVentButton(PlayerControl pc) => CanVent.GetBool(); + public override bool CanUseImpostorVentButton(PlayerControl pc) => CurrentTask.Objective == Objective.VentXTimes || CanVent.GetBool(); public override bool CanUseSabotage(PlayerControl pc) => GotRewards.Contains(Reward.Sabotage) || GotRewards.Contains(Reward.Morph); public override void ApplyGameOptions(IGameOptions opt, byte id) @@ -131,20 +131,24 @@ namespace EHR.Neutral public override void OnFixedUpdate(PlayerControl pc) { - if (!DoCheck || !pc.IsAlive() || !GameStates.IsInTask) return; + if (!pc.IsAlive() || !GameStates.IsInTask) return; Count++; if (Count < 30) return; Count = 0; - if (LastPos is null) + if (DoCheck && Moving) { - LastPos = pc.Pos(); - return; - } + if (LastPos is null) + { + LastPos = pc.Pos(); + return; + } - Moving = Vector2.Distance(pc.Pos(), LastPos.Value) >= 0.1f; - LastPos = pc.Pos(); + Moving = Vector2.Distance(pc.Pos(), LastPos.Value) >= 0.1f; + LastPos = pc.Pos(); + if (!Moving) pc.Notify(Utils.ColorString(Color.red, "x")); + } if (MorphCooldown > 0) { @@ -163,8 +167,7 @@ namespace EHR.Neutral { if (CurrentTask.Objective == Objective.CallEmergencyMeeting) { - SetTaskCompleted(); - _ = new LateTask(() => { Utils.SendMessage("\n", RoguePC.PlayerId, Translator.GetString("Rogue.TaskCompleted")); }, 8f, log: false); + SetTaskCompleted(chatMessage: true); } } @@ -176,11 +179,13 @@ namespace EHR.Neutral } } - void SetTaskCompleted() + void SetTaskCompleted(bool chatMessage = false) { CurrentTask.IsCompleted = true; SendRPC(); - Utils.NotifyRoles(SpecifySeer: RoguePC, SpecifyTarget: RoguePC); + + if (chatMessage) _ = new LateTask(() => { Utils.SendMessage("\n", RoguePC.PlayerId, Translator.GetString("Rogue.TaskCompleted")); }, 8f, log: false); + else Utils.NotifyRoles(SpecifySeer: RoguePC, SpecifyTarget: RoguePC); } public override void OnReportDeadBody() @@ -189,7 +194,7 @@ namespace EHR.Neutral if (CurrentTask.Objective == Objective.DontStopWalking && Moving) { - SetTaskCompleted(); + SetTaskCompleted(chatMessage: true); } } @@ -205,10 +210,20 @@ namespace EHR.Neutral GotRewards.Add(CurrentTask.Reward); } - if (CurrentTask.Reward == Reward.HelpfulAddon) + switch (CurrentTask.Reward) { - var addon = Options.GroupedAddons[AddonTypes.Helpful].RandomElement(); - RoguePC.RpcSetCustomRole(addon); + case Reward.HelpfulAddon: + var addon = Options.GroupedAddons[AddonTypes.Helpful].RandomElement(); + RoguePC.RpcSetCustomRole(addon); + break; + case Reward.DecreasedKillCooldown: + RoguePC.ResetKillCooldown(); + RoguePC.SyncSettings(); + RoguePC.SetKillCooldown(); + break; + case Reward.Sabotage when RoguePC.IsHost(): + HudManager.Instance.SetHudActive(RoguePC, RoguePC.Data.Role, true); + break; } var objective = Enum.GetValues().Except(GotObjectives).Shuffle()[0]; @@ -221,7 +236,6 @@ namespace EHR.Neutral Objective.KillXTimes => IRandom.Instance.Next(2, 5), _ => null }; - if (data is int n) RoguePC.SetAbilityUseLimit(n); CurrentTask = (objective, reward, data, false); SendRPC(); @@ -234,6 +248,9 @@ namespace EHR.Neutral DoCheck = true; }, 5f, log: false); } + + Utils.NotifyRoles(SpecifySeer: RoguePC, SpecifyTarget: RoguePC); + Logger.Info($" Objective: {Translator.GetString("Rogue.Objective." + objective)} - Reward: {Translator.GetString("Rogue.Reward." + reward)} - Data: {data}", "Rogue"); } catch (Exception e) { @@ -284,7 +301,7 @@ namespace EHR.Neutral public override string GetSuffix(PlayerControl seer, PlayerControl target, bool isHUD = false, bool isMeeting = false) { - if (seer.PlayerId != RoguePC.PlayerId || seer.PlayerId != target.PlayerId || (target.IsModClient() && !isHUD)) return string.Empty; + if (seer.PlayerId != RoguePC.PlayerId || seer.PlayerId != target.PlayerId || (seer.IsModClient() && !isHUD) || MeetingStates.FirstMeeting) return string.Empty; if (AllTasksCompleted) return Translator.GetString("Rogue.AllTasksCompleted"); if (CurrentTask.IsCompleted) return Translator.GetString("Rogue.TaskCompleted"); @@ -327,4 +344,4 @@ namespace EHR.Neutral ImpostorVision } } -} +} \ No newline at end of file