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

61 lines
1.4 KiB
C#
Raw Normal View History

using QSB.Messaging;
2021-12-24 00:20:17 +00:00
using QSB.Player.TransformSync;
using QSB.WorldSync;
using QuantumUNET.Transport;
2020-12-11 12:54:19 +00:00
namespace QSB.ConversationSync.Messages
2020-12-11 12:54:19 +00:00
{
2021-12-24 00:20:17 +00:00
public class DialogueConditionMessage : QSBMessage
2020-12-11 12:54:19 +00:00
{
static DialogueConditionMessage() => GlobalMessenger<string, bool>.AddListener(OWEvents.DialogueConditionChanged, Handler);
2020-12-11 12:54:19 +00:00
2021-12-24 00:20:17 +00:00
private static void Handler(string name, bool state)
2020-12-11 12:54:19 +00:00
{
2021-12-24 06:40:37 +00:00
if (PlayerTransformSync.LocalInstance)
2021-12-24 00:20:17 +00:00
{
new DialogueConditionMessage(name, state).Send();
}
}
private string ConditionName;
private bool ConditionState;
public DialogueConditionMessage(string name, bool state)
{
ConditionName = name;
ConditionState = state;
2020-12-11 12:54:19 +00:00
}
2020-12-23 12:58:45 +00:00
public override void Serialize(QNetworkWriter writer)
2020-12-11 12:54:19 +00:00
{
base.Serialize(writer);
writer.Write(ConditionName);
writer.Write(ConditionState);
}
2021-12-24 00:20:17 +00:00
public override void Deserialize(QNetworkReader reader)
{
base.Deserialize(reader);
ConditionName = reader.ReadString();
ConditionState = reader.ReadBoolean();
}
public override void OnReceiveRemote()
{
if (QSBCore.IsHost)
{
QSBWorldSync.SetDialogueCondition(ConditionName, ConditionState);
}
DialogueConditionManager.SharedInstance.SetConditionState(ConditionName, ConditionState);
}
public override void OnReceiveLocal()
{
if (QSBCore.IsHost)
{
QSBWorldSync.SetDialogueCondition(ConditionName, ConditionState);
}
}
2020-12-11 12:54:19 +00:00
}
2021-12-24 00:20:17 +00:00
}