2021-12-23 17:07:29 -08:00
|
|
|
|
using QSB.WorldSync;
|
2021-12-10 23:28:42 -08:00
|
|
|
|
using QuantumUNET.Transport;
|
2021-12-23 17:07:29 -08:00
|
|
|
|
using System;
|
2021-12-10 23:28:42 -08:00
|
|
|
|
|
|
|
|
|
namespace QSB.Messaging
|
|
|
|
|
{
|
|
|
|
|
public abstract class QSBWorldObjectMessage<T> : QSBMessage where T : IWorldObject
|
|
|
|
|
{
|
2021-12-23 16:08:02 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// set automatically by SendMessage
|
|
|
|
|
/// </summary>
|
2021-12-22 17:13:54 -08:00
|
|
|
|
internal int ObjectId;
|
2021-12-23 16:08:02 -08:00
|
|
|
|
/// <summary>
|
2021-12-25 23:48:32 -08:00
|
|
|
|
/// set automatically by ShouldReceive
|
2021-12-23 16:08:02 -08:00
|
|
|
|
/// </summary>
|
2021-12-23 15:46:18 -08:00
|
|
|
|
protected T WorldObject { get; private set; }
|
2021-12-10 23:28:42 -08: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 12:38:43 -08:00
|
|
|
|
public override bool ShouldReceive
|
2021-12-10 23:28:42 -08:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (!WorldObjectManager.AllObjectsReady)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-25 22:37:20 -08:00
|
|
|
|
WorldObject = ObjectId.GetWorldObject<T>();
|
2021-12-10 23:28:42 -08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public abstract class QSBBoolWorldObjectMessage<T> : QSBWorldObjectMessage<T> where T : IWorldObject
|
|
|
|
|
{
|
2021-12-22 17:13:54 -08:00
|
|
|
|
protected bool Value;
|
2021-12-10 23:28:42 -08: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-22 17:13:54 -08:00
|
|
|
|
protected float Value;
|
2021-12-10 23:28:42 -08: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-22 17:13:54 -08:00
|
|
|
|
protected E Value;
|
2021-12-10 23:28:42 -08: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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|