mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-30 03:32:47 +00:00
Revert "remove jellyfish stuff"
This reverts commit 267c62403753b84a9d298baf9ceb7e403e6eb861.
This commit is contained in:
parent
1b0c877cb6
commit
3ac1c278d2
@ -10,6 +10,7 @@ using QSB.DeathSync.Events;
|
||||
using QSB.ElevatorSync.Events;
|
||||
using QSB.GeyserSync.Events;
|
||||
using QSB.ItemSync.Events;
|
||||
using QSB.JellyfishSync.Events;
|
||||
using QSB.LogSync.Events;
|
||||
using QSB.MeteorSync.Events;
|
||||
using QSB.OrbSync.Events;
|
||||
@ -104,6 +105,7 @@ namespace QSB.Events
|
||||
new MeteorSpecialImpactEvent(),
|
||||
new FragmentDamageEvent(),
|
||||
new FragmentResyncEvent(),
|
||||
new JellyfishRisingEvent(),
|
||||
// Conversation/dialogue/exploration
|
||||
new ConversationEvent(),
|
||||
new ConversationStartEndEvent(),
|
||||
|
35
QSB/JellyfishSync/Events/JellyfishRisingEvent.cs
Normal file
35
QSB/JellyfishSync/Events/JellyfishRisingEvent.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using QSB.Events;
|
||||
using QSB.JellyfishSync.WorldObjects;
|
||||
using QSB.WorldSync;
|
||||
using QSB.WorldSync.Events;
|
||||
|
||||
namespace QSB.JellyfishSync.Events
|
||||
{
|
||||
public class JellyfishRisingEvent : QSBEvent<BoolWorldObjectMessage>
|
||||
{
|
||||
public override void SetupListener()
|
||||
=> GlobalMessenger<QSBJellyfish>.AddListener(EventNames.QSBJellyfishRising, Handler);
|
||||
|
||||
public override void CloseListener()
|
||||
=> GlobalMessenger<QSBJellyfish>.RemoveListener(EventNames.QSBJellyfishRising, Handler);
|
||||
|
||||
private void Handler(QSBJellyfish qsbJellyfish) => SendEvent(CreateMessage(qsbJellyfish));
|
||||
|
||||
private BoolWorldObjectMessage CreateMessage(QSBJellyfish qsbJellyfish) => new()
|
||||
{
|
||||
ObjectId = qsbJellyfish.ObjectId,
|
||||
State = qsbJellyfish.IsRising
|
||||
};
|
||||
|
||||
public override void OnReceiveRemote(bool isHost, BoolWorldObjectMessage message)
|
||||
{
|
||||
if (!QSBCore.WorldObjectsReady)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var qsbJellyfish = QSBWorldSync.GetWorldFromId<QSBJellyfish>(message.ObjectId);
|
||||
qsbJellyfish.IsRising = message.State;
|
||||
}
|
||||
}
|
||||
}
|
11
QSB/JellyfishSync/JellyfishManager.cs
Normal file
11
QSB/JellyfishSync/JellyfishManager.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using QSB.JellyfishSync.WorldObjects;
|
||||
using QSB.WorldSync;
|
||||
|
||||
namespace QSB.JellyfishSync
|
||||
{
|
||||
public class JellyfishManager : WorldObjectManager
|
||||
{
|
||||
protected override void RebuildWorldObjects(OWScene scene)
|
||||
=> QSBWorldSync.Init<QSBJellyfish, JellyfishController>();
|
||||
}
|
||||
}
|
73
QSB/JellyfishSync/Patches/JellyfishPatches.cs
Normal file
73
QSB/JellyfishSync/Patches/JellyfishPatches.cs
Normal file
@ -0,0 +1,73 @@
|
||||
using HarmonyLib;
|
||||
using QSB.Events;
|
||||
using QSB.JellyfishSync.WorldObjects;
|
||||
using QSB.Patches;
|
||||
using QSB.WorldSync;
|
||||
|
||||
namespace QSB.JellyfishSync.Patches
|
||||
{
|
||||
public class JellyfishPatches : QSBPatch
|
||||
{
|
||||
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(JellyfishController), nameof(JellyfishController.OnSectorOccupantsUpdated))]
|
||||
public static bool OnSectorOccupantsUpdated(JellyfishController __instance)
|
||||
{
|
||||
if (!QSBCore.WorldObjectsReady)
|
||||
{
|
||||
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();
|
||||
QSBEventManager.FireEvent(EventNames.QSBSuspendChange, qsbJellyfish.TransformSync.NetIdentity, false);
|
||||
return false;
|
||||
}
|
||||
if (__instance.gameObject.activeSelf && !__instance._sector.ContainsAnyOccupants(DynamicOccupant.Player | DynamicOccupant.Probe | DynamicOccupant.Ship))
|
||||
{
|
||||
__instance._jellyfishBody.Suspend();
|
||||
__instance.gameObject.SetActive(false);
|
||||
QSBEventManager.FireEvent(EventNames.QSBSuspendChange, qsbJellyfish.TransformSync.NetIdentity, true);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(JellyfishController), nameof(JellyfishController.FixedUpdate))]
|
||||
public static bool FixedUpdate(JellyfishController __instance)
|
||||
{
|
||||
if (!QSBCore.WorldObjectsReady)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
var qsbJellyfish = QSBWorldSync.GetWorldFromUnity<QSBJellyfish>(__instance);
|
||||
|
||||
var sqrMagnitude = (__instance._jellyfishBody.GetPosition() - __instance._planetBody.GetPosition()).sqrMagnitude;
|
||||
if (qsbJellyfish.IsRising)
|
||||
{
|
||||
__instance._jellyfishBody.AddAcceleration(__instance.transform.up * __instance._upwardsAcceleration);
|
||||
if (sqrMagnitude > __instance._upperLimit * __instance._upperLimit)
|
||||
{
|
||||
qsbJellyfish.IsRising = false;
|
||||
QSBEventManager.FireEvent(EventNames.QSBJellyfishRising, qsbJellyfish);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
__instance._jellyfishBody.AddAcceleration(-__instance.transform.up * __instance._downwardsAcceleration);
|
||||
if (sqrMagnitude < __instance._lowerLimit * __instance._lowerLimit)
|
||||
{
|
||||
qsbJellyfish.IsRising = true;
|
||||
QSBEventManager.FireEvent(EventNames.QSBJellyfishRising, qsbJellyfish);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
164
QSB/JellyfishSync/TransformSync/JellyfishTransformSync.cs
Normal file
164
QSB/JellyfishSync/TransformSync/JellyfishTransformSync.cs
Normal file
@ -0,0 +1,164 @@
|
||||
using System.Collections.Generic;
|
||||
using QSB.JellyfishSync.WorldObjects;
|
||||
using QSB.Syncs;
|
||||
using QSB.Syncs.Unsectored.Rigidbodies;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using QuantumUNET.Transport;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.JellyfishSync.TransformSync
|
||||
{
|
||||
public class JellyfishTransformSync : UnsectoredRigidbodySync
|
||||
{
|
||||
public override bool IsReady => QSBCore.WorldObjectsReady;
|
||||
public override bool UseInterpolation => false;
|
||||
|
||||
private QSBJellyfish _qsbJellyfish;
|
||||
private static readonly List<JellyfishTransformSync> _instances = new();
|
||||
|
||||
protected override OWRigidbody GetRigidbody()
|
||||
=> _qsbJellyfish.AttachedObject._jellyfishBody;
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
_instances.Add(this);
|
||||
base.Start();
|
||||
}
|
||||
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
_instances.Remove(this);
|
||||
base.OnDestroy();
|
||||
}
|
||||
|
||||
public override float GetNetworkSendInterval() => 10;
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
_qsbJellyfish = QSBWorldSync.GetWorldFromId<QSBJellyfish>(_instances.IndexOf(this));
|
||||
_qsbJellyfish.TransformSync = this;
|
||||
|
||||
base.Init();
|
||||
SetReferenceTransform(_qsbJellyfish.AttachedObject._planetBody.transform);
|
||||
}
|
||||
|
||||
public override void SerializeTransform(QNetworkWriter writer, bool initialState)
|
||||
{
|
||||
base.SerializeTransform(writer, initialState);
|
||||
|
||||
if (!QSBCore.WorldObjectsReady)
|
||||
{
|
||||
writer.Write(false);
|
||||
return;
|
||||
}
|
||||
|
||||
_qsbJellyfish.Align = true;
|
||||
writer.Write(_qsbJellyfish.IsRising);
|
||||
}
|
||||
|
||||
private bool _shouldUpdate;
|
||||
|
||||
public override void DeserializeTransform(QNetworkReader reader, bool initialState)
|
||||
{
|
||||
base.DeserializeTransform(reader, initialState);
|
||||
|
||||
if (!QSBCore.WorldObjectsReady || HasAuthority)
|
||||
{
|
||||
reader.ReadBoolean();
|
||||
return;
|
||||
}
|
||||
|
||||
_qsbJellyfish.Align = false;
|
||||
_qsbJellyfish.IsRising = reader.ReadBoolean();
|
||||
_shouldUpdate = true;
|
||||
}
|
||||
|
||||
/// replacement using SetPosition/Rotation instead of Move
|
||||
protected override bool UpdateTransform()
|
||||
{
|
||||
if (HasAuthority)
|
||||
{
|
||||
SetValuesToSync();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!_shouldUpdate)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_shouldUpdate = false;
|
||||
|
||||
var targetPos = ReferenceTransform.DecodePos(transform.position);
|
||||
var targetRot = ReferenceTransform.DecodeRot(transform.rotation);
|
||||
|
||||
if (targetPos == Vector3.zero || transform.position == Vector3.zero)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var positionToSet = targetPos;
|
||||
var rotationToSet = targetRot;
|
||||
|
||||
if (UseInterpolation)
|
||||
{
|
||||
positionToSet = SmartSmoothDamp(AttachedObject.transform.position, targetPos);
|
||||
rotationToSet = QuaternionHelper.SmoothDamp(AttachedObject.transform.rotation, targetRot, ref _rotationSmoothVelocity, SmoothTime);
|
||||
}
|
||||
|
||||
var hasMoved = CustomHasMoved(
|
||||
transform.position,
|
||||
_localPrevPosition,
|
||||
transform.rotation,
|
||||
_localPrevRotation,
|
||||
_relativeVelocity,
|
||||
_localPrevVelocity,
|
||||
_relativeAngularVelocity,
|
||||
_localPrevAngularVelocity);
|
||||
|
||||
_localPrevPosition = transform.position;
|
||||
_localPrevRotation = transform.rotation;
|
||||
_localPrevVelocity = _relativeVelocity;
|
||||
_localPrevAngularVelocity = _relativeAngularVelocity;
|
||||
|
||||
if (!hasMoved)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
((OWRigidbody)AttachedObject).SetPosition(positionToSet);
|
||||
((OWRigidbody)AttachedObject).SetRotation(rotationToSet);
|
||||
|
||||
var targetVelocity = ReferenceTransform.GetAttachedOWRigidbody().DecodeVel(_relativeVelocity, targetPos);
|
||||
var targetAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().DecodeAngVel(_relativeAngularVelocity);
|
||||
|
||||
((OWRigidbody)AttachedObject).SetVelocity(targetVelocity);
|
||||
((OWRigidbody)AttachedObject).SetAngularVelocity(targetAngularVelocity);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
protected override void OnRenderObject()
|
||||
{
|
||||
if (!QSBCore.WorldObjectsReady
|
||||
|| !QSBCore.ShowLinesInDebug
|
||||
|| !IsReady
|
||||
|| ReferenceTransform == null
|
||||
|| ((OWRigidbody)AttachedObject).IsSuspended())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
base.OnRenderObject();
|
||||
|
||||
var jellyfish = _qsbJellyfish.AttachedObject;
|
||||
var position = ReferenceTransform.position;
|
||||
var dir = Vector3.Normalize(jellyfish.transform.position - position);
|
||||
// Popcron.Gizmos.Line(position + dir * jellyfish._lowerLimit, position + dir * jellyfish._upperLimit, Color.magenta);
|
||||
Popcron.Gizmos.Sphere(position + dir * jellyfish._lowerLimit, 10f, Color.magenta);
|
||||
Popcron.Gizmos.Sphere(position + dir * jellyfish._upperLimit, 10f, Color.magenta);
|
||||
}
|
||||
}
|
||||
}
|
63
QSB/JellyfishSync/WorldObjects/QSBJellyfish.cs
Normal file
63
QSB/JellyfishSync/WorldObjects/QSBJellyfish.cs
Normal file
@ -0,0 +1,63 @@
|
||||
using QSB.Events;
|
||||
using QSB.JellyfishSync.TransformSync;
|
||||
using QSB.SuspendableSync;
|
||||
using QSB.WorldSync;
|
||||
using QuantumUNET;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.JellyfishSync.WorldObjects
|
||||
{
|
||||
public class QSBJellyfish : WorldObject<JellyfishController>
|
||||
{
|
||||
public JellyfishTransformSync TransformSync;
|
||||
private AlignWithTargetBody _alignWithTargetBody;
|
||||
|
||||
public override void Init(JellyfishController attachedObject, int id)
|
||||
{
|
||||
ObjectId = id;
|
||||
AttachedObject = attachedObject;
|
||||
_alignWithTargetBody = AttachedObject.GetRequiredComponent<AlignWithTargetBody>();
|
||||
|
||||
if (QSBCore.IsHost)
|
||||
{
|
||||
QNetworkServer.Spawn(Object.Instantiate(QSBNetworkManager.Instance.JellyfishPrefab));
|
||||
QSBCore.UnityEvents.RunWhen(() => TransformSync, () =>
|
||||
SuspendableManager.Register(TransformSync.NetIdentity));
|
||||
}
|
||||
|
||||
// for when you host/connect mid-game
|
||||
QSBCore.UnityEvents.RunWhen(() => TransformSync, () =>
|
||||
QSBEventManager.FireEvent(EventNames.QSBSuspendChange, TransformSync.NetIdentity, AttachedObject._jellyfishBody.IsSuspended()));
|
||||
}
|
||||
|
||||
public override void OnRemoval()
|
||||
{
|
||||
if (QSBCore.IsHost)
|
||||
{
|
||||
SuspendableManager.Unregister(TransformSync.NetIdentity);
|
||||
QNetworkServer.Destroy(TransformSync.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bool IsRising
|
||||
{
|
||||
get => AttachedObject._isRising;
|
||||
set
|
||||
{
|
||||
if (AttachedObject._isRising == value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
AttachedObject._isRising = value;
|
||||
AttachedObject._attractiveFluidVolume.SetVolumeActivation(!value);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Align
|
||||
{
|
||||
set => _alignWithTargetBody.enabled = value;
|
||||
}
|
||||
}
|
||||
}
|
@ -14,6 +14,7 @@ using QSB.ElevatorSync.Patches;
|
||||
using QSB.GeyserSync.Patches;
|
||||
using QSB.Inputs.Patches;
|
||||
using QSB.ItemSync.Patches;
|
||||
using QSB.JellyfishSync.Patches;
|
||||
using QSB.LogSync.Patches;
|
||||
using QSB.MeteorSync.Patches;
|
||||
using QSB.OrbSync.Patches;
|
||||
@ -78,6 +79,7 @@ namespace QSB.Patches
|
||||
new AnglerPatches(),
|
||||
new MeteorClientPatches(),
|
||||
new MeteorServerPatches(),
|
||||
new JellyfishPatches(),
|
||||
new TravelerControllerPatches(),
|
||||
new ZeroGCavePatches()
|
||||
};
|
||||
|
@ -12,6 +12,7 @@ using QSB.ElevatorSync;
|
||||
using QSB.GeyserSync;
|
||||
using QSB.Inputs;
|
||||
using QSB.ItemSync;
|
||||
using QSB.JellyfishSync;
|
||||
using QSB.Menus;
|
||||
using QSB.MeteorSync;
|
||||
using QSB.OrbSync;
|
||||
@ -141,6 +142,7 @@ namespace QSB
|
||||
gameObject.AddComponent<AirlockManager>();
|
||||
gameObject.AddComponent<AnglerManager>();
|
||||
gameObject.AddComponent<MeteorManager>();
|
||||
gameObject.AddComponent<JellyfishManager>();
|
||||
gameObject.AddComponent<ZeroGCaveManager>();
|
||||
|
||||
DebugBoxManager.Init();
|
||||
|
Loading…
x
Reference in New Issue
Block a user