mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-09 12:54:51 +00:00
65 lines
1.7 KiB
C#
65 lines
1.7 KiB
C#
using QSB.ItemSync.WorldObjects.Items;
|
|
using QSB.ItemSync.WorldObjects.Sockets;
|
|
using QSB.Messaging;
|
|
using QSB.Player;
|
|
using QSB.Utility;
|
|
using QSB.WorldSync;
|
|
|
|
namespace QSB.ItemSync.Messages;
|
|
|
|
internal class SocketItemMessage : QSBMessage<(SocketMessageType Type, int SocketId, int ItemId)>
|
|
{
|
|
public SocketItemMessage(SocketMessageType type, OWItemSocket socket, OWItem item) : base((
|
|
type,
|
|
socket ? socket.GetWorldObject<QSBItemSocket>().ObjectId : -1,
|
|
item ? item.GetWorldObject<IQSBItem>().ObjectId : -1
|
|
)) { }
|
|
|
|
public override bool ShouldReceive => QSBWorldSync.AllObjectsReady;
|
|
|
|
public override void OnReceiveRemote()
|
|
{
|
|
switch (Data.Type)
|
|
{
|
|
case SocketMessageType.Socket:
|
|
{
|
|
var qsbItemSocket = Data.SocketId.GetWorldObject<QSBItemSocket>();
|
|
var qsbItem = Data.ItemId.GetWorldObject<IQSBItem>();
|
|
|
|
qsbItemSocket.PlaceIntoSocket(qsbItem);
|
|
|
|
var player = QSBPlayerManager.GetPlayer(From);
|
|
player.HeldItem = null;
|
|
player.AnimationSync.VisibleAnimator.SetTrigger("DropHeldItem");
|
|
return;
|
|
}
|
|
case SocketMessageType.StartUnsocket:
|
|
{
|
|
var qsbItemSocket = Data.SocketId.GetWorldObject<QSBItemSocket>();
|
|
var qsbItem = Data.ItemId.GetWorldObject<IQSBItem>();
|
|
|
|
if (!qsbItemSocket.IsSocketOccupied())
|
|
{
|
|
DebugLog.ToConsole($"Warning - Trying to start unsocket on socket that is unoccupied! Socket:{qsbItemSocket.Name}");
|
|
return;
|
|
}
|
|
|
|
qsbItem.StoreLocation();
|
|
|
|
var player = QSBPlayerManager.GetPlayer(From);
|
|
player.HeldItem = qsbItem;
|
|
|
|
qsbItemSocket.RemoveFromSocket();
|
|
return;
|
|
}
|
|
case SocketMessageType.CompleteUnsocket:
|
|
{
|
|
var qsbItem = Data.ItemId.GetWorldObject<IQSBItem>();
|
|
|
|
qsbItem.OnCompleteUnsocket();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|