using QSB.ConversationSync.WorldObjects; using QSB.Events; using QSB.WorldSync; namespace QSB.ConversationSync.Messages { internal class EnterRemoteDialogueEvent : QSBEvent { public override bool RequireWorldObjectsReady => true; public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBEnterRemoteDialogue, Handler); public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBEnterRemoteDialogue, Handler); private void Handler(QSBRemoteDialogueTrigger remoteTrigger, int activatedIndex, int listIndex) => SendEvent(CreateMessage(remoteTrigger, activatedIndex, listIndex)); private EnterRemoteDialogueMessage CreateMessage(QSBRemoteDialogueTrigger remoteTrigger, int activatedIndex, int listIndex) => new() { AboutId = LocalPlayerId, ObjectId = remoteTrigger.ObjectId, ActivatedDialogueIndex = activatedIndex, ListDialoguesIndex = listIndex }; public override void OnReceiveRemote(bool isHost, EnterRemoteDialogueMessage message) { var qsbObj = QSBWorldSync.GetWorldFromId(message.ObjectId); qsbObj.RemoteEnterDialogue(message.ActivatedDialogueIndex, message.ListDialoguesIndex); } } }