51 lines
2.1 KiB
C#
Raw Normal View History

2020-11-03 21:42:14 +00:00
using QSB.EventsCore;
2020-11-03 21:33:48 +00:00
using QSB.Player;
2020-10-24 11:17:52 +01:00
using QSB.WorldSync;
2020-09-22 21:11:29 +01:00
2020-11-03 17:56:48 +00:00
namespace QSB.ConversationSync.Events
2020-09-22 21:11:29 +01:00
{
2020-09-29 20:42:45 +02:00
public class ConversationEvent : QSBEvent<ConversationMessage>
2020-09-22 21:11:29 +01:00
{
public override EventType Type => EventType.Conversation;
public override void SetupListener() => GlobalMessenger<uint, string, ConversationType>.AddListener(EventNames.QSBConversation, Handler);
2020-09-22 21:11:29 +01:00
public override void CloseListener() => GlobalMessenger<uint, string, ConversationType>.RemoveListener(EventNames.QSBConversation, Handler);
2020-09-22 21:11:29 +01:00
private void Handler(uint id, string message, ConversationType type) => SendEvent(CreateMessage(id, message, type));
2020-09-22 21:11:29 +01:00
private ConversationMessage CreateMessage(uint id, string message, ConversationType type) => new ConversationMessage
2020-09-22 21:11:29 +01:00
{
AboutId = LocalPlayerId,
ObjectId = (int)id,
2020-09-22 21:11:29 +01:00
Type = type,
Message = message
};
2020-09-22 21:39:53 +01:00
public override void OnReceiveRemote(ConversationMessage message)
{
switch (message.Type)
{
case ConversationType.Character:
var translated = TextTranslation.Translate(message.Message).Trim();
2020-10-23 23:08:48 +01:00
ConversationManager.Instance.DisplayCharacterConversationBox(message.ObjectId, translated);
break;
case ConversationType.Player:
ConversationManager.Instance.DisplayPlayerConversationBox((uint)message.ObjectId, message.Message);
break;
2020-10-24 15:31:20 +01:00
case ConversationType.CloseCharacter:
2020-10-24 11:20:45 +01:00
if (message.ObjectId == -1)
{
break;
}
2020-10-25 15:19:23 +00:00
var tree = WorldRegistry.OldDialogueTrees[message.ObjectId];
UnityEngine.Object.Destroy(ConversationManager.Instance.BoxMappings[tree]);
2020-10-23 23:08:48 +01:00
break;
2020-10-24 15:31:20 +01:00
case ConversationType.ClosePlayer:
2020-11-03 21:18:40 +00:00
UnityEngine.Object.Destroy(QSBPlayerManager.GetPlayer((uint)message.ObjectId).CurrentDialogueBox);
2020-10-23 23:08:48 +01:00
break;
}
2020-09-22 21:39:53 +01:00
}
2020-09-22 21:11:29 +01:00
}
}