Skip to content

Commit

Permalink
Remove the crew/Imp limit settings
Browse files Browse the repository at this point in the history
  • Loading branch information
mxyx0412 committed Sep 15, 2024
1 parent dee5a88 commit 6867a9f
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 103 deletions.
33 changes: 6 additions & 27 deletions TheOtherRoles/CustomOptionHolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,8 @@ public class CustomOptionHolder
public static string[] presets = ["Preset 1", "Preset 2", "Preset 3", "Random Preset Skeld", "Random Preset Mira HQ", "Random Preset Polus", "Random Preset Airship", "Random Preset Fungle", "Random Preset Submerged"];

public static CustomOption presetSelection;
public static CustomOption activateRoles;
public static CustomOption crewmateRolesCountMin;
public static CustomOption crewmateRolesCountMax;
public static CustomOption crewmateRolesFill;
public static CustomOption neutralRolesCountMin;
public static CustomOption neutralRolesCountMax;
public static CustomOption impostorRolesCountMin;
public static CustomOption impostorRolesCountMax;
public static CustomOption modifiersCountMin;
public static CustomOption modifiersCountMax;

Expand Down Expand Up @@ -609,32 +603,17 @@ public static void Load()
vanillaSettings = TheOtherRolesPlugin.Instance.Config.Bind("Preset0", "VanillaOptions", "");

// Role Options
presetSelection = Create(0, Types.General, cs(new Color(204f / 255f, 204f / 255f, 0, 1f), "Preset"), presets, null, true);
activateRoles = Create(1, Types.General, cs(new Color(204f / 255f, 204f / 255f, 0, 1f), "Enable Mod Roles And Block Vanilla Roles"), true, null, true);
presetSelection = Create(0, Types.General, cs(new Color32(204, 204, 0, 255), "Preset"), presets, null, true);

anyPlayerCanStopStart = Create(2, Types.General, cs(new Color(204f / 255f, 204f / 255f, 0, 1f), "Any Player Can Stop The Start"), false, null, false);
anyPlayerCanStopStart = Create(2, Types.General, cs(new Color32(204, 204, 0, 255), "Any Player Can Stop The Start"), false, null, false);

if (Utilities.EventUtility.canBeEnabled) enableEventMode = Create(3, Types.General, cs(Color.green, "Enable Special Mode"), true, null, true);

// Using new id's for the options to not break compatibilty with older versions
crewmateRolesCountMin = Create(5, Types.General,
cs(new Color(204f / 255f, 204f / 255f, 0, 1f), "Minimum Crewmate Roles"), 15f, 0f, 15f, 1f, null, true);
crewmateRolesCountMax = Create(6, Types.General,
cs(new Color(204f / 255f, 204f / 255f, 0, 1f), "Maximum Crewmate Roles"), 15f, 0f, 15f, 1f);
crewmateRolesFill = Create(7, Types.General,
cs(new Color(204f / 255f, 204f / 255f, 0, 1f), "Fill Crewmate Roles\n(Ignores Min/Max)"), false);
neutralRolesCountMin = Create(8, Types.General,
cs(new Color(204f / 255f, 204f / 255f, 0, 1f), "Minimum Neutral Roles"), 15f, 0f, 15f, 1f);
neutralRolesCountMax = Create(9, Types.General,
cs(new Color(204f / 255f, 204f / 255f, 0, 1f), "Maximum Neutral Roles"), 15f, 0f, 15f, 1f);
impostorRolesCountMin = Create(10, Types.General,
cs(new Color(204f / 255f, 204f / 255f, 0, 1f), "Minimum Impostor Roles"), 15f, 0f, 15f, 1f);
impostorRolesCountMax = Create(11, Types.General,
cs(new Color(204f / 255f, 204f / 255f, 0, 1f), "Maximum Impostor Roles"), 15f, 0f, 15f, 1f);
modifiersCountMin = Create(12, Types.General,
cs(new Color(204f / 255f, 204f / 255f, 0, 1f), "Minimum Modifiers"), 15f, 0f, 15f, 1f);
modifiersCountMax = Create(13, Types.General,
cs(new Color(204f / 255f, 204f / 255f, 0, 1f), "Maximum Modifiers"), 15f, 0f, 15f, 1f);
neutralRolesCountMin = Create(8, Types.General, cs(new Color32(204, 204, 0, 255), "Minimum Neutral Roles"), 15f, 0f, 15f, 1f);
neutralRolesCountMax = Create(9, Types.General, cs(new Color32(204, 204, 0, 255), "Maximum Neutral Roles"), 15f, 0f, 15f, 1f);
modifiersCountMin = Create(12, Types.General, cs(new Color32(204, 204, 0, 255), "Minimum Modifiers"), 15f, 0f, 15f, 1f);
modifiersCountMax = Create(13, Types.General, cs(new Color32(204, 204, 0, 255), "Maximum Modifiers"), 15f, 0f, 15f, 1f);

