[+] Added Gangwar playability

This commit is contained in:
Lukas Moungos
2019-12-01 15:57:37 +01:00
parent ba58c97182
commit a810a5abf8
6 changed files with 278 additions and 51 deletions

View File

@@ -29,7 +29,6 @@
<Folder Include="assets\html\Reportlist\" /> <Folder Include="assets\html\Reportlist\" />
<Folder Include="assets\img\atm\" /> <Folder Include="assets\img\atm\" />
<Folder Include="assets\img\items\" /> <Folder Include="assets\img\items\" />
<Folder Include="Gangwar\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -45,6 +45,7 @@
colorZone_b: number; colorZone_b: number;
rotation: number; rotation: number;
owner: string; owner: string;
attacker: string;
blip: BlipMp; blip: BlipMp;
_colshape: ColshapeMp; _colshape: ColshapeMp;
vector: Vector3Mp; vector: Vector3Mp;
@@ -60,28 +61,12 @@
} }
_setup(name, id, x, y, range, color, rot, owner, edit) { _setup(name, id, x, y, range, color, rot, owner, edit) {
var self = this; var self = this;
self.name = name; self.name = name;
self.id = id; self.id = id;
self.range = range; self.range = range;
if (owner === "Ballas") { self.setColor(owner);
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.x = x; self.x = x;
self.y = y; self.y = y;
self.rotation = rot; self.rotation = rot;
@@ -92,11 +77,30 @@
self._inColshape = false; self._inColshape = false;
self._timerCheck; self._timerCheck;
self.owner = owner; self.owner = owner;
self.attacker = null;
self.edit = edit; self.edit = edit;
self.loadArea(); 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() { loadArea() {
@@ -149,16 +153,25 @@
y: self.y + range * Math.sin(degrees) 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); 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); if (self.edit) {
//mp.game.graphics.drawLine(top_left.x, top_left.y, z, top_left.x, top_left.y, z + 25, 0, 0, 255, 255); mp.game.graphics.drawLine(bottom_right.x, bottom_right.y, z, bottom_right.x, bottom_right.y, z + 25, 0, 255, 0, 255);
let a = 0; 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 + 1; i += 0.001) { 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, self.colorZone_r, self.colorZone_g, self.colorZone_b, 60 - a * 100); 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, 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, 255, 0, 0, 255);
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_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, 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, 255, 0, 0, 255);
a += 0.001 }
} } 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()) { if (self.isInsideArea()) {
mp.game.graphics.drawText(self.name, [self.x, self.y, mp.players.local.position.z + 20], { mp.game.graphics.drawText(self.name, [self.x, self.y, mp.players.local.position.z + 20], {
@@ -177,6 +190,7 @@
var self = this; var self = this;
if (status == "attack") { if (status == "attack") {
self._status = "attack"; self._status = "attack";
self.attacker = args[1];
mp.game.invoke(Natives.SET_BLIP_FLASHES, self.blip, true); mp.game.invoke(Natives.SET_BLIP_FLASHES, self.blip, true);
return; return;
} }
@@ -187,9 +201,11 @@
} }
if (status == "conquered") { if (status == "conquered") {
self._status = "normal"; self._status = "normal";
self.owner = args[1]; self.owner = args[0];
self.attacker = null;
mp.game.invoke(Natives.SET_BLIP_FLASHES, self.blip, false); 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; return;
} }
} }
@@ -207,7 +223,7 @@
if (self._entered == true) { if (self._entered == true) {
if (!self.isInsideArea() || (self.isNearGround() == false)) { if (!self.isInsideArea() || (self.isNearGround() == false)) {
self._entered = 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._entered)) {
if (self.isInsideArea() && (self.isNearGround() == true)) { if (self.isInsideArea() && (self.isNearGround() == true)) {
self._entered = 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) { } else if (self._entered == true) {
if (!self.isInsideArea() || (self.isNearGround() == false)) { if (!self.isInsideArea() || (self.isNearGround() == false)) {
self._entered = false; self._entered = false;
//mp.events.callRemote("Gangarea:Leave", self.id); mp.events.callRemote("Gangarea:Leave", JSON.stringify(self.id));
} }
} }
}, 1000); }, 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);
}
});
});
} }

View File

@@ -3039,6 +3039,8 @@ namespace ReallifeGamemode.Server.Commands
return; return;
} }
player.TriggerEvent("ADMIN:DeleteTurf");
} }

View File

