Skip to content

Commit

Permalink
Add marker listener
Browse files Browse the repository at this point in the history
  • Loading branch information
MSWS committed Jan 27, 2024
1 parent 7c004a5 commit d4b9193
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 6 deletions.
7 changes: 1 addition & 6 deletions mod/Jailbreak.Warden/Commands/WardenCommandsBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.")]
Expand Down
48 changes: 48 additions & 0 deletions mod/Jailbreak.Warden/Markers/WardenMarkerBehavior.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 2 additions & 0 deletions mod/Jailbreak.Warden/WardenServiceExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,5 +19,6 @@ public static void AddJailbreakWarden(this IServiceCollection serviceCollection)
serviceCollection.AddPluginBehavior<IWardenSelectionService, WardenSelectionBehavior>();

serviceCollection.AddPluginBehavior<WardenCommandsBehavior>();
serviceCollection.AddPluginBehavior<WardenMarkerBehavior>();
}
}
6 changes: 6 additions & 0 deletions public/Jailbreak.Public/Mod/Warden/IWardenService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ public interface IWardenService
/// </summary>
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);

Expand Down

0 comments on commit d4b9193

Please sign in to comment.