From a4caf4e0ca2212e03060caefc4b167914a8bdb0c Mon Sep 17 00:00:00 2001 From: Isaac Date: Sat, 3 Feb 2024 23:18:04 -0800 Subject: [PATCH] Feat/warden laser (#15) * Start work on warden laser * Working commit * Add warden beam * Improvements to drawing --- .../Markers/WardenMarkerBehavior.cs | 35 ++++++++++++++++++- .../Paint/WardenPaintBehavior.cs | 24 ++----------- .../Extensions/VectorExtensions.cs | 2 +- .../Jailbreak.Public/Mod/Draw/BeamCircle.cs | 6 ++++ public/Jailbreak.Public/Mod/Draw/BeamLine.cs | 6 +--- 5 files changed, 45 insertions(+), 28 deletions(-) diff --git a/mod/Jailbreak.Warden/Markers/WardenMarkerBehavior.cs b/mod/Jailbreak.Warden/Markers/WardenMarkerBehavior.cs index e8ba7f07..c4919994 100644 --- a/mod/Jailbreak.Warden/Markers/WardenMarkerBehavior.cs +++ b/mod/Jailbreak.Warden/Markers/WardenMarkerBehavior.cs @@ -3,6 +3,7 @@ using CounterStrikeSharp.API.Modules.Commands; using CounterStrikeSharp.API.Modules.Utils; using Jailbreak.Public.Behaviors; +using Jailbreak.Public.Extensions; using Jailbreak.Public.Mod.Draw; using Jailbreak.Public.Mod.Warden; @@ -12,7 +13,12 @@ public class WardenMarkerBehavior : IPluginBehavior { private readonly IWardenService _warden; - private DrawableShape? _marker; + private BeamCircle? _marker; + + private Vector? currentPos; + private const float MIN_RADIUS = 60f, MAX_RADIUS = 360f; + private float radius = MIN_RADIUS; + private long placementTime = 0; public WardenMarkerBehavior(IWardenService warden) { @@ -33,7 +39,34 @@ public HookResult OnPing(EventPlayerPing @event, GameEventInfo info) if (!_warden.IsWarden(player)) return HookResult.Handled; Vector vec = new Vector(@event.X, @event.Y, @event.Z); + + if (currentPos != null) + { + float distance = currentPos.Distance(vec); + long timeElapsed = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() - placementTime; + if (timeElapsed < 500) + { + if (distance <= MAX_RADIUS * 1.5) + { + distance = Math.Clamp(distance, MIN_RADIUS, MAX_RADIUS); + _marker?.SetRadius(distance); + _marker?.Update(); + radius = distance; + return HookResult.Handled; + } + } + else if (distance <= radius) + { + _marker?.Remove(); + return HookResult.Handled; + } + } + + radius = MIN_RADIUS; + currentPos = vec; + placementTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); _marker?.Move(vec); + _marker?.SetRadius(radius); _marker?.Update(); return HookResult.Handled; } diff --git a/mod/Jailbreak.Warden/Paint/WardenPaintBehavior.cs b/mod/Jailbreak.Warden/Paint/WardenPaintBehavior.cs index 752b4796..ef52504c 100644 --- a/mod/Jailbreak.Warden/Paint/WardenPaintBehavior.cs +++ b/mod/Jailbreak.Warden/Paint/WardenPaintBehavior.cs @@ -15,7 +15,6 @@ public class WardenPaintBehavior : IPluginBehavior private IWardenService _warden; private BasePlugin parent; private Vector? _lastPosition; - private BeamLine? _beamLine; public WardenPaintBehavior(IWardenService warden) { @@ -25,26 +24,20 @@ public WardenPaintBehavior(IWardenService warden) public void Start(BasePlugin parent) { this.parent = parent; - // parent.AddTimer(0.1f, Paint, TimerFlags.REPEAT); parent.RegisterListener(Paint); } - + private void Paint() { if (!_warden.HasWarden) - { - _beamLine?.Remove(); - _beamLine = null; return; - } + var warden = _warden.Warden; if (warden == null || !warden.IsValid) return; if ((warden.Buttons & PlayerButtons.Use) == 0) { - _beamLine?.Remove(); - _beamLine = null; return; } @@ -52,23 +45,14 @@ private void Paint() if (position == null) return; - if (_beamLine == null) - { - _beamLine = new BeamLine(parent, position, position); - _beamLine.SetColor(Color.FromArgb(200, 150, 150, 255)); - _beamLine.Draw(); - } - var start = _lastPosition ?? position; start = start.Clone(); - var eyeLocation = warden.Pawn.Value!.AbsOrigin!.Clone(); - eyeLocation.Z += warden.Pawn.Value!.CameraServices!.OldPlayerViewOffsetZ; if (_lastPosition != null && position.DistanceSquared(_lastPosition) < 25 * 25) { return; } - + _lastPosition = position; if (start.DistanceSquared(position) > 150 * 150 || start.Z - position.Z > 0.001f) { @@ -76,8 +60,6 @@ private void Paint() } new BeamLine(parent, start.Clone(), position.Clone()).Draw(10f); - _beamLine.Move(eyeLocation, position.Clone()); - _beamLine.Update(); } private Vector? FindFloorIntersection(CCSPlayerController player) diff --git a/public/Jailbreak.Public/Extensions/VectorExtensions.cs b/public/Jailbreak.Public/Extensions/VectorExtensions.cs index f0bf4335..158b738d 100644 --- a/public/Jailbreak.Public/Extensions/VectorExtensions.cs +++ b/public/Jailbreak.Public/Extensions/VectorExtensions.cs @@ -14,7 +14,7 @@ public static Vector Clone(this Vector vector) }; return vec; } - + public static Vector Add(this Vector vector, Vector other) { vector.X += other.X; diff --git a/public/Jailbreak.Public/Mod/Draw/BeamCircle.cs b/public/Jailbreak.Public/Mod/Draw/BeamCircle.cs index bdfe9a94..7bc034b8 100644 --- a/public/Jailbreak.Public/Mod/Draw/BeamCircle.cs +++ b/public/Jailbreak.Public/Mod/Draw/BeamCircle.cs @@ -59,4 +59,10 @@ public override void Draw() } } } + + public void SetRadius(float radius) + { + this.radius = radius; + offsets = generateOffsets(); + } } \ No newline at end of file diff --git a/public/Jailbreak.Public/Mod/Draw/BeamLine.cs b/public/Jailbreak.Public/Mod/Draw/BeamLine.cs index 2bb8ba2a..3a073e34 100644 --- a/public/Jailbreak.Public/Mod/Draw/BeamLine.cs +++ b/public/Jailbreak.Public/Mod/Draw/BeamLine.cs @@ -25,11 +25,7 @@ public void Move(Vector start, Vector end) public override void Draw() { - if(this.beam != null) - { - this.beam.Remove(); - this.beam = null; - } + Remove(); var beam = Utilities.CreateEntityByName("env_beam"); if (beam == null) return; beam.RenderMode = RenderMode_t.kRenderTransColor;