diff --git a/MiraAPI/Events/Vanilla/Gameplay/SetRoleEvent.cs b/MiraAPI/Events/Vanilla/Gameplay/SetRoleEvent.cs new file mode 100644 index 0000000..4c00cf2 --- /dev/null +++ b/MiraAPI/Events/Vanilla/Gameplay/SetRoleEvent.cs @@ -0,0 +1,30 @@ +using AmongUs.GameOptions; + +namespace MiraAPI.Events.Vanilla.Gameplay; + +/// +/// Event that is invoked after a player's role is set. This event is not cancelable. +/// +public class SetRoleEvent : MiraEvent +{ + /// + /// Gets the player whos role was changed. + /// + public PlayerControl Player { get; } + + /// + /// Gets the role that the player was set to. + /// + public RoleTypes Role { get; } + + /// + /// Initializes a new instance of the class. + /// + /// The player. + /// The new role. + public SetRoleEvent(PlayerControl player, RoleTypes role) + { + Player = player; + Role = role; + } +} diff --git a/MiraAPI/Patches/Roles/RoleManagerPatches.cs b/MiraAPI/Patches/Roles/RoleManagerPatches.cs index 357b2eb..ed1c5e2 100644 --- a/MiraAPI/Patches/Roles/RoleManagerPatches.cs +++ b/MiraAPI/Patches/Roles/RoleManagerPatches.cs @@ -1,5 +1,7 @@ using AmongUs.GameOptions; using HarmonyLib; +using MiraAPI.Events; +using MiraAPI.Events.Vanilla.Gameplay; using MiraAPI.Modifiers; using MiraAPI.Roles; using System.Linq; @@ -9,6 +11,14 @@ namespace MiraAPI.Patches.Roles; [HarmonyPatch(typeof(RoleManager))] public static class RoleManagerPatches { + [HarmonyPostfix] + [HarmonyPatch(nameof(RoleManager.SetRole))] + public static void SetRolePatch(RoleManager __instance, PlayerControl targetPlayer, RoleTypes roleType) + { + var @event = new SetRoleEvent(targetPlayer, roleType); + MiraEventManager.InvokeEvent(@event); + } + [HarmonyPostfix] [HarmonyPatch(nameof(RoleManager.SelectRoles))] public static void ModifierSelectionPatches(RoleManager __instance)