Fix barriers not working (#19774)

This commit is contained in:
DrSmugleaf
2023-09-04 15:33:40 -07:00
committed by GitHub
parent e4ca6f4fb9
commit 0527d2e719
5 changed files with 89 additions and 58 deletions

View File

@@ -1,7 +0,0 @@
namespace Content.Server.Security.Components;
[RegisterComponent]
public sealed partial class DeployableBarrierComponent : Component
{
}

View File

@@ -1,49 +0,0 @@
using Content.Server.Pulling;
using Content.Server.Security.Components;
using Content.Shared.Lock;
using Content.Shared.Pulling.Components;
using Content.Shared.Security;
using Robust.Server.GameObjects;
namespace Content.Server.Security.Systems
{
public sealed class DeployableBarrierSystem : EntitySystem
{
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly PullingSystem _pulling = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<DeployableBarrierComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<DeployableBarrierComponent, LockToggledEvent>(OnLockToggled);
}
private void OnStartup(EntityUid uid, DeployableBarrierComponent component, ComponentStartup args)
{
if (!TryComp(uid, out LockComponent? lockComponent))
return;
ToggleBarrierDeploy(uid, lockComponent.Locked);
}
private void OnLockToggled(EntityUid uid, DeployableBarrierComponent component, ref LockToggledEvent args)
{
ToggleBarrierDeploy(uid, args.Locked);
}
private void ToggleBarrierDeploy(EntityUid uid, bool isDeployed)
{
Transform(uid).Anchored = isDeployed;
var state = isDeployed ? DeployableBarrierState.Deployed : DeployableBarrierState.Idle;
_appearance.SetData(uid, DeployableBarrierVisuals.State, state);
if (TryComp<SharedPullableComponent>(uid, out var pullable))
_pulling.TryStopPull(pullable);
if (TryComp(uid, out PointLightComponent? light))
light.Enabled = isDeployed;
}
}
}

View File

@@ -0,0 +1,14 @@
using Content.Shared.Security.Systems;
using Robust.Shared.GameStates;
namespace Content.Shared.Security.Components;
[RegisterComponent, NetworkedComponent]
[Access(typeof(DeployableBarrierSystem))]
public sealed partial class DeployableBarrierComponent : Component
{
/// <summary>
/// The fixture to change collision on.
/// </summary>
[DataField("fixture", required: true)] public string FixtureId = string.Empty;
}

View File

@@ -0,0 +1,67 @@
using Content.Shared.Lock;
using Content.Shared.Pulling;
using Content.Shared.Pulling.Components;
using Content.Shared.Security.Components;
using Robust.Shared.Physics.Systems;
namespace Content.Shared.Security.Systems;
public sealed class DeployableBarrierSystem : EntitySystem
{
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly FixtureSystem _fixtures = default!;
[Dependency] private readonly SharedPointLightSystem _pointLight = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly SharedPullingSystem _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);
}
var state = isDeployed ? DeployableBarrierState.Deployed : DeployableBarrierState.Idle;
_appearance.SetData(uid, DeployableBarrierVisuals.State, state);
if (TryComp(uid, out SharedPullableComponent? pullable))
_pulling.TryStopPull(pullable);
if (TryComp(uid, out SharedPointLightComponent? light))
_pointLight.SetEnabled(uid, isDeployed, light);
}
}

View File

@@ -5,6 +5,7 @@
parent: BaseStructure parent: BaseStructure
components: components:
- type: Transform - type: Transform
anchored: false
noRot: true noRot: true
- type: Sprite - type: Sprite
sprite: Objects/Specific/Security/barrier.rsi sprite: Objects/Specific/Security/barrier.rsi
@@ -24,21 +25,26 @@
canCollide: false canCollide: false
- type: Fixtures - type: Fixtures
fixtures: fixtures:
fix1: base:
shape: shape:
!type:PhysShapeCircle !type:PhysShapeCircle
radius: 0.45 radius: 0.45
density: 75 density: 75
mask: mask:
- MachineMask - MachineMask
barrier:
shape:
!type:PhysShapeCircle
radius: 0.45
layer: layer:
- WallLayer - WallLayer
- type: DeployableBarrier
fixture: barrier
- type: AccessReader - type: AccessReader
access: [["Security"]] access: [["Security"]]
- type: Lock - type: Lock
locked: false locked: false
lockOnClick: true # toggle lock just by clicking on barrier lockOnClick: true # toggle lock just by clicking on barrier
- type: DeployableBarrier
- type: Damageable - type: Damageable
damageContainer: Inorganic damageContainer: Inorganic
damageModifierSet: Metallic damageModifierSet: Metallic