[+] Add Gangwar System (bugs incl.)

This commit is contained in:
Lukas Moungos
2020-01-13 21:43:55 +01:00
parent 3b0189807e
commit e8321e3ec3
10 changed files with 246 additions and 85 deletions

View File

@@ -1767,7 +1767,6 @@ namespace ReallifeGamemode.Server.Commands
ChatService.SendMessage(player, "~b~[ADMIN]~s~ Du hast hast den Spieler ~y~" + target.Name + "~s~ zum Leader der Fraktion ~o~" + f.Name + "~s~ ernannt.");
ChatService.SendMessage(target, "~b~[ADMIN]~s~ Du wurdest von ~y~" + player.Name + "~s~ zum Leader der Fraktion ~o~" + f.Name + "~s~ ernannt.");
u.FactionLeader = false;
switch (u.FactionId)
{
case null:
@@ -3056,7 +3055,7 @@ namespace ReallifeGamemode.Server.Commands
Gangwar.Gangwar.loadClient(player);
}
[Command("reloadturfs", "~m~Benutzung:~s~ /reloadturfs")]
[Command("reloadturfs", "~m~Benutzung:~s~ /ReloadTurfs")]
public void CmdAdmReloadTurf(Client player)
{
if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
@@ -3067,7 +3066,7 @@ namespace ReallifeGamemode.Server.Commands
Gangwar.Gangwar.loadTurfs();
Gangwar.Gangwar.loadTurfs_ToAllClients();
}
[Command("deleteturf", "~m~Benutzung:~s~ /reloadturfs")]
[Command("deleteturf", "~m~Benutzung:~s~ /DeleteTurfs")]
public void CmdAdmDeleteTurf(Client player)
{
if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
@@ -3077,7 +3076,16 @@ namespace ReallifeGamemode.Server.Commands
}
player.TriggerEvent("ADMIN:DeleteTurf");
}
[Command("setturfpoint", "~m~Benutzung:~s~ /setturfpoint")]
public void CmdAdmSetTurfPoint(Client player)
{
if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
{
ChatService.NotAuthorized(player);
return;
}
player.TriggerEvent("ADMIN:Turf_CreateLeaderBlip");
}
#endregion
#region ALevel1338

View File

