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.
This commit is contained in:
Ed
2025-06-19 12:47:46 +03:00
parent f4dd46cded
commit 63a1d60c6a
3 changed files with 29 additions and 6 deletions

View File

@@ -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<CP14DashComponent>(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);
}
}

View File

@@ -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<CP14DashSystem>();
dashSys.PerformDash(args.User.Value, args.Position.Value, DashSpeed);
dashSys.PerformDash(args.User.Value, args.Position.Value, Speed, Range);
}
}

View File

@@ -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