diff --git a/DeathLog/DeathLogConfig.cs b/DeathLog/DeathLogConfig.cs index 06d89b8..2b9d210 100644 --- a/DeathLog/DeathLogConfig.cs +++ b/DeathLog/DeathLogConfig.cs @@ -8,4 +8,8 @@ public sealed class DeathLogConfig { public bool LogLeavingScpPlayers { get; set; } = true; + public bool KillOnSightPermitted { get; set; } = false; + + public float DefaultFontSizeScalar { get; set; } = 1; + } diff --git a/DeathLog/DeathLogPlugin.cs b/DeathLog/DeathLogPlugin.cs index eb68e1c..87cc422 100644 --- a/DeathLog/DeathLogPlugin.cs +++ b/DeathLog/DeathLogPlugin.cs @@ -10,7 +10,7 @@ namespace DeathLog; public sealed class DeathLogPlugin { - [PluginEntryPoint("DeathLog", "1.0.0", "DeathLog", "Axwabo")] + [PluginEntryPoint("DeathLog", "1.1.0", "DeathLog", "Axwabo")] public void OnEnabled() { PluginAPI.Events.EventManager.RegisterEvents(this); Log.Info("DeathLog loaded!"); @@ -42,9 +42,9 @@ public sealed class DeathLogPlugin { [PluginEvent(ServerEventType.PlayerDying)] private void OnPlayerDeath(Player player, Player attacker, DamageHandlerBase handler) { if (attacker != null && handler is AttackerDamageHandler adh) - LogHandler.LogAttackerDeathMessage(player, attacker, adh, Config.VisibilityRequirement); + LogHandler.LogAttackerDeathMessage(player, attacker, adh, Config.VisibilityRequirement, Config.KillOnSightPermitted, Config.DefaultFontSizeScalar); else if (Config.LogSimpleDeaths) - LogHandler.LogSimpleDeathMessage(player, handler, Config.VisibilityRequirement); + LogHandler.LogSimpleDeathMessage(player, handler, Config.VisibilityRequirement, Config.DefaultFontSizeScalar); if (!IsUnknownCause(handler) || player.ReferenceHub.roleManager.CurrentRole is not FpcStandardScp scp) return; _lastRole = scp.RoleName.Color(scp.RoleColor.ToHex()); @@ -68,7 +68,7 @@ public sealed class DeathLogPlugin { [PluginEvent(ServerEventType.PlayerLeft)] private void OnPlayerLeave(Player player) { if (!_spawnWaveOccurred && Config.LogLeavingScpPlayers && player.UserId == _lastId) - LogHandler.LogLeavingScp(_lastRole, _lastHealth, _lastHumeShield, Config.VisibilityRequirement); + LogHandler.LogLeavingScp(_lastRole, _lastHealth, _lastHumeShield, Config.VisibilityRequirement, Config.DefaultFontSizeScalar); } } diff --git a/DeathLog/LogHandler.cs b/DeathLog/LogHandler.cs index 0925ae5..f33be61 100644 --- a/DeathLog/LogHandler.cs +++ b/DeathLog/LogHandler.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; using Axwabo.Helpers; using PlayerRoles; using PlayerRoles.PlayableScps; @@ -32,19 +33,19 @@ public static class LogHandler { 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); + public static void LogSimpleDeathMessage(Player player, DamageHandlerBase handler, PlayerPermissions permissions, float defaultScalar) => Log(sizeScalar => "DEATH LOG" + "#" + string.Format( + GetDeathMessage(handler, sizeScalar), + GetVictimStatus(player, sizeScalar) + ), true, permissions, defaultScalar); - 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)}", + private static string GetDeathMessage(DamageHandlerBase handler, float sizeScalar) => handler switch { + CustomReasonDamageHandler custom => $"{{0}} has died: {custom._deathReason.Bold().Color(Lime).Size(30.Scale(sizeScalar))}", + UniversalDamageHandler universal => $"{{0}} has died. Reason: {universal._logsText.TrimEnd('.').Bold().Color(Lime).Size(30.Scale(sizeScalar))}", + WarheadDamageHandler => $"{{0}} died to {"the Alpha Warhead".Bold().Color(Lime).Size(30.Scale(sizeScalar))}", _ => $"{{0}} has died. {"Reason is unknown".Italic().Color(Lime)}" }; - public static void LogAttackerDeathMessage(Player victim, Player attacker, AttackerDamageHandler handler, PlayerPermissions permissions) { + public static void LogAttackerDeathMessage(Player victim, Player attacker, AttackerDamageHandler handler, PlayerPermissions permissions, bool kosPermitted, float defaultScalar) { var isCuffed = victim.IsDisarmed; var inv = victim.ReferenceHub.inventory; var hasWeaponEquipped = IsWeapon(inv.CurItem.TypeId); @@ -52,70 +53,82 @@ public static class LogHandler { 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); + var canBeKos = !kosPermitted && IsKos(victimRole, attackerRole); + Log(sizeScalar => "KILL LOG".Bold().Color("yellow") + "#" + string.Format( + GetKillMessage(handler, canBeKos, hasWeaponEquipped, isCuffed, carriesWeapon, PlayerRoleLoader.TryGetRoleTemplate(attackerRole, out FpcStandardScp _), sizeScalar), + GetKillerStatus(attacker, sizeScalar), + GetVictimStatus(victim, sizeScalar) + ), !isCuffed && (!canBeKos || hasWeaponEquipped), permissions, defaultScalar); } - private static void Log(string msg, bool success, PlayerPermissions playerPermissions) { + private static bool IsKos(RoleTypeId victimRole, RoleTypeId attackerRole) => + 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; + + private static void Log(Func msg, bool success, PlayerPermissions playerPermissions, float defaultScalar) { 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, ""); + if (!p.RemoteAdminAccess || !PermissionsHandler.IsPermitted(sender.Permissions, playerPermissions) || ToggleLogsCommand.HiddenIdList.Contains(sender.SenderId)) + continue; + var scalar = ToggleLogsCommand.SizeScalar.TryGetValue(sender.SenderId, out var sizeScalar) ? sizeScalar : defaultScalar; + sender.RaReply(msg(scalar), success, true, ""); } } - private static string GetIdWithDnt(Player player) { + private static string GetIdWithDnt(Player player, float sizeScalar) { var dnt = player.DoNotTrack; - return $"{(dnt ? "(DNT)".Color(DntColor).Size(50) + " " : "")}{player.UserId.Color(Color.magenta)} {player.PlayerId.ToString().Bold().Color("yellow").Size(30)}"; + return $"{(dnt ? "(DNT)".Color(DntColor).Size(50.Scale(sizeScalar)) + " " : "")}{player.UserId.Color(Color.magenta)} {player.PlayerId.ToString().Bold().Color("yellow").Size(30.Scale(sizeScalar))}"; } - private static object GetKillerStatus(Player attacker) { + private static object GetKillerStatus(Player attacker, float sizeScalar) { var role = attacker.Rm().CurrentRole; - return GetIdWithDnt(attacker) + return GetIdWithDnt(attacker, sizeScalar) + " " - + role.RoleName.Color(role.RoleColor.ToHex(true, false)).Size(35) - + " " + attacker.Nickname.Bold().Size(35); + + role.RoleName.Color(role.RoleColor.ToHex(true, false)).Size(35.Scale(sizeScalar)) + + " " + attacker.Nickname.Bold().Size(35.Scale(sizeScalar)); } - private static object GetVictimStatus(Player victim) { + private static object GetVictimStatus(Player victim, float sizeScalar) { var role = victim.Rm().CurrentRole; - return GetIdWithDnt(victim).Size(25) + return GetIdWithDnt(victim, sizeScalar).Size(25.Scale(sizeScalar)) + " " - + role.RoleName.Color(role.RoleColor.ToHex(true, false)).Size(35) - + " " + victim.Nickname.Bold().Size(30); + + role.RoleName.Color(role.RoleColor.ToHex(true, false)).Size(35.Scale(sizeScalar)) + + " " + victim.Nickname.Bold().Size(30.Scale(sizeScalar)); } - 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) + " " : "") + private static string GetKillMessage(AttackerDamageHandler handler, bool canBeKos, bool hasWeaponEquipped, bool cuffed, bool carriesWeapon, bool scpAttacker, float sizeScalar) => + (canBeKos && !hasWeaponEquipped ? "POSSIBLE KOS".Color("red").Size(50.Scale(sizeScalar)) + " " : "") + + (cuffed ? "DETAINED KILL ".Color(Cyan).Size(50.Scale(sizeScalar)) + " " : "") + 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)}", + RecontainmentDamageHandler => $"{{0}} {"recontained".Bold().Color(Lime).Size(35.Scale(sizeScalar))} {{1}}", + FirearmDamageHandler firearm => GetFirearmKillLog(firearm, sizeScalar), + ScpDamageHandler => $"{{0}} killed {{1}} using the {"default SCP attack".Bold().Color(Lime).Size(35.Scale(sizeScalar))}", + Scp096DamageHandler scp096 => $"{{0}} killed {{1}} using {GetScp096AttackType(scp096).Bold().Color(Lime).Size(35.Scale(sizeScalar))}", + Scp049DamageHandler scp049 => $"{{0}} killed {{1}} using {GetScp049AttackType(scp049).Bold().Color(Lime).Size(35.Scale(sizeScalar))}", + Scp939DamageHandler scp939 => $"{{0}} killed {{1}} using {GetScp939AttackType(scp939).Bold().Color(Lime).Size(35.Scale(sizeScalar))}", + MicroHidDamageHandler => $"{{0}} fried {{1}} with the {"Micro H.I.D.".Bold().Color(Lime).Size(35.Scale(sizeScalar))}", + ExplosionDamageHandler => $"{{0}} {"exploded".Bold().Color(Lime).Size(35.Scale(sizeScalar))} {{1}}", + Scp018DamageHandler => $"{{0}} killed {{1}} with {"SCP-018".Bold().Color(Lime).Size(35.Scale(sizeScalar))}", + DisruptorDamageHandler => $"{{0}} killed {{1}} with the {"3-X Particle Disruptor".Bold().Color(Lime).Size(35.Scale(sizeScalar))}", + JailbirdDamageHandler => $"{{0}} killed {{1}} with the {"Jailbird".Bold().Color(Lime).Size(35.Scale(sizeScalar))}", _ => $"{{0}} killed {{1}}. {"Reason is unknown".Italic().Color(Lime)}" } - + WeaponStatusMessage(!scpAttacker, hasWeaponEquipped, carriesWeapon); + + WeaponStatusMessage(!scpAttacker, hasWeaponEquipped, carriesWeapon, sizeScalar); - 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 WeaponStatusMessage(bool show, bool hasWeaponEquipped, bool carriesWeapon, float sizeScalar) => + show && (carriesWeapon || hasWeaponEquipped) + ? (hasWeaponEquipped + ? " Victim was " + "holding".Underline() + " a weapon." + : " Victim was " + "carrying".Underline() + " a weapon." + ).Color(Cyan).Size(30.Scale(sizeScalar)) + : ""; - 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 GetFirearmKillLog(FirearmDamageHandler firearm, float sizeScalar) => + $"{{0}} shot {{1}} with {firearm.WeaponType.ToString().Bold().Color("red").Size(35.Scale(sizeScalar))} to the hitbox " + firearm.Hitbox.ToString().Color("red").Bold().Size(35.Scale(sizeScalar)); private static string GetScp096AttackType(Scp096DamageHandler scp096) => scp096._attackType switch { - Scp096DamageHandler.AttackType.Charge => "Charge", + Scp096DamageHandler.AttackType.Charge => nameof(Scp096DamageHandler.AttackType.Charge), Scp096DamageHandler.AttackType.SlapLeft => "Left Slap", Scp096DamageHandler.AttackType.SlapRight => "Right Slap", Scp096DamageHandler.AttackType.GateKill => "Gate Kill", @@ -123,22 +136,24 @@ public static class LogHandler { }; private static string GetScp049AttackType(Scp049DamageHandler scp049) => scp049.DamageSubType switch { - Scp049DamageHandler.AttackType.Instakill => "Instakill", + Scp049DamageHandler.AttackType.Instakill => nameof(Scp049DamageHandler.AttackType.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.Claw => nameof(Scp939DamageType.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); + public static void LogLeavingScp(string role, float health, float hs, PlayerPermissions permissions, float defaultScalar) => + Log(sizeScalar => $"{"SCP Left".Color("red").Bold()}#Please replace {role.Size(40.Scale(sizeScalar))} as the player has left the game.\n" + + ($"HP: {((int) health).ToString().Color("red")} " + + $"HS: {((int) hs).ToString().Color("purple")}").Size(35.Scale(sizeScalar)), false, permissions, defaultScalar); + + private static int Scale(this int number, float scalar) => (int) (number * scalar); } diff --git a/DeathLog/Properties/AssemblyInfo.cs b/DeathLog/Properties/AssemblyInfo.cs index 6175dbb..3bbe6de 100644 --- a/DeathLog/Properties/AssemblyInfo.cs +++ b/DeathLog/Properties/AssemblyInfo.cs @@ -9,7 +9,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("DeathLog")] -[assembly: AssemblyCopyright("Copyright © 2023")] +[assembly: AssemblyCopyright("Copyright © 2023")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -31,5 +31,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.1.0.0")] +[assembly: AssemblyFileVersion("1.1.0.0")] diff --git a/DeathLog/ToggleLogsCommand.cs b/DeathLog/ToggleLogsCommand.cs index 499eb48..17485ed 100644 --- a/DeathLog/ToggleLogsCommand.cs +++ b/DeathLog/ToggleLogsCommand.cs @@ -9,10 +9,11 @@ namespace DeathLog; public sealed class ToggleLogsCommand : ICommand { public static readonly HashSet HiddenIdList = new(); + public static readonly Dictionary SizeScalar = new(); public string Command => "toggleKillLogs"; public string[] Aliases { get; } = {"tkl"}; - public string Description => "Toggles the visibility of kill logs for the caller."; + public string Description => "Toggles the visibility of kill logs or changes the font size scalar for the caller."; public bool Execute(ArraySegment arguments, ICommandSender sender, out string response) { if (sender is not PlayerCommandSender {ReferenceHub.characterClassManager.UserId: var id}) { @@ -32,18 +33,33 @@ public sealed class ToggleLogsCommand : ICommand { } switch (arguments.At(0).ToLower()) { - case "on" or "enable" or "true" or "1": + case "on" or "enable" or "true" or "yes": HiddenIdList.Remove(id); response = "You will now see kill logs."; return true; - case "off" or "disable" or "false" or "0": + case "off" or "disable" or "false" or "no": HiddenIdList.Add(id); response = "You will no longer see kill logs."; return true; default: - response = "Invalid argument."; - return false; + return ParseScalar(arguments, id, out response); } } + private static bool ParseScalar(ArraySegment arguments, string id, out string response) { + if (!float.TryParse(arguments.At(0), out var scalar)) { + response = "Invalid argument. Expected a float or a boolean."; + return false; + } + + if (scalar is not (> 0 and <= 5)) { + response = "Invalid argument. Expected a float in range 0-5."; + return false; + } + + SizeScalar[id] = scalar; + response = $"Your kill log font size scalar is now {scalar}."; + return true; + } + }