59 lines
1.9 KiB
C#
Raw Normal View History

2021-04-13 17:25:00 +01:00
using OWML.Utils;
using QSB.Events;
2021-04-12 11:31:21 +01:00
using QSB.Patches;
2021-04-13 17:25:00 +01:00
using System.Linq;
2021-04-12 12:02:08 +01:00
using UnityEngine;
2021-04-12 11:31:21 +01:00
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));
QSBCore.HarmonyHelper.AddPrefix<HatchController>("OnEntry", typeof(ShipPatches), nameof(HatchController_OnEntry));
2021-04-13 17:25:00 +01:00
QSBCore.HarmonyHelper.AddPrefix<ShipTractorBeamSwitch>("OnTriggerExit", typeof(ShipPatches), nameof(ShipTractorBeamSwitch_OnTriggerExit));
}
2021-04-12 11:31:21 +01:00
public override void DoUnpatches()
{
QSBCore.HarmonyHelper.Unpatch<HatchController>("OnPressInteract");
QSBCore.HarmonyHelper.Unpatch<HatchController>("OnEntry");
2021-04-13 17:25:00 +01:00
QSBCore.HarmonyHelper.Unpatch<ShipTractorBeamSwitch>("OnTriggerExit");
}
2021-04-12 11:31:21 +01:00
public static bool HatchController_OnPressInteract()
{
2021-04-13 17:25:00 +01:00
if (!PlayerState.IsInsideShip())
{
Resources.FindObjectsOfTypeAll<ShipTractorBeamSwitch>().First().ActivateTractorBeam();
}
QSBEventManager.FireEvent(EventNames.QSBHatchState, true);
return true;
}
2021-04-12 12:02:08 +01:00
public static bool HatchController_OnEntry(GameObject hitObj)
{
if (hitObj.CompareTag("PlayerDetector"))
{
QSBEventManager.FireEvent(EventNames.QSBHatchState, false);
}
2021-04-12 11:31:21 +01:00
return true;
}
2021-04-13 17:25:00 +01:00
public static bool ShipTractorBeamSwitch_OnTriggerExit(Collider hitCollider, bool ____isPlayerInShip, bool ____functional)
{
var shipTransform = Locator.GetShipTransform();
var hatchController = shipTransform.GetComponentInChildren<HatchController>();
if (!____isPlayerInShip && ____functional && hitCollider.CompareTag("PlayerDetector") && !hatchController.GetValue<GameObject>("_hatchObject").activeSelf)
2021-04-13 17:25:00 +01:00
{
hatchController.Invoke("CloseHatch");
QSBEventManager.FireEvent(EventNames.QSBHatchState, false);
}
return false;
}
2021-04-12 11:31:21 +01:00
}
}