Merge branch 'hotfix/turf-death' into develop
This commit is contained in:
@@ -25,9 +25,19 @@ namespace ReallifeGamemode.Server.Events
|
||||
{
|
||||
public class Death : Script
|
||||
{
|
||||
private readonly Dictionary<Player, DateTime> lastPlayerDeathTime = new Dictionary<Player, DateTime>();
|
||||
|
||||
|
||||
[ServerEvent(Event.PlayerDeath)]
|
||||
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())
|
||||
{
|
||||
player.Kick();
|
||||
@@ -51,18 +61,28 @@ namespace ReallifeGamemode.Server.Events
|
||||
float killerPosZ = -1;
|
||||
float killerHeading = -1;
|
||||
|
||||
NAPI.Util.ConsoleOutput($"OnPlayerDeath - Player {player.Name} died - Killer = {(killer != null ? killer.Name : "no killer found")}");
|
||||
|
||||
if (killer.IsLoggedIn())
|
||||
{
|
||||
NAPI.Util.ConsoleOutput($"OnPlayerDeath - Player {player.Name} died - Killer is logged in");
|
||||
|
||||
var killerUser = killer.GetUser(dbContext);
|
||||
if (killerUser != null)
|
||||
{
|
||||
NAPI.Util.ConsoleOutput($"OnPlayerDeath - Player {player.Name} died - Killer GetUser is not null");
|
||||
killerId = killerUser.Id;
|
||||
killerPosX = killer.Position.X;
|
||||
killerPosY = killer.Position.Y;
|
||||
killerPosZ = killer.Position.Z;
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
if (user.Wanteds > 0)
|
||||
@@ -100,7 +136,7 @@ namespace ReallifeGamemode.Server.Events
|
||||
{
|
||||
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
|
||||
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 });
|
||||
}
|
||||
|
||||
player.SetData("isDead", true);
|
||||
player.SetData("isDead", true);
|
||||
|
||||
if (player.GetUser().IsAdmin(AdminLevel.ADMIN) == true)
|
||||
{
|
||||
@@ -157,22 +193,6 @@ namespace ReallifeGamemode.Server.Events
|
||||
|
||||
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);
|
||||
@@ -242,7 +262,7 @@ namespace ReallifeGamemode.Server.Events
|
||||
player.RemoveAllWeapons();
|
||||
MedicTask task = Medic.ReviveTasks.FirstOrDefault(t => t.Victim == player.Name);
|
||||
|
||||
if(task != null)
|
||||
if (task != null)
|
||||
{
|
||||
Player medicPlayer = PlayerService.GetPlayerByNameOrId(task.MedicName);
|
||||
Medic.RemoveTaskFromList(task);
|
||||
|
||||
@@ -49,13 +49,22 @@ namespace ReallifeGamemode.Server.Gangwar
|
||||
|
||||
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())
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,11 +203,16 @@ namespace ReallifeGamemode.Server.Gangwar
|
||||
public void enter(Player client)
|
||||
{
|
||||
User user = client.GetUser();
|
||||
if(user == null || user.FactionId == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.status == "attack")
|
||||
{
|
||||
if (user.Faction.Name != getOwner() && user.Faction.Name != getAttacker())
|
||||
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)
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
@@ -366,10 +371,12 @@ namespace ReallifeGamemode.Server.Gangwar
|
||||
{
|
||||
if (getOwner() == FactionName)
|
||||
{
|
||||
NAPI.Util.ConsoleOutput($"GangwarKill - Adding Point for Faction {getAttacker()}");
|
||||
Att_Score += 1;
|
||||
}
|
||||
else if (getAttacker() == FactionName)
|
||||
{
|
||||
NAPI.Util.ConsoleOutput($"GangwarKill - Adding Point for Faction {getOwner()}");
|
||||
Def_Score += 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user