@@ -49,6 +49,11 @@ namespace ReallifeGamemode.Server.Events
killerPosY = killer.Position.Y; killerPosY = killer.Position.Y;
killerPosZ = killer.Position.Z; killerPosZ = killer.Position.Z;
killerHeading = killer.Heading; killerHeading = killer.Heading;
if(player.HasData("inGangWar") && killer.HasData("inGangWar"))
{
}
if (player != killer) if (player != killer)
{ {
Autowanted.Check_AutoWanted(killer, player); Autowanted.Check_AutoWanted(killer, player);
@@ -58,7 +63,7 @@ namespace ReallifeGamemode.Server.Events
} }
User user = player.GetUser(); User user = player.GetUser();
if(user.JailTime <= 0) if(user.JailTime <= 0 && !player.HasData("inGangWar"))
{ {
//MEDIC AUFTRAG //MEDIC AUFTRAG
MedicTask reviveTask = new MedicTask() MedicTask reviveTask = new MedicTask()

View File

@@ -6,6 +6,8 @@ using System.Linq;
using ReallifeGamemode.Database.Models; using ReallifeGamemode.Database.Models;
using ReallifeGamemode.Database.Entities; using ReallifeGamemode.Database.Entities;
using Newtonsoft.Json; using Newtonsoft.Json;
using ReallifeGamemode.Server.Services;
using ReallifeGamemode.Server.Extensions;
namespace ReallifeGamemode.Server.Gangwar namespace ReallifeGamemode.Server.Gangwar
{ {
@@ -40,12 +42,55 @@ namespace ReallifeGamemode.Server.Gangwar
NAPI.ClientEvent.TriggerClientEventForAll("GangAreas:Create", JsonConvert.SerializeObject(turfs.ToArray())); 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() public Turf[] getTurfs()
{ {
return _loadedTurfs; return _loadedTurfs;
} }
[RemoteEvent("Gangarea:Enter")]
public void RmtEvent_TurfEnter(Client client, string jsonId)
{
int id = JsonConvert.DeserializeObject<int>(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<int>(jsonId);
foreach (var turf in getTurfs())
{
if (turf.getId() == id)
{
turf.leave(client);
return;
}
}
}
[RemoteEvent("SERVER:SetTurf")] [RemoteEvent("SERVER:SetTurf")]
public void RmtEvent_SetTurf(Client client, string jsonX, string jsonY, string jsonRot, string jsonRange, string Name) 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", Owner = "Neutral",
Color = 0 Color = 0
}; };
using(var dbContext = new DatabaseContext()) using (var dbContext = new DatabaseContext())
{ {
dbContext.Turfs.Add(newTurf); dbContext.Turfs.Add(newTurf);
dbContext.SaveChanges(); dbContext.SaveChanges();
} }
loadTurfs(); loadTurfs();
loadTurfs_ToAllClients() loadTurfs_ToAllClients();
}
[RemoteEvent("SERVER:DeleteTurf")]
public void RmtEvent_DeleteTurf(Client client, string jsonId)
{
int id = JsonConvert.DeserializeObject<int>(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);
}
}
}
}
} }
} }

View File

@@ -5,6 +5,10 @@ using GTANetworkAPI;
using System.Timers; using System.Timers;
using System.Linq; using System.Linq;
using ReallifeGamemode.Server.Extensions; using ReallifeGamemode.Server.Extensions;
using ReallifeGamemode.Database.Models;
using ReallifeGamemode.Database.Entities;
using ReallifeGamemode.Server.Services;
using Newtonsoft.Json;
namespace ReallifeGamemode.Server.Gangwar namespace ReallifeGamemode.Server.Gangwar
{ {
@@ -21,6 +25,7 @@ namespace ReallifeGamemode.Server.Gangwar
public string status { get; set; } public string status { get; set; }
public Client[] playerInside { get; set; } public Client[] playerInside { get; set; }
public Timer timer { get; set; } public Timer timer { get; set; }
public Client[] playerInGangwar { get; set; }
public Turf(int TurfID, string TurfName, int color, string Owner) public Turf(int TurfID, string TurfName, int color, string Owner)
@@ -30,8 +35,8 @@ namespace ReallifeGamemode.Server.Gangwar
this.Color = color; this.Color = color;
this.Owner = Owner; this.Owner = Owner;
this.Attacker = null; this.Attacker = null;
this.Att_Score = 50; this.Att_Score = 5;
this.Def_Score = 50; this.Def_Score = 5;
this.status = "normal"; this.status = "normal";
this.playerInside = null; this.playerInside = null;
this.timer = null; this.timer = null;
@@ -81,17 +86,17 @@ namespace ReallifeGamemode.Server.Gangwar
private void update() private void update()
{ {
Client[] owners = this.playerInside.Where(c => c.GetUser().Faction.Name == this.Owner ).ToArray(); Client[] owners = this.playerInGangwar.Where(c => c.GetUser().Faction.Name == this.Owner ).ToArray();
Client[] attackers = this.playerInside.Where(c => c.GetUser().Faction.Name == this.Attacker).ToArray(); Client[] attackers = this.playerInGangwar.Where(c => c.GetUser().Faction.Name == this.Attacker).ToArray();
/* /*
if (owners.Length > attackers.Length) if (owners.Length > attackers.Length)
this.Att_Score -= owners.Length - attackers.Length; this.Att_Score -= owners.Length - attackers.Length;
if(owners.Length < attackers.Length) if(owners.Length < attackers.Length)
this.Def_Score -= attackers.Length - owners.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) if(this.Def_Score <= 0)
{ {
@@ -104,11 +109,29 @@ namespace ReallifeGamemode.Server.Gangwar
public void enter(Client client) 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) { if(Array.IndexOf(this.playerInside, client) == -1) {
Client[] refObj = this.playerInside; Client[] refObj = this.playerInside;
Array.Resize(ref refObj, this.playerInside.Length + 1); Array.Resize(ref refObj, this.playerInside.Length + 1);
this.playerInside = refObj; this.playerInside = refObj;
this.playerInside[this.playerInside.GetUpperBound(0)] = client; 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.Stop();
this.timer = null; 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") if(this.status == "normal")
{ {
@@ -137,15 +185,40 @@ namespace ReallifeGamemode.Server.Gangwar
this.timer.Stop(); this.timer.Stop();
this.timer = null; this.timer = null;
} }
this.Attacker = client.GetUser().Faction.Name; this.Attacker = attacker;
this.status = "attack"; 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<Client> clientsInGangwar = new List<Client>();
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(); 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));
}
}
} }
} }