Adds anchor checks for containment fields (#8909)

* Adds anchor checks for containment fields

* norot

Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
keronshb
2022-06-23 00:27:49 -04:00
committed by GitHub
parent f5e21e1c8d
commit 4ecac09428
4 changed files with 68 additions and 0 deletions

View File

@@ -23,5 +23,11 @@ namespace Content.Server.Singularity.Components
public Tuple<Direction, ContainmentFieldConnection>? Connection1; public Tuple<Direction, ContainmentFieldConnection>? Connection1;
public Tuple<Direction, ContainmentFieldConnection>? Connection2; public Tuple<Direction, ContainmentFieldConnection>? Connection2;
[ViewVariables]
public bool Enabled;
[ViewVariables]
public bool IsConnected;
} }
} }

View File

@@ -8,12 +8,17 @@ using Robust.Shared.Physics;
using Robust.Shared.Physics.Dynamics; using Robust.Shared.Physics.Dynamics;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using Content.Server.Popups;
using Content.Shared.Construction.Components;
using Content.Shared.Interaction;
using Robust.Shared.Player;
namespace Content.Server.Singularity.EntitySystems namespace Content.Server.Singularity.EntitySystems
{ {
public sealed class ContainmentFieldGeneratorSystem : EntitySystem public sealed class ContainmentFieldGeneratorSystem : EntitySystem
{ {
[Dependency] private readonly TagSystem _tags = default!; [Dependency] private readonly TagSystem _tags = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
public override void Initialize() public override void Initialize()
{ {
@@ -24,6 +29,50 @@ namespace Content.Server.Singularity.EntitySystems
SubscribeLocalEvent<ContainmentFieldGeneratorComponent, StartCollideEvent>(HandleGeneratorCollide); SubscribeLocalEvent<ContainmentFieldGeneratorComponent, StartCollideEvent>(HandleGeneratorCollide);
SubscribeLocalEvent<ParticleProjectileComponent, StartCollideEvent>(HandleParticleCollide); SubscribeLocalEvent<ParticleProjectileComponent, StartCollideEvent>(HandleParticleCollide);
SubscribeLocalEvent<ContainmentFieldGeneratorComponent, AnchorStateChangedEvent>(OnAnchorChanged); SubscribeLocalEvent<ContainmentFieldGeneratorComponent, AnchorStateChangedEvent>(OnAnchorChanged);
SubscribeLocalEvent<ContainmentFieldGeneratorComponent, UnanchorAttemptEvent>(OnUnanchorAttempt);
SubscribeLocalEvent<ContainmentFieldGeneratorComponent, InteractHandEvent>(OnInteract);
}
private void OnInteract(EntityUid uid, ContainmentFieldGeneratorComponent component, InteractHandEvent args)
{
if (args.Handled)
return;
if (TryComp(component.Owner, out TransformComponent? transformComp) && transformComp.Anchored)
{
if (!component.Enabled)
TurnOn(component);
else if (component.Enabled && component.IsConnected)
{
_popupSystem.PopupEntity(Loc.GetString("comp-containment-anchor-warning"), args.User, Filter.Entities(args.User));
return;
}
else
TurnOff(component);
}
args.Handled = true;
}
private void OnUnanchorAttempt(EntityUid uid, ContainmentFieldGeneratorComponent component, UnanchorAttemptEvent args)
{
if (component.Enabled)
{
_popupSystem.PopupEntity(Loc.GetString("comp-containment-anchor-warning"), args.User, Filter.Entities(args.User));
args.Cancel();
}
}
private void TurnOn(ContainmentFieldGeneratorComponent component)
{
component.Enabled = true;
_popupSystem.PopupEntity(Loc.GetString("comp-containment-turned-on"), component.Owner, Filter.Pvs(component.Owner));
}
private void TurnOff(ContainmentFieldGeneratorComponent component)
{
component.Enabled = false;
_popupSystem.PopupEntity(Loc.GetString("comp-containment-turned-off"), component.Owner, Filter.Pvs(component.Owner));
} }
private void OnComponentRemoved(EntityUid uid, ContainmentFieldGeneratorComponent component, ComponentRemove args) private void OnComponentRemoved(EntityUid uid, ContainmentFieldGeneratorComponent component, ComponentRemove args)
@@ -101,11 +150,13 @@ namespace Content.Server.Singularity.EntitySystems
if (component.Connection1?.Item2 == connection) if (component.Connection1?.Item2 == connection)
{ {
component.Connection1 = null; component.Connection1 = null;
component.IsConnected = false;
UpdateConnectionLights(component); UpdateConnectionLights(component);
} }
else if (component.Connection2?.Item2 == connection) else if (component.Connection2?.Item2 == connection)
{ {
component.Connection2 = null; component.Connection2 = null;
component.IsConnected = false;
UpdateConnectionLights(component); UpdateConnectionLights(component);
} }
else if (connection != null) else if (connection != null)
@@ -117,6 +168,7 @@ namespace Content.Server.Singularity.EntitySystems
private bool TryGenerateFieldConnection([NotNullWhen(true)] ref Tuple<Direction, ContainmentFieldConnection>? propertyFieldTuple, ContainmentFieldGeneratorComponent component) private bool TryGenerateFieldConnection([NotNullWhen(true)] ref Tuple<Direction, ContainmentFieldConnection>? propertyFieldTuple, ContainmentFieldGeneratorComponent component)
{ {
if (propertyFieldTuple != null) return false; if (propertyFieldTuple != null) return false;
if (!component.Enabled) return false; //don't gen a field unless it's on
if (EntityManager.TryGetComponent<TransformComponent>(component.Owner, out var xform) && !xform.Anchored) return false; if (EntityManager.TryGetComponent<TransformComponent>(component.Owner, out var xform) && !xform.Anchored) return false;
foreach (var direction in new[] { Direction.North, Direction.East, Direction.South, Direction.West }) foreach (var direction in new[] { Direction.North, Direction.East, Direction.South, Direction.West })
@@ -165,6 +217,8 @@ namespace Content.Server.Singularity.EntitySystems
{ {
Logger.Error("When trying to connect two Containmentfieldgenerators, the second one already had two connection but the check didn't catch it"); Logger.Error("When trying to connect two Containmentfieldgenerators, the second one already had two connection but the check didn't catch it");
} }
component.IsConnected = true;
UpdateConnectionLights(component); UpdateConnectionLights(component);
return true; return true;
} }

View File

@@ -0,0 +1,7 @@
comp-containment-turned-on = The containment field generator boots up.
comp-containment-turned-off = The containment field generator shuts down.
comp-containment-connected = The containment field generator shoots out a light as it establishes a connection!
comp-containment-disconnected = The containment field generator light fades away, severing the connection.
comp-containment-anchor-warning = You cannot unanchor the containment field generator while it's on or connected!

View File

@@ -20,6 +20,7 @@
sprite: Structures/Power/Generation/Singularity/containment.rsi sprite: Structures/Power/Generation/Singularity/containment.rsi
state: icon state: icon
netsync: false netsync: false
noRot: true
- type: Icon - type: Icon
sprite: Structures/Power/Generation/Singularity/containment.rsi sprite: Structures/Power/Generation/Singularity/containment.rsi
state: icon state: icon