quantum-space-buddies/QSB/ConversationSync/Messages/ConversationMessage.cs

68 lines
1.6 KiB
C#
Raw Normal View History

2021-12-26 00:29:00 +00:00
using QSB.Messaging;
using QSB.Player;
using QSB.WorldSync;
using QuantumUNET.Transport;
2021-12-26 00:29:00 +00:00
using System.Text.RegularExpressions;
2021-12-26 06:53:36 +00:00
using UnityEngine;
2020-09-22 20:11:29 +00:00
namespace QSB.ConversationSync.Messages
2020-09-22 20:11:29 +00:00
{
2021-12-26 00:29:00 +00:00
public class ConversationMessage : QSBEnumMessage<ConversationType>
2020-12-02 21:23:01 +00:00
{
2021-12-26 00:29:00 +00:00
private int Id;
private string Message;
2020-09-22 20:11:29 +00:00
2021-12-26 06:12:21 +00:00
public ConversationMessage(ConversationType type, int id, string message = "")
2020-12-02 21:23:01 +00:00
{
Value = type;
2021-12-26 00:29:00 +00:00
Id = id;
2021-12-26 06:12:21 +00:00
Message = message;
2020-12-02 21:23:01 +00:00
}
2020-09-22 20:11:29 +00:00
2020-12-23 12:58:45 +00:00
public override void Serialize(QNetworkWriter writer)
2020-12-02 21:23:01 +00:00
{
base.Serialize(writer);
2021-12-26 00:29:00 +00:00
writer.Write(Id);
2021-12-26 06:12:21 +00:00
writer.Write(Message);
2020-12-02 21:23:01 +00:00
}
2021-12-26 00:29:00 +00:00
public override void Deserialize(QNetworkReader reader)
{
base.Deserialize(reader);
Id = reader.ReadInt32();
2021-12-26 06:12:21 +00:00
Message = reader.ReadString();
2021-12-26 00:29:00 +00:00
}
public override bool ShouldReceive => WorldObjectManager.AllObjectsReady;
public override void OnReceiveRemote()
{
switch (Value)
{
case ConversationType.Character:
var translated = TextTranslation.Translate(Message).Trim();
translated = Regex.Replace(translated, @"<[Pp]ause=?\d*\.?\d*\s?\/?>", "");
ConversationManager.Instance.DisplayCharacterConversationBox(Id, translated);
break;
case ConversationType.Player:
ConversationManager.Instance.DisplayPlayerConversationBox((uint)Id, Message);
break;
case ConversationType.CloseCharacter:
if (Id == -1)
{
break;
}
var tree = QSBWorldSync.OldDialogueTrees[Id];
2021-12-26 06:53:36 +00:00
Object.Destroy(ConversationManager.Instance.BoxMappings[tree]);
2021-12-26 00:29:00 +00:00
break;
case ConversationType.ClosePlayer:
2021-12-26 06:53:36 +00:00
Object.Destroy(QSBPlayerManager.GetPlayer((uint)Id).CurrentDialogueBox);
2021-12-26 00:29:00 +00:00
break;
}
}
2020-12-02 21:23:01 +00:00
}
2020-12-03 08:28:05 +00:00
}