diff --git a/MiraAPI.Example/Roles/ChameleonRole.cs b/MiraAPI.Example/Roles/ChameleonRole.cs index 72fe6fc..13db85a 100644 --- a/MiraAPI.Example/Roles/ChameleonRole.cs +++ b/MiraAPI.Example/Roles/ChameleonRole.cs @@ -15,7 +15,7 @@ public class ChameloenRole : CrewmateRole, ICustomRole public CustomRoleConfiguration Configuration => new CustomRoleConfiguration(this) { - MaxPlayers = 2, + MaxRoleCount = 0, OptionsScreenshot = ExampleAssets.Banner, }; diff --git a/MiraAPI.Example/Roles/FreezerRole.cs b/MiraAPI.Example/Roles/FreezerRole.cs index 628ef6e..4f07124 100644 --- a/MiraAPI.Example/Roles/FreezerRole.cs +++ b/MiraAPI.Example/Roles/FreezerRole.cs @@ -15,6 +15,6 @@ public class FreezerRole : ImpostorRole, ICustomRole public CustomRoleConfiguration Configuration => new CustomRoleConfiguration(this) { OptionsScreenshot = ExampleAssets.Banner, - MaxPlayers = 2, + MaxRoleCount = 2, }; } diff --git a/MiraAPI.Example/Roles/NeutralKillerRole.cs b/MiraAPI.Example/Roles/NeutralKillerRole.cs index 90dec65..0eb60af 100644 --- a/MiraAPI.Example/Roles/NeutralKillerRole.cs +++ b/MiraAPI.Example/Roles/NeutralKillerRole.cs @@ -16,7 +16,7 @@ public class NeutralKillerRole : ImpostorRole, ICustomRole { UseVanillaKillButton = true, CanGetKilled = true, - CanUseVent = true + CanUseVent = true, }; public override void SpawnTaskHeader(PlayerControl playerControl) diff --git a/MiraAPI.Example/Roles/TeleporterRole.cs b/MiraAPI.Example/Roles/TeleporterRole.cs index c48dacd..447e185 100644 --- a/MiraAPI.Example/Roles/TeleporterRole.cs +++ b/MiraAPI.Example/Roles/TeleporterRole.cs @@ -12,8 +12,11 @@ public class TeleporterRole : CrewmateRole, ICustomRole public Color RoleColor => new Color32(221, 176, 152, 255); public ModdedRoleTeams Team => ModdedRoleTeams.Crewmate; - public CustomRoleConfiguration Configuration => new CustomRoleConfiguration() + public CustomRoleConfiguration Configuration => new CustomRoleConfiguration(this) { OptionsScreenshot = ExampleAssets.Banner, + CanModifyChance = false, + DefaultChance = 73, + DefaultRoleCount = 4, }; } diff --git a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs index 554c18d..4cc492e 100644 --- a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs +++ b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs @@ -166,11 +166,17 @@ public static class RoleSettingMenuPatches try { - role.ParentMod.PluginConfig.TryGetEntry(role.NumConfigDefinition, out var numEntry); - numEntry.Value = roleSetting.RoleMaxCount; + if (role.Configuration.MaxRoleCount != 0) + { + role.ParentMod.PluginConfig.TryGetEntry(role.NumConfigDefinition, out var numEntry); + numEntry.Value = Mathf.Clamp(roleSetting.RoleMaxCount, 0, role.Configuration.MaxRoleCount); + } - role.ParentMod.PluginConfig.TryGetEntry(role.ChanceConfigDefinition, out var chanceEntry); - chanceEntry.Value = roleSetting.RoleChance; + if (role.Configuration.CanModifyChance) + { + role.ParentMod.PluginConfig.TryGetEntry(role.ChanceConfigDefinition, out var chanceEntry); + chanceEntry.Value = roleSetting.RoleChance; + } } catch (Exception e) { @@ -305,12 +311,24 @@ public static class RoleSettingMenuPatches Quaternion.identity, __instance.RoleChancesSettings.transform); roleOptionSetting.transform.localPosition = new Vector3(-0.15f, yPos, -2f); + roleOptionSetting.SetRole(GameOptionsManager.Instance.CurrentGameOptions.RoleOptions, role, 20); roleOptionSetting.labelSprite.color = customRole.RoleColor; roleOptionSetting.OnValueChanged = new Action(ValueChanged); roleOptionSetting.SetClickMask(__instance.ButtonClickMask); __instance.roleChances.Add(roleOptionSetting); + if (customRole.Configuration.MaxRoleCount == 0 && customRole.Configuration.CanModifyChance) + { + roleOptionSetting.CountMinusBtn.gameObject.SetActive(false); + roleOptionSetting.CountPlusBtn.gameObject.SetActive(false); + } + else if (!customRole.Configuration.CanModifyChance) + { + roleOptionSetting.ChanceMinusBtn.gameObject.SetActive(false); + roleOptionSetting.ChancePlusBtn.gameObject.SetActive(false); + } + roleOptionSetting.titleText.transform.localPosition = new Vector3(-0.5376f, -0.2923f, 0f); roleOptionSetting.titleText.color = customRole.RoleColor.GetAlternateColor(); roleOptionSetting.titleText.horizontalAlignment = HorizontalAlignmentOptions.Left; diff --git a/MiraAPI/Roles/CustomRoleConfiguration.cs b/MiraAPI/Roles/CustomRoleConfiguration.cs index c7775e6..7f6c6a0 100644 --- a/MiraAPI/Roles/CustomRoleConfiguration.cs +++ b/MiraAPI/Roles/CustomRoleConfiguration.cs @@ -15,7 +15,10 @@ public struct CustomRoleConfiguration /// The role in which you are configuring. public CustomRoleConfiguration(ICustomRole role) { - MaxPlayers = 15; + MaxRoleCount = 15; + DefaultRoleCount = 0; + DefaultChance = 0; + OptionsScreenshot = Icon = MiraAssets.Empty; AffectedByLightOnAirship = role.Team == ModdedRoleTeams.Crewmate; KillButtonOutlineColor = role.Team switch @@ -33,12 +36,28 @@ public struct CustomRoleConfiguration TasksCountForProgress = role.Team == ModdedRoleTeams.Crewmate; IsGhostRole = false; HideSettings = IsGhostRole; + CanModifyChance = true; } /// - /// Gets the hard limit of players that can have this role. This property is used to set a limit in the Role Options menu. + /// Gets the hard limit of players that can have this role. This property is used to set a limit in the Role Options menu. If set to 0, the role will not be assigned at start. /// - public int MaxPlayers; + public int MaxRoleCount; + + /// + /// Gets the default role count. + /// + public int DefaultRoleCount; + + /// + /// Gets the default role chance. + /// + public int DefaultChance; + + /// + /// Whether the chance option can be changed or not. + /// + public bool CanModifyChance; /// /// Gets the Sprite used for the Role Options menu screenshot. diff --git a/MiraAPI/Roles/CustomRoleManager.cs b/MiraAPI/Roles/CustomRoleManager.cs index 92a5c8b..417f3a8 100644 --- a/MiraAPI/Roles/CustomRoleManager.cs +++ b/MiraAPI/Roles/CustomRoleManager.cs @@ -90,7 +90,7 @@ public static class CustomRoleManager roleBehaviour.TasksCountTowardProgress = customRole.Configuration.TasksCountForProgress; roleBehaviour.CanVent = customRole.Configuration.CanUseVent; roleBehaviour.DefaultGhostRole = customRole.Configuration.GhostRole; - roleBehaviour.MaxCount = customRole.Configuration.MaxPlayers; + roleBehaviour.MaxCount = customRole.Configuration.MaxRoleCount; roleBehaviour.RoleScreenshot = customRole.Configuration.OptionsScreenshot.LoadAsset(); if (customRole.Configuration.IsGhostRole) @@ -114,8 +114,8 @@ public static class CustomRoleManager } var config = parentMod.PluginConfig; - config.Bind(customRole.NumConfigDefinition, 1); - config.Bind(customRole.ChanceConfigDefinition, 100); + config.Bind(customRole.NumConfigDefinition, Mathf.Clamp(customRole.Configuration.DefaultRoleCount, 0, customRole.Configuration.MaxRoleCount)); + config.Bind(customRole.ChanceConfigDefinition, Mathf.Clamp(customRole.Configuration.DefaultChance, 0, 100)); return roleBehaviour; }