diff --git a/Modules/CustomOptionsHolder.cs b/Modules/CustomOptionsHolder.cs index 2aec984..9c98f0d 100644 --- a/Modules/CustomOptionsHolder.cs +++ b/Modules/CustomOptionsHolder.cs @@ -297,9 +297,12 @@ namespace AmongUsRevamped // Roles public static OptionItem TabGroupCrewmate; public static OptionItem MayorPerc; + public static OptionItem MayorExtraVoteCount; + public static OptionItem MayorVentToMeeting; public static OptionItem TabGroupNeutral; public static OptionItem JesterPerc; + public static OptionItem JesterCanVent; public static OptionItem TabGroupImpostor; @@ -379,15 +382,22 @@ namespace AmongUsRevamped // Custom role settings TabGroupCrewmate = TextOptionItem.Create(100000, Translator.Get("tabGroupCrewmate"), TabGroup.CustomRoleSettings) .SetColor(CL.Hex("#8cffff")); - MayorPerc = IntegerOptionItem.Create(100001, Translator.Get("mayorPerc"), new(0, 100, 5), 0, TabGroup.CustomRoleSettings, false) + MayorPerc = IntegerOptionItem.Create(100001, Translator.Get("Mayor"), new(0, 100, 5), 0, TabGroup.CustomRoleSettings, false) .SetValueFormat(OptionFormat.Percent) .SetColor(CL.Hex("#204d42")); + MayorExtraVoteCount = IntegerOptionItem.Create(100002, Translator.Get("mayorExtraVoteCount"), new(1, 15, 1), 1, TabGroup.CustomRoleSettings, false) + .SetValueFormat(OptionFormat.Level) + .SetParent(MayorPerc); + MayorVentToMeeting = BooleanOptionItem.Create(100003, Translator.Get("mayorVentToMeeting"), true, TabGroup.CustomRoleSettings, false) + .SetParent(MayorPerc); TabGroupNeutral = TextOptionItem.Create(101000, Translator.Get("tabGroupNeutral"), TabGroup.CustomRoleSettings) .SetColor(CL.Hex("#FFFF99")); - JesterPerc = IntegerOptionItem.Create(101001, Translator.Get("jesterPerc"), new(0, 100, 5), 0, TabGroup.CustomRoleSettings, false) + JesterPerc = IntegerOptionItem.Create(101001, Translator.Get("Jester"), new(0, 100, 5), 0, TabGroup.CustomRoleSettings, false) .SetValueFormat(OptionFormat.Percent) .SetColor(CL.Hex("#ec62a5")); + JesterCanVent = BooleanOptionItem.Create(101002, Translator.Get("jesterCanVent"), false, TabGroup.CustomRoleSettings, false) + .SetParent(MayorPerc); TabGroupImpostor = TextOptionItem.Create(102000, Translator.Get("tabGroupImpostor"), TabGroup.CustomRoleSettings) .SetColor(CL.Hex("#ff1919")); diff --git a/Modules/CustomRoleManagement.cs b/Modules/CustomRoleManagement.cs index 971b3b7..87ad225 100644 --- a/Modules/CustomRoleManagement.cs +++ b/Modules/CustomRoleManagement.cs @@ -73,7 +73,7 @@ public static class CustomRoleManagement sb.Append(c); } return sb.ToString(); -} + } public static string GetActiveRoles() { @@ -123,7 +123,15 @@ public static class CustomRoleManagement PendingRoleMessages++; new LateTask(() => { - Utils.SendPrivateMessage(player, roleMessages[role]); + if (Utils.InGame) + { + Utils.SendPrivateMessage(player, roleMessages[role]); + } + else + { + Logger.Info("Role sending was forcefully canceled. This should not happen.", "SendRoleMessages") + } + PendingRoleMessages--; if (PendingRoleMessages <= 0) diff --git a/Patches/ExilePatch.cs b/Patches/ExilePatch.cs index 9b8783a..e2f303b 100644 --- a/Patches/ExilePatch.cs +++ b/Patches/ExilePatch.cs @@ -24,12 +24,18 @@ class ExileControllerWrapUpPatch Logger.Info($" {ejectedPlayer.PlayerName} was ejected", "ExileController"); - if (!CustomRoleManagement.PlayerRoles.TryGetValue(ejectedPlayer.PlayerId, out var role)) return; - - if (role == "Jester") + if (CustomRoleManagement.PlayerRoles.TryGetValue(ejectedPlayer.PlayerId, out var role) && role == "Jester") { Utils.CustomWinnerEndGame(pc, 1); + NormalGameEndChecker.LastWinReason = $"Jester wins! (Voted)\n\nImpostors: {impostorList}" + (string.IsNullOrEmpty(customRoles) ? "" : "\n\n" + customRoles); + return; } + + CustomRoleManagement.SendRoleMessages(new Dictionary + { + { "Jester", Translator.Get("JesterPriv")}, + { "Mayor", Translator.Get("MayorPriv", Options.MayorExtraVoteCount.GetInt())} + }); } } } \ No newline at end of file diff --git a/Patches/IntroPatch.cs b/Patches/IntroPatch.cs index c1ad19f..a3f4fa1 100644 --- a/Patches/IntroPatch.cs +++ b/Patches/IntroPatch.cs @@ -15,15 +15,10 @@ internal static class CoShowIntroPatch if (!AmongUsClient.Instance.AmHost) return; - if ((Options.Gamemode.GetValue() == 0 || Options.Gamemode.GetValue() == 1) && !Utils.isHideNSeek) - { - CustomRoleManagement.AssignRoles(); - } - CustomRoleManagement.SendRoleMessages(new Dictionary { { "Jester", Translator.Get("JesterPriv")}, - { "Mayor", Translator.Get("MayorPriv")} + { "Mayor", Translator.Get("MayorPriv", Options.MayorExtraVoteCount.GetInt())} }); if (Options.DisableAnnoyingMeetingCalls.GetBool()) @@ -51,7 +46,7 @@ class BeginCrewmatePatch PlayerControl.LocalPlayer.CmdReportDeadBody(null); MeetingHud.Instance.RpcClose(); - }, 6.5f, "SetChatVisible"); + }, 7f, "SetChatVisible"); } if (Main.GM.Value) diff --git a/Patches/MeetingPatches.cs b/Patches/MeetingPatches.cs new file mode 100644 index 0000000..973e1a2 --- /dev/null +++ b/Patches/MeetingPatches.cs @@ -0,0 +1,44 @@ +namespace AmongUsRevamped; + +[HarmonyPatch(typeof(MeetingHud), nameof(MeetingHud.CheckForEndVoting))] +public static class CheckForEndVotingPatch +{ + public static bool Prefix(MeetingHud __instance) + { + if (!AmongUsClient.Instance.AmHost) return true; + + if (!__instance.playerStates.All(ps => ps.AmDead || ps.DidVote)) return true; + + var votes = __instance.CalculateVotes(); + var visualVotes = new List(); + + foreach (var ps in __instance.playerStates) + { + if (ps == null) continue; + + byte voterId = ps.TargetPlayerId; + byte votedFor = ps.VotedFor; + if (votedFor == byte.MaxValue) continue; + + visualVotes.Add(new MeetingHud.VoterState { VoterId = voterId, VotedForId = votedFor }); + + if (CustomRoleManagement.PlayerRoles.TryGetValue(voterId, out string role) && role == "Mayor") + { + int extraVotes = Options.MayorExtraVoteCount.GetInt(); + if (!votes.TryGetValue(votedFor, out int currentVotes)) currentVotes = 0; + votes[votedFor] = currentVotes + extraVotes; + + for (int i = 0; i < extraVotes; i++) + visualVotes.Add(new MeetingHud.VoterState { VoterId = voterId, VotedForId = votedFor }); + } + } + + var max = votes.MaxPair(out var tie); + var exiled = GameData.Instance.AllPlayers.ToArray().FirstOrDefault(p => !tie && p.PlayerId == max.Key); + var statesArray = visualVotes.ToArray(); + + __instance.RpcVotingComplete(statesArray, exiled, tie); + + return false; + } +} \ No newline at end of file diff --git a/Patches/OnGameStartedPatch.cs b/Patches/OnGameStartedPatch.cs index 8a03ea1..8e56184 100644 --- a/Patches/OnGameStartedPatch.cs +++ b/Patches/OnGameStartedPatch.cs @@ -15,6 +15,10 @@ internal class CoStartGamePatch Logger.Info(" -------- GAME STARTED --------", "StartGame"); Logger.Info($" Gamemode: {Options.Gamemode.GetValue()}", "StartGame"); + if ((Options.Gamemode.GetValue() == 0 || Options.Gamemode.GetValue() == 1) && !Utils.isHideNSeek) + { + CustomRoleManagement.AssignRoles(); + } NormalGameEndChecker.imps.Clear(); NormalGameEndChecker.LastWinReason = ""; @@ -40,6 +44,31 @@ class PlayerControlSetRolePatch roleType = RoleTypes.CrewmateGhost; } + if (CustomRoleManagement.PlayerRoles.TryGetValue(__instance.PlayerId, out var role) && role == "Mayor") + { + if (Options.MayorVentToMeeting.GetBool()) + { + roleType = RoleTypes.Engineer; + Logger.Info($"{__instance.Data.PlayerName} is Engineer due to being Mayor", "SetRolePatch"); + } + else + { + roleType = RoleTypes.Crewmate; + } + } + if (CustomRoleManagement.PlayerRoles.TryGetValue(__instance.PlayerId, out var r) && r == "Jester") + { + if (Options.JesterCanVent.GetBool()) + { + roleType = RoleTypes.Engineer; + Logger.Info($"{__instance.Data.PlayerName} is Engineer due to being Jester", "SetRolePatch"); + } + else + { + roleType = RoleTypes.Crewmate; + } + } + if (Utils.isHideNSeek && i == 0) { int seekersCount = Options.NumSeekers.GetInt(); diff --git a/Patches/VentPatches.cs b/Patches/VentPatches.cs new file mode 100644 index 0000000..873f218 --- /dev/null +++ b/Patches/VentPatches.cs @@ -0,0 +1,16 @@ +namespace AmongUsRevamped; + +[HarmonyPatch(typeof(Vent), nameof(Vent.EnterVent))] +class EnterVentPatch +{ + public static void Postfix(Vent __instance, [HarmonyArgument(0)] PlayerControl pc) + { + if (!AmongUsClient.Instance.AmHost) return; + + if (CustomRoleManagement.PlayerRoles.TryGetValue(pc.PlayerId, out var role) && role == "Mayor") + { + pc.CmdReportDeadBody(null); + Logger.Info($" The Mayor, {pc.Data.PlayerName}, called a meeting by venting", "EnterVent"); + } + } +} \ No newline at end of file diff --git a/Resources/Language/English.json b/Resources/Language/English.json index e5f6492..ea2a768 100644 --- a/Resources/Language/English.json +++ b/Resources/Language/English.json @@ -38,9 +38,7 @@ "slashStartAndEndGameCmd": "Who Can Use /startgame And /endgame", "tabGroupCrewmate": "Crewmate Roles", - "mayorPerc": "PLACEHOLDER", "tabGroupNeutral": "Neutral Roles", - "jesterPerc": "PLACEHOLDER", "tabGroupImpostor": "Impostor Roles", "tabGroupStandard": "Standard", @@ -203,16 +201,24 @@ "noKcdMode": "0 Kill Cooldown:\n\nImpostors have no kill cooldown, Crewmates have low tasks\nThink fast and pay attention!", "SnSModeOne": "Shift and Seek:\n\nImpostors can only kill someone while shapeshifted as them\nEmergency Meetings = Off", - "SnSModeTwo": "Crew wins by tasks/surviving {0}s\nImp wins by killing\nOne wrong kill = Can't kill for {1}s\n{2} wrong kills = suicide", + "SnSModeTwo": "Crew wins by tasks/surviving {0}s\nImp wins by killing\nOne wrong kill = Can't kill for {1}s\n{2} wrong kill(s) = suicide", "speedrunMode": "Speedrun:\n\nEveryone is a crewmate. The 1st player to finish tasks wins the game. Game auto ends after {0}s", "allCommandsFull": "Commands:\n/r - Current mode description\n/0kc, /sns, /sp - Specific mode description\n/l - Shows last winner info\n/kick, /ban - Bans or kicks a player by name\n/ckick, /cban - Bans or kicks a player by color", "allCommandsOne": "Commands:\n/r - Current mode description\n/0kc, /sns, /sp - Specific mode description\n/l - Shows last winner info", "allCommandsTwo": "/kick, /ban - Bans or kicks a player by name\n/ckick, /cban - Bans or kicks a player by color", "socialsAll": "AUR socials:\n\ng i t h u b . c o m /\nApeMV/AmongUsRevamped\n\nd i s c o r d . g g /\n83Zhzhyhya", "translationReloaded": "Your file has successfully been reset.\nTo apply the changes, restart your game.", + "Mayor": "Mayor", - "MayorPriv": "PRIVATE:\n\nYour role is Mayor!\n\nYou are a crewmate with i total votes. Use your voting power to eject Impostors.", + "MayorPublic": "Mayor:\n\nThe Mayor is a crewmate with {0} extra vote(s). Depending on settings, they can vent to call a meeting.", + "MayorPriv": "Your role is Mayor!\n\nYou are a crewmate with {0} extra vote(s). If you are an Engineer, vent to call a meeting.", + "mayorExtraVoteCount": "Extra Votes", + "mayorVentToMeeting": "Can Vent To Call Meetings", "Jester": "Jester", - "JesterPriv": "PRIVATE:\n\nYour role is Jester!\nYou are NOT a crewmate!\n\nYou win by getting voted. Act as suspicious as possible." + "JesterPublic": "Jester:\n\nThe Jester wins alone by getting voted. Their goal is to act as suspicious as possible.", + "JesterPriv": "Your role is Jester!\nYou are NOT a crewmate!\n\nYou win by getting voted. Act as suspicious as possible.", + "jesterCanVent": "Can Vent", + + "roleDescriptionHelp": "Your Role can be seen at the start of meetings. It is shown by a private text, looking like the host." }