2022-01-14 07:38:45 +00:00
using Mirror ;
using OWML.Common ;
2021-12-26 06:04:46 +00:00
using QSB.Messaging ;
using QSB.QuantumSync.WorldObjects ;
using QSB.Utility ;
2020-12-23 10:43:13 +00:00
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 ;
2022-01-14 07:38:45 +00:00
public override void Serialize ( NetworkWriter writer )
2021-12-26 06:04:46 +00:00
{
base . Serialize ( writer ) ;
writer . Write ( StateIndex ) ;
}
2020-12-23 10:43:13 +00:00
2022-01-14 07:38:45 +00:00
public override void Deserialize ( NetworkReader reader )
2020-12-23 10:43:13 +00:00
{
base . Deserialize ( reader ) ;
2022-01-14 07:38:45 +00:00
StateIndex = reader . Read < int > ( ) ;
2020-12-23 10:43:13 +00:00
}
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
}
}
}