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

52 lines
1.1 KiB
C#
Raw Normal View History

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