145 lines
7.9 KiB
C#
145 lines
7.9 KiB
C#
using System.Linq;
|
|
using Axwabo.Helpers;
|
|
using PlayerRoles;
|
|
using PlayerRoles.PlayableScps;
|
|
using PlayerRoles.PlayableScps.Scp939;
|
|
using PlayerStatsSystem;
|
|
using PluginAPI.Core;
|
|
using UnityEngine;
|
|
|
|
namespace DeathLog;
|
|
|
|
public static class LogHandler {
|
|
|
|
private const string Lime = "#00FF00";
|
|
private const string Cyan = "#00FFF6";
|
|
|
|
private static readonly Color DntColor = new(0.59f, 0.59f, 0.59f);
|
|
|
|
private static bool IsWeapon(ItemType type) => type is ItemType.GunCOM15
|
|
or ItemType.GunCOM18
|
|
or ItemType.GunCom45
|
|
or ItemType.GunFSP9
|
|
or ItemType.GunCrossvec
|
|
or ItemType.GunE11SR
|
|
or ItemType.GunAK
|
|
or ItemType.GunRevolver
|
|
or ItemType.GunShotgun
|
|
or ItemType.GunLogicer
|
|
or ItemType.ParticleDisruptor
|
|
or ItemType.Jailbird
|
|
or ItemType.GrenadeHE
|
|
or ItemType.SCP018
|
|
or ItemType.MicroHID;
|
|
|
|
public static void LogSimpleDeathMessage(Player player, DamageHandlerBase handler, PlayerPermissions permissions) => Log("DEATH LOG" + "#" + string.Format(
|
|
GetDeathMessage(handler),
|
|
GetVictimStatus(player)
|
|
), true, permissions);
|
|
|
|
private static string GetDeathMessage(DamageHandlerBase handler) => handler switch {
|
|
CustomReasonDamageHandler custom => $"{{0}} has died: {custom._deathReason.Bold().Color(Lime).Size(30)}",
|
|
UniversalDamageHandler universal => $"{{0}} has died. Reason: {universal._logsText.TrimEnd('.').Bold().Color(Lime).Size(30)}",
|
|
WarheadDamageHandler => $"{{0}} died to {"the Alpha Warhead".Bold().Color(Lime).Size(30)}",
|
|
_ => $"{{0}} has died. {"Reason is unknown".Italic().Color(Lime)}"
|
|
};
|
|
|
|
public static void LogAttackerDeathMessage(Player victim, Player attacker, AttackerDamageHandler handler, PlayerPermissions permissions) {
|
|
var isCuffed = victim.IsDisarmed;
|
|
var inv = victim.ReferenceHub.inventory;
|
|
var hasWeaponEquipped = IsWeapon(inv.CurItem.TypeId);
|
|
var carriesWeapon = inv.UserInventory.Items.Any(item => IsWeapon(item.Value.ItemTypeId));
|
|
var victimRole = victim.Role;
|
|
var footprint = handler.Attacker;
|
|
var attackerRole = footprint.Role;
|
|
var canBeKos = victimRole == RoleTypeId.ClassD && attackerRole == RoleTypeId.Scientist
|
|
|| victimRole == RoleTypeId.Scientist && attackerRole == RoleTypeId.ClassD
|
|
|| victimRole == RoleTypeId.ClassD && attackerRole is RoleTypeId.FacilityGuard or RoleTypeId.NtfPrivate or RoleTypeId.NtfSergeant or RoleTypeId.NtfSpecialist or RoleTypeId.NtfCaptain;
|
|
Log("KILL LOG".Bold().Color("yellow") + "#" + string.Format(
|
|
GetKillMessage(handler, canBeKos, hasWeaponEquipped, isCuffed, carriesWeapon, PlayerRoleLoader.TryGetRoleTemplate(attackerRole, out FpcStandardScp _)),
|
|
GetKillerStatus(attacker),
|
|
GetVictimStatus(victim)
|
|
), !isCuffed && (!canBeKos || hasWeaponEquipped), permissions);
|
|
}
|
|
|
|
private static void Log(string msg, bool success, PlayerPermissions playerPermissions) {
|
|
foreach (var p in Player.GetPlayers()) {
|
|
var sender = p.ReferenceHub.queryProcessor._sender;
|
|
if (p.RemoteAdminAccess && PermissionsHandler.IsPermitted(sender.Permissions, playerPermissions) && !ToggleLogsCommand.HiddenIdList.Contains(sender.SenderId))
|
|
sender.RaReply(msg, success, true, "");
|
|
}
|
|
}
|
|
|
|
private static string GetIdWithDnt(Player player) {
|
|
var dnt = player.DoNotTrack;
|
|
return $"{(dnt ? "(DNT)".Color(DntColor).Size(50) + " " : "")}{player.UserId.Color(Color.magenta)} {player.PlayerId.ToString().Bold().Color("yellow").Size(30)}";
|
|
}
|
|
|
|
private static object GetKillerStatus(Player attacker) {
|
|
var role = attacker.Rm().CurrentRole;
|
|
return GetIdWithDnt(attacker)
|
|
+ " "
|
|
+ role.RoleName.Color(role.RoleColor.ToHex(true, false)).Size(35)
|
|
+ " " + attacker.Nickname.Bold().Size(35);
|
|
}
|
|
|
|
private static object GetVictimStatus(Player victim) {
|
|
var role = victim.Rm().CurrentRole;
|
|
return GetIdWithDnt(victim).Size(25)
|
|
+ " "
|
|
+ role.RoleName.Color(role.RoleColor.ToHex(true, false)).Size(35)
|
|
+ " " + victim.Nickname.Bold().Size(30);
|
|
}
|
|
|
|
private static string GetKillMessage(AttackerDamageHandler handler, bool canBeKos, bool hasWeaponEquipped, bool cuffed, bool carriesWeapon, bool scpAttacker) =>
|
|
(canBeKos && !hasWeaponEquipped ? "POSSIBLE KOS".Color("red").Size(50) + " " : "")
|
|
+ (cuffed ? "DETAINED KILL ".Color(Cyan).Size(50) + " " : "")
|
|
+ handler switch {
|
|
RecontainmentDamageHandler => $"{{0}} {"recontained".Bold().Color(Lime).Size(35)} {{1}}",
|
|
FirearmDamageHandler firearm => GetFirearmKillLog(firearm),
|
|
ScpDamageHandler => $"{{0}} killed {{1}} using the {"default SCP attack".Bold().Color(Lime).Size(35)}",
|
|
Scp096DamageHandler scp096 => $"{{0}} killed {{1}} using {GetScp096AttackType(scp096).Bold().Color(Lime).Size(35)}",
|
|
Scp049DamageHandler scp049 => $"{{0}} killed {{1}} using {GetScp049AttackType(scp049).Bold().Color(Lime).Size(35)}",
|
|
Scp939DamageHandler scp939 => $"{{0}} killed {{1}} using {GetScp939AttackType(scp939).Bold().Color(Lime).Size(35)}",
|
|
MicroHidDamageHandler => $"{{0}} fried {{1}} with the {"Micro H.I.D.".Bold().Color(Lime).Size(35)}",
|
|
ExplosionDamageHandler => $"{{0}} {"exploded".Bold().Color(Lime).Size(35)} {{1}}",
|
|
Scp018DamageHandler => $"{{0}} killed {{1}} with {"SCP-018".Bold().Color(Lime).Size(35)}",
|
|
DisruptorDamageHandler => $"{{0}} killed {{1}} with the {"3-X Particle Disruptor".Bold().Color(Lime).Size(35)}",
|
|
JailbirdDamageHandler => $"{{0}} killed {{1}} with the {"Jailbird".Bold().Color(Lime).Size(35)}",
|
|
_ => $"{{0}} killed {{1}}. {"Reason is unknown".Italic().Color(Lime)}"
|
|
}
|
|
+ WeaponStatusMessage(!scpAttacker, hasWeaponEquipped, carriesWeapon);
|
|
|
|
private static string WeaponStatusMessage(bool show, bool hasWeaponEquipped, bool carriesWeapon) => show && (carriesWeapon || hasWeaponEquipped) ? (hasWeaponEquipped ? " Victim was " + "holding".Underline() + " a weapon." : " Victim was " + "carrying".Underline() + " a weapon.").Color(Cyan).Size(30) : "";
|
|
|
|
private static string GetFirearmKillLog(FirearmDamageHandler firearm) => $"{{0}} shot {{1}} with {firearm.WeaponType.ToString().Bold().Color("red").Size(35)} to the hitbox " + firearm.Hitbox.ToString().Color("red").Bold().Size(35);
|
|
|
|
private static string GetScp096AttackType(Scp096DamageHandler scp096) => scp096._attackType switch {
|
|
Scp096DamageHandler.AttackType.Charge => "Charge",
|
|
Scp096DamageHandler.AttackType.SlapLeft => "Left Slap",
|
|
Scp096DamageHandler.AttackType.SlapRight => "Right Slap",
|
|
Scp096DamageHandler.AttackType.GateKill => "Gate Kill",
|
|
_ => "[an unknown attack type]"
|
|
};
|
|
|
|
private static string GetScp049AttackType(Scp049DamageHandler scp049) => scp049.DamageSubType switch {
|
|
Scp049DamageHandler.AttackType.Instakill => "Instakill",
|
|
Scp049DamageHandler.AttackType.Scp0492 => "SCP-049-2",
|
|
Scp049DamageHandler.AttackType.CardiacArrest => "Cardiac Arrest",
|
|
_ => "[an unknown attack type]"
|
|
};
|
|
|
|
private static string GetScp939AttackType(Scp939DamageHandler scp939) => scp939._damageType switch {
|
|
Scp939DamageType.Claw => "Claw",
|
|
Scp939DamageType.LungeSecondary => "Lunge Secondary",
|
|
Scp939DamageType.LungeTarget => "Lunge Target",
|
|
_ => "[an unknown attack type]"
|
|
};
|
|
|
|
public static void LogLeavingScp(string role, float health, float hs, PlayerPermissions permissions) =>
|
|
Log($"{"SCP Left".Color("red").Bold()}#Please replace {role.Size(40)} as the player has left the game.\n" +
|
|
($"HP: {((int) health).ToString().Color("red")} " +
|
|
$"HS: {((int) hs).ToString().Color("purple")}").Size(35), false, permissions);
|
|
|
|
}
|