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

58 lines
1.1 KiB
C#
Raw Normal View History

using QSB.Messaging;
2021-12-24 00:20:17 +00:00
using QSB.WorldSync;
2020-12-11 12:54:19 +00:00
namespace QSB.ConversationSync.Messages
2020-12-11 12:54:19 +00:00
{
public class DialogueConditionMessage : QSBMessage<(string Name, bool State)>
2020-12-11 12:54:19 +00:00
{
public DialogueConditionMessage(string name, bool state)
{
Data.Name = name;
Data.State = state;
}
public override void OnReceiveRemote()
2021-12-24 00:20:17 +00:00
{
if (QSBCore.IsHost)
2021-12-24 00:20:17 +00:00
{
QSBWorldSync.SetDialogueCondition(Data.Name, Data.State);
2021-12-24 00:20:17 +00:00
}
var sharedInstance = DialogueConditionManager.SharedInstance;
var flag = true;
if (sharedInstance.ConditionExists(Data.Name))
{
if (sharedInstance._dictConditions[Data.Name] == Data.State)
{
flag = false;
}
sharedInstance._dictConditions[Data.Name] = Data.State;
}
else
{
sharedInstance.AddCondition(Data.Name, Data.State);
}
if (flag)
{
GlobalMessenger<string, bool>.FireEvent("DialogueConditionChanged", Data.Name, Data.State);
}
if (Data.Name == "LAUNCH_CODES_GIVEN")
{
PlayerData.LearnLaunchCodes();
}
2021-12-24 00:20:17 +00:00
}
public override void OnReceiveLocal()
2021-12-24 00:20:17 +00:00
{
if (QSBCore.IsHost)
{
QSBWorldSync.SetDialogueCondition(Data.Name, Data.State);
}
2021-12-24 00:20:17 +00:00
}
2020-12-11 12:54:19 +00:00
}
}