quantum-space-buddies/QSB/ItemSync/Events/MoveToCarryEvent.cs

54 lines
1.4 KiB
C#
Raw Normal View History

2021-02-25 22:45:32 +00:00
using QSB.Events;
using QSB.ItemSync.WorldObjects;
using QSB.Player;
using QSB.WorldSync;
using QSB.WorldSync.Events;
2021-02-26 10:23:08 +00:00
using UnityEngine;
2021-02-25 22:45:32 +00:00
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-02-26 10:23:08 +00:00
public override QSB.Events.EventType Type => QSB.Events.EventType.MoveToCarry;
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));
private WorldObjectMessage CreateMessage(int itemid) => new WorldObjectMessage
{
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();
Transform itemSocket = null;
switch (itemType)
{
case ItemType.Scroll:
itemSocket = player.ScrollSocket;
break;
case ItemType.WarpCore:
break;
case ItemType.SharedStone:
itemSocket = player.SharedStoneSocket;
break;
default:
itemSocket = player.ItemSocket;
break;
}
itemObject.PickUpItem(itemSocket);
2021-02-25 22:45:32 +00:00
}
}
}