CatStation/Content.Shared/Ninja/Systems/DashAbilitySystem.cs
Whatstone a88d2c5164
Cleanup: Resolve remaining PopupSystem warnings in Content.Shared (#44685)
* PopupClient to PopupEntity/Coordinates

* PopupPredictedX to PopupEntity/Cursor/Coordinates

* The rest of the damn owl

* nullability fixes

* Buckle cleanup

* cleanup, address PR comments

* ExecutionSystem: one popup method

* correct my filthy lies

* Apply most of ajcm's suggestions

* return user to SharedItemRecallSystem.cs

* Fix lingering Ensnarable broadcast popups

* targeted drain popups

* fix lingering untargeted Guardian popups

I read the comment on GuardianHostRecall.  Oops.

* target stethoscope popups

* fix the PDA vibration popup

* Fix target for encryption key removal popup

* anomaly scanner: args.User, not uid

* disposal unit comment, bcast pda vibration popup
2026-07-16 21:54:33 +00:00

105 lines
3.9 KiB
C#

using Content.Shared.Actions;
using Content.Shared.Charges.Systems;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction;
using Content.Shared.Movement.Pulling.Components;
using Content.Shared.Movement.Pulling.Systems;
using Content.Shared.Ninja.Components;
using Content.Shared.Popups;
using Content.Shared.Examine;
namespace Content.Shared.Ninja.Systems;
/// <summary>
/// Handles dashing logic including charge consumption and checking attempt events.
/// </summary>
public sealed partial class DashAbilitySystem : EntitySystem
{
[Dependency] private ActionContainerSystem _actionContainer = default!;
[Dependency] private SharedChargesSystem _sharedCharges = default!;
[Dependency] private SharedHandsSystem _hands = default!;
[Dependency] private ExamineSystemShared _examine = default!;
[Dependency] private SharedPopupSystem _popup = default!;
[Dependency] private PullingSystem _pullingSystem = default!;
[Dependency] private SharedTransformSystem _transform = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<DashAbilityComponent, GetItemActionsEvent>(OnGetActions);
SubscribeLocalEvent<DashAbilityComponent, DashEvent>(OnDash);
SubscribeLocalEvent<DashAbilityComponent, MapInitEvent>(OnMapInit);
}
private void OnMapInit(Entity<DashAbilityComponent> ent, ref MapInitEvent args)
{
var (uid, comp) = ent;
_actionContainer.EnsureAction(uid, ref comp.DashActionEntity, comp.DashAction);
Dirty(uid, comp);
}
private void OnGetActions(Entity<DashAbilityComponent> ent, ref GetItemActionsEvent args)
{
if (CheckDash(ent, args.User))
args.AddAction(ent.Comp.DashActionEntity);
}
/// <summary>
/// Handle charges and teleport to a visible location.
/// </summary>
private void OnDash(Entity<DashAbilityComponent> ent, ref DashEvent args)
{
var (uid, comp) = ent;
var user = args.Performer;
if (!CheckDash(uid, user))
return;
if (!_hands.IsHolding(user, uid, out var _))
{
_popup.PopupEntity(Loc.GetString("dash-ability-not-held", ("item", uid)), user, user);
return;
}
var origin = _transform.GetMapCoordinates(user);
var target = _transform.ToMapCoordinates(args.Target);
if (!_examine.InRangeUnOccluded(origin, target, SharedInteractionSystem.MaxRaycastRange, null))
{
// can only dash if the destination is visible on screen
_popup.PopupEntity(Loc.GetString("dash-ability-cant-see", ("item", uid)), user, user);
return;
}
if (!_sharedCharges.TryUseCharge(uid))
{
_popup.PopupEntity(Loc.GetString("dash-ability-no-charges", ("item", uid)), user, user);
return;
}
// Check if the user is BEING pulled, and escape if so
if (TryComp<PullableComponent>(user, out var pull) && _pullingSystem.IsPulled(user, pull))
_pullingSystem.TryStopPull(user, pull);
// Check if the user is pulling anything, and drop it if so
if (TryComp<PullerComponent>(user, out var puller) && TryComp<PullableComponent>(puller.Pulling, out var pullable))
_pullingSystem.TryStopPull(puller.Pulling.Value, pullable);
var xform = Transform(user);
_transform.SetCoordinates(user, xform, args.Target);
_transform.AttachToGridOrMap(user, xform);
args.Handled = true;
}
public bool CheckDash(EntityUid uid, EntityUid user)
{
var ev = new CheckDashEvent(user);
RaiseLocalEvent(uid, ref ev);
return !ev.Cancelled;
}
}
/// <summary>
/// Raised on the item before adding the dash action and when using the action.
/// </summary>
[ByRefEvent]
public record struct CheckDashEvent(EntityUid User, bool Cancelled = false);