//-------------------------- Other options 1 - 599 -------------------------- //

Expand Down
6 changes: 6 additions & 0 deletions TheOtherRoles/Helper/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,12 @@ public static bool isAlive(this PlayerControl player)
return !player.isDead();
}

public static List<T> ToList<T>(this Il2CppSystem.Collections.Generic.List<T> list)
{
List<T> newList = [.. list];
return newList;
}

public static bool hasFakeTasks(this PlayerControl player)
{
return player == Werewolf.werewolf
Expand Down
7 changes: 4 additions & 3 deletions TheOtherRoles/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class TheOtherRolesPlugin : BasePlugin

public static int optionsPage = 2;

public static ConfigEntry<string> DebugMode { get; private set; }
public static ConfigEntry<bool> DebugMode { get; private set; }
public static ConfigEntry<bool> GhostsSeeInformation { get; set; }
public static ConfigEntry<bool> GhostsSeeRoles { get; set; }
public static ConfigEntry<bool> GhostsSeeModifier { get; set; }
Expand Down Expand Up @@ -93,7 +93,7 @@ public override void Load()
_ = checkBeta(); // Exit if running an expired beta
_ = Patches.CredentialsPatch.MOTD.loadMOTDs();

DebugMode = Config.Bind("Custom", "Enable Debug Mode", "false");
DebugMode = Config.Bind("Custom", "Enable Debug Mode", false);
GhostsSeeInformation = Config.Bind("Custom", "Ghosts See Remaining Tasks", true);
GhostsSeeRoles = Config.Bind("Custom", "Ghosts See Roles", true);
GhostsSeeModifier = Config.Bind("Custom", "Ghosts See Modifier", true);
Expand All @@ -112,10 +112,11 @@ public override void Load()

UpdateRegions();

DebugMode = Config.Bind("Custom", "Enable Debug Mode", "false");
DebugMode = Config.Bind("Custom", "Enable Debug Mode", false);
Harmony.PatchAll();

CustomOptionHolder.Load();
TORMapOptions.reloadPluginOptions();
CustomColors.Load();
CustomHatManager.LoadHats();
if (ToggleCursor.Value)
Expand Down
5 changes: 5 additions & 0 deletions TheOtherRoles/MapOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ namespace TheOtherRoles;

static class TORMapOptions
{
public static float ButtonCooldown => CustomOptionHolder.resteButtonCooldown.getFloat();
public static bool PreventTaskEnd => CustomOptionHolder.preventTaskEnd.getBool();
public static float KillCooddown => GameOptionsManager.Instance.currentNormalGameOptions.KillCooldown;
public static int NumImpostors => GameOptionsManager.Instance.currentNormalGameOptions.NumImpostors;

// Set values
public static int maxNumberOfMeetings = 10;
public static bool blockSkippingInEmergencyMeetings = false;
Expand Down
57 changes: 12 additions & 45 deletions TheOtherRoles/Modules/CustomOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,8 @@ private static void createGuesserTabs(GameOptionsMenu __instance)


List<Transform> menus = new List<Transform>() { torMenu.transform, impostorMenu.transform, neutralMenu.transform, crewmateMenu.transform, modifierMenu.transform, guesserMenu.transform };
List<List<OptionBehaviour>> optionBehaviours = new List<List<OptionBehaviour>>() { torOptions, impostorOptions, neutralOptions, crewmateOptions, modifierOptions, guesserOptions };
List<int> exludedIds = new List<int> { 310, 311, 312, 313, 314, 315, 316, 317, 318 };
List<List<OptionBehaviour>> optionBehaviours = new() { torOptions, impostorOptions, neutralOptions, crewmateOptions, modifierOptions, guesserOptions };
List<int> exludedIds = new() { 10000, 10001, 10002, 10003, 10004, 10005, 10006, 10007, 10008, 30100, 30101, 30102, 30103, 30104 };

for (int i = 0; i < options.Count; i++)
{
Expand Down Expand Up @@ -1087,11 +1087,11 @@ private static string buildOptionsOfType(CustomOption.CustomOptionType type, boo
{
if (type == CustomOptionType.General)
options = CustomOption.options.Where(o => o.type == type || o.type == CustomOptionType.Guesser);
List<int> remove = new List<int> { 308, 310, 311, 312, 313, 314, 315, 316, 317, 318 };
List<int> remove = new List<int> { 10000, 10001, 10002, 10003, 10004,10005, 10006, 10007, 10008, 30100, 30101, 30102, 30103, 30104 };
options = options.Where(x => !remove.Contains(x.id));
}
else if (TORMapOptions.gameMode == CustomGamemodes.Classic)
options = options.Where(x => !(x.type == CustomOptionType.Guesser || x == CustomOptionHolder.crewmateRolesFill));
options = options.Where(x => !(x.type == CustomOptionType.Guesser));
else if (TORMapOptions.gameMode == CustomGamemodes.HideNSeek)
options = options.Where(x => x.type == CustomOptionType.HideNSeekMain || x.type == CustomOptionType.HideNSeekRoles);
else if (TORMapOptions.gameMode == CustomGamemodes.PropHunt)
Expand All @@ -1107,14 +1107,13 @@ private static string buildOptionsOfType(CustomOption.CustomOptionType type, boo
}
else if (option.parent.getSelection() > 0)
{
if (option.id == 103) //Deputy
if (option.id == 30060) //Deputy
sb.AppendLine($"- {cs(Deputy.color, "Deputy")}: {option.selections[option.selection].ToString()}");
else if (option.id == 224) //Sidekick
else if (option.id == 20048) //Sidekick
sb.AppendLine($"- {cs(Sidekick.color, "Sidekick")}: {option.selections[option.selection].ToString()}");
else if (option.id == 358) //Prosecutor
else if (option.id == 20071) //Prosecutor
sb.AppendLine($"- {cs(Lawyer.color, "Prosecutor")}: {option.selections[option.selection].ToString()}");

else if (option.id == 3642134) //Can Swoop
else if (option.id == 20042) //Can Swoop
sb.AppendLine($"- {cs(Swooper.color, "Swooper")}: {option.selections[option.selection].ToString()}");

}
Expand All @@ -1136,57 +1135,25 @@ private static string buildOptionsOfType(CustomOption.CustomOptionType type, boo
}
else
{
if (option == CustomOptionHolder.crewmateRolesCountMin)
{
var optionName = CustomOptionHolder.cs(new Color(204f / 255f, 204f / 255f, 0, 1f), "Crewmate Roles");
var min = CustomOptionHolder.crewmateRolesCountMin.getSelection();
var max = CustomOptionHolder.crewmateRolesCountMax.getSelection();
string optionValue = "";
if (CustomOptionHolder.crewmateRolesFill.getBool())
{
var crewCount = PlayerControl.AllPlayerControls.Count - GameOptionsManager.Instance.currentGameOptions.NumImpostors;
int minNeutral = CustomOptionHolder.neutralRolesCountMin.getSelection();
int maxNeutral = CustomOptionHolder.neutralRolesCountMax.getSelection();
if (minNeutral > maxNeutral) minNeutral = maxNeutral;
min = crewCount - maxNeutral;
max = crewCount - minNeutral;
if (min < 0) min = 0;
if (max < 0) max = 0;
optionValue = "Fill: ";
}
if (min > max) min = max;
optionValue += (min == max) ? $"{max}" : $"{min} - {max}";
sb.AppendLine($"{optionName}: {optionValue}");
}
else if (option == CustomOptionHolder.neutralRolesCountMin)
if (option == CustomOptionHolder.neutralRolesCountMin)
{
var optionName = CustomOptionHolder.cs(new Color(204f / 255f, 204f / 255f, 0, 1f), "Neutral Roles");
var optionName = CustomOptionHolder.cs(new Color32(204, 204, 0, 255), "Neutral Roles");
var min = CustomOptionHolder.neutralRolesCountMin.getSelection();
var max = CustomOptionHolder.neutralRolesCountMax.getSelection();
if (min > max) min = max;
var optionValue = (min == max) ? $"{max}" : $"{min} - {max}";
sb.AppendLine($"{optionName}: {optionValue}");
}
else if (option == CustomOptionHolder.impostorRolesCountMin)
{
var optionName = CustomOptionHolder.cs(new Color(204f / 255f, 204f / 255f, 0, 1f), "Impostor Roles");
var min = CustomOptionHolder.impostorRolesCountMin.getSelection();
var max = CustomOptionHolder.impostorRolesCountMax.getSelection();
if (max > GameOptionsManager.Instance.currentGameOptions.NumImpostors) max = GameOptionsManager.Instance.currentGameOptions.NumImpostors;
if (min > max) min = max;
var optionValue = (min == max) ? $"{max}" : $"{min} - {max}";
sb.AppendLine($"{optionName}: {optionValue}");
}
else if (option == CustomOptionHolder.modifiersCountMin)
{
var optionName = CustomOptionHolder.cs(new Color(204f / 255f, 204f / 255f, 0, 1f), "Modifiers");
var optionName = CustomOptionHolder.cs(new Color32(204, 204, 0, 255), "Modifiers");
var min = CustomOptionHolder.modifiersCountMin.getSelection();
var max = CustomOptionHolder.modifiersCountMax.getSelection();
if (min > max) min = max;
var optionValue = (min == max) ? $"{max}" : $"{min} - {max}";
sb.AppendLine($"{optionName}: {optionValue}");
}
else if ((option == CustomOptionHolder.crewmateRolesCountMax) || (option == CustomOptionHolder.neutralRolesCountMax) || (option == CustomOptionHolder.impostorRolesCountMax) || option == CustomOptionHolder.modifiersCountMax)
else if (option == CustomOptionHolder.neutralRolesCountMax || option == CustomOptionHolder.modifiersCountMax)
{
continue;
}
Expand Down
1 change: 0 additions & 1 deletion TheOtherRoles/Patches/IntroPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,6 @@ public static void SetRoleTexts(IntroCutscene __instance)
}
public static bool Prefix(IntroCutscene __instance)
{
if (!CustomOptionHolder.activateRoles.getBool()) return true;
seed = rnd.Next(5000);
FastDestroyableSingleton<HudManager>.Instance.StartCoroutine(Effects.Lerp(1f, new Action<float>((p) =>
{
Expand Down
40 changes: 13 additions & 27 deletions TheOtherRoles/Patches/RoleAssignmentPatch.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using AmongUs.GameOptions;
using Hazel;
Expand All @@ -15,7 +16,8 @@ class RoleOptionsDataGetNumPerGamePatch
{
public static void Postfix(ref int __result)
{
if (CustomOptionHolder.activateRoles.getBool() && GameOptionsManager.Instance.CurrentGameOptions.GameMode == GameModes.Normal) __result = 0; // Deactivate Vanilla Roles if the mod roles are active
// Deactivate Vanilla Roles if the mod roles are active
if (GameOptionsManager.Instance.CurrentGameOptions.GameMode == GameModes.Normal) __result = 0;
}
}

Expand Down Expand Up @@ -62,8 +64,7 @@ public static void Postfix()
AmongUsClient.Instance.FinishRpcImmediately(writer);
RPCProcedure.resetVariables();
if (TORMapOptions.gameMode == CustomGamemodes.HideNSeek || TORMapOptions.gameMode == CustomGamemodes.PropHunt || GameOptionsManager.Instance.currentGameOptions.GameMode == GameModes.HideNSeek) return; // Don't assign Roles in Hide N Seek
if (CustomOptionHolder.activateRoles.getBool()) // Don't assign Roles in Tutorial or if deactivated
assignRoles();
assignRoles();
}

private static void assignRoles()
Expand All @@ -88,36 +89,21 @@ public static RoleAssignmentData getRoleAssignmentData()
List<PlayerControl> impostors = PlayerControl.AllPlayerControls.ToArray().ToList().OrderBy(x => Guid.NewGuid()).ToList();
impostors.RemoveAll(x => !x.Data.Role.IsImpostor);

var crewmateMin = CustomOptionHolder.crewmateRolesCountMin.getSelection();
var crewmateMax = CustomOptionHolder.crewmateRolesCountMax.getSelection();
var neutralMin = CustomOptionHolder.neutralRolesCountMin.getSelection();
var neutralMax = CustomOptionHolder.neutralRolesCountMax.getSelection();
var impostorMin = CustomOptionHolder.impostorRolesCountMin.getSelection();
var impostorMax = CustomOptionHolder.impostorRolesCountMax.getSelection();
var impostorNum = TORMapOptions.NumImpostors;

// Make sure min is less or equal to max
if (crewmateMin > crewmateMax) crewmateMin = crewmateMax;
if (neutralMin > neutralMax) neutralMin = neutralMax;
if (impostorMin > impostorMax) impostorMin = impostorMax;

// Automatically force everyone to get a role by setting crew Min / Max according to Neutral Settings
if (CustomOptionHolder.crewmateRolesFill.getBool())
{
crewmateMax = crewmates.Count - neutralMin;
crewmateMin = crewmates.Count - neutralMax;
crewmateMin += neutralMax;
crewmateMax += neutralMax;
}

// Get the maximum allowed count of each role type based on the minimum and maximum option
int crewCountSettings = rnd.Next(crewmateMin, crewmateMax + 1);
int neutralCountSettings = rnd.Next(neutralMin, neutralMax + 1);
int impCountSettings = rnd.Next(impostorMin, impostorMax + 1);
var crewCountSettings = PlayerControl.AllPlayerControls.Count - neutralCountSettings - impostorNum;

// Potentially lower the actual maximum to the assignable players
int maxCrewmateRoles = Mathf.Min(crewmates.Count, crewCountSettings);
int maxNeutralRoles = Mathf.Min(crewmates.Count, neutralCountSettings);
int maxImpostorRoles = Mathf.Min(impostors.Count, impCountSettings);
int maxImpostorRoles = Mathf.Min(impostors.Count, impostorNum);

// Fill in the lists with the roles that should be assigned to players. Note that the special roles (like Mafia or Lovers) are NOT included in these lists
Dictionary<byte, int> impSettings = new Dictionary<byte, int>();
Expand Down Expand Up @@ -207,14 +193,14 @@ private static void assignSpecialRoles(RoleAssignmentData data)
}
if (data.impostors.Count < 2 && data.maxImpostorRoles < 2 && (rnd.Next(1, 101) <= CustomOptionHolder.cultistSpawnRate.getSelection() * 10))
{
// var index = rnd.Next(0, data.impostors.Count);
// PlayerControl playerControl = data.impostors[index];
//var index = rnd.Next(0, data.impostors.Count);
//PlayerControl playerControl = data.impostors[index];

// Helpers.turnToCrewmate(playerControl);
//Helpers.turnToCrewmate(playerControl);

// data.impostors.RemoveAt(index);
// data.crewmates.Add(playerControl);
// setRoleToRandomPlayer((byte)RoleId.Cultist, data.impostors);
//data.impostors.RemoveAt(index);
//data.crewmates.Add(playerControl);
//setRoleToRandomPlayer((byte)RoleId.Cultist, data.impostors);
//data.impostors.Count = 1;
data.impostors.Capacity = 1;
data.maxImpostorRoles = 1;
Expand Down

0 comments on commit 6867a9f

Please sign in to comment.