Begin script abstraction

This commit is contained in:
hydrant
2020-02-29 14:50:10 +01:00
parent 447dd2eabc
commit 37f499a446
48 changed files with 2201 additions and 49 deletions

View File

@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Text;
using ReallifeGamemode.Server.Common;
using ReallifeGamemode.Server.Core.API;
namespace ReallifeGamemode.Server.Core.RageMP
{
public class RageEntity : IEntity
{
private readonly GTANetworkAPI.Entity entity;
public Position Position
{
get => entity.Position.ToPosition();
set => entity.Position = value.ToVector3();
}
public Position Rotation
{
get => entity.Rotation.ToPosition();
set => entity.Rotation = value.ToVector3();
}
public ulong Handle => entity.Handle.Value;
public double Heading
{
get => Rotation.Z;
set
{
var rotation = Rotation;
rotation.Z = value;
Rotation = rotation;
}
}
public RageEntity(GTANetworkAPI.Entity rageEntity)
{
entity = rageEntity;
}
public void Remove()
{
entity.Delete();
}
public void SetSharedData<T>(string key, T data)
{
entity.SetSharedData(key, data.SerializeJson());
}
public T GetSharedData<T>(string key, T fallback)
{
if (!entity.HasSharedData(key))
{
return fallback;
}
return (entity.GetSharedData<string>(key)).DeserializeJson<T>();
}
}
}