48 lines
1.5 KiB
C#
Raw Normal View History

2021-02-25 21:24:10 +00:00
using QSB.Events;
using QSB.ItemSync.WorldObjects;
using QSB.Player;
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-02-25 22:45:32 +00:00
public override EventType Type => EventType.SocketItem;
2021-02-25 21:24:10 +00:00
public override void SetupListener()
=> GlobalMessenger<int, int, SocketEventType>.AddListener(EventNames.QSBSocketItem, Handler);
2021-02-25 21:24:10 +00:00
public override void CloseListener()
=> GlobalMessenger<int, int, SocketEventType>.RemoveListener(EventNames.QSBSocketItem, Handler);
2021-02-25 21:24:10 +00:00
private void Handler(int socketId, int itemId, SocketEventType type)
=> SendEvent(CreateMessage(socketId, itemId, type));
2021-02-25 21:24:10 +00:00
private SocketItemMessage CreateMessage(int socketId, int itemId, SocketEventType type) => new SocketItemMessage
2021-02-25 21:24:10 +00:00
{
AboutId = QSBPlayerManager.LocalPlayerId,
SocketId = socketId,
ItemId = itemId,
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);
switch (message.SocketType)
2021-02-25 22:45:32 +00:00
{
case SocketEventType.Socket:
socketWorldObject.PlaceIntoSocket(itemWorldObject);
return;
case SocketEventType.StartUnsocket:
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
}
}