using GTA;
using GTA.Math;
using System.Diagnostics;
namespace RageCoop.Client
{
///
///
///
public abstract class SyncedEntity
{
///
/// Indicates whether the current player is responsible for syncing this entity.
///
public bool IsLocal
{
get => OwnerID == Main.LocalPlayerID;
}
///
/// Network ID for this entity
///
public int ID { get; internal set; }
private int _ownerID;
///
///
///
public int OwnerID
{
get => _ownerID;
internal set
{
if (value==_ownerID && Owner!=null) { return; }
_ownerID = value;
Owner=PlayerList.GetPlayer(value);
}
}
internal virtual Player Owner { get; private set; }
///
///
///
public bool IsOutOfSync
{
get => Main.Ticked - LastSynced > 200 && ID != 0;
}
internal bool IsReady
{
get => LastSynced > 0 || LastFullSynced == 0;
}
internal bool IsInvincible { get; set; } = false;
internal bool NeedUpdate
{
get => LastSynced >= LastUpdated;
}
#region LAST STATE
///
/// Last time a new sync message arrived.
///
public ulong LastSynced { get; set; } = 0;
///
/// Last time a new sync message arrived.
///
public ulong LastFullSynced { get; internal set; } = 0;
///
/// Last time the local entity has been updated,
///
public ulong LastUpdated { get; set; } = 0;
internal Stopwatch LastSentStopWatch { get; set; } = Stopwatch.StartNew();
#endregion
public bool SendNextFrame { get; set; } = false;
public bool SendFullNextFrame { get; set; } = false;
///
///
///
internal protected bool _lastFrozen = false;
internal Model Model { get; set; }
internal Vector3 Position { get; set; }
internal Vector3 Rotation { get; set; }
internal Quaternion Quaternion { get; set; }
internal Vector3 Velocity { get; set; }
internal abstract void Update();
internal void PauseUpdate(ulong frames)
{
LastUpdated=Main.Ticked+frames;
}
}
}