From 32b63824876900c528b852695715ebe36ed3d408 Mon Sep 17 00:00:00 2001 From: ang-xd Date: Sat, 18 May 2024 10:27:51 -0400 Subject: [PATCH] Neutral role support --- MiraAPI.Example/CustomRole.cs | 4 ++-- MiraAPI.Example/ModifierExample.cs | 9 +++++++++ .../Attributes/ModdedToggleOptionAttribute.cs | 2 -- MiraAPI/Patches/HudManagerPatches.cs | 1 + MiraAPI/Patches/Roles/TaskAdderPatch.cs | 2 +- MiraAPI/Roles/CustomRoleManager.cs | 2 +- MiraAPI/Roles/ICustomRole.cs | 18 +++++++++--------- MiraAPI/Roles/ModdedRoleTeams.cs | 9 +++++++++ 8 files changed, 32 insertions(+), 15 deletions(-) create mode 100644 MiraAPI.Example/ModifierExample.cs create mode 100644 MiraAPI/Roles/ModdedRoleTeams.cs diff --git a/MiraAPI.Example/CustomRole.cs b/MiraAPI.Example/CustomRole.cs index 5c547c4..16568e9 100644 --- a/MiraAPI.Example/CustomRole.cs +++ b/MiraAPI.Example/CustomRole.cs @@ -6,10 +6,10 @@ namespace MiraAPI.Example [RegisterCustomRole(ExamplePlugin.Id)] public class CustomRole : CrewmateRole, ICustomRole { - public string RoleName => "Sussy Baka"; + public string RoleName => "Test Role"; public string RoleDescription => "Role decs?"; public string RoleLongDescription => "Extra role decs?"; public Color RoleColor => Palette.Orange; - public RoleTeamTypes Team => RoleTeamTypes.Crewmate; + public ModdedRoleTeams Team => ModdedRoleTeams.Neutral; } } diff --git a/MiraAPI.Example/ModifierExample.cs b/MiraAPI.Example/ModifierExample.cs new file mode 100644 index 0000000..537cf9f --- /dev/null +++ b/MiraAPI.Example/ModifierExample.cs @@ -0,0 +1,9 @@ +namespace MiraAPI.Example +{ + public class ModifierExample + { + //name, role specific, etc + + // mono behaviour stuff here (ModdedPlayerModifier inherits monobehaviour) + } +} diff --git a/MiraAPI/GameOptions/Attributes/ModdedToggleOptionAttribute.cs b/MiraAPI/GameOptions/Attributes/ModdedToggleOptionAttribute.cs index 5e0ea54..3459f9e 100644 --- a/MiraAPI/GameOptions/Attributes/ModdedToggleOptionAttribute.cs +++ b/MiraAPI/GameOptions/Attributes/ModdedToggleOptionAttribute.cs @@ -1,7 +1,6 @@ using MiraAPI.GameOptions.OptionTypes; using System; using System.Reflection; -using UnityEngine; namespace MiraAPI.GameOptions.Attributes { @@ -13,7 +12,6 @@ namespace MiraAPI.GameOptions.Attributes public override IModdedOption CreateOption(object value, PropertyInfo property) { - Debug.LogError(value.ToString()); var toggleOpt = new ModdedToggleOption(Title, (bool)value, RoleType); return toggleOpt; } diff --git a/MiraAPI/Patches/HudManagerPatches.cs b/MiraAPI/Patches/HudManagerPatches.cs index f69fbf8..7e65a24 100644 --- a/MiraAPI/Patches/HudManagerPatches.cs +++ b/MiraAPI/Patches/HudManagerPatches.cs @@ -85,6 +85,7 @@ namespace MiraAPI.Patches } //CustomGameModeManager.ActiveMode.HudUpdate(__instance); + if (local.Data.Role is null) return; if (local.Data.Role is ICustomRole customRole) { diff --git a/MiraAPI/Patches/Roles/TaskAdderPatch.cs b/MiraAPI/Patches/Roles/TaskAdderPatch.cs index 976d831..3984517 100644 --- a/MiraAPI/Patches/Roles/TaskAdderPatch.cs +++ b/MiraAPI/Patches/Roles/TaskAdderPatch.cs @@ -46,7 +46,7 @@ public static class TaskAdderPatch { if (__instance.role is ICustomRole lpRole) { - if (lpRole.IsOutcast) + if (lpRole.IsNeutral) { __instance.FileImage.color = Color.gray; } diff --git a/MiraAPI/Roles/CustomRoleManager.cs b/MiraAPI/Roles/CustomRoleManager.cs index e964814..e3c02a9 100644 --- a/MiraAPI/Roles/CustomRoleManager.cs +++ b/MiraAPI/Roles/CustomRoleManager.cs @@ -58,7 +58,7 @@ public static class CustomRoleManager } roleBehaviour.Role = (RoleTypes)roleId; - roleBehaviour.TeamType = customRole.Team; + roleBehaviour.TeamType = customRole.Team == ModdedRoleTeams.Neutral ? RoleTeamTypes.Crewmate : (RoleTeamTypes)customRole.Team; roleBehaviour.NameColor = customRole.RoleColor; roleBehaviour.StringName = CustomStringName.CreateAndRegister(customRole.RoleName); roleBehaviour.BlurbName = CustomStringName.CreateAndRegister(customRole.RoleDescription); diff --git a/MiraAPI/Roles/ICustomRole.cs b/MiraAPI/Roles/ICustomRole.cs index 4a0a881..e76cec8 100644 --- a/MiraAPI/Roles/ICustomRole.cs +++ b/MiraAPI/Roles/ICustomRole.cs @@ -17,7 +17,7 @@ public interface ICustomRole Color RoleColor { get; } - RoleTeamTypes Team { get; } + ModdedRoleTeams Team { get; } LoadableAsset Icon => MiraAssets.Empty; @@ -25,17 +25,17 @@ public interface ICustomRole ConfigDefinition ChanceConfigDefinition => new("Roles", $"Chance{RoleName}"); - bool AffectedByLight => Team == RoleTeamTypes.Crewmate; + bool AffectedByLight => Team == ModdedRoleTeams.Crewmate; - bool CanGetKilled => Team == RoleTeamTypes.Crewmate; + bool CanGetKilled => Team == ModdedRoleTeams.Crewmate; - bool IsOutcast => false; + bool IsNeutral => Team == ModdedRoleTeams.Neutral; - bool CanKill => Team == RoleTeamTypes.Impostor; + bool CanKill => Team == ModdedRoleTeams.Impostor; - bool CanUseVent => Team == RoleTeamTypes.Impostor; + bool CanUseVent => Team == ModdedRoleTeams.Impostor; - bool TasksCount => Team == RoleTeamTypes.Crewmate; + bool TasksCount => Team == ModdedRoleTeams.Crewmate; bool IsGhostRole => false; @@ -45,7 +45,7 @@ public interface ICustomRole bool HideSettings => IsGhostRole; - RoleTypes GhostRole => Team == RoleTeamTypes.Crewmate ? RoleTypes.CrewmateGhost : RoleTypes.ImpostorGhost; + RoleTypes GhostRole => Team == ModdedRoleTeams.Crewmate ? RoleTypes.CrewmateGhost : RoleTypes.ImpostorGhost; void CreateOptions() { } @@ -55,7 +55,7 @@ public interface ICustomRole string GetCustomEjectionMessage(GameData.PlayerInfo player) { - return Team == RoleTeamTypes.Impostor ? $"{player.PlayerName} was The {RoleName}" : null; + return Team == ModdedRoleTeams.Impostor ? $"{player.PlayerName} was The {RoleName}" : null; } StringBuilder SetTabText() diff --git a/MiraAPI/Roles/ModdedRoleTeams.cs b/MiraAPI/Roles/ModdedRoleTeams.cs new file mode 100644 index 0000000..01913e5 --- /dev/null +++ b/MiraAPI/Roles/ModdedRoleTeams.cs @@ -0,0 +1,9 @@ +namespace MiraAPI.Roles +{ + public enum ModdedRoleTeams + { + Crewmate, + Impostor, + Neutral + } +}