quantum-space-buddies/QSB/Animation/NPC/Events/NpcAnimationEvent.cs
Mister_Nebula 200e344064 cleanup
2021-04-29 21:00:02 +01:00

38 lines
1.2 KiB
C#

using QSB.Animation.NPC.WorldObjects;
using QSB.Events;
using QSB.WorldSync;
namespace QSB.Animation.NPC.Events
{
internal class NpcAnimationEvent : QSBEvent<NpcAnimationMessage>
{
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;
}
}
}
}