diff --git a/lang/Jailbreak.English/Warden/SpecialTreatmentNotifications.cs b/lang/Jailbreak.English/Warden/SpecialTreatmentNotifications.cs new file mode 100644 index 00000000..38699f51 --- /dev/null +++ b/lang/Jailbreak.English/Warden/SpecialTreatmentNotifications.cs @@ -0,0 +1,38 @@ +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Modules.Utils; + +using Jailbreak.Formatting.Base; +using Jailbreak.Formatting.Core; +using Jailbreak.Formatting.Logistics; +using Jailbreak.Formatting.Objects; +using Jailbreak.Formatting.Views; + +namespace Jailbreak.English.Warden; + +public class SpecialTreatmentNotifications : ISpecialTreatmentNotifications, ILanguage +{ + public static FormatObject PREFIX = new HiddenFormatObject( $" {ChatColors.Lime}[{ChatColors.Green}ST{ChatColors.Lime}]" ) + { + // Hide in panorama and center text + Plain = false, + Panorama = false, + Chat = true, + }; + + public IView GRANTED => + new SimpleView { PREFIX, "You now have special treatment!" }; + + public IView REVOKED => + new SimpleView { PREFIX, "Your special treatment was removed" }; + + public IView GRANTED_TO(CCSPlayerController player) + { + return new SimpleView { PREFIX, player, "now has Special Treatment!" }; + } + + public IView REVOKED_FROM(CCSPlayerController player) + { + return new SimpleView { PREFIX, player, "no longer has Special Treatment." }; + } + +} diff --git a/mod/Jailbreak.Warden/Commands/SpecialTreatmentCommandsBehavior.cs b/mod/Jailbreak.Warden/Commands/SpecialTreatmentCommandsBehavior.cs new file mode 100644 index 00000000..f14f3f90 --- /dev/null +++ b/mod/Jailbreak.Warden/Commands/SpecialTreatmentCommandsBehavior.cs @@ -0,0 +1,78 @@ +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Core.Attributes.Registration; +using CounterStrikeSharp.API.Modules.Commands; +using CounterStrikeSharp.API.Modules.Utils; + +using Jailbreak.Formatting.Extensions; +using Jailbreak.Formatting.Views; +using Jailbreak.Public.Behaviors; +using Jailbreak.Public.Mod.Warden; + +namespace Jailbreak.Warden.Commands; + +public class SpecialTreatmentCommandsBehavior : IPluginBehavior +{ + + private IWardenService _warden; + private ISpecialTreatmentService _specialTreatment; + + private IGenericCommandNotifications _generic; + private ISpecialTreatmentNotifications _notifications; + + public SpecialTreatmentCommandsBehavior(IWardenService warden, ISpecialTreatmentService specialTreatment, IGenericCommandNotifications generic, ISpecialTreatmentNotifications notifications) + { + _warden = warden; + _specialTreatment = specialTreatment; + _generic = generic; + _notifications = notifications; + } + + [ConsoleCommand("css_treat", "Grant or revoke special treatment from a player")] + [ConsoleCommand("css_st", "Grant or revoke special treatment from a player")] + [CommandHelper(1, "[target]", CommandUsage.CLIENT_ONLY)] + public void Command_Toggle(CCSPlayerController? player, CommandInfo command) + { + if (player == null) + return; + + if (!_warden.IsWarden(player)) + // You're not that warden, blud + return; + + // Since we have min_args, don't need to check for validity here. + // just only get targets that are T's. + var targets = command.GetArgTargetResult(1); + var eligible = targets + .Where(player => player.Team == CsTeam.Terrorist) + .ToList(); + + if (eligible.Count == 0) + { + _generic.PlayerNotFound(command.GetArg(1)) + .ToPlayerChat(player) + .ToPlayerConsole(player); + return; + } + else if (eligible.Count != 1) + { + _generic.PlayerFoundMultiple(command.GetArg(1)) + .ToPlayerChat(player) + .ToPlayerConsole(player); + return; + } + + // One target, mark as ST. + var special = eligible.First(); + + if (_specialTreatment.IsSpecialTreatment(special)) + { + // Revoke + _specialTreatment.Revoke(special); + } + else + { + // Player does not have ST, grant + _specialTreatment.Grant(special); + } + } +} diff --git a/mod/Jailbreak.Warden/SpecialTreatment/SpecialTreatmentBehavior.cs b/mod/Jailbreak.Warden/SpecialTreatment/SpecialTreatmentBehavior.cs new file mode 100644 index 00000000..e5cb7da0 --- /dev/null +++ b/mod/Jailbreak.Warden/SpecialTreatment/SpecialTreatmentBehavior.cs @@ -0,0 +1,90 @@ +using System.Drawing; + +using CounterStrikeSharp.API; +using CounterStrikeSharp.API.Core; + +using Jailbreak.Formatting.Extensions; +using Jailbreak.Formatting.Views; +using Jailbreak.Public.Behaviors; +using Jailbreak.Public.Generic; +using Jailbreak.Public.Mod.Rebel; +using Jailbreak.Public.Mod.Warden; + +namespace Jailbreak.Warden.SpecialTreatment; + +public class SpecialTreatmentBehavior : IPluginBehavior, ISpecialTreatmentService +{ + private IPlayerState _sts; + private IRebelService _rebel; + private ISpecialTreatmentNotifications _notifications; + + public SpecialTreatmentBehavior(IPlayerStateFactory factory, IRebelService rebel, ISpecialTreatmentNotifications notifications) + { + _sts = factory.Round(); + + _rebel = rebel; + _notifications = notifications; + } + + private class SpecialTreatmentState + { + public bool HasSpecialTreatment { get; set; } = false; + } + + public bool IsSpecialTreatment(CCSPlayerController player) + { + return _sts.Get(player) + .HasSpecialTreatment; + } + + public void Grant(CCSPlayerController player) + { + // Player is already granted ST + if (IsSpecialTreatment(player)) + return; + + _sts.Get(player).HasSpecialTreatment = true; + + _rebel.UnmarkRebel(player); + this.SetPlayerColor(player, /* hasSt */ true); + + _notifications.GRANTED + .ToPlayerChat(player) + .ToPlayerCenter(player); + + _notifications.GRANTED_TO(player) + .ToAllChat(); + } + + public void Revoke(CCSPlayerController player) + { + // Player is already revoked + if (!IsSpecialTreatment(player)) + return; + + _sts.Get(player).HasSpecialTreatment = false; + + this.SetPlayerColor(player, /* hasSt */ false); + + _notifications.REVOKED + .ToPlayerChat(player) + .ToPlayerCenter(player); + + _notifications.REVOKED_FROM(player) + .ToAllChat(); + } + + private void SetPlayerColor(CCSPlayerController player, bool hasSt) + { + if (!player.IsValid || player.Pawn.Value == null) + return; + + var color = hasSt + ? Color.FromArgb(254, 150, 255, 150) + : Color.FromArgb(254, 255, 255, 255); + + player.Pawn.Value.RenderMode = RenderMode_t.kRenderTransColor; + player.Pawn.Value.Render = color; + Utilities.SetStateChanged(player.Pawn.Value, "CBaseModelEntity", "m_clrRender"); + } +} diff --git a/mod/Jailbreak.Warden/WardenServiceExtension.cs b/mod/Jailbreak.Warden/WardenServiceExtension.cs index 9f7a0fc5..c9ecda85 100644 --- a/mod/Jailbreak.Warden/WardenServiceExtension.cs +++ b/mod/Jailbreak.Warden/WardenServiceExtension.cs @@ -5,6 +5,8 @@ using Jailbreak.Warden.Markers; using Jailbreak.Warden.Paint; using Jailbreak.Warden.Selection; +using Jailbreak.Warden.SpecialTreatment; + using Microsoft.Extensions.DependencyInjection; namespace Jailbreak.Warden; @@ -15,9 +17,12 @@ public static void AddJailbreakWarden(this IServiceCollection serviceCollection) { serviceCollection.AddPluginBehavior(); serviceCollection.AddPluginBehavior(); + serviceCollection.AddPluginBehavior(); + serviceCollection.AddPluginBehavior(); serviceCollection.AddPluginBehavior(); + serviceCollection.AddPluginBehavior(); serviceCollection.AddPluginBehavior(); } -} \ No newline at end of file +} diff --git a/public/Jailbreak.Formatting/Logistics/LanguageConfig.cs b/public/Jailbreak.Formatting/Logistics/LanguageConfig.cs index c988e9f1..5e4fe0eb 100644 --- a/public/Jailbreak.Formatting/Logistics/LanguageConfig.cs +++ b/public/Jailbreak.Formatting/Logistics/LanguageConfig.cs @@ -34,8 +34,12 @@ public void WithRebel() public void WithLogging() where TLogging : class, ILanguage, ILogMessages => _collection.AddSingleton(); - + public void WithLastRequest() where TLastRequest : class, ILanguage, ILastRequestMessages => _collection.AddSingleton(); + + public void WithSpecialTreatment() + where TSpecialTreatment : class, ILanguage, ISpecialTreatmentNotifications + => _collection.AddSingleton(); } diff --git a/public/Jailbreak.Formatting/Views/ISpecialTreatmentNotifications.cs b/public/Jailbreak.Formatting/Views/ISpecialTreatmentNotifications.cs new file mode 100644 index 00000000..43f08600 --- /dev/null +++ b/public/Jailbreak.Formatting/Views/ISpecialTreatmentNotifications.cs @@ -0,0 +1,17 @@ +using CounterStrikeSharp.API.Core; + +using Jailbreak.Formatting.Base; + +namespace Jailbreak.Formatting.Views; + +public interface ISpecialTreatmentNotifications +{ + public IView GRANTED { get; } + + public IView REVOKED { get; } + + public IView GRANTED_TO(CCSPlayerController player); + + public IView REVOKED_FROM(CCSPlayerController player); + +} diff --git a/public/Jailbreak.Public/Mod/Warden/ISpecialTreatmentService.cs b/public/Jailbreak.Public/Mod/Warden/ISpecialTreatmentService.cs new file mode 100644 index 00000000..ee4bc6ce --- /dev/null +++ b/public/Jailbreak.Public/Mod/Warden/ISpecialTreatmentService.cs @@ -0,0 +1,21 @@ +using CounterStrikeSharp.API.Core; + +namespace Jailbreak.Public.Mod.Warden; + +public interface ISpecialTreatmentService +{ + public bool IsSpecialTreatment(CCSPlayerController player); + + /// + /// Give this player ST for the rest of the round + /// + /// + public void Grant(CCSPlayerController player); + + /// + /// Revoke the player's special treatment for the current round + /// Does nothing if not ST. + /// + /// + public void Revoke(CCSPlayerController player); +} diff --git a/src/Jailbreak/JailbreakServiceCollection.cs b/src/Jailbreak/JailbreakServiceCollection.cs index afde5d71..7a5f2f9d 100644 --- a/src/Jailbreak/JailbreakServiceCollection.cs +++ b/src/Jailbreak/JailbreakServiceCollection.cs @@ -50,6 +50,7 @@ public void ConfigureServices(IServiceCollection serviceCollection) config.WithRebel(); config.WithLogging(); config.WithLastRequest(); + config.WithSpecialTreatment(); }); } }