Add limitation to start Gangwar @Turf.cs

This commit is contained in:
Siga
2020-03-24 19:45:09 +01:00
parent c4879bb152
commit 17cdc5bd60

View File

@@ -9,6 +9,7 @@ using ReallifeGamemode.Database.Models;
using ReallifeGamemode.Database.Entities;
using ReallifeGamemode.Server.Services;
using Newtonsoft.Json;
using Microsoft.EntityFrameworkCore;
namespace ReallifeGamemode.Server.Gangwar
{
@@ -122,7 +123,8 @@ namespace ReallifeGamemode.Server.Gangwar
if (this.Def_Score <= 0)
{
this.takeOver(this.Attacker);
} else if (this.Att_Score <= 0)
}
else if (this.Att_Score <= 0)
{
this.takeOver(this.Owner);
}
@@ -137,7 +139,8 @@ namespace ReallifeGamemode.Server.Gangwar
}
this.takeOver(this.Owner);
this.Att_Score = 0;
}else if(this.Def_Score < this.Att_Score)
}
else if (this.Def_Score < this.Att_Score)
{
foreach (Player gangwarPlayer in this.playerInGangwar)
{
@@ -179,7 +182,8 @@ namespace ReallifeGamemode.Server.Gangwar
}
}
if(playerInside.Find(c => c == client) == null) {
if (playerInside.Find(c => c == client) == null)
{
playerInside.Add(client);
client.SetData("GotInsideOfTurf", true);
}
@@ -252,6 +256,30 @@ namespace ReallifeGamemode.Server.Gangwar
public void attack(string attacker)
{
Player[] usersInGangwar;
using (var context = new DatabaseContext())
{
var onlinePlayers = NAPI.Pools.GetAllPlayers().Where(c => c.IsLoggedIn()).Select(c => c.Name);
List<Player> ownersInGangwar = context.Users.Include(u => u.Faction).Where(u => onlinePlayers.Contains(u.Name) && u.Faction.Name == getOwner()).Select(u => u.Player).ToList();
List<Player> attackersInGangwar = context.Users.Include(u => u.Faction).Where(u => onlinePlayers.Contains(u.Name) && u.Faction.Name == getAttacker()).Select(u => u.Player).ToList();
if (ownersInGangwar.Count < 5 && attackersInGangwar.Count < 5)
{
List<Player> leaders = context.Users.Include(u => u.Faction).Where(u => onlinePlayers.Contains(u.Name) && u.Faction.Name == getAttacker() && u.FactionLeader).Select(u => u.Player).ToList();
foreach(var l in leaders)
{
ChatService.ErrorMessage(l, "Gangwarstart ist nicht möglich, da die beteiligten Fraktionen nicht genügend Mitglieder online haben.");
}
return;
}
List<Player> inGangwar = new List<Player>();
inGangwar.AddRange(ownersInGangwar);
inGangwar.AddRange(attackersInGangwar);
usersInGangwar = inGangwar.ToArray();
}
if (this.status == "normal")
{
if (this.timer != null)
@@ -261,11 +289,9 @@ namespace ReallifeGamemode.Server.Gangwar
}
this.Attacker = attacker;
this.status = "attack";
using (var context = new DatabaseContext())
{
List<Player> clientsInGangwar = new List<Player>();
Player[] usersInGangwar = NAPI.Pools.GetAllPlayers().Where(c => c.IsLoggedIn() && (c.GetUser().Faction.Name == getOwner() || c.GetUser().Faction.Name == getAttacker())).ToArray();
foreach (var u in usersInGangwar)
{
u.TriggerEvent("CLIENT:setAttackBlip", true, TurfID);
@@ -275,7 +301,6 @@ namespace ReallifeGamemode.Server.Gangwar
clientsInGangwar.Add(u);
}
playerInGangwar = clientsInGangwar.ToArray();
}
NAPI.ClientEvent.TriggerClientEventForAll("CLIENT:Turf_Update", JsonConvert.SerializeObject(this.TurfID), JsonConvert.SerializeObject(this.status), JsonConvert.SerializeObject(this.Owner), JsonConvert.SerializeObject(this.Attacker));
this.TurfTick();
}