38 lines
1.2 KiB
C#
Raw Normal View History

2021-04-29 18:30:45 +01:00
using QSB.Animation.NPC.WorldObjects;
using QSB.Events;
using QSB.WorldSync;
namespace QSB.Animation.NPC.Events
{
2021-04-29 21:00:02 +01:00
internal class NpcAnimationEvent : QSBEvent<NpcAnimationMessage>
2021-04-29 18:30:45 +01:00
{
public override EventType Type => EventType.NpcAnimEvent;
public override void SetupListener() => GlobalMessenger<AnimationEvent, int>.AddListener(EventNames.QSBNpcAnimEvent, Handler);
public override void CloseListener() => GlobalMessenger<AnimationEvent, int>.RemoveListener(EventNames.QSBNpcAnimEvent, Handler);
private void Handler(AnimationEvent animEvent, int index) => SendEvent(CreateMessage(animEvent, index));
private NpcAnimationMessage CreateMessage(AnimationEvent animEvent, int index) => new NpcAnimationMessage
{
AboutId = LocalPlayerId,
AnimationEvent = animEvent,
AnimControllerIndex = index
};
public override void OnReceiveRemote(bool server, NpcAnimationMessage message)
{
var qsbObj = QSBWorldSync.GetWorldFromId<INpcAnimController>(message.AnimControllerIndex);
switch (message.AnimationEvent)
{
case AnimationEvent.StartConversation:
qsbObj.StartConversation();
break;
case AnimationEvent.EndConversation:
qsbObj.EndConversation();
break;
}
}
}
}