From 9e800908c51882f08dc069ad6da7222ff81b2504 Mon Sep 17 00:00:00 2001 From: Gurge44 Date: Tue, 10 Feb 2026 08:39:23 +0100 Subject: [PATCH] Blessed shield on game start --- Patches/IntroPatch.cs | 7 ++-- Roles/Standard/Addons/Common/Blessed.cs | 44 ++++++++----------------- 2 files changed, 19 insertions(+), 32 deletions(-) diff --git a/Patches/IntroPatch.cs b/Patches/IntroPatch.cs index ac0688e1a..95de86d3e 100644 --- a/Patches/IntroPatch.cs +++ b/Patches/IntroPatch.cs @@ -1205,11 +1205,11 @@ internal static class IntroCutsceneDestroyPatch StartGameHostPatch.RpcSetRoleReplacer.SetActualSelfRolesAfterOverride(); - var doubleAgents = Main.EnumerateAlivePlayerControls().Where(x => x.Is(CustomRoles.DoubleAgent)).ToList(); + var doubleAgents = aapc.Where(x => x.Is(CustomRoles.DoubleAgent)).ToList(); if (doubleAgents.Count > 0) { - Main.EnumerateAlivePlayerControls().DoIf(x => x.Is(Team.Impostor), x => + aapc.DoIf(x => x.Is(Team.Impostor), x => { var sender = CustomRpcSender.Create("Double Agent", SendOption.Reliable); doubleAgents.ForEach(da => sender.RpcSetRole(da, RoleTypes.Impostor, x.OwnerId, changeRoleMap: true)); @@ -1311,6 +1311,9 @@ internal static class IntroCutsceneDestroyPatch switch (Options.CurrentGameMode) { + case CustomGameMode.Standard: + Blessed.AfterMeetingTasks(); + break; case CustomGameMode.KingOfTheZones: Main.Instance.StartCoroutine(KingOfTheZones.GameStart()); break; diff --git a/Roles/Standard/Addons/Common/Blessed.cs b/Roles/Standard/Addons/Common/Blessed.cs index 1ca66eb68..218c2d3cd 100644 --- a/Roles/Standard/Addons/Common/Blessed.cs +++ b/Roles/Standard/Addons/Common/Blessed.cs @@ -1,6 +1,5 @@ -using System.Collections; +using System; using System.Collections.Generic; -using System.Diagnostics; using EHR.Modules; using EHR.Modules.Extensions; using Hazel; @@ -15,7 +14,7 @@ public class Blessed : IAddon private static OptionItem MinLivingPlayersToActivateShield; public static HashSet ShieldActive = []; - private static Stopwatch ShieldTimer; + private static CountdownTimer ShieldTimer; public void SetupCustomOption() { @@ -41,41 +40,26 @@ public class Blessed : IAddon ShieldActive.Add(pc.PlayerId); } - ShieldTimer = Stopwatch.StartNew(); - Utils.SendRPC(CustomRPC.Blessed, 1); - Main.Instance.StartCoroutine(CoRoutine()); - return; - - IEnumerator CoRoutine() + ShieldTimer = new CountdownTimer(ShieldDuration.GetInt(), () => { - int duration = ShieldDuration.GetInt(); - while (ShieldTimer.GetRemainingTime(duration) > 0 && !(GameStates.IsMeeting || ExileController.Instance || GameStates.IsEnded || !GameStates.InGame)) yield return null; - - ShieldTimer.Reset(); - Utils.SendRPC(CustomRPC.Blessed, 2); - - if (GameStates.IsInTask && !ExileController.Instance && !AntiBlackout.SkipTasks) - ShieldActive.ToValidPlayers().Do(x => Utils.NotifyRoles(SpecifySeer: x, SpecifyTarget: x)); - - ShieldActive = []; - } + ShieldTimer = null; + ShieldActive.ToValidPlayers().Do(x => Utils.NotifyRoles(SpecifySeer: x, SpecifyTarget: x)); + ShieldActive.Clear(); + }, onCanceled: () => + { + ShieldTimer = null; + ShieldActive.Clear(); + }); + Utils.SendRPC(CustomRPC.Blessed); } public static void ReceiveRPC(MessageReader reader) { - switch (reader.ReadPackedInt32()) - { - case 1: - ShieldTimer = Stopwatch.StartNew(); - break; - case 2: - ShieldTimer.Reset(); - break; - } + ShieldTimer = new CountdownTimer(ShieldDuration.GetInt(), () => ShieldTimer = null, onCanceled: () => ShieldTimer = null); } public static string GetSuffix(PlayerControl seer) { - return !ShieldTimer.IsRunning ? string.Empty : $"{(seer.IsModdedClient() ? string.Format(Translator.GetString("SafeguardSuffixTimer"), ShieldTimer.GetRemainingTime(ShieldDuration.GetInt())) : Translator.GetString("SafeguardSuffix"))}"; + return ShieldTimer == null ? string.Empty : $"{(seer.IsModdedClient() ? string.Format(Translator.GetString("SafeguardSuffixTimer"), (int)Math.Ceiling(ShieldTimer.Remaining.TotalSeconds)) : Translator.GetString("SafeguardSuffix"))}"; } } \ No newline at end of file