diff --git a/GameMode/BedWars.cs b/GameMode/BedWars.cs index c6142c016..fdb40627b 100644 --- a/GameMode/BedWars.cs +++ b/GameMode/BedWars.cs @@ -67,7 +67,7 @@ public static class BedWars private static OptionItem IronSwordDamageMultiplierOption; private static OptionItem DiamondSwordDamageMultiplierOption; - public static (Color Color, string Team) Winner = (Color.white, "No one wins"); + public static (Color Color, string Team) WinnerData = (Color.white, "No one wins"); public static void SetupCustomOption() { @@ -268,15 +268,52 @@ public static class BedWars if (Enum.GetValues().FindFirst(x => Main.AllAlivePlayerControls.Select(p => p.PlayerId).Concat(Reviving).All(p => !Data.TryGetValue(p, out PlayerData data) || data.Team == x), out BedWarsTeam team)) { - Winner = (team.GetColor(), team.GetName() + Translator.GetString("Win")); + WinnerData = (team.GetColor(), team.GetName() + Translator.GetString("Win")); CustomWinnerHolder.WinnerIds = Data.Where(x => x.Value.Team == team).Select(x => x.Key).ToHashSet(); Logger.Info($"Winners: {team.GetName()} - {string.Join(", ", CustomWinnerHolder.WinnerIds.Select(id => Main.AllPlayerNames.GetValueOrDefault(id, string.Empty)))}", "BedWars"); + SendRPC(); return true; } return false; } + private static void SendRPC() + { + var w = Utils.CreateRPC(CustomRPC.BedWarsSync); + + w.Write(WinnerData.Color); + w.Write(WinnerData.Team); + + w.Write(Data.Count); + + foreach ((byte id, PlayerData data) in Data) + { + w.Write(id); + w.Write((byte)data.Team); + } + + Utils.EndRPC(w); + } + + public static void ReceiveRPC(MessageReader reader) + { + WinnerData.Color = reader.ReadColor(); + WinnerData.Team = reader.ReadString(); + + int count = reader.ReadInt32(); + + for (int i = 0; i < count; i++) + { + byte id = reader.ReadByte(); + + if (!Data.TryGetValue(id, out PlayerData data)) + Data[id] = data = new PlayerData(); + + data.Team = (BedWarsTeam)reader.ReadInt32(); + } + } + public static void OnCheckMurder(PlayerControl killer, PlayerControl target) { if (IsGracePeriod || !Data.TryGetValue(killer.PlayerId, out PlayerData killerData) || !Data.TryGetValue(target.PlayerId, out PlayerData targetData) || killerData.Team == targetData.Team) return; @@ -322,7 +359,7 @@ public static class BedWars Trapped = []; Reviving = []; - Winner = (Color.white, "No one wins"); + WinnerData = (Color.white, "No one wins"); FixedUpdatePatch.LastUpdate = []; InventorySlots = InventorySlotsOption.GetInt(); @@ -358,7 +395,7 @@ public static class BedWars { if (Options.CurrentGameMode != CustomGameMode.BedWars) yield break; - Winner = (Color.white, "No one wins"); + WinnerData = (Color.white, "No one wins"); yield return new WaitForSecondsRealtime(3f); diff --git a/Modules/RPC.cs b/Modules/RPC.cs index 51ddf2b4c..ed5561ad0 100644 --- a/Modules/RPC.cs +++ b/Modules/RPC.cs @@ -176,7 +176,8 @@ public enum CustomRPC KOTZSync, SpeedrunSync, NaturalDisastersSync, - TMGSync + TMGSync, + BedWarsSync } public enum Sounds @@ -1302,6 +1303,11 @@ internal static class RPCHandlerPatch TheMindGame.ReceiveRPC(reader); break; } + case CustomRPC.BedWarsSync: + { + BedWars.ReceiveRPC(reader); + break; + } case CustomRPC.ParityCopCommand: { ParityCop.ReceiveRPC(reader); @@ -1676,3 +1682,4 @@ internal static class PlayerPhysicsRPCHandlerPatch } } + diff --git a/Modules/Utils.cs b/Modules/Utils.cs index a99cf33ad..867f1ff34 100644 --- a/Modules/Utils.cs +++ b/Modules/Utils.cs @@ -246,7 +246,7 @@ public static class Utils public static bool IsAnySabotageActive() { - return CustomSabotage.Instances.Count > 0 || new[] { SystemTypes.Electrical, SystemTypes.Reactor, SystemTypes.Laboratory, SystemTypes.LifeSupp, SystemTypes.Comms, SystemTypes.HeliSabotage, SystemTypes.MushroomMixupSabotage }.Any(IsActive); + return CustomSabotage.Instances.Count > 0 || new[] { SystemTypes.Electrical, SystemTypes.Reactor, SystemTypes.Laboratory, SystemTypes.LifeSupp, SystemTypes.Comms, SystemTypes.HeliSabotage, SystemTypes.MushroomMixupSabotage, (SystemTypes)SubmergedCompatibility.SubmergedSystemTypes.Ballast }.Any(IsActive); } public static bool IsActive(SystemTypes type) @@ -4180,3 +4180,4 @@ public class Message(string text, byte sendTo = byte.MaxValue, string title = "" public byte SendTo { get; } = sendTo; public string Title { get; } = title; } + diff --git a/Patches/HudSpritePatch.cs b/Patches/HudSpritePatch.cs index 73244fcd9..1ae71fd2d 100644 --- a/Patches/HudSpritePatch.cs +++ b/Patches/HudSpritePatch.cs @@ -40,7 +40,7 @@ public static class HudSpritePatch if (player == null) return; if (!Main.EnableCustomButton.Value || !Main.ProcessShapeshifts || Mastermind.ManipulatedPlayers.ContainsKey(player.PlayerId) || ExileController.Instance || GameStates.IsMeeting) return; - if ((!SetHudActivePatch.IsActive && !MeetingStates.FirstMeeting) || !player.IsAlive() || Options.CurrentGameMode is not CustomGameMode.Standard and not CustomGameMode.CaptureTheFlag) return; + if ((!SetHudActivePatch.IsActive && !MeetingStates.FirstMeeting) || !player.IsAlive()) return; if (ResetButtonIcons || !AmongUsClient.Instance.IsGameStarted || !Main.IntroDestroyed || GameStates.IsLobby || GameStates.IsNotJoined || !GameStates.InGame) { @@ -516,3 +516,4 @@ public static class HudSpritePatch } } } + diff --git a/Patches/OutroPatch.cs b/Patches/OutroPatch.cs index 806a871be..2dc1d1c0a 100644 --- a/Patches/OutroPatch.cs +++ b/Patches/OutroPatch.cs @@ -13,7 +13,6 @@ using TMPro; using UnityEngine; using static EHR.Translator; - namespace EHR; [HarmonyPatch(typeof(AmongUsClient), nameof(AmongUsClient.OnGameEnd))] @@ -281,7 +280,7 @@ internal static class SetEverythingUpPatch } case CustomGameMode.BedWars: { - (Color Color, string Team) winnerData = AmongUsClient.Instance.AmHost ? BedWars.Winner : (Color.black, string.Empty); + (Color Color, string Team) winnerData = BedWars.WinnerData; __instance.BackgroundBar.material.color = winnerData.Color; winnerText.text = winnerData.Team; winnerText.color = winnerData.Color; @@ -717,4 +716,5 @@ internal static class SetEverythingUpPatch return name; } } -} \ No newline at end of file + +} diff --git a/Roles/Impostor/Inhibitor.cs b/Roles/Impostor/Inhibitor.cs index 6b504e82b..a4b89a6e2 100644 --- a/Roles/Impostor/Inhibitor.cs +++ b/Roles/Impostor/Inhibitor.cs @@ -50,7 +50,7 @@ internal class Inhibitor : RoleBase public override bool CanUseKillButton(PlayerControl pc) { - return base.CanUseKillButton(pc) && !Utils.IsActive(SystemTypes.Electrical) && !Utils.IsActive(SystemTypes.Comms) && !Utils.IsActive(SystemTypes.MushroomMixupSabotage) && !Utils.IsActive(SystemTypes.Laboratory) && !Utils.IsActive(SystemTypes.LifeSupp) && !Utils.IsActive(SystemTypes.Reactor) && !Utils.IsActive(SystemTypes.HeliSabotage); + return base.CanUseKillButton(pc) && !Utils.IsAnySabotageActive(); } public override void SetKillCooldown(byte id) @@ -73,4 +73,4 @@ internal class Inhibitor : RoleBase { Main.AllPlayerKillCooldown[InhibitorId] = InhibitorCDAfterMeetings.GetFloat(); } -} \ No newline at end of file +}