2021-12-24 01:07:29 +00:00
|
|
|
|
using QSB.WorldSync;
|
2021-12-11 07:28:42 +00:00
|
|
|
|
using QuantumUNET.Transport;
|
2021-12-24 01:07:29 +00:00
|
|
|
|
using System;
|
2021-12-11 07:28:42 +00:00
|
|
|
|
|
|
|
|
|
namespace QSB.Messaging
|
|
|
|
|
{
|
|
|
|
|
public abstract class QSBWorldObjectMessage<T> : QSBMessage where T : IWorldObject
|
|
|
|
|
{
|
2021-12-24 00:08:02 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// set automatically by SendMessage
|
|
|
|
|
/// </summary>
|
2021-12-23 01:13:54 +00:00
|
|
|
|
internal int ObjectId;
|
2021-12-24 00:08:02 +00:00
|
|
|
|
/// <summary>
|
2021-12-26 07:48:32 +00:00
|
|
|
|
/// set automatically by ShouldReceive
|
2021-12-24 00:08:02 +00:00
|
|
|
|
/// </summary>
|
2021-12-23 23:46:18 +00:00
|
|
|
|
protected T WorldObject { get; private set; }
|
2021-12-11 07:28:42 +00:00
|
|
|
|
|
|
|
|
|
public override void Serialize(QNetworkWriter writer)
|
|
|
|
|
{
|
|
|
|
|
base.Serialize(writer);
|
|
|
|
|
writer.Write(ObjectId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Deserialize(QNetworkReader reader)
|
|
|
|
|
{
|
|
|
|
|
base.Deserialize(reader);
|
|
|
|
|
ObjectId = reader.ReadInt32();
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-21 20:38:43 +00:00
|
|
|
|
public override bool ShouldReceive
|
2021-12-11 07:28:42 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (!WorldObjectManager.AllObjectsReady)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-26 06:37:20 +00:00
|
|
|
|
WorldObject = ObjectId.GetWorldObject<T>();
|
2021-12-11 07:28:42 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public abstract class QSBBoolWorldObjectMessage<T> : QSBWorldObjectMessage<T> where T : IWorldObject
|
|
|
|
|
{
|
2021-12-23 01:13:54 +00:00
|
|
|
|
protected bool Value;
|
2021-12-11 07:28:42 +00:00
|
|
|
|
|
|
|
|
|
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<T> : QSBWorldObjectMessage<T> where T : IWorldObject
|
|
|
|
|
{
|
2021-12-23 01:13:54 +00:00
|
|
|
|
protected float Value;
|
2021-12-11 07:28:42 +00:00
|
|
|
|
|
|
|
|
|
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<T, E> : QSBWorldObjectMessage<T>
|
|
|
|
|
where T : IWorldObject
|
|
|
|
|
where E : Enum
|
|
|
|
|
{
|
2021-12-23 01:13:54 +00:00
|
|
|
|
protected E Value;
|
2021-12-11 07:28:42 +00:00
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|