CatStation/Content.Shared/Movement/Systems/SharedJumpAbilitySystem.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

113 lines
4.5 KiB
C#

using Content.Shared.Actions;
using Content.Shared.Actions.Components;
using Content.Shared.Cloning.Events;
using Content.Shared.Gravity;
using Content.Shared.Movement.Components;
using Content.Shared.Popups;
using Content.Shared.Standing;
using Content.Shared.Stunnable;
using Content.Shared.Throwing;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Physics.Events;
namespace Content.Shared.Movement.Systems;
public sealed partial class SharedJumpAbilitySystem : EntitySystem
{
[Dependency] private ThrowingSystem _throwing = default!;
[Dependency] private SharedAudioSystem _audio = default!;
[Dependency] private SharedGravitySystem _gravity = default!;
[Dependency] private SharedActionsSystem _actions = default!;
[Dependency] private SharedStunSystem _stun = default!;
[Dependency] private StandingStateSystem _standing = default!;
[Dependency] private SharedPopupSystem _popup = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<JumpAbilityComponent, MapInitEvent>(OnInit);
SubscribeLocalEvent<JumpAbilityComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<JumpAbilityComponent, GravityJumpEvent>(OnGravityJump);
SubscribeLocalEvent<ActiveLeaperComponent, StartCollideEvent>(OnLeaperCollide);
SubscribeLocalEvent<ActiveLeaperComponent, LandEvent>(OnLeaperLand);
SubscribeLocalEvent<ActiveLeaperComponent, StopThrowEvent>(OnLeaperStopThrow);
SubscribeLocalEvent<JumpAbilityComponent, CloningEvent>(OnClone);
}
private void OnInit(Entity<JumpAbilityComponent> entity, ref MapInitEvent args)
{
if (!TryComp(entity, out ActionsComponent? comp))
return;
_actions.AddAction(entity, ref entity.Comp.ActionEntity, entity.Comp.Action, component: comp);
}
private void OnShutdown(Entity<JumpAbilityComponent> entity, ref ComponentShutdown args)
{
_actions.RemoveAction(entity.Owner, entity.Comp.ActionEntity);
}
private void OnLeaperCollide(Entity<ActiveLeaperComponent> entity, ref StartCollideEvent args)
{
_stun.TryKnockdown(entity.Owner, entity.Comp.KnockdownDuration, force: true);
RemCompDeferred<ActiveLeaperComponent>(entity);
}
private void OnLeaperLand(Entity<ActiveLeaperComponent> entity, ref LandEvent args)
{
RemCompDeferred<ActiveLeaperComponent>(entity);
}
private void OnLeaperStopThrow(Entity<ActiveLeaperComponent> entity, ref StopThrowEvent args)
{
RemCompDeferred<ActiveLeaperComponent>(entity);
}
private void OnGravityJump(Entity<JumpAbilityComponent> entity, ref GravityJumpEvent args)
{
if (_gravity.IsWeightless(args.Performer) || _standing.IsDown(args.Performer))
{
if (entity.Comp.JumpFailedPopup != null)
_popup.PopupEntity(Loc.GetString(entity.Comp.JumpFailedPopup.Value), args.Performer, args.Performer);
return;
}
var xform = Transform(args.Performer);
var throwing = xform.LocalRotation.ToWorldVec() * entity.Comp.JumpDistance;
var direction = xform.Coordinates.Offset(throwing); // to make the character jump in the direction he's looking
_throwing.TryThrow(args.Performer, direction, entity.Comp.JumpThrowSpeed);
_audio.PlayPredicted(entity.Comp.JumpSound, args.Performer, args.Performer);
if (entity.Comp.CanCollide)
{
EnsureComp<ActiveLeaperComponent>(entity, out var leaperComp);
leaperComp.KnockdownDuration = entity.Comp.CollideKnockdown;
Dirty(entity.Owner, leaperComp);
}
args.Handled = true;
}
private void OnClone(Entity<JumpAbilityComponent> ent, ref CloningEvent args)
{
if (!args.Settings.EventComponents.Contains(Factory.GetRegistration(ent.Comp.GetType()).Name))
return;
// Make sure to set the datafields before adding the component so that the correct action gets spawned on map init.
var targetComp = Factory.GetComponent<JumpAbilityComponent>();
targetComp.Action = ent.Comp.Action;
targetComp.JumpDistance = ent.Comp.JumpDistance;
targetComp.JumpThrowSpeed = ent.Comp.JumpThrowSpeed;
targetComp.CanCollide = ent.Comp.CanCollide;
targetComp.CollideKnockdown = ent.Comp.CollideKnockdown;
targetComp.JumpSound = ent.Comp.JumpSound;
targetComp.JumpFailedPopup = ent.Comp.JumpFailedPopup;
AddComp(args.CloneUid, targetComp, true);
}
}