diff --git a/Main.cs b/Main.cs index 839bad23e..d0baf878e 100644 --- a/Main.cs +++ b/Main.cs @@ -109,7 +109,6 @@ public class Main : BasePlugin public static Dictionary GuesserGuessed = []; public static Dictionary GuesserGuessedMeeting = []; public static bool HasJustStarted; - public static int AliveImpostorCount; public static Dictionary CheckShapeshift = []; public static Dictionary ShapeshiftTarget = []; public static bool VisibleTasksCount; @@ -231,7 +230,7 @@ public class Main : BasePlugin { foreach (var pc in PlayerControl.AllPlayerControls) { - if (pc == null || pc.PlayerId >= 254) continue; + if (!pc || pc.PlayerId >= 254) continue; yield return pc; } } @@ -240,7 +239,7 @@ public class Main : BasePlugin { return EnumeratePlayerControls() .Where(pc => pc.IsAlive() - && pc.Data != null + && pc.Data && (!pc.Data.Disconnected || !IntroDestroyed) && !Pelican.IsEaten(pc.PlayerId)); } diff --git a/Modules/ExtendedPlayerControl.cs b/Modules/ExtendedPlayerControl.cs index cef5e71b8..f054a77b3 100644 --- a/Modules/ExtendedPlayerControl.cs +++ b/Modules/ExtendedPlayerControl.cs @@ -285,7 +285,7 @@ internal static class ExtendedPlayerControl /// public static CustomRoles GetCustomRole(this PlayerControl player) { - if (player == null) + if (!player) { MethodBase callerMethod = new StackFrame(1, false).GetMethod(); string callerMethodName = callerMethod?.Name; @@ -300,7 +300,7 @@ internal static class ExtendedPlayerControl { if (GameStates.IsLobby) return []; - if (player == null) + if (!player) { Logger.Warn("The player is null", "GetCustomSubRoles"); return []; @@ -311,7 +311,7 @@ internal static class ExtendedPlayerControl public static CountTypes GetCountTypes(this PlayerControl player) { - if (player == null) + if (!player) { StackFrame caller = new(1, false); MethodBase callerMethod = caller.GetMethod(); @@ -330,7 +330,7 @@ internal static class ExtendedPlayerControl public static void RpcResetTasks(this PlayerControl player, bool init = true) { - if (!AmongUsClient.Instance.AmHost || !GameStates.IsInGame || player == null) return; + if (!AmongUsClient.Instance.AmHost || !GameStates.IsInGame || !player) return; player.Data.RpcSetTasks(new Il2CppStructArray(0)); if (init) Main.PlayerStates[player.PlayerId].InitTask(player); @@ -430,7 +430,7 @@ internal static class ExtendedPlayerControl public static void RpcSetRoleDesync(this PlayerControl player, RoleTypes role, int clientId, bool setRoleMap = false) { if (!AmongUsClient.Instance.AmHost) return; - if (player == null) return; + if (!player) return; if (setRoleMap) { @@ -470,7 +470,7 @@ internal static class ExtendedPlayerControl // https://github.com/Ultradragon005/TownofHost-Enhanced/blob/ea5f1e8ea87e6c19466231c305d6d36d511d5b2d/Modules/ExtendedPlayerControl.cs public static void RpcRevive(this PlayerControl player) { - if (player == null) return; + if (!player) return; if (!player.Data.IsDead) { @@ -512,7 +512,7 @@ internal static class ExtendedPlayerControl { if (!forced) { - if (!AmongUsClient.Instance.AmHost || !GameStates.IsInGame || player == null || !player.IsAlive()) return; + if (!AmongUsClient.Instance.AmHost || !GameStates.IsInGame || !player || !player.IsAlive()) return; if (AntiBlackout.SkipTasks || ExileController.Instance) { @@ -762,7 +762,7 @@ internal static class ExtendedPlayerControl public static void RpcExitVentDesync(this PlayerPhysics physics, int ventId, PlayerControl seer) { - if (physics == null) return; + if (!physics) return; int clientId = seer.OwnerId; @@ -785,7 +785,7 @@ internal static class ExtendedPlayerControl public static bool IsInsideMap(this PlayerControl player) { - if (player == null) return false; + if (!player) return false; var results = new Collider2D[10]; int overlapPointNonAlloc = Physics2D.OverlapPointNonAlloc(player.Pos(), results, Constants.ShipOnlyMask); @@ -808,7 +808,7 @@ internal static class ExtendedPlayerControl public static void KillFlash(this PlayerControl player) { - if (GameStates.IsLobby || player == null) return; + if (GameStates.IsLobby || !player) return; // Kill flash (blackout + reactor flash) processing @@ -1003,7 +1003,7 @@ internal static class ExtendedPlayerControl public static void SetKillCooldown(this PlayerControl player, float time = -1f, PlayerControl target = null, bool forceAnime = false) { - if (player == null) return; + if (!player) return; if (!Mathf.Approximately(time, -1f) && Commited.ReduceKCD.TryGetValue(player.PlayerId, out float reduction)) time = Math.Max(time - reduction, 0.01f); @@ -1185,7 +1185,7 @@ internal static class ExtendedPlayerControl public static void FixBlackScreen(this PlayerControl pc) { - if (pc == null || !AmongUsClient.Instance.AmHost) return; + if (!pc || !AmongUsClient.Instance.AmHost) return; if (MeetingStates.FirstMeeting) { @@ -1315,7 +1315,7 @@ internal static class ExtendedPlayerControl public static void ReactorFlash(this PlayerControl pc, float delay = 0f, float flashDuration = float.NaN, bool canBlind = true) { - if (pc == null) return; + if (!pc) return; Logger.Info($"Reactor Flash for {pc.GetNameWithRole()}", "ReactorFlash"); @@ -1753,7 +1753,7 @@ internal static class ExtendedPlayerControl public static bool IsDousedPlayer(this PlayerControl arsonist, PlayerControl target) { - if (arsonist == null || target == null || Arsonist.IsDoused == null) return false; + if (!arsonist || !target) return false; Arsonist.IsDoused.TryGetValue((arsonist.PlayerId, target.PlayerId), out bool isDoused); return isDoused; @@ -1761,7 +1761,7 @@ internal static class ExtendedPlayerControl public static bool IsDrawPlayer(this PlayerControl arsonist, PlayerControl target) { - if (arsonist == null || target == null || Revolutionist.IsDraw == null) return false; + if (!arsonist || !target) return false; Revolutionist.IsDraw.TryGetValue((arsonist.PlayerId, target.PlayerId), out bool isDraw); return isDraw; @@ -1769,7 +1769,7 @@ internal static class ExtendedPlayerControl public static bool IsRevealedPlayer(this PlayerControl player, PlayerControl target) { - if (player == null || target == null || Investigator.IsRevealed == null) return false; + if (!player || !target) return false; Investigator.IsRevealed.TryGetValue((player.PlayerId, target.PlayerId), out bool isDoused); return isDoused; @@ -2127,7 +2127,7 @@ internal static class ExtendedPlayerControl public static bool UsesPetInsteadOfKill(this PlayerControl pc) { - return pc != null && !pc.Is(CustomRoles.Bloodlust) && pc.GetCustomRole().UsesPetInsteadOfKill(); + return pc && !pc.Is(CustomRoles.Bloodlust) && pc.GetCustomRole().UsesPetInsteadOfKill(); } public static bool IsModdedClient(this PlayerControl player) @@ -2413,7 +2413,7 @@ internal static class ExtendedPlayerControl public static bool IsAlive(this PlayerControl target) { - if (target == null || target.Is(CustomRoles.GM)) return false; + if (!target || target.Is(CustomRoles.GM)) return false; return GameStates.IsLobby || !Main.PlayerStates.TryGetValue(target.PlayerId, out PlayerState ps) || !ps.IsDead; } diff --git a/Modules/FixedUpdateCaller.cs b/Modules/FixedUpdateCaller.cs index ce5526863..f94b3bae2 100644 --- a/Modules/FixedUpdateCaller.cs +++ b/Modules/FixedUpdateCaller.cs @@ -19,44 +19,19 @@ public static class FixedUpdateCaller private static long LastFileLoadTS; private static long LastAutoMessageSendTS; - private static long LastMeasureTS; - // ReSharper disable once UnusedMember.Global public static void Postfix() { try { long now = Utils.TimeStamp; - Stopwatch stopwatch = Stopwatch.StartNew(); - bool measure = false; - - if (LastMeasureTS != now) - { - LastMeasureTS = now; - measure = true; - } - - if (measure) Logger.Warn($"Elapsed: {stopwatch.ElapsedMilliseconds} ms (1)", "debug"); - var amongUsClient = AmongUsClient.Instance; - - var shipStatus = ShipStatus.Instance; - - if (shipStatus) - { - if (measure) Logger.Warn($"Elapsed: {stopwatch.ElapsedMilliseconds} ms (2)", "debug"); - ShipStatusFixedUpdatePatch.Postfix(shipStatus); - if (measure) Logger.Warn($"Elapsed: {stopwatch.ElapsedMilliseconds} ms (3)", "debug"); - } - var lobbyBehaviour = LobbyBehaviour.Instance; if (lobbyBehaviour) { LobbyFixedUpdatePatch.Postfix(); - if (measure) Logger.Warn($"Elapsed: {stopwatch.ElapsedMilliseconds} ms (4)", "debug"); LobbyBehaviourUpdatePatch.Postfix(lobbyBehaviour); - if (measure) Logger.Warn($"Elapsed: {stopwatch.ElapsedMilliseconds} ms (5)", "debug"); //long now = Utils.TimeStamp; @@ -64,38 +39,28 @@ public static class FixedUpdateCaller { LastFileLoadTS = now; Options.LoadUserData(); - if (measure) Logger.Warn($"Elapsed: {stopwatch.ElapsedMilliseconds} ms (6)", "debug"); } if (Options.EnableAutoMessage.GetBool() && now - LastAutoMessageSendTS > Options.AutoMessageSendInterval.GetInt()) { LastAutoMessageSendTS = now; TemplateManager.SendTemplate("Notification", sendOption: SendOption.None); - if (measure) Logger.Warn($"Elapsed: {stopwatch.ElapsedMilliseconds} ms (7)", "debug"); } } - if (measure) Logger.Warn($"Elapsed: {stopwatch.ElapsedMilliseconds} ms (8)", "debug"); if (HudManager.InstanceExists) { HudManager hudManager = HudManager.Instance; HudManagerPatch.Postfix(hudManager); - if (measure) Logger.Warn($"Elapsed: {stopwatch.ElapsedMilliseconds} ms (9)", "debug"); Zoom.Postfix(); - if (measure) Logger.Warn($"Elapsed: {stopwatch.ElapsedMilliseconds} ms (10)", "debug"); HudSpritePatch.Postfix(hudManager); - if (measure) Logger.Warn($"Elapsed: {stopwatch.ElapsedMilliseconds} ms (11)", "debug"); } - if (measure) Logger.Warn($"Elapsed: {stopwatch.ElapsedMilliseconds} ms (12)", "debug"); - - if (measure) Logger.Warn($"Elapsed: {stopwatch.ElapsedMilliseconds} ms (13)", "debug"); if (!PlayerControl.LocalPlayer) return; if (amongUsClient.IsGameStarted) Utils.CountAlivePlayers(); - if (measure) Logger.Warn($"Elapsed: {stopwatch.ElapsedMilliseconds} ms (14)", "debug"); try { @@ -130,7 +95,6 @@ public static class FixedUpdateCaller } } catch { } - if (measure) Logger.Warn($"Elapsed: {stopwatch.ElapsedMilliseconds} ms (15)", "debug"); try { @@ -138,13 +102,11 @@ public static class FixedUpdateCaller FixedUpdatePatch.LoversSuicide(); } catch (Exception e) { Utils.ThrowException(e); } - if (measure) Logger.Warn($"Elapsed: {stopwatch.ElapsedMilliseconds} ms (16)", "debug"); bool lobby = GameStates.IsLobby; if (lobby || (Main.IntroDestroyed && GameStates.InGame && !GameStates.IsMeeting && !ExileController.Instance && !AntiBlackout.SkipTasks)) { - if (measure) Logger.Warn($"Elapsed: {stopwatch.ElapsedMilliseconds} ms (17)", "debug"); NonLowLoadPlayerIndex++; int count = PlayerControl.AllPlayerControls.Count; @@ -153,11 +115,9 @@ public static class FixedUpdateCaller NonLowLoadPlayerIndex = Math.Min(0, -(30 - count)); CustomGameMode currentGameMode = Options.CurrentGameMode; - if (measure) Logger.Warn($"Elapsed: {stopwatch.ElapsedMilliseconds} ms (18)", "debug"); for (var index = 0; index < count; index++) { - if (measure) Logger.Warn($"Elapsed: {stopwatch.ElapsedMilliseconds} ms (19)", "debug"); try { PlayerControl pc = PlayerControl.AllPlayerControls[index]; @@ -197,7 +157,6 @@ public static class FixedUpdateCaller } catch (Exception e) { Utils.ThrowException(e); } } - if (measure) Logger.Warn($"Elapsed: {stopwatch.ElapsedMilliseconds} ms (20)", "debug"); if (lobby) return; @@ -235,7 +194,6 @@ public static class FixedUpdateCaller } } catch (Exception e) { Utils.ThrowException(e); } - if (measure) Logger.Warn($"Elapsed: {stopwatch.ElapsedMilliseconds} ms (21)", "debug"); try { @@ -255,7 +213,6 @@ public static class FixedUpdateCaller } } catch (Exception e) { Utils.ThrowException(e); } - if (measure) Logger.Warn($"Elapsed: {stopwatch.ElapsedMilliseconds} ms (22)", "debug"); } } catch (Exception e) { Utils.ThrowException(e); } diff --git a/Modules/Statistics.cs b/Modules/Statistics.cs index 74b7a1e2a..cace1839e 100644 --- a/Modules/Statistics.cs +++ b/Modules/Statistics.cs @@ -313,7 +313,7 @@ public static class Statistics if (killer.AmOwner) { - if (Main.AliveImpostorCount == 0 && killer.IsCrewmate() && target.IsImpostor() && !Main.EnumerateAlivePlayerControls().Any(x => x.IsNeutralKiller())) + if (!Main.EnumerateAlivePlayerControls().Any(pc => pc.Is(CustomRoleTypes.Impostor)) && killer.IsCrewmate() && target.IsImpostor() && !Main.EnumerateAlivePlayerControls().Any(x => x.IsNeutralKiller())) Achievements.Type.ImCrewISwear.Complete(); if ((killer.IsImpostor() && target.IsMadmate()) || (killer.IsMadmate() && target.IsImpostor())) diff --git a/Modules/Utils.cs b/Modules/Utils.cs index 945b1d1e1..167eab075 100644 --- a/Modules/Utils.cs +++ b/Modules/Utils.cs @@ -94,11 +94,6 @@ public static class Utils public static int AllAlivePlayersCount => Main.EnumerateAlivePlayerControls().Count(pc => !pc.Is(CountTypes.OutOfGame)); public static bool IsAllAlive => Main.PlayerStates.Values.All(state => state.countTypes == CountTypes.OutOfGame || !state.IsDead); - public static long GetTimeStamp(DateTime? dateTime = null) - { - return (long)((dateTime ?? DateTime.Now).ToUniversalTime() - Epoch).TotalSeconds; - } - public static void ErrorEnd(string text) { if (AmongUsClient.Instance.AmHost) @@ -227,7 +222,7 @@ public static class Utils public static ClientData GetClientById(int id) { - try { return AmongUsClient.Instance.allClients.ToArray().FirstOrDefault(cd => cd.Id == id); } + try { return AmongUsClient.Instance.GetClient(id); } catch { return null; } } @@ -249,64 +244,43 @@ public static class Utils case SystemTypes.Electrical: { if (mapId == 5) return false; - - var switchSystem = systemType.CastFast(); - return switchSystem is { IsActive: true }; + return systemType.TryCast(out var switchSystem) && switchSystem.IsActive; } case SystemTypes.Reactor: { - switch (mapId) + return mapId switch { - case 2: - return false; - case 4: - var heliSabotageSystem = systemType.CastFast(); - return heliSabotageSystem != null && heliSabotageSystem.IsActive; - default: - var reactorSystemType = systemType.CastFast(); - return reactorSystemType is { IsActive: true }; - } + 2 => false, + 4 => systemType.TryCast(out var heliSabotageSystem) && heliSabotageSystem.IsActive, + _ => systemType.TryCast(out var reactorSystemType) && reactorSystemType.IsActive + }; } case SystemTypes.Laboratory: { if (mapId != 2) return false; - - var reactorSystemType = systemType.CastFast(); - return reactorSystemType is { IsActive: true }; + return systemType.TryCast(out var reactorSystemType) && reactorSystemType.IsActive; } case SystemTypes.LifeSupp: { if (mapId is 2 or 4 or 5) return false; - - var lifeSuppSystemType = systemType.CastFast(); - return lifeSuppSystemType is { IsActive: true }; + return systemType.TryCast(out var lifeSuppSystemType) && lifeSuppSystemType.IsActive; } case SystemTypes.Comms: { if (mapId is 1 or 5) - { - var hqHudSystemType = systemType.TryCast(); - // ReSharper disable once MergeIntoPattern - // For some reason, the game sometimes crashes here when trying to get_IsActive - return hqHudSystemType != null && hqHudSystemType.IsActive; - } + return systemType.TryCast(out var hqHudSystemType) && hqHudSystemType.IsActive; - var hudOverrideSystemType = systemType.CastFast(); - return hudOverrideSystemType is { IsActive: true }; + return systemType.TryCast(out var hudOverrideSystemType) && hudOverrideSystemType.IsActive; } case SystemTypes.HeliSabotage: { if (mapId != 4) return false; - - var heliSabotageSystem = systemType.CastFast(); - return heliSabotageSystem != null && heliSabotageSystem.IsActive; + return systemType.TryCast(out var heliSabotageSystem) && heliSabotageSystem.IsActive; } case SystemTypes.MushroomMixupSabotage: { if (mapId != 5) return false; - - var mushroomMixupSabotageSystem = systemType.CastFast(); - return mushroomMixupSabotageSystem != null && mushroomMixupSabotageSystem.IsActive; + return systemType.TryCast(out var mushroomMixupSabotageSystem) && mushroomMixupSabotageSystem.IsActive; } default: return false; @@ -1007,7 +981,7 @@ public static class Utils public static bool CanBeMadmate(this PlayerControl pc) { - return pc != null && pc.IsCrewmate() && !pc.Is(CustomRoles.Madmate) + return pc && pc.IsCrewmate() && !pc.Is(CustomRoles.Madmate) && !( (pc.Is(CustomRoles.Sheriff) && !Options.SheriffCanBeMadmate.GetBool()) || (pc.Is(CustomRoles.Mayor) && !Options.MayorCanBeMadmate.GetBool()) || @@ -1748,7 +1722,7 @@ public static class Utils { try { - if (Options.CurrentGameMode != CustomGameMode.Standard || deadPlayer == null || deadPlayer.Object.Is(CustomRoles.Renegade) || Main.HasJustStarted || !GameStates.InGame || !Options.SpawnAdditionalRenegadeOnImpsDead.GetBool() || Main.AllAlivePlayerControls.Count < Options.SpawnAdditionalRenegadeMinAlivePlayers.GetInt() || CustomRoles.Renegade.RoleExist(true) || Main.EnumerateAlivePlayerControls() == null || Main.AllAlivePlayerControls.Count == 0 || Main.EnumerateAlivePlayerControls().Any(x => x.PlayerId != deadPlayer.PlayerId && (x.Is(CustomRoleTypes.Impostor) || (x.IsNeutralKiller() && !Options.SpawnAdditionalRenegadeWhenNKAlive.GetBool())))) return; + if (Options.CurrentGameMode != CustomGameMode.Standard || !deadPlayer || deadPlayer.Object.Is(CustomRoles.Renegade) || Main.HasJustStarted || !GameStates.InGame || !Options.SpawnAdditionalRenegadeOnImpsDead.GetBool() || Main.AllAlivePlayerControls.Count < Options.SpawnAdditionalRenegadeMinAlivePlayers.GetInt() || CustomRoles.Renegade.RoleExist(true) || Main.EnumerateAlivePlayerControls().Any(x => x.PlayerId != deadPlayer.PlayerId && (x.Is(CustomRoleTypes.Impostor) || (x.IsNeutralKiller() && !Options.SpawnAdditionalRenegadeWhenNKAlive.GetBool())))) return; PlayerControl[] listToChooseFrom = Main.EnumerateAlivePlayerControls().Where(x => x.PlayerId != deadPlayer.PlayerId && x.Is(CustomRoleTypes.Crewmate) && !x.Is(CustomRoles.Loyal)).ToArray(); @@ -1829,7 +1803,7 @@ public static class Utils Logger.Info($"SendMessage called from {callerFilePath.Split('\\')[^1].Split('/')[^1]} at line {callerLineNumber}", "SendMessage"); PlayerControl receiver = GetPlayerById(sendTo, false); - if (sendTo != byte.MaxValue && receiver == null || !force && title.RemoveHtmlTags().Trim().Length == 0 && text.RemoveHtmlTags().Trim().Length == 0) return writer; + if (sendTo != byte.MaxValue && !receiver || !force && title.RemoveHtmlTags().Trim().Length == 0 && text.RemoveHtmlTags().Trim().Length == 0) return writer; if (!AmongUsClient.Instance.AmHost) { @@ -2348,7 +2322,7 @@ public static class Utils public static bool ApplySuffix(PlayerControl player, out string name) { name = string.Empty; - if (!AmongUsClient.Instance.AmHost || player == null) return false; + if (!AmongUsClient.Instance.AmHost || !player) return false; DevManager.TagInfo devUser = player.FriendCode.GetDevUser(); bool admin = ChatCommands.IsPlayerAdmin(player.FriendCode); @@ -2446,8 +2420,6 @@ public static class Utils foreach (PlayerControl pc in Main.EnumerateAlivePlayerControls()) { - if (!pc.IsAlive()) return null; - Vector3 position = pc.Pos(); Il2CppReferenceArray rooms = ShipStatus.Instance.AllRooms; @@ -2534,7 +2506,7 @@ public static class Utils { if (playerId is > byte.MaxValue or < byte.MinValue) return null; - if (fast && GameStates.InGame && Main.PlayerStates.TryGetValue((byte)playerId, out PlayerState state) && state.Player != null) return state.Player; + if (fast && GameStates.InGame && Main.PlayerStates.TryGetValue((byte)playerId, out PlayerState state) && state.Player) return state.Player; if (playerId == PlayerControl.LocalPlayer.PlayerId) return PlayerControl.LocalPlayer; @@ -2648,11 +2620,11 @@ public static class Utils try { if (!AmongUsClient.Instance.AmHost) return; - if (!SetUpRoleTextPatch.IsInIntro && ((SpecifySeer != null && SpecifySeer.IsModdedClient() && (Options.CurrentGameMode == CustomGameMode.Standard || SpecifySeer.IsHost())) || (GameStates.IsMeeting && !ForMeeting) || GameStates.IsLobby)) return; + if (!SetUpRoleTextPatch.IsInIntro && ((SpecifySeer && SpecifySeer.IsModdedClient() && (Options.CurrentGameMode == CustomGameMode.Standard || SpecifySeer.IsHost())) || (GameStates.IsMeeting && !ForMeeting) || GameStates.IsLobby)) return; var apc = Main.AllPlayerControls; - var seerList = SpecifySeer != null ? [SpecifySeer] : apc; - var targetList = SpecifyTarget != null ? [SpecifyTarget] : apc; + var seerList = SpecifySeer ? [SpecifySeer] : apc; + var targetList = SpecifyTarget ? [SpecifyTarget] : apc; var sender = CustomRpcSender.Create("NotifyRoles", SendOption, log: false); var hasValue = false; @@ -2693,7 +2665,7 @@ public static class Utils try { - if (seer == null || seer.Data.Disconnected || (seer.IsModdedClient() && (seer.IsHost() || Options.CurrentGameMode == CustomGameMode.Standard)) || (!SetUpRoleTextPatch.IsInIntro && GameStates.IsLobby)) + if (!seer || seer.Data.Disconnected || (seer.IsModdedClient() && (seer.IsHost() || Options.CurrentGameMode == CustomGameMode.Standard)) || (!SetUpRoleTextPatch.IsInIntro && GameStates.IsLobby)) return false; sender ??= CustomRpcSender.Create("NotifyRoles", sendOption); @@ -3977,7 +3949,7 @@ public static class Utils break; } - if (target == null) return; + if (!target) return; if (!disconnect && !onMeeting) Randomizer.OnAnyoneDeath(target); if (Executioner.Target.ContainsValue(target.PlayerId)) Executioner.ChangeRoleByTarget(target); @@ -4035,9 +4007,9 @@ public static class Utils Logger.Exception(ex, "AfterPlayerDeathTasks"); } - if (target == null || (Main.DiedThisRound.Contains(target.PlayerId) && IsRevivingRoleAlive()) || Options.CurrentGameMode != CustomGameMode.Standard) return; + if (!target || (Main.DiedThisRound.Contains(target.PlayerId) && IsRevivingRoleAlive()) || Options.CurrentGameMode != CustomGameMode.Standard) return; - if (targetRealKiller != null) + if (targetRealKiller) target.Notify($"<#ffffff>{string.Format(GetString("DeathCommand"), targetRealKiller.PlayerId.ColoredPlayerName(), (targetRealKiller.Is(CustomRoles.Bloodlust) ? $"{CustomRoles.Bloodlust.ToColoredString()} " : string.Empty) + targetRealKiller.GetCustomRole().ToColoredString())}", 10f); } @@ -4045,15 +4017,6 @@ public static class Utils { try { - int aliveImpostorCount = Main.EnumerateAlivePlayerControls().Count(pc => pc.Is(CustomRoleTypes.Impostor)); - - if (Main.AliveImpostorCount != aliveImpostorCount) - { - Logger.Info("Number of living Impostors: " + aliveImpostorCount, "CountAliveImpostors"); - Main.AliveImpostorCount = aliveImpostorCount; - LastImpostor.SetSubRole(); - } - if (sendLog) { StringBuilder sb = new(100); @@ -4085,7 +4048,7 @@ public static class Utils return num switch { - < 128 when player != null => player.GetNameWithRole().RemoveHtmlTags(), + < 128 when player => player.GetNameWithRole().RemoveHtmlTags(), 253 => "Skip", 254 => "None", 255 => "Dead", @@ -4096,7 +4059,7 @@ public static class Utils public static string PadRightV2(this object text, int num) { var t = text.ToString(); - if (t == null) return string.Empty; + if (string.IsNullOrEmpty(t)) return string.Empty; int bc = t.Sum(c => Encoding.GetEncoding("UTF-8").GetByteCount(c.ToString()) == 1 ? 1 : 2); @@ -4121,7 +4084,7 @@ public static class Utils if (!open) return; - if (PlayerControl.LocalPlayer != null && HudManager.InstanceExists) + if (PlayerControl.LocalPlayer && HudManager.InstanceExists) HudManager.Instance?.Chat?.AddChat(PlayerControl.LocalPlayer, string.Format(GetString("Message.DumpfileSaved"), "EHR" + filename.Split("EHR")[1])); if (OperatingSystem.IsWindows()) Process.Start("explorer.exe", f.Replace("/", "\\")); @@ -4408,11 +4371,11 @@ public static class Utils { if (!HudManager.InstanceExists) return; HudManager hud = HudManager.Instance; - if (hud.FullScreen == null) return; + if (!hud.FullScreen) return; GameObject obj = hud.transform.FindChild("FlashColor_FullScreen")?.gameObject; - if (obj == null) + if (!obj) { obj = Object.Instantiate(hud.FullScreen.gameObject, hud.transform); obj.name = "FlashColor_FullScreen"; @@ -4496,7 +4459,7 @@ public static class Utils foreach (var pc in aapc) { var dummyImp = aapc.FirstOrDefault(x => x != pc); - if (dummyImp != null) dummyImp.RpcSetRoleDesync(RoleTypes.Impostor, pc.OwnerId); + if (dummyImp) dummyImp.RpcSetRoleDesync(RoleTypes.Impostor, pc.OwnerId); } } @@ -4514,7 +4477,7 @@ public static class Utils try { var panelThing = hud.TaskStuff.transform.FindChild("RolePanel"); - if (panelThing != null) panelThing.gameObject.GetComponent().open = open; + if (panelThing) panelThing.gameObject.GetComponent().open = open; } catch (Exception e) { ThrowException(e); } } @@ -4690,7 +4653,7 @@ public static class Utils public static void RpcCreateDeadBody(Vector3 position, byte colorId, PlayerControl deadBodyParent, SendOption sendOption = SendOption.Reliable) { - if (deadBodyParent == null || !Main.IntroDestroyed || !AmongUsClient.Instance.AmHost) return; + if (!deadBodyParent || !Main.IntroDestroyed || !AmongUsClient.Instance.AmHost) return; CreateDeadBody(position, colorId, deadBodyParent); PlayerControl playerControl = Object.Instantiate(AmongUsClient.Instance.PlayerPrefab, Vector2.zero, Quaternion.identity); playerControl.PlayerId = deadBodyParent.PlayerId; @@ -4754,18 +4717,18 @@ public static class Utils public static MethodBase GetStateMachineMoveNext(string methodName) { var typeName = typeof(T).FullName; - var showRoleStateMachine = + var stateMachine = typeof(T) .GetNestedTypes() - .FirstOrDefault(x=>x.Name.Contains(methodName)); + .FirstOrDefault(x => x.Name.Contains(methodName)); - if (showRoleStateMachine == null) + if (stateMachine == null) { Logger.Error($"Failed to find {methodName} state machine for {typeName}", "GetStateMachineMoveNext"); return null; } - var moveNext = AccessTools.Method(showRoleStateMachine, "MoveNext"); + var moveNext = AccessTools.Method(stateMachine, "MoveNext"); if (moveNext == null) { Logger.Error($"Failed to find MoveNext method for {typeName}.{methodName}", "GetStateMachineMoveNext"); diff --git a/Modules/Zoom.cs b/Modules/Zoom.cs index 40ae024aa..d8869cc12 100644 --- a/Modules/Zoom.cs +++ b/Modules/Zoom.cs @@ -88,7 +88,7 @@ public static class Zoom public static void SetZoomSize(bool times = false, bool reset = false) { - if (Camera.main == null || !HudManager.InstanceExists) return; + if (!Camera.main || !HudManager.InstanceExists) return; var size = 1.5f; if (!times) size = 1 / size; @@ -117,7 +117,7 @@ public static class Zoom public static void OnFixedUpdate() { - if (Camera.main == null || !HudManager.InstanceExists) return; + if (!Camera.main || !HudManager.InstanceExists) return; HudManager.Instance?.ShadowQuad?.gameObject.SetActive(Mathf.Approximately(Camera.main.orthographicSize, 3.0f) && PlayerControl.LocalPlayer.IsAlive()); } diff --git a/Patches/ChatCommandPatch.cs b/Patches/ChatCommandPatch.cs index 8e959e271..ae10c11ca 100644 --- a/Patches/ChatCommandPatch.cs +++ b/Patches/ChatCommandPatch.cs @@ -1357,13 +1357,18 @@ internal static class ChatCommands private static void DraftDescriptionCommand(PlayerControl player, string text, string[] args) { CustomRoles role; - try //Sometimes a System.ArgumentOutOfRangeException occurs here + + try // Sometimes a System.ArgumentOutOfRangeException occurs here { - if (DraftRoles.Count == 0 || !DraftRoles.TryGetValue(player.PlayerId, out List roles) || args.Length < 2 || !int.TryParse(args[1], out int chosenIndex) || roles.Count < chosenIndex) return; + if (DraftRoles.Count == 0 || !DraftRoles.TryGetValue(player.PlayerId, out List roles) || args.Length < 2 || !int.TryParse(args[1], out int chosenIndex) || chosenIndex <= 0 || roles.Count < chosenIndex) return; role = roles[chosenIndex - 1]; } - catch (Exception e) { Utils.ThrowException(e); return; } + catch (Exception e) + { + Utils.ThrowException(e); + return; + } string coloredString = role.ToColoredString(); string roleName = GetString(role.ToString()); diff --git a/Patches/HudPatch.cs b/Patches/HudPatch.cs index 71b81450d..c46a23205 100644 --- a/Patches/HudPatch.cs +++ b/Patches/HudPatch.cs @@ -390,8 +390,8 @@ internal static class HudManagerPatch } } - - if (Input.GetKeyDown(KeyCode.Y) && AmongUsClient.Instance.NetworkMode == NetworkModes.FreePlay) +#if DEBUG + if (Input.GetKeyDown(KeyCode.Y)) { __instance.ToggleMapVisible(new() { @@ -428,6 +428,7 @@ internal static class HudManagerPatch if (Input.GetKeyDown(KeyCode.Alpha9)) RepairSender.Input(9); if (Input.GetKeyDown(KeyCode.Return)) RepairSender.InputEnter(); } +#endif } catch (NullReferenceException e) { @@ -1356,8 +1357,10 @@ internal static class TaskPanelBehaviourPatch __instance.taskText.text = taskList; +#if DEBUG if (RepairSender.Enabled && AmongUsClient.Instance.NetworkMode != NetworkModes.OnlineGame) __instance.taskText.text = RepairSender.GetText(); +#endif } } @@ -1374,6 +1377,7 @@ internal static class DialogueBoxShowPatch } } +#if DEBUG internal static class RepairSender { public static bool Enabled; @@ -1422,3 +1426,5 @@ internal static class RepairSender return SystemType + "(" + (SystemTypes)SystemType + ")\r\n" + Amount; } } + +#endif \ No newline at end of file diff --git a/Patches/IntroPatch.cs b/Patches/IntroPatch.cs index e40422b74..73a10e0a9 100644 --- a/Patches/IntroPatch.cs +++ b/Patches/IntroPatch.cs @@ -1355,6 +1355,7 @@ internal static class IntroCutsceneDestroyPatch LateTask.New(() => Main.Instance.StartCoroutine(Utils.NotifyEveryoneAsync()), 3f, "NotifyEveryoneAsync On Game Start"); LateTask.New(Utils.MarkEveryoneDirtySettings, 0.5f, "SyncAllSettings On Game Start"); + LateTask.New(() => Main.Instance.StartCoroutine(ShipStatusFixedUpdatePatch.Postfix()), 5f, "ShipStatusFixedUpdatePatch Postfix Start"); } else { diff --git a/Patches/LobbyPatch.cs b/Patches/LobbyPatch.cs index 3ccc29cea..b13bab818 100644 --- a/Patches/LobbyPatch.cs +++ b/Patches/LobbyPatch.cs @@ -16,7 +16,7 @@ public static class LobbyFixedUpdatePatch { try { - if (Paint == null) + if (!Paint) { GameObject leftBox = GameObject.Find("Leftbox"); @@ -30,7 +30,7 @@ public static class LobbyFixedUpdatePatch } } - if (LeftEngineSR == null || RightEngineSR == null) + if (!LeftEngineSR || !RightEngineSR) { var leftEngine = GameObject.Find("LeftEngine"); if (leftEngine != null) LeftEngineSR = leftEngine.GetComponent(); diff --git a/Patches/PlayerControlPatch.cs b/Patches/PlayerControlPatch.cs index 5a6d0947f..9ef93b9ef 100644 --- a/Patches/PlayerControlPatch.cs +++ b/Patches/PlayerControlPatch.cs @@ -170,7 +170,7 @@ internal static class CheckMurderPatch return false; } - if (MeetingHud.Instance != null) + if (MeetingHud.Instance) { Logger.Info("Kill during meeting, canceled", "CheckMurder"); return false; @@ -640,7 +640,7 @@ internal static class MurderPlayerPatch public static void Postfix(PlayerControl __instance, [HarmonyArgument(0)] PlayerControl target, bool __state) { - if (__instance == null || target == null || __instance.PlayerId >= 254 || target.PlayerId >= 254 || !__state) return; + if (!__instance || !target || __instance.PlayerId >= 254 || target.PlayerId >= 254 || !__state) return; if (target.AmOwner) RemoveDisableDevicesPatch.UpdateDisableDevices(); @@ -847,7 +847,7 @@ internal static class ShapeshiftPatch return false; } - if (shapeshifter == null || target == null) return true; + if (!shapeshifter || !target) return true; Logger.Info($"{shapeshifter.GetNameWithRole()} => {target.GetNameWithRole()}", "Shapeshift"); @@ -940,24 +940,21 @@ internal static class ShapeshiftPatch } // Tasks that should run when someone performs a shapeshift (with the egg animation) should be here. - public static void Prefix(PlayerControl __instance, [HarmonyArgument(0)] PlayerControl target) + public static void Prefix(PlayerControl __instance, [HarmonyArgument(0)] PlayerControl target, [HarmonyArgument(1)] bool shouldAnimate) { - if (!Main.ProcessShapeshifts || !GameStates.IsInTask || __instance == null || target == null) return; + if (!Main.ProcessShapeshifts || !GameStates.IsInTask || !__instance || !target) return; - bool animated = !Options.DisableShapeshiftAnimations.GetBool() - && !Options.DisableAllShapeshiftAnimations.GetBool() - && !__instance.GetCustomRole().IsNoAnimationShifter(); - - float ssTimer = animated ? 1.2f : 0.5f; - - LateTask.New(() => + if (shouldAnimate) { - if (AmongUsClient.Instance.AmHost) + LateTask.New(() => { - __instance.RpcSetName(Main.AllPlayerNames[target.PlayerId]); - NotifyRoles(NoCache: true); - } - }, ssTimer, "PlayerControl.Shapeshift Prefix Patch - Force Name"); + if (AmongUsClient.Instance.AmHost) + { + __instance.RpcSetName(Main.AllPlayerNames[target.PlayerId]); + NotifyRoles(NoCache: true); + } + }, 1.2f, "PlayerControl.Shapeshift Prefix Patch - Force Name"); + } bool shapeshifting = __instance.PlayerId != target.PlayerId; @@ -1457,7 +1454,7 @@ internal static class FixedUpdatePatch { try { - if (__instance == null || __instance.PlayerId >= 254) return; + if (__instance.PlayerId >= 254) return; CheckMurderPatch.Update(__instance.PlayerId); @@ -1542,7 +1539,11 @@ internal static class FixedUpdatePatch Zoom.OnFixedUpdate(); TextBoxPatch.CheckChatOpen(); - if (!lowLoad) NameNotifyManager.OnFixedUpdate(); + if (!lowLoad) + { + NameNotifyManager.OnFixedUpdate(); + LastImpostor.SetSubRole(); + } } if (!lowLoad) @@ -1642,7 +1643,7 @@ internal static class FixedUpdatePatch PlagueBearer.PlayerIdList.Remove(playerId); } - bool checkPos = inTask && !ExileController.Instance && !AntiBlackout.SkipTasks && player != null && alive && !Pelican.IsEaten(playerId) && Main.IntroDestroyed; + bool checkPos = inTask && !ExileController.Instance && !AntiBlackout.SkipTasks && alive && !Pelican.IsEaten(playerId) && Main.IntroDestroyed; if (checkPos) Asthmatic.OnCheckPlayerPosition(player); foreach (PlayerState state in Main.PlayerStates.Values) @@ -1736,7 +1737,7 @@ internal static class FixedUpdatePatch bool shouldUpdateRegardlessOfLowLoad = self && GameStates.InGame && PlayerControl.LocalPlayer.IsAlive() && ((PlayerControl.AllPlayerControls.Count > 30 && LastSelfNameUpdateTS != now && Options.CurrentGameMode is CustomGameMode.StopAndGo or CustomGameMode.HotPotato or CustomGameMode.Speedrun or CustomGameMode.RoomRush or CustomGameMode.KingOfTheZones or CustomGameMode.Quiz or CustomGameMode.Mingle) || DirtyName.Remove(lpId)); - if (player == null || (lowLoad && !shouldUpdateRegardlessOfLowLoad)) return; + if (lowLoad && !shouldUpdateRegardlessOfLowLoad) return; if (self) LastSelfNameUpdateTS = now; @@ -1963,7 +1964,7 @@ internal static class FixedUpdatePatch Mark.Append(Snitch.GetWarningMark(seer, target)); Mark.Append(Deathpact.GetDeathpactMark(seer, target)); - Main.LoversPlayers.ToArray().DoIf(x => x == null, x => Main.LoversPlayers.Remove(x)); + Main.LoversPlayers.RemoveAll(x => !x); if (!Main.HasJustStarted) Main.LoversPlayers.DoIf(x => !x.Is(CustomRoles.Lovers), x => x.RpcSetCustomRole(CustomRoles.Lovers)); if (Main.LoversPlayers.Exists(x => x.PlayerId == target.PlayerId) && (Main.LoversPlayers.Exists(x => x.PlayerId == lpId) || !seer.IsAlive())) @@ -2299,7 +2300,7 @@ internal static class PlayerControlCompleteTaskPatch public static void Postfix(PlayerControl __instance, [HarmonyArgument(0)] uint idx) { - if (GameStates.IsMeeting || __instance == null || !__instance.IsAlive()) return; + if (GameStates.IsMeeting || !__instance || !__instance.IsAlive()) return; Snitch.OnCompleteTask(__instance); @@ -2555,6 +2556,6 @@ internal static class BootFromVentPatch { public static bool Prefix(PlayerPhysics __instance) { - return !GameStates.IsInTask || ExileController.Instance || __instance == null || __instance.myPlayer == null || !__instance.myPlayer.IsAlive() || !__instance.myPlayer.Is(CustomRoles.Nimble); + return !GameStates.IsInTask || ExileController.Instance || !__instance || !__instance.myPlayer || !__instance.myPlayer.IsAlive() || !__instance.myPlayer.Is(CustomRoles.Nimble); } } diff --git a/Patches/ShipStatusPatch.cs b/Patches/ShipStatusPatch.cs index e515c978a..7a1758e5f 100644 --- a/Patches/ShipStatusPatch.cs +++ b/Patches/ShipStatusPatch.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using AmongUs.GameOptions; using BepInEx; @@ -62,8 +63,10 @@ internal static class RepairSystemPatch [HarmonyArgument(2)] byte amount) { Logger.Msg($"SystemType: {systemType}, PlayerName: {player.GetNameWithRole().RemoveHtmlTags()}, amount: {amount}", "RepairSystem"); +#if DEBUG if (RepairSender.Enabled && AmongUsClient.Instance.NetworkMode != NetworkModes.OnlineGame) Logger.SendInGame($"SystemType: {systemType}, PlayerName: {player.GetNameWithRole().RemoveHtmlTags()}, amount: {amount}"); +#endif if (!AmongUsClient.Instance.AmHost) return true; // Execute the following only on the host @@ -675,21 +678,31 @@ internal static class ShipStatusFixedUpdatePatch public static Dictionary ClosestVent = []; public static Dictionary CanUseClosestVent = []; - private static int Count; + private static Stopwatch Stopwatch; - public static void Postfix(ShipStatus __instance) + public static System.Collections.IEnumerator Postfix() { - try + Stopwatch = Stopwatch.StartNew(); + + while (ShipStatus.Instance) { - if (!AmongUsClient.Instance.AmHost || !GameStates.InGame || !Main.IntroDestroyed || GameStates.IsMeeting || ExileController.Instance || AntiBlackout.SkipTasks) return; + if (ReportDeadBodyPatch.MeetingStarted || GameStates.IsMeeting || ExileController.Instance || AntiBlackout.SkipTasks) + { + Stopwatch.Reset(); + yield return new WaitForSecondsRealtime(AntiBlackout.SkipTasks ? 2f : 5f); + Stopwatch.Start(); + continue; + } - if (IntroCutsceneDestroyPatch.IntroDestroyTS + 5 > Utils.TimeStamp) return; - - if (Count++ < 40) return; - Count = 0; - - var ventilationSystem = __instance.Systems[SystemTypes.Ventilation].CastFast(); - if (ventilationSystem == null) return; + var ventilationSystem = ShipStatus.Instance.Systems[SystemTypes.Ventilation].CastFast(); + + if (ventilationSystem == null) + { + Stopwatch.Reset(); + yield return new WaitForSecondsRealtime(0.1f); + Stopwatch.Start(); + continue; + } foreach (PlayerControl pc in Main.EnumerateAlivePlayerControls()) { @@ -713,8 +726,21 @@ internal static class ShipStatusFixedUpdatePatch CanUseClosestVent[pc.PlayerId] = canUseVent; } catch (Exception e) { Utils.ThrowException(e); } + + if (Stopwatch.ElapsedMilliseconds > 3) + { + Stopwatch.Reset(); + yield return null; + Stopwatch.Start(); + } } + + Stopwatch.Reset(); + yield return new WaitForSecondsRealtime(0.5f); + Stopwatch.Start(); } - catch (Exception e) { Utils.ThrowException(e); } + + if (ShipStatus.Instance) + Main.Instance.StartCoroutine(Postfix()); } } \ No newline at end of file diff --git a/Roles/Standard/Addons/Impostor/LastImpostor.cs b/Roles/Standard/Addons/Impostor/LastImpostor.cs index 769052773..dd34072d6 100644 --- a/Roles/Standard/Addons/Impostor/LastImpostor.cs +++ b/Roles/Standard/Addons/Impostor/LastImpostor.cs @@ -1,3 +1,4 @@ +using System.Linq; using Hazel; namespace EHR.Roles; @@ -49,7 +50,7 @@ public class LastImpostor : IAddon { if (CurrentId != byte.MaxValue || !AmongUsClient.Instance.AmHost) return; - if (Options.CurrentGameMode != CustomGameMode.Standard || !CustomRoles.LastImpostor.IsEnable() || Main.AliveImpostorCount != 1) return; + if (Options.CurrentGameMode != CustomGameMode.Standard || !CustomRoles.LastImpostor.IsEnable() || Main.EnumerateAlivePlayerControls().Count(pc => pc.Is(CustomRoleTypes.Impostor)) != 1) return; foreach (PlayerControl pc in Main.EnumerateAlivePlayerControls()) { diff --git a/Roles/Standard/Crewmate/Miscellaneous/CameraMan.cs b/Roles/Standard/Crewmate/Miscellaneous/CameraMan.cs index 9d55ec153..e2bb4ced4 100644 --- a/Roles/Standard/Crewmate/Miscellaneous/CameraMan.cs +++ b/Roles/Standard/Crewmate/Miscellaneous/CameraMan.cs @@ -22,7 +22,6 @@ public class CameraMan : RoleBase private static Vector2 CameraPosition; private Vector2 BasePos; - private bool IsTeleported; public override bool IsEnable => PlayerIdList.Count > 0; public override void SetupCustomOption() @@ -70,7 +69,6 @@ public class CameraMan : RoleBase { PlayerIdList.Add(playerId); playerId.SetAbilityUseLimit(UseLimitOpt.GetFloat()); - IsTeleported = false; } public override void Remove(byte playerId) @@ -116,35 +114,24 @@ public class CameraMan : RoleBase BasePos = pc.Pos(); pc.RPCPlayCustomSound("teleport"); - if (pc.TP(CameraPosition)) + if (pc.TP(CameraPosition) && TPBackWhenMoveAway.GetBool()) { - IsTeleported = true; - - if (TPBackWhenMoveAway.GetBool()) - { - Main.Instance.StartCoroutine(Coroutine()); + Main.Instance.StartCoroutine(Coroutine()); - System.Collections.IEnumerator Coroutine() - { - yield return new WaitForSecondsRealtime(2f); + System.Collections.IEnumerator Coroutine() + { + yield return new WaitForSecondsRealtime(2f); - while (GameStates.IsInTask && pc.IsAlive() && FastVector2.DistanceWithinRange(pc.Pos(), CameraPosition, DisableDevice.UsableDistance)) - yield return new WaitForSecondsRealtime(0.5f); + while (GameStates.IsInTask && pc.IsAlive() && FastVector2.DistanceWithinRange(pc.Pos(), CameraPosition, DisableDevice.UsableDistance)) + yield return new WaitForSecondsRealtime(0.5f); - if (!pc.IsAlive() || !GameStates.IsInTask) yield break; - - IsTeleported = false; - pc.TP(BasePos); - } + if (!pc.IsAlive() || !GameStates.IsInTask) yield break; + + pc.TP(BasePos); } } } - public override void OnReportDeadBody() - { - IsTeleported = false; - } - public override bool CanUseVent(PlayerControl pc, int ventId) { return !IsThisRole(pc) || pc.Is(CustomRoles.Nimble) || pc.GetClosestVent()?.Id == ventId; diff --git a/Roles/Standard/Crewmate/Support/Rhapsode.cs b/Roles/Standard/Crewmate/Support/Rhapsode.cs index 2b8cb5e10..5296ebc7d 100644 --- a/Roles/Standard/Crewmate/Support/Rhapsode.cs +++ b/Roles/Standard/Crewmate/Support/Rhapsode.cs @@ -21,7 +21,6 @@ public class Rhapsode : RoleBase public static OptionItem AbilityChargesWhenFinishedTasks; private CountdownTimer Timer; - private long LastUpdate; private byte RhapsodeId; public override bool IsEnable => On; @@ -67,7 +66,6 @@ public class Rhapsode : RoleBase Instances.Add(this); RhapsodeId = playerId; Timer = null; - LastUpdate = 0; playerId.SetAbilityUseLimit(AbilityUseLimit.GetFloat()); } diff --git a/Roles/Standard/Impostor/Concealing/Duellist.cs b/Roles/Standard/Impostor/Concealing/Duellist.cs index 820d28fb8..a9aeb0240 100644 --- a/Roles/Standard/Impostor/Concealing/Duellist.cs +++ b/Roles/Standard/Impostor/Concealing/Duellist.cs @@ -14,8 +14,6 @@ public class Duellist : RoleBase private static Dictionary DuelPair = []; private static OptionItem SSCD; - private int Count; - public override bool IsEnable => PlayerIdList.Count > 0 || Randomizer.Exists; public override void SetupCustomOption() diff --git a/Roles/Standard/Impostor/Concealing/Warlock.cs b/Roles/Standard/Impostor/Concealing/Warlock.cs index 7e434ff17..b288e3f82 100644 --- a/Roles/Standard/Impostor/Concealing/Warlock.cs +++ b/Roles/Standard/Impostor/Concealing/Warlock.cs @@ -29,7 +29,6 @@ internal class Warlock : RoleBase private CountdownTimer CurseCD; private CountdownTimer KCD; - private long LastNotify; private byte WarlockId; public override bool IsEnable => On; @@ -73,7 +72,6 @@ internal class Warlock : RoleBase PlayerControl pc = playerId.GetPlayer(); KCD = new CountdownTimer(KillCooldown.GetFloat() + 8, () => KCD = null, onTick: () => Utils.NotifyRoles(SpecifySeer: pc, SpecifyTarget: pc, SendOption: SendOption.None), onCanceled: () => KCD = null); CurseCD = new CountdownTimer(CurseCooldown.GetFloat() + 8, () => CurseCD = null, onTick: () => Utils.NotifyRoles(SpecifySeer: pc, SpecifyTarget: pc, SendOption: SendOption.None), onCanceled: () => CurseCD = null); - LastNotify = 0; } public override void Init() diff --git a/Roles/Standard/Impostor/Killing/Fireworker.cs b/Roles/Standard/Impostor/Killing/Fireworker.cs index 53694c09c..dd376cbd1 100644 --- a/Roles/Standard/Impostor/Killing/Fireworker.cs +++ b/Roles/Standard/Impostor/Killing/Fireworker.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using EHR.Modules; using Hazel; using UnityEngine; @@ -152,7 +153,7 @@ public class Fireworker : RoleBase nowFireworksCount--; state = nowFireworksCount == 0 - ? Main.AliveImpostorCount <= 1 ? FireworkerState.ReadyFire : FireworkerState.WaitTime + ? Main.EnumerateAlivePlayerControls().Count(x => x.Is(CustomRoleTypes.Impostor)) <= 1 ? FireworkerState.ReadyFire : FireworkerState.WaitTime : FireworkerState.SettingFireworks; break; @@ -191,7 +192,7 @@ public class Fireworker : RoleBase var retText = string.Empty; if (seer == null || !seer.IsAlive() || seer.PlayerId != target.PlayerId || Main.PlayerStates[seer.PlayerId].Role is not Fireworker fw) return retText; - if (fw.state == FireworkerState.WaitTime && Main.AliveImpostorCount <= 1) + if (fw.state == FireworkerState.WaitTime && Main.EnumerateAlivePlayerControls().Count(pc => pc.Is(CustomRoleTypes.Impostor)) <= 1) { fw.state = FireworkerState.ReadyFire; fw.SendRPC(seer.PlayerId);