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
|
|
|
|
{
|
2021-12-27 17:26:16 +01: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; }
|
2021-12-26 03:25:00 +01:00
|
|
|
|
public int PedHandle
|
|
|
|
|
{
|
|
|
|
|
get => CurrentPedHandle;
|
2021-12-27 17:26:16 +01:00
|
|
|
|
internal set
|
2021-12-26 03:25:00 +01:00
|
|
|
|
{
|
2021-12-27 17:26:16 +01:00
|
|
|
|
LastPedHandle = CurrentPedHandle == default ? value : CurrentPedHandle;
|
2021-12-26 03:25:00 +01:00
|
|
|
|
CurrentPedHandle = value;
|
2021-12-27 17:26:16 +01:00
|
|
|
|
|
2021-12-28 13:51:36 +01:00
|
|
|
|
if (CurrentPedHandle != LastPedHandle && Server.RunningResource != null)
|
2021-12-26 03:25:00 +01:00
|
|
|
|
{
|
2021-12-28 13:51:36 +01:00
|
|
|
|
Server.RunningResource.InvokePlayerPedHandleUpdate(Username);
|
2021-12-26 03:25:00 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private int LastVehicleHandle { get; set; }
|
|
|
|
|
private int CurrentVehicleHandle { get; set; }
|
|
|
|
|
public int VehicleHandle
|
|
|
|
|
{
|
|
|
|
|
get => CurrentPedHandle;
|
2021-12-27 17:26:16 +01:00
|
|
|
|
internal set
|
2021-12-26 03:25:00 +01:00
|
|
|
|
{
|
2021-12-27 17:26:16 +01:00
|
|
|
|
LastVehicleHandle = CurrentVehicleHandle == default ? value : CurrentVehicleHandle;
|
2021-12-26 03:25:00 +01:00
|
|
|
|
CurrentVehicleHandle = value;
|
2021-12-27 17:26:16 +01:00
|
|
|
|
|
2021-12-28 13:51:36 +01:00
|
|
|
|
if (CurrentVehicleHandle != LastVehicleHandle && Server.RunningResource != null)
|
2021-12-26 03:25:00 +01:00
|
|
|
|
{
|
2021-12-28 13:51:36 +01:00
|
|
|
|
Server.RunningResource.InvokePlayerPedHandleUpdate(Username);
|
2021-12-26 03:25:00 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-27 17:26:16 +01:00
|
|
|
|
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
|
|
|
|
|
{
|
2021-11-25 16:32:04 +01:00
|
|
|
|
get => CurrentPosition;
|
2021-12-27 17:26:16 +01:00
|
|
|
|
internal set
|
2021-08-20 17:28:13 +02:00
|
|
|
|
{
|
2021-12-27 17:26:16 +01:00
|
|
|
|
LastPosition = CurrentPosition.Equals(default(LVector3)) ? value : CurrentPosition;
|
2021-08-20 17:28:13 +02:00
|
|
|
|
CurrentPosition = value;
|
|
|
|
|
|
2021-12-28 13:51:36 +01:00
|
|
|
|
if (Server.RunningResource != null && !LVector3.Equals(CurrentPosition, LastPosition))
|
2021-08-20 17:28:13 +02:00
|
|
|
|
{
|
2021-12-28 13:51:36 +01:00
|
|
|
|
Server.RunningResource.InvokePlayerPositionUpdate(Username);
|
2021-08-20 17:28:13 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-27 17:26:16 +01:00
|
|
|
|
private int LastHealth { get; set; }
|
2021-11-25 16:32:04 +01:00
|
|
|
|
private int CurrentHealth { get; set; }
|
|
|
|
|
public int Health
|
|
|
|
|
{
|
|
|
|
|
get => CurrentHealth;
|
2021-12-27 17:26:16 +01:00
|
|
|
|
internal set
|
2021-11-25 16:32:04 +01:00
|
|
|
|
{
|
2021-12-27 17:26:16 +01:00
|
|
|
|
LastHealth = CurrentHealth == default ? value : CurrentHealth;
|
|
|
|
|
CurrentHealth = value;
|
|
|
|
|
|
2021-12-28 13:51:36 +01:00
|
|
|
|
if (CurrentHealth != LastHealth && Server.RunningResource != null)
|
2021-11-25 16:32:04 +01:00
|
|
|
|
{
|
2021-12-28 13:51:36 +01:00
|
|
|
|
Server.RunningResource.InvokePlayerHealthUpdate(Username);
|
2021-11-25 16:32:04 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
}
|