add open hatch event

This commit is contained in:
Mister_Nebula 2021-04-12 11:31:21 +01:00
parent 6d612a0004
commit d20739d2f3
9 changed files with 64 additions and 16 deletions

View File

@ -63,5 +63,6 @@
public static string QSBExitPlatform = "QSBExitPlatform";
public static string QSBCampfireState = "QSBCampfireState";
public static string QSBMarshmallowEvent = "QSBMarshmallowEvent";
public static string QSBOpenHatch = "QSBOpenHatch";
}
}

View File

@ -43,6 +43,7 @@
CampfireState,
Roasting,
MarshmallowEvent,
FlyShip
FlyShip,
OpenHatch
}
}

View File

@ -78,7 +78,8 @@ namespace QSB.Events
new IdentifyFrequencyEvent(),
new IdentifySignalEvent(),
// Ship
new FlyShipEvent()
new FlyShipEvent(),
new OpenHatchEvent()
};
if (UnitTestDetector.IsInUnitTest)

View File

@ -11,6 +11,7 @@ using QSB.OrbSync.Patches;
using QSB.PoolSync.Patches;
using QSB.QuantumSync.Patches;
using QSB.RoastingSync.Patches;
using QSB.ShipSync.Patches;
using QSB.StatueSync.Patches;
using QSB.TimeSync.Patches;
using QSB.TranslationSync.Patches;
@ -49,7 +50,8 @@ namespace QSB.Patches
new GeyserPatches(),
new PoolPatches(),
new CampfirePatches(),
new RoastingPatches()
new RoastingPatches(),
new ShipPatches()
};
DebugLog.DebugWrite("Patch Manager ready.", MessageType.Success);

View File

@ -225,7 +225,8 @@
<Compile Include="RoastingSync\Patches\RoastingPatches.cs" />
<Compile Include="SectorSync\FakeSector.cs" />
<Compile Include="ShipSync\Events\FlyShipEvent.cs" />
<Compile Include="ShipSync\Events\HatchEvent.cs" />
<Compile Include="ShipSync\Events\OpenHatchEvent.cs" />
<Compile Include="ShipSync\Patches\ShipPatches.cs" />
<Compile Include="ShipSync\ShipManager.cs" />
<Compile Include="StatueSync\Events\StartStatueEvent.cs" />
<Compile Include="StatueSync\Events\StartStatueMessage.cs" />

View File

@ -39,7 +39,7 @@ namespace QSB.ShipSync.Events
{
SetCurrentFlyer(message.Value, message.AboutId);
var shipCockpitController = GameObject.Find("ShipCockpitController").GetComponent<ShipCockpitController>();
var interactVolume = shipCockpitController.GetValue<SingleInteractionVolume>("_interactVolumes");
var interactVolume = shipCockpitController.GetValue<SingleInteractionVolume>("_interactVolume");
if (message.Value)
{
interactVolume.DisableInteraction();

View File

@ -1,11 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace QSB.ShipSync.Events
{
class HatchEvent
{
}
}

View File

@ -0,0 +1,31 @@
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");
}
}
}

View File

@ -0,0 +1,22 @@
using QSB.Events;
using QSB.Patches;
namespace QSB.ShipSync.Patches
{
class ShipPatches : QSBPatch
{
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
public override void DoPatches()
=> QSBCore.HarmonyHelper.AddPrefix<HatchController>("OnPressInteract", typeof(ShipPatches), nameof(HatchController_OnPressInteract));
public override void DoUnpatches()
=> QSBCore.HarmonyHelper.Unpatch<HatchController>("OnPressInteract");
public static bool HatchController_OnPressInteract()
{
QSBEventManager.FireEvent(EventNames.QSBOpenHatch);
return true;
}
}
}