quantum-space-buddies/QSB/ConversationSync/Events/DialogueConditionEvent.cs

40 lines
1.3 KiB
C#
Raw Normal View History

2020-12-14 16:24:52 +00:00
using QSB.Events;
2020-12-11 13:14:58 +00:00
using QSB.WorldSync;
2020-12-11 12:54:19 +00:00
2020-12-18 21:00:22 +00:00
namespace QSB.ConversationSync.Events
2020-12-11 12:54:19 +00:00
{
public class DialogueConditionEvent : QSBEvent<DialogueConditionMessage>
{
public override EventType Type => EventType.DialogueCondition;
public override void SetupListener() => GlobalMessenger<string, bool>.AddListener(EventNames.DialogueCondition, Handler);
public override void CloseListener() => GlobalMessenger<string, bool>.RemoveListener(EventNames.DialogueCondition, Handler);
private void Handler(string name, bool state) => SendEvent(CreateMessage(name, state));
private DialogueConditionMessage CreateMessage(string name, bool state) => new DialogueConditionMessage
{
AboutId = LocalPlayerId,
ConditionName = name,
ConditionState = state
};
2020-12-11 22:42:21 +00:00
public override void OnReceiveLocal(bool server, DialogueConditionMessage message)
{
if (server)
{
QSBWorldSync.SetDialogueCondition(message.ConditionName, message.ConditionState);
}
}
2020-12-11 13:14:58 +00:00
2020-12-11 22:42:21 +00:00
public override void OnReceiveRemote(bool server, DialogueConditionMessage message)
2020-12-11 12:54:19 +00:00
{
2020-12-11 22:42:21 +00:00
if (server)
{
QSBWorldSync.SetDialogueCondition(message.ConditionName, message.ConditionState);
}
2021-06-18 22:38:32 +01:00
2020-12-11 22:42:21 +00:00
DialogueConditionManager.SharedInstance.SetConditionState(message.ConditionName, message.ConditionState);
2020-12-11 12:54:19 +00:00
}
}
}