quantum-space-buddies/QSB/ConversationSync/Messages/ConversationMessage.cs
2022-05-13 22:38:06 +01:00

45 lines
1.3 KiB
C#

using QSB.ConversationSync.WorldObjects;
using QSB.Messaging;
using QSB.Player;
using QSB.WorldSync;
using System.Text.RegularExpressions;
using UnityEngine;
namespace QSB.ConversationSync.Messages;
public class ConversationMessage : QSBMessage<(ConversationType Type, int Id, string Message)>
{
public ConversationMessage(ConversationType type, int id, string message = "") : base((type, id, message)) { }
public override bool ShouldReceive => QSBWorldSync.AllObjectsReady;
public override void OnReceiveRemote()
{
switch (Data.Type)
{
case ConversationType.Character:
var translated = TextTranslation.Translate(Data.Message).Trim();
translated = Regex.Replace(translated, @"<[Pp]ause=?\d*\.?\d*\s?\/?>", "");
ConversationManager.Instance.DisplayCharacterConversationBox(Data.Id, translated);
break;
case ConversationType.Player:
ConversationManager.Instance.DisplayPlayerConversationBox((uint)Data.Id, Data.Message);
break;
case ConversationType.CloseCharacter:
if (Data.Id == -1)
{
break;
}
var tree = Data.Id.GetWorldObject<QSBCharacterDialogueTree>().AttachedObject;
Object.Destroy(ConversationManager.Instance.BoxMappings[tree]);
break;
case ConversationType.ClosePlayer:
Object.Destroy(QSBPlayerManager.GetPlayer((uint)Data.Id).CurrentDialogueBox);
break;
}
}
}