using QSB.Events; using QSB.ItemSync.WorldObjects.Items; using QSB.Player; using QSB.Utility; using QSB.WorldSync; using UnityEngine; namespace QSB.ItemSync.Events { internal class DropItemEvent : QSBEvent { public override bool RequireWorldObjectsReady => true; public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBDropItem, Handler); public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBDropItem, Handler); private void Handler(int objectId, Vector3 position, Vector3 normal, Sector sector) => SendEvent(CreateMessage(objectId, position, normal, sector)); private DropItemMessage CreateMessage(int objectId, Vector3 position, Vector3 normal, Sector sector) => new() { ObjectId = objectId, Position = position, Normal = normal, Sector = sector }; public override void OnReceiveRemote(bool server, DropItemMessage message) { var worldObject = QSBWorldSync.GetWorldFromId(message.ObjectId); worldObject.DropItem(message.Position, message.Normal, message.Sector); var player = QSBPlayerManager.GetPlayer(message.FromId); player.HeldItem = worldObject; } } }