From 81f8aed6476105afccd222539f83a273f817a85d Mon Sep 17 00:00:00 2001 From: hydrant Date: Fri, 9 Apr 2021 19:47:03 +0200 Subject: [PATCH] [HOTFIX] Gangwar starten crasht Server nicht mehr --- ReallifeGamemode.Server/Gangwar/Turf.cs | 116 ++++++++++++------------ 1 file changed, 56 insertions(+), 60 deletions(-) diff --git a/ReallifeGamemode.Server/Gangwar/Turf.cs b/ReallifeGamemode.Server/Gangwar/Turf.cs index 62321bcc..ea2f3ea0 100644 --- a/ReallifeGamemode.Server/Gangwar/Turf.cs +++ b/ReallifeGamemode.Server/Gangwar/Turf.cs @@ -133,79 +133,70 @@ namespace ReallifeGamemode.Server.Gangwar private void update() { - #region Ticket system - - /* - try + NAPI.Task.Run(() => { - 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) + foreach (Player gangwarPlayer in this.playerInGangwar) { - if (!NAPI.Entity.DoesEntityExist(c.Handle)) + if(!gangwarPlayer.IsLoggedIn()) { - this.playerInside = this.playerInside.Where(gp => gp != c).ToArray(); + continue; } - i++; + + gangwarPlayer.TriggerEvent("GangwarScore", this.Attacker, this.Owner, this.Att_Score, this.Def_Score, 900 - timerCount); } - } - 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) - { - gangwarPlayer.TriggerEvent("GangwarScore", this.Attacker, this.Owner, this.Att_Score, this.Def_Score, 900 - timerCount); - } - /*if (this.Att_Score >= 200) - { - this.takeOver(this.Attacker); - } - else if (this.Def_Score >= 200) - { - this.takeOver(this.Owner); - }*/ - timerCount += 1; - 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 >= 200) { - foreach (Player gangwarPlayer in this.playerInGangwar) - { - gangwarPlayer.TriggerEvent("GangwarScore", this.Attacker, this.Owner, 0, 0, 0); - } this.takeOver(this.Attacker); - this.Def_Score = 0; - return; } - else if (this.Att_Score < this.Def_Score) + else if (this.Def_Score >= 200) { - foreach (Player gangwarPlayer in this.playerInGangwar) - { - gangwarPlayer.TriggerEvent("GangwarScore", this.Attacker, this.Owner, 0, 0, 0); - } this.takeOver(this.Owner); - this.Att_Score = 0; - return; - } - else if (this.Def_Score == this.Att_Score) + }*/ + timerCount += 1; + if (timerCount >= 900) //change to 900 (seconds) before release for testing reasons change to whatever you like { - foreach (Player gangwarPlayer in this.playerInGangwar) + if (this.Att_Score > this.Def_Score) { - gangwarPlayer.TriggerEvent("GangwarScore", this.Attacker, this.Owner, 0, 0, 0); + foreach (Player gangwarPlayer in this.playerInGangwar) + { + if(!gangwarPlayer.IsLoggedIn()) + { + continue; + } + + gangwarPlayer.TriggerEvent("GangwarScore", this.Attacker, this.Owner, 0, 0, 0); + } + this.takeOver(this.Attacker); + this.Def_Score = 0; + return; + } + else if (this.Att_Score < this.Def_Score) + { + foreach (Player gangwarPlayer in this.playerInGangwar) + { + gangwarPlayer.TriggerEvent("GangwarScore", this.Attacker, this.Owner, 0, 0, 0); + } + this.takeOver(this.Owner); + this.Att_Score = 0; + return; + } + else if (this.Def_Score == this.Att_Score) + { + foreach (Player gangwarPlayer in this.playerInGangwar) + { + if (!gangwarPlayer.IsLoggedIn()) + { + continue; + } + + gangwarPlayer.TriggerEvent("GangwarScore", this.Attacker, this.Owner, 0, 0, 0); + } + this.takeOver(this.Owner); + this.Def_Score = 0; + return; } - this.takeOver(this.Owner); - this.Def_Score = 0; - return; } - } + }); } public void enter(Player client) @@ -215,7 +206,7 @@ namespace ReallifeGamemode.Server.Gangwar { if (user.Faction.Name != getOwner() && user.Faction.Name != getAttacker()) 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) { using (var dbContext = new DatabaseContext()) @@ -294,6 +285,11 @@ namespace ReallifeGamemode.Server.Gangwar this.Attacker = null; foreach (var c in playerInGangwar) { + if (!c.IsLoggedIn()) + { + continue; + } + c.TriggerEvent("CLIENT:setAttackBlip", false, TurfID); c.ResetData("inGangWar"); c.ResetData("GotInsideOfTurf");