Skip to content

Commit

Permalink
basic "sabotage" event
Browse files Browse the repository at this point in the history
  • Loading branch information
XtraCube committed Dec 8, 2024
1 parent 3ea46d5 commit 04ee35d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
28 changes: 28 additions & 0 deletions MiraAPI/Events/Vanilla/UpdateSystemEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace MiraAPI.Events.Vanilla;

/// <summary>
/// Cancelable event that is invoked before a system is updated. Usually used for sabotage events.
/// </summary>
public class UpdateSystemEvent : MiraCancelableEvent
{
/// <summary>
/// Gets the type of system that will be updated.
/// </summary>
public SystemTypes SystemType { get; }

/// <summary>
/// Gets the byte amount the system is being updated by.
/// </summary>
public byte Amount { get; }

/// <summary>
/// Initializes a new instance of the <see cref="UpdateSystemEvent"/> class.
/// </summary>
/// <param name="systemType">The SystemType being updated.</param>
/// <param name="amount">Amount to update System to.</param>
public UpdateSystemEvent(SystemTypes systemType, byte amount)
{
SystemType = systemType;
Amount = amount;
}
}
1 change: 1 addition & 0 deletions MiraAPI/Patches/Events/HudButtonEventPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace MiraAPI.Patches.Events;
/// <summary>
/// Patch for button related MiraEvents.
/// </summary>
[HarmonyPatch]
public static class HudButtonEventPatches
{
[HarmonyPrefix]
Expand Down
21 changes: 21 additions & 0 deletions MiraAPI/Patches/Events/SabotageEventPatches.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using HarmonyLib;
using MiraAPI.Events;
using MiraAPI.Events.Vanilla;

namespace MiraAPI.Patches.Events;

/// <summary>
/// Used for patching sabotage/system related MiraEvents.
/// </summary>
[HarmonyPatch]
public static class SabotageEventPatches
{
[HarmonyPrefix]
[HarmonyPatch(typeof(ShipStatus), nameof(ShipStatus.RpcUpdateSystem), typeof(SystemTypes), typeof(byte))]
public static bool ShipStatusRpcUpdateSystemPrefix(ShipStatus __instance, SystemTypes systemType, byte amount)
{
var @event = new UpdateSystemEvent(systemType, amount);
MiraEventManager.InvokeEvent(@event);
return !@event.IsCancelled;
}
}

0 comments on commit 04ee35d

Please sign in to comment.