79 lines
2.0 KiB
C#
79 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using GTANetworkAPI;
|
|
using System.Linq;
|
|
using ReallifeGamemode.Database.Models;
|
|
using ReallifeGamemode.Database.Entities;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace ReallifeGamemode.Server.Gangwar
|
|
{
|
|
public class Gangwar : Script
|
|
{
|
|
public static Turf[] _loadedTurfs;
|
|
private static List<Turfs> turfs;
|
|
|
|
public static void loadTurfs()
|
|
{
|
|
_loadedTurfs = null;
|
|
using (var context = new DatabaseContext())
|
|
{
|
|
turfs = context.Turfs.Select(t => t).ToList();
|
|
List<Turf> turfing = new List<Turf>();
|
|
foreach (var t in turfs)
|
|
{
|
|
Turf newTurf = new Turf(t.Id, t.Name, t.Color, t.Owner);
|
|
turfing.Add(newTurf);
|
|
}
|
|
_loadedTurfs = turfing.ToArray();
|
|
}
|
|
}
|
|
|
|
public static void loadClient(Client client)
|
|
{
|
|
client.TriggerEvent("GangAreas:Create", JsonConvert.SerializeObject(turfs.ToArray()));
|
|
}
|
|
|
|
public static void loadTurfs_ToAllClients()
|
|
{
|
|
NAPI.ClientEvent.TriggerClientEventForAll("GangAreas:Create", JsonConvert.SerializeObject(turfs.ToArray()));
|
|
}
|
|
|
|
|
|
public Turf[] getTurfs()
|
|
{
|
|
return _loadedTurfs;
|
|
}
|
|
|
|
|
|
[RemoteEvent("SERVER:SetTurf")]
|
|
public void RmtEvent_SetTurf(Client client, string jsonX, string jsonY, string jsonRot, string jsonRange, string Name)
|
|
{
|
|
float pX = JsonConvert.DeserializeObject<float>(jsonX);
|
|
float pY = (float)JsonConvert.DeserializeObject<float>(jsonY);
|
|
float Rot = (float)JsonConvert.DeserializeObject<float>(jsonRot);
|
|
float Range = (float)JsonConvert.DeserializeObject<float>(jsonRange);
|
|
|
|
var newTurf = new Turfs
|
|
{
|
|
Name = Name,
|
|
X = pX,
|
|
Y = pY,
|
|
Rotation = Rot,
|
|
Range = Range,
|
|
Owner = "Neutral",
|
|
Color = 0
|
|
};
|
|
using(var dbContext = new DatabaseContext())
|
|
{
|
|
dbContext.Turfs.Add(newTurf);
|
|
dbContext.SaveChanges();
|
|
}
|
|
loadTurfs();
|
|
loadTurfs_ToAllClients()
|
|
}
|
|
|
|
}
|
|
}
|