From de41ed966b4b355e7efdf44270b18ea20eaa3d29 Mon Sep 17 00:00:00 2001 From: Gurge44 Date: Sun, 8 Dec 2024 11:11:20 +0100 Subject: [PATCH] try fixing NB/NE/NK limits & fix Bloodlust sometimes doesn't spawn --- Modules/CustomRoleSelector.cs | 60 +++++++++++++++++++++-------------- Patches/OnGameStartedPatch.cs | 5 +-- 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/Modules/CustomRoleSelector.cs b/Modules/CustomRoleSelector.cs index 82b2190fa..df123cb70 100644 --- a/Modules/CustomRoleSelector.cs +++ b/Modules/CustomRoleSelector.cs @@ -166,35 +166,49 @@ internal static class CustomRoleSelector Logger.Msg("=====================================================", "AllActiveRoles"); Dictionary subCategoryLimits = Options.RoleSubCategoryLimits - .Where(x => x.Value[0].GetBool()) - .ToDictionary(x => x.Key, x => IRandom.Instance.Next(x.Value[1].GetInt(), x.Value[2].GetInt() + 1)); + .Where(x => x.Value[0].GetBool()) + .ToDictionary(x => x.Key, x => IRandom.Instance.Next(x.Value[1].GetInt(), x.Value[2].GetInt() + 1)); if (subCategoryLimits.Count > 0) Logger.Info($"Sub-Category Limits: {string.Join(", ", subCategoryLimits.Select(x => $"{x.Key}: {x.Value}"))}", "SubCategoryLimits"); + + var nkHasLimit = subCategoryLimits.TryGetValue(RoleOptionType.Neutral_Killing, out var nkSetLimit); + var nkLimit = nkHasLimit ? nkSetLimit : neutralLimits.MaxSetting.GetInt(); + + var neHasLimit = subCategoryLimits.TryGetValue(RoleOptionType.Neutral_Evil, out var neLimit); + var nbHasLimit = subCategoryLimits.TryGetValue(RoleOptionType.Neutral_Benign, out var nbLimit); + + int nnkLimit = neHasLimit && nbHasLimit ? neLimit + nbLimit : neHasLimit ? neLimit : nbHasLimit ? nbLimit : neutralLimits.MaxSetting.GetInt() - (nkHasLimit ? nkSetLimit : 0); + + Logger.Info($"Number of Neutral Killing roles to select: {nkLimit}", "NeutralKillingLimit"); + Logger.Info($"Number of Non-Killing Neutral roles to select: {nnkLimit}", "NonKillingNeutralLimit"); + + foreach (RoleAssignType type in Roles.Keys.ToArray()) { Roles[type] = Roles[type] - .Shuffle() - .OrderBy(x => x.SpawnChance != 100) - .DistinctBy(x => x.Role) - .Select(x => ( - Info: x, - Limit: subCategoryLimits.TryGetValue(x.OptionType, out var limit) - ? (Exists: true, Value: limit) - : (Exists: false, Value: 0))) - .GroupBy(x => x.Info.OptionType) - .Select(x => (Grouping: x, x.FirstOrDefault().Limit)) - .SelectMany(x => x.Limit.Exists ? x.Grouping.Take(x.Limit.Value) : x.Grouping) - .OrderByDescending(x => x.Limit is { Exists: true, Value: > 0 }) - .Select(x => x.Info) - .Take(type switch - { - RoleAssignType.Impostor => optImpNum, - RoleAssignType.NeutralKilling or RoleAssignType.NonKillingNeutral => neutralLimits.MaxSetting.GetInt(), - RoleAssignType.Crewmate => playerCount, - _ => 0 - }) - .ToList(); + .Shuffle() + .OrderBy(x => x.SpawnChance != 100) + .DistinctBy(x => x.Role) + .Select(x => ( + Info: x, + Limit: subCategoryLimits.TryGetValue(x.OptionType, out var limit) + ? (Exists: true, Value: limit) + : (Exists: false, Value: 0))) + .GroupBy(x => x.Info.OptionType) + .Select(x => (Grouping: x, x.FirstOrDefault().Limit)) + .SelectMany(x => x.Limit.Exists ? x.Grouping.Take(x.Limit.Value) : x.Grouping) + .OrderByDescending(x => x.Limit is { Exists: true, Value: > 0 }) + .Take(type switch + { + RoleAssignType.Impostor => optImpNum, + RoleAssignType.NeutralKilling => nkLimit, + RoleAssignType.NonKillingNeutral => nnkLimit, + RoleAssignType.Crewmate => playerCount, + _ => 0 + }) + .Select(x => x.Info) + .ToList(); } int attempts = 0; diff --git a/Patches/OnGameStartedPatch.cs b/Patches/OnGameStartedPatch.cs index d0ebd5e79..5fe5c6d79 100644 --- a/Patches/OnGameStartedPatch.cs +++ b/Patches/OnGameStartedPatch.cs @@ -518,7 +518,7 @@ internal static class StartGameHostPatch HashSet bloodlustList = [], nimbleList = [], physicistList = [], finderList = [], noisyList = []; bool hasBanned = Main.NeverSpawnTogetherCombos.TryGetValue(OptionItem.CurrentPreset, out Dictionary> banned); - if (nimbleSpawn || physicistSpawn || finderSpawn || noisySpawn) + if (nimbleSpawn || physicistSpawn || finderSpawn || noisySpawn || bloodlustSpawn) { foreach (PlayerControl player in Main.AllPlayerControls) { @@ -535,15 +535,12 @@ internal static class StartGameHostPatch if (kp.Value.IsCrewmate()) { if (!bloodlustBanned && !kp.Value.IsTaskBasedCrewmate()) bloodlustList.Add(player.PlayerId); - if (!nimbleBanned) nimbleList.Add(player.PlayerId); if (kp.Value.GetRoleTypes() == RoleTypes.Crewmate) { if (!physicistBanned) physicistList.Add(player.PlayerId); - if (!finderBanned) finderList.Add(player.PlayerId); - if (!noisyBanned) noisyList.Add(player.PlayerId); } }