From 4fa3a312f94b59e05ce569a08cd99d870bcde988 Mon Sep 17 00:00:00 2001 From: Lukas Moungos Date: Wed, 4 Dec 2019 20:21:30 +0100 Subject: [PATCH] add Blips and Sounds to Gangwar --- ReallifeGamemode.Client/util/Gangwar.ts | 32 ++++++++++++++---- ReallifeGamemode.Server/Gangwar/Turf.cs | 45 +++++++++++++++++++++++-- 2 files changed, 68 insertions(+), 9 deletions(-) diff --git a/ReallifeGamemode.Client/util/Gangwar.ts b/ReallifeGamemode.Client/util/Gangwar.ts index 3ba14b8b..ae9fbb0a 100644 --- a/ReallifeGamemode.Client/util/Gangwar.ts +++ b/ReallifeGamemode.Client/util/Gangwar.ts @@ -55,6 +55,7 @@ _inColshape: boolean; _timerCheck; edit: boolean; + attackBlip: BlipMp; constructor(name, id, x, y, range, color, rot, owner, edit) { this._setup(name, id, x, y, range, color, rot, owner, edit); @@ -80,6 +81,7 @@ self.attacker = null; self.edit = edit; self.loadArea(); + self.attackBlip = null; } setColor(owner) { @@ -199,7 +201,7 @@ } if (status == "normal") { self._status = "normal"; - mp.game.invoke(Natives.SET_BLIP_FLASHES, self.blip, false); + mp.game.invoke(Natives.SET_BLIP_FLASHES, self.blip, false); return; } if (status == "conquered") { @@ -213,6 +215,18 @@ } } + setAttackBlip(bool) { + var self = this; + if (bool) { + self.attackBlip = mp.game.ui.addBlipForRadius(self.x, self.y, 1, 3); + mp.game.invoke(Natives.SET_BLIP_SPRITE, self.attackBlip, 378); + mp.game.invoke(Natives.SET_BLIP_FLASHES, self.attackBlip, true); + } else if (!bool) { + mp.game.invoke(Natives.SET_BLIP_ALPHA, self.blip, 0); + mp.game.invoke(Natives.SET_BLIP_FLASHES, self.attackBlip, false); + } + } + isTurfArea(shape) { return (shape == this._colshape) } @@ -237,11 +251,13 @@ if ((!self._entered)) { if (self.isInsideArea() && (self.isNearGround() == true)) { self._entered = true; + mp.game.audio.playSoundFrontend(1, "Enter_Capture_Zone", "DLC_Apartments_Drop_Zone_Sounds", true); mp.events.callRemote("Gangarea:Enter", JSON.stringify(self.id)); } } else if (self._entered == true) { if (!self.isInsideArea() || (self.isNearGround() == false)) { self._entered = false; + mp.game.audio.playSoundFrontend(1, "Exit_Capture_Zone", "DLC_Apartments_Drop_Zone_Sounds", true); mp.events.callRemote("Gangarea:Leave", JSON.stringify(self.id)); } } @@ -331,6 +347,13 @@ }); }); + mp.events.add('CLIENT:loose', () => { + mp.game.audio.playSoundFrontend(1, "Zone_Enemy_Capture", "DLC_Apartments_Drop_Zone_Sounds", true); + }); + mp.events.add('CLIENT:win', () => { + mp.game.audio.playSoundFrontend(1, "Zone_Team_Capture", "DLC_Apartments_Drop_Zone_Sounds", true); + }); + function clearBlips() { mp.game.gameplay.setThisScriptCanRemoveBlipsCreatedByAnyScript(true); var x = 0; @@ -394,13 +417,10 @@ }); }); - mp.events.add('CLIENT:ScoreUpdate1', (JSONattackerScore, JSONdefenderScore, JSONid) => { - var attackerScore = JSON.parse(JSONattackerScore); - var defenderScore = JSON.parse(JSONdefenderScore); - var id = JSON.parse(JSONid); + mp.events.add('CLIENT:setAttackBlip', (bool, id) => { gangturfs.forEach(function (turf) { if (turf.id == id) { - turf.scoreUpdate(attackerScore, defenderScore); + turf.setAttackBlip(bool); } }); }); diff --git a/ReallifeGamemode.Server/Gangwar/Turf.cs b/ReallifeGamemode.Server/Gangwar/Turf.cs index cf867c43..d0f9c84d 100644 --- a/ReallifeGamemode.Server/Gangwar/Turf.cs +++ b/ReallifeGamemode.Server/Gangwar/Turf.cs @@ -26,6 +26,7 @@ namespace ReallifeGamemode.Server.Gangwar public List playerInside { get; set; } public Timer timer { get; set; } public Client[] playerInGangwar { get; set; } + public int timerCount; public Turf(int TurfID, string TurfName, int color, string Owner) @@ -40,6 +41,7 @@ namespace ReallifeGamemode.Server.Gangwar this.status = "normal"; this.timer = null; this.playerInside = new List(); + this.timerCount = 0; } public int getId() @@ -73,7 +75,8 @@ namespace ReallifeGamemode.Server.Gangwar this.timer.Elapsed += Tick; this.timer.AutoReset = true; - this.timer.Enabled = true; + this.timer.Enabled = true; + this.timerCount = 0; } private void Tick(object sender, System.Timers.ElapsedEventArgs e) @@ -84,6 +87,8 @@ namespace ReallifeGamemode.Server.Gangwar } } + + private void update() { /* @@ -119,6 +124,12 @@ namespace ReallifeGamemode.Server.Gangwar { this.takeOver(this.Owner); } + timerCount += 1; + if(timerCount >= 69) + { + this.timer.Stop(); + this.timer = null; + } } public void enter(Client client) @@ -163,23 +174,49 @@ namespace ReallifeGamemode.Server.Gangwar { if (getOwner() == FactionName) { + Client[] owners = NAPI.Pools.GetAllPlayers().Where(c => c.GetUser().Faction.Name == this.Owner).ToArray(); + Client[] attackers = NAPI.Pools.GetAllPlayers().Where(c => c.GetUser().Faction.Name == this.Attacker).ToArray(); + foreach (var o in owners) + { + o.TriggerEvent("CLIENT:win"); + } + foreach (var a in attackers) + { + 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 den Angrif auf das Gebiet ~r~" + getName() + "~w~ verloren.", dbContext.Factions.Where(f => f.Name == getAttacker()).FirstOrDefault()); } else if (getOwner() != FactionName) { - ChatService.BroadcastFaction("~y~[GANGWAR] ~w~Deine Fraktion konnte das Gebiet ~r~" + getName() + "~w~ nicht erobern.", dbContext.Factions.Where(f => f.Name == getAttacker()).FirstOrDefault()); + foreach (var c in playerInGangwar) + { + + } + ChatService.BroadcastFaction("~y~[GANGWAR] ~w~Deine Fraktion konnte das Gebiet ~r~" + getName() + "~w~ nicht verteidigen.", dbContext.Factions.Where(f => f.Name == getOwner()).FirstOrDefault()); + Client[] owners = NAPI.Pools.GetAllPlayers().Where(c => c.GetUser().Faction.Name == this.Owner).ToArray(); + Client[] attackers = NAPI.Pools.GetAllPlayers().Where(c => c.GetUser().Faction.Name == this.Attacker).ToArray(); + foreach (var o in owners) + { + o.TriggerEvent("CLIENT:loose"); + } + foreach (var a in attackers) + { + a.TriggerEvent("CLIENT:win"); + } this.Owner = FactionName; + ChatService.BroadcastFaction("~y~[GANGWAR] ~w~Deine Fraktion konnte erfolgreich das Gebiet ~g~" + getName() + "~w~ verteidigen.", dbContext.Factions.Where(f => f.Name == getOwner()).FirstOrDefault()); 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 konnte erfolgreich das Gebiet ~g~" + getName() + "~w~ verteidigen.", dbContext.Factions.Where(f => f.Name == this.Owner).FirstOrDefault()); + } this.Attacker = null; foreach(var c in playerInGangwar) { + c.TriggerEvent("CLIENT:setAttackBlip", false, TurfID); c.ResetData("inGangWar"); c.ResetData("GotInsideOfTurf"); } @@ -206,8 +243,10 @@ 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("CLIENT:setAttackBlip", true, TurfID); u.TriggerEvent("GangwarScore", this.Attacker, this.Owner, this.Att_Score, this.Def_Score); u.SetData("inGangWar", getId()); + ChatService.SendMessage(u, "~y~[GANGWAR]~w~ Die " + getAttacker() + " hat das Gebiet ~y~"+ TurfName +"~w~ der "+ getOwner() +" angegriffen."); clientsInGangwar.Add(u); } playerInGangwar = clientsInGangwar.ToArray();