mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 01:46:15 +00:00
basic "sabotage" event
This commit is contained in:
1 parent
3ea46d5574
commit
04ee35d708
3 files changed
+50
No files matched your search
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ namespace MiraAPI.Patches.Events;
|
||||
/// <summary>
|
||||
/// Patch for button related MiraEvents.
|
||||
/// </summary>
|
||||
[HarmonyPatch]
|
||||
public static class HudButtonEventPatches
|
||||
{
|
||||
[HarmonyPrefix]
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user