mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-19 15:51:48 +00:00
SetRole event
This commit is contained in:
1 parent
e412e5ead5
commit
328ee52549
2 files changed
+40
No files matched your search
@@ -0,0 +1,30 @@
|
|||||||
|
using AmongUs.GameOptions;
|
||||||
|
|
||||||
|
namespace MiraAPI.Events.Vanilla.Gameplay;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Event that is invoked after a player's role is set. This event is not cancelable.
|
||||||
|
/// </summary>
|
||||||
|
public class SetRoleEvent : MiraEvent
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the player whos role was changed.
|
||||||
|
/// </summary>
|
||||||
|
public PlayerControl Player { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the role that the player was set to.
|
||||||
|
/// </summary>
|
||||||
|
public RoleTypes Role { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="SetRoleEvent"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="player">The player.</param>
|
||||||
|
/// <param name="role">The new role.</param>
|
||||||
|
public SetRoleEvent(PlayerControl player, RoleTypes role)
|
||||||
|
{
|
||||||
|
Player = player;
|
||||||
|
Role = role;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
using AmongUs.GameOptions;
|
using AmongUs.GameOptions;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
|
using MiraAPI.Events;
|
||||||
|
using MiraAPI.Events.Vanilla.Gameplay;
|
||||||
using MiraAPI.Modifiers;
|
using MiraAPI.Modifiers;
|
||||||
using MiraAPI.Roles;
|
using MiraAPI.Roles;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -9,6 +11,14 @@ namespace MiraAPI.Patches.Roles;
|
|||||||
[HarmonyPatch(typeof(RoleManager))]
|
[HarmonyPatch(typeof(RoleManager))]
|
||||||
public static class RoleManagerPatches
|
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]
|
[HarmonyPostfix]
|
||||||
[HarmonyPatch(nameof(RoleManager.SelectRoles))]
|
[HarmonyPatch(nameof(RoleManager.SelectRoles))]
|
||||||
public static void ModifierSelectionPatches(RoleManager __instance)
|
public static void ModifierSelectionPatches(RoleManager __instance)
|
||||||
|
|||||||
Reference in new issue
Block a user