76 lines
1.9 KiB
C#
Raw Normal View History

using Mirror;
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
namespace QSB.ItemSync.Messages
2021-02-25 21:24:10 +00:00
{
internal class SocketItemMessage : QSBMessage<SocketMessageType>
{
private int SocketId;
private int ItemId;
2021-02-25 21:24:10 +00:00
public SocketItemMessage(SocketMessageType type, int socketId = -1, int itemId = -1)
{
Value = type;
SocketId = socketId;
ItemId = itemId;
}
2021-12-25 22:35:32 -08:00
public override void Serialize(NetworkWriter writer)
{
base.Serialize(writer);
writer.Write(SocketId);
writer.Write(ItemId);
}
2021-12-25 22:35:32 -08:00
public override void Deserialize(NetworkReader reader)
{
base.Deserialize(reader);
SocketId = reader.Read<int>();
ItemId = reader.Read<int>();
}
2021-12-25 22:35:32 -08:00
public override bool ShouldReceive => QSBWorldSync.AllObjectsReady;
2022-01-26 13:12:22 +00:00
public override void OnReceiveRemote()
{
QSBItemSocket socketWorldObject;
IQSBItem itemWorldObject;
var player = QSBPlayerManager.GetPlayer(From);
player.HeldItem = null;
2022-01-26 13:12:22 +00:00
DebugLog.DebugWrite("DROP HELD ITEM");
player.AnimationSync.VisibleAnimator.SetTrigger("DropHeldItem");
2021-12-25 22:35:32 -08:00
switch (Value)
{
case SocketMessageType.Socket:
socketWorldObject = SocketId.GetWorldObject<QSBItemSocket>();
itemWorldObject = ItemId.GetWorldObject<IQSBItem>();
socketWorldObject.PlaceIntoSocket(itemWorldObject);
2021-12-25 22:35:32 -08:00
return;
case SocketMessageType.StartUnsocket:
socketWorldObject = SocketId.GetWorldObject<QSBItemSocket>();
if (!socketWorldObject.IsSocketOccupied())
{
DebugLog.ToConsole($"Warning - Trying to start unsocket on socket that is unoccupied! Socket:{socketWorldObject.Name}");
return;
}
2021-12-25 22:35:32 -08:00
socketWorldObject.RemoveFromSocket();
return;
case SocketMessageType.CompleteUnsocket:
itemWorldObject = ItemId.GetWorldObject<IQSBItem>();
2021-12-25 22:35:32 -08:00
itemWorldObject.OnCompleteUnsocket();
return;
}
2021-02-25 21:24:10 +00:00
}
}
}