fix hatch interaction

This commit is contained in:
Mister_Nebula 2021-04-13 21:09:26 +01:00
parent 38162b3994
commit 0e218b95ad
3 changed files with 47 additions and 6 deletions

View File

@ -1,6 +1,7 @@
using OWML.Utils;
using QSB.Events;
using QSB.Patches;
using QSB.Utility;
using System.Linq;
using UnityEngine;
@ -15,6 +16,7 @@ namespace QSB.ShipSync.Patches
QSBCore.HarmonyHelper.AddPrefix<HatchController>("OnPressInteract", typeof(ShipPatches), nameof(HatchController_OnPressInteract));
QSBCore.HarmonyHelper.AddPrefix<HatchController>("OnEntry", typeof(ShipPatches), nameof(HatchController_OnEntry));
QSBCore.HarmonyHelper.AddPrefix<ShipTractorBeamSwitch>("OnTriggerExit", typeof(ShipPatches), nameof(ShipTractorBeamSwitch_OnTriggerExit));
QSBCore.HarmonyHelper.AddPrefix<InteractZone>("UpdateInteractVolume", typeof(ShipPatches), nameof(InteractZone_UpdateInteractVolume));
}
public override void DoUnpatches()
@ -22,6 +24,7 @@ namespace QSB.ShipSync.Patches
QSBCore.HarmonyHelper.Unpatch<HatchController>("OnPressInteract");
QSBCore.HarmonyHelper.Unpatch<HatchController>("OnEntry");
QSBCore.HarmonyHelper.Unpatch<ShipTractorBeamSwitch>("OnTriggerExit");
QSBCore.HarmonyHelper.Unpatch<InteractZone>("UpdateInteractVolume");
}
public static bool HatchController_OnPressInteract()
@ -53,5 +56,35 @@ namespace QSB.ShipSync.Patches
}
return false;
}
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;
}
}
}

View File

@ -36,11 +36,6 @@ namespace QSB.ShipSync
{
QSBSceneManager.OnUniverseSceneLoaded += OnSceneLoaded;
Instance = this;
var shipTransform = Locator.GetShipTransform();
HatchController = shipTransform.GetComponentInChildren<HatchController>();
HatchInteractZone = HatchController.GetComponent<InteractZone>();
ShipTractorBeam = Resources.FindObjectsOfTypeAll<ShipTractorBeamSwitch>().First();
}
private void OnSceneLoaded(OWScene scene)
@ -49,7 +44,11 @@ namespace QSB.ShipSync
{
return;
}
HatchInteractZone.SetValue("_viewingWindow", 90f);
var shipTransform = GameObject.Find("Ship_Body");
HatchController = shipTransform.GetComponentInChildren<HatchController>();
HatchInteractZone = HatchController.GetComponent<InteractZone>();
ShipTractorBeam = Resources.FindObjectsOfTypeAll<ShipTractorBeamSwitch>().First();
var sphereShape = HatchController.GetComponent<SphereShape>();
sphereShape.radius = 2.5f;

View File

@ -60,5 +60,14 @@ namespace QSB.Utility
public static float Map(this float value, float inputFrom, float inputTo, float outputFrom, float outputTo)
=> ((value - inputFrom) / (inputTo - inputFrom) * (outputTo - outputFrom)) + outputFrom;
public static void CallBase<ThisType, BaseType>(this ThisType obj, string methodName)
where ThisType : BaseType
{
var method = typeof(BaseType).GetMethod(methodName);
var functionPointer = method.MethodHandle.GetFunctionPointer();
var methodAction = (Action)Activator.CreateInstance(typeof(Action), obj, functionPointer);
methodAction();
}
}
}