This commit is contained in:
Lukas Moungos
2019-12-01 18:14:31 +01:00
parent af08c85986
commit e81772d351
2 changed files with 37 additions and 17 deletions

View File

@@ -23,7 +23,7 @@ namespace ReallifeGamemode.Server.Gangwar
public int Att_Score { get; set; }
public int Def_Score { get; set; }
public string status { get; set; }
public Client[] playerInside { get; set; }
public List<Client> playerInside { get; set; }
public Timer timer { get; set; }
public Client[] playerInGangwar { get; set; }
@@ -39,6 +39,7 @@ namespace ReallifeGamemode.Server.Gangwar
this.Def_Score = 5;
this.status = "normal";
this.timer = null;
this.playerInside = new List<Client>();
}
public int getId()
@@ -107,10 +108,7 @@ namespace ReallifeGamemode.Server.Gangwar
if(owners.Length < attackers.Length)
this.Def_Score -= attackers.Length - owners.Length;
*/
foreach (Client gangwarPlayer in this.playerInGangwar)
{
gangwarPlayer.TriggerEvent("CLIENT:ScoreUpdate", JsonConvert.SerializeObject(this.Att_Score), JsonConvert.SerializeObject(this.Def_Score), JsonConvert.SerializeObject(this.TurfID));
}
if (this.Def_Score <= 0)
{
this.takeOver(this.Attacker);
@@ -138,21 +136,19 @@ namespace ReallifeGamemode.Server.Gangwar
}
}
if(Array.IndexOf(this.playerInside, client) == -1) {
Client[] refObj = this.playerInside;
Array.Resize(ref refObj, this.playerInside.Length + 1);
this.playerInside = refObj;
this.playerInside[this.playerInside.GetUpperBound(0)] = client;
if (status == "attack")
client.SetData("GotInsideOfTurf", true);
if(playerInside.Find(c => c == client) == null) {
playerInside.Add(client);
client.SetData("GotInsideOfTurf", true);
}
}
public void leave(Client client)
{
if(Array.IndexOf(this.playerInside, client) > -1)
if(playerInside.Find(c => c == client) != null)
{
this.playerInside = this.playerInside.Where(c => c != client).ToArray();
this.playerInside = this.playerInside.Where(c => c != client).ToList();
if(this.status != "attack")
client.ResetData("GotInsideOfTurf");
}
}
@@ -169,14 +165,14 @@ namespace ReallifeGamemode.Server.Gangwar
}
else if (getOwner() != FactionName)
{
ChatService.BroadcastFaction("~y~[GANGWAR] ~w~Deine Fraktion konnte das Gebiet " + getName() + " nicht verteidigen.", dbContext.Factions.Where(f => f.Name == getAttacker()).FirstOrDefault());
ChatService.BroadcastFaction("~y~[GANGWAR] ~w~Deine Fraktion konnte das Gebiet ~r~" + getName() + "~w~ nicht verteidigen.", dbContext.Factions.Where(f => f.Name == getAttacker()).FirstOrDefault());
this.Owner = FactionName;
Turfs turf = dbContext.Turfs.Where(t => t.Id == getId()).FirstOrDefault();
turf.Owner = this.Owner;
turf.FactionId = dbContext.Factions.Where(f => f.Name == this.Owner).FirstOrDefault().Id;
dbContext.SaveChanges();
}
ChatService.BroadcastFaction("~y~[GANGWAR] ~w~Deine Fraktion hat erfolgreich das Gebiet " + getName() + " erobert.", dbContext.Factions.Where(f => f.Name == this.Owner).FirstOrDefault());
ChatService.BroadcastFaction("~y~[GANGWAR] ~w~Deine Fraktion hat erfolgreich das Gebiet ~g~" + getName() + "~w~ erobert.", dbContext.Factions.Where(f => f.Name == this.Owner).FirstOrDefault());
}
this.Attacker = null;
foreach(var c in playerInGangwar)
@@ -207,6 +203,7 @@ namespace ReallifeGamemode.Server.Gangwar
Client[] usersInGangwar = NAPI.Pools.GetAllPlayers().Where(c => c.GetUser().Faction.Name == getOwner() || c.GetUser().Faction.Name == getAttacker()).ToArray();
foreach (var u in usersInGangwar)
{
u.TriggerEvent("GangwarScore", this.Attacker, this.Owner, this.Att_Score, this.Def_Score);
u.SetData("inGangWar", getId());
clientsInGangwar.Add(u);
}
@@ -231,7 +228,7 @@ namespace ReallifeGamemode.Server.Gangwar
foreach (Client gangwarPlayer in this.playerInGangwar)
{
gangwarPlayer.TriggerEvent("CLIENT:ScoreUpdate1", JsonConvert.SerializeObject(this.Att_Score), JsonConvert.SerializeObject(this.Def_Score), JsonConvert.SerializeObject(this.TurfID));
gangwarPlayer.TriggerEvent("GangwarScore", this.Attacker, this.Owner, this.Att_Score, this.Def_Score);
}
}
}