APCs now require engineering access (#2795)

* APCs now require engineering access

* Allow if access reader is null
This commit is contained in:
ike709
2020-12-22 06:08:35 -06:00
committed by GitHub
parent eb576884f9
commit 7f7f22ef5d
2 changed files with 24 additions and 4 deletions

View File

@@ -1,9 +1,11 @@
#nullable enable #nullable enable
using System; using System;
using Content.Server.GameObjects.Components.Access;
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups; using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
using Content.Server.GameObjects.Components.Power.PowerNetComponents; using Content.Server.GameObjects.Components.Power.PowerNetComponents;
using Content.Server.Utility; using Content.Server.Utility;
using Content.Shared.GameObjects.Components.Power; using Content.Shared.GameObjects.Components.Power;
using Content.Shared.Interfaces;
using Content.Shared.Interfaces.GameObjects.Components; using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Server.GameObjects.Components.UserInterface; using Robust.Server.GameObjects.Components.UserInterface;
@@ -11,9 +13,11 @@ using Robust.Server.GameObjects.EntitySystems;
using Robust.Server.Interfaces.GameObjects; using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.ComponentDependencies;
using Robust.Shared.GameObjects.Systems; using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.Timing; using Robust.Shared.Interfaces.Timing;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Power.ApcNetComponents 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; public BatteryComponent? Battery => Owner.TryGetComponent(out BatteryComponent? batteryComponent) ? batteryComponent : null;
[ComponentDependency] private AccessReader? _accessReader = null;
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
@@ -57,6 +63,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents
Owner.EnsureComponent<BatteryComponent>(); Owner.EnsureComponent<BatteryComponent>();
Owner.EnsureComponent<PowerConsumerComponent>(); Owner.EnsureComponent<PowerConsumerComponent>();
Owner.EnsureComponentWarn<ServerUserInterfaceComponent>(); Owner.EnsureComponentWarn<ServerUserInterfaceComponent>();
Owner.EnsureComponentWarn<AccessReader>();
if (UserInterface != null) if (UserInterface != null)
{ {
@@ -80,9 +87,20 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents
{ {
if (serverMsg.Message is ApcToggleMainBreakerMessage) if (serverMsg.Message is ApcToggleMainBreakerMessage)
{ {
MainBreakerEnabled = !MainBreakerEnabled; var user = serverMsg.Session.AttachedEntity;
_uiDirty = true; if(user == null) return;
EntitySystem.Get<AudioSystem>().PlayFromEntity("/Audio/Machines/machine_switch.ogg", Owner, AudioParams.Default.WithVolume(-2f));
if (_accessReader == null || _accessReader.IsAllowed(user))
{
MainBreakerEnabled = !MainBreakerEnabled;
_uiDirty = true;
EntitySystem.Get<AudioSystem>().PlayFromEntity("/Audio/Machines/machine_switch.ogg", Owner, AudioParams.Default.WithVolume(-2f));
}
else
{
user.PopupMessageCursor(Loc.GetString("Insufficient access!"));
}
} }
} }

View File

@@ -155,6 +155,8 @@
mode: SnapgridCenter mode: SnapgridCenter
components: components:
- type: Clickable - type: Clickable
- type: AccessReader
access: [["Engineering"]]
- type: InteractionOutline - type: InteractionOutline
- type: Physics - type: Physics
shapes: shapes: