quantum-space-buddies/QSB/ItemSync/Messages/SocketItemMessage.cs

68 lines
1.9 KiB
C#
Raw Normal View History

using QSB.ItemSync.WorldObjects.Items;
2021-12-26 06:35:32 +00:00
using QSB.ItemSync.WorldObjects.Sockets;
using QSB.Messaging;
using QSB.Player;
using QSB.Utility;
using QSB.WorldSync;
2021-02-25 21:24:10 +00:00
2022-03-03 03:46:33 +00:00
namespace QSB.ItemSync.Messages;
internal class SocketItemMessage : QSBMessage<(SocketMessageType Type, int SocketId, int ItemId)>
2021-02-25 21:24:10 +00:00
{
2022-03-23 22:26:42 +00:00
public SocketItemMessage(SocketMessageType type, OWItemSocket socket, OWItem item) : base((
type,
socket ? socket.GetWorldObject<QSBItemSocket>().ObjectId : -1,
item ? item.GetWorldObject<IQSBItem>().ObjectId : -1
)) { }
2022-01-26 13:12:22 +00:00
2022-03-03 03:46:33 +00:00
public override bool ShouldReceive => QSBWorldSync.AllObjectsReady;
2022-01-26 13:12:22 +00:00
2022-03-03 03:46:33 +00:00
public override void OnReceiveRemote()
{
switch (Data.Type)
{
case SocketMessageType.Socket:
2022-03-23 22:26:42 +00:00
{
var qsbItemSocket = Data.SocketId.GetWorldObject<QSBItemSocket>();
var qsbItem = Data.ItemId.GetWorldObject<IQSBItem>();
2022-03-03 03:46:33 +00:00
2022-03-23 22:26:42 +00:00
qsbItemSocket.PlaceIntoSocket(qsbItem);
qsbItem.ItemState.HasBeenInteractedWith = true;
2022-07-25 12:09:51 +00:00
qsbItem.ItemState.State = ItemStateType.Socketed;
qsbItem.ItemState.Socket = qsbItemSocket.AttachedObject;
2022-03-03 03:46:33 +00:00
2022-03-23 22:26:42 +00:00
var player = QSBPlayerManager.GetPlayer(From);
player.HeldItem = null;
player.AnimationSync.VisibleAnimator.SetTrigger("DropHeldItem");
2021-12-26 06:35:32 +00:00
return;
2022-03-03 03:46:33 +00:00
}
2022-03-23 22:26:42 +00:00
case SocketMessageType.StartUnsocket:
{
var qsbItemSocket = Data.SocketId.GetWorldObject<QSBItemSocket>();
var qsbItem = Data.ItemId.GetWorldObject<IQSBItem>();
2022-03-23 22:26:42 +00:00
if (!qsbItemSocket.IsSocketOccupied())
{
DebugLog.ToConsole($"Warning - Trying to start unsocket on socket that is unoccupied! Socket:{qsbItemSocket.Name}");
return;
}
qsbItem.StoreLocation();
2022-03-23 22:26:42 +00:00
var player = QSBPlayerManager.GetPlayer(From);
player.HeldItem = qsbItem;
2022-03-24 04:44:21 +00:00
qsbItemSocket.RemoveFromSocket();
2022-03-23 22:26:42 +00:00
return;
}
2022-03-03 03:46:33 +00:00
case SocketMessageType.CompleteUnsocket:
2022-03-23 22:26:42 +00:00
{
var qsbItem = Data.ItemId.GetWorldObject<IQSBItem>();
2021-12-26 06:35:32 +00:00
2022-03-23 22:26:42 +00:00
qsbItem.OnCompleteUnsocket();
return;
}
2021-02-25 21:24:10 +00:00
}
}
2022-03-23 22:26:42 +00:00
}