diff --git a/MiraAPI.Example/MiraDebugWindow.cs b/MiraAPI.Example/MiraDebugWindow.cs index 0332776..f01d3ac 100644 --- a/MiraAPI.Example/MiraDebugWindow.cs +++ b/MiraAPI.Example/MiraDebugWindow.cs @@ -1,6 +1,4 @@ -using MiraAPI.Example.Modifiers; -using MiraAPI.Utilities; -using Reactor.Utilities.Attributes; +using Reactor.Utilities.Attributes; using Reactor.Utilities.ImGui; using System; using UnityEngine; @@ -28,4 +26,4 @@ public class MiraDebugWindow(IntPtr ptr) : MonoBehaviour(ptr) { DebuggingWindow.OnGUI(); } -} \ No newline at end of file +} diff --git a/MiraAPI.Example/Roles/FreezerRole.cs b/MiraAPI.Example/Roles/FreezerRole.cs index 05b950f..490ce3d 100644 --- a/MiraAPI.Example/Roles/FreezerRole.cs +++ b/MiraAPI.Example/Roles/FreezerRole.cs @@ -9,7 +9,7 @@ public class FreezerRole : ImpostorRole, ICustomRole { public string RoleName => "Freezer"; public string RoleLongDescription => "Freeze another player for a duration of time."; - public string RoleDescription => this.RoleLongDescription; + public string RoleDescription => RoleLongDescription; public Color RoleColor => Palette.Blue; public ModdedRoleTeams Team => ModdedRoleTeams.Impostor; public LoadableAsset OptionsScreenshot => ExampleAssets.Banner; diff --git a/MiraAPI/GameModes/CustomGameModeManager.cs b/MiraAPI/GameModes/CustomGameModeManager.cs index e80b05c..028eb94 100644 --- a/MiraAPI/GameModes/CustomGameModeManager.cs +++ b/MiraAPI/GameModes/CustomGameModeManager.cs @@ -1,5 +1,4 @@ -#nullable enable -using Reactor.Utilities; +using Reactor.Utilities; using System; using System.Collections.Generic; using System.Linq; diff --git a/MiraAPI/Hud/CustomActionButton.cs b/MiraAPI/Hud/CustomActionButton.cs index 6cae97d..5511a0d 100644 --- a/MiraAPI/Hud/CustomActionButton.cs +++ b/MiraAPI/Hud/CustomActionButton.cs @@ -1,5 +1,4 @@ -#nullable enable -using MiraAPI.Utilities.Assets; +using MiraAPI.Utilities.Assets; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; diff --git a/MiraAPI/Hud/CustomButtonSingleton.cs b/MiraAPI/Hud/CustomButtonSingleton.cs index 9c609e3..65d0bad 100644 --- a/MiraAPI/Hud/CustomButtonSingleton.cs +++ b/MiraAPI/Hud/CustomButtonSingleton.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Linq; namespace MiraAPI.Hud; diff --git a/MiraAPI/MiraApiPlugin.cs b/MiraAPI/MiraApiPlugin.cs index 918b53b..b928565 100644 --- a/MiraAPI/MiraApiPlugin.cs +++ b/MiraAPI/MiraApiPlugin.cs @@ -2,7 +2,6 @@ using BepInEx.Unity.IL2CPP; using HarmonyLib; using MiraAPI.PluginLoading; -using MiraAPI.Utilities; using Reactor; using Reactor.Networking; using Reactor.Networking.Attributes; diff --git a/MiraAPI/Patches/HudManagerPatches.cs b/MiraAPI/Patches/HudManagerPatches.cs index 25e2d48..89878aa 100644 --- a/MiraAPI/Patches/HudManagerPatches.cs +++ b/MiraAPI/Patches/HudManagerPatches.cs @@ -1,5 +1,4 @@ -using System; -using HarmonyLib; +using HarmonyLib; using InnerNet; using MiraAPI.Hud; using MiraAPI.Roles; diff --git a/MiraAPI/Patches/Options/GameSettingMenuPatches.cs b/MiraAPI/Patches/Options/GameSettingMenuPatches.cs index b74581b..680cb69 100644 --- a/MiraAPI/Patches/Options/GameSettingMenuPatches.cs +++ b/MiraAPI/Patches/Options/GameSettingMenuPatches.cs @@ -1,5 +1,4 @@ -#nullable enable -using HarmonyLib; +using HarmonyLib; using MiraAPI.PluginLoading; using MiraAPI.Utilities.Assets; using Reactor.Utilities.Extensions; diff --git a/MiraAPI/Patches/Options/LobbyViewPanePatches.cs b/MiraAPI/Patches/Options/LobbyViewPanePatches.cs index a0b79ee..a952807 100644 --- a/MiraAPI/Patches/Options/LobbyViewPanePatches.cs +++ b/MiraAPI/Patches/Options/LobbyViewPanePatches.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq; using HarmonyLib; diff --git a/MiraAPI/Patches/Roles/RoleManagerPatches.cs b/MiraAPI/Patches/Roles/RoleManagerPatches.cs index f7d0401..350767f 100644 --- a/MiraAPI/Patches/Roles/RoleManagerPatches.cs +++ b/MiraAPI/Patches/Roles/RoleManagerPatches.cs @@ -3,7 +3,6 @@ using HarmonyLib; using MiraAPI.Modifiers; using MiraAPI.Roles; using System.Linq; -using UnityEngine; namespace MiraAPI.Patches.Roles; diff --git a/MiraAPI/Roles/ICustomRole.cs b/MiraAPI/Roles/ICustomRole.cs index 12f07d8..7ed70e8 100644 --- a/MiraAPI/Roles/ICustomRole.cs +++ b/MiraAPI/Roles/ICustomRole.cs @@ -1,92 +1,159 @@ using AmongUs.GameOptions; using BepInEx.Configuration; -using HarmonyLib; using MiraAPI.Modifiers; -using MiraAPI.Networking; using MiraAPI.PluginLoading; using MiraAPI.Utilities; using MiraAPI.Utilities.Assets; -using System; using System.Text; using UnityEngine; namespace MiraAPI.Roles; +/// +/// Interface for custom roles. +/// public interface ICustomRole { + /// + /// Gets the name of the role. + /// string RoleName { get; } + /// + /// Gets the description of the role. Used in the Intro Cutscene. + /// string RoleDescription { get; } + /// + /// Gets the long description of the role. Used in the Role Tab and Role Options. + /// string RoleLongDescription { get; } + /// + /// Gets the color of the role. + /// Color RoleColor { get; } + /// + /// Gets the team of the role. + /// ModdedRoleTeams Team { get; } + /// + /// Gets the **maximum amount** of players that can have this role at a time. This is not the same as the **number** of players that can have this role in a game. + /// int MaxPlayers => 15; + /// + /// Gets the Sprite used for the Role Options menu screenshot. + /// LoadableAsset OptionsScreenshot => MiraAssets.Empty; + /// + /// Gets the Sprite used for the Role Icon. + /// LoadableAsset Icon => MiraAssets.Empty; - ConfigDefinition NumConfigDefinition => new("Roles", $"Num {this.GetType().FullName}"); + /// + /// Gets the BepInEx ConfigDefinition for the amount of players that can have this role. + /// + ConfigDefinition NumConfigDefinition => new("Roles", $"Num {GetType().FullName}"); - ConfigDefinition ChanceConfigDefinition => new("Roles", $"Chance {this.GetType().FullName}"); + /// + /// Gets the BepInEx ConfigDefinition for the chance of this role being selected. + /// + ConfigDefinition ChanceConfigDefinition => new("Roles", $"Chance {GetType().FullName}"); - bool AffectedByLight => this.Team == ModdedRoleTeams.Crewmate; + /// + /// Gets a value indicating whether the role is affected by light sabotages. + /// + bool AffectedByLight => Team == ModdedRoleTeams.Crewmate; - bool CanGetKilled => this.Team == ModdedRoleTeams.Crewmate; + /// + /// Gets a value indicating whether the role can be killed by others. + /// + bool CanGetKilled => Team == ModdedRoleTeams.Crewmate; - bool CanKill => this.Team == ModdedRoleTeams.Impostor; + /// + /// Gets a value indicating whether the role can kill others. + /// + bool CanKill => Team == ModdedRoleTeams.Impostor; - bool CanUseVent => this.Team == ModdedRoleTeams.Impostor; + /// + /// Gets a value indicating whether the role can use vents. + /// + bool CanUseVent => Team == ModdedRoleTeams.Impostor; - bool TasksCount => this.Team == ModdedRoleTeams.Crewmate; + /// + /// Gets a value indicating whether the role's tasks count towards task progress. + /// + bool TasksCount => Team == ModdedRoleTeams.Crewmate; + /// + /// Gets a value indicating whether the role is a Ghost. + /// bool IsGhostRole => false; + /// + /// Unused for some reason. + /// + // TODO: change this to an enum bool CreateCustomTab => true; - bool HideSettings => this.IsGhostRole; + /// + /// Gets a value indicating whether the role should show up in the Role Options menu. + /// + bool HideSettings => IsGhostRole; - RoleTypes GhostRole => this.Team == ModdedRoleTeams.Impostor ? RoleTypes.ImpostorGhost : RoleTypes.CrewmateGhost; + /// + /// Gets the Ghost role that is applied when the player is killed. + /// + RoleTypes GhostRole => Team == ModdedRoleTeams.Impostor ? RoleTypes.ImpostorGhost : RoleTypes.CrewmateGhost; + /// + /// Gets the parent mod of this role. + /// MiraPluginInfo ParentMod => CustomRoleManager.FindParentMod(this); /// - /// Runs on the PlayerControl FixedUpdate method for any player with this role + /// This method runs on the PlayerControl.FixedUpdate method for ALL players with this role. /// - /// The PlayerControl that has this role - void PlayerControlFixedUpdate(PlayerControl playerControl) { } + /// The PlayerControl that has this role. + void PlayerControlFixedUpdate(PlayerControl playerControl) + { + } /// - /// Only runs for local player on HudManager Update method + /// This method runs on the HudManager.Update method ONLY when the LOCAL player has this role. /// - /// Reference to HudManager instance - void HudUpdate(HudManager hudManager) { } + /// Reference to HudManager instance. + void HudUpdate(HudManager hudManager) + { + } + /// + /// Gets a custom ejection message for the role. Return null to use the default message. + /// + /// The NetworkedPlayerInfo object for this player. + /// A string with a custom ejection message or null. string? GetCustomEjectionMessage(NetworkedPlayerInfo player) { - return this.Team == ModdedRoleTeams.Impostor ? $"{player.PlayerName} was The {this.RoleName}" : null; + return Team == ModdedRoleTeams.Impostor ? $"{player.PlayerName} was The {RoleName}" : null; } - StringBuilder SetTabText() - { - var taskStringBuilder = Helpers.CreateForRole(this); - return taskStringBuilder; - } + /// + /// Get the custom Role Tab text for this role. + /// + /// A StringBuilder with the role tab text. + StringBuilder SetTabText() => Helpers.CreateForRole(this); + /// + /// Determine whether a given modifier can be applied to this role. + /// + /// The modifier to be tested. + /// True if the modifier is valid on this role, false otherwise. bool IsModifierApplicable(BaseModifier modifier) { return true; } - - NetData GetNetData() - { - this.ParentMod.PluginConfig.TryGetEntry(this.NumConfigDefinition, out var numEntry); - this.ParentMod.PluginConfig.TryGetEntry(this.ChanceConfigDefinition, out var chanceEntry); - - return new NetData(RoleId.Get(this.GetType()), BitConverter.GetBytes(numEntry.Value).AddRangeToArray(BitConverter.GetBytes(chanceEntry.Value))); - } } diff --git a/MiraAPI/Utilities/Extensions.cs b/MiraAPI/Utilities/Extensions.cs index ffe0c23..ab51417 100644 --- a/MiraAPI/Utilities/Extensions.cs +++ b/MiraAPI/Utilities/Extensions.cs @@ -1,18 +1,36 @@ -#nullable enable +using System; +using System.Collections.Generic; +using System.Linq; +using HarmonyLib; using MiraAPI.GameOptions; using MiraAPI.Modifiers; using MiraAPI.Networking; +using MiraAPI.Roles; using Reactor.Networking.Attributes; using Reactor.Utilities; -using System.Collections.Generic; -using System.Linq; using UnityEngine; namespace MiraAPI.Utilities; +/// +/// Extension methods for various classes. +/// public static class Extensions { - public static bool IsStatic(this System.Type type) + internal static NetData GetNetData(this ICustomRole role) + { + role.ParentMod.PluginConfig.TryGetEntry(role.NumConfigDefinition, out var numEntry); + role.ParentMod.PluginConfig.TryGetEntry(role.ChanceConfigDefinition, out var chanceEntry); + + return new NetData(RoleId.Get(role.GetType()), BitConverter.GetBytes(numEntry.Value).AddRangeToArray(BitConverter.GetBytes(chanceEntry.Value))); + } + + /// + /// Checks if a type is static. + /// + /// The type being checked. + /// True if the type is static, false otherwise. + public static bool IsStatic(this Type type) { return type is { IsClass: true, IsAbstract: true, IsSealed: true }; }