mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-03 17:38:30 +00:00
use events instead of patches
This commit is contained in:
parent
c28353c26d
commit
fe370960a7
@ -30,35 +30,6 @@ namespace QSB.Anglerfish.Patches
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(AnglerfishController), nameof(AnglerfishController.OnSectorOccupantsUpdated))]
|
||||
public static bool OnSectorOccupantsUpdated(AnglerfishController __instance)
|
||||
{
|
||||
if (!WorldObjectManager.AllObjectsReady)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
var qsbAngler = QSBWorldSync.GetWorldFromUnity<QSBAngler>(__instance);
|
||||
|
||||
if (!__instance.gameObject.activeSelf && __instance._sector.ContainsAnyOccupants(DynamicOccupant.Player | DynamicOccupant.Probe | DynamicOccupant.Ship))
|
||||
{
|
||||
__instance.gameObject.SetActive(true);
|
||||
__instance._anglerBody.Unsuspend();
|
||||
__instance.RaiseEvent(nameof(__instance.OnAnglerUnsuspended), __instance._currentState);
|
||||
qsbAngler.TransformSync.NetIdentity.FireAuthQueue(true);
|
||||
return false;
|
||||
}
|
||||
if (__instance.gameObject.activeSelf && !__instance._sector.ContainsAnyOccupants(DynamicOccupant.Player | DynamicOccupant.Probe | DynamicOccupant.Ship))
|
||||
{
|
||||
__instance._anglerBody.Suspend();
|
||||
__instance.gameObject.SetActive(false);
|
||||
__instance.RaiseEvent(nameof(__instance.OnAnglerSuspended), __instance._currentState);
|
||||
qsbAngler.TransformSync.NetIdentity.FireAuthQueue(false);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(AnglerfishController), nameof(AnglerfishController.OnSectorOccupantRemoved))]
|
||||
public static bool OnSectorOccupantRemoved(AnglerfishController __instance,
|
||||
|
@ -35,6 +35,8 @@ namespace QSB.Anglerfish.TransformSync
|
||||
{
|
||||
NetIdentity.UnregisterAuthQueue();
|
||||
}
|
||||
AttachedObject.OnUnsuspendOWRigidbody -= OnUnsuspend;
|
||||
AttachedObject.OnSuspendOWRigidbody -= OnSuspend;
|
||||
}
|
||||
|
||||
public override float GetNetworkSendInterval() => 1;
|
||||
@ -51,10 +53,14 @@ namespace QSB.Anglerfish.TransformSync
|
||||
{
|
||||
NetIdentity.RegisterAuthQueue();
|
||||
}
|
||||
// for when you host/connect mid-game
|
||||
AttachedObject.OnUnsuspendOWRigidbody += OnUnsuspend;
|
||||
AttachedObject.OnSuspendOWRigidbody += OnSuspend;
|
||||
NetIdentity.FireAuthQueue(!AttachedObject.IsSuspended());
|
||||
}
|
||||
|
||||
private void OnUnsuspend(OWRigidbody suspendedBody) => NetIdentity.FireAuthQueue(true);
|
||||
private void OnSuspend(OWRigidbody suspendedBody) => NetIdentity.FireAuthQueue(false);
|
||||
|
||||
private bool _shouldUpdate;
|
||||
|
||||
public override void DeserializeTransform(QNetworkReader reader, bool initialState)
|
||||
|
@ -11,33 +11,6 @@ namespace QSB.JellyfishSync.Patches
|
||||
{
|
||||
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(JellyfishController), nameof(JellyfishController.OnSectorOccupantsUpdated))]
|
||||
public static bool OnSectorOccupantsUpdated(JellyfishController __instance)
|
||||
{
|
||||
if (!WorldObjectManager.AllObjectsReady)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
var qsbJellyfish = QSBWorldSync.GetWorldFromUnity<QSBJellyfish>(__instance);
|
||||
|
||||
if (!__instance.gameObject.activeSelf && __instance._sector.ContainsAnyOccupants(DynamicOccupant.Player | DynamicOccupant.Probe | DynamicOccupant.Ship))
|
||||
{
|
||||
__instance.gameObject.SetActive(true);
|
||||
__instance._jellyfishBody.Unsuspend();
|
||||
qsbJellyfish.TransformSync.NetIdentity.FireAuthQueue(true);
|
||||
return false;
|
||||
}
|
||||
if (__instance.gameObject.activeSelf && !__instance._sector.ContainsAnyOccupants(DynamicOccupant.Player | DynamicOccupant.Probe | DynamicOccupant.Ship))
|
||||
{
|
||||
__instance._jellyfishBody.Suspend();
|
||||
__instance.gameObject.SetActive(false);
|
||||
qsbJellyfish.TransformSync.NetIdentity.FireAuthQueue(false);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(JellyfishController), nameof(JellyfishController.FixedUpdate))]
|
||||
public static bool FixedUpdate(JellyfishController __instance)
|
||||
|
@ -36,6 +36,8 @@ namespace QSB.JellyfishSync.TransformSync
|
||||
{
|
||||
NetIdentity.UnregisterAuthQueue();
|
||||
}
|
||||
AttachedObject.OnUnsuspendOWRigidbody -= OnUnsuspend;
|
||||
AttachedObject.OnSuspendOWRigidbody -= OnSuspend;
|
||||
}
|
||||
|
||||
public override float GetNetworkSendInterval() => 10;
|
||||
@ -52,10 +54,14 @@ namespace QSB.JellyfishSync.TransformSync
|
||||
{
|
||||
NetIdentity.RegisterAuthQueue();
|
||||
}
|
||||
// for when you host/connect mid-game
|
||||
AttachedObject.OnUnsuspendOWRigidbody += OnUnsuspend;
|
||||
AttachedObject.OnSuspendOWRigidbody += OnSuspend;
|
||||
NetIdentity.FireAuthQueue(!AttachedObject.IsSuspended());
|
||||
}
|
||||
|
||||
private void OnUnsuspend(OWRigidbody suspendedBody) => NetIdentity.FireAuthQueue(true);
|
||||
private void OnSuspend(OWRigidbody suspendedBody) => NetIdentity.FireAuthQueue(false);
|
||||
|
||||
public override void SerializeTransform(QNetworkWriter writer, bool initialState)
|
||||
{
|
||||
base.SerializeTransform(writer, initialState);
|
||||
|
Loading…
Reference in New Issue
Block a user