61 lines
1.6 KiB
C#
Raw Normal View History

using QSB.ItemSync.WorldObjects.Items;
2021-12-25 22:35:32 -08: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-02 19:46:33 -08:00
namespace QSB.ItemSync.Messages;
2023-07-28 19:30:57 +01:00
public class SocketItemMessage : QSBWorldObjectMessage<IQSBItem, (SocketMessageType Type, int SocketId)>
2021-02-25 21:24:10 +00:00
{
public SocketItemMessage(SocketMessageType type, OWItemSocket socket) : base((
2022-03-23 15:26:42 -07:00
type,
socket ? socket.GetWorldObject<QSBItemSocket>().ObjectId : -1
2022-03-23 15:26:42 -07:00
)) { }
2022-01-26 13:12:22 +00:00
2022-03-02 19:46:33 -08:00
public override void OnReceiveRemote()
{
switch (Data.Type)
{
case SocketMessageType.Socket:
2022-03-23 15:26:42 -07:00
{
var qsbItemSocket = Data.SocketId.GetWorldObject<QSBItemSocket>();
2022-03-02 19:46:33 -08:00
qsbItemSocket.PlaceIntoSocket(WorldObject);
WorldObject.ItemState.HasBeenInteractedWith = true;
WorldObject.ItemState.State = ItemStateType.Socketed;
WorldObject.ItemState.Socket = qsbItemSocket.AttachedObject;
2022-03-02 19:46:33 -08:00
2022-03-23 15:26:42 -07:00
var player = QSBPlayerManager.GetPlayer(From);
player.HeldItem = null;
player.AnimationSync.VisibleAnimator.SetTrigger("DropHeldItem");
2021-12-25 22:35:32 -08:00
return;
2022-03-02 19:46:33 -08:00
}
2022-03-23 15:26:42 -07:00
case SocketMessageType.StartUnsocket:
{
var qsbItemSocket = Data.SocketId.GetWorldObject<QSBItemSocket>();
2022-03-23 15:26:42 -07:00
if (!qsbItemSocket.IsSocketOccupied())
{
DebugLog.ToConsole($"Warning - Trying to start unsocket on socket that is unoccupied! Socket:{qsbItemSocket.Name}");
return;
}
WorldObject.StoreLocation();
2022-03-23 15:26:42 -07:00
var player = QSBPlayerManager.GetPlayer(From);
player.HeldItem = WorldObject;
2022-03-23 21:44:21 -07:00
qsbItemSocket.RemoveFromSocket();
2022-03-23 15:26:42 -07:00
return;
}
2022-03-02 19:46:33 -08:00
case SocketMessageType.CompleteUnsocket:
2022-03-23 15:26:42 -07:00
{
WorldObject.OnCompleteUnsocket();
2022-03-23 15:26:42 -07:00
return;
}
2021-02-25 21:24:10 +00:00
}
}
2022-03-23 15:26:42 -07:00
}