diff --git a/ReallifeGamemode.Client/ReallifeGamemode.Client.csproj b/ReallifeGamemode.Client/ReallifeGamemode.Client.csproj
index c5577593..d98e9154 100644
--- a/ReallifeGamemode.Client/ReallifeGamemode.Client.csproj
+++ b/ReallifeGamemode.Client/ReallifeGamemode.Client.csproj
@@ -29,7 +29,6 @@
-
diff --git a/ReallifeGamemode.Client/util/Gangwar.ts b/ReallifeGamemode.Client/util/Gangwar.ts
index ec8690f8..edfa8e7c 100644
--- a/ReallifeGamemode.Client/util/Gangwar.ts
+++ b/ReallifeGamemode.Client/util/Gangwar.ts
@@ -45,6 +45,7 @@
colorZone_b: number;
rotation: number;
owner: string;
+ attacker: string;
blip: BlipMp;
_colshape: ColshapeMp;
vector: Vector3Mp;
@@ -60,28 +61,12 @@
}
_setup(name, id, x, y, range, color, rot, owner, edit) {
-
+
var self = this;
self.name = name;
self.id = id;
self.range = range;
- if (owner === "Ballas") {
- self.color = 83;
- self.colorZone_r = 143;
- self.colorZone_g = 0;
- self.colorZone_b = 199;
- } else if (owner === "GroveStreet") {
- self.color = 2;
- self.colorZone_r = 22;
- self.colorZone_g = 87;
- self.colorZone_b = 0;
- } else if (owner === "Neutral") {
- self.color = 0;
- self.colorZone_r = 255;
- self.colorZone_g = 255;
- self.colorZone_b = 255;
- }
-
+ self.setColor(owner);
self.x = x;
self.y = y;
self.rotation = rot;
@@ -92,11 +77,30 @@
self._inColshape = false;
self._timerCheck;
self.owner = owner;
+ self.attacker = null;
self.edit = edit;
self.loadArea();
}
-
+ setColor(owner) {
+ var self = this;
+ if (owner === "Ballas") {
+ self.color = 83;
+ self.colorZone_r = 143;
+ self.colorZone_g = 0;
+ self.colorZone_b = 199;
+ } else if (owner === "Grove") {
+ self.color = 2;
+ self.colorZone_r = 22;
+ self.colorZone_g = 87;
+ self.colorZone_b = 0;
+ } else if (owner === "Neutral") {
+ self.color = 0;
+ self.colorZone_r = 255;
+ self.colorZone_g = 255;
+ self.colorZone_b = 255;
+ }
+ }
loadArea() {
@@ -149,16 +153,25 @@
y: self.y + range * Math.sin(degrees)
}
let z = mp.game.gameplay.getGroundZFor3dCoord(mp.players.local.position.x, mp.players.local.position.y, mp.players.local.position.z, 0, false);
- //mp.game.graphics.drawLine(bottom_right.x, bottom_right.y, z, bottom_right.x, bottom_right.y, z + 25, 0, 255, 0, 255);
- //mp.game.graphics.drawLine(top_left.x, top_left.y, z, top_left.x, top_left.y, z + 25, 0, 0, 255, 255);
- let a = 0;
- for (var i = z; i < z + 1; i += 0.001) {
- mp.game.graphics.drawLine(top_left.x, top_left.y, i, top_right.x, top_right.y, i, self.colorZone_r, self.colorZone_g, self.colorZone_b, 60 - a * 100);
- mp.game.graphics.drawLine(top_right.x, top_right.y, i, bottom_right.x, bottom_right.y, i, self.colorZone_r, self.colorZone_g, self.colorZone_b, 60 - a * 100);
- mp.game.graphics.drawLine(bottom_right.x, bottom_right.y, i, bottom_left.x, bottom_left.y, i, self.colorZone_r, self.colorZone_g, self.colorZone_b, 60 - a * 100);
- mp.game.graphics.drawLine(bottom_left.x, bottom_left.y, i, top_left.x, top_left.y, i, self.colorZone_r, self.colorZone_g, self.colorZone_b, 60 - a * 100);
- a += 0.001
- }
+ if (self.edit) {
+ mp.game.graphics.drawLine(bottom_right.x, bottom_right.y, z, bottom_right.x, bottom_right.y, z + 25, 0, 255, 0, 255);
+ mp.game.graphics.drawLine(top_left.x, top_left.y, z, top_left.x, top_left.y, z + 25, 0, 0, 255, 255);
+ for (var i = z; i < z + 25; i += 0.5) {
+ mp.game.graphics.drawLine(top_left.x, top_left.y, i, top_right.x, top_right.y, i, 255, 0, 0, 255);
+ mp.game.graphics.drawLine(top_right.x, top_right.y, i, bottom_right.x, bottom_right.y, i, 255, 0, 0, 255);
+ mp.game.graphics.drawLine(bottom_right.x, bottom_right.y, i, bottom_left.x, bottom_left.y, i, 255, 0, 0, 255);
+ mp.game.graphics.drawLine(bottom_left.x, bottom_left.y, i, top_left.x, top_left.y, i, 255, 0, 0, 255);
+ }
+ } else {
+ let a = 0;
+ for (var i = z; i < z + 1; i += 0.001) {
+ mp.game.graphics.drawLine(top_left.x, top_left.y, i, top_right.x, top_right.y, i, self.colorZone_r, self.colorZone_g, self.colorZone_b, 60 - a * 100);
+ mp.game.graphics.drawLine(top_right.x, top_right.y, i, bottom_right.x, bottom_right.y, i, self.colorZone_r, self.colorZone_g, self.colorZone_b, 60 - a * 100);
+ mp.game.graphics.drawLine(bottom_right.x, bottom_right.y, i, bottom_left.x, bottom_left.y, i, self.colorZone_r, self.colorZone_g, self.colorZone_b, 60 - a * 100);
+ mp.game.graphics.drawLine(bottom_left.x, bottom_left.y, i, top_left.x, top_left.y, i, self.colorZone_r, self.colorZone_g, self.colorZone_b, 60 - a * 100);
+ a += 0.001
+ }
+ }
}
if (self.isInsideArea()) {
mp.game.graphics.drawText(self.name, [self.x, self.y, mp.players.local.position.z + 20], {
@@ -177,6 +190,7 @@
var self = this;
if (status == "attack") {
self._status = "attack";
+ self.attacker = args[1];
mp.game.invoke(Natives.SET_BLIP_FLASHES, self.blip, true);
return;
}
@@ -187,9 +201,11 @@
}
if (status == "conquered") {
self._status = "normal";
- self.owner = args[1];
+ self.owner = args[0];
+ self.attacker = null;
mp.game.invoke(Natives.SET_BLIP_FLASHES, self.blip, false);
- self.blip.setColour(args[0]);
+ self.setColor(self.owner)
+ mp.game.invoke(Natives.SET_BLIP_COLOUR, self.blip, self.color);
return;
}
}
@@ -207,7 +223,7 @@
if (self._entered == true) {
if (!self.isInsideArea() || (self.isNearGround() == false)) {
self._entered = false;
- // mp.events.callRemote("Gangarea:Leave", self.id);
+ mp.events.callRemote("Gangarea:Leave", self.id);
}
}
}
@@ -218,12 +234,12 @@
if ((!self._entered)) {
if (self.isInsideArea() && (self.isNearGround() == true)) {
self._entered = true;
- // mp.events.callRemote("Gangarea:Enter", self.id);
+ mp.events.callRemote("Gangarea:Enter", JSON.stringify(self.id));
}
} else if (self._entered == true) {
if (!self.isInsideArea() || (self.isNearGround() == false)) {
self._entered = false;
- //mp.events.callRemote("Gangarea:Leave", self.id);
+ mp.events.callRemote("Gangarea:Leave", JSON.stringify(self.id));
}
}
}, 1000);
@@ -353,5 +369,39 @@
}
});
+ mp.events.add('ADMIN:DeleteTurf', () => {
+ gangturfs.forEach(function (turf) {
+ if (turf._entered == true) {
+ mp.events.callRemote("SERVER:DeleteTurf", JSON.stringify(turf.id));
+ return;
+ }
+ });
+ mp.events.callRemote("SERVER:DeleteTurf", JSON.stringify(-1));
+ });
+
+ mp.events.add('CLIENT:Turf_Update', (jsonId, jsonStatus, jsonOwner, jsonAttacker) => {
+ var id = JSON.parse(jsonId);
+ var status = JSON.parse(jsonStatus);
+ var owner = JSON.parse(jsonOwner);
+ var attacker = JSON.parse(jsonAttacker);
+
+ gangturfs.forEach(function (turf) {
+ if (turf.id == id) {
+ turf.updateArea(status, owner, attacker);
+ }
+ });
+ });
+
+ mp.events.add('CLIENT:ScoreUpdate1', (JSONattackerScore, JSONdefenderScore, JSONid) => {
+ var attackerScore = JSON.parse(JSONattackerScore);
+ var defenderScore = JSON.parse(JSONdefenderScore);
+ var id = JSON.parse(JSONid);
+ gangturfs.forEach(function (turf) {
+ if (turf.id == id) {
+ turf.scoreUpdate(attackerScore, defenderScore);
+ }
+ });
+ });
+
}
\ No newline at end of file
diff --git a/ReallifeGamemode.Server/Commands/AdminCommands.cs b/ReallifeGamemode.Server/Commands/AdminCommands.cs
index a4a85632..d2ba5dfc 100644
--- a/ReallifeGamemode.Server/Commands/AdminCommands.cs
+++ b/ReallifeGamemode.Server/Commands/AdminCommands.cs
@@ -3039,6 +3039,8 @@ namespace ReallifeGamemode.Server.Commands
return;
}
+ player.TriggerEvent("ADMIN:DeleteTurf");
+
}
diff --git a/ReallifeGamemode.Server/Events/Death.cs b/ReallifeGamemode.Server/Events/Death.cs
index f7759e99..faa38807 100644
--- a/ReallifeGamemode.Server/Events/Death.cs
+++ b/ReallifeGamemode.Server/Events/Death.cs
@@ -49,6 +49,11 @@ namespace ReallifeGamemode.Server.Events
killerPosY = killer.Position.Y;
killerPosZ = killer.Position.Z;
killerHeading = killer.Heading;
+ if(player.HasData("inGangWar") && killer.HasData("inGangWar"))
+ {
+
+ }
+
if (player != killer)
{
Autowanted.Check_AutoWanted(killer, player);
@@ -58,7 +63,7 @@ namespace ReallifeGamemode.Server.Events
}
User user = player.GetUser();
- if(user.JailTime <= 0)
+ if(user.JailTime <= 0 && !player.HasData("inGangWar"))
{
//MEDIC AUFTRAG
MedicTask reviveTask = new MedicTask()
diff --git a/ReallifeGamemode.Server/Gangwar/Gangwar.cs b/ReallifeGamemode.Server/Gangwar/Gangwar.cs
index 926683c3..cfce2994 100644
--- a/ReallifeGamemode.Server/Gangwar/Gangwar.cs
+++ b/ReallifeGamemode.Server/Gangwar/Gangwar.cs
@@ -6,6 +6,8 @@ using System.Linq;
using ReallifeGamemode.Database.Models;
using ReallifeGamemode.Database.Entities;
using Newtonsoft.Json;
+using ReallifeGamemode.Server.Services;
+using ReallifeGamemode.Server.Extensions;
namespace ReallifeGamemode.Server.Gangwar
{
@@ -40,12 +42,55 @@ namespace ReallifeGamemode.Server.Gangwar
NAPI.ClientEvent.TriggerClientEventForAll("GangAreas:Create", JsonConvert.SerializeObject(turfs.ToArray()));
}
+ public void GangwarKill(Client killer, Client victim)
+ {
+ if (killer.HasData("GotInsideOfTurf") && victim.HasData("GotInsideOfTurf"))
+ {
+ foreach (var turf in getTurfs())
+ {
+ if (turf.getId() == victim.GetData("inGangWar"))
+ {
+ turf.setKill(victim.GetUser().Faction.Name);
+ return;
+ }
+ }
+ }
+ }
public Turf[] getTurfs()
{
return _loadedTurfs;
}
+ [RemoteEvent("Gangarea:Enter")]
+ public void RmtEvent_TurfEnter(Client client, string jsonId)
+ {
+ int id = JsonConvert.DeserializeObject(jsonId);
+
+ foreach (var turf in getTurfs())
+ {
+ if (turf.getId() == id)
+ {
+ turf.enter(client);
+ return;
+ }
+ }
+ }
+
+ [RemoteEvent("Gangarea:Leave")]
+ public void RmtEvent_TurfLeave(Client client, string jsonId)
+ {
+ int id = JsonConvert.DeserializeObject(jsonId);
+
+ foreach (var turf in getTurfs())
+ {
+ if (turf.getId() == id)
+ {
+ turf.leave(client);
+ return;
+ }
+ }
+ }
[RemoteEvent("SERVER:SetTurf")]
public void RmtEvent_SetTurf(Client client, string jsonX, string jsonY, string jsonRot, string jsonRange, string Name)
@@ -65,13 +110,66 @@ namespace ReallifeGamemode.Server.Gangwar
Owner = "Neutral",
Color = 0
};
- using(var dbContext = new DatabaseContext())
+ using (var dbContext = new DatabaseContext())
{
dbContext.Turfs.Add(newTurf);
dbContext.SaveChanges();
}
loadTurfs();
- loadTurfs_ToAllClients()
+ loadTurfs_ToAllClients();
+ }
+
+ [RemoteEvent("SERVER:DeleteTurf")]
+ public void RmtEvent_DeleteTurf(Client client, string jsonId)
+ {
+ int id = JsonConvert.DeserializeObject(jsonId);
+ if (id == -1)
+ {
+ ChatService.ErrorMessage(client, "Du befindest dich in keinem Gebiet");
+ return;
+ }
+ using (var dbContext = new DatabaseContext())
+ {
+ Turfs dturf = dbContext.Turfs.Where(t => t.Id == id).FirstOrDefault();
+ if (dturf != null)
+ {
+ dbContext.Turfs.Remove(dturf);
+ dbContext.SaveChanges();
+ loadTurfs();
+ loadTurfs_ToAllClients();
+ }
+ }
+ }
+
+ [Command("/gwstart")]
+ public void StartGangwar(Client client)
+ {
+ if (!client.GetUser().FactionLeader)
+ return;
+
+ foreach (var turf in getTurfs())
+ {
+ if (turf.status == "attack")
+ {
+ client.SendChatMessage("Ein GW läuft grad bruder"); // DEBUG
+ return;
+ }
+ }
+ if(client.GetUser().Faction.Name == "Ballas" || client.GetUser().Faction.Name == "Grove")
+ {
+ foreach (var turf in getTurfs())
+ {
+ foreach(var u in turf.playerInside)
+ {
+ if(u == client)
+ {
+ if (turf.Owner != client.GetUser().Faction.Name)
+ turf.attack(client.GetUser().Faction.Name);
+ }
+ }
+ }
+ }
+
}
}
diff --git a/ReallifeGamemode.Server/Gangwar/Turf.cs b/ReallifeGamemode.Server/Gangwar/Turf.cs
index aab2f8e9..43b8638f 100644
--- a/ReallifeGamemode.Server/Gangwar/Turf.cs
+++ b/ReallifeGamemode.Server/Gangwar/Turf.cs
@@ -5,6 +5,10 @@ using GTANetworkAPI;
using System.Timers;
using System.Linq;
using ReallifeGamemode.Server.Extensions;
+using ReallifeGamemode.Database.Models;
+using ReallifeGamemode.Database.Entities;
+using ReallifeGamemode.Server.Services;
+using Newtonsoft.Json;
namespace ReallifeGamemode.Server.Gangwar
{
@@ -21,6 +25,7 @@ namespace ReallifeGamemode.Server.Gangwar
public string status { get; set; }
public Client[] playerInside { get; set; }
public Timer timer { get; set; }
+ public Client[] playerInGangwar { get; set; }
public Turf(int TurfID, string TurfName, int color, string Owner)
@@ -30,8 +35,8 @@ namespace ReallifeGamemode.Server.Gangwar
this.Color = color;
this.Owner = Owner;
this.Attacker = null;
- this.Att_Score = 50;
- this.Def_Score = 50;
+ this.Att_Score = 5;
+ this.Def_Score = 5;
this.status = "normal";
this.playerInside = null;
this.timer = null;
@@ -81,17 +86,17 @@ namespace ReallifeGamemode.Server.Gangwar
private void update()
{
- Client[] owners = this.playerInside.Where(c => c.GetUser().Faction.Name == this.Owner ).ToArray();
- Client[] attackers = this.playerInside.Where(c => c.GetUser().Faction.Name == this.Attacker).ToArray();
+ Client[] owners = this.playerInGangwar.Where(c => c.GetUser().Faction.Name == this.Owner ).ToArray();
+ Client[] attackers = this.playerInGangwar.Where(c => c.GetUser().Faction.Name == this.Attacker).ToArray();
/*
if (owners.Length > attackers.Length)
this.Att_Score -= owners.Length - attackers.Length;
if(owners.Length < attackers.Length)
this.Def_Score -= attackers.Length - owners.Length;
*/
- foreach (Client playerInArea in this.playerInside)
+ foreach (Client gangwarPlayer in this.playerInGangwar)
{
- playerInArea.TriggerEvent("CLIENT:Turf_Update", this.TurfID, this.status, this.Owner, this.Attacker, this.Color, this.Att_Score, this.Def_Score);
+ gangwarPlayer.TriggerEvent("CLIENT:ScoreUpdate", JsonConvert.SerializeObject(this.Att_Score), JsonConvert.SerializeObject(this.Def_Score), JsonConvert.SerializeObject(this.TurfID));
}
if(this.Def_Score <= 0)
{
@@ -104,11 +109,29 @@ namespace ReallifeGamemode.Server.Gangwar
public void enter(Client client)
{
+ if (this.status == "attack")
+ {
+ if (client.GetUser().Faction.Name != getOwner() && client.GetUser().Faction.Name != getAttacker())
+ return;
+ Client gClient = playerInGangwar.Where(c => c.GetUser().Id == client.GetUser().Id).FirstOrDefault();
+ if (gClient == null)
+ {
+ using (var dbContext = new DatabaseContext())
+ {
+ ChatService.BroadcastFaction("~y~[GANGWAR] ~r~" + client.Name + "~w~ ist nicht im Gangwar beteiligt !", dbContext.Factions.Where(f => f.Name == getOwner()).FirstOrDefault());
+ ChatService.BroadcastFaction("~y~[GANGWAR] ~r~" + client.Name + "~w~ ist nicht im Gangwar beteiligt !", dbContext.Factions.Where(f => f.Name == getAttacker()).FirstOrDefault());
+ }
+ return;
+ }
+ }
+
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);
}
}
@@ -124,11 +147,36 @@ namespace ReallifeGamemode.Server.Gangwar
{
this.timer.Stop();
this.timer = null;
-
-
+ using (var dbContext = new DatabaseContext())
+ {
+ if (getOwner() == FactionName)
+ {
+ 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 " + getName() + " 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());
+ }
+ this.Attacker = null;
+ foreach(var c in playerInGangwar)
+ {
+ c.ResetData("inGangWar");
+ c.ResetData("GotInsideOfTurf");
+ }
+ this.playerInGangwar = null;
+ Gangwar.loadTurfs();
+ Gangwar.loadTurfs_ToAllClients();
}
- public void attack(Client client)
+ public void attack(string attacker)
{
if(this.status == "normal")
{
@@ -137,15 +185,40 @@ namespace ReallifeGamemode.Server.Gangwar
this.timer.Stop();
this.timer = null;
}
- this.Attacker = client.GetUser().Faction.Name;
+ this.Attacker = attacker;
this.status = "attack";
- foreach(Client playerInArea in this.playerInside)
+ using (var context = new DatabaseContext())
{
- playerInArea.TriggerEvent("CLIENT:Turf_Update", this.TurfID, this.status, this.Owner, this.Attacker, this.Color, this.Att_Score, this.Def_Score);
+ List clientsInGangwar = new List();
+ User[] usersInGangwar = context.Users.Where(c => c.Faction.Name == getOwner() || c.Faction.Name == getAttacker()).ToArray();
+ foreach(var u in usersInGangwar)
+ {
+ u.Client.SetData("inGangWar", getId());
+ clientsInGangwar.Add(u.Client);
+ }
+ playerInGangwar = clientsInGangwar.ToArray();
}
+ NAPI.ClientEvent.TriggerClientEventForAll("CLIENT:Turf_Update", JsonConvert.SerializeObject(this.TurfID), JsonConvert.SerializeObject(this.status), JsonConvert.SerializeObject(this.Owner), JsonConvert.SerializeObject(this.Attacker));
+
this.TurfTick();
}
}
-
+
+ public void setKill(string FactionName)
+ {
+ if (getOwner() == FactionName)
+ {
+ Def_Score -= 1;
+ }
+ else if (getAttacker() == FactionName)
+ {
+ Att_Score -= 1;
+ }
+
+ foreach (Client gangwarPlayer in this.playerInGangwar)
+ {
+ gangwarPlayer.TriggerEvent("CLIENT:ScoreUpdate1", JsonConvert.SerializeObject(this.Att_Score), JsonConvert.SerializeObject(this.Def_Score), JsonConvert.SerializeObject(this.TurfID));
+ }
+ }
}
}