@@ -53,6 +53,10 @@ namespace ReallifeGamemode.Server.Events
player.SetData("duty", false);
player.TriggerEvent("SERVER:SET_HANDMONEY", user.Handmoney, 0);
Gangwar.Gangwar.loadClient(player);
if (player.GetUser().FactionLeader)
{
player.TriggerEvent("CLIENT:Turf_LoadLeaderBlip");
}
if (user.IsAdmin(AdminLevel.HEADADMIN) == true)
{
player.SetData("editmode", false);

View File

@@ -40,6 +40,14 @@ namespace ReallifeGamemode.Server.Gangwar
public static void loadTurfs_ToAllClients()
{
NAPI.ClientEvent.TriggerClientEventForAll("GangAreas:Create", JsonConvert.SerializeObject(turfs.ToArray()));
foreach(var l in NAPI.Pools.GetAllPlayers())
{
if (!l.IsLoggedIn() && !l.GetUser().FactionLeader)
return;
l.TriggerEvent("CLIENT:Turf_LoadLeaderBlip");
}
}
public static void GangwarKill(Client killer, Client victim)
@@ -108,7 +116,8 @@ namespace ReallifeGamemode.Server.Gangwar
Rotation = Rot,
Range = Range,
Owner = "Neutral",
Color = 0
Color = 0,
Vector = null
};
using (var dbContext = new DatabaseContext())
{
@@ -141,8 +150,30 @@ namespace ReallifeGamemode.Server.Gangwar
}
}
[Command("/gwstart")]
public void StartGangwar(Client client)
[RemoteEvent("SERVER:Turf_SetNewLeaderPoint")]
public void RmtEvent_SetNewLeaderPoint(Client client, string vector, 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)
{
dturf.Vector = vector;
dbContext.SaveChanges();
loadTurfs();
loadTurfs_ToAllClients();
}
}
}
[RemoteEvent("SERVER:StartGangwar")]
public void RmtEvent_StartGangwar(Client client)
{
if (!client.GetUser().FactionLeader)
return;
@@ -151,7 +182,7 @@ namespace ReallifeGamemode.Server.Gangwar
{
if (turf.status == "attack")
{
client.SendChatMessage("Ein GW läuft grad bruder"); // DEBUG
client.SendChatMessage("Ein GW läuft grad bruder"); // DEBUG //change to smth more serious
return;
}
}

View File

@@ -14,7 +14,7 @@ namespace ReallifeGamemode.Server.Gangwar
{
public class Turf
{
public int TurfID { get; set; }
public string TurfName { get; set; }
public int Color { get; set; }
@@ -36,8 +36,8 @@ namespace ReallifeGamemode.Server.Gangwar
this.Color = color;
this.Owner = Owner;
this.Attacker = null;
this.Att_Score = 5;
this.Def_Score = 5;
this.Att_Score = 50;
this.Def_Score = 50;
this.status = "normal";
this.timer = null;
this.playerInside = new List<Client>();
@@ -68,7 +68,7 @@ namespace ReallifeGamemode.Server.Gangwar
{
return this.Attacker;
}
private void TurfTick()
{
this.timer = new System.Timers.Timer(1000);
@@ -81,7 +81,7 @@ namespace ReallifeGamemode.Server.Gangwar
private void Tick(object sender, System.Timers.ElapsedEventArgs e)
{
if (this.status == "attack")
if(this.status == "attack")
{
update();
}
@@ -91,6 +91,7 @@ namespace ReallifeGamemode.Server.Gangwar
private void update()
{
#region Ticket system
/*
try
{
@@ -113,6 +114,7 @@ namespace ReallifeGamemode.Server.Gangwar
if(owners.Length < attackers.Length)
this.Def_Score -= attackers.Length - owners.Length;
*/
#endregion
foreach (Client gangwarPlayer in this.playerInGangwar)
{
gangwarPlayer.TriggerEvent("GangwarScore", this.Attacker, this.Owner, this.Att_Score, this.Def_Score);
@@ -120,43 +122,40 @@ namespace ReallifeGamemode.Server.Gangwar
if (this.Def_Score <= 0)
{
this.takeOver(this.Attacker);
}
else if (this.Att_Score <= 0)
} else if (this.Att_Score <= 0)
{
this.takeOver(this.Owner);
}
timerCount += 1;
if (timerCount >= 60) //change to 900 before release
if(timerCount >= 900) //change to 900 (seconds) before release for testing reasons change to whatever you like
{
this.timer.Stop();
this.timer = null;
if (this.Def_Score > this.Att_Score)
if(this.Def_Score > this.Att_Score)
{
foreach (Client gangwarPlayer in this.playerInGangwar)
{
gangwarPlayer.TriggerEvent("GangwarScore", this.Attacker, this.Owner, 0, 0);
}
this.takeOver(this.Owner);
this.Att_Score = 0;
}else if(this.Def_Score < this.Att_Score)
{
foreach (Client gangwarPlayer in this.playerInGangwar)
{
gangwarPlayer.TriggerEvent("GangwarScore", this.Attacker, this.Owner, 0, 0);
}
}
else if (this.Def_Score < this.Att_Score)
{
this.takeOver(this.Attacker);
this.Def_Score = 0;
foreach (Client gangwarPlayer in this.playerInGangwar)
{
gangwarPlayer.TriggerEvent("GangwarScore", this.Attacker, this.Owner, 0, 0);
}
return;
}
else if (this.Def_Score == this.Att_Score)
else if(this.Def_Score == this.Att_Score)
{
this.takeOver(this.Attacker);
this.Def_Score = 0;
foreach (Client gangwarPlayer in this.playerInGangwar)
{
gangwarPlayer.TriggerEvent("GangwarScore", this.Attacker, this.Owner, 0, 0);
}
this.takeOver(this.Attacker);
this.Def_Score = 0;
return;
}
}
@@ -179,9 +178,8 @@ namespace ReallifeGamemode.Server.Gangwar
return;
}
}
if (playerInside.Find(c => c == client) == null)
{
if(playerInside.Find(c => c == client) == null) {
playerInside.Add(client);
client.SetData("GotInsideOfTurf", true);
}
@@ -189,10 +187,10 @@ namespace ReallifeGamemode.Server.Gangwar
public void leave(Client client)
{
if (playerInside.Find(c => c == client) != null)
if(playerInside.Find(c => c == client) != null)
{
this.playerInside = this.playerInside.Where(c => c != client).ToList();
if (this.status != "attack")
if(this.status != "attack")
client.ResetData("GotInsideOfTurf");
}
}
@@ -216,14 +214,10 @@ namespace ReallifeGamemode.Server.Gangwar
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());
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)
{
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.IsLoggedIn() && c.GetUser().Faction.Name == this.Owner).ToArray();
Client[] attackers = NAPI.Pools.GetAllPlayers().Where(c => c.IsLoggedIn() && c.GetUser().Faction.Name == this.Attacker).ToArray();
@@ -242,10 +236,10 @@ namespace ReallifeGamemode.Server.Gangwar
turf.FactionId = dbContext.Factions.Where(f => f.Name == this.Owner).FirstOrDefault().Id;
dbContext.SaveChanges();
}
}
this.Attacker = null;
foreach (var c in playerInGangwar)
foreach(var c in playerInGangwar)
{
c.TriggerEvent("CLIENT:setAttackBlip", false, TurfID);
c.ResetData("inGangWar");
@@ -258,9 +252,9 @@ namespace ReallifeGamemode.Server.Gangwar
public void attack(string attacker)
{
if (this.status == "normal")
if(this.status == "normal")
{
if (this.timer != null)
if(this.timer != null)
{
this.timer.Stop();
this.timer = null;
@@ -277,7 +271,7 @@ namespace ReallifeGamemode.Server.Gangwar
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.");
ChatService.SendMessage(u, "~y~[GANGWAR]~w~ Die " + getAttacker() + " haben das Gebiet ~y~"+ TurfName +"~w~ der "+ getOwner() +" angegriffen.");
clientsInGangwar.Add(u);
}
playerInGangwar = clientsInGangwar.ToArray();