]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix adding/removing airlock protections via welding (#19926)
authorchromiumboy <50505512+chromiumboy@users.noreply.github.com>
Thu, 14 Sep 2023 05:54:49 +0000 (00:54 -0500)
committerGitHub <noreply@github.com>
Thu, 14 Sep 2023 05:54:49 +0000 (21:54 -0800)
Content.Server/Doors/Systems/AirlockSystem.cs
Content.Server/Wires/WiresSystem.cs
Content.Shared/Tools/Systems/WeldableSystem.cs
Content.Shared/Wires/SharedWiresSystem.cs
Content.Shared/Wires/WiresPanelComponent.cs
Content.Shared/Wires/WiresPanelSecurityLevelPrototype.cs
Resources/Prototypes/Entities/Structures/Doors/Airlocks/airlocks.yml
Resources/Prototypes/Entities/Structures/Doors/wires_panel_security.yml

index f07dd23f4b1e0deb0ae24f3bb3693bdecc1e302f..bb75fc7d4764a230d300a867df6dce4c3af70f3b 100644 (file)
@@ -9,6 +9,7 @@ using Content.Shared.Doors.Systems;
 using Content.Shared.Interaction;
 using Robust.Server.GameObjects;
 using Content.Shared.Wires;
+using Robust.Shared.Prototypes;
 
 namespace Content.Server.Doors.Systems;
 
@@ -17,6 +18,7 @@ public sealed class AirlockSystem : SharedAirlockSystem
     [Dependency] private readonly WiresSystem _wiresSystem = default!;
     [Dependency] private readonly PowerReceiverSystem _power = default!;
     [Dependency] private readonly DoorBoltSystem _bolts = default!;
+    [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
 
     public override void Initialize()
     {
@@ -149,8 +151,11 @@ public sealed class AirlockSystem : SharedAirlockSystem
 
     private void OnActivate(EntityUid uid, AirlockComponent component, ActivateInWorldEvent args)
     {
-        if (TryComp<WiresPanelComponent>(uid, out var panel) && panel.Open && panel.WiresAccessible
-            && TryComp<ActorComponent>(args.User, out var actor))
+        if (TryComp<WiresPanelComponent>(uid, out var panel) &&
+            panel.Open &&
+            _prototypeManager.TryIndex<WiresPanelSecurityLevelPrototype>(panel.CurrentSecurityLevelID, out var securityLevelPrototype) &&
+            securityLevelPrototype.WiresAccessible &&
+            TryComp<ActorComponent>(args.User, out var actor))
         {
             _wiresSystem.OpenUserInterface(uid, actor.PlayerSession);
             args.Handled = true;
index 0baf0c5c224f05e1178e3eeb3d6b6839fd56c172..e9522485ca1bb337453398b13dd7696edea40bcd 100644 (file)
@@ -59,7 +59,6 @@ public sealed class WiresSystem : SharedWiresSystem
         SubscribeLocalEvent<ActivatableUIRequiresPanelComponent, ActivatableUIOpenAttemptEvent>(OnAttemptOpenActivatableUI);
         SubscribeLocalEvent<ActivatableUIRequiresPanelComponent, PanelChangedEvent>(OnActivatableUIPanelChanged);
     }
-
     private void SetOrCreateWireLayout(EntityUid uid, WiresComponent? wires = null)
     {
         if (!Resolve(uid, ref wires))
@@ -459,7 +458,9 @@ public sealed class WiresSystem : SharedWiresSystem
         if (!TryComp<ToolComponent>(args.Used, out var tool) || !TryComp<WiresPanelComponent>(uid, out var panel))
             return;
 
-        if (panel.Open && panel.WiresAccessible &&
+        if (panel.Open &&
+            _protoMan.TryIndex<WiresPanelSecurityLevelPrototype>(panel.CurrentSecurityLevelID, out var securityLevelPrototype) &&
+            securityLevelPrototype.WiresAccessible &&
             (_toolSystem.HasQuality(args.Used, "Cutting", tool) ||
             _toolSystem.HasQuality(args.Used, "Pulsing", tool)))
         {
@@ -642,14 +643,14 @@ public sealed class WiresSystem : SharedWiresSystem
     {
         component.Visible = visible;
         UpdateAppearance(uid, component);
-        Dirty(component);
+        Dirty(uid, component);
     }
 
     public void TogglePanel(EntityUid uid, WiresPanelComponent component, bool open)
     {
         component.Open = open;
         UpdateAppearance(uid, component);
-        Dirty(component);
+        Dirty(uid, component);
 
         var ev = new PanelChangedEvent(component.Open);
         RaiseLocalEvent(uid, ref ev);
@@ -657,16 +658,11 @@ public sealed class WiresSystem : SharedWiresSystem
 
     public void SetWiresPanelSecurityData(EntityUid uid, WiresPanelComponent component, string wiresPanelSecurityLevelID)
     {
-        var wiresPanelSecurityLevelPrototype = _protoMan.Index<WiresPanelSecurityLevelPrototype>(wiresPanelSecurityLevelID);
-
-        if (wiresPanelSecurityLevelPrototype == null)
-            return;
-
-        component.WiresAccessible = wiresPanelSecurityLevelPrototype.WiresAccessible;
-        component.WiresPanelSecurityExamination = wiresPanelSecurityLevelPrototype.Examine;
-        Dirty(component);
+        component.CurrentSecurityLevelID = wiresPanelSecurityLevelID;
+        Dirty(uid, component);
 
-        if (wiresPanelSecurityLevelPrototype?.WiresAccessible == false)
+        if (_protoMan.TryIndex<WiresPanelSecurityLevelPrototype>(component.CurrentSecurityLevelID, out var securityLevelPrototype) &&
+            securityLevelPrototype.WiresAccessible)
         {
             _uiSystem.TryCloseAll(uid, WiresUiKey.Key);
         }
index 11ead6bba10179b86cd84e3b80e5e29c434af02c..f887ed3049f767925597c5c8b74785059bebe81c 100644 (file)
@@ -41,16 +41,6 @@ public sealed class WeldableSystem : EntitySystem
 
     private void OnInteractUsing(EntityUid uid, WeldableComponent component, InteractUsingEvent args)
     {
-        // If any construction graph edges has its conditions meet and requires welding, then this construction takes priority
-        /* TODO: Whatever this is is not the way to do what you think you want to do.
-        if (Enumerable.Any<ConstructionGraphEdge>(_construction.GetCurrentNode(uid)?.Edges, x => _construction.CheckConditions(uid, x.Conditions)
-                                                                                                                               && Enumerable.Any<ConstructionGraphStep>(x.Steps, y => (y as ToolConstructionGraphStep)?.Tool == "Welding")) == true)
-        {
-            args.Handled = false;
-            return;
-        }
-        */
-
         if (args.Handled)
             return;
 
index 78cb2980708268accb6f9f5b463392073f858436..055827e8b1dd288225809f3266b274957d4710a1 100644 (file)
@@ -1,13 +1,19 @@
 using Content.Shared.Examine;
+using Content.Shared.Tools.Systems;
+using Robust.Shared.Prototypes;
 
 namespace Content.Shared.Wires;
 
 public abstract class SharedWiresSystem : EntitySystem
 {
+    [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
+
     public override void Initialize()
     {
         base.Initialize();
+
         SubscribeLocalEvent<WiresPanelComponent, ExaminedEvent>(OnExamine);
+        SubscribeLocalEvent<WiresPanelComponent, WeldableAttemptEvent>(OnWeldableAttempt);
     }
 
     private void OnExamine(EntityUid uid, WiresPanelComponent component, ExaminedEvent args)
@@ -20,10 +26,21 @@ public abstract class SharedWiresSystem : EntitySystem
         {
             args.PushMarkup(Loc.GetString("wires-panel-component-on-examine-open"));
 
-            if (component?.WiresPanelSecurityExamination != null)
+            if (_prototypeManager.TryIndex<WiresPanelSecurityLevelPrototype>(component.CurrentSecurityLevelID, out var securityLevelPrototype) &&
+                securityLevelPrototype.Examine != null)
             {
-                args.PushMarkup(Loc.GetString(component.WiresPanelSecurityExamination));
+                args.PushMarkup(Loc.GetString(securityLevelPrototype.Examine));
             }
         }
     }
+
+    private void OnWeldableAttempt(EntityUid uid, WiresPanelComponent component, WeldableAttemptEvent args)
+    {
+        if (component.Open &&
+            _prototypeManager.TryIndex<WiresPanelSecurityLevelPrototype>(component.CurrentSecurityLevelID, out var securityLevelPrototype) &&
+            !securityLevelPrototype.WeldingAllowed)
+        {
+            args.Cancel();
+        }
+    }
 }
index db7d018625f93828dc8b31c07ef3a816eef8701c..adc9d9a5f097f77133af93d2c35bd210a9950aa8 100644 (file)
@@ -28,11 +28,13 @@ public sealed partial class WiresPanelComponent : Component
     [DataField("screwdriverCloseSound")]
     public SoundSpecifier ScrewdriverCloseSound = new SoundPathSpecifier("/Audio/Machines/screwdriverclose.ogg");
 
+    /// <summary>
+    ///     This prototype describes the current security features of the wire panel
+    /// </summary>
+    [DataField("securityLevel")]
+    [ValidatePrototypeId<WiresPanelSecurityLevelPrototype>]
     [AutoNetworkedField]
-    public string? WiresPanelSecurityExamination = default!;
-
-    [AutoNetworkedField]
-    public bool WiresAccessible = true;
+    public string CurrentSecurityLevelID = "Level0";
 }
 
 /// <summary>
index f5a72a66d75ed373379c0c141c67c865aaa5f16c..8ddc8eeab8192a9273226287234ab6271c4299fe 100644 (file)
@@ -8,9 +8,24 @@ public sealed class WiresPanelSecurityLevelPrototype : IPrototype
     [IdDataField]
     public string ID { get; private set; } = default!;
 
+    /// <summary>
+    ///     A verbal description of the wire panel's current security level
+    /// </summary>
     [DataField("examine")]
     public string? Examine = default!;
 
+    /// <summary>
+    ///     Determines whether the wiring is accessible to hackers or not
+    /// </summary>
     [DataField("wiresAccessible")]
     public bool WiresAccessible = true;
+
+    /// <summary>
+    ///     Determines whether the device can be welded shut or not
+    /// </summary>
+    /// <remarks>
+    ///     Should be set false when you need to weld/unweld something to/from the wire panel
+    /// </remarks>
+    [DataField("weldingAllowed")]
+    public bool WeldingAllowed = true;
 }
index e729cbe6f9225087bc1a63246baf00f2593c0b3f..0d77c8b98638f1ea28ec2d62b57eba3a8d49d864 100644 (file)
@@ -21,6 +21,8 @@
   components:
   - type: Sprite
     sprite: Structures/Doors/Airlocks/Standard/atmospherics.rsi
+  - type: WiresPanel
+    securityLevel: Level2
   - type: Construction
     node: airlockMedSecurity
 
@@ -71,6 +73,8 @@
   components:
   - type: Sprite
     sprite: Structures/Doors/Airlocks/Standard/command.rsi
+  - type: WiresPanel
+    securityLevel: Level5
   - type: Construction
     node: airlockMaxSecurity
 
@@ -81,6 +85,8 @@
   components:
   - type: Sprite
     sprite: Structures/Doors/Airlocks/Standard/security.rsi
+  - type: WiresPanel
+    securityLevel: Level2
   - type: Construction
     node: airlockMedSecurity
 
     sprite: Structures/Doors/Airlocks/Glass/atmospherics.rsi
   - type: PaintableAirlock
     group: Glass
+  - type: WiresPanel
+    securityLevel: Level2
   - type: Construction
     node: glassAirlockMedSecurity
 
     sprite: Structures/Doors/Airlocks/Glass/command.rsi
   - type: PaintableAirlock
     group: Glass
+  - type: WiresPanel
+    securityLevel: Level5
   - type: Construction
     node: glassAirlockMaxSecurity
 
     sprite: Structures/Doors/Airlocks/Glass/security.rsi
   - type: PaintableAirlock
     group: Glass
+  - type: WiresPanel
+    securityLevel: Level2
   - type: Construction
     node: glassAirlockMedSecurity
 
index fb5b7626620643735a5b6592bdf1c8658cd2a553..4a42ed36ad8f93490a916764c73f5940aec78f82 100644 (file)
@@ -6,21 +6,25 @@
   id: Level1
   examine: wires-panel-component-on-examine-security-level1
   wiresAccessible: false
+  weldingAllowed: false
   
 - type: WiresPanelSecurityLevel
   id: Level2
   examine: wires-panel-component-on-examine-security-level2
   wiresAccessible: false
+  weldingAllowed: false
   
 - type: WiresPanelSecurityLevel
   id: Level3
   examine: wires-panel-component-on-examine-security-level3
   wiresAccessible: false
+  weldingAllowed: false
   
 - type: WiresPanelSecurityLevel
   id: Level4
   examine: wires-panel-component-on-examine-security-level4
   wiresAccessible: false
+  weldingAllowed: false
   
 - type: WiresPanelSecurityLevel
   id: Level5
   id: Level6
   examine: wires-panel-component-on-examine-security-level6
   wiresAccessible: false
+  weldingAllowed: false
   
 - type: WiresPanelSecurityLevel
   id: Level7
   examine: wires-panel-component-on-examine-security-level7
   wiresAccessible: false
+  weldingAllowed: false
   
\ No newline at end of file