diff --git a/MiraAPI/Patches/PlayerControlPatches.cs b/MiraAPI/Patches/PlayerControlPatches.cs index a3a0dd3..7d4d97a 100644 --- a/MiraAPI/Patches/PlayerControlPatches.cs +++ b/MiraAPI/Patches/PlayerControlPatches.cs @@ -1,14 +1,20 @@ using HarmonyLib; using MiraAPI.Hud; -using MiraAPI.Roles; using MiraAPI.Modifiers; +using MiraAPI.Roles; using Reactor.Utilities.Extensions; namespace MiraAPI.Patches; +/// +/// General patches for the PlayerControl class. +/// [HarmonyPatch(typeof(PlayerControl))] public static class PlayerControlPatches { + /// + /// Adds the modifier component to the player on start. + /// [HarmonyPrefix] [HarmonyPatch(nameof(PlayerControl.Start))] public static void PlayerControlStartPostfix(PlayerControl __instance) @@ -21,6 +27,24 @@ public static void PlayerControlStartPostfix(PlayerControl __instance) __instance.gameObject.AddComponent(); } + /// + /// Calls the OnDeath method for all active modifiers. + /// + [HarmonyPostfix] + [HarmonyPatch(nameof(PlayerControl.Die))] + public static void PlayerControlDiePostfix(PlayerControl __instance) + { + var modifiersComponent = __instance.GetComponent(); + + if (modifiersComponent) + { + modifiersComponent.ActiveModifiers.ForEach(x=>x.OnDeath()); + } + } + + /// + /// FixedUpdate handler for custom roles and custom buttons. + /// [HarmonyPostfix] [HarmonyPatch(nameof(PlayerControl.FixedUpdate))] public static void PlayerControlFixedUpdatePostfix(PlayerControl __instance)