RAGECOOP-V/Server/PlayerData.cs

80 lines
2.6 KiB
C#
Raw Normal View History

2021-12-17 21:32:57 +01:00
using System.Linq;
namespace CoopServer
2021-07-07 13:36:25 +02:00
{
2021-08-26 17:01:32 +02:00
public struct PlayerData
2021-07-07 13:36:25 +02:00
{
public string Username { get; internal set; }
2021-12-26 03:30:05 +01:00
private int LastPedHandle { get; set; }
private int CurrentPedHandle { get; set; }
public int PedHandle
{
get => CurrentPedHandle;
internal set
{
LastPedHandle = CurrentPedHandle == default ? value : CurrentPedHandle;
CurrentPedHandle = value;
if (CurrentPedHandle != LastPedHandle && Server.RunningResource != null)
{
Server.RunningResource.InvokePlayerPedHandleUpdate(Username);
}
}
}
private int LastVehicleHandle { get; set; }
private int CurrentVehicleHandle { get; set; }
public int VehicleHandle
{
get => CurrentPedHandle;
internal set
{
LastVehicleHandle = CurrentVehicleHandle == default ? value : CurrentVehicleHandle;
CurrentVehicleHandle = value;
if (CurrentVehicleHandle != LastVehicleHandle && Server.RunningResource != null)
{
Server.RunningResource.InvokePlayerPedHandleUpdate(Username);
}
}
}
public bool IsInVehicle { get; internal set; }
2021-08-26 17:01:32 +02:00
private LVector3 LastPosition { get; set; }
private LVector3 CurrentPosition { get; set; }
2021-08-20 17:28:13 +02:00
public LVector3 Position
{
get => CurrentPosition;
internal set
2021-08-20 17:28:13 +02:00
{
LastPosition = CurrentPosition.Equals(default(LVector3)) ? value : CurrentPosition;
2021-08-20 17:28:13 +02:00
CurrentPosition = value;
if (Server.RunningResource != null && !LVector3.Equals(CurrentPosition, LastPosition))
2021-08-20 17:28:13 +02:00
{
Server.RunningResource.InvokePlayerPositionUpdate(Username);
2021-08-20 17:28:13 +02:00
}
}
}
private int LastHealth { get; set; }
private int CurrentHealth { get; set; }
public int Health
{
get => CurrentHealth;
internal set
{
LastHealth = CurrentHealth == default ? value : CurrentHealth;
CurrentHealth = value;
if (CurrentHealth != LastHealth && Server.RunningResource != null)
{
Server.RunningResource.InvokePlayerHealthUpdate(Username);
}
}
}
2021-08-20 17:28:13 +02:00
public bool IsInRangeOf(LVector3 position, float distance)
{
return LVector3.Subtract(Position, position).Length() < distance;
}
2021-07-07 13:36:25 +02:00
}
}