Begin script abstraction
This commit is contained in:
61
ReallifeGamemode.Server.Core.RageMP/RageAPI.cs
Normal file
61
ReallifeGamemode.Server.Core.RageMP/RageAPI.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using GTANetworkAPI;
|
||||
using ReallifeGamemode.Server.Core.API;
|
||||
using ReallifeGamemode.Server.Core.API.API;
|
||||
|
||||
namespace ReallifeGamemode.Server.Core.RageMP
|
||||
{
|
||||
public class RageAPI : IAPI
|
||||
{
|
||||
public IColShapeAPI ColShape => new RageColShapeAPI();
|
||||
|
||||
public IVehicleAPI Vehicle => new RageVehicleAPI();
|
||||
|
||||
public void DisableDefaultCommandErrorMessages()
|
||||
{
|
||||
NAPI.Server.SetCommandErrorMessage(null);
|
||||
NAPI.Server.SetGlobalDefaultCommandMessages(false);
|
||||
}
|
||||
|
||||
public void SetGlobalChatEnabled(bool enable)
|
||||
{
|
||||
NAPI.Server.SetGlobalServerChat(enable);
|
||||
}
|
||||
|
||||
public void DisableDefaultSpawnBehavior()
|
||||
{
|
||||
NAPI.Server.SetAutoSpawnOnConnect(false);
|
||||
}
|
||||
|
||||
public IPlayer GetPlayerFromNameOrId(string nameOrId)
|
||||
{
|
||||
Player player;
|
||||
if (int.TryParse(nameOrId, out var playerId))
|
||||
{
|
||||
player = NAPI.Pools.GetAllPlayers().Where(u => u.Handle.Value == playerId).FirstOrDefault();
|
||||
}
|
||||
else
|
||||
{
|
||||
player = NAPI.Player.GetPlayerFromName(nameOrId);
|
||||
}
|
||||
|
||||
if (player == null || player.Handle == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new RagePlayer(player);
|
||||
}
|
||||
|
||||
public void SetTime(int hour, int minute, int second)
|
||||
{
|
||||
NAPI.World.SetTime(hour, minute, second);
|
||||
}
|
||||
|
||||
public void TriggerClientEventForAll(string eventName, params object[] args)
|
||||
{
|
||||
NAPI.ClientEvent.TriggerClientEventForAll("SERVER:" + eventName, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
23
ReallifeGamemode.Server.Core.RageMP/RageColShape.cs
Normal file
23
ReallifeGamemode.Server.Core.RageMP/RageColShape.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using ReallifeGamemode.Server.Core.API;
|
||||
|
||||
namespace ReallifeGamemode.Server.Core.RageMP
|
||||
{
|
||||
public class RageColShape : RageEntity, IColShape
|
||||
{
|
||||
private GTANetworkAPI.ColShape colShape;
|
||||
|
||||
public RageColShape(GTANetworkAPI.ColShape colShape) : base(colShape)
|
||||
{
|
||||
this.colShape = colShape;
|
||||
|
||||
this.colShape.OnEntityEnterColShape += (c, p) => OnEntityEnter?.Invoke(this, new RagePlayer(p));
|
||||
this.colShape.OnEntityExitColShape += (c, p) => OnEntityExit?.Invoke(this, new RagePlayer(p));
|
||||
}
|
||||
|
||||
public event IColShape.ColShapeEvent OnEntityEnter;
|
||||
public event IColShape.ColShapeEvent OnEntityExit;
|
||||
}
|
||||
}
|
||||
21
ReallifeGamemode.Server.Core.RageMP/RageColShapeAPI.cs
Normal file
21
ReallifeGamemode.Server.Core.RageMP/RageColShapeAPI.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using ReallifeGamemode.Server.Core.API;
|
||||
using ReallifeGamemode.Server.Core.API.API;
|
||||
|
||||
namespace ReallifeGamemode.Server.Core.RageMP
|
||||
{
|
||||
class RageColShapeAPI : IColShapeAPI
|
||||
{
|
||||
public IColShape CreateCyclinder(Position position, float height, float range)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IColShape CreateSphere(Position position, float range)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
63
ReallifeGamemode.Server.Core.RageMP/RageEntity.cs
Normal file
63
ReallifeGamemode.Server.Core.RageMP/RageEntity.cs
Normal 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>();
|
||||
}
|
||||
}
|
||||
}
|
||||
39
ReallifeGamemode.Server.Core.RageMP/RageExtensions.cs
Normal file
39
ReallifeGamemode.Server.Core.RageMP/RageExtensions.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using GTANetworkAPI;
|
||||
using ReallifeGamemode.Server.Core.API;
|
||||
using ReallifeGamemode.Server.Types;
|
||||
|
||||
namespace ReallifeGamemode.Server.Core.RageMP
|
||||
{
|
||||
public static class RageExtensions
|
||||
{
|
||||
public static Vector3 ToVector3(this Position position)
|
||||
{
|
||||
return new Vector3(position.X, position.Y, position.Z);
|
||||
}
|
||||
|
||||
public static Position ToPosition(this Vector3 vector)
|
||||
{
|
||||
return new Position(vector.X, vector.Y, vector.Z);
|
||||
}
|
||||
|
||||
public static DisconnectReason ToDisconnectReason(this DisconnectionType disconnectionType)
|
||||
{
|
||||
switch (disconnectionType)
|
||||
{
|
||||
case DisconnectionType.Left:
|
||||
return DisconnectReason.Quit;
|
||||
|
||||
case DisconnectionType.Kicked:
|
||||
return DisconnectReason.Kick;
|
||||
|
||||
case DisconnectionType.Timeout:
|
||||
return DisconnectReason.Timeout;
|
||||
default:
|
||||
return DisconnectReason.Unknown;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
79
ReallifeGamemode.Server.Core.RageMP/RagePlayer.cs
Normal file
79
ReallifeGamemode.Server.Core.RageMP/RagePlayer.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using ReallifeGamemode.Server.Core.API;
|
||||
using ReallifeGamemode.Server.Types;
|
||||
|
||||
namespace ReallifeGamemode.Server.Core.RageMP
|
||||
{
|
||||
public class RagePlayer : RageEntity, IPlayer
|
||||
{
|
||||
private readonly GTANetworkAPI.Player client;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => client.Name;
|
||||
set => client.Name = value;
|
||||
}
|
||||
|
||||
public string SocialClubName => client.SocialClubName;
|
||||
|
||||
public IPAddress RemoteAddress => IPAddress.Parse(client.Address);
|
||||
|
||||
public IVehicle Vehicle => client.IsInVehicle ? new RageVehicle(client.Vehicle) : null;
|
||||
|
||||
public VehicleSeat VehicleSeat => (VehicleSeat)client.VehicleSeat;
|
||||
|
||||
public bool IsInVehicle => Vehicle != null;
|
||||
|
||||
public int Health { get => client.Health; set => client.Health = value; }
|
||||
public int Armor { get => client.Armor; set => client.Armor = value; }
|
||||
|
||||
public RagePlayer(GTANetworkAPI.Player client) : base(client)
|
||||
{
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
public void SendRawMessage(string message)
|
||||
{
|
||||
client.SendChatMessage(message);
|
||||
}
|
||||
|
||||
public void TriggerEventRaw(string eventName, params object[] args)
|
||||
{
|
||||
client.TriggerEvent(eventName, args);
|
||||
}
|
||||
|
||||
public void SetIntoVehicle(IVehicle vehicle, VehicleSeat seat)
|
||||
{
|
||||
client.SetIntoVehicle(new GTANetworkAPI.NetHandle((ushort)vehicle.Handle, GTANetworkAPI.EntityType.Vehicle), (int)seat - 1);
|
||||
}
|
||||
|
||||
public void Kick() => client.Kick();
|
||||
|
||||
public void SendNotification(string message, bool flashing = true)
|
||||
{
|
||||
client.SendNotification(message, flashing);
|
||||
}
|
||||
|
||||
public void Spawn(Position position, float heading = 0)
|
||||
{
|
||||
Health = 100;
|
||||
Armor = 0;
|
||||
|
||||
Position = position;
|
||||
Heading = heading;
|
||||
}
|
||||
|
||||
public void PlayAnimation(string dict, string name, AnimationFlags flags, float speed = 8.0f)
|
||||
{
|
||||
GTANetworkAPI.NAPI.Player.PlayPlayerAnimation(client, (int)flags, dict, name, speed);
|
||||
}
|
||||
|
||||
public void CancelAnimation()
|
||||
{
|
||||
client.StopAnimation();
|
||||
}
|
||||
}
|
||||
}
|
||||
30
ReallifeGamemode.Server.Core.RageMP/RageVehicle.cs
Normal file
30
ReallifeGamemode.Server.Core.RageMP/RageVehicle.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using GTANetworkAPI;
|
||||
using ReallifeGamemode.Server.Core.API;
|
||||
using ReallifeGamemode.Server.Types;
|
||||
|
||||
namespace ReallifeGamemode.Server.Core.RageMP
|
||||
{
|
||||
class RageVehicle : RageEntity, IVehicle
|
||||
{
|
||||
private readonly Vehicle vehicle;
|
||||
|
||||
public RageVehicle(Vehicle vehicle) : base(vehicle)
|
||||
{
|
||||
this.vehicle = vehicle;
|
||||
}
|
||||
|
||||
public VehicleModel Model => (VehicleModel)vehicle.Model;
|
||||
|
||||
public sbyte PrimaryColor { get => (sbyte)vehicle.PrimaryColor; set => vehicle.PrimaryColor = value; }
|
||||
|
||||
public sbyte SecondaryColor { get => (sbyte)vehicle.SecondaryColor; set => vehicle.SecondaryColor = value; }
|
||||
|
||||
public void Repair()
|
||||
{
|
||||
vehicle.Repair();
|
||||
}
|
||||
}
|
||||
}
|
||||
22
ReallifeGamemode.Server.Core.RageMP/RageVehicleAPI.cs
Normal file
22
ReallifeGamemode.Server.Core.RageMP/RageVehicleAPI.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using ReallifeGamemode.Server.Core.API;
|
||||
using ReallifeGamemode.Server.Core.API.API;
|
||||
using ReallifeGamemode.Server.Types;
|
||||
|
||||
namespace ReallifeGamemode.Server.Core.RageMP
|
||||
{
|
||||
class RageVehicleAPI : IVehicleAPI
|
||||
{
|
||||
public IVehicle GetVehicleFromHandle(ulong handle)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IVehicle Spawn(VehicleModel model, Position position, Position rotation, sbyte primaryColor, sbyte secondaryColor)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ReallifeGamemode.Server.Common\ReallifeGamemode.Server.Common.csproj" />
|
||||
<ProjectReference Include="..\ReallifeGamemode.Server.Core.API\ReallifeGamemode.Server.Core.API.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="Bootstrapper">
|
||||
<HintPath>..\Import\Bootstrapper.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user