From d4dbc9273a5f73236a8a91e9ce07663295078b89 Mon Sep 17 00:00:00 2001 From: Gurge44 Date: Tue, 14 May 2024 21:22:50 +0200 Subject: [PATCH] Fixes & Improvements & Reverts --- CTA/CustomTeamAssigner/CustomRoles.cs | 1 + EHR.sln.DotSettings | 1 + .../GameOptionsSender/GameOptionsSender.cs | 2 +- .../NormalGameOptionsSender.cs | 2 +- .../PlayerGameOptionsSender.cs | 4 +-- Modules/RoleBasisChanger.cs | 12 +++++++ Patches/ExilePatch.cs | 3 ++ Resources/Lang/en_US.json | 3 +- Roles/Neutral/Patroller.cs | 34 ++++++++++++++++--- main.cs | 4 +-- 10 files changed, 55 insertions(+), 11 deletions(-) diff --git a/CTA/CustomTeamAssigner/CustomRoles.cs b/CTA/CustomTeamAssigner/CustomRoles.cs index 94747d32e..a4a612565 100644 --- a/CTA/CustomTeamAssigner/CustomRoles.cs +++ b/CTA/CustomTeamAssigner/CustomRoles.cs @@ -257,6 +257,7 @@ public enum CustomRoles Mycologist, Necromancer, Opportunist, + Patroller, Pelican, Pestilence, Phantom, diff --git a/EHR.sln.DotSettings b/EHR.sln.DotSettings index b91809f94..6cb2b2d76 100644 --- a/EHR.sln.DotSettings +++ b/EHR.sln.DotSettings @@ -1,6 +1,7 @@  + VISIBLE_FILES AU CD CK diff --git a/Modules/GameOptionsSender/GameOptionsSender.cs b/Modules/GameOptionsSender/GameOptionsSender.cs index c57a16b5a..1cc7801af 100644 --- a/Modules/GameOptionsSender/GameOptionsSender.cs +++ b/Modules/GameOptionsSender/GameOptionsSender.cs @@ -48,7 +48,7 @@ public abstract class GameOptionsSender protected virtual void SendOptionsArray(Il2CppStructArray optionArray) { byte i = 0; - foreach (var logicComponent in GameManager.Instance.LogicComponents.GetFastEnumerator()) + foreach (var logicComponent in GameManager.Instance.LogicComponents) { if (logicComponent.TryCast(out _)) { diff --git a/Modules/GameOptionsSender/NormalGameOptionsSender.cs b/Modules/GameOptionsSender/NormalGameOptionsSender.cs index fc9adbe6f..0b3d14660 100644 --- a/Modules/GameOptionsSender/NormalGameOptionsSender.cs +++ b/Modules/GameOptionsSender/NormalGameOptionsSender.cs @@ -16,7 +16,7 @@ public class NormalGameOptionsSender : GameOptionsSender { if (GameManager.Instance != null && GameManager.Instance.LogicComponents != null && (_logicOptions == null || !GameManager.Instance.LogicComponents.Contains(_logicOptions))) { - foreach (var glc in GameManager.Instance.LogicComponents.GetFastEnumerator()) + foreach (var glc in GameManager.Instance.LogicComponents) if (glc.TryCast(out var lo)) _logicOptions = lo; } diff --git a/Modules/GameOptionsSender/PlayerGameOptionsSender.cs b/Modules/GameOptionsSender/PlayerGameOptionsSender.cs index b23e92f14..c87c986bf 100644 --- a/Modules/GameOptionsSender/PlayerGameOptionsSender.cs +++ b/Modules/GameOptionsSender/PlayerGameOptionsSender.cs @@ -88,7 +88,7 @@ public class PlayerGameOptionsSender(PlayerControl player) : GameOptionsSender var opt = BuildGameOptions(); if (GameManager.Instance?.LogicComponents != null) { - foreach (var com in GameManager.Instance.LogicComponents.GetFastEnumerator()) + foreach (var com in GameManager.Instance.LogicComponents) { if (com.TryCast(out var lo)) lo.SetGameOptions(opt); @@ -105,7 +105,7 @@ public class PlayerGameOptionsSender(PlayerControl player) : GameOptionsSender try { byte i = 0; - foreach (var logicComponent in GameManager.Instance.LogicComponents.GetFastEnumerator()) + foreach (var logicComponent in GameManager.Instance.LogicComponents) { if (logicComponent.TryCast(out _)) { diff --git a/Modules/RoleBasisChanger.cs b/Modules/RoleBasisChanger.cs index a38662cfc..703369ee9 100644 --- a/Modules/RoleBasisChanger.cs +++ b/Modules/RoleBasisChanger.cs @@ -66,6 +66,18 @@ namespace EHR.Modules _ = new LateTask(() => { IsChangeInProgress = false; }, 5f, log: false); } + public static void ChangeBasisToImpostor(this PlayerControl pc) + { + pc.Data.IsDead = true; + GameData.Instance.SetDirty(); + pc.RpcSetRole(RoleTypes.ImpostorGhost); + pc.SyncSettings(); + pc.Data.IsDead = false; + GameData.Instance.SetDirty(); + pc.MarkDirtySettings(); + pc.KillFlash(); + } + [HarmonyPatch(typeof(InnerNetClient), nameof(InnerNetClient.Spawn))] public static class Client_SpawnDisable { diff --git a/Patches/ExilePatch.cs b/Patches/ExilePatch.cs index 1c69d3754..b59b0f294 100644 --- a/Patches/ExilePatch.cs +++ b/Patches/ExilePatch.cs @@ -1,6 +1,7 @@ using System.Linq; using AmongUs.Data; using AmongUs.GameOptions; +using EHR.Modules; using EHR.Roles.AddOns.Crewmate; using EHR.Roles.AddOns.Impostor; using EHR.Roles.Crewmate; @@ -145,6 +146,8 @@ class ExileControllerWrapUpPatch pc.RpcSetCustomRole(CustomRoles.Refugee); pc.SetKillCooldown(); Logger.Warn($"{pc.GetRealName()} is now a Refugee since all Impostors are dead", "Add Refugee"); + + pc.ChangeBasisToImpostor(); } else Logger.Msg("No Player to change to Refugee.", "Add Refugee"); } diff --git a/Resources/Lang/en_US.json b/Resources/Lang/en_US.json index 03e7295a5..8f470bb9c 100644 --- a/Resources/Lang/en_US.json +++ b/Resources/Lang/en_US.json @@ -3137,7 +3137,8 @@ "GamblerGet.HighKCD": "Effect: Higher Kill Cooldown ({0}s)", "Patroller": "Patroller", "PatrollerInfo": "Have Different Boosts in Each Room", - "PatrollerInfoLong": "(Neutrals):\\nAs the Patroller, you have different boosts in each room.\\nAt the start of the game, it gets randomly rolled which boosts you get in which room.\\nKill everyone to win!\\n\\nYou can see your boosts by petting your pet if the setting to use them is on.", + "PatrollerInfoLong": "(Neutrals):\\nAs the Patroller, you have different boosts in each room.\\nAt the start of the game, it gets randomly rolled which boosts you get in which room.\\nAdditionally, you can vent freely from any room once per round.\\nKill everyone to win!\\n\\nYou can see your boosts by petting your pet if the setting to use them is on.", + "PatrollerNotifyNoBoost": "You are now in {0}\\nIn this room, you have <#ff0000>no boosts", "PatrollerNotify": "You are now in {0}\\nIn this room, {1}", "PatrollerBoost.Speed": "you have higher speed", "PatrollerBoost.Vision": "you have higher vision", diff --git a/Roles/Neutral/Patroller.cs b/Roles/Neutral/Patroller.cs index bd82e6ce1..32fc27dc0 100644 --- a/Roles/Neutral/Patroller.cs +++ b/Roles/Neutral/Patroller.cs @@ -13,7 +13,10 @@ namespace EHR.Neutral private static OptionItem KillCooldown; private static OptionItem DecreasedKillCooldown; private static OptionItem IncreasedSpeed; + + private int Count; private PlainShipRoom LastRoom; + private byte PatrollerId; private Dictionary RoomBoosts = []; @@ -41,6 +44,7 @@ namespace EHR.Neutral public override void Add(byte playerId) { On = true; + PatrollerId = playerId; LastRoom = null; RoomBoosts = ShipStatus.Instance.AllRooms @@ -48,13 +52,15 @@ namespace EHR.Neutral .Zip(Enum.GetValues()) .ToDictionary(x => x.Second, x => x.First); + playerId.SetAbilityUseLimit(1); + if (!AmongUsClient.Instance.AmHost) return; if (!Main.ResetCamPlayerList.Contains(playerId)) Main.ResetCamPlayerList.Add(playerId); } public override void SetKillCooldown(byte id) => Main.AllPlayerKillCooldown[id] = Utils.GetPlayerById(id).GetPlainShipRoom() == RoomBoosts[Boost.Cooldown] ? DecreasedKillCooldown.GetFloat() : KillCooldown.GetFloat(); - public override bool CanUseImpostorVentButton(PlayerControl pc) => pc.GetPlainShipRoom() == RoomBoosts[Boost.Vent]; + public override bool CanUseImpostorVentButton(PlayerControl pc) => pc.inVent || pc.GetAbilityUseLimit() > 0 || pc.GetPlainShipRoom() == RoomBoosts[Boost.Vent]; public override bool CanUseSabotage(PlayerControl pc) => pc.GetPlainShipRoom() == RoomBoosts[Boost.Sabotage]; public override void ApplyGameOptions(IGameOptions opt, byte id) @@ -69,13 +75,33 @@ namespace EHR.Neutral public override void OnFixedUpdate(PlayerControl pc) { if (!pc.IsAlive() || !GameStates.IsInTask) return; + Count++; + if (Count < 20) return; + Count = 0; var room = pc.GetPlainShipRoom(); - if (room == LastRoom) return; + if (LastRoom != null && room == LastRoom) return; LastRoom = room; - pc.Notify(string.Format(Translator.GetString("PatrollerNotify"), Translator.GetString(room.RoomId.ToString()), Translator.GetString($"PatrollerBoost.{RoomBoosts.GetKeyByValue(room)}"))); - pc.SyncSettings(); + var roomName = Translator.GetString(room.RoomId.ToString()); + pc.Notify(RoomBoosts.Any(x => x.Value == room) + ? string.Format(Translator.GetString("PatrollerNotify"), roomName, Translator.GetString($"PatrollerBoost.{RoomBoosts.First(x => x.Value == room).Key}")) + : string.Format(Translator.GetString("PatrollerNotifyNoBoost"), roomName), 300f); + pc.MarkDirtySettings(); + + if (pc.PlayerId == PlayerControl.LocalPlayer.PlayerId) + HudManager.Instance.SetHudActive(pc, pc.Data.Role, true); + } + + public override void OnEnterVent(PlayerControl pc, Vent vent) + { + if (pc.GetPlainShipRoom() == RoomBoosts[Boost.Vent]) return; + pc.RpcRemoveAbilityUse(); + } + + public override void AfterMeetingTasks() + { + PatrollerId.SetAbilityUseLimit(1); } public override void OnPet(PlayerControl pc) diff --git a/main.cs b/main.cs index a3b7c1b39..557eebb55 100644 --- a/main.cs +++ b/main.cs @@ -173,7 +173,7 @@ public class Main : BasePlugin { List result = []; // ReSharper disable once LoopCanBeConvertedToQuery - foreach (var pc in PlayerControl.AllPlayerControls.GetFastEnumerator()) + foreach (var pc in PlayerControl.AllPlayerControls) { if (pc == null) continue; result.Add(pc); @@ -189,7 +189,7 @@ public class Main : BasePlugin { List result = []; // ReSharper disable once LoopCanBeConvertedToQuery - foreach (var pc in PlayerControl.AllPlayerControls.GetFastEnumerator()) + foreach (var pc in PlayerControl.AllPlayerControls) { if (pc == null || !pc.IsAlive() || pc.Data.Disconnected || Pelican.IsEaten(pc.PlayerId)) continue; result.Add(pc);