quantum-space-buddies/QSB/ShipSync/Patches/ShipPatches.cs

91 lines
2.8 KiB
C#
Raw Normal View History

2021-04-13 16:25:00 +00:00
using OWML.Utils;
using QSB.Events;
2021-04-12 10:31:21 +00:00
using QSB.Patches;
2021-04-13 20:09:26 +00:00
using QSB.Utility;
2021-04-13 16:25:00 +00:00
using System.Linq;
2021-04-12 11:02:08 +00:00
using UnityEngine;
2021-04-12 10:31:21 +00: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 16:25:00 +00:00
QSBCore.HarmonyHelper.AddPrefix<ShipTractorBeamSwitch>("OnTriggerExit", typeof(ShipPatches), nameof(ShipTractorBeamSwitch_OnTriggerExit));
2021-04-13 20:09:26 +00:00
QSBCore.HarmonyHelper.AddPrefix<InteractZone>("UpdateInteractVolume", typeof(ShipPatches), nameof(InteractZone_UpdateInteractVolume));
}
2021-04-12 10:31:21 +00:00
public override void DoUnpatches()
{
QSBCore.HarmonyHelper.Unpatch<HatchController>("OnPressInteract");
QSBCore.HarmonyHelper.Unpatch<HatchController>("OnEntry");
2021-04-13 16:25:00 +00:00
QSBCore.HarmonyHelper.Unpatch<ShipTractorBeamSwitch>("OnTriggerExit");
2021-04-13 20:09:26 +00:00
QSBCore.HarmonyHelper.Unpatch<InteractZone>("UpdateInteractVolume");
}
2021-04-12 10:31:21 +00:00
public static bool HatchController_OnPressInteract()
{
2021-04-13 16:25:00 +00:00
if (!PlayerState.IsInsideShip())
{
2021-04-13 17:50:15 +00:00
ShipManager.Instance.ShipTractorBeam.ActivateTractorBeam();
2021-04-13 16:25:00 +00:00
}
QSBEventManager.FireEvent(EventNames.QSBHatchState, true);
return true;
}
2021-04-12 11:02:08 +00:00
public static bool HatchController_OnEntry(GameObject hitObj)
{
if (hitObj.CompareTag("PlayerDetector"))
{
QSBEventManager.FireEvent(EventNames.QSBHatchState, false);
}
2021-04-12 10:31:21 +00:00
return true;
}
2021-04-13 16:25:00 +00:00
public static bool ShipTractorBeamSwitch_OnTriggerExit(Collider hitCollider, bool ____isPlayerInShip, bool ____functional)
{
2021-04-13 17:50:15 +00:00
if (!____isPlayerInShip && ____functional && hitCollider.CompareTag("PlayerDetector") && !ShipManager.Instance.HatchController.GetValue<GameObject>("_hatchObject").activeSelf)
2021-04-13 16:25:00 +00:00
{
2021-04-13 17:50:15 +00:00
ShipManager.Instance.HatchController.Invoke("CloseHatch");
ShipManager.Instance.ShipTractorBeam.DeactivateTractorBeam();
2021-04-13 16:25:00 +00:00
QSBEventManager.FireEvent(EventNames.QSBHatchState, false);
}
return false;
}
2021-04-13 20:09:26 +00:00
public static bool InteractZone_UpdateInteractVolume(InteractZone __instance, OWCamera ____playerCam, ref bool ____focused)
{
/* Angle for interaction with the ship hatch
*
* \ 80° / - If in ship
* \ /
* \ /
* [=====] - Hatch
* / \
* / \
* / 280° \ - If not in ship
*
*/
if (!QSBCore.HasWokenUp || __instance != ShipManager.Instance.HatchInteractZone)
{
return true;
}
var angle = 2f * Vector3.Angle(____playerCam.transform.forward, __instance.transform.forward);
____focused = PlayerState.IsInsideShip()
? angle <= 80
: angle >= 280;
__instance.CallBase<InteractZone, SingleInteractionVolume>("UpdateInteractVolume");
return false;
}
2021-04-12 10:31:21 +00:00
}
}