Fix adding/removing airlock protections via welding (#19926)

This commit is contained in:
chromiumboy
2023-09-14 00:54:49 -05:00
committed by GitHub
parent 4c25483693
commit 3753fed920
8 changed files with 74 additions and 31 deletions

View 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;

View 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);
component.CurrentSecurityLevelID = wiresPanelSecurityLevelID;
Dirty(uid, component);
if (wiresPanelSecurityLevelPrototype == null)
return;
component.WiresAccessible = wiresPanelSecurityLevelPrototype.WiresAccessible;
component.WiresPanelSecurityExamination = wiresPanelSecurityLevelPrototype.Examine;
Dirty(component);
if (wiresPanelSecurityLevelPrototype?.WiresAccessible == false)
if (_protoMan.TryIndex<WiresPanelSecurityLevelPrototype>(component.CurrentSecurityLevelID, out var securityLevelPrototype) &&
securityLevelPrototype.WiresAccessible)
{
_uiSystem.TryCloseAll(uid, WiresUiKey.Key);
}

View 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;

View 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();
}
}
}

View 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>

View 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;
}

View 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
@@ -170,6 +176,8 @@
sprite: Structures/Doors/Airlocks/Glass/atmospherics.rsi
- type: PaintableAirlock
group: Glass
- type: WiresPanel
securityLevel: Level2
- type: Construction
node: glassAirlockMedSecurity
@@ -222,6 +230,8 @@
sprite: Structures/Doors/Airlocks/Glass/command.rsi
- type: PaintableAirlock
group: Glass
- type: WiresPanel
securityLevel: Level5
- type: Construction
node: glassAirlockMaxSecurity
@@ -234,6 +244,8 @@
sprite: Structures/Doors/Airlocks/Glass/security.rsi
- type: PaintableAirlock
group: Glass
- type: WiresPanel
securityLevel: Level2
- type: Construction
node: glassAirlockMedSecurity

View 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
@@ -31,9 +35,11 @@
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