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
|
|
|
|
|
internal class PlayerEntangledMessage : QSBMessage
|
|
|
|
|
{
|
|
|
|
|
private int ObjectId;
|
|
|
|
|
|
|
|
|
|
public PlayerEntangledMessage(int objectId) => ObjectId = objectId;
|
|
|
|
|
|
|
|
|
|
public override bool ShouldReceive => WorldObjectManager.AllObjectsReady;
|
|
|
|
|
|
|
|
|
|
public override void OnReceiveLocal()
|
|
|
|
|
{
|
|
|
|
|
var player = QSBPlayerManager.LocalPlayer;
|
|
|
|
|
if (ObjectId == -1)
|
|
|
|
|
{
|
|
|
|
|
player.EntangledObject = null;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-26 06:37:20 +00:00
|
|
|
|
var quantumObject = ObjectId.GetWorldObject<IQSBQuantumObject>();
|
2021-12-23 04:45:25 +00:00
|
|
|
|
player.EntangledObject = quantumObject;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnReceiveRemote()
|
|
|
|
|
{
|
|
|
|
|
var player = QSBPlayerManager.GetPlayer(From);
|
|
|
|
|
if (ObjectId == -1)
|
|
|
|
|
{
|
|
|
|
|
player.EntangledObject = null;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-26 06:37:20 +00:00
|
|
|
|
var quantumObject = ObjectId.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);
|
|
|
|
|
writer.Write(ObjectId);
|
|
|
|
|
}
|
|
|
|
|
|
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-14 07:38:45 +00:00
|
|
|
|
ObjectId = reader.Read<int>();
|
2021-12-23 04:45:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|