Begin script abstraction
This commit is contained in:
28
ReallifeGamemode.Server.Core.API/IAPI.cs
Normal file
28
ReallifeGamemode.Server.Core.API/IAPI.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using ReallifeGamemode.Server.Core.API.API;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ReallifeGamemode.Server.Core.API
|
||||
{
|
||||
public interface IAPI
|
||||
{
|
||||
IColShapeAPI ColShape { get; }
|
||||
|
||||
IVehicleAPI Vehicle { get; }
|
||||
|
||||
void DisableDefaultCommandErrorMessages();
|
||||
|
||||
void DisableDefaultSpawnBehavior();
|
||||
|
||||
IPlayer GetPlayerFromNameOrId(string nameOrId);
|
||||
|
||||
void SetGlobalChatEnabled(bool enable);
|
||||
|
||||
void SetTime(int hour, int minute, int second);
|
||||
|
||||
void TriggerClientEventForAll(string eventName, params object[] args);
|
||||
}
|
||||
}
|
||||
14
ReallifeGamemode.Server.Core.API/IColShape.cs
Normal file
14
ReallifeGamemode.Server.Core.API/IColShape.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace ReallifeGamemode.Server.Core.API
|
||||
{
|
||||
public interface IColShape : IEntity
|
||||
{
|
||||
delegate void ColShapeEvent(IColShape colShape, IEntity entity);
|
||||
|
||||
event ColShapeEvent OnEntityEnter;
|
||||
event ColShapeEvent OnEntityExit;
|
||||
}
|
||||
}
|
||||
13
ReallifeGamemode.Server.Core.API/IColShapeAPI.cs
Normal file
13
ReallifeGamemode.Server.Core.API/IColShapeAPI.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace ReallifeGamemode.Server.Core.API.API
|
||||
{
|
||||
public interface IColShapeAPI
|
||||
{
|
||||
IColShape CreateCyclinder(Position position, float height, float range);
|
||||
|
||||
IColShape CreateSphere(Position position, float range);
|
||||
}
|
||||
}
|
||||
21
ReallifeGamemode.Server.Core.API/IEntity.cs
Normal file
21
ReallifeGamemode.Server.Core.API/IEntity.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
|
||||
namespace ReallifeGamemode.Server.Core.API
|
||||
{
|
||||
public interface IEntity
|
||||
{
|
||||
ulong Handle { get; }
|
||||
|
||||
Position Position { get; set; }
|
||||
|
||||
Position Rotation { get; set; }
|
||||
|
||||
double Heading { get; set; }
|
||||
|
||||
void Remove();
|
||||
|
||||
void SetSharedData<T>(string key, T data);
|
||||
|
||||
T GetSharedData<T>(string key, T fallback);
|
||||
}
|
||||
}
|
||||
43
ReallifeGamemode.Server.Core.API/IPlayer.cs
Normal file
43
ReallifeGamemode.Server.Core.API/IPlayer.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using ReallifeGamemode.Server.Types;
|
||||
using ReallifeGamemode.Server.Common;
|
||||
using System.Net;
|
||||
|
||||
namespace ReallifeGamemode.Server.Core.API
|
||||
{
|
||||
public interface IPlayer : IEntity
|
||||
{
|
||||
string Name { get; set; }
|
||||
|
||||
string SocialClubName { get; }
|
||||
|
||||
int Health { get; set; }
|
||||
|
||||
int Armor { get; set; }
|
||||
|
||||
IPAddress RemoteAddress { get; }
|
||||
|
||||
IVehicle Vehicle { get; }
|
||||
|
||||
bool IsInVehicle { get; }
|
||||
|
||||
VehicleSeat VehicleSeat { get; }
|
||||
|
||||
void SendMessage(string message, ChatPrefix prefix = ChatPrefix.None) => SendRawMessage(prefix.GetValue() + message);
|
||||
|
||||
void SendRawMessage(string message);
|
||||
|
||||
void TriggerEvent(string eventName, params object[] args) => TriggerEventRaw("SERVER:" + eventName, args);
|
||||
void CancelAnimation();
|
||||
void TriggerEventRaw(string eventName, params object[] args);
|
||||
|
||||
void SetIntoVehicle(IVehicle vehicle, VehicleSeat seat);
|
||||
|
||||
void Kick();
|
||||
|
||||
void SendNotification(string message, bool flashing = true);
|
||||
|
||||
void Spawn(Position position, float heading = 0.0f);
|
||||
|
||||
void PlayAnimation(string dict, string name, AnimationFlags flags, float speed = 8.0f);
|
||||
}
|
||||
}
|
||||
17
ReallifeGamemode.Server.Core.API/IVehicle.cs
Normal file
17
ReallifeGamemode.Server.Core.API/IVehicle.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
|
||||
using ReallifeGamemode.Server.Types;
|
||||
|
||||
namespace ReallifeGamemode.Server.Core.API
|
||||
{
|
||||
public interface IVehicle : IEntity
|
||||
{
|
||||
VehicleModel Model { get; }
|
||||
|
||||
sbyte PrimaryColor { get; set; }
|
||||
|
||||
sbyte SecondaryColor { get; set; }
|
||||
|
||||
void Repair();
|
||||
}
|
||||
}
|
||||
14
ReallifeGamemode.Server.Core.API/IVehicleAPI.cs
Normal file
14
ReallifeGamemode.Server.Core.API/IVehicleAPI.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using ReallifeGamemode.Server.Types;
|
||||
|
||||
namespace ReallifeGamemode.Server.Core.API.API
|
||||
{
|
||||
public interface IVehicleAPI
|
||||
{
|
||||
IVehicle Spawn(VehicleModel model, Position position, Position rotation, sbyte primaryColor, sbyte secondaryColor);
|
||||
|
||||
IVehicle GetVehicleFromHandle(ulong handle);
|
||||
}
|
||||
}
|
||||
76
ReallifeGamemode.Server.Core.API/Position.cs
Normal file
76
ReallifeGamemode.Server.Core.API/Position.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
namespace ReallifeGamemode.Server.Core.API
|
||||
{
|
||||
public class Position
|
||||
{
|
||||
public double X { get; set; }
|
||||
|
||||
public double Y { get; set; }
|
||||
|
||||
public double Z { get; set; }
|
||||
|
||||
public Position()
|
||||
{
|
||||
X = 0.0;
|
||||
Y = 0.0;
|
||||
Z = 0.0;
|
||||
}
|
||||
|
||||
public Position(double x, double y, double z)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
}
|
||||
|
||||
public Position(float x, float y, float z)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
}
|
||||
public Position(decimal x, decimal y, decimal z)
|
||||
{
|
||||
X = (double)x;
|
||||
Y = (double)y;
|
||||
Z = (double)z;
|
||||
}
|
||||
|
||||
public Position(int x, int y, int z)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
}
|
||||
|
||||
public Position Add(Position toAdd)
|
||||
{
|
||||
return new Position(X + toAdd.X, Y + toAdd.Y, Z + toAdd.Z);
|
||||
}
|
||||
|
||||
public Position Subtract(Position toSubtract)
|
||||
{
|
||||
return new Position(X - toSubtract.X, Y - toSubtract.Y, Z - toSubtract.Z);
|
||||
}
|
||||
|
||||
public double DistanceTo(Position position)
|
||||
{
|
||||
var x = position.X - X;
|
||||
var y = position.Y - Y;
|
||||
var z = position.Z - Z;
|
||||
|
||||
return Math.Sqrt(x * x + y * y + z * z);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
var x = Math.Round(this.X, 2).ToString(CultureInfo.InvariantCulture);
|
||||
var y = Math.Round(this.Y, 2).ToString(CultureInfo.InvariantCulture);
|
||||
var z = Math.Round(this.Z, 2).ToString(CultureInfo.InvariantCulture);
|
||||
|
||||
return $"{x}, {y}, {z}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ReallifeGamemode.Server.Common\ReallifeGamemode.Server.Common.csproj" />
|
||||
<ProjectReference Include="..\ReallifeGamemode.Server.Types\ReallifeGamemode.Server.Types.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user