2021-02-25 21:24:10 +00:00
|
|
|
|
using QSB.Events;
|
2021-11-01 15:49:00 +00:00
|
|
|
|
using QSB.ItemSync.WorldObjects.Items;
|
|
|
|
|
using QSB.ItemSync.WorldObjects.Sockets;
|
2021-02-25 21:24:10 +00:00
|
|
|
|
using QSB.Player;
|
2021-03-26 20:56:57 +00:00
|
|
|
|
using QSB.Utility;
|
2021-02-25 21:24:10 +00:00
|
|
|
|
using QSB.WorldSync;
|
|
|
|
|
|
|
|
|
|
namespace QSB.ItemSync.Events
|
2021-02-23 14:42:18 +00:00
|
|
|
|
{
|
2021-02-25 21:24:10 +00:00
|
|
|
|
internal class SocketItemEvent : QSBEvent<SocketItemMessage>
|
2021-02-23 14:42:18 +00:00
|
|
|
|
{
|
2021-12-05 11:03:09 +00:00
|
|
|
|
public override bool RequireWorldObjectsReady => true;
|
2021-12-04 16:39:37 +00:00
|
|
|
|
|
2021-02-25 21:24:10 +00:00
|
|
|
|
public override void SetupListener()
|
2021-02-26 12:47:05 +00:00
|
|
|
|
=> GlobalMessenger<int, int, SocketEventType>.AddListener(EventNames.QSBSocketItem, Handler);
|
2021-02-25 21:24:10 +00:00
|
|
|
|
|
|
|
|
|
public override void CloseListener()
|
2021-02-26 12:47:05 +00:00
|
|
|
|
=> GlobalMessenger<int, int, SocketEventType>.RemoveListener(EventNames.QSBSocketItem, Handler);
|
2021-02-25 21:24:10 +00:00
|
|
|
|
|
2021-02-26 12:47:05 +00:00
|
|
|
|
private void Handler(int socketId, int itemId, SocketEventType type)
|
|
|
|
|
=> SendEvent(CreateMessage(socketId, itemId, type));
|
2021-02-25 21:24:10 +00:00
|
|
|
|
|
2021-11-20 19:49:50 +00:00
|
|
|
|
private SocketItemMessage CreateMessage(int socketId, int itemId, SocketEventType type) => new()
|
2021-02-25 21:24:10 +00:00
|
|
|
|
{
|
|
|
|
|
AboutId = QSBPlayerManager.LocalPlayerId,
|
|
|
|
|
SocketId = socketId,
|
|
|
|
|
ItemId = itemId,
|
2021-02-26 12:47:05 +00:00
|
|
|
|
SocketType = type
|
2021-02-25 21:24:10 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public override void OnReceiveRemote(bool server, SocketItemMessage message)
|
|
|
|
|
{
|
|
|
|
|
var socketWorldObject = QSBWorldSync.GetWorldFromId<IQSBOWItemSocket>(message.SocketId);
|
|
|
|
|
var itemWorldObject = QSBWorldSync.GetWorldFromId<IQSBOWItem>(message.ItemId);
|
2021-10-30 15:14:38 +00:00
|
|
|
|
var player = QSBPlayerManager.GetPlayer(message.FromId);
|
|
|
|
|
player.HeldItem = null;
|
2021-02-26 12:47:05 +00:00
|
|
|
|
switch (message.SocketType)
|
2021-02-25 22:45:32 +00:00
|
|
|
|
{
|
2021-02-26 12:47:05 +00:00
|
|
|
|
case SocketEventType.Socket:
|
|
|
|
|
socketWorldObject.PlaceIntoSocket(itemWorldObject);
|
|
|
|
|
return;
|
|
|
|
|
case SocketEventType.StartUnsocket:
|
2021-03-26 20:56:57 +00:00
|
|
|
|
if (!socketWorldObject.IsSocketOccupied())
|
|
|
|
|
{
|
2021-12-11 23:08:56 +00:00
|
|
|
|
DebugLog.ToConsole($"Warning - Trying to start unsocket on socket that is unoccupied! Socket:{socketWorldObject.Name}");
|
2021-03-26 20:56:57 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2021-06-18 21:38:32 +00:00
|
|
|
|
|
2021-02-26 12:47:05 +00:00
|
|
|
|
socketWorldObject.RemoveFromSocket();
|
|
|
|
|
return;
|
|
|
|
|
case SocketEventType.CompleteUnsocket:
|
|
|
|
|
itemWorldObject.OnCompleteUnsocket();
|
|
|
|
|
return;
|
2021-02-25 22:45:32 +00:00
|
|
|
|
}
|
2021-02-25 21:24:10 +00:00
|
|
|
|
}
|
2021-02-23 14:42:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|