using QSB.AuthoritySync; using QSB.Events; using QSB.WorldSync.Events; using QSB.OrbSync.WorldObjects; using QSB.WorldSync; namespace QSB.OrbSync.Events { public class OrbDragEvent : QSBEvent { public override bool RequireWorldObjectsReady => true; public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBOrbDrag, Handler); public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBOrbDrag, Handler); private void Handler(QSBOrb qsbOrb, bool isDragging) => SendEvent(CreateMessage(qsbOrb, isDragging)); private BoolWorldObjectMessage CreateMessage(QSBOrb qsbOrb, bool isDragging) => new() { ObjectId = qsbOrb.ObjectId, State = isDragging }; public override void OnReceiveLocal(bool isHost, BoolWorldObjectMessage message) { var qsbOrb = QSBWorldSync.GetWorldFromId(message.ObjectId); if (message.State && isHost) { qsbOrb.TransformSync.NetIdentity.SetAuthority(message.FromId); } } public override void OnReceiveRemote(bool isHost, BoolWorldObjectMessage message) { var qsbOrb = QSBWorldSync.GetWorldFromId(message.ObjectId); if (message.State && isHost) { qsbOrb.TransformSync.NetIdentity.SetAuthority(message.FromId); } qsbOrb.SetDragging(message.State); } } }