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