Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/warden markers #4

Merged
merged 6 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Jailbreak.sln
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "lang", "lang", "{CDCDE44E-0
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jailbreak.English", "lang\Jailbreak.English\Jailbreak.English.csproj", "{FC2D6F50-BCFF-41E6-A965-6C73CC01C3BF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jailbreak.Draw", "mod\Jailbreak.Draw\Jailbreak.Draw.csproj", "{E809B726-088D-4BC6-95C9-EE6A991C8AA9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -56,6 +58,10 @@ Global
{FC2D6F50-BCFF-41E6-A965-6C73CC01C3BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FC2D6F50-BCFF-41E6-A965-6C73CC01C3BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FC2D6F50-BCFF-41E6-A965-6C73CC01C3BF}.Release|Any CPU.Build.0 = Release|Any CPU
{E809B726-088D-4BC6-95C9-EE6A991C8AA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E809B726-088D-4BC6-95C9-EE6A991C8AA9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E809B726-088D-4BC6-95C9-EE6A991C8AA9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E809B726-088D-4BC6-95C9-EE6A991C8AA9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{9135CCC9-66C5-4A9C-AE3C-91475B5F0437} = {177DA48D-8306-4102-918D-992569878581}
Expand All @@ -65,5 +71,6 @@ Global
{28EE05E4-8FE3-4CC6-AA03-0C533EFBFBF2} = {36BA84C0-291C-4930-A7C6-97CDF8F7F0D7}
{446E0B6F-E4FE-45E6-BD9B-BD943698327A} = {59311734-3648-43C2-B43C-385718B0D103}
{FC2D6F50-BCFF-41E6-A965-6C73CC01C3BF} = {CDCDE44E-01D2-4B76-99DA-A57E1E956038}
{E809B726-088D-4BC6-95C9-EE6A991C8AA9} = {36BA84C0-291C-4930-A7C6-97CDF8F7F0D7}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "7.0.0",
"version": "8.0.0",
"rollForward": "latestMinor",
"allowPrerelease": false
}
Expand Down
14 changes: 14 additions & 0 deletions mod/Jailbreak.Draw/DrawServiceExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Jailbreak.Draw.Global;
using Jailbreak.Public.Extensions;
using Jailbreak.Public.Mod.Draw;
using Microsoft.Extensions.DependencyInjection;

namespace Jailbreak.Draw;

public static class DrawServiceExtension
{
public static void AddJailbreakDraw(this IServiceCollection serviceCollection)
{
serviceCollection.AddPluginBehavior<IDrawService, DrawManager>();
}
}
30 changes: 30 additions & 0 deletions mod/Jailbreak.Draw/Global/DrawManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Timers;
using Jailbreak.Public.Behaviors;
using Jailbreak.Public.Mod.Draw;

namespace Jailbreak.Draw.Global;

public class DrawManager : IPluginBehavior, IDrawService
{
private List<DrawableShape> shapes = new List<DrawableShape>();

public DrawManager(BasePlugin plugin)
{
plugin.AddTimer(1f, Tick, TimerFlags.REPEAT);
}

private void Tick()
{
shapes.ForEach(s => s.Tick());
}

public void DrawShape(DrawableShape shape, float tickRate = 0f)
{
}

public List<DrawableShape> GetShapes()
{
return shapes;
}
}
14 changes: 14 additions & 0 deletions mod/Jailbreak.Draw/Jailbreak.Draw.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>Jailbreak.Drawable</RootNamespace>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\public\Jailbreak.Public\Jailbreak.Public.csproj" />
</ItemGroup>

</Project>
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>();
}
}
60 changes: 60 additions & 0 deletions public/Jailbreak.Public/Mod/Draw/BeamCircle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System.Drawing;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;

namespace Jailbreak.Public.Mod.Draw;

public class BeamCircle : BeamedShape
{

private BeamLine[] lines;
private Vector[] offsets;
private float radius;

public BeamCircle(BasePlugin plugin, Vector position, float radius, int resolution) : base(plugin, position, resolution)
{
this.radius = radius;
this.lines = new BeamLine[resolution];

offsets = generateOffsets();
}

private float degToRadian(float d)
{
return (float)(d * (Math.PI / 180));
}

private Vector[] generateOffsets()
{
var offsets = new Vector[lines.Length];
var angle = 360f / lines.Length;
for (var i = 0; i < lines.Length; i++)
{
var x = radius * MathF.Cos(degToRadian(angle * i));
var y = radius * MathF.Sin(degToRadian(angle * i));
offsets[i] = new Vector(x, y, 0);
}
return offsets;
}

public override void Draw()
{
for (var i = 0; i < lines.Length; i++)
{
var line = lines[i];
if (line == null)
{
line = new BeamLine(plugin, position, position + offsets[i]);
line.SetColor(color);
line.Draw();
lines[i] = line;
}
else
{
line.Move(position, position + offsets[i]);
line.Update();
}
}
}
}
56 changes: 56 additions & 0 deletions public/Jailbreak.Public/Mod/Draw/BeamLine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System.Drawing;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;

namespace Jailbreak.Public.Mod.Draw;

public class BeamLine : DrawableShape, IColorable
{
private Vector end;
private Color color = Color.White;
private CEnvBeam? beam;

public BeamLine(BasePlugin plugin, Vector position, Vector end) : base(plugin, position)
{
this.end = end;
}

public void Move(Vector start, Vector end)
{
this.position = start;
this.end = end;
}

public override void Draw()
{
var beam = Utilities.CreateEntityByName<CEnvBeam>("env_beam");
if (beam == null) return;
beam.RenderMode = RenderMode_t.kRenderTransColor;
beam.Render = GetColor();

beam.Teleport(position, new QAngle(), new Vector());
beam.EndPos.X = end.X;
beam.EndPos.Y = end.Y;
beam.EndPos.Z = end.Z;
this.beam = beam;

Utilities.SetStateChanged(beam, "CBeam", "m_vecEndPos");
}

public override void Remove()
{
beam?.Remove();
beam = null;
}

public void SetColor(Color color)
{
this.color = color;
}

public Color GetColor()
{
return color;
}
}
41 changes: 41 additions & 0 deletions public/Jailbreak.Public/Mod/Draw/BeamedShape.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Drawing;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;

namespace Jailbreak.Public.Mod.Draw;

/// <summary>
/// Represents a shape that is drawn using many beam segments
/// </summary>
public abstract class BeamedShape : DrawableShape, IColorable
{
protected BeamLine?[] beams;
protected Color color = Color.White;
protected int resolution;

protected BeamedShape(BasePlugin plugin, Vector position, int resolution) : base(plugin, position)
{
beams = new BeamLine[resolution];
}

// TODO: Add support for rotation across arbitrary axis

public Color GetColor()
{
return color;
}

public void SetColor(Color color)
{
this.color = color;
}

public override void Remove()
{
for(int i = 0; i < beams.Length; i++)
{
beams[i]?.Remove();
beams[i] = null;
}
}
}
49 changes: 49 additions & 0 deletions public/Jailbreak.Public/Mod/Draw/DrawableShape.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System.Drawing;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Timers;
using CounterStrikeSharp.API.Modules.Utils;
using Timer = CounterStrikeSharp.API.Modules.Timers.Timer;

namespace Jailbreak.Public.Mod.Draw;

/// <summary>
/// Represents a drawable shape
/// </summary>
public abstract class DrawableShape
{

protected BasePlugin plugin;
protected Vector position; // Represents the origin of the shape
// Note that this can mean different things for different shapes
protected DateTime startTime = DateTime.Now;

private Timer? killTimer; // Internal timer used to remove the shape after a certain amount of time

public DrawableShape(BasePlugin plugin, Vector position)
{
this.plugin = plugin;
this.position = position;
}

public abstract void Draw();

public virtual void Update() {
Remove();
Draw();
}

public virtual void Tick() { }

public void Draw(float lifetime)
{
Draw();
killTimer = plugin.AddTimer(lifetime, Remove, TimerFlags.STOP_ON_MAPCHANGE);
}

public virtual void Move(Vector position)
{
this.position = position;
}

public abstract void Remove();
}
Loading
Loading