From 63a1d60c6a6d1865ea48af11862cddfeb870c8f8 Mon Sep 17 00:00:00 2001 From: Ed Date: Thu, 19 Jun 2025 12:47:46 +0300 Subject: [PATCH] Add dash range limit to dash spell and system Introduces a maximum dash range to the dash system and spell effect, clamping the dash target if it exceeds the allowed distance. Updates configuration fields and prototype YAML to support the new range parameter. --- Content.Shared/_CP14/Dash/CP14DashSystem.cs | 22 +++++++++++++++++-- .../_CP14/MagicSpell/Spells/CP14SpellDash.cs | 8 +++++-- .../Entities/Actions/Spells/Physical/dash.yml | 5 +++-- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/Content.Shared/_CP14/Dash/CP14DashSystem.cs b/Content.Shared/_CP14/Dash/CP14DashSystem.cs index beac1b20ec..98e1ea851a 100644 --- a/Content.Shared/_CP14/Dash/CP14DashSystem.cs +++ b/Content.Shared/_CP14/Dash/CP14DashSystem.cs @@ -1,3 +1,4 @@ +using System.Numerics; using Content.Shared.ActionBlocker; using Content.Shared.Movement.Events; using Content.Shared.Throwing; @@ -11,6 +12,7 @@ public sealed partial class CP14DashSystem : EntitySystem [Dependency] private readonly ActionBlockerSystem _blocker = default!; [Dependency] private readonly ThrowingSystem _throwing = default!; [Dependency] private readonly SharedAudioSystem _audio = default!; + [Dependency] private readonly SharedTransformSystem _transform = default!; public override void Initialize() { @@ -46,10 +48,26 @@ public sealed partial class CP14DashSystem : EntitySystem args.Cancel(); } - public void PerformDash(EntityUid ent, EntityCoordinates targetPosition, float speed = 10f) + public void PerformDash(EntityUid ent, EntityCoordinates targetPosition, float speed = 10f, float maxDistance = 3.5f) { EnsureComp(ent, out var dash); _audio.PlayPredicted(dash.DashSound, ent, ent); - _throwing.TryThrow(ent, targetPosition, speed, null, 0f, 10, true, false, false, false, false); + + var entMapPos = _transform.ToMapCoordinates(Transform(ent).Coordinates); + var targetMapPos = _transform.ToMapCoordinates(targetPosition); + + var distance = Vector2.Distance(entMapPos.Position, targetMapPos.Position); + + if (distance > maxDistance) + { + var direction = (targetMapPos.Position - entMapPos.Position).Normalized(); + var clampedTarget = entMapPos.Position + direction * maxDistance; + targetMapPos = new MapCoordinates(clampedTarget, entMapPos.MapId); + } + + var finalTarget = _transform.ToCoordinates(targetMapPos); + + _throwing.TryThrow(ent, finalTarget, speed, null, 0f, 10, true, false, false, false, false); } + } diff --git a/Content.Shared/_CP14/MagicSpell/Spells/CP14SpellDash.cs b/Content.Shared/_CP14/MagicSpell/Spells/CP14SpellDash.cs index f971472fed..d87f5568dd 100644 --- a/Content.Shared/_CP14/MagicSpell/Spells/CP14SpellDash.cs +++ b/Content.Shared/_CP14/MagicSpell/Spells/CP14SpellDash.cs @@ -5,7 +5,11 @@ namespace Content.Shared._CP14.MagicSpell.Spells; public sealed partial class CP14SpellDash : CP14SpellEffect { [DataField] - public float DashSpeed = 10f; + public float Speed = 10f; + + [DataField] + public float Range = 3.5f; + public override void Effect(EntityManager entManager, CP14SpellEffectBaseArgs args) { if (args.User is null) @@ -15,6 +19,6 @@ public sealed partial class CP14SpellDash : CP14SpellEffect var dashSys = entManager.System(); - dashSys.PerformDash(args.User.Value, args.Position.Value, DashSpeed); + dashSys.PerformDash(args.User.Value, args.Position.Value, Speed, Range); } } diff --git a/Resources/Prototypes/_CP14/Entities/Actions/Spells/Physical/dash.yml b/Resources/Prototypes/_CP14/Entities/Actions/Spells/Physical/dash.yml index 29f8cd566e..2638739ed3 100644 --- a/Resources/Prototypes/_CP14/Entities/Actions/Spells/Physical/dash.yml +++ b/Resources/Prototypes/_CP14/Entities/Actions/Spells/Physical/dash.yml @@ -9,14 +9,15 @@ - type: CP14MagicEffect effects: - !type:CP14SpellDash - dashSpeed: 20 + speed: 20 + range: 3.5 - type: Action icon: sprite: _CP14/Actions/Spells/physical.rsi state: dash - type: TargetAction checkCanAccess: false - range: 3.5 + range: 10 #Thats not dash range, thats interaction clickable zone range - type: WorldTargetAction event: !type:CP14WorldTargetActionEvent cooldown: 5 \ No newline at end of file