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

31 lines
787 B
C#
Raw Normal View History

using Mirror;
using QSB.Messaging;
2021-12-26 06:04:46 +00:00
using QSB.QuantumSync.WorldObjects;
2021-12-24 01:07:29 +00:00
using System;
using System.Linq;
2021-01-01 10:17:35 +00:00
namespace QSB.QuantumSync.Messages
2021-01-01 10:17:35 +00:00
{
2021-12-26 06:04:46 +00:00
internal class QuantumShuffleMessage : QSBWorldObjectMessage<QSBQuantumShuffleObject>
2021-01-01 10:17:35 +00:00
{
2021-12-26 06:04:46 +00:00
private int[] IndexArray;
2021-01-01 10:17:35 +00:00
2021-12-26 06:04:46 +00:00
public QuantumShuffleMessage(int[] indexArray) => IndexArray = indexArray;
public override void Serialize(NetworkWriter writer)
2021-01-01 10:17:35 +00:00
{
base.Serialize(writer);
var temp = IndexArray.Select(x => (byte)x).ToArray();
writer.WriteBytesAndSize(temp);
2021-01-01 10:17:35 +00:00
}
2021-12-26 06:04:46 +00:00
public override void Deserialize(NetworkReader reader)
2021-12-26 06:04:46 +00:00
{
base.Deserialize(reader);
IndexArray = Array.ConvertAll(reader.ReadBytesAndSize(), Convert.ToInt32);
}
public override void OnReceiveRemote() => WorldObject.ShuffleObjects(IndexArray);
2021-01-01 10:17:35 +00:00
}
}