From 7b7076e51e0caad63a32a54692fa8ef2febcd87d Mon Sep 17 00:00:00 2001 From: Gurge44 Date: Mon, 13 May 2024 20:26:23 +0200 Subject: [PATCH] Fix bugs --- Modules/GhostRolesManager.cs | 11 ++++++++++- Modules/Utils.cs | 3 +++ Patches/MeetingHudPatch.cs | 11 ++++++++--- Patches/OnGameStartedPatch.cs | 2 ++ Patches/PlayerControlPatch.cs | 18 ++---------------- Roles/AddOns/GhostRoles/Haunter.cs | 6 +++++- Roles/Crewmate/Medic.cs | 18 ++++++++---------- Roles/Crewmate/Tracefinder.cs | 2 +- Roles/Crewmate/Tracker.cs | 2 +- Roles/Neutral/Vulture.cs | 2 +- 10 files changed, 41 insertions(+), 34 deletions(-) diff --git a/Modules/GhostRolesManager.cs b/Modules/GhostRolesManager.cs index 9ff9317ab..289138c42 100644 --- a/Modules/GhostRolesManager.cs +++ b/Modules/GhostRolesManager.cs @@ -55,8 +55,17 @@ namespace EHR.Modules { if (AssignedGhostRoles.Count >= GhostRoles.Count) return false; if (pc.IsAlive() || pc.GetCountTypes() is CountTypes.None or CountTypes.OutOfGame || pc.Is(CustomRoles.EvilSpirit)) return false; + var suitableRole = GetSuitableGhostRole(pc); - if (suitableRole == CustomRoles.Specter && IsPartnerPickedRole()) return false; + switch (suitableRole) + { + case CustomRoles.Specter when IsPartnerPickedRole(): + return false; + case CustomRoles.Haunter: + GhostRoles.Remove(CustomRoles.Haunter); + break; + } + return suitableRole.IsGhostRole() && !AssignedGhostRoles.Any(x => x.Key == pc.PlayerId || x.Value.Role == suitableRole); bool IsPartnerPickedRole() => Main.PlayerStates[pc.PlayerId].Role switch diff --git a/Modules/Utils.cs b/Modules/Utils.cs index 60e0cc2c3..37339d0f1 100644 --- a/Modules/Utils.cs +++ b/Modules/Utils.cs @@ -2520,6 +2520,9 @@ public static class Utils case CustomRoles.Markseeker: Markseeker.OnDeath(target); break; + case CustomRoles.Medic: + Medic.IsDead(target); + break; } if (target == null) return; diff --git a/Patches/MeetingHudPatch.cs b/Patches/MeetingHudPatch.cs index b479b17f7..72f6540f1 100644 --- a/Patches/MeetingHudPatch.cs +++ b/Patches/MeetingHudPatch.cs @@ -362,6 +362,8 @@ class CheckForEndVotingPatch int impnum = 0; int neutralnum = 0; + var DecidedWinner = false; + if (CustomRoles.Bard.RoleExist()) { Bard.OnMeetingHudDestroy(ref name); @@ -417,8 +419,6 @@ class CheckForEndVotingPatch name += $" ({Utils.ColorString(Utils.GetRoleColor(CustomRoles.Brakar), GetString("Brakar"))})"; } - var DecidedWinner = false; - if (crole == CustomRoles.Jester) { name = string.Format(GetString("ExiledJester"), realName, coloredRole); @@ -486,7 +486,7 @@ class CheckForEndVotingPatch name = name.Replace("color=", string.Empty) + ""; - EjectionText = name.Split('\n')[0]; + EjectionText = name.Split('\n')[DecidedWinner ? 1 : 0]; _ = new LateTask(() => { @@ -745,6 +745,11 @@ class MeetingHudStartPatch AddMsg(MimicMsg, ipc.PlayerId, Utils.ColorString(Utils.GetRoleColor(CustomRoles.Mimic), GetString("MimicMsgTitle"))); } + if (msgToSend.Count > 0) + { + _ = new LateTask(() => { msgToSend.Do(x => Utils.SendMessage(x.MESSAGE, x.TARGET_ID, x.TITLE)); }, 6f, "Meeting Start Notify"); + } + Main.CyberStarDead.Clear(); Express.SpeedNormal.Clear(); Express.SpeedUp.Clear(); diff --git a/Patches/OnGameStartedPatch.cs b/Patches/OnGameStartedPatch.cs index 13dc4e465..3b1c2b2b6 100644 --- a/Patches/OnGameStartedPatch.cs +++ b/Patches/OnGameStartedPatch.cs @@ -123,6 +123,8 @@ internal class ChangeRoleSettings Main.LastNotifyNames = []; + CheckForEndVotingPatch.EjectionText = string.Empty; + Arsonist.CurrentDousingTarget = byte.MaxValue; Revolutionist.CurrentDrawTarget = byte.MaxValue; Main.PlayerColors = []; diff --git a/Patches/PlayerControlPatch.cs b/Patches/PlayerControlPatch.cs index d236e32b6..8b0cf59b8 100644 --- a/Patches/PlayerControlPatch.cs +++ b/Patches/PlayerControlPatch.cs @@ -1828,22 +1828,8 @@ class CoEnterVentPatch { try { - MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(__instance.NetId, (byte)RpcCalls.BootFromVent, SendOption.Reliable); - writer.WritePacked(127); - AmongUsClient.Instance.FinishRpcImmediately(writer); - _ = new LateTask(() => - { - try - { - int clientId = __instance.myPlayer.GetClientId(); - MessageWriter writer2 = AmongUsClient.Instance.StartRpcImmediately(__instance.NetId, (byte)RpcCalls.BootFromVent, SendOption.Reliable, clientId); - writer2.Write(id); - AmongUsClient.Instance.FinishRpcImmediately(writer2); - } - catch - { - } - }, 0.5f, "Fix DesyncImpostor Stuck"); + __instance.RpcBootFromVent(id); + return false; } catch { diff --git a/Roles/AddOns/GhostRoles/Haunter.cs b/Roles/AddOns/GhostRoles/Haunter.cs index e1b3ff8c7..740f62a51 100644 --- a/Roles/AddOns/GhostRoles/Haunter.cs +++ b/Roles/AddOns/GhostRoles/Haunter.cs @@ -16,6 +16,8 @@ namespace EHR.Roles.AddOns.GhostRoles private static OptionItem NumberOfReveals; private List WarnedImps = []; + + private long WarnTimeStamp = 0; public Team Team => Team.Crewmate | Team.Neutral; public int Cooldown => 900; @@ -76,6 +78,8 @@ namespace EHR.Roles.AddOns.GhostRoles imp.Notify(Translator.GetString("Haunter1TaskLeft"), 300f); WarnedImps.Add(imp.PlayerId); } + + WarnTimeStamp = Utils.TimeStamp; } public void OnFinishedTasks(PlayerControl pc) @@ -103,7 +107,7 @@ namespace EHR.Roles.AddOns.GhostRoles public void Update(PlayerControl pc) { - if (WarnedImps.Count == 0) return; + if (WarnedImps.Count == 0 || WarnTimeStamp == Utils.TimeStamp) return; if (WarnedImps.Any(imp => TargetArrow.GetArrows(Utils.GetPlayerById(imp), pc.PlayerId) == "・")) { diff --git a/Roles/Crewmate/Medic.cs b/Roles/Crewmate/Medic.cs index 70e48f597..b0b386df5 100644 --- a/Roles/Crewmate/Medic.cs +++ b/Roles/Crewmate/Medic.cs @@ -42,12 +42,7 @@ public class Medic : RoleBase "DeactivationIsVisibleOFF", ]; - enum Visible - { - Immediately, - AfterMeeting, - OFF, - } + public override bool IsEnable => playerIdList.Count > 0; public static void SetupCustomOption() { @@ -95,8 +90,6 @@ public class Medic : RoleBase Main.ResetCamPlayerList.Add(playerId); } - public override bool IsEnable => playerIdList.Count > 0; - private static void SendRPCForProtectList() { if (!Utils.DoRPC) return; @@ -247,8 +240,6 @@ public class Medic : RoleBase if (!target.Is(CustomRoles.Medic)) return; if (!ShieldDeactivatesWhenMedicDies.GetBool()) return; - if (playerIdList.Any(x => Utils.GetPlayerById(x).IsAlive())) return; // If not all Medic-s are dead, return - Utils.NotifyRoles(SpecifySeer: target); ProtectList.Clear(); @@ -293,4 +284,11 @@ public class Medic : RoleBase return string.Empty; } + + enum Visible + { + Immediately, + AfterMeeting, + OFF, + } } \ No newline at end of file diff --git a/Roles/Crewmate/Tracefinder.cs b/Roles/Crewmate/Tracefinder.cs index 4a9278433..66684bfad 100644 --- a/Roles/Crewmate/Tracefinder.cs +++ b/Roles/Crewmate/Tracefinder.cs @@ -64,7 +64,7 @@ public class Tracefinder : RoleBase public static void OnPlayerDead(PlayerControl target) { - if (!On || !GameStates.IsInTask || target == null) return; + if (!On || !GameStates.IsInTask || target == null || target.Data.Disconnected) return; float delay; if (ArrowDelayMax.GetFloat() < ArrowDelayMin.GetFloat()) delay = 0f; diff --git a/Roles/Crewmate/Tracker.cs b/Roles/Crewmate/Tracker.cs index c8eb2f3bb..92069a5e5 100644 --- a/Roles/Crewmate/Tracker.cs +++ b/Roles/Crewmate/Tracker.cs @@ -103,7 +103,7 @@ namespace EHR.Roles.Crewmate if (!TrackerTarget.ContainsKey(seer.PlayerId)) return string.Empty; if (GameStates.IsMeeting) return string.Empty; - return TrackerTarget[seer.PlayerId].Aggregate(string.Empty, (current, trackTarget) => current + Utils.ColorString(CanGetColoredArrow.GetBool() ? Main.PlayerColors[trackTarget] : Color.white, TargetArrow.GetArrows(seer, trackTarget) + LocateArrow.GetArrows(seer))); + return TrackerTarget[seer.PlayerId].Aggregate(string.Empty, (current, trackTarget) => current + Utils.ColorString(CanGetColoredArrow.GetBool() ? Main.PlayerColors[trackTarget] : Color.white, TargetArrow.GetArrows(seer, trackTarget))) + LocateArrow.GetArrows(seer); } public static bool IsTrackTarget(PlayerControl seer, PlayerControl target) diff --git a/Roles/Neutral/Vulture.cs b/Roles/Neutral/Vulture.cs index 1cc702172..3b05f5228 100644 --- a/Roles/Neutral/Vulture.cs +++ b/Roles/Neutral/Vulture.cs @@ -122,7 +122,7 @@ public class Vulture : RoleBase public static void OnPlayerDead(PlayerControl target) { - if (!ArrowsPointingToDeadBody.GetBool()) return; + if (!ArrowsPointingToDeadBody.GetBool() || target.Data.Disconnected) return; foreach (byte pc in playerIdList) {