IQSBDropTarget

This commit is contained in:
JohnCorby 2022-04-01 14:08:08 -07:00
parent b6e9c33d2d
commit 61d51b109a
6 changed files with 24 additions and 10 deletions

View File

@ -2,6 +2,7 @@
using QSB.AuthoritySync;
using QSB.EchoesOfTheEye.LightSensorSync.WorldObjects;
using QSB.EchoesOfTheEye.RaftSync.TransformSync;
using QSB.ItemSync.WorldObjects;
using QSB.Utility.LinkedWorldObject;
using QSB.WorldSync;
using System.Linq;
@ -10,8 +11,10 @@ using UnityEngine;
namespace QSB.EchoesOfTheEye.RaftSync.WorldObjects;
public class QSBRaft : LinkedWorldObject<RaftController, RaftTransformSync>
public class QSBRaft : LinkedWorldObject<RaftController, RaftTransformSync>, IQSBDropTarget
{
IItemDropTarget IQSBDropTarget.AttachedObject => AttachedObject;
public override bool ShouldDisplayDebug() => false;
protected override GameObject NetworkObjectPrefab => QSBNetworkManager.singleton.RaftPrefab;

View File

@ -1,10 +1,13 @@
using QSB.Patches;
using QSB.ItemSync.WorldObjects;
using QSB.Patches;
using QSB.WorldSync;
namespace QSB.EchoesOfTheEye.RaftSync.WorldObjects;
public class QSBRaftDock : WorldObject<RaftDock>
public class QSBRaftDock : WorldObject<RaftDock>, IQSBDropTarget
{
IItemDropTarget IQSBDropTarget.AttachedObject => AttachedObject;
public override void SendInitialState(uint to) { }
public void OnPressInteract() =>

View File

@ -33,10 +33,10 @@ internal class ItemManager : WorldObjectManager
// Sockets
QSBWorldSync.Init<QSBItemSocket, OWItemSocket>();
// drop targets
// other drop targets that don't already have world objects
var listToInitFrom = QSBWorldSync.GetUnityObjects<MonoBehaviour>()
.Where(x => x is IItemDropTarget and not (RaftDock or RaftController))
.SortDeterministic();
QSBWorldSync.Init<QSBDropTarget, MonoBehaviour>(listToInitFrom);
QSBWorldSync.Init<QSBOtherDropTarget, MonoBehaviour>(listToInitFrom);
}
}

View File

@ -32,7 +32,7 @@ internal class DropItemMessage : QSBWorldObjectMessage<IQSBItem,
else
{
tuple.rigidBodyId = -1;
tuple.dropTargetId = ((MonoBehaviour)customDropTarget).GetWorldObject<QSBDropTarget>().ObjectId;
tuple.dropTargetId = ((MonoBehaviour)customDropTarget).GetWorldObject<IQSBDropTarget>().ObjectId;
}
tuple.sectorId = sector.GetWorldObject<QSBSector>().ObjectId;
@ -46,7 +46,7 @@ internal class DropItemMessage : QSBWorldObjectMessage<IQSBItem,
{
var customDropTarget = Data.dropTargetId == -1
? null
: Data.dropTargetId.GetWorldObject<QSBDropTarget>().AttachedObject;
: Data.dropTargetId.GetWorldObject<IQSBDropTarget>().AttachedObject;
var parent = customDropTarget == null
? Data.rigidBodyId.GetWorldObject<QSBOWRigidbody>().AttachedObject.transform

View File

@ -0,0 +1,8 @@
using QSB.WorldSync;
namespace QSB.ItemSync.WorldObjects;
public interface IQSBDropTarget : IWorldObject
{
new IItemDropTarget AttachedObject { get; }
}

View File

@ -6,13 +6,13 @@ using UnityEngine;
namespace QSB.ItemSync.WorldObjects;
public class QSBDropTarget : WorldObject<MonoBehaviour>
public class QSBOtherDropTarget : WorldObject<MonoBehaviour>, IQSBDropTarget
{
public new IItemDropTarget AttachedObject => (IItemDropTarget)base.AttachedObject;
IItemDropTarget IQSBDropTarget.AttachedObject => (IItemDropTarget)AttachedObject;
public override async UniTask Init(CancellationToken ct)
{
if (base.AttachedObject is not IItemDropTarget)
if (AttachedObject is not IItemDropTarget)
{
throw new ArgumentException("QSBDropTarget.AttachedObject is not an IItemDropTarget!");
}