Merge branch 'hotfix/turf-death' into develop

This commit is contained in:
hydrant
2021-04-18 03:39:56 +02:00
3 changed files with 59 additions and 23 deletions

View File

@@ -25,9 +25,19 @@ namespace ReallifeGamemode.Server.Events
{ {
public class Death : Script public class Death : Script
{ {
private readonly Dictionary<Player, DateTime> lastPlayerDeathTime = new Dictionary<Player, DateTime>();
[ServerEvent(Event.PlayerDeath)] [ServerEvent(Event.PlayerDeath)]
public void OnPlayerDeath(Player player, Player killer, uint reason) public void OnPlayerDeath(Player player, Player killer, uint reason)
{ {
if (lastPlayerDeathTime.TryGetValue(player, out DateTime lastDeathTime) && DateTime.Now - lastDeathTime < TimeSpan.FromSeconds(5))
{
return;
}
lastPlayerDeathTime[player] = DateTime.Now;
if (!player.IsLoggedIn()) if (!player.IsLoggedIn())
{ {
player.Kick(); player.Kick();
@@ -51,18 +61,28 @@ namespace ReallifeGamemode.Server.Events
float killerPosZ = -1; float killerPosZ = -1;
float killerHeading = -1; float killerHeading = -1;
NAPI.Util.ConsoleOutput($"OnPlayerDeath - Player {player.Name} died - Killer = {(killer != null ? killer.Name : "no killer found")}");
if (killer.IsLoggedIn()) if (killer.IsLoggedIn())
{ {
NAPI.Util.ConsoleOutput($"OnPlayerDeath - Player {player.Name} died - Killer is logged in");
var killerUser = killer.GetUser(dbContext); var killerUser = killer.GetUser(dbContext);
if (killerUser != null) if (killerUser != null)
{ {
NAPI.Util.ConsoleOutput($"OnPlayerDeath - Player {player.Name} died - Killer GetUser is not null");
killerId = killerUser.Id; killerId = killerUser.Id;
killerPosX = killer.Position.X; killerPosX = killer.Position.X;
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"))
var playerInGangwar = player.HasData("inGangWar");
var killerInGangwar = killer.HasData("inGangWar");
NAPI.Util.ConsoleOutput($"OnPlayerDeath - Player {player.Name} died - PlayerInGangwar = {playerInGangwar}, KillerInGangwar = {killerInGangwar}");
if (playerInGangwar && killerInGangwar)
{ {
NAPI.Util.ConsoleOutput($"OnPlayerDeath - Player {player.Name} died - Both players in gangwar, setting kill");
Gangwar.Gangwar.GangwarKill(killer, player); Gangwar.Gangwar.GangwarKill(killer, player);
} }
@@ -78,6 +98,22 @@ namespace ReallifeGamemode.Server.Events
} }
} }
var dead = new Database.Entities.Logs.Death
{
VictimId = player.GetUser().Id,
KillerId = killerId,
KillerPositionX = killerPosX,
KillerPositionY = killerPosY,
KillerPositionZ = killerPosZ,
KillerHeading = killerHeading,
VictimPositionX = player.Position.X,
VictimPositionY = player.Position.Y,
VictimPositionZ = player.Position.Z,
VictimHeading = player.Heading,
CauseOfDeath = reason.ToString()
};
dbContext.DeathLogs.Add(dead);
bool copNearby = NAPI.Pools.GetAllPlayers().Any(u => u.IsDuty() && u.IsAlive() && u.Position.DistanceToSquared(player.Position) <= 200 * 200); bool copNearby = NAPI.Pools.GetAllPlayers().Any(u => u.IsDuty() && u.IsAlive() && u.Position.DistanceToSquared(player.Position) <= 200 * 200);
if (user.Wanteds > 0) if (user.Wanteds > 0)
@@ -100,7 +136,7 @@ namespace ReallifeGamemode.Server.Events
{ {
user.Dead = true; user.Dead = true;
if (!player.HasData("reviveSperre") && player.GetData<bool>("isDead") == false && !player.HasData("inGangWar") && player.GetData<bool>("SAdminduty") == false) if (!player.HasData("reviveSperre") && player.GetData<bool>("isDead") == false && !player.HasData("inGangWar") && player.GetData<bool>("SAdminduty") == false)
{ {
//MEDIC AUFTRAG //MEDIC AUFTRAG
MedicTask reviveTask = new MedicTask() MedicTask reviveTask = new MedicTask()
@@ -118,7 +154,7 @@ namespace ReallifeGamemode.Server.Events
ChatService.BroadcastFaction("~y~[MEDIC] ~w~" + player.Name + " ist soeben verstorben.", new List<int>() { 2 }); ChatService.BroadcastFaction("~y~[MEDIC] ~w~" + player.Name + " ist soeben verstorben.", new List<int>() { 2 });
} }
player.SetData("isDead", true); player.SetData("isDead", true);
if (player.GetUser().IsAdmin(AdminLevel.ADMIN) == true) if (player.GetUser().IsAdmin(AdminLevel.ADMIN) == true)
{ {
@@ -157,22 +193,6 @@ namespace ReallifeGamemode.Server.Events
dbContext.Remove(item); dbContext.Remove(item);
} }
var dead = new Database.Entities.Logs.Death
{
VictimId = player.GetUser().Id,
KillerId = killerId,
KillerPositionX = killerPosX,
KillerPositionY = killerPosY,
KillerPositionZ = killerPosZ,
KillerHeading = killerHeading,
VictimPositionX = player.Position.X,
VictimPositionY = player.Position.Y,
VictimPositionZ = player.Position.Z,
VictimHeading = player.Heading,
CauseOfDeath = reason.ToString()
};
dbContext.DeathLogs.Add(dead);
} }
} }
Job.JobBase job = Managers.JobManager.GetJob(player.GetUser().JobId ?? -1); Job.JobBase job = Managers.JobManager.GetJob(player.GetUser().JobId ?? -1);
@@ -242,7 +262,7 @@ namespace ReallifeGamemode.Server.Events
player.RemoveAllWeapons(); player.RemoveAllWeapons();
MedicTask task = Medic.ReviveTasks.FirstOrDefault(t => t.Victim == player.Name); MedicTask task = Medic.ReviveTasks.FirstOrDefault(t => t.Victim == player.Name);
if(task != null) if (task != null)
{ {
Player medicPlayer = PlayerService.GetPlayerByNameOrId(task.MedicName); Player medicPlayer = PlayerService.GetPlayerByNameOrId(task.MedicName);
Medic.RemoveTaskFromList(task); Medic.RemoveTaskFromList(task);

View File

@@ -49,13 +49,22 @@ namespace ReallifeGamemode.Server.Gangwar
public static void GangwarKill(Player killer, Player victim) public static void GangwarKill(Player killer, Player victim)
{ {
if (killer.HasData("GotInsideOfTurf") && victim.HasData("GotInsideOfTurf")) var killerInsideTurf = killer.HasData("GotInsideOfTurf");
var victimInsideTurf = victim.HasData("GotInsideOfTurf");
NAPI.Util.ConsoleOutput($"GangwarKill - Victim {victim.Name} - KillerInsideTurf = {killerInsideTurf}, VictimInsideTurf = {victimInsideTurf}");
if (killerInsideTurf && victimInsideTurf)
{ {
NAPI.Util.ConsoleOutput($"GangwarKill - Victim {victim.Name} - Killer and Victim are in Turf area");
foreach (var turf in getTurfs()) foreach (var turf in getTurfs())
{ {
if (turf.getId() == victim.GetData<int>("inGangWar")) if (turf.getId() == victim.GetData<int>("inGangWar"))
{ {
turf.setKill(victim.GetUser().Faction.Name); NAPI.Util.ConsoleOutput($"GangwarKill - Victim {victim.Name} - Killed in turf id {turf.getId()}");
var victimFactionName = victim.GetUser().Faction.Name;
NAPI.Util.ConsoleOutput($"GangwarKill - Victim {victim.Name} - Faction Name = {victimFactionName}");
turf.setKill(victimFactionName);
return; return;
} }
} }

View File

@@ -203,11 +203,16 @@ namespace ReallifeGamemode.Server.Gangwar
public void enter(Player client) public void enter(Player client)
{ {
User user = client.GetUser(); User user = client.GetUser();
if(user == null || user.FactionId == null)
{
return;
}
if (this.status == "attack") if (this.status == "attack")
{ {
if (user.Faction.Name != getOwner() && user.Faction.Name != getAttacker()) if (user.Faction.Name != getOwner() && user.Faction.Name != getAttacker())
return; return;
Player gPlayer = playerInGangwar.Where(c => c != null && !c.Handle.IsNull && c.IsLoggedIn() && c.GetUser()?.Id == user.Id).FirstOrDefault(); Player gPlayer = playerInGangwar.Where(c => c != null && !c.Handle.IsNull && c.IsLoggedIn() && c.Handle.Value == client.Handle.Value).FirstOrDefault();
if (gPlayer == null) if (gPlayer == null)
{ {
using (var dbContext = new DatabaseContext()) using (var dbContext = new DatabaseContext())
@@ -366,10 +371,12 @@ namespace ReallifeGamemode.Server.Gangwar
{ {
if (getOwner() == FactionName) if (getOwner() == FactionName)
{ {
NAPI.Util.ConsoleOutput($"GangwarKill - Adding Point for Faction {getAttacker()}");
Att_Score += 1; Att_Score += 1;
} }
else if (getAttacker() == FactionName) else if (getAttacker() == FactionName)
{ {
NAPI.Util.ConsoleOutput($"GangwarKill - Adding Point for Faction {getOwner()}");
Def_Score += 1; Def_Score += 1;
} }
} }