Add limitation to start Gangwar @Turf.cs
This commit is contained in:
@@ -9,6 +9,7 @@ using ReallifeGamemode.Database.Models;
|
|||||||
using ReallifeGamemode.Database.Entities;
|
using ReallifeGamemode.Database.Entities;
|
||||||
using ReallifeGamemode.Server.Services;
|
using ReallifeGamemode.Server.Services;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace ReallifeGamemode.Server.Gangwar
|
namespace ReallifeGamemode.Server.Gangwar
|
||||||
{
|
{
|
||||||
@@ -81,7 +82,7 @@ namespace ReallifeGamemode.Server.Gangwar
|
|||||||
|
|
||||||
private void Tick(object sender, System.Timers.ElapsedEventArgs e)
|
private void Tick(object sender, System.Timers.ElapsedEventArgs e)
|
||||||
{
|
{
|
||||||
if(this.status == "attack")
|
if (this.status == "attack")
|
||||||
{
|
{
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
@@ -122,14 +123,15 @@ namespace ReallifeGamemode.Server.Gangwar
|
|||||||
if (this.Def_Score <= 0)
|
if (this.Def_Score <= 0)
|
||||||
{
|
{
|
||||||
this.takeOver(this.Attacker);
|
this.takeOver(this.Attacker);
|
||||||
} else if (this.Att_Score <= 0)
|
}
|
||||||
|
else if (this.Att_Score <= 0)
|
||||||
{
|
{
|
||||||
this.takeOver(this.Owner);
|
this.takeOver(this.Owner);
|
||||||
}
|
}
|
||||||
timerCount += 1;
|
timerCount += 1;
|
||||||
if(timerCount >= 900) //change to 900 (seconds) before release for testing reasons change to whatever you like
|
if (timerCount >= 900) //change to 900 (seconds) before release for testing reasons change to whatever you like
|
||||||
{
|
{
|
||||||
if(this.Def_Score > this.Att_Score)
|
if (this.Def_Score > this.Att_Score)
|
||||||
{
|
{
|
||||||
foreach (Player gangwarPlayer in this.playerInGangwar)
|
foreach (Player gangwarPlayer in this.playerInGangwar)
|
||||||
{
|
{
|
||||||
@@ -137,7 +139,8 @@ namespace ReallifeGamemode.Server.Gangwar
|
|||||||
}
|
}
|
||||||
this.takeOver(this.Owner);
|
this.takeOver(this.Owner);
|
||||||
this.Att_Score = 0;
|
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)
|
foreach (Player gangwarPlayer in this.playerInGangwar)
|
||||||
{
|
{
|
||||||
@@ -147,7 +150,7 @@ namespace ReallifeGamemode.Server.Gangwar
|
|||||||
this.Def_Score = 0;
|
this.Def_Score = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if(this.Def_Score == this.Att_Score)
|
else if (this.Def_Score == this.Att_Score)
|
||||||
{
|
{
|
||||||
foreach (Player gangwarPlayer in this.playerInGangwar)
|
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);
|
playerInside.Add(client);
|
||||||
client.SetData("GotInsideOfTurf", true);
|
client.SetData("GotInsideOfTurf", true);
|
||||||
}
|
}
|
||||||
@@ -187,10 +191,10 @@ namespace ReallifeGamemode.Server.Gangwar
|
|||||||
|
|
||||||
public void leave(Player client)
|
public void leave(Player client)
|
||||||
{
|
{
|
||||||
if(playerInside.Find(c => c == client) != null)
|
if (playerInside.Find(c => c == client) != null)
|
||||||
{
|
{
|
||||||
this.playerInside = this.playerInside.Where(c => c != client).ToList();
|
this.playerInside = this.playerInside.Where(c => c != client).ToList();
|
||||||
if(this.status != "attack")
|
if (this.status != "attack")
|
||||||
client.ResetData("GotInsideOfTurf");
|
client.ResetData("GotInsideOfTurf");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -239,7 +243,7 @@ namespace ReallifeGamemode.Server.Gangwar
|
|||||||
|
|
||||||
}
|
}
|
||||||
this.Attacker = null;
|
this.Attacker = null;
|
||||||
foreach(var c in playerInGangwar)
|
foreach (var c in playerInGangwar)
|
||||||
{
|
{
|
||||||
c.TriggerEvent("CLIENT:setAttackBlip", false, TurfID);
|
c.TriggerEvent("CLIENT:setAttackBlip", false, TurfID);
|
||||||
c.ResetData("inGangWar");
|
c.ResetData("inGangWar");
|
||||||
@@ -252,30 +256,51 @@ namespace ReallifeGamemode.Server.Gangwar
|
|||||||
|
|
||||||
public void attack(string attacker)
|
public void attack(string attacker)
|
||||||
{
|
{
|
||||||
if(this.status == "normal")
|
Player[] usersInGangwar;
|
||||||
|
using (var context = new DatabaseContext())
|
||||||
{
|
{
|
||||||
if(this.timer != null)
|
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)
|
||||||
{
|
{
|
||||||
this.timer.Stop();
|
this.timer.Stop();
|
||||||
this.timer = null;
|
this.timer = null;
|
||||||
}
|
}
|
||||||
this.Attacker = attacker;
|
this.Attacker = attacker;
|
||||||
this.status = "attack";
|
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();
|
List<Player> clientsInGangwar = new List<Player>();
|
||||||
foreach (var u in usersInGangwar)
|
|
||||||
{
|
foreach (var u in usersInGangwar)
|
||||||
u.TriggerEvent("CLIENT:setAttackBlip", true, TurfID);
|
{
|
||||||
u.TriggerEvent("GangwarScore", this.Attacker, this.Owner, this.Att_Score, this.Def_Score);
|
u.TriggerEvent("CLIENT:setAttackBlip", true, TurfID);
|
||||||
u.SetData("inGangWar", getId());
|
u.TriggerEvent("GangwarScore", this.Attacker, this.Owner, this.Att_Score, this.Def_Score);
|
||||||
ChatService.SendMessage(u, "~y~[GANGWAR]~w~ Die " + getAttacker() + " haben das Gebiet ~y~"+ TurfName +"~w~ der "+ getOwner() +" angegriffen.");
|
u.SetData("inGangWar", getId());
|
||||||
clientsInGangwar.Add(u);
|
ChatService.SendMessage(u, "~y~[GANGWAR]~w~ Die " + getAttacker() + " haben das Gebiet ~y~" + TurfName + "~w~ der " + getOwner() + " angegriffen.");
|
||||||
}
|
clientsInGangwar.Add(u);
|
||||||
playerInGangwar = clientsInGangwar.ToArray();
|
|
||||||
}
|
}
|
||||||
|
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));
|
NAPI.ClientEvent.TriggerClientEventForAll("CLIENT:Turf_Update", JsonConvert.SerializeObject(this.TurfID), JsonConvert.SerializeObject(this.status), JsonConvert.SerializeObject(this.Owner), JsonConvert.SerializeObject(this.Attacker));
|
||||||
this.TurfTick();
|
this.TurfTick();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user