73 lines
1.8 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
{
2021-12-25 22:35:32 -08:00
internal class SocketItemMessage : QSBEnumMessage<SocketMessageType>
2021-02-25 21:24:10 +00:00
{
2021-12-25 22:35:32 -08:00
private int SocketId;
private int ItemId;
2021-02-25 21:24:10 +00:00
2021-12-25 22:35:32 -08:00
public SocketItemMessage(SocketMessageType type, int socketId = -1, int itemId = -1)
2021-02-25 21:24:10 +00:00
{
2021-12-25 22:35:32 -08:00
Value = type;
SocketId = socketId;
ItemId = itemId;
2021-02-25 21:24:10 +00:00
}
public override void Serialize(NetworkWriter writer)
2021-02-25 21:24:10 +00:00
{
base.Serialize(writer);
writer.Write(SocketId);
writer.Write(ItemId);
2021-12-25 22:35:32 -08:00
}
public override void Deserialize(NetworkReader reader)
2021-12-25 22:35:32 -08:00
{
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;
2021-12-25 22:35:32 -08:00
public override void OnReceiveRemote()
{
2022-01-25 21:38:38 -08:00
QSBItemSocket socketWorldObject;
2022-01-25 21:48:52 -08:00
QSBItem itemWorldObject;
2021-12-25 22:35:32 -08:00
var player = QSBPlayerManager.GetPlayer(From);
player.HeldItem = null;
switch (Value)
{
case SocketMessageType.Socket:
2022-01-25 21:38:38 -08:00
socketWorldObject = SocketId.GetWorldObject<QSBItemSocket>();
2022-01-25 21:48:52 -08:00
itemWorldObject = ItemId.GetWorldObject<QSBItem>();
2021-12-25 22:35:32 -08:00
socketWorldObject.PlaceIntoSocket(itemWorldObject);
return;
case SocketMessageType.StartUnsocket:
2022-01-25 21:38:38 -08:00
socketWorldObject = SocketId.GetWorldObject<QSBItemSocket>();
2021-12-25 22:35:32 -08:00
if (!socketWorldObject.IsSocketOccupied())
{
DebugLog.ToConsole($"Warning - Trying to start unsocket on socket that is unoccupied! Socket:{socketWorldObject.Name}");
return;
}
socketWorldObject.RemoveFromSocket();
return;
case SocketMessageType.CompleteUnsocket:
2022-01-25 21:48:52 -08:00
itemWorldObject = ItemId.GetWorldObject<QSBItem>();
2021-12-25 22:35:32 -08:00
itemWorldObject.OnCompleteUnsocket();
return;
}
2021-02-25 21:24:10 +00:00
}
}
}