diff --git a/Content.Server/Singularity/Components/ContainmentFieldGeneratorComponent.cs b/Content.Server/Singularity/Components/ContainmentFieldGeneratorComponent.cs index 0e9631c202..40f34b1942 100644 --- a/Content.Server/Singularity/Components/ContainmentFieldGeneratorComponent.cs +++ b/Content.Server/Singularity/Components/ContainmentFieldGeneratorComponent.cs @@ -23,5 +23,11 @@ namespace Content.Server.Singularity.Components public Tuple? Connection1; public Tuple? Connection2; + [ViewVariables] + public bool Enabled; + + [ViewVariables] + public bool IsConnected; + } } diff --git a/Content.Server/Singularity/EntitySystems/ContainmentFieldGeneratorSystem.cs b/Content.Server/Singularity/EntitySystems/ContainmentFieldGeneratorSystem.cs index 0cee86fbc0..fbe2182c85 100644 --- a/Content.Server/Singularity/EntitySystems/ContainmentFieldGeneratorSystem.cs +++ b/Content.Server/Singularity/EntitySystems/ContainmentFieldGeneratorSystem.cs @@ -8,12 +8,17 @@ using Robust.Shared.Physics; using Robust.Shared.Physics.Dynamics; using System.Diagnostics.CodeAnalysis; 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 { public sealed class ContainmentFieldGeneratorSystem : EntitySystem { [Dependency] private readonly TagSystem _tags = default!; + [Dependency] private readonly PopupSystem _popupSystem = default!; public override void Initialize() { @@ -24,6 +29,50 @@ namespace Content.Server.Singularity.EntitySystems SubscribeLocalEvent(HandleGeneratorCollide); SubscribeLocalEvent(HandleParticleCollide); SubscribeLocalEvent(OnAnchorChanged); + SubscribeLocalEvent(OnUnanchorAttempt); + SubscribeLocalEvent(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) @@ -101,11 +150,13 @@ namespace Content.Server.Singularity.EntitySystems if (component.Connection1?.Item2 == connection) { component.Connection1 = null; + component.IsConnected = false; UpdateConnectionLights(component); } else if (component.Connection2?.Item2 == connection) { component.Connection2 = null; + component.IsConnected = false; UpdateConnectionLights(component); } else if (connection != null) @@ -117,6 +168,7 @@ namespace Content.Server.Singularity.EntitySystems private bool TryGenerateFieldConnection([NotNullWhen(true)] ref Tuple? propertyFieldTuple, ContainmentFieldGeneratorComponent component) { if (propertyFieldTuple != null) return false; + if (!component.Enabled) return false; //don't gen a field unless it's on if (EntityManager.TryGetComponent(component.Owner, out var xform) && !xform.Anchored) return false; 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"); } + + component.IsConnected = true; UpdateConnectionLights(component); return true; } diff --git a/Resources/Locale/en-US/singularity/components/containment-component.ftl b/Resources/Locale/en-US/singularity/components/containment-component.ftl new file mode 100644 index 0000000000..852981c05c --- /dev/null +++ b/Resources/Locale/en-US/singularity/components/containment-component.ftl @@ -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! diff --git a/Resources/Prototypes/Entities/Structures/Power/Generation/Singularity/containment.yml b/Resources/Prototypes/Entities/Structures/Power/Generation/Singularity/containment.yml index 720cd9c7fb..2b6aa5630d 100644 --- a/Resources/Prototypes/Entities/Structures/Power/Generation/Singularity/containment.yml +++ b/Resources/Prototypes/Entities/Structures/Power/Generation/Singularity/containment.yml @@ -20,6 +20,7 @@ sprite: Structures/Power/Generation/Singularity/containment.rsi state: icon netsync: false + noRot: true - type: Icon sprite: Structures/Power/Generation/Singularity/containment.rsi state: icon