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;
|
|
|
|
|
|
2021-12-23 21:49:47 +00:00
|
|
|
|
namespace QSB.Player.Messages
|
2021-12-23 04:45:25 +00:00
|
|
|
|
{
|
|
|
|
|
// almost a world object message, but supports null (-1) as well
|
2022-01-27 05:00:12 +00:00
|
|
|
|
internal class PlayerEntangledMessage : QSBMessage<int>
|
2021-12-23 04:45:25 +00:00
|
|
|
|
{
|
2022-01-27 05:00:12 +00:00
|
|
|
|
public PlayerEntangledMessage(int objectId) => Value = objectId;
|
2021-12-23 04:45:25 +00:00
|
|
|
|
|
2022-01-18 08:27:32 +00:00
|
|
|
|
public override bool ShouldReceive => QSBWorldSync.AllObjectsReady;
|
2021-12-23 04:45:25 +00:00
|
|
|
|
|
|
|
|
|
public override void OnReceiveLocal()
|
|
|
|
|
{
|
|
|
|
|
var player = QSBPlayerManager.LocalPlayer;
|
2022-01-27 05:00:12 +00:00
|
|
|
|
if (Value == -1)
|
2021-12-23 04:45:25 +00:00
|
|
|
|
{
|
|
|
|
|
player.EntangledObject = null;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-27 05:00:12 +00:00
|
|
|
|
var quantumObject = Value.GetWorldObject<IQSBQuantumObject>();
|
2021-12-23 04:45:25 +00:00
|
|
|
|
player.EntangledObject = quantumObject;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnReceiveRemote()
|
|
|
|
|
{
|
|
|
|
|
var player = QSBPlayerManager.GetPlayer(From);
|
2022-01-27 05:00:12 +00:00
|
|
|
|
if (Value == -1)
|
2021-12-23 04:45:25 +00:00
|
|
|
|
{
|
|
|
|
|
player.EntangledObject = null;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-27 05:00:12 +00:00
|
|
|
|
var quantumObject = Value.GetWorldObject<IQSBQuantumObject>();
|
2021-12-23 04:45:25 +00:00
|
|
|
|
player.EntangledObject = quantumObject;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-14 07:38:45 +00:00
|
|
|
|
public override void Serialize(NetworkWriter writer)
|
2021-12-23 04:45:25 +00:00
|
|
|
|
{
|
|
|
|
|
base.Serialize(writer);
|
2022-01-27 05:00:12 +00:00
|
|
|
|
writer.Write(Value);
|
2021-12-23 04:45:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-14 07:38:45 +00:00
|
|
|
|
public override void Deserialize(NetworkReader reader)
|
2021-12-23 04:45:25 +00:00
|
|
|
|
{
|
|
|
|
|
base.Deserialize(reader);
|
2022-01-27 05:00:12 +00:00
|
|
|
|
Value = reader.Read<int>();
|
2021-12-23 04:45:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|