2021-02-25 22:45:32 +00:00
|
|
|
|
using QSB.Events;
|
2021-11-01 15:49:00 +00:00
|
|
|
|
using QSB.ItemSync.WorldObjects.Items;
|
2021-02-25 22:45:32 +00:00
|
|
|
|
using QSB.Player;
|
|
|
|
|
using QSB.WorldSync;
|
|
|
|
|
using QSB.WorldSync.Events;
|
|
|
|
|
|
|
|
|
|
namespace QSB.ItemSync.Events
|
|
|
|
|
{
|
2021-02-25 22:46:31 +00:00
|
|
|
|
internal class MoveToCarryEvent : QSBEvent<WorldObjectMessage>
|
2021-02-25 22:45:32 +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 22:45:32 +00:00
|
|
|
|
public override void SetupListener()
|
|
|
|
|
=> GlobalMessenger<int>.AddListener(EventNames.QSBMoveToCarry, Handler);
|
|
|
|
|
|
|
|
|
|
public override void CloseListener()
|
|
|
|
|
=> GlobalMessenger<int>.RemoveListener(EventNames.QSBMoveToCarry, Handler);
|
|
|
|
|
|
|
|
|
|
private void Handler(int itemId)
|
|
|
|
|
=> SendEvent(CreateMessage(itemId));
|
|
|
|
|
|
2021-11-20 19:49:50 +00:00
|
|
|
|
private WorldObjectMessage CreateMessage(int itemid) => new()
|
2021-02-25 22:45:32 +00:00
|
|
|
|
{
|
|
|
|
|
AboutId = QSBPlayerManager.LocalPlayerId,
|
|
|
|
|
ObjectId = itemid
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public override void OnReceiveRemote(bool server, WorldObjectMessage message)
|
|
|
|
|
{
|
2021-02-26 10:23:08 +00:00
|
|
|
|
var player = QSBPlayerManager.GetPlayer(message.AboutId);
|
2021-02-25 22:45:32 +00:00
|
|
|
|
var itemObject = QSBWorldSync.GetWorldFromId<IQSBOWItem>(message.ObjectId);
|
2021-02-26 10:23:08 +00:00
|
|
|
|
var itemType = itemObject.GetItemType();
|
2021-10-30 16:14:38 +01:00
|
|
|
|
|
|
|
|
|
player.HeldItem = itemObject;
|
2021-11-20 19:49:50 +00:00
|
|
|
|
var itemSocket = itemType switch
|
2021-02-26 10:23:08 +00:00
|
|
|
|
{
|
2021-11-20 19:49:50 +00:00
|
|
|
|
ItemType.Scroll => player.ScrollSocket,
|
|
|
|
|
ItemType.SharedStone => player.SharedStoneSocket,
|
|
|
|
|
ItemType.WarpCore => ((QSBWarpCoreItem)itemObject).IsVesselCoreType()
|
|
|
|
|
? player.VesselCoreSocket
|
|
|
|
|
: player.WarpCoreSocket,
|
|
|
|
|
ItemType.Lantern => player.SimpleLanternSocket,
|
|
|
|
|
ItemType.DreamLantern => player.DreamLanternSocket,
|
|
|
|
|
ItemType.SlideReel => player.SlideReelSocket,
|
|
|
|
|
ItemType.VisionTorch => player.VisionTorchSocket,
|
|
|
|
|
_ => player.ItemSocket,
|
|
|
|
|
};
|
2021-03-23 13:18:29 +00:00
|
|
|
|
itemObject.PickUpItem(itemSocket, message.AboutId);
|
2021-02-25 22:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|