Blessed shield on game start

This commit is contained in:
Gurge44 committed 2026-02-10 08:39:23 +01:00
1 parent f53d04cc13
commit 9e800908c5
2 files changed
+19 -32

No files matched your search

+5 -2
View File
@@ -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;
+14 -30
View File
@@ -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<byte> 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 : $"<size=80%>{(seer.IsModdedClient() ? string.Format(Translator.GetString("SafeguardSuffixTimer"), ShieldTimer.GetRemainingTime(ShieldDuration.GetInt())) : Translator.GetString("SafeguardSuffix"))}</size>";
return ShieldTimer == null ? string.Empty : $"<size=80%>{(seer.IsModdedClient() ? string.Format(Translator.GetString("SafeguardSuffixTimer"), (int)Math.Ceiling(ShieldTimer.Remaining.TotalSeconds)) : Translator.GetString("SafeguardSuffix"))}</size>";
}
}