From 2bb7d3428d877966f2a0b2465731272d138747fc Mon Sep 17 00:00:00 2001 From: MSWS Date: Mon, 5 Feb 2024 00:09:46 -0800 Subject: [PATCH] Verified working --- mod/Jailbreak.Debug/DebugCommand.cs | 3 ++ .../Subcommands/AbstractCommand.cs | 15 +++++--- mod/Jailbreak.Debug/Subcommands/MarkRebel.cs | 2 +- mod/Jailbreak.Debug/Subcommands/Pardon.cs | 36 +++++++++++++++++++ mod/Jailbreak.Logs/LogsListeners.cs | 2 +- mod/Jailbreak.Rebel/RebelManager.cs | 23 ++++++++++-- 6 files changed, 72 insertions(+), 9 deletions(-) create mode 100644 mod/Jailbreak.Debug/Subcommands/Pardon.cs diff --git a/mod/Jailbreak.Debug/DebugCommand.cs b/mod/Jailbreak.Debug/DebugCommand.cs index 32532b9a..f0208769 100644 --- a/mod/Jailbreak.Debug/DebugCommand.cs +++ b/mod/Jailbreak.Debug/DebugCommand.cs @@ -1,4 +1,5 @@ using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Core.Attributes.Registration; using CounterStrikeSharp.API.Modules.Admin; using CounterStrikeSharp.API.Modules.Commands; using Jailbreak.Debug.Subcommands; @@ -15,9 +16,11 @@ public class DebugCommand : IPluginBehavior public DebugCommand(IServiceProvider serviceProvider) { commands.Add("markrebel", new MarkRebel(serviceProvider)); + commands.Add("pardon", new Pardon(serviceProvider)); } [RequiresPermissions("@css/root")] + [ConsoleCommand("css_debug", "Debug command for Jailbreak.")] public void Command_Debug(CCSPlayerController? executor, CommandInfo info) { if (executor == null) diff --git a/mod/Jailbreak.Debug/Subcommands/AbstractCommand.cs b/mod/Jailbreak.Debug/Subcommands/AbstractCommand.cs index 010ec189..c42a3c56 100644 --- a/mod/Jailbreak.Debug/Subcommands/AbstractCommand.cs +++ b/mod/Jailbreak.Debug/Subcommands/AbstractCommand.cs @@ -69,7 +69,7 @@ protected AbstractCommand(IServiceProvider services) command.CallingPlayer.CanTarget(p) && (predicate == null || predicate(p))); } - internal TargetResult? GetSingleTarget(CommandInfo command, int argIndex = 1) + protected TargetResult? GetSingleTarget(CommandInfo command, int argIndex = 1) { var matches = command.GetArgTargetResult(argIndex); @@ -90,7 +90,11 @@ protected AbstractCommand(IServiceProvider services) return matches; } - internal string GetTargetLabel(CommandInfo info, int argIndex = 1) + protected string GetTargetLabel(WrappedInfo info, int argIndex = 1) + { + return GetTargetLabel(info.info, argIndex + 1); + } + protected string GetTargetLabel(CommandInfo info, int argIndex = 1) { switch (info.GetArg(argIndex)) { @@ -122,8 +126,11 @@ internal string GetTargetLabel(CommandInfo info, int argIndex = 1) } } - - internal string GetTargetLabels(CommandInfo info, int argIndex = 1) + protected string GetTargetLabels(WrappedInfo info, int argIndex = 1) + { + return GetTargetLabels(info.info, argIndex + 1); + } + protected string GetTargetLabels(CommandInfo info, int argIndex = 1) { string label = GetTargetLabel(info, argIndex); if (label.ToLower().EndsWith("s")) diff --git a/mod/Jailbreak.Debug/Subcommands/MarkRebel.cs b/mod/Jailbreak.Debug/Subcommands/MarkRebel.cs index 7e735a43..b884ad5b 100644 --- a/mod/Jailbreak.Debug/Subcommands/MarkRebel.cs +++ b/mod/Jailbreak.Debug/Subcommands/MarkRebel.cs @@ -40,6 +40,6 @@ public override void OnCommand(CCSPlayerController? executor, WrappedInfo info) { services.GetRequiredService().MarkRebel(player, duration); } - info.ReplyToCommand($"Marked {target.Players.Count()} players as rebels for {duration} seconds"); + info.ReplyToCommand($"Marked {GetTargetLabel(info)} as rebels for {duration} seconds."); } } \ No newline at end of file diff --git a/mod/Jailbreak.Debug/Subcommands/Pardon.cs b/mod/Jailbreak.Debug/Subcommands/Pardon.cs new file mode 100644 index 00000000..ebdfa46d --- /dev/null +++ b/mod/Jailbreak.Debug/Subcommands/Pardon.cs @@ -0,0 +1,36 @@ +using CounterStrikeSharp.API; +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Modules.Commands; +using Jailbreak.Formatting.Views; +using Jailbreak.Public.Mod.Rebel; +using Microsoft.Extensions.DependencyInjection; + +namespace Jailbreak.Debug.Subcommands; + +// css_markrebel [player] +public class Pardon : AbstractCommand +{ + public Pardon(IServiceProvider services) : base(services) + { + } + + public override void OnCommand(CCSPlayerController? executor, WrappedInfo info) + { + if (info.ArgCount == 1) + { + info.ReplyToCommand("Specify target?"); + return; + } + + var target = GetVulnerableTarget(info); + if (target == null) + return; + + foreach (var player in target.Players) + { + services.GetRequiredService().UnmarkRebel(player); + } + + info.ReplyToCommand($"Pardoned {GetTargetLabel(info)}"); + } +} \ No newline at end of file diff --git a/mod/Jailbreak.Logs/LogsListeners.cs b/mod/Jailbreak.Logs/LogsListeners.cs index 6305e041..50fc0f5e 100644 --- a/mod/Jailbreak.Logs/LogsListeners.cs +++ b/mod/Jailbreak.Logs/LogsListeners.cs @@ -61,7 +61,7 @@ private HookResult OnPlayerHurt(EventPlayerHurt @event, GameEventInfo info) var attacker = @event.Attacker; bool isWorld = attacker == null || !attacker.IsReal(); - int health = @event.Health; + int health = @event.DmgHealth; if (isWorld) { diff --git a/mod/Jailbreak.Rebel/RebelManager.cs b/mod/Jailbreak.Rebel/RebelManager.cs index e971b2c5..61d6203d 100644 --- a/mod/Jailbreak.Rebel/RebelManager.cs +++ b/mod/Jailbreak.Rebel/RebelManager.cs @@ -29,6 +29,7 @@ public void Start(BasePlugin parent) parent.RegisterEventHandler(OnPlayerDisconnect); parent.RegisterEventHandler(OnPlayerDeath); parent.RegisterEventHandler(OnRoundStart); + parent.RegisterListener(OnTick); parent.AddTimer(1f, () => { @@ -49,6 +50,22 @@ public void Start(BasePlugin parent) }, TimerFlags.REPEAT); } + private void OnTick() + { + foreach (var player in GetActiveRebels()) + { + if (!player.IsReal()) + continue; + + if (GetRebelTimeLeft(player) <= 0) + { + continue; + } + + SendTimeLeft(player); + } + } + HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info) { rebelTimes.Clear(); @@ -127,7 +144,7 @@ private float GetRebelTimePercentage(CCSPlayerController player) return 0; return (float)(100 - (120 - x) * (Math.Sqrt(120 - x)) / 13f) / 100; } - + private Color GetRebelColor(CCSPlayerController player) { var percent = GetRebelTimePercentage(player); @@ -158,7 +175,7 @@ private void SendTimeLeft(CCSPlayerController player) var formattedTime = TimeSpan.FromSeconds(timeLeft).ToString(@"mm\:ss"); var color = GetRebelColor(player); var formattedColor = $""; - - player.PrintToCenterHtml($"You are a rebel for {formattedColor}{formattedTime} more seconds."); + + player.PrintToCenterHtml($"You are {formattedColor}rebelling"); } } \ No newline at end of file