using QSB.Animation.NPC.WorldObjects; using QSB.Events; using QSB.WorldSync; namespace QSB.Animation.NPC.Messages { internal class NpcAnimationEvent : QSBEvent { public override bool RequireWorldObjectsReady => true; public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBNpcAnimEvent, Handler); public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBNpcAnimEvent, Handler); private void Handler(AnimationEvent animEvent, int index) => SendEvent(CreateMessage(animEvent, index)); private NpcAnimationMessage CreateMessage(AnimationEvent animEvent, int index) => new() { AboutId = LocalPlayerId, AnimationEvent = animEvent, AnimControllerIndex = index }; public override void OnReceiveRemote(bool server, NpcAnimationMessage message) { var qsbObj = QSBWorldSync.GetWorldFromId(message.AnimControllerIndex); switch (message.AnimationEvent) { case AnimationEvent.StartConversation: qsbObj.StartConversation(); break; case AnimationEvent.EndConversation: qsbObj.EndConversation(); break; } } } }