2022-01-26 07:16:03 +00:00
|
|
|
|
using Mirror;
|
|
|
|
|
using QSB.ConversationSync.WorldObjects;
|
|
|
|
|
using QSB.Messaging;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
namespace QSB.ConversationSync.Messages;
|
|
|
|
|
|
|
|
|
|
internal class RemoteDialogueInitialStateMessage : QSBWorldObjectMessage<QSBRemoteDialogueTrigger>
|
2022-01-26 07:16:03 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
private bool _inRemoteDialogue;
|
|
|
|
|
private bool[] _activatedDialogues;
|
|
|
|
|
private int _dialogueIndex;
|
|
|
|
|
private bool _colliderEnabled;
|
2022-01-26 07:16:03 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public RemoteDialogueInitialStateMessage(RemoteDialogueTrigger trigger)
|
|
|
|
|
{
|
|
|
|
|
_inRemoteDialogue = trigger._inRemoteDialogue;
|
|
|
|
|
_activatedDialogues = trigger._activatedDialogues;
|
|
|
|
|
_dialogueIndex = trigger._listDialogues
|
|
|
|
|
.IndexOf(x => x.dialogue == trigger._activeRemoteDialogue);
|
|
|
|
|
_colliderEnabled = trigger._collider.enabled;
|
|
|
|
|
}
|
2022-01-26 07:16:03 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public override void Serialize(NetworkWriter writer)
|
|
|
|
|
{
|
|
|
|
|
base.Serialize(writer);
|
|
|
|
|
writer.Write(_inRemoteDialogue);
|
|
|
|
|
writer.Write(_activatedDialogues);
|
|
|
|
|
writer.Write(_dialogueIndex);
|
|
|
|
|
writer.Write(_colliderEnabled);
|
|
|
|
|
}
|
2022-01-26 07:16:03 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public override void Deserialize(NetworkReader reader)
|
|
|
|
|
{
|
|
|
|
|
base.Deserialize(reader);
|
|
|
|
|
_inRemoteDialogue = reader.Read<bool>();
|
|
|
|
|
_activatedDialogues = reader.Read<bool[]>();
|
|
|
|
|
_dialogueIndex = reader.Read<int>();
|
|
|
|
|
_colliderEnabled = reader.Read<bool>();
|
|
|
|
|
}
|
2022-02-27 12:40:44 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public override void OnReceiveRemote()
|
|
|
|
|
{
|
|
|
|
|
var trigger = WorldObject.AttachedObject;
|
|
|
|
|
trigger._activatedDialogues = _activatedDialogues;
|
|
|
|
|
trigger._inRemoteDialogue = _inRemoteDialogue;
|
|
|
|
|
trigger._activeRemoteDialogue = trigger._listDialogues.ElementAtOrDefault(_dialogueIndex).dialogue;
|
|
|
|
|
trigger._collider.enabled = _colliderEnabled;
|
2022-01-26 07:16:03 +00:00
|
|
|
|
}
|
2022-02-25 06:04:54 +00:00
|
|
|
|
}
|