[+] Added Gangwar playability

This commit is contained in:
Lukas Moungos
2019-12-01 15:57:37 +01:00
parent ba58c97182
commit a810a5abf8
6 changed files with 278 additions and 51 deletions

View File

@@ -6,6 +6,8 @@ using System.Linq;
using ReallifeGamemode.Database.Models;
using ReallifeGamemode.Database.Entities;
using Newtonsoft.Json;
using ReallifeGamemode.Server.Services;
using ReallifeGamemode.Server.Extensions;
namespace ReallifeGamemode.Server.Gangwar
{
@@ -40,12 +42,55 @@ namespace ReallifeGamemode.Server.Gangwar
NAPI.ClientEvent.TriggerClientEventForAll("GangAreas:Create", JsonConvert.SerializeObject(turfs.ToArray()));
}
public void GangwarKill(Client killer, Client victim)
{
if (killer.HasData("GotInsideOfTurf") && victim.HasData("GotInsideOfTurf"))
{
foreach (var turf in getTurfs())
{
if (turf.getId() == victim.GetData("inGangWar"))
{
turf.setKill(victim.GetUser().Faction.Name);
return;
}
}
}
}
public Turf[] getTurfs()
{
return _loadedTurfs;
}
[RemoteEvent("Gangarea:Enter")]
public void RmtEvent_TurfEnter(Client client, string jsonId)
{
int id = JsonConvert.DeserializeObject<int>(jsonId);
foreach (var turf in getTurfs())
{
if (turf.getId() == id)
{
turf.enter(client);
return;
}
}
}
[RemoteEvent("Gangarea:Leave")]
public void RmtEvent_TurfLeave(Client client, string jsonId)
{
int id = JsonConvert.DeserializeObject<int>(jsonId);
foreach (var turf in getTurfs())
{
if (turf.getId() == id)
{
turf.leave(client);
return;
}
}
}
[RemoteEvent("SERVER:SetTurf")]
public void RmtEvent_SetTurf(Client client, string jsonX, string jsonY, string jsonRot, string jsonRange, string Name)
@@ -65,13 +110,66 @@ namespace ReallifeGamemode.Server.Gangwar
Owner = "Neutral",
Color = 0
};
using(var dbContext = new DatabaseContext())
using (var dbContext = new DatabaseContext())
{
dbContext.Turfs.Add(newTurf);
dbContext.SaveChanges();
}
loadTurfs();
loadTurfs_ToAllClients()
loadTurfs_ToAllClients();
}
[RemoteEvent("SERVER:DeleteTurf")]
public void RmtEvent_DeleteTurf(Client client, string jsonId)
{
int id = JsonConvert.DeserializeObject<int>(jsonId);
if (id == -1)
{
ChatService.ErrorMessage(client, "Du befindest dich in keinem Gebiet");
return;
}
using (var dbContext = new DatabaseContext())
{
Turfs dturf = dbContext.Turfs.Where(t => t.Id == id).FirstOrDefault();
if (dturf != null)
{
dbContext.Turfs.Remove(dturf);
dbContext.SaveChanges();
loadTurfs();
loadTurfs_ToAllClients();
}
}
}
[Command("/gwstart")]
public void StartGangwar(Client client)
{
if (!client.GetUser().FactionLeader)
return;
foreach (var turf in getTurfs())
{
if (turf.status == "attack")
{
client.SendChatMessage("Ein GW läuft grad bruder"); // DEBUG
return;
}
}
if(client.GetUser().Faction.Name == "Ballas" || client.GetUser().Faction.Name == "Grove")
{
foreach (var turf in getTurfs())
{
foreach(var u in turf.playerInside)
{
if(u == client)
{
if (turf.Owner != client.GetUser().Faction.Name)
turf.attack(client.GetUser().Faction.Name);
}
}
}
}
}
}