using QSB.WorldSync; using QuantumUNET.Transport; using System; namespace QSB.Messaging { public abstract class QSBWorldObjectMessage : QSBMessage where T : IWorldObject { /// /// set automatically by SendMessage /// internal int ObjectId; /// /// set automatically by ShouldReceive /// protected T WorldObject { get; private set; } public override void Serialize(QNetworkWriter writer) { base.Serialize(writer); writer.Write(ObjectId); } public override void Deserialize(QNetworkReader reader) { base.Deserialize(reader); ObjectId = reader.ReadInt32(); } public override bool ShouldReceive { get { if (!WorldObjectManager.AllObjectsReady) { return false; } WorldObject = ObjectId.GetWorldObject(); return true; } } } public abstract class QSBBoolWorldObjectMessage : QSBWorldObjectMessage where T : IWorldObject { protected bool Value; public override void Serialize(QNetworkWriter writer) { base.Serialize(writer); writer.Write(Value); } public override void Deserialize(QNetworkReader reader) { base.Deserialize(reader); Value = reader.ReadBoolean(); } } public abstract class QSBFloatWorldObjectMessage : QSBWorldObjectMessage where T : IWorldObject { protected float Value; public override void Serialize(QNetworkWriter writer) { base.Serialize(writer); writer.Write(Value); } public override void Deserialize(QNetworkReader reader) { base.Deserialize(reader); Value = reader.ReadSingle(); } } public abstract class QSBEnumWorldObjectMessage : QSBWorldObjectMessage where T : IWorldObject where E : Enum { protected E Value; public override void Serialize(QNetworkWriter writer) { base.Serialize(writer); writer.Write((int)(object)Value); } public override void Deserialize(QNetworkReader reader) { base.Deserialize(reader); Value = (E)(object)reader.ReadInt32(); } } }