130 lines
3.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 21:09:26 +01:00
using QSB.Utility;
2021-04-12 12:02:08 +01:00
using UnityEngine;
2021-04-12 11:31:21 +01:00
namespace QSB.ShipSync.Patches
{
2021-05-15 21:31:29 +01:00
internal class ShipPatches : QSBPatch
2021-04-12 11:31:21 +01:00
{
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
public override void DoPatches()
{
2021-06-18 21:54:32 +01:00
Prefix(nameof(HatchController_OnPressInteract));
Prefix(nameof(HatchController_OnEntry));
Prefix(nameof(ShipTractorBeamSwitch_OnTriggerExit));
Prefix(nameof(InteractZone_UpdateInteractVolume));
2021-06-19 12:14:45 +01:00
Prefix(nameof(ShipElectricalComponent_OnEnterShip));
Prefix(nameof(ShipElectricalComponent_OnExitShip));
Prefix(nameof(ElectricalSystem_SetPowered));
Prefix(nameof(ElectricalComponent_SetPowered));
2021-06-19 15:48:32 +01:00
Prefix(nameof(ShipComponent_SetDamaged));
Postfix(nameof(ShipComponent_RepairTick));
}
2021-04-12 11:31:21 +01:00
public static bool HatchController_OnPressInteract()
{
2021-04-13 17:25:00 +01:00
if (!PlayerState.IsInsideShip())
{
2021-04-13 18:50:15 +01:00
ShipManager.Instance.ShipTractorBeam.ActivateTractorBeam();
2021-06-14 16:13:32 +01:00
QSBEventManager.FireEvent(EventNames.QSBEnableFunnel);
2021-04-13 17:25:00 +01:00
}
2021-06-18 22:38:32 +01:00
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-06-18 22:38:32 +01:00
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)
{
2021-04-13 18:50:15 +01:00
if (!____isPlayerInShip && ____functional && hitCollider.CompareTag("PlayerDetector") && !ShipManager.Instance.HatchController.GetValue<GameObject>("_hatchObject").activeSelf)
2021-04-13 17:25:00 +01:00
{
2021-04-13 18:50:15 +01:00
ShipManager.Instance.HatchController.Invoke("CloseHatch");
ShipManager.Instance.ShipTractorBeam.DeactivateTractorBeam();
2021-04-13 17:25:00 +01:00
QSBEventManager.FireEvent(EventNames.QSBHatchState, false);
}
2021-06-18 22:38:32 +01:00
2021-04-13 17:25:00 +01:00
return false;
}
2021-04-13 21:09:26 +01: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
*
*/
2021-05-10 14:30:38 +01:00
if (!QSBCore.WorldObjectsReady || __instance != ShipManager.Instance.HatchInteractZone)
2021-04-13 21:09:26 +01:00
{
return true;
}
var angle = 2f * Vector3.Angle(____playerCam.transform.forward, __instance.transform.forward);
2021-06-19 11:26:05 +01:00
____focused = PlayerState.IsInsideShip()
? angle <= 80
2021-04-13 21:09:26 +01:00
: angle >= 280;
__instance.CallBase<InteractZone, SingleInteractionVolume>("UpdateInteractVolume");
return false;
}
2021-06-19 12:14:45 +01:00
public static bool ShipElectricalComponent_OnEnterShip(ShipElectricalComponent __instance, bool ____damaged, ElectricalSystem ____electricalSystem)
{
__instance.CallBase<ShipElectricalComponent, ShipComponent>("OnEnterShip");
return false;
}
public static bool ShipElectricalComponent_OnExitShip(ShipElectricalComponent __instance, bool ____damaged, ElectricalSystem ____electricalSystem)
{
__instance.CallBase<ShipElectricalComponent, ShipComponent>("OnExitShip");
return false;
}
public static bool ElectricalSystem_SetPowered(ElectricalSystem __instance, bool powered)
{
2021-06-19 15:48:32 +01:00
DebugLog.DebugWrite($"[E SYSTEM] {__instance.name} set powered {powered}");
2021-06-19 12:14:45 +01:00
return true;
}
public static bool ElectricalComponent_SetPowered(ElectricalComponent __instance, bool powered)
{
2021-06-19 15:48:32 +01:00
DebugLog.DebugWrite($"[E COMPONENT] {__instance.name} set powered {powered}");
2021-06-19 12:14:45 +01:00
return true;
}
2021-06-19 15:48:32 +01:00
public static bool ShipComponent_SetDamaged(ShipComponent __instance, bool damaged)
{
DebugLog.DebugWrite($"[S COMPONENT] {__instance.name} set damaged {damaged}", OWML.Common.MessageType.Warning);
return true;
}
public static void ShipComponent_RepairTick(ShipComponent __instance, float ____repairFraction)
{
DebugLog.DebugWrite($"[S COMPONENT] {__instance.name} repair tick {____repairFraction}");
return;
}
2021-04-12 11:31:21 +01:00
}
}