Files
wwdpublic/Content.Shared/Security/Systems/DeployableBarrierSystem.cs
SimpleStation14 24f36c1803 Mirror: Pulling Rework V2 (#269)
## Mirror of PR #24936: [Pulling rework
v2](https://github.com/space-wizards/space-station-14/pull/24936) from
<img src="https://avatars.githubusercontent.com/u/10567778?v=4"
alt="space-wizards" width="22"/>
[space-wizards](https://github.com/space-wizards)/[space-station-14](https://github.com/space-wizards/space-station-14)

###### `c584f6444a85cc53edb060230f7e7b2b76cc87bf`

PR opened by <img
src="https://avatars.githubusercontent.com/u/31366439?v=4"
width="16"/><a href="https://github.com/metalgearsloth">
metalgearsloth</a> at 2024-02-04 01:43:17 UTC

---

PR changed 53 files with 796 additions and 1356 deletions.

The PR had the following labels:
- Status: Needs Review


---

<details open="true"><summary><h1>Original Body</h1></summary>

> Health v2 moment
> 
> Fixes https://github.com/space-wizards/space-station-14/issues/24900
> 
> - Fixes container changes.
> - Fixes keybind.
> - Fixes multi-pull.
> - Fixes alerts cleanup for non-predicted pull stops.
> 
> I'm awake now for any issues.


</details>

---------

Co-authored-by: SimpleStation14 <Unknown>
Co-authored-by: Danger Revolution! <142105406+DangerRevolution@users.noreply.github.com>
Co-authored-by: VMSolidus <evilexecutive@gmail.com>
2024-07-09 19:51:27 -04:00

67 lines
2.3 KiB
C#

using Content.Shared.Lock;
using Content.Shared.Movement.Pulling.Components;
using Content.Shared.Movement.Pulling.Systems;
using Content.Shared.Security.Components;
using Robust.Shared.Physics.Systems;
namespace Content.Shared.Security.Systems;
public sealed class DeployableBarrierSystem : EntitySystem
{
[Dependency] private readonly FixtureSystem _fixtures = default!;
[Dependency] private readonly SharedPointLightSystem _pointLight = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly PullingSystem _pulling = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
public override void Initialize()
{
SubscribeLocalEvent<DeployableBarrierComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<DeployableBarrierComponent, LockToggledEvent>(OnLockToggled);
}
private void OnMapInit(EntityUid uid, DeployableBarrierComponent component, MapInitEvent args)
{
if (!TryComp(uid, out LockComponent? lockComponent))
return;
ToggleBarrierDeploy(uid, lockComponent.Locked, component);
}
private void OnLockToggled(EntityUid uid, DeployableBarrierComponent component, ref LockToggledEvent args)
{
ToggleBarrierDeploy(uid, args.Locked, component);
}
private void ToggleBarrierDeploy(EntityUid uid, bool isDeployed, DeployableBarrierComponent? component)
{
if (!Resolve(uid, ref component))
return;
var transform = Transform(uid);
var fixture = _fixtures.GetFixtureOrNull(uid, component.FixtureId);
if (isDeployed && transform.GridUid != null)
{
_transform.AnchorEntity(uid, transform);
if (fixture != null)
_physics.SetHard(uid, fixture, true);
}
else
{
_transform.Unanchor(uid, transform);
if (fixture != null)
_physics.SetHard(uid, fixture, false);
}
if (TryComp(uid, out PullableComponent? pullable))
_pulling.TryStopPull(uid, pullable);
SharedPointLightComponent? pointLight = null;
if (_pointLight.ResolveLight(uid, ref pointLight))
{
_pointLight.SetEnabled(uid, isDeployed, pointLight);
}
}
}