52 lines
1.7 KiB
C#
Raw Normal View History

2020-12-14 16:24:52 +00:00
using QSB.Events;
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-12-02 21:23:01 +00:00
public class ConversationEvent : QSBEvent<ConversationMessage>
{
public override EventType Type => EventType.Conversation;
2020-09-22 21:11:29 +01:00
2020-12-02 21:23:01 +00:00
public override void SetupListener() => GlobalMessenger<uint, string, ConversationType>.AddListener(EventNames.QSBConversation, Handler);
public override void CloseListener() => GlobalMessenger<uint, string, ConversationType>.RemoveListener(EventNames.QSBConversation, Handler);
2020-09-22 21:11:29 +01:00
2020-12-02 21:23:01 +00:00
private void Handler(uint id, string message, ConversationType type) => SendEvent(CreateMessage(id, message, type));
2020-09-22 21:11:29 +01:00
2020-12-02 21:23:01 +00:00
private ConversationMessage CreateMessage(uint id, string message, ConversationType type) => new ConversationMessage
{
AboutId = LocalPlayerId,
ObjectId = (int)id,
Type = type,
Message = message
};
2020-09-22 21:39:53 +01:00
2020-12-11 22:42:21 +00:00
public override void OnReceiveRemote(bool server, ConversationMessage message)
2020-12-02 21:23:01 +00:00
{
switch (message.Type)
{
case ConversationType.Character:
var translated = TextTranslation.Translate(message.Message).Trim();
ConversationManager.Instance.DisplayCharacterConversationBox(message.ObjectId, translated);
break;
2020-12-03 08:28:05 +00:00
2020-12-02 21:23:01 +00:00
case ConversationType.Player:
ConversationManager.Instance.DisplayPlayerConversationBox((uint)message.ObjectId, message.Message);
break;
2020-12-03 08:28:05 +00:00
2020-12-02 21:23:01 +00:00
case ConversationType.CloseCharacter:
if (message.ObjectId == -1)
{
break;
}
2020-12-11 13:14:58 +00:00
var tree = QSBWorldSync.OldDialogueTrees[message.ObjectId];
2020-12-02 21:23:01 +00:00
UnityEngine.Object.Destroy(ConversationManager.Instance.BoxMappings[tree]);
break;
2020-12-03 08:28:05 +00:00
2020-12-02 21:23:01 +00:00
case ConversationType.ClosePlayer:
UnityEngine.Object.Destroy(QSBPlayerManager.GetPlayer((uint)message.ObjectId).CurrentDialogueBox);
break;
}
}
}
2020-12-03 08:28:05 +00:00
}