45 lines
1.3 KiB
C#
Raw Normal View History

2022-05-13 22:38:06 +01:00
using QSB.ConversationSync.WorldObjects;
using QSB.Messaging;
2021-12-25 16:29:00 -08:00
using QSB.Player;
using QSB.WorldSync;
using System.Text.RegularExpressions;
2021-12-25 22:53:36 -08:00
using UnityEngine;
2020-09-22 21:11:29 +01:00
2022-03-02 19:46:33 -08:00
namespace QSB.ConversationSync.Messages;
public class ConversationMessage : QSBMessage<(ConversationType Type, int Id, string Message)>
2020-09-22 21:11:29 +01:00
{
2022-03-10 17:57:50 -08:00
public ConversationMessage(ConversationType type, int id, string message = "") : base((type, id, message)) { }
2022-03-02 19:46:33 -08:00
public override bool ShouldReceive => QSBWorldSync.AllObjectsReady;
2021-12-25 16:29:00 -08:00
2022-03-02 19:46:33 -08:00
public override void OnReceiveRemote()
{
switch (Data.Type)
{
2022-03-02 19:46:33 -08:00
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;
2021-12-25 16:29:00 -08:00
2022-03-02 19:46:33 -08:00
case ConversationType.Player:
ConversationManager.Instance.DisplayPlayerConversationBox((uint)Data.Id, Data.Message);
break;
2022-03-02 19:46:33 -08:00
case ConversationType.CloseCharacter:
if (Data.Id == -1)
{
break;
2022-03-02 19:46:33 -08:00
}
2022-05-13 22:38:06 +01:00
var tree = Data.Id.GetWorldObject<QSBCharacterDialogueTree>().AttachedObject;
2022-03-02 19:46:33 -08:00
Object.Destroy(ConversationManager.Instance.BoxMappings[tree]);
break;
case ConversationType.ClosePlayer:
Object.Destroy(QSBPlayerManager.GetPlayer((uint)Data.Id).CurrentDialogueBox);
break;
2021-12-25 16:29:00 -08:00
}
2020-12-02 21:23:01 +00:00
}
2022-03-02 19:46:33 -08:00
}