This commit is contained in:
hydrant
2021-04-09 19:53:20 +02:00

View File

@@ -133,35 +133,15 @@ namespace ReallifeGamemode.Server.Gangwar
private void update() private void update()
{ {
#region Ticket system NAPI.Task.Run(() =>
/*
try
{ {
Player[] owners = NAPI.Pools.GetAllPlayers().Where(c => c.GetUser().Faction.Name == this.Owner).ToArray();
Player[] attackers = NAPI.Pools.GetAllPlayers().Where(c => c.GetUser().Faction.Name == this.Attacker).ToArray();
}catch(NullReferenceException ex)
{
int i = 0;
foreach(var c in playerInGangwar)
{
if (!NAPI.Entity.DoesEntityExist(c.Handle))
{
this.playerInside = this.playerInside.Where(gp => gp != c).ToArray();
}
i++;
}
}
if (owners.Length > attackers.Length)
this.Att_Score -= owners.Length - attackers.Length;
if(owners.Length < attackers.Length)
this.Def_Score -= attackers.Length - owners.Length;
*/
#endregion Ticket system
foreach (Player gangwarPlayer in this.playerInGangwar) foreach (Player gangwarPlayer in this.playerInGangwar)
{ {
if (!gangwarPlayer.IsLoggedIn())
{
continue;
}
gangwarPlayer.TriggerEvent("GangwarScore", this.Attacker, this.Owner, this.Att_Score, this.Def_Score, 900 - timerCount); gangwarPlayer.TriggerEvent("GangwarScore", this.Attacker, this.Owner, this.Att_Score, this.Def_Score, 900 - timerCount);
} }
/*if (this.Att_Score >= 200) /*if (this.Att_Score >= 200)
@@ -173,12 +153,17 @@ namespace ReallifeGamemode.Server.Gangwar
this.takeOver(this.Owner); this.takeOver(this.Owner);
}*/ }*/
timerCount += 1; timerCount += 1;
if (timerCount >= 10) //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.Att_Score > this.Def_Score) if (this.Att_Score > this.Def_Score)
{ {
foreach (Player gangwarPlayer in this.playerInGangwar) foreach (Player gangwarPlayer in this.playerInGangwar)
{ {
if (!gangwarPlayer.IsLoggedIn())
{
continue;
}
gangwarPlayer.TriggerEvent("GangwarScore", this.Attacker, this.Owner, 0, 0, 0); gangwarPlayer.TriggerEvent("GangwarScore", this.Attacker, this.Owner, 0, 0, 0);
} }
this.takeOver(this.Attacker); this.takeOver(this.Attacker);
@@ -199,6 +184,11 @@ namespace ReallifeGamemode.Server.Gangwar
{ {
foreach (Player gangwarPlayer in this.playerInGangwar) foreach (Player gangwarPlayer in this.playerInGangwar)
{ {
if (!gangwarPlayer.IsLoggedIn())
{
continue;
}
gangwarPlayer.TriggerEvent("GangwarScore", this.Attacker, this.Owner, 0, 0, 0); gangwarPlayer.TriggerEvent("GangwarScore", this.Attacker, this.Owner, 0, 0, 0);
} }
this.takeOver(this.Owner); this.takeOver(this.Owner);
@@ -206,8 +196,10 @@ namespace ReallifeGamemode.Server.Gangwar
return; return;
} }
} }
});
} }
public void enter(Player client) public void enter(Player client)
{ {
User user = client.GetUser(); User user = client.GetUser();
@@ -215,7 +207,7 @@ namespace ReallifeGamemode.Server.Gangwar
{ {
if (user.Faction.Name != getOwner() && user.Faction.Name != getAttacker()) if (user.Faction.Name != getOwner() && user.Faction.Name != getAttacker())
return; return;
Player gPlayer = playerInGangwar.Where(c => c != null && !c.Handle.IsNull && c.IsLoggedIn() && c.GetUser().Id == user.Id).FirstOrDefault(); Player gPlayer = playerInGangwar.Where(c => c != null && !c.Handle.IsNull && c.IsLoggedIn() && c.GetUser()?.Id == user.Id).FirstOrDefault();
if (gPlayer == null) if (gPlayer == null)
{ {
using (var dbContext = new DatabaseContext()) using (var dbContext = new DatabaseContext())
@@ -257,12 +249,10 @@ namespace ReallifeGamemode.Server.Gangwar
Player[] attackers = NAPI.Pools.GetAllPlayers().Where(c => c.IsLoggedIn() && c.GetUser().Faction.Name == this.Attacker).ToArray(); Player[] attackers = NAPI.Pools.GetAllPlayers().Where(c => c.IsLoggedIn() && c.GetUser().Faction.Name == this.Attacker).ToArray();
foreach (var o in owners) foreach (var o in owners)
{ {
if (o != null)
o.TriggerEvent("CLIENT:win"); o.TriggerEvent("CLIENT:win");
} }
foreach (var a in attackers) foreach (var a in attackers)
{ {
if (a != null)
a.TriggerEvent("CLIENT:loose"); a.TriggerEvent("CLIENT:loose");
} }
ChatService.BroadcastFaction("~y~[GANGWAR] ~w~Deine Fraktion hat erfolgreich das Gebiet ~g~" + getName() + "~w~ verteidigt.", dbContext.Factions.Where(f => f.Name == getOwner()).FirstOrDefault()); ChatService.BroadcastFaction("~y~[GANGWAR] ~w~Deine Fraktion hat erfolgreich das Gebiet ~g~" + getName() + "~w~ verteidigt.", dbContext.Factions.Where(f => f.Name == getOwner()).FirstOrDefault());
@@ -272,15 +262,8 @@ namespace ReallifeGamemode.Server.Gangwar
else if (getOwner() != FactionName) else if (getOwner() != FactionName)
{ {
ChatService.BroadcastFaction("~y~[GANGWAR] ~w~Deine Fraktion konnte das Gebiet ~r~" + getName() + "~w~ nicht verteidigen.", dbContext.Factions.Where(f => f.Name == getOwner()).FirstOrDefault()); ChatService.BroadcastFaction("~y~[GANGWAR] ~w~Deine Fraktion konnte das Gebiet ~r~" + getName() + "~w~ nicht verteidigen.", dbContext.Factions.Where(f => f.Name == getOwner()).FirstOrDefault());
Console.WriteLine("[DEBUG:GANGWAR] getting owners...");
Player[] owners = NAPI.Pools.GetAllPlayers().Where(c => c.IsLoggedIn() && c.GetUser().Faction.Name == this.Owner).ToArray(); Player[] owners = NAPI.Pools.GetAllPlayers().Where(c => c.IsLoggedIn() && c.GetUser().Faction.Name == this.Owner).ToArray();
Console.WriteLine($"[DEBUG:GANGWAR] got owners {owners}.");
Console.WriteLine($"[DEBUG:GANGWAR] got owners {owners.ToString()}.");
Console.WriteLine("[DEBUG:GANGWAR] getting attackers...");
Player[] attackers = NAPI.Pools.GetAllPlayers().Where(c => c.IsLoggedIn() && c.GetUser().Faction.Name == this.Attacker).ToArray(); Player[] attackers = NAPI.Pools.GetAllPlayers().Where(c => c.IsLoggedIn() && c.GetUser().Faction.Name == this.Attacker).ToArray();
Console.WriteLine($"[DEBUG:GANGWAR] got attackers {attackers}.");
Console.WriteLine($"[DEBUG:GANGWAR] got attackers {attackers.ToString()}.");
foreach (var o in owners) foreach (var o in owners)
{ {
if (o != null) if (o != null)
@@ -303,6 +286,11 @@ namespace ReallifeGamemode.Server.Gangwar
this.Attacker = null; this.Attacker = null;
foreach (var c in playerInGangwar) foreach (var c in playerInGangwar)
{ {
if (!c.IsLoggedIn())
{
continue;
}
c.TriggerEvent("CLIENT:setAttackBlip", false, TurfID); c.TriggerEvent("CLIENT:setAttackBlip", false, TurfID);
c.ResetData("inGangWar"); c.ResetData("inGangWar");
c.ResetData("GotInsideOfTurf"); c.ResetData("GotInsideOfTurf");