Skip to content

Commit

Permalink
fix issue #11
Browse files Browse the repository at this point in the history
  • Loading branch information
XtraCube committed Sep 1, 2024
1 parent 0e40526 commit 8178967
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion MiraAPI/Patches/PlayerControlPatches.cs
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// General patches for the PlayerControl class.
/// </summary>
[HarmonyPatch(typeof(PlayerControl))]
public static class PlayerControlPatches
{
/// <summary>
/// Adds the modifier component to the player on start.
/// </summary>
[HarmonyPrefix]
[HarmonyPatch(nameof(PlayerControl.Start))]
public static void PlayerControlStartPostfix(PlayerControl __instance)
Expand All @@ -21,6 +27,24 @@ public static void PlayerControlStartPostfix(PlayerControl __instance)
__instance.gameObject.AddComponent<ModifierComponent>();
}

/// <summary>
/// Calls the OnDeath method for all active modifiers.
/// </summary>
[HarmonyPostfix]
[HarmonyPatch(nameof(PlayerControl.Die))]
public static void PlayerControlDiePostfix(PlayerControl __instance)
{
var modifiersComponent = __instance.GetComponent<ModifierComponent>();

if (modifiersComponent)
{
modifiersComponent.ActiveModifiers.ForEach(x=>x.OnDeath());
}
}

/// <summary>
/// FixedUpdate handler for custom roles and custom buttons.
/// </summary>
[HarmonyPostfix]
[HarmonyPatch(nameof(PlayerControl.FixedUpdate))]
public static void PlayerControlFixedUpdatePostfix(PlayerControl __instance)
Expand Down

0 comments on commit 8178967

Please sign in to comment.