mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-13 12:40:50 +00:00
change hatch patch to be open and close
This commit is contained in:
parent
d20739d2f3
commit
a250a222a0
@ -63,6 +63,6 @@
|
||||
public static string QSBExitPlatform = "QSBExitPlatform";
|
||||
public static string QSBCampfireState = "QSBCampfireState";
|
||||
public static string QSBMarshmallowEvent = "QSBMarshmallowEvent";
|
||||
public static string QSBOpenHatch = "QSBOpenHatch";
|
||||
public static string QSBHatchState = "QSBOpenHatch";
|
||||
}
|
||||
}
|
39
QSB/ShipSync/Events/HatchEvent.cs
Normal file
39
QSB/ShipSync/Events/HatchEvent.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using OWML.Utils;
|
||||
using QSB.Events;
|
||||
using QSB.Messaging;
|
||||
|
||||
namespace QSB.ShipSync.Events
|
||||
{
|
||||
class HatchEvent : QSBEvent<BoolMessage>
|
||||
{
|
||||
public override EventType Type => EventType.OpenHatch;
|
||||
|
||||
public override void SetupListener()
|
||||
=> GlobalMessenger<bool>.AddListener(EventNames.QSBHatchState, Handler);
|
||||
|
||||
public override void CloseListener()
|
||||
=> GlobalMessenger<bool>.RemoveListener(EventNames.QSBHatchState, Handler);
|
||||
|
||||
private void Handler(bool open) => SendEvent(CreateMessage(open));
|
||||
|
||||
private BoolMessage CreateMessage(bool open) => new BoolMessage
|
||||
{
|
||||
AboutId = LocalPlayerId,
|
||||
Value = open
|
||||
};
|
||||
|
||||
public override void OnReceiveRemote(bool server, BoolMessage message)
|
||||
{
|
||||
var shipTransform = Locator.GetShipTransform();
|
||||
var hatchController = shipTransform.GetComponentInChildren<HatchController>();
|
||||
if (message.Value)
|
||||
{
|
||||
hatchController.Invoke("OpenHatch");
|
||||
}
|
||||
else
|
||||
{
|
||||
hatchController.Invoke("CloseHatch");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
using OWML.Utils;
|
||||
using QSB.Events;
|
||||
using QSB.Messaging;
|
||||
|
||||
namespace QSB.ShipSync.Events
|
||||
{
|
||||
class OpenHatchEvent : QSBEvent<PlayerMessage>
|
||||
{
|
||||
public override EventType Type => EventType.OpenHatch;
|
||||
|
||||
public override void SetupListener()
|
||||
=> GlobalMessenger.AddListener(EventNames.QSBOpenHatch, Handler);
|
||||
|
||||
public override void CloseListener()
|
||||
=> GlobalMessenger.RemoveListener(EventNames.QSBOpenHatch, Handler);
|
||||
|
||||
private void Handler() => SendEvent(CreateMessage());
|
||||
|
||||
private PlayerMessage CreateMessage() => new PlayerMessage
|
||||
{
|
||||
AboutId = LocalPlayerId
|
||||
};
|
||||
|
||||
public override void OnReceiveRemote(bool server, PlayerMessage message)
|
||||
{
|
||||
var shipTransform = Locator.GetShipTransform();
|
||||
var hatchController = shipTransform.GetComponentInChildren<HatchController>();
|
||||
hatchController.Invoke("OpenHatch");
|
||||
}
|
||||
}
|
||||
}
|
@ -7,15 +7,30 @@ namespace QSB.ShipSync.Patches
|
||||
{
|
||||
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
|
||||
|
||||
public override void DoPatches()
|
||||
=> QSBCore.HarmonyHelper.AddPrefix<HatchController>("OnPressInteract", typeof(ShipPatches), nameof(HatchController_OnPressInteract));
|
||||
public override void DoPatches()
|
||||
{
|
||||
QSBCore.HarmonyHelper.AddPrefix<HatchController>("OnPressInteract", typeof(ShipPatches), nameof(HatchController_OnPressInteract));
|
||||
QSBCore.HarmonyHelper.AddPrefix<HatchController>("OnEntry", typeof(ShipPatches), nameof(HatchController_OnEntry));
|
||||
}
|
||||
|
||||
public override void DoUnpatches()
|
||||
=> QSBCore.HarmonyHelper.Unpatch<HatchController>("OnPressInteract");
|
||||
public override void DoUnpatches()
|
||||
{
|
||||
QSBCore.HarmonyHelper.Unpatch<HatchController>("OnPressInteract");
|
||||
QSBCore.HarmonyHelper.Unpatch<HatchController>("OnEntry");
|
||||
}
|
||||
|
||||
public static bool HatchController_OnPressInteract()
|
||||
{
|
||||
QSBEventManager.FireEvent(EventNames.QSBOpenHatch);
|
||||
QSBEventManager.FireEvent(EventNames.QSBHatchState, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool HatchController_OnEntry(GameObjectActivationTrigger hitObj)
|
||||
{
|
||||
if (hitObj.CompareTag("PlayerDetector"))
|
||||
{
|
||||
QSBEventManager.FireEvent(EventNames.QSBHatchState, false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user