From d4b919373cc1ee1d9f27c110812a6fd23ff42114 Mon Sep 17 00:00:00 2001 From: MSWS Date: Fri, 26 Jan 2024 20:17:41 -0800 Subject: [PATCH] Add marker listener --- .../Commands/WardenCommandsBehavior.cs | 7 +-- .../Markers/WardenMarkerBehavior.cs | 48 +++++++++++++++++++ .../WardenServiceExtension.cs | 2 + .../Mod/Warden/IWardenService.cs | 6 +++ 4 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 mod/Jailbreak.Warden/Markers/WardenMarkerBehavior.cs diff --git a/mod/Jailbreak.Warden/Commands/WardenCommandsBehavior.cs b/mod/Jailbreak.Warden/Commands/WardenCommandsBehavior.cs index 2e5510b1..032d95d8 100644 --- a/mod/Jailbreak.Warden/Commands/WardenCommandsBehavior.cs +++ b/mod/Jailbreak.Warden/Commands/WardenCommandsBehavior.cs @@ -35,9 +35,8 @@ public void Command_Pass(CCSPlayerController? player, CommandInfo command) return; var isCt = player.GetTeam() == CsTeam.CounterTerrorist; - var isWarden = _warden.HasWarden && _warden.Warden?.Slot == player.Slot; - if (isWarden) + if (_warden.IsWarden(player)) { // Handle warden pass _notifications.PASS_WARDEN(player) @@ -48,11 +47,7 @@ public void Command_Pass(CCSPlayerController? player, CommandInfo command) if (!_warden.TryRemoveWarden()) Server.PrintToChatAll("[BUG] Couldn't remove warden :^("); - - return; } - - return; } [ConsoleCommand("css_warden", "Become a warden, Join the warden queue, or see information about the current warden.")] diff --git a/mod/Jailbreak.Warden/Markers/WardenMarkerBehavior.cs b/mod/Jailbreak.Warden/Markers/WardenMarkerBehavior.cs new file mode 100644 index 00000000..5980dba2 --- /dev/null +++ b/mod/Jailbreak.Warden/Markers/WardenMarkerBehavior.cs @@ -0,0 +1,48 @@ +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Core.Attributes.Registration; +using CounterStrikeSharp.API.Modules.Commands; +using CounterStrikeSharp.API.Modules.Utils; +using Jailbreak.Public.Behaviors; +using Jailbreak.Public.Mod.Draw; +using Jailbreak.Public.Mod.Warden; + +namespace Jailbreak.Warden.Markers; + +public class WardenMarkerBehavior : IPluginBehavior +{ + private readonly IWardenService _warden; + private IDrawService _drawer; + + private DrawableShape? _marker; + + public WardenMarkerBehavior(IWardenService warden, IDrawService drawer) + { + _warden = warden; + _drawer = drawer; + } + + public void Start(BasePlugin plugin) + { + _marker = new BeamCircle(plugin, new Vector(), 40f, (int)Math.PI * 10); + plugin.AddCommandListener("player_ping", CommandListener_PlayerPing); + } + + [GameEventHandler] + public HookResult OnPing(EventPlayerPing @event, GameEventInfo info) + { + var player = @event.Userid; + + if (!_warden.IsWarden(player)) + return HookResult.Handled; + + Vector vec = new Vector(@event.X, @event.Y, @event.Z); + _marker?.Move(vec); + _marker?.Update(); + return HookResult.Handled; + } + + HookResult CommandListener_PlayerPing(CCSPlayerController? player, CommandInfo info) + { + return HookResult.Handled; + } +} \ No newline at end of file diff --git a/mod/Jailbreak.Warden/WardenServiceExtension.cs b/mod/Jailbreak.Warden/WardenServiceExtension.cs index 4646f63f..b0716735 100644 --- a/mod/Jailbreak.Warden/WardenServiceExtension.cs +++ b/mod/Jailbreak.Warden/WardenServiceExtension.cs @@ -4,6 +4,7 @@ using Jailbreak.Public.Mod.Warden; using Jailbreak.Warden.Commands; using Jailbreak.Warden.Global; +using Jailbreak.Warden.Markers; using Jailbreak.Warden.Selection; using Microsoft.Extensions.DependencyInjection; @@ -18,5 +19,6 @@ public static void AddJailbreakWarden(this IServiceCollection serviceCollection) serviceCollection.AddPluginBehavior(); serviceCollection.AddPluginBehavior(); + serviceCollection.AddPluginBehavior(); } } diff --git a/public/Jailbreak.Public/Mod/Warden/IWardenService.cs b/public/Jailbreak.Public/Mod/Warden/IWardenService.cs index 097efd3c..5ae3c882 100644 --- a/public/Jailbreak.Public/Mod/Warden/IWardenService.cs +++ b/public/Jailbreak.Public/Mod/Warden/IWardenService.cs @@ -12,6 +12,12 @@ public interface IWardenService /// bool HasWarden { get; } + bool IsWarden(CCSPlayerController? player) + { + if (player == null || !player.IsValid) + return false; + return HasWarden && Warden != null && Warden.Slot == player.Slot; + } bool TrySetWarden(CCSPlayerController warden);