-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |