quantum-space-buddies/QSB/QuantumSync/Messages/SocketStateChangeMessage.cs

45 lines
1.1 KiB
C#
Raw Normal View History

using Mirror;
using OWML.Common;
2021-12-25 22:04:46 -08:00
using QSB.Messaging;
using QSB.QuantumSync.WorldObjects;
using QSB.Utility;
2020-12-22 21:39:53 +00:00
using UnityEngine;
2022-03-02 19:46:33 -08:00
namespace QSB.QuantumSync.Messages;
internal class SocketStateChangeMessage : QSBWorldObjectMessage<QSBSocketedQuantumObject>
2020-12-22 21:39:53 +00:00
{
2022-03-02 19:46:33 -08:00
private int SocketId;
private Quaternion LocalRotation;
public SocketStateChangeMessage(int socketId, Quaternion localRotation)
2020-12-22 21:39:53 +00:00
{
2022-03-02 19:46:33 -08:00
SocketId = socketId;
LocalRotation = localRotation;
}
2020-12-22 21:39:53 +00:00
2022-03-02 19:46:33 -08:00
public override void Serialize(NetworkWriter writer)
{
base.Serialize(writer);
writer.Write(SocketId);
writer.Write(LocalRotation);
}
2020-12-22 21:39:53 +00:00
2022-03-02 19:46:33 -08:00
public override void Deserialize(NetworkReader reader)
{
base.Deserialize(reader);
SocketId = reader.Read<int>();
LocalRotation = reader.ReadQuaternion();
}
2021-12-25 22:04:46 -08:00
2022-03-02 19:46:33 -08:00
public override void OnReceiveRemote()
{
if (WorldObject.ControllingPlayer != From)
2021-12-25 22:04:46 -08:00
{
2022-03-02 19:46:33 -08:00
DebugLog.ToConsole($"Error - Got SocketStateChangeEvent for {WorldObject.Name} from {From}, but it's currently controlled by {WorldObject.ControllingPlayer}!", MessageType.Error);
return;
2021-12-25 22:04:46 -08:00
}
2022-03-02 19:46:33 -08:00
WorldObject.MoveToSocket(From, SocketId, LocalRotation);
2020-12-22 21:39:53 +00:00
}
2021-12-25 22:04:46 -08:00
}