From b26ba4c6504c70d7d9b968bbb016c5db816a7db2 Mon Sep 17 00:00:00 2001 From: Gurge44 Date: Thu, 30 May 2024 12:36:51 +0200 Subject: [PATCH] Legacy Lovers --- CustomRoles.cs | 2 ++ Modules/CustomRoleSelector.cs | 16 ++++++++++++++++ Modules/CustomRolesHelper.cs | 3 +++ Modules/GuessManager.cs | 11 +++++++++++ Modules/OptionHolder.cs | 1 + Patches/IntroPatch.cs | 20 ++++++++++++++++++++ Resources/Lang/en_US.json | 10 +++++++++- Roles/AddOns/Common/Lovers.cs | 21 +++++++++++++++++++++ Roles/Crewmate/CrewmateVanillaRoles.cs | 2 ++ main.cs | 2 ++ 10 files changed, 87 insertions(+), 1 deletion(-) diff --git a/CustomRoles.cs b/CustomRoles.cs index 6bae7887d..444b8af0e 100644 --- a/CustomRoles.cs +++ b/CustomRoles.cs @@ -131,6 +131,8 @@ public enum CustomRoles Convener, CopyCat, Bloodhound, // Coroner + LovingCrewmate, + LovingImpostor, Crusader, Demolitionist, Deputy, diff --git a/Modules/CustomRoleSelector.cs b/Modules/CustomRoleSelector.cs index a49c9e665..77a35505e 100644 --- a/Modules/CustomRoleSelector.cs +++ b/Modules/CustomRoleSelector.cs @@ -4,6 +4,7 @@ using System.Linq; using AmongUs.GameOptions; using EHR.Roles.Impostor; using EHR.Roles.Neutral; +using EHR.Roles.AddOns.Common; using HarmonyLib; namespace EHR.Modules; @@ -83,12 +84,15 @@ internal static class CustomRoleSelector foreach (var id in Main.SetRoles.Keys.Where(id => Utils.GetPlayerById(id) == null).ToArray()) Main.SetRoles.Remove(id); + (bool Spawning, bool OneIsImp) LoversData = (Lovers.LegacyLovers.GetBool(), rd.Next(100) < Lovers.LovingImpostorSpawnChance.GetInt()); + foreach (var role in Enum.GetValues()) { int chance = role.GetMode(); if (role.IsVanilla() || chance == 0 || role.IsAdditionRole() || (role.OnlySpawnsWithPets() && !Options.UsePets.GetBool()) || (role != CustomRoles.Randomizer && role.IsCrewmate() && Options.AprilFoolsMode.GetBool()) || HnSManager.AllHnSRoles.Contains(role)) continue; switch (role) { + case CustomRoles.LovingCrewmate or CustomRoles.LovingImpostor when !Lovers.LegacyLovers.GetBool(): case CustomRoles.Commander when optImpNum <= 1 && Commander.CannotSpawnAsSoloImp.GetBool(): case CustomRoles.Changeling when Changeling.GetAvailableRoles(check: true).Count == 0: case CustomRoles.Camouflager when Camouflager.DoesntSpawnOnFungle.GetBool() && Main.CurrentMap == MapNames.Fungle: @@ -119,6 +123,18 @@ internal static class CustomRoleSelector else Roles[RoleAssignType.Crewmate].Add(info); } + LoversData.Spawning &= rd.Next(100) < Options.CustomAdtRoleSpawnRate[CustomRoles.Lovers].GetInt(); + + if (LoversData.Spawning) + { + if (LoversData.OneIsImp) + { + Roles[RoleAssignType.Crewmate].Add(new(CustomRoles.LovingCrewmate, 100, 1)); + Roles[RoleAssignType.Impostor].Add(new(CustomRoles.LovingImpostor, 100, 1)); + } + else Roles[RoleAssignType.Crewmate].Add(new(CustomRoles.LovingCrewmate, 100, 2)); + } + if (Roles[RoleAssignType.Impostor].Count == 0 && optNeutralKillingNum == 0 && optNonNeutralKillingNum == 0 && !Main.SetRoles.Values.Any(x => x.IsImpostor() || x.IsNK())) { Roles[RoleAssignType.Impostor].Add(new(CustomRoles.ImpostorEHR, 100, optImpNum)); diff --git a/Modules/CustomRolesHelper.cs b/Modules/CustomRolesHelper.cs index 0df8b7813..d9704c5c8 100644 --- a/Modules/CustomRolesHelper.cs +++ b/Modules/CustomRolesHelper.cs @@ -186,6 +186,8 @@ internal static class CustomRolesHelper CustomRoles.Altruist => CustomRoles.Crewmate, CustomRoles.Transmitter => CustomRoles.Crewmate, CustomRoles.Autocrat => CustomRoles.Crewmate, + CustomRoles.LovingCrewmate => CustomRoles.Crewmate, + CustomRoles.LovingImpostor => CustomRoles.Impostor, CustomRoles.ToiletMaster => CustomRoles.Crewmate, CustomRoles.Sentry => CustomRoles.Crewmate, CustomRoles.Perceiver => UsePets ? CustomRoles.Crewmate : CustomRoles.Engineer, @@ -557,6 +559,7 @@ internal static class CustomRolesHelper public static bool IsImpostor(this CustomRoles role) => role is CustomRoles.Impostor or + CustomRoles.LovingImpostor or CustomRoles.Godfather or CustomRoles.Shapeshifter or CustomRoles.ShapeshifterEHR or diff --git a/Modules/GuessManager.cs b/Modules/GuessManager.cs index 5ab837fe3..603d943fc 100644 --- a/Modules/GuessManager.cs +++ b/Modules/GuessManager.cs @@ -273,6 +273,10 @@ public static class GuessManager switch (target.GetCustomRole()) { + case CustomRoles.LovingCrewmate or CustomRoles.LovingImpostor when Lovers.CannotBeGuessed.GetBool(): + if (!isUI) Utils.SendMessage(GetString("GuessLovers"), pc.PlayerId); + else pc.ShowPopUp(GetString("GuessLovers")); + return true; case CustomRoles.Workaholic when Workaholic.WorkaholicVisibleToEveryone.GetBool(): if (!isUI) Utils.SendMessage(GetString("GuessWorkaholic"), pc.PlayerId); else pc.ShowPopUp(GetString("GuessWorkaholic")); @@ -347,6 +351,13 @@ public static class GuessManager return true; } + if (target.Is(CustomRoles.Lovers) && Lovers.CannotBeGuessed.GetBool()) + { + if (!isUI) Utils.SendMessage(GetString("GuessLovers"), pc.PlayerId); + else pc.ShowPopUp(GetString("GuessLovers")); + return true; + } + if (Jailor.playerIdList.Any(x => Main.PlayerStates[x].Role is Jailor { IsEnable: true } jl && jl.JailorTarget == target.PlayerId)) { if (!isUI) Utils.SendMessage(GetString("Can'tGuessJailed"), pc.PlayerId, title: Utils.ColorString(Utils.GetRoleColor(CustomRoles.Jailor), GetString("JailorTitle"))); diff --git a/Modules/OptionHolder.cs b/Modules/OptionHolder.cs index 8fc1a7992..fbf960bc0 100644 --- a/Modules/OptionHolder.cs +++ b/Modules/OptionHolder.cs @@ -206,6 +206,7 @@ public static class Options public static OptionItem SidekickCanKillJackal; public static OptionItem SidekickCanKillSidekick; + public static OptionItem VanillaCrewmateCannotBeGuessed; public static OptionItem EGCanGuessImp; public static OptionItem EGCanGuessAdt; public static OptionItem EGCanGuessTime; diff --git a/Patches/IntroPatch.cs b/Patches/IntroPatch.cs index 51324a6af..d360e5aa1 100644 --- a/Patches/IntroPatch.cs +++ b/Patches/IntroPatch.cs @@ -178,6 +178,17 @@ class BeginCrewmatePatch return false; } + if (PlayerControl.LocalPlayer.GetCustomRole() == CustomRoles.LovingCrewmate) + { + teamToDisplay = new(); + teamToDisplay.Add(PlayerControl.LocalPlayer); + teamToDisplay.Add(Main.LoversPlayers.First(x => x.PlayerId != PlayerControl.LocalPlayer.PlayerId)); + } + else if (PlayerControl.LocalPlayer.GetCustomRole() == CustomRoles.LovingImpostor) + { + teamToDisplay.Add(Main.LoversPlayers.First(x => x.PlayerId != PlayerControl.LocalPlayer.PlayerId)); + } + if (CustomTeamManager.EnabledCustomTeams.Count > 0) { var team = CustomTeamManager.GetCustomTeam(PlayerControl.LocalPlayer.PlayerId); @@ -223,6 +234,15 @@ class BeginCrewmatePatch __instance.ImpostorText.gameObject.SetActive(true); __instance.ImpostorText.text = GetString("SubText.Bloodlust"); } + else if (role is CustomRoles.LovingCrewmate or CustomRoles.LovingImpostor) + { + __instance.TeamTitle.text = GetString($"Team{role}"); + __instance.TeamTitle.color = __instance.BackgroundBar.material.color = Utils.GetRoleColor(role); + PlayerControl.LocalPlayer.Data.Role.IntroSound = GetIntroSound(role.GetRoleTypes()); + __instance.ImpostorText.gameObject.SetActive(true); + byte otherLoverId = Main.LoversPlayers.First(x => x.PlayerId != PlayerControl.LocalPlayer.PlayerId).PlayerId; + __instance.ImpostorText.text = string.Format(GetString($"SubText.{role}"), Utils.ColorString(Main.PlayerColors.TryGetValue(otherLoverId, out var color) ? color : Color.white, Main.AllPlayerNames[otherLoverId])); + } else { switch (role.GetCustomRoleTypes()) diff --git a/Resources/Lang/en_US.json b/Resources/Lang/en_US.json index c899eb0be..e4a6ac55d 100644 --- a/Resources/Lang/en_US.json +++ b/Resources/Lang/en_US.json @@ -10,6 +10,8 @@ "SubText.Impostor": "Sabotage and kill everyone", "SubText.Neutral": "A team on their own", "SubText.Madmate": "Help the Impostors", + "SubText.LovingCrewmate": "You are in love with {0}", + "SubText.LovingImpostor": "You're an <#ff1919>Impostor, but also in love with {0}", "TypeImpostor": "Impostors", "TypeCrewmate": "Crewmates", "TypeNeutral": "Neutrals", @@ -18,6 +20,8 @@ "TeamNeutral": "Neutral", "TeamCrewmate": "Crewmate", "TeamMadmate": "Madmate", + "TeamLovingCrewmate": "Lover", + "TeamLovingImpostor": "Loving Impostor", "Neutral": "Neutral", "YouAreCrewmate": "TEAM: CREWMATES", "YouAreImpostor": ".", @@ -594,7 +598,6 @@ "ClumsyInfo": "You trip while walking", "MischievousInfo": "You can sabotage", "UnreportableInfo": "Your body can't be reported", - "RogueInfo": "Work against your team and win with other Rogues", "LuckyInfo": "Dodge attackers", "DoubleShotInfo": "You have an extra life when guessing", "RascalInfo": "You appear evil in some cases", @@ -1348,6 +1351,11 @@ "LoverSuicide": "Lovers die together", "NumberOfLovers": "Number of Lover Pairs (x2 members)", "LoverKnowRoles": "Lovers know the roles of each other", + "LegacyLovers": "Legacy Lovers", + "LovingImpostorSpawnChance": "Loving <#ff1919>Impostor Spawn Chance", + "PrivateChat": "Enable Private Chat for Lovers", + "CannotBeGuessed": "Lovers Cannot Be Guessed", + "GuessLovers": "Sorry, Lovers cannot be guessed.", "TrapperBlockMoveTime": "Freeze time", "RogueKnowEachOtherRoles": "Rogues know the roles of each other", "RogueKnowEachOther": "Rogues know each other", diff --git a/Roles/AddOns/Common/Lovers.cs b/Roles/AddOns/Common/Lovers.cs index df669f0e0..bc2907b69 100644 --- a/Roles/AddOns/Common/Lovers.cs +++ b/Roles/AddOns/Common/Lovers.cs @@ -6,6 +6,11 @@ namespace EHR.Roles.AddOns.Common { public AddonTypes Type => AddonTypes.Mixed; + public static OptionItem LegacyLovers; + public static OptionItem LovingImpostorSpawnChance; + public static OptionItem PrivateChat; + public static OptionItem CannotBeGuessed; + public void SetupCustomOption() { const CustomRoles role = CustomRoles.Lovers; @@ -43,6 +48,22 @@ namespace EHR.Roles.AddOns.Common .SetParent(spawnOption) .SetGameMode(customGameMode); + LegacyLovers = BooleanOptionItem.Create(id + 8, "LegacyLovers", false, TabGroup.Addons) + .SetParent(spawnOption) + .SetGameMode(customGameMode); + + LovingImpostorSpawnChance = FloatOptionItem.Create(id + 9, "LovingImpostorSpawnChance", new(0, 100, 5), 25, TabGroup.Addons) + .SetParent(LegacyLovers) + .SetGameMode(customGameMode); + + PrivateChat = BooleanOptionItem.Create(id + 10, "PrivateChat", false, TabGroup.Addons) + .SetParent(spawnOption) + .SetGameMode(customGameMode); + + CannotBeGuessed = BooleanOptionItem.Create(id + 11, "CannotBeGuessed", false, TabGroup.Addons) + .SetParent(spawnOption) + .SetGameMode(customGameMode); + var countOption = IntegerOptionItem.Create(id + 1, "NumberOfLovers", new(2, 2, 1), 2, TabGroup.Addons) .SetParent(spawnOption) diff --git a/Roles/Crewmate/CrewmateVanillaRoles.cs b/Roles/Crewmate/CrewmateVanillaRoles.cs index 69833b9a4..98b400138 100644 --- a/Roles/Crewmate/CrewmateVanillaRoles.cs +++ b/Roles/Crewmate/CrewmateVanillaRoles.cs @@ -17,6 +17,8 @@ namespace EHR.Roles.Crewmate ScientistDur = FloatOptionItem.Create(5111, "VitalsDuration", new(1f, 250f, 1f), 15f, Tab) .SetParent(CustomRoleSpawnChances[CustomRoles.ScientistEHR]) .SetValueFormat(OptionFormat.Seconds); + VanillaCrewmateCannotBeGuessed = BooleanOptionItem.Create(5112, "VanillaCrewmateCannotBeGuessed", false, Tab) + .SetParent(CustomRoleSpawnChances[CustomRoles.CrewmateEHR]); } } } diff --git a/main.cs b/main.cs index 1e4aee258..6499b34a2 100644 --- a/main.cs +++ b/main.cs @@ -330,6 +330,8 @@ public class Main : BasePlugin { CustomRoles.Gaulois, "#42d1f5" }, { CustomRoles.Druid, "#ffb694" }, { CustomRoles.Autocrat, "#e2ed64" }, + { CustomRoles.LovingCrewmate, "#ff9ace" }, + { CustomRoles.LovingImpostor, "#ff9ace" }, { CustomRoles.ToiletMaster, "#4281f5" }, { CustomRoles.Goose, "#f9ffb8" }, { CustomRoles.Sentry, "#db55f2" },