From dfe24dda668b5329c1cc0ad061d6a00adf60ea32 Mon Sep 17 00:00:00 2001 From: MSWS Date: Sat, 10 Feb 2024 22:31:08 -0800 Subject: [PATCH] Add factory, enhance ALR, add empty knifefight example --- .../LastRequest/LastRequestMessages.cs | 17 ++++++++ .../Jailbreak.LastRequest.csproj | 1 + .../LastRequestConfig.cs | 6 +++ .../LastRequestExtension.cs | 15 +++++++ .../LastRequestFactory.cs | 25 ++++++++++++ .../LastRequestManager.cs | 39 ++++++++++++++++++- .../LastRequests/KnifeFight.cs | 28 +++++++++++++ .../Views/ILastRequestMessages.cs | 9 +++++ .../Mod/LastRequest/AbstractLastRequest.cs | 27 ++++++++----- 9 files changed, 157 insertions(+), 10 deletions(-) create mode 100644 lang/Jailbreak.English/LastRequest/LastRequestMessages.cs create mode 100644 mod/Jailbreak.LastRequest/LastRequestConfig.cs create mode 100644 mod/Jailbreak.LastRequest/LastRequestExtension.cs create mode 100644 mod/Jailbreak.LastRequest/LastRequestFactory.cs create mode 100644 mod/Jailbreak.LastRequest/LastRequests/KnifeFight.cs create mode 100644 public/Jailbreak.Formatting/Views/ILastRequestMessages.cs diff --git a/lang/Jailbreak.English/LastRequest/LastRequestMessages.cs b/lang/Jailbreak.English/LastRequest/LastRequestMessages.cs new file mode 100644 index 00000000..7f2442ec --- /dev/null +++ b/lang/Jailbreak.English/LastRequest/LastRequestMessages.cs @@ -0,0 +1,17 @@ +using Jailbreak.Formatting.Base; +using Jailbreak.Formatting.Views; + +namespace Jailbreak.English.LastRequest; + +public class LastRequestMessages : ILastRequestMessages +{ + public IView LastRequestEnabled() => new SimpleView() + { + { "Last Request has been enabled." } + }; + + public IView LastRequestDisabled() => new SimpleView() + { + { "Last Request has been disabled." } + }; +} \ No newline at end of file diff --git a/mod/Jailbreak.LastRequest/Jailbreak.LastRequest.csproj b/mod/Jailbreak.LastRequest/Jailbreak.LastRequest.csproj index 1e02febe..87ee1a09 100644 --- a/mod/Jailbreak.LastRequest/Jailbreak.LastRequest.csproj +++ b/mod/Jailbreak.LastRequest/Jailbreak.LastRequest.csproj @@ -7,6 +7,7 @@ + diff --git a/mod/Jailbreak.LastRequest/LastRequestConfig.cs b/mod/Jailbreak.LastRequest/LastRequestConfig.cs new file mode 100644 index 00000000..fd59e8aa --- /dev/null +++ b/mod/Jailbreak.LastRequest/LastRequestConfig.cs @@ -0,0 +1,6 @@ +namespace Jailbreak.LastRequest; + +public class LastRequestConfig +{ + public int PrisonersToActiveLR { get; set; } = 2; +} \ No newline at end of file diff --git a/mod/Jailbreak.LastRequest/LastRequestExtension.cs b/mod/Jailbreak.LastRequest/LastRequestExtension.cs new file mode 100644 index 00000000..eceec6d0 --- /dev/null +++ b/mod/Jailbreak.LastRequest/LastRequestExtension.cs @@ -0,0 +1,15 @@ +using Jailbreak.Public.Extensions; +using Jailbreak.Public.Mod.LastRequest; +using Microsoft.Extensions.DependencyInjection; + +namespace Jailbreak.LastRequest; + +public static class LastRequestExtension +{ + public static void AddJailbreakLastRequest(this IServiceCollection collection) + { + collection.AddConfig("lastrequest"); + + collection.AddPluginBehavior(); + } +} \ No newline at end of file diff --git a/mod/Jailbreak.LastRequest/LastRequestFactory.cs b/mod/Jailbreak.LastRequest/LastRequestFactory.cs new file mode 100644 index 00000000..012f6f03 --- /dev/null +++ b/mod/Jailbreak.LastRequest/LastRequestFactory.cs @@ -0,0 +1,25 @@ +using CounterStrikeSharp.API.Core; +using Jailbreak.LastRequest.LastRequests; +using Jailbreak.Public.Mod.LastRequest; +using Jailbreak.Public.Mod.LastRequest.Enums; + +namespace Jailbreak.LastRequest; + +public class LastRequestFactory : ILastRequestFactory +{ + private BasePlugin plugin; + + public LastRequestFactory(BasePlugin plugin) + { + this.plugin = plugin; + } + + public AbstractLastRequest CreateLastRequest(CCSPlayerController prisoner, CCSPlayerController guard, LRType type) + { + return type switch + { + LRType.KnifeFight => new KnifeFight(plugin, prisoner, guard), + _ => throw new ArgumentException("Invalid last request type: " + type, nameof(type)) + }; + } +} \ No newline at end of file diff --git a/mod/Jailbreak.LastRequest/LastRequestManager.cs b/mod/Jailbreak.LastRequest/LastRequestManager.cs index fe125ace..ef3a760e 100644 --- a/mod/Jailbreak.LastRequest/LastRequestManager.cs +++ b/mod/Jailbreak.LastRequest/LastRequestManager.cs @@ -1,5 +1,11 @@ -using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API; +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Core.Attributes.Registration; +using CounterStrikeSharp.API.Modules.Utils; +using Jailbreak.Formatting.Extensions; +using Jailbreak.Formatting.Views; using Jailbreak.Public.Behaviors; +using Jailbreak.Public.Extensions; using Jailbreak.Public.Mod.LastRequest; namespace Jailbreak.LastRequest; @@ -7,6 +13,14 @@ namespace Jailbreak.LastRequest; public class LastRequestManager : IPluginBehavior, ILastRequestManager { private BasePlugin _parent; + private LastRequestConfig config; + private ILastRequestMessages messages; + + public LastRequestManager(LastRequestConfig config, ILastRequestMessages messages) + { + this.config = config; + this.messages = messages; + } public void Start(BasePlugin parent) { @@ -14,11 +28,34 @@ public void Start(BasePlugin parent) _parent.RegisterEventHandler(OnPlayerDeath); } + [GameEventHandler(HookMode.Post)] public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info) { + var player = @event.Userid; + if (!player.IsReal()) + return HookResult.Continue; + + if (player.GetTeam() != CsTeam.Terrorist) + return HookResult.Continue; + + int remainingPrisoners = Utilities.GetPlayers().Count(CountsToLR); + if (remainingPrisoners > config.PrisonersToActiveLR) + return HookResult.Continue; + + IsLREnabled = true; + messages.LastRequestEnabled().ToAllChat(); return HookResult.Continue; } + private bool CountsToLR(CCSPlayerController player) + { + if (!player.IsReal()) + return false; + if (!player.PawnIsAlive) + return false; + return player.GetTeam() == CsTeam.Terrorist; + } + public bool IsLREnabled { get; set; } public IList ActiveLRs { get; } = new List(); diff --git a/mod/Jailbreak.LastRequest/LastRequests/KnifeFight.cs b/mod/Jailbreak.LastRequest/LastRequests/KnifeFight.cs new file mode 100644 index 00000000..70a4480b --- /dev/null +++ b/mod/Jailbreak.LastRequest/LastRequests/KnifeFight.cs @@ -0,0 +1,28 @@ +using CounterStrikeSharp.API.Core; +using Jailbreak.Public.Mod.LastRequest; +using Jailbreak.Public.Mod.LastRequest.Enums; + +namespace Jailbreak.LastRequest.LastRequests; + +public class KnifeFight : AbstractLastRequest +{ + public KnifeFight(BasePlugin plugin, CCSPlayerController prisoner, CCSPlayerController guard) : base(plugin, + prisoner, guard) + { + } + + public override void Setup() + { + // Strip weapons, teleport T to CT + } + + public override void Execute() + { + // Give knives + } + + public override void End(LRResult result) + { + // Slay the loser + } +} \ No newline at end of file diff --git a/public/Jailbreak.Formatting/Views/ILastRequestMessages.cs b/public/Jailbreak.Formatting/Views/ILastRequestMessages.cs new file mode 100644 index 00000000..10235732 --- /dev/null +++ b/public/Jailbreak.Formatting/Views/ILastRequestMessages.cs @@ -0,0 +1,9 @@ +using Jailbreak.Formatting.Base; + +namespace Jailbreak.Formatting.Views; + +public interface ILastRequestMessages +{ + public IView LastRequestEnabled(); + public IView LastRequestDisabled(); +} \ No newline at end of file diff --git a/public/Jailbreak.Public/Mod/LastRequest/AbstractLastRequest.cs b/public/Jailbreak.Public/Mod/LastRequest/AbstractLastRequest.cs index 1b7404a1..e7f6d6f1 100644 --- a/public/Jailbreak.Public/Mod/LastRequest/AbstractLastRequest.cs +++ b/public/Jailbreak.Public/Mod/LastRequest/AbstractLastRequest.cs @@ -5,13 +5,22 @@ namespace Jailbreak.Public.Mod.LastRequest; public abstract class AbstractLastRequest { - protected CCSPlayerController prisoner, guard; - protected LRType type; - protected LRState state; - - protected DateTimeOffset startTime; - - public abstract void Setup(); - public abstract void Execute(); - public abstract void End(LRResult result); + public CCSPlayerController prisoner { get; protected set; } + public CCSPlayerController guard { get; protected set; } + public LRType type { get; protected set; } + public LRState state { get; protected set; } + protected BasePlugin plugin; + protected DateTimeOffset startTime; + + protected AbstractLastRequest(BasePlugin plugin, CCSPlayerController prisoner, CCSPlayerController guard) + { + this.plugin = plugin; + this.prisoner = prisoner; + this.guard = guard; + } + + + public abstract void Setup(); + public abstract void Execute(); + public abstract void End(LRResult result); } \ No newline at end of file