From f23b4ea53be4d8ad5b3731f10af65b59f8c32469 Mon Sep 17 00:00:00 2001 From: Gurge44 Date: Wed, 17 Jun 2026 18:43:10 +0200 Subject: [PATCH] even more fixes --- Gamemodes/HotPotato.cs | 2 +- Gamemodes/NaturalDisasters.cs | 11 ++++++++--- Gamemodes/RoomRush.cs | 29 ++++++++++++++++++++--------- Modules/SpamManager.cs | 2 +- Modules/TemplateManager.cs | 6 +++--- Modules/Utils.cs | 21 ++++++++++++++++++++- Patches/HudPatch.cs | 2 +- 7 files changed, 54 insertions(+), 19 deletions(-) diff --git a/Gamemodes/HotPotato.cs b/Gamemodes/HotPotato.cs index 9274de453..a471140b5 100644 --- a/Gamemodes/HotPotato.cs +++ b/Gamemodes/HotPotato.cs @@ -91,7 +91,7 @@ internal static class HotPotato public static string GetIndicator(byte id) { - return HotPotatoState.HolderID == id ? " \u2668 " : string.Empty; + return HotPotatoState.HolderID == id ? " \u2668 " : string.Empty; } public static string GetSuffixText(byte id, bool hud) diff --git a/Gamemodes/NaturalDisasters.cs b/Gamemodes/NaturalDisasters.cs index 7a23f3c33..91750e109 100644 --- a/Gamemodes/NaturalDisasters.cs +++ b/Gamemodes/NaturalDisasters.cs @@ -132,6 +132,7 @@ public static class NaturalDisasters public static void OnGameStart() { LoadAllDisasters(); + DeathMessageQueue.Clear(); SurvivalTimes.Clear(); ActiveDisasters.Clear(); PreparingDisasters.Clear(); @@ -173,7 +174,11 @@ public static class NaturalDisasters var collapsedRooms = BuildingCollapse.CollapsedRooms; string cb; - if (allRooms.Count / 2 <= collapsedRooms.Count) + if (DisasterSpawnChances["BuildingCollapse"].GetInt() == 0) + { + cb = string.Empty; + } + else if (allRooms.Count / 2 <= collapsedRooms.Count) { SystemTypes[] remainingRooms = allRooms.Select(x => x.RoomId).Where(x => x is not (SystemTypes.Hallway or SystemTypes.Outside or SystemTypes.Decontamination2 or SystemTypes.Decontamination3)).Except(collapsedRooms.ConvertAll(x => x.RoomId)).ToArray(); cb = string.Format(Translator.GetString("AvailableBuildings"), remainingRooms.Length > 0 @@ -266,9 +271,9 @@ public static class NaturalDisasters CustomGameMode.BedWars => (30, BedWars.IsGracePeriod), CustomGameMode.HideAndSeek => (0, CustomHnS.IsBlindTime), CustomGameMode.KingOfTheZones => (0, !KingOfTheZones.GameGoing), - CustomGameMode.RoomRush => (40, false), + CustomGameMode.RoomRush => (0, !RoomRush.GameGoing), CustomGameMode.Deathrace => (0, !Deathrace.GameGoing), - CustomGameMode.Mingle => (60, !Mingle.GameGoing), + CustomGameMode.Mingle => (40, !Mingle.GameGoing), _ => (0, false) }; diff --git a/Gamemodes/RoomRush.cs b/Gamemodes/RoomRush.cs index 219a32696..b077d6b34 100644 --- a/Gamemodes/RoomRush.cs +++ b/Gamemodes/RoomRush.cs @@ -35,7 +35,7 @@ public static class RoomRush private static long TimeLimitEndTS; private static HashSet DonePlayers = []; - private static bool GameGoing; + public static bool GameGoing; public static DateTime GameStartDateTime; private static RandomSpawn.SpawnMap Map; @@ -700,7 +700,7 @@ public static class RoomRush GameGoing = false; int ventLimit = VentTimes.GetInt(); - VentLimit = Main.EnumeratePlayerControls().ToDictionary(x => x.PlayerId, _ => ventLimit); + VentLimit = Main.CachedAllPlayerControls().ToDictionary(x => x.PlayerId, _ => ventLimit); AllRooms = ShipStatus.Instance.AllRooms.Select(x => x.RoomId).ToHashSet(); AllRooms.Remove(SystemTypes.Hallway); @@ -711,7 +711,7 @@ public static class RoomRush Points = []; if (WinByPointsInsteadOfDeaths.GetBool()) - Points = Main.EnumeratePlayerControls().ToDictionary(x => x.PlayerId, _ => 0); + Points = Main.CachedAllPlayerControls().ToDictionary(x => x.PlayerId, _ => 0); try { Map = RandomSpawn.SpawnMap.GetSpawnMap(); } catch { } @@ -807,7 +807,14 @@ public static class RoomRush } if (ventLimit > 0) - aapc.Do(x => x.RpcSetRoleGlobal(RoleTypes.Engineer)); + { + for (int i = 0; i < aapc.Count; i++) + { + var pc = aapc[i]; + if (!pc || !pc.IsAlive()) continue; + pc.RpcSetRoleGlobal(RoleTypes.Engineer); + } + } Utils.SendRPC(CustomRPC.RoomRushDataSync, 1); @@ -839,7 +846,6 @@ public static class RoomRush DonePlayers.Clear(); RoomGoal = AllRooms.Without(previous).RandomElement(); - Vector2 goalPos = RoomGoal.GetRoomClass().transform.position; float speed = Main.RealOptionsData.GetFloat(FloatOptionNames.PlayerSpeedMod); int time; @@ -880,8 +886,13 @@ public static class RoomRush TimeLimitEndTS = Utils.TimeStamp + time; Logger.Info($"Starting a new round - Goal = from: {Translator.GetString(previous)} ({previous}), to: {Translator.GetString(RoomGoal)} ({RoomGoal}) - Time: {time} ({map})", "RoomRush"); - Main.EnumeratePlayerControls().Do(x => LocateArrow.RemoveAllTarget(x.PlayerId)); - if (DisplayArrowToRoom.GetBool()) Main.EnumeratePlayerControls().Do(x => LocateArrow.Add(x.PlayerId, goalPos)); + try + { + Main.CachedAllPlayerControls().Do(x => LocateArrow.RemoveAllTarget(x.PlayerId)); + Vector2 goalPos = RoomGoal.GetRoomClass().transform.position; + if (DisplayArrowToRoom.GetBool()) Main.CachedAllPlayerControls().Do(x => LocateArrow.Add(x.PlayerId, goalPos)); + } + catch (Exception e) { Utils.ThrowException(e); } Utils.NotifyRoles(); LateTask.New(() => Utils.DirtyName.Add(PlayerControl.LocalPlayer.PlayerId), 0.2f); @@ -961,8 +972,8 @@ public static class RoomRush case 1: PointsToWinValue = PointsToWin.GetInt() * Main.AllAlivePlayerControlsCount; int ventLimit = VentTimes.GetInt(); - VentLimit = Main.EnumeratePlayerControls().ToDictionary(x => x.PlayerId, _ => ventLimit); - if (WinByPointsInsteadOfDeaths.GetBool()) Points = Main.EnumeratePlayerControls().ToDictionary(x => x.PlayerId, _ => 0); + VentLimit = Main.CachedAllPlayerControls().ToDictionary(x => x.PlayerId, _ => ventLimit); + if (WinByPointsInsteadOfDeaths.GetBool()) Points = Main.CachedAllPlayerControls().ToDictionary(x => x.PlayerId, _ => 0); break; case 2: int limit = reader.ReadPackedInt32(); diff --git a/Modules/SpamManager.cs b/Modules/SpamManager.cs index aa4be385d..900373ffe 100644 --- a/Modules/SpamManager.cs +++ b/Modules/SpamManager.cs @@ -189,7 +189,7 @@ public static class SpamManager if (text.Length > 35) return false; - string normalized = Normalize(text); + string normalized = Normalize(text).Replace("starlight", string.Empty); foreach (string word in words) { diff --git a/Modules/TemplateManager.cs b/Modules/TemplateManager.cs index 9962b64a8..53fa3e33f 100644 --- a/Modules/TemplateManager.cs +++ b/Modules/TemplateManager.cs @@ -563,11 +563,11 @@ public static class TemplateManager blocked = false; blockSource = null; - List restricted = [.. eligible.FindAll(hasCondition)]; + List restricted = eligible.FindAll(hasCondition); if (restricted.Count == 0) return eligible; - List unrestricted = [.. eligible.FindAll(e => !hasCondition(e))]; - List passing = [.. restricted.FindAll(meetsCondition)]; + List unrestricted = eligible.FindAll(e => !hasCondition(e)); + List passing = restricted.FindAll(meetsCondition); if (passing.Count > 0) return passing; if (unrestricted.Count > 0) return unrestricted; diff --git a/Modules/Utils.cs b/Modules/Utils.cs index 3c8e84212..c248f6748 100644 --- a/Modules/Utils.cs +++ b/Modules/Utils.cs @@ -96,7 +96,26 @@ public static class Utils private static readonly Dictionary LongRoleDescriptions = []; - public static bool DoRPC => AmongUsClient.Instance.AmHost && Main.EnumeratePlayerControls().Any(x => x.IsModdedClient() && !x.IsHost()); + public static bool DoRPC + { + get + { + if (!AmongUsClient.Instance.AmHost) return false; + + var apc = Main.CachedAllPlayerControls(); + + for (int i = 0; i < apc.Count; i++) + { + PlayerControl pc = apc[i]; + + if (pc && !pc.AmOwner && Main.PlayerVersion.ContainsKey(pc.PlayerId)) + return true; + } + + return false; + } + } + public static int TotalTaskCountForReset => Main.RealOptionsData.GetInt(Int32OptionNames.NumLongTasks) + Main.RealOptionsData.GetInt(Int32OptionNames.NumShortTasks); public static bool IsAllAlive => Main.PlayerStates.Values.All(state => state.countTypes == CountTypes.OutOfGame || !state.IsDead); diff --git a/Patches/HudPatch.cs b/Patches/HudPatch.cs index d6af0f8f8..173a1d595 100644 --- a/Patches/HudPatch.cs +++ b/Patches/HudPatch.cs @@ -1387,7 +1387,7 @@ internal static class TaskPanelBehaviourPatch { FinalTextBuilder.Append("\r\n\r\n") .Append("") - .Append(string.Join('\n', Main.EnumeratePlayerControls().Select(pc => new { pc, alive = pc.IsAlive() }).OrderByDescending(x => x.alive).Select(x => $"{(!x.alive ? "<#777777>" : "")}{HotPotato.GetIndicator(x.pc.PlayerId)}{(x.alive ? x.pc.PlayerId.ColoredPlayerName() : Main.AllPlayerNames.GetValueOrDefault(x.pc.PlayerId, $"ID {x.pc.PlayerId}"))}{(!x.alive ? $" <#ff0000>{GetString("Dead")}" : "")}"))) + .Append(string.Join('\n', Main.EnumeratePlayerControls().Select(pc => new { pc, alive = pc.IsAlive() }).OrderByDescending(x => x.alive).Select(x => $"{(!x.alive ? "<#777777>" : "")}{HotPotato.GetIndicator(x.pc.PlayerId)}{(x.alive ? x.pc.PlayerId.ColoredPlayerName() : Main.AllPlayerNames.GetValueOrDefault(x.pc.PlayerId, $"ID {x.pc.PlayerId}"))}{(!x.alive ? $" <#ff0000>{GetString("Dead")}" : "")}"))) .Append(""); break; }