55 lines
1.7 KiB
C#
Raw Normal View History

2021-02-25 21:24:10 +00:00
using QSB.Events;
using QSB.ItemSync.WorldObjects;
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-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:
2021-03-26 20:56:57 +00:00
if (!socketWorldObject.IsSocketOccupied())
{
DebugLog.ToConsole($"Warning - Trying to start unsocket on socket that is unoccupied! Socket:{(socketWorldObject as IWorldObject).Name}");
return;
}
2021-06-18 22:38:32 +01: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
}
}