2022-01-14 07:38:45 +00:00
|
|
|
|
using Mirror;
|
|
|
|
|
using QSB.Messaging;
|
2021-12-23 04:45:25 +00:00
|
|
|
|
using QSB.QuantumSync.WorldObjects;
|
|
|
|
|
using QSB.WorldSync;
|
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
namespace QSB.Player.Messages;
|
|
|
|
|
|
|
|
|
|
// almost a world object message, but supports null (-1) as well
|
|
|
|
|
internal class PlayerEntangledMessage : QSBMessage<int>
|
2021-12-23 04:45:25 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public PlayerEntangledMessage(int objectId) => Data = objectId;
|
2021-12-23 04:45:25 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public override bool ShouldReceive => QSBWorldSync.AllObjectsReady;
|
2021-12-23 04:45:25 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public override void OnReceiveLocal()
|
|
|
|
|
{
|
|
|
|
|
var player = QSBPlayerManager.LocalPlayer;
|
|
|
|
|
if (Data == -1)
|
2021-12-23 04:45:25 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
player.EntangledObject = null;
|
|
|
|
|
return;
|
2021-12-23 04:45:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
var quantumObject = Data.GetWorldObject<IQSBQuantumObject>();
|
|
|
|
|
player.EntangledObject = quantumObject;
|
|
|
|
|
}
|
2021-12-23 04:45:25 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public override void OnReceiveRemote()
|
|
|
|
|
{
|
|
|
|
|
var player = QSBPlayerManager.GetPlayer(From);
|
|
|
|
|
if (Data == -1)
|
2022-02-27 12:40:44 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
player.EntangledObject = null;
|
|
|
|
|
return;
|
2022-02-27 12:40:44 +00:00
|
|
|
|
}
|
2022-02-25 06:04:54 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
var quantumObject = Data.GetWorldObject<IQSBQuantumObject>();
|
|
|
|
|
player.EntangledObject = quantumObject;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Serialize(NetworkWriter writer)
|
|
|
|
|
{
|
|
|
|
|
base.Serialize(writer);
|
|
|
|
|
writer.Write(Data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Deserialize(NetworkReader reader)
|
|
|
|
|
{
|
|
|
|
|
base.Deserialize(reader);
|
|
|
|
|
Data = reader.Read<int>();
|
2021-12-23 04:45:25 +00:00
|
|
|
|
}
|
2022-02-25 06:04:54 +00:00
|
|
|
|
}
|