2022-04-01 19:08:03 +01:00
|
|
|
|
using QSB.ItemSync.WorldObjects;
|
|
|
|
|
using QSB.ItemSync.WorldObjects.Items;
|
2021-12-25 22:35:32 -08:00
|
|
|
|
using QSB.Messaging;
|
|
|
|
|
using QSB.Player;
|
2021-02-24 10:45:25 +00:00
|
|
|
|
using QSB.SectorSync.WorldObjects;
|
|
|
|
|
using QSB.WorldSync;
|
2022-04-01 19:08:03 +01:00
|
|
|
|
using QSB.WorldSync.WorldObjects;
|
2021-02-24 10:45:25 +00:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
namespace QSB.ItemSync.Messages;
|
|
|
|
|
|
2022-04-01 19:08:03 +01:00
|
|
|
|
internal class DropItemMessage : QSBWorldObjectMessage<IQSBItem, (Vector3 localPosition, Vector3 localNormal, int sectorId, int dropTargetId, int rigidBodyId)>
|
2021-02-24 10:45:25 +00:00
|
|
|
|
{
|
2022-04-01 19:08:03 +01:00
|
|
|
|
public DropItemMessage(Vector3 worldPosition, Vector3 worldNormal, Transform parent, Sector sector, MonoBehaviourWorldObject customDropTarget, OWRigidbody targetRigidbody)
|
|
|
|
|
: base(ProcessInputs(worldPosition, worldNormal, parent, sector, customDropTarget, targetRigidbody)) { }
|
|
|
|
|
|
|
|
|
|
private static (Vector3 localPosition, Vector3 localNormal, int sectorId, int dropTargetId, int rigidBodyId) ProcessInputs(
|
|
|
|
|
Vector3 worldPosition,
|
|
|
|
|
Vector3 worldNormal,
|
|
|
|
|
Transform parent,
|
|
|
|
|
Sector sector,
|
|
|
|
|
MonoBehaviourWorldObject customDropTarget,
|
|
|
|
|
OWRigidbody targetRigidbody)
|
|
|
|
|
{
|
|
|
|
|
(Vector3 localPosition, Vector3 localNormal, int sectorId, int dropTargetId, int rigidBodyId) tuple = new();
|
|
|
|
|
|
|
|
|
|
if (customDropTarget == null)
|
|
|
|
|
{
|
|
|
|
|
tuple.rigidBodyId = targetRigidbody.GetWorldObject<QSBOWRigidbody>().ObjectId;
|
|
|
|
|
tuple.dropTargetId = -1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
tuple.rigidBodyId = -1;
|
|
|
|
|
tuple.dropTargetId = customDropTarget.ObjectId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tuple.sectorId = sector.GetWorldObject<QSBSector>().ObjectId;
|
|
|
|
|
tuple.localPosition = parent.InverseTransformPoint(worldPosition);
|
|
|
|
|
tuple.localNormal = parent.InverseTransformDirection(worldNormal);
|
|
|
|
|
|
|
|
|
|
return tuple;
|
|
|
|
|
}
|
2022-03-02 19:46:33 -08:00
|
|
|
|
|
|
|
|
|
public override void OnReceiveRemote()
|
|
|
|
|
{
|
2022-04-01 19:08:03 +01:00
|
|
|
|
var customDropTarget = (Data.dropTargetId == -1)
|
|
|
|
|
? null
|
|
|
|
|
: QSBWorldSync.GetWorldObject<MonoBehaviourWorldObject>(Data.dropTargetId).AttachedObject as IItemDropTarget;
|
|
|
|
|
|
|
|
|
|
var parent = (Data.dropTargetId == -1)
|
|
|
|
|
? QSBWorldSync.GetWorldObject<QSBOWRigidbody>(Data.rigidBodyId).AttachedObject.transform
|
|
|
|
|
: customDropTarget.GetItemDropTargetTransform(null);
|
|
|
|
|
|
|
|
|
|
var worldPos = parent.TransformPoint(Data.localPosition);
|
|
|
|
|
var worldNormal = parent.TransformDirection(Data.localNormal);
|
|
|
|
|
|
|
|
|
|
var sector = QSBWorldSync.GetWorldObject<QSBSector>(Data.sectorId).AttachedObject;
|
|
|
|
|
|
|
|
|
|
WorldObject.DropItem(worldPos, worldNormal, parent, sector, customDropTarget);
|
2022-03-02 19:46:33 -08:00
|
|
|
|
|
|
|
|
|
var player = QSBPlayerManager.GetPlayer(From);
|
2022-03-23 15:26:42 -07:00
|
|
|
|
player.HeldItem = null;
|
2022-03-02 19:46:33 -08:00
|
|
|
|
player.AnimationSync.VisibleAnimator.SetTrigger("DropHeldItem");
|
2021-02-24 10:45:25 +00:00
|
|
|
|
}
|
2022-03-04 11:37:24 -08:00
|
|
|
|
}
|