From e81772d3515e8ecb7fbde6f611ba31ca7065d0ae Mon Sep 17 00:00:00 2001 From: Lukas Moungos Date: Sun, 1 Dec 2019 18:14:31 +0100 Subject: [PATCH] fix GW --- ReallifeGamemode.Client/Gui/infobox.ts | 23 ++++++++++++++++++ ReallifeGamemode.Server/Gangwar/Turf.cs | 31 +++++++++++-------------- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/ReallifeGamemode.Client/Gui/infobox.ts b/ReallifeGamemode.Client/Gui/infobox.ts index d0d30ba7..ed02cf02 100644 --- a/ReallifeGamemode.Client/Gui/infobox.ts +++ b/ReallifeGamemode.Client/Gui/infobox.ts @@ -16,6 +16,10 @@ export default function (globalData: GlobalData): void { var adutyMode = false; var dutyMode = false; let jailTime = 0; + let att_score = 0; + let def_score = 0; + let att = null; + let def = null; let countdown = 0; var cdTimestamp; var countdownText; @@ -73,6 +77,13 @@ export default function (globalData: GlobalData): void { jailTime = time; }); + mp.events.add("GangwarScore", (attacker, defender, attscore, defscore) => { + att = attacker; + def = defender; + att_score = attscore; + def_score = defscore; + }); + mp.events.add("countdown", (timer, text) => { countdown = timer; cdTimestamp = Date.now(); @@ -238,6 +249,18 @@ export default function (globalData: GlobalData): void { centre: false }) } + + if (att_score > 0 && def_score > 0) { + mp.game.graphics.drawText("~y~" + def + " " + def_score + " : " + att_score + " " + att, [0.92, 0.50], + { + font: 4, + color: [255, 255, 255, 255], + scale: [0.5, 0.5], + outline: true, + centre: false + }) + } + } if (editMode === true) { mp.game.graphics.drawText("~r~EDIT-MODE AKTIV", [0.5, 0], diff --git a/ReallifeGamemode.Server/Gangwar/Turf.cs b/ReallifeGamemode.Server/Gangwar/Turf.cs index ba06959d..8ced59c4 100644 --- a/ReallifeGamemode.Server/Gangwar/Turf.cs +++ b/ReallifeGamemode.Server/Gangwar/Turf.cs @@ -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 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(); } 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); } } }