Skip to content

Commit

Permalink
Verified working
Browse files Browse the repository at this point in the history
  • Loading branch information
MSWS committed Feb 5, 2024
1 parent 72a610c commit 2bb7d34
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 9 deletions.
3 changes: 3 additions & 0 deletions mod/Jailbreak.Debug/DebugCommand.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)
Expand Down
15 changes: 11 additions & 4 deletions mod/Jailbreak.Debug/Subcommands/AbstractCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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))
{
Expand Down Expand Up @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion mod/Jailbreak.Debug/Subcommands/MarkRebel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ public override void OnCommand(CCSPlayerController? executor, WrappedInfo info)
{
services.GetRequiredService<IRebelService>().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.");
}
}
36 changes: 36 additions & 0 deletions mod/Jailbreak.Debug/Subcommands/Pardon.cs
Original file line number Diff line number Diff line change
@@ -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] <duration>
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<IRebelService>().UnmarkRebel(player);
}

info.ReplyToCommand($"Pardoned {GetTargetLabel(info)}");
}
}
2 changes: 1 addition & 1 deletion mod/Jailbreak.Logs/LogsListeners.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
23 changes: 20 additions & 3 deletions mod/Jailbreak.Rebel/RebelManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public void Start(BasePlugin parent)
parent.RegisterEventHandler<EventPlayerDisconnect>(OnPlayerDisconnect);
parent.RegisterEventHandler<EventPlayerDeath>(OnPlayerDeath);
parent.RegisterEventHandler<EventRoundStart>(OnRoundStart);
parent.RegisterListener<Listeners.OnTick>(OnTick);

parent.AddTimer(1f, () =>
{
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -158,7 +175,7 @@ private void SendTimeLeft(CCSPlayerController player)
var formattedTime = TimeSpan.FromSeconds(timeLeft).ToString(@"mm\:ss");
var color = GetRebelColor(player);
var formattedColor = $"<font color=\"#{color.R:X2}{color.G:X2}{color.B:X2}\">";
player.PrintToCenterHtml($"You are a rebel for {formattedColor}{formattedTime}</font> more seconds.");

player.PrintToCenterHtml($"You are {formattedColor}<b>rebelling</b></font>");
}
}

0 comments on commit 2bb7d34

Please sign in to comment.