2022-01-13 23:38:45 -08:00
|
|
|
|
using Mirror;
|
|
|
|
|
using QSB.Messaging;
|
2021-12-22 20:45:25 -08:00
|
|
|
|
using QSB.QuantumSync.WorldObjects;
|
|
|
|
|
using QSB.WorldSync;
|
|
|
|
|
|
2021-12-23 13:49:47 -08:00
|
|
|
|
namespace QSB.Player.Messages
|
2021-12-22 20:45:25 -08:00
|
|
|
|
{
|
|
|
|
|
// almost a world object message, but supports null (-1) as well
|
|
|
|
|
internal class PlayerEntangledMessage : QSBMessage
|
|
|
|
|
{
|
|
|
|
|
private int ObjectId;
|
|
|
|
|
|
|
|
|
|
public PlayerEntangledMessage(int objectId) => ObjectId = objectId;
|
|
|
|
|
|
2022-01-18 00:27:32 -08:00
|
|
|
|
public override bool ShouldReceive => QSBWorldSync.AllObjectsReady;
|
2021-12-22 20:45:25 -08:00
|
|
|
|
|
|
|
|
|
public override void OnReceiveLocal()
|
|
|
|
|
{
|
|
|
|
|
var player = QSBPlayerManager.LocalPlayer;
|
|
|
|
|
if (ObjectId == -1)
|
|
|
|
|
{
|
|
|
|
|
player.EntangledObject = null;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-25 22:37:20 -08:00
|
|
|
|
var quantumObject = ObjectId.GetWorldObject<IQSBQuantumObject>();
|
2021-12-22 20:45:25 -08:00
|
|
|
|
player.EntangledObject = quantumObject;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnReceiveRemote()
|
|
|
|
|
{
|
|
|
|
|
var player = QSBPlayerManager.GetPlayer(From);
|
|
|
|
|
if (ObjectId == -1)
|
|
|
|
|
{
|
|
|
|
|
player.EntangledObject = null;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-25 22:37:20 -08:00
|
|
|
|
var quantumObject = ObjectId.GetWorldObject<IQSBQuantumObject>();
|
2021-12-22 20:45:25 -08:00
|
|
|
|
player.EntangledObject = quantumObject;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-13 23:38:45 -08:00
|
|
|
|
public override void Serialize(NetworkWriter writer)
|
2021-12-22 20:45:25 -08:00
|
|
|
|
{
|
|
|
|
|
base.Serialize(writer);
|
|
|
|
|
writer.Write(ObjectId);
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-13 23:38:45 -08:00
|
|
|
|
public override void Deserialize(NetworkReader reader)
|
2021-12-22 20:45:25 -08:00
|
|
|
|
{
|
|
|
|
|
base.Deserialize(reader);
|
2022-01-13 23:38:45 -08:00
|
|
|
|
ObjectId = reader.Read<int>();
|
2021-12-22 20:45:25 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|