2021-12-26 06:04:46 +00:00
using OWML.Common ;
using QSB.Messaging ;
using QSB.QuantumSync.WorldObjects ;
using QSB.Utility ;
2020-12-23 10:43:13 +00:00
using QuantumUNET.Transport ;
2021-12-24 00:26:31 +00:00
namespace QSB.QuantumSync.Messages
2020-12-23 10:43:13 +00:00
{
2021-12-26 06:04:46 +00:00
internal class MultiStateChangeMessage : QSBWorldObjectMessage < QSBMultiStateQuantumObject >
2020-12-23 10:43:13 +00:00
{
2021-12-26 06:04:46 +00:00
private int StateIndex ;
public MultiStateChangeMessage ( int stateIndex ) = > StateIndex = stateIndex ;
public override void Serialize ( QNetworkWriter writer )
{
base . Serialize ( writer ) ;
writer . Write ( StateIndex ) ;
}
2020-12-23 10:43:13 +00:00
2020-12-23 12:58:45 +00:00
public override void Deserialize ( QNetworkReader reader )
2020-12-23 10:43:13 +00:00
{
base . Deserialize ( reader ) ;
StateIndex = reader . ReadInt32 ( ) ;
}
2021-12-26 06:04:46 +00:00
public override void OnReceiveRemote ( )
{
if ( WorldObject . ControllingPlayer ! = From )
{
DebugLog . ToConsole ( $"Error - Got MultiStateChangeEvent for {WorldObject.Name} from {From}, but it's currently controlled by {WorldObject.ControllingPlayer}!" , MessageType . Error ) ;
return ;
}
WorldObject . ChangeState ( StateIndex ) ;
2020-12-23 10:43:13 +00:00
}
}
}