From 7f7f22ef5d2c62d9a3ad60eff49cc1c1b83840ab Mon Sep 17 00:00:00 2001 From: ike709 Date: Tue, 22 Dec 2020 06:08:35 -0600 Subject: [PATCH] APCs now require engineering access (#2795) * APCs now require engineering access * Allow if access reader is null --- .../Power/ApcNetComponents/ApcComponent.cs | 26 ++++++++++++++++--- .../Constructible/Power/power_base.yml | 2 ++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Content.Server/GameObjects/Components/Power/ApcNetComponents/ApcComponent.cs b/Content.Server/GameObjects/Components/Power/ApcNetComponents/ApcComponent.cs index ceac693a91..4edd7f3df8 100644 --- a/Content.Server/GameObjects/Components/Power/ApcNetComponents/ApcComponent.cs +++ b/Content.Server/GameObjects/Components/Power/ApcNetComponents/ApcComponent.cs @@ -1,9 +1,11 @@ -#nullable enable +#nullable enable using System; +using Content.Server.GameObjects.Components.Access; using Content.Server.GameObjects.Components.NodeContainer.NodeGroups; using Content.Server.GameObjects.Components.Power.PowerNetComponents; using Content.Server.Utility; using Content.Shared.GameObjects.Components.Power; +using Content.Shared.Interfaces; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Server.GameObjects; using Robust.Server.GameObjects.Components.UserInterface; @@ -11,9 +13,11 @@ using Robust.Server.GameObjects.EntitySystems; using Robust.Server.Interfaces.GameObjects; using Robust.Shared.Audio; using Robust.Shared.GameObjects; +using Robust.Shared.GameObjects.ComponentDependencies; using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.Timing; using Robust.Shared.IoC; +using Robust.Shared.Localization; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Power.ApcNetComponents @@ -50,6 +54,8 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents public BatteryComponent? Battery => Owner.TryGetComponent(out BatteryComponent? batteryComponent) ? batteryComponent : null; + [ComponentDependency] private AccessReader? _accessReader = null; + public override void Initialize() { base.Initialize(); @@ -57,6 +63,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents Owner.EnsureComponent(); Owner.EnsureComponent(); Owner.EnsureComponentWarn(); + Owner.EnsureComponentWarn(); if (UserInterface != null) { @@ -80,9 +87,20 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents { if (serverMsg.Message is ApcToggleMainBreakerMessage) { - MainBreakerEnabled = !MainBreakerEnabled; - _uiDirty = true; - EntitySystem.Get().PlayFromEntity("/Audio/Machines/machine_switch.ogg", Owner, AudioParams.Default.WithVolume(-2f)); + var user = serverMsg.Session.AttachedEntity; + if(user == null) return; + + if (_accessReader == null || _accessReader.IsAllowed(user)) + { + MainBreakerEnabled = !MainBreakerEnabled; + _uiDirty = true; + EntitySystem.Get().PlayFromEntity("/Audio/Machines/machine_switch.ogg", Owner, AudioParams.Default.WithVolume(-2f)); + } + else + { + user.PopupMessageCursor(Loc.GetString("Insufficient access!")); + } + } } diff --git a/Resources/Prototypes/Entities/Constructible/Power/power_base.yml b/Resources/Prototypes/Entities/Constructible/Power/power_base.yml index 958c28d0e6..01e5d25777 100644 --- a/Resources/Prototypes/Entities/Constructible/Power/power_base.yml +++ b/Resources/Prototypes/Entities/Constructible/Power/power_base.yml @@ -155,6 +155,8 @@ mode: SnapgridCenter components: - type: Clickable + - type: AccessReader + access: [["Engineering"]] - type: InteractionOutline - type: Physics shapes: