From b20b4b11ccc9dcb76e936845cb440d99a29dbeea Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Sat, 21 Jan 2023 12:51:02 +1300 Subject: [PATCH] Wire action cleanup (#13496) --- Content.Server/Access/AccessWireAction.cs | 66 +++------------- .../ArcadeInvincibilityWireActions.cs | 28 +++---- .../WireActions/ArcadeOverflowWireAction.cs | 25 ++---- .../Monitor/WireActions/AirAlarmPanicWire.cs | 40 ++-------- .../WireActions/AtmosAlarmableAlarmWire.cs | 61 ++++---------- .../WireActions/DoorBoltLightWireAction.cs | 60 +++----------- .../Doors/WireActions/DoorBoltWireAction.cs | 77 ++++-------------- .../Doors/WireActions/DoorSafetyWireAction.cs | 66 ++++------------ .../Doors/WireActions/DoorTimingWireAction.cs | 79 +++++-------------- .../Medical/CryoPodEjectLockWireAction.cs | 45 +++-------- Content.Server/Power/PowerWireAction.cs | 50 +++--------- .../VendingMachineContrabandWireAction.cs | 16 ++-- .../VendingMachineEjectItemWireAction.cs | 59 +++----------- Content.Server/Wires/BaseToggleWireAction.cs | 4 +- Content.Server/Wires/BaseWireAction.cs | 69 ++++++++++------ Content.Server/Wires/ComponentWireAction.cs | 40 ++++++++++ Content.Server/Wires/DummyWireAction.cs | 44 ----------- Content.Server/Wires/IWireAction.cs | 9 +-- Content.Server/Wires/WiresSystem.cs | 64 +++++++-------- Content.Shared.Database/LogType.cs | 3 +- Resources/Locale/en-US/wires/wire-names.ftl | 16 ++++ 21 files changed, 294 insertions(+), 627 deletions(-) create mode 100644 Content.Server/Wires/ComponentWireAction.cs delete mode 100644 Content.Server/Wires/DummyWireAction.cs create mode 100644 Resources/Locale/en-US/wires/wire-names.ftl diff --git a/Content.Server/Access/AccessWireAction.cs b/Content.Server/Access/AccessWireAction.cs index 0f40de544a..35f3efbf0d 100644 --- a/Content.Server/Access/AccessWireAction.cs +++ b/Content.Server/Access/AccessWireAction.cs @@ -5,76 +5,36 @@ using Content.Shared.Wires; namespace Content.Server.Access; -[DataDefinition] -public sealed class AccessWireAction : BaseWireAction +public sealed class AccessWireAction : ComponentWireAction { - [DataField("color")] - private Color _statusColor = Color.Green; - - [DataField("name")] - private string _text = "ACC"; - protected override string Text - { - get => _text; - set => _text = value; - } + public override Color Color { get; set; } = Color.Green; + public override string Name { get; set; } = "wire-name-access"; [DataField("pulseTimeout")] private int _pulseTimeout = 30; - public override StatusLightData? GetStatusLightData(Wire wire) - { - StatusLightState lightState = StatusLightState.Off; - if (IsPowered(wire.Owner) - && EntityManager.TryGetComponent(wire.Owner, out var access)) - { - if (access.Enabled) - { - lightState = StatusLightState.On; - } - } - - return new StatusLightData( - _statusColor, - lightState, - _text); - } + public override StatusLightState? GetLightState(Wire wire, AccessReaderComponent comp) + => comp.Enabled ? StatusLightState.On : StatusLightState.Off; public override object StatusKey { get; } = AccessWireActionKey.Status; - public override bool Cut(EntityUid user, Wire wire) + public override bool Cut(EntityUid user, Wire wire, AccessReaderComponent comp) { - base.Cut(user, wire); - if (EntityManager.TryGetComponent(wire.Owner, out var access)) - { - WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key); - access.Enabled = false; - } - + WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key); + comp.Enabled = false; return true; } - public override bool Mend(EntityUid user, Wire wire) + public override bool Mend(EntityUid user, Wire wire, AccessReaderComponent comp) { - base.Mend(user, wire); - if (EntityManager.TryGetComponent(wire.Owner, out var access)) - { - access.Enabled = true; - } - + comp.Enabled = true; return true; } - public override bool Pulse(EntityUid user, Wire wire) + public override void Pulse(EntityUid user, Wire wire, AccessReaderComponent comp) { - base.Pulse(user, wire); - if (EntityManager.TryGetComponent(wire.Owner, out var access)) - { - access.Enabled = false; - WiresSystem.StartWireAction(wire.Owner, _pulseTimeout, PulseTimeoutKey.Key, new TimedWireEvent(AwaitPulseCancel, wire)); - } - - return true; + comp.Enabled = false; + WiresSystem.StartWireAction(wire.Owner, _pulseTimeout, PulseTimeoutKey.Key, new TimedWireEvent(AwaitPulseCancel, wire)); } public override void Update(Wire wire) diff --git a/Content.Server/Arcade/WireActions/ArcadeInvincibilityWireActions.cs b/Content.Server/Arcade/WireActions/ArcadeInvincibilityWireActions.cs index 36f6d51a91..72ae200620 100644 --- a/Content.Server/Arcade/WireActions/ArcadeInvincibilityWireActions.cs +++ b/Content.Server/Arcade/WireActions/ArcadeInvincibilityWireActions.cs @@ -5,16 +5,11 @@ using Content.Shared.Wires; namespace Content.Server.Arcade; -[DataDefinition] public sealed class ArcadePlayerInvincibleWireAction : BaseToggleWireAction { - private string _text = "MNGR"; - protected override string Text - { - get => _text; - set => _text = value; - } - private Color _color = Color.Purple; + public override string Name { get; set; } = "wire-name-arcade-invincible"; + + public override Color Color { get; set; } = Color.Purple; public override object? StatusKey { get; } = SharedSpaceVillainArcadeComponent.Indicators.HealthManager; @@ -32,27 +27,24 @@ public sealed class ArcadePlayerInvincibleWireAction : BaseToggleWireAction && !arcade.PlayerInvincibilityFlag; } - public override StatusLightData? GetStatusLightData(Wire wire) + public override StatusLightState? GetLightState(Wire wire) { - var lightState = StatusLightState.Off; - - if (IsPowered(wire.Owner) && EntityManager.TryGetComponent(wire.Owner, out var arcade)) + if (EntityManager.TryGetComponent(wire.Owner, out var arcade)) { - lightState = arcade.PlayerInvincibilityFlag || arcade.EnemyInvincibilityFlag + return arcade.PlayerInvincibilityFlag || arcade.EnemyInvincibilityFlag ? StatusLightState.BlinkingSlow : StatusLightState.On; } - return new StatusLightData( - _color, - lightState, - _text); + return StatusLightState.Off; } } -[DataDefinition] public sealed class ArcadeEnemyInvincibleWireAction : BaseToggleWireAction { + public override string Name { get; set; } = "wire-name-player-invincible"; + public override Color Color { get; set; } = Color.Purple; + public override object? StatusKey { get; } = null; public override void ToggleValue(EntityUid owner, bool setting) diff --git a/Content.Server/Arcade/WireActions/ArcadeOverflowWireAction.cs b/Content.Server/Arcade/WireActions/ArcadeOverflowWireAction.cs index a673a3622d..2b672824cf 100644 --- a/Content.Server/Arcade/WireActions/ArcadeOverflowWireAction.cs +++ b/Content.Server/Arcade/WireActions/ArcadeOverflowWireAction.cs @@ -5,17 +5,11 @@ using Content.Shared.Wires; namespace Content.Server.Arcade; -[DataDefinition] public sealed class ArcadeOverflowWireAction : BaseToggleWireAction { - private Color _color = Color.Red; - private string _text = "LMTR"; - protected override string Text - { - get => _text; - set => _text = value; - } - + public override Color Color { get; set; } = Color.Red; + public override string Name { get; set; } = "wire-name-arcade-overflow"; + public override object? StatusKey { get; } = SharedSpaceVillainArcadeComponent.Indicators.HealthLimiter; public override void ToggleValue(EntityUid owner, bool setting) @@ -32,20 +26,15 @@ public sealed class ArcadeOverflowWireAction : BaseToggleWireAction && !arcade.OverflowFlag; } - public override StatusLightData? GetStatusLightData(Wire wire) + public override StatusLightState? GetLightState(Wire wire) { - var lightState = StatusLightState.Off; - - if (IsPowered(wire.Owner) && EntityManager.HasComponent(wire.Owner)) + if (EntityManager.HasComponent(wire.Owner)) { - lightState = !GetValue(wire.Owner) + return !GetValue(wire.Owner) ? StatusLightState.BlinkingSlow : StatusLightState.On; } - return new StatusLightData( - _color, - lightState, - _text); + return StatusLightState.Off; } } diff --git a/Content.Server/Atmos/Monitor/WireActions/AirAlarmPanicWire.cs b/Content.Server/Atmos/Monitor/WireActions/AirAlarmPanicWire.cs index 0991cb691e..22cbadb485 100644 --- a/Content.Server/Atmos/Monitor/WireActions/AirAlarmPanicWire.cs +++ b/Content.Server/Atmos/Monitor/WireActions/AirAlarmPanicWire.cs @@ -7,36 +7,19 @@ using Content.Shared.Wires; namespace Content.Server.Atmos.Monitor; -[DataDefinition] -public sealed class AirAlarmPanicWire : BaseWireAction +public sealed class AirAlarmPanicWire : ComponentWireAction { - private string _text = "PANC"; - protected override string Text - { - get => _text; - set => _text = value; - } - private Color _color = Color.Red; + public override string Name { get; set; } = "wire-name-air-alarm-panic"; + public override Color Color { get; set; } = Color.Red; private AirAlarmSystem _airAlarmSystem = default!; public override object StatusKey { get; } = AirAlarmWireStatus.Panic; - public override StatusLightData? GetStatusLightData(Wire wire) - { - var lightState = StatusLightState.Off; - if (IsPowered(wire.Owner) && EntityManager.TryGetComponent(wire.Owner, out var alarm)) - { - lightState = alarm.CurrentMode == AirAlarmMode.Panic + public override StatusLightState? GetLightState(Wire wire, AirAlarmComponent comp) + => comp.CurrentMode == AirAlarmMode.Panic ? StatusLightState.On : StatusLightState.Off; - } - - return new StatusLightData( - _color, - lightState, - _text); - } public override void Initialize() { @@ -45,9 +28,8 @@ public sealed class AirAlarmPanicWire : BaseWireAction _airAlarmSystem = EntityManager.System(); } - public override bool Cut(EntityUid user, Wire wire) + public override bool Cut(EntityUid user, Wire wire, AirAlarmComponent comp) { - base.Cut(user, wire); if (EntityManager.TryGetComponent(wire.Owner, out var devNet)) { _airAlarmSystem.SetMode(wire.Owner, devNet.Address, AirAlarmMode.Panic, false); @@ -56,28 +38,22 @@ public sealed class AirAlarmPanicWire : BaseWireAction return true; } - public override bool Mend(EntityUid user, Wire wire) + public override bool Mend(EntityUid user, Wire wire, AirAlarmComponent alarm) { - base.Mend(user, wire); if (EntityManager.TryGetComponent(wire.Owner, out var devNet) - && EntityManager.TryGetComponent(wire.Owner, out var alarm) && alarm.CurrentMode == AirAlarmMode.Panic) { _airAlarmSystem.SetMode(wire.Owner, devNet.Address, AirAlarmMode.Filtering, false, alarm); } - return true; } - public override bool Pulse(EntityUid user, Wire wire) + public override void Pulse(EntityUid user, Wire wire, AirAlarmComponent comp) { - base.Pulse(user, wire); if (EntityManager.TryGetComponent(wire.Owner, out var devNet)) { _airAlarmSystem.SetMode(wire.Owner, devNet.Address, AirAlarmMode.Panic, false); } - - return true; } } diff --git a/Content.Server/Atmos/Monitor/WireActions/AtmosAlarmableAlarmWire.cs b/Content.Server/Atmos/Monitor/WireActions/AtmosAlarmableAlarmWire.cs index 61168e5d3f..496600ee1e 100644 --- a/Content.Server/Atmos/Monitor/WireActions/AtmosAlarmableAlarmWire.cs +++ b/Content.Server/Atmos/Monitor/WireActions/AtmosAlarmableAlarmWire.cs @@ -6,46 +6,30 @@ using Content.Shared.Wires; namespace Content.Server.Atmos.Monitor; -[DataDefinition] -public sealed class AtmosMonitorDeviceNetWire : BaseWireAction +public sealed class AtmosMonitorDeviceNetWire : ComponentWireAction { // whether or not this wire will send out an alarm upon // being pulsed [DataField("alarmOnPulse")] private bool _alarmOnPulse = false; - private string _text = "NETW"; - protected override string Text - { - get => _text; - set => _text = value; - } - private Color _color = Color.Orange; + public override string Name { get; set; } = "wire-name-device-net"; + public override Color Color { get; set; } = Color.Orange; private AtmosAlarmableSystem _atmosAlarmableSystem = default!; public override object StatusKey { get; } = AtmosMonitorAlarmWireActionKeys.Network; - public override StatusLightData? GetStatusLightData(Wire wire) + public override StatusLightState? GetLightState(Wire wire, AtmosAlarmableComponent comp) { - var lightState = StatusLightState.Off; - - if (IsPowered(wire.Owner) && EntityManager.TryGetComponent(wire.Owner, out var monitor)) + if (!_atmosAlarmableSystem.TryGetHighestAlert(wire.Owner, out var alarm, comp)) { - if (!_atmosAlarmableSystem.TryGetHighestAlert(wire.Owner, out var alarm)) - { - alarm = AtmosAlarmType.Normal; - } - - lightState = alarm == AtmosAlarmType.Danger - ? StatusLightState.BlinkingFast - : StatusLightState.On; + alarm = AtmosAlarmType.Normal; } - return new StatusLightData( - _color, - lightState, - _text); + return alarm == AtmosAlarmType.Danger + ? StatusLightState.BlinkingFast + : StatusLightState.On; } public override void Initialize() @@ -55,36 +39,21 @@ public sealed class AtmosMonitorDeviceNetWire : BaseWireAction _atmosAlarmableSystem = EntityManager.System(); } - public override bool Cut(EntityUid user, Wire wire) + public override bool Cut(EntityUid user, Wire wire, AtmosAlarmableComponent comp) { - base.Cut(user, wire); - if (EntityManager.TryGetComponent(wire.Owner, out var monitor)) - { - monitor.IgnoreAlarms = true; - } - + comp.IgnoreAlarms = true; return true; } - public override bool Mend(EntityUid user, Wire wire) + public override bool Mend(EntityUid user, Wire wire, AtmosAlarmableComponent comp) { - base.Mend(user, wire); - if (EntityManager.TryGetComponent(wire.Owner, out var monitor)) - { - monitor.IgnoreAlarms = false; - } - + comp.IgnoreAlarms = false; return true; } - public override bool Pulse(EntityUid user, Wire wire) + public override void Pulse(EntityUid user, Wire wire, AtmosAlarmableComponent comp) { - base.Pulse(user, wire); if (_alarmOnPulse) - { - _atmosAlarmableSystem.ForceAlert(wire.Owner, AtmosAlarmType.Danger); - } - - return true; + _atmosAlarmableSystem.ForceAlert(wire.Owner, AtmosAlarmType.Danger, comp); } } diff --git a/Content.Server/Doors/WireActions/DoorBoltLightWireAction.cs b/Content.Server/Doors/WireActions/DoorBoltLightWireAction.cs index 97f026a2bd..90ce33f440 100644 --- a/Content.Server/Doors/WireActions/DoorBoltLightWireAction.cs +++ b/Content.Server/Doors/WireActions/DoorBoltLightWireAction.cs @@ -1,4 +1,3 @@ -using Content.Server.Doors.Components; using Content.Server.Doors.Systems; using Content.Server.Wires; using Content.Shared.Doors; @@ -7,68 +6,31 @@ using Content.Shared.Wires; namespace Content.Server.Doors; -[DataDefinition] -public sealed class DoorBoltLightWireAction : BaseWireAction +public sealed class DoorBoltLightWireAction : ComponentWireAction { - [DataField("color")] - private Color _statusColor = Color.Lime; + public override Color Color { get; set; } = Color.Lime; + public override string Name { get; set; } = "wire-name-bolt-light"; - [DataField("name")] - private string _text = "BLIT"; - protected override string Text - { - get => _text; - set => _text = value; - } - - public override StatusLightData? GetStatusLightData(Wire wire) - { - var lightState = StatusLightState.Off; - if (IsPowered(wire.Owner) && EntityManager.TryGetComponent(wire.Owner, out var door)) - { - lightState = door.BoltLightsEnabled - ? StatusLightState.On - : StatusLightState.Off; - } - - return new StatusLightData( - _statusColor, - lightState, - _text); - } + public override StatusLightState? GetLightState(Wire wire, AirlockComponent comp) + => comp.BoltLightsEnabled ? StatusLightState.On : StatusLightState.Off; public override object StatusKey { get; } = AirlockWireStatus.BoltLightIndicator; - public override bool Cut(EntityUid user, Wire wire) + public override bool Cut(EntityUid user, Wire wire, AirlockComponent door) { - base.Cut(user, wire); - if (EntityManager.TryGetComponent(wire.Owner, out var door)) - { - EntityManager.System().SetBoltLightsEnabled(wire.Owner, door, false); - } - + EntityManager.System().SetBoltLightsEnabled(wire.Owner, door, false); return true; } - public override bool Mend(EntityUid user, Wire wire) + public override bool Mend(EntityUid user, Wire wire, AirlockComponent door) { - base.Mend(user, wire); - if (EntityManager.TryGetComponent(wire.Owner, out var door)) - { - EntityManager.System().SetBoltLightsEnabled(wire.Owner, door, true); - } + EntityManager.System().SetBoltLightsEnabled(wire.Owner, door, true); return true; } - public override bool Pulse(EntityUid user, Wire wire) + public override void Pulse(EntityUid user, Wire wire, AirlockComponent door) { - base.Pulse(user, wire); - if (EntityManager.TryGetComponent(wire.Owner, out var door)) - { - EntityManager.System().SetBoltLightsEnabled(wire.Owner, door, !door.BoltLightsEnabled); - } - - return true; + EntityManager.System().SetBoltLightsEnabled(wire.Owner, door, !door.BoltLightsEnabled); } } diff --git a/Content.Server/Doors/WireActions/DoorBoltWireAction.cs b/Content.Server/Doors/WireActions/DoorBoltWireAction.cs index e59f30a6a1..ca311b296c 100644 --- a/Content.Server/Doors/WireActions/DoorBoltWireAction.cs +++ b/Content.Server/Doors/WireActions/DoorBoltWireAction.cs @@ -1,4 +1,3 @@ -using Content.Server.Doors.Components; using Content.Server.Doors.Systems; using Content.Server.Wires; using Content.Shared.Doors; @@ -8,78 +7,36 @@ using Content.Shared.Wires; namespace Content.Server.Doors; -[DataDefinition] -public sealed class DoorBoltWireAction : BaseWireAction +public sealed class DoorBoltWireAction : ComponentWireAction { - [DataField("color")] - private Color _statusColor = Color.Red; - - [DataField("name")] - private string _text = "BOLT"; - protected override string Text - { - get => _text; - set => _text = value; - } - - public override StatusLightData? GetStatusLightData(Wire wire) - { - StatusLightState lightState = StatusLightState.Off; - if (IsPowered(wire.Owner) - && EntityManager.TryGetComponent(wire.Owner, out var door)) - { - if (door.BoltsDown) - { - lightState = StatusLightState.On; - } - } - - return new StatusLightData( - _statusColor, - lightState, - _text); - } + public override Color Color { get; set; } = Color.Red; + public override string Name { get; set; } = "wire-name-door-bolt"; + + public override StatusLightState? GetLightState(Wire wire, AirlockComponent comp) + => comp.BoltsDown ? StatusLightState.On : StatusLightState.Off; public override object StatusKey { get; } = AirlockWireStatus.BoltIndicator; - public override bool Cut(EntityUid user, Wire wire) + public override bool Cut(EntityUid user, Wire wire, AirlockComponent airlock) { - base.Cut(user, wire); - if (EntityManager.TryGetComponent(wire.Owner, out var airlock)) - { - EntityManager.System().SetBoltWireCut(airlock, true); - if (!airlock.BoltsDown && IsPowered(wire.Owner)) - EntityManager.System().SetBoltsWithAudio(wire.Owner, airlock, true); - } + EntityManager.System().SetBoltWireCut(airlock, true); + if (!airlock.BoltsDown && IsPowered(wire.Owner)) + EntityManager.System().SetBoltsWithAudio(wire.Owner, airlock, true); return true; } - public override bool Mend(EntityUid user, Wire wire) + public override bool Mend(EntityUid user, Wire wire, AirlockComponent door) { - base.Mend(user, wire); - if (EntityManager.TryGetComponent(wire.Owner, out var door)) - EntityManager.System().SetBoltWireCut(door, true); - + EntityManager.System().SetBoltWireCut(door, true); return true; } - public override bool Pulse(EntityUid user, Wire wire) + public override void Pulse(EntityUid user, Wire wire, AirlockComponent door) { - base.Pulse(user, wire); - if (EntityManager.TryGetComponent(wire.Owner, out var door)) - { - if (IsPowered(wire.Owner)) - { - EntityManager.System().SetBoltsWithAudio(wire.Owner, door, !door.BoltsDown); - } - else if (!door.BoltsDown) - { - EntityManager.System().SetBoltsWithAudio(wire.Owner, door, true); - } - - } - - return true; + if (IsPowered(wire.Owner)) + EntityManager.System().SetBoltsWithAudio(wire.Owner, door, !door.BoltsDown); + else if (!door.BoltsDown) + EntityManager.System().SetBoltsWithAudio(wire.Owner, door, true); } } diff --git a/Content.Server/Doors/WireActions/DoorSafetyWireAction.cs b/Content.Server/Doors/WireActions/DoorSafetyWireAction.cs index 2de1e2b2e9..8d02d923fe 100644 --- a/Content.Server/Doors/WireActions/DoorSafetyWireAction.cs +++ b/Content.Server/Doors/WireActions/DoorSafetyWireAction.cs @@ -7,75 +7,37 @@ using Content.Shared.Wires; namespace Content.Server.Doors; -[DataDefinition] -public sealed class DoorSafetyWireAction : BaseWireAction +public sealed class DoorSafetyWireAction : ComponentWireAction { - [DataField("color")] - private Color _statusColor = Color.Red; - - [DataField("name")] - private string _text = "SAFE"; - protected override string Text - { - get => _text; - set => _text = value; - } + public override Color Color { get; set; } = Color.Red; + public override string Name { get; set; } = "wire-name-door-safety"; + [DataField("timeout")] private int _timeout = 30; - public override StatusLightData? GetStatusLightData(Wire wire) - { - var lightState = StatusLightState.Off; - if (IsPowered(wire.Owner) - && EntityManager.TryGetComponent(wire.Owner, out var door)) - { - lightState = door.Safety - ? StatusLightState.On - : StatusLightState.Off; - } - - return new StatusLightData( - _statusColor, - lightState, - _text); - } + public override StatusLightState? GetLightState(Wire wire, AirlockComponent comp) + => comp.Safety ? StatusLightState.On : StatusLightState.Off; public override object StatusKey { get; } = AirlockWireStatus.SafetyIndicator; - public override bool Cut(EntityUid user, Wire wire) + public override bool Cut(EntityUid user, Wire wire, AirlockComponent door) { - base.Cut(user, wire); - if (EntityManager.TryGetComponent(wire.Owner, out var door)) - { - WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key); - EntityManager.System().SetSafety(door, false); - } - + WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key); + EntityManager.System().SetSafety(door, false); return true; } - public override bool Mend(EntityUid user, Wire wire) + public override bool Mend(EntityUid user, Wire wire, AirlockComponent door) { - base.Mend(user, wire); - if (EntityManager.TryGetComponent(wire.Owner, out var door)) - { - EntityManager.System().SetSafety(door, true); - } - + EntityManager.System().SetSafety(door, true); return true; } - public override bool Pulse(EntityUid user, Wire wire) + public override void Pulse(EntityUid user, Wire wire, AirlockComponent door) { - base.Pulse(user, wire); - if (EntityManager.TryGetComponent(wire.Owner, out var door)) - { - EntityManager.System().SetSafety(door, false); - WiresSystem.StartWireAction(wire.Owner, _timeout, PulseTimeoutKey.Key, new TimedWireEvent(AwaitSafetyTimerFinish, wire)); - } - - return true; + EntityManager.System().SetSafety(door, false); + WiresSystem.StartWireAction(wire.Owner, _timeout, PulseTimeoutKey.Key, new TimedWireEvent(AwaitSafetyTimerFinish, wire)); } public override void Update(Wire wire) diff --git a/Content.Server/Doors/WireActions/DoorTimingWireAction.cs b/Content.Server/Doors/WireActions/DoorTimingWireAction.cs index cbeaa3fba3..1539575590 100644 --- a/Content.Server/Doors/WireActions/DoorTimingWireAction.cs +++ b/Content.Server/Doors/WireActions/DoorTimingWireAction.cs @@ -7,85 +7,46 @@ using Content.Shared.Wires; namespace Content.Server.Doors; -[DataDefinition] -public sealed class DoorTimingWireAction : BaseWireAction +public sealed class DoorTimingWireAction : ComponentWireAction { - [DataField("color")] - private Color _statusColor = Color.Orange; - - [DataField("name")] - private string _text = "TIMR"; - protected override string Text - { - get => _text; - set => _text = value; - } - + public override Color Color { get; set; } = Color.Orange; + public override string Name { get; set; } = "wire-name-door-timer"; + [DataField("timeout")] private int _timeout = 30; - public override StatusLightData? GetStatusLightData(Wire wire) + public override StatusLightState? GetLightState(Wire wire, AirlockComponent comp) { - var lightState = StatusLightState.Off; - if (IsPowered(wire.Owner) - && EntityManager.TryGetComponent(wire.Owner, out var door)) + switch (comp.AutoCloseDelayModifier) { - switch (door.AutoCloseDelayModifier) - { - case 0.01f: - lightState = StatusLightState.Off; - break; - case <= 0.5f: - lightState = StatusLightState.BlinkingSlow; - break; - default: - lightState = StatusLightState.On; - break; - } + case 0.01f: + return StatusLightState.Off; + case <= 0.5f: + return StatusLightState.BlinkingSlow; + default: + return StatusLightState.On; } - - return new StatusLightData( - _statusColor, - lightState, - _text); } public override object StatusKey { get; } = AirlockWireStatus.TimingIndicator; - public override bool Cut(EntityUid user, Wire wire) + public override bool Cut(EntityUid user, Wire wire, AirlockComponent door) { - base.Cut(user, wire); - if (EntityManager.TryGetComponent(wire.Owner, out var door)) - { - WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key); - EntityManager.System().SetAutoCloseDelayModifier(door, 0.01f); - } - + WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key); + EntityManager.System().SetAutoCloseDelayModifier(door, 0.01f); return true; } - public override bool Mend(EntityUid user, Wire wire) + public override bool Mend(EntityUid user, Wire wire, AirlockComponent door) { - base.Mend(user, wire); - if (EntityManager.TryGetComponent(wire.Owner, out var door)) - { - EntityManager.System().SetAutoCloseDelayModifier(door, 1f); - } - + EntityManager.System().SetAutoCloseDelayModifier(door, 1f); return true; } - public override bool Pulse(EntityUid user, Wire wire) + public override void Pulse(EntityUid user, Wire wire, AirlockComponent door) { - base.Pulse(user, wire); - if (EntityManager.TryGetComponent(wire.Owner, out var door)) - { - EntityManager.System().SetAutoCloseDelayModifier(door, 0.5f); - WiresSystem.StartWireAction(wire.Owner, _timeout, PulseTimeoutKey.Key, new TimedWireEvent(AwaitTimingTimerFinish, wire)); - } - - - return true; + EntityManager.System().SetAutoCloseDelayModifier(door, 0.5f); + WiresSystem.StartWireAction(wire.Owner, _timeout, PulseTimeoutKey.Key, new TimedWireEvent(AwaitTimingTimerFinish, wire)); } public override void Update(Wire wire) diff --git a/Content.Server/Medical/CryoPodEjectLockWireAction.cs b/Content.Server/Medical/CryoPodEjectLockWireAction.cs index 337184ecbd..93c6a49aa9 100644 --- a/Content.Server/Medical/CryoPodEjectLockWireAction.cs +++ b/Content.Server/Medical/CryoPodEjectLockWireAction.cs @@ -1,4 +1,4 @@ -using Content.Server.Medical.Components; +using Content.Server.Medical.Components; using Content.Server.Wires; using Content.Shared.Medical.Cryogenics; using Content.Shared.Wires; @@ -8,52 +8,31 @@ namespace Content.Server.Medical; /// /// Causes a failure in the cryo pod ejection system when cut. A crowbar will be needed to pry open the pod. /// -[DataDefinition] -public sealed class CryoPodEjectLockWireAction: BaseWireAction +public sealed class CryoPodEjectLockWireAction: ComponentWireAction { - [DataField("color")] - private Color _statusColor = Color.Red; - - [DataField("name")] - private string _text = "LOCK"; + public override Color Color { get; set; } = Color.Red; + public override string Name { get; set; } = "wire-name-lock"; + public override bool LightRequiresPower { get; set; } = false; public override object? StatusKey { get; } = CryoPodWireActionKey.Key; - public override bool Cut(EntityUid user, Wire wire) + public override bool Cut(EntityUid user, Wire wire, CryoPodComponent cryoPodComponent) { - if (EntityManager.TryGetComponent(wire.Owner, out var cryoPodComponent) && !cryoPodComponent.PermaLocked) - { + if (!cryoPodComponent.PermaLocked) cryoPodComponent.Locked = true; - } return true; } - public override bool Mend(EntityUid user, Wire wire) + public override bool Mend(EntityUid user, Wire wire, CryoPodComponent cryoPodComponent) { - if (EntityManager.TryGetComponent(wire.Owner, out var cryoPodComponent) && !cryoPodComponent.PermaLocked) - { + if (!cryoPodComponent.PermaLocked) cryoPodComponent.Locked = false; - } return true; } - public override bool Pulse(EntityUid user, Wire wire) - { - return true; - } + public override void Pulse(EntityUid user, Wire wire, CryoPodComponent cryoPodComponent) { } - public override StatusLightData? GetStatusLightData(Wire wire) - { - StatusLightState lightState = StatusLightState.Off; - if (EntityManager.TryGetComponent(wire.Owner, out var cryoPodComponent) && cryoPodComponent.Locked) - { - lightState = StatusLightState.On; //TODO figure out why this doesn't get updated when the pod is emagged - } - - return new StatusLightData( - _statusColor, - lightState, - _text); - } + public override StatusLightState? GetLightState(Wire wire, CryoPodComponent comp) + => comp.Locked ? StatusLightState.On : StatusLightState.Off; } diff --git a/Content.Server/Power/PowerWireAction.cs b/Content.Server/Power/PowerWireAction.cs index d228fb3781..2d9d43088d 100644 --- a/Content.Server/Power/PowerWireAction.cs +++ b/Content.Server/Power/PowerWireAction.cs @@ -8,19 +8,10 @@ namespace Content.Server.Power; // Generic power wire action. Use on anything // that requires power. -[DataDefinition] public sealed class PowerWireAction : BaseWireAction { - [DataField("color")] - private Color _statusColor = Color.Red; - - [DataField("name")] - private string _text = "POWR"; - protected override string Text - { - get => _text; - set => _text = value; - } + public override Color Color { get; set; } = Color.Red; + public override string Name { get; set; } = "wire-name-power"; [DataField("pulseTimeout")] private int _pulseTimeout = 30; @@ -29,35 +20,22 @@ public sealed class PowerWireAction : BaseWireAction public override object StatusKey { get; } = PowerWireActionKey.Status; - public override StatusLightData? GetStatusLightData(Wire wire) + public override StatusLightState? GetLightState(Wire wire) { - StatusLightState lightState = StatusLightState.Off; if (WiresSystem.TryGetData(wire.Owner, PowerWireActionKey.MainWire, out int main) && main != wire.Id) { return null; } - if (IsPowered(wire.Owner)) - { - if (!AllWiresMended(wire.Owner) + if (!AllWiresMended(wire.Owner) || WiresSystem.TryGetData(wire.Owner, PowerWireActionKey.Pulsed, out bool pulsed) && pulsed) - { - lightState = StatusLightState.BlinkingSlow; - } - else - { - lightState = (AllWiresCut(wire.Owner)) - ? StatusLightState.Off - : StatusLightState.On; - } + { + return StatusLightState.BlinkingSlow; } - return new StatusLightData( - _statusColor, - lightState, - _text); + return AllWiresCut(wire.Owner) ? StatusLightState.Off : StatusLightState.On; } private bool AllWiresCut(EntityUid owner) @@ -233,29 +211,23 @@ public sealed class PowerWireAction : BaseWireAction return true; } - public override bool Pulse(EntityUid user, Wire wire) + public override void Pulse(EntityUid user, Wire wire) { base.Pulse(user, wire); WiresSystem.TryCancelWireAction(wire.Owner, PowerWireActionKey.ElectrifiedCancel); var electrocuted = !TrySetElectrocution(user, wire, true); - if (WiresSystem.TryGetData(wire.Owner, PowerWireActionKey.Pulsed, out bool pulsedKey) - && pulsedKey) - { - return false; - } + if (WiresSystem.TryGetData(wire.Owner, PowerWireActionKey.Pulsed, out bool pulsedKey) && pulsedKey) + return; WiresSystem.SetData(wire.Owner, PowerWireActionKey.Pulsed, true); WiresSystem.StartWireAction(wire.Owner, _pulseTimeout, PowerWireActionKey.PulseCancel, new TimedWireEvent(AwaitPulseCancel, wire)); if (electrocuted) - { - return false; - } + return; SetPower(wire.Owner, true); - return true; } public override void Update(Wire wire) diff --git a/Content.Server/VendingMachines/VendingMachineContrabandWireAction.cs b/Content.Server/VendingMachines/VendingMachineContrabandWireAction.cs index 5f5ba7243b..0d7d974737 100644 --- a/Content.Server/VendingMachines/VendingMachineContrabandWireAction.cs +++ b/Content.Server/VendingMachines/VendingMachineContrabandWireAction.cs @@ -7,25 +7,21 @@ namespace Content.Server.VendingMachines; [DataDefinition] public sealed class VendingMachineContrabandWireAction : BaseToggleWireAction { - private readonly Color _color = Color.Green; - private readonly string _text = "MNGR"; + public override Color Color { get; set; } = Color.Green; + public override string Name { get; set; } = "wire-name-vending-contraband"; public override object? StatusKey { get; } = ContrabandWireKey.StatusKey; public override object? TimeoutKey { get; } = ContrabandWireKey.TimeoutKey; - public override StatusLightData? GetStatusLightData(Wire wire) + public override StatusLightState? GetLightState(Wire wire) { - var lightState = StatusLightState.Off; - if (IsPowered(wire.Owner) && EntityManager.TryGetComponent(wire.Owner, out VendingMachineComponent? vending)) + if (EntityManager.TryGetComponent(wire.Owner, out VendingMachineComponent? vending)) { - lightState = vending.Contraband + return vending.Contraband ? StatusLightState.BlinkingSlow : StatusLightState.On; } - return new StatusLightData( - _color, - lightState, - _text); + return StatusLightState.Off; } public override void ToggleValue(EntityUid owner, bool setting) diff --git a/Content.Server/VendingMachines/VendingMachineEjectItemWireAction.cs b/Content.Server/VendingMachines/VendingMachineEjectItemWireAction.cs index 3a674cea65..c9b1fbc4f1 100644 --- a/Content.Server/VendingMachines/VendingMachineEjectItemWireAction.cs +++ b/Content.Server/VendingMachines/VendingMachineEjectItemWireAction.cs @@ -4,72 +4,39 @@ using Content.Shared.Wires; namespace Content.Server.VendingMachines; -[DataDefinition] -public sealed class VendingMachineEjectItemWireAction : BaseWireAction +public sealed class VendingMachineEjectItemWireAction : ComponentWireAction { private VendingMachineSystem _vendingMachineSystem = default!; - private Color _color = Color.Red; - private string _text = "VEND"; - protected override string Text - { - get => _text; - set => _text = value; - } + public override Color Color { get; set; } = Color.Red; + public override string Name { get; set; } = "wire-name-vending-eject"; + public override object? StatusKey { get; } = EjectWireKey.StatusKey; - public override StatusLightData? GetStatusLightData(Wire wire) - { - var lightState = StatusLightState.Off; - - if (IsPowered(wire.Owner) - && EntityManager.TryGetComponent(wire.Owner, out VendingMachineComponent? vending)) - { - lightState = vending.CanShoot - ? StatusLightState.BlinkingFast - : StatusLightState.On; - } - - return new StatusLightData( - _color, - lightState, - _text); - } + public override StatusLightState? GetLightState(Wire wire, VendingMachineComponent comp) + => comp.CanShoot ? StatusLightState.BlinkingFast : StatusLightState.On; public override void Initialize() { base.Initialize(); - _vendingMachineSystem = EntitySystem.Get(); + _vendingMachineSystem = EntityManager.System(); } - public override bool Cut(EntityUid user, Wire wire) + public override bool Cut(EntityUid user, Wire wire, VendingMachineComponent vending) { - base.Cut(user, wire); - if (EntityManager.TryGetComponent(wire.Owner, out VendingMachineComponent? vending)) - { - _vendingMachineSystem.SetShooting(wire.Owner, true, vending); - } - + _vendingMachineSystem.SetShooting(wire.Owner, true, vending); return true; } - public override bool Mend(EntityUid user, Wire wire) + public override bool Mend(EntityUid user, Wire wire, VendingMachineComponent vending) { - base.Mend(user, wire); - if (EntityManager.TryGetComponent(wire.Owner, out VendingMachineComponent? vending)) - { - _vendingMachineSystem.SetShooting(wire.Owner, false, vending); - } - + _vendingMachineSystem.SetShooting(wire.Owner, false, vending); return true; } - public override bool Pulse(EntityUid user, Wire wire) + public override void Pulse(EntityUid user, Wire wire, VendingMachineComponent vending) { - base.Pulse(user, wire); - _vendingMachineSystem.EjectRandom(wire.Owner, true); - - return true; + _vendingMachineSystem.EjectRandom(wire.Owner, true, vendComponent: vending); } } diff --git a/Content.Server/Wires/BaseToggleWireAction.cs b/Content.Server/Wires/BaseToggleWireAction.cs index 21886a1d09..33d9d12c3b 100644 --- a/Content.Server/Wires/BaseToggleWireAction.cs +++ b/Content.Server/Wires/BaseToggleWireAction.cs @@ -48,7 +48,7 @@ public abstract class BaseToggleWireAction : BaseWireAction return true; } - public override bool Pulse(EntityUid user, Wire wire) + public override void Pulse(EntityUid user, Wire wire) { base.Pulse(user, wire); ToggleValue(wire.Owner, !GetValue(wire.Owner)); @@ -57,8 +57,6 @@ public abstract class BaseToggleWireAction : BaseWireAction { WiresSystem.StartWireAction(wire.Owner, Delay, TimeoutKey, new TimedWireEvent(AwaitPulseCancel, wire)); } - - return true; } public override void Update(Wire wire) diff --git a/Content.Server/Wires/BaseWireAction.cs b/Content.Server/Wires/BaseWireAction.cs index 8990acf6d8..10baed90eb 100644 --- a/Content.Server/Wires/BaseWireAction.cs +++ b/Content.Server/Wires/BaseWireAction.cs @@ -1,4 +1,3 @@ -using Content.Server.Power.Components; using Content.Server.Power.EntitySystems; using Content.Shared.Administration.Logs; using Content.Shared.Database; @@ -7,15 +6,43 @@ using Content.Shared.Wires; namespace Content.Server.Wires; /// +[ImplicitDataDefinitionForInheritors] public abstract class BaseWireAction : IWireAction { private ISharedAdminLogManager _adminLogger = default!; - protected virtual string Text + + /// + /// The loc-string of the text that gets returned by . Also used for admin logging. + /// + [DataField("name")] + public abstract string Name { get; set; } + + /// + /// Default color that gets returned by . + /// + [DataField("color")] + public abstract Color Color { get; set; } + + /// + /// If true, the default behavior of will return an off-light when the + /// wire owner is not powered. + /// + [DataField("lightRequiresPower")] + public virtual bool LightRequiresPower { get; set; } = true; + + public virtual StatusLightData? GetStatusLightData(Wire wire) { - get => GetType().Name.Replace("WireAction", ""); - set { } + if (LightRequiresPower && !IsPowered(wire.Owner)) + return new StatusLightData(Color, StatusLightState.Off, Loc.GetString(Name)); + + var state = GetLightState(wire); + return state == null + ? null + : new StatusLightData(Color, state.Value, Loc.GetString(Name)); } + public virtual StatusLightState? GetLightState(Wire wire) => null; + public IEntityManager EntityManager = default!; public WiresSystem WiresSystem = default!; @@ -32,31 +59,27 @@ public abstract class BaseWireAction : IWireAction } public virtual bool AddWire(Wire wire, int count) => count == 1; - public virtual bool Cut(EntityUid user, Wire wire) + public virtual bool Cut(EntityUid user, Wire wire) => Log(user, wire, "cut"); + public virtual bool Mend(EntityUid user, Wire wire) => Log(user, wire, "mended"); + public virtual void Pulse(EntityUid user, Wire wire) => Log(user, wire, "pulsed"); + + private bool Log(EntityUid user, Wire wire, string verb) { - _adminLogger.Add(LogType.Action, LogImpact.Medium, $"{EntityManager.ToPrettyString(user):player} cut {wire.Color.Name()} {Text} in {EntityManager.ToPrettyString(wire.Owner)}"); - return false; - } - public virtual bool Mend(EntityUid user, Wire wire) - { - _adminLogger.Add(LogType.Action, LogImpact.Medium, $"{EntityManager.ToPrettyString(user):player} mended {wire.Color.Name()} {Text} in {EntityManager.ToPrettyString(wire.Owner)}"); - return false; - } - public virtual bool Pulse(EntityUid user, Wire wire) - { - _adminLogger.Add(LogType.Action, LogImpact.Medium, $"{EntityManager.ToPrettyString(user):player} pulsed {wire.Color.Name()} {Text} in {EntityManager.ToPrettyString(wire.Owner)}"); - return false; + var player = EntityManager.ToPrettyString(user); + var owner = EntityManager.ToPrettyString(wire.Owner); + var name = Loc.GetString(Name); + var color = wire.Color.Name(); + var action = GetType().Name; + + // logs something like "... mended red POWR wire (PowerWireAction) in ...." + _adminLogger.Add(LogType.WireHacking, LogImpact.Medium, $"{player} {verb} {color} {name} wire ({action}) in {owner}"); + return true; } + public virtual void Update(Wire wire) { - return; } - public abstract StatusLightData? GetStatusLightData(Wire wire); - // most things that use wires are powered by *something*, so - // - // this isn't required by any wire system methods though, so whatever inherits it here - // can use it /// /// Utility function to check if this given entity is powered. /// diff --git a/Content.Server/Wires/ComponentWireAction.cs b/Content.Server/Wires/ComponentWireAction.cs new file mode 100644 index 0000000000..0ee1d231f4 --- /dev/null +++ b/Content.Server/Wires/ComponentWireAction.cs @@ -0,0 +1,40 @@ +using Content.Shared.Wires; + +namespace Content.Server.Wires; + +/// +/// convenience class for wires that depend on the existence of some component to function. Slightly reduces boilerplate. +/// +public abstract class ComponentWireAction : BaseWireAction where TComponent : Component +{ + public abstract StatusLightState? GetLightState(Wire wire, TComponent component); + public override StatusLightState? GetLightState(Wire wire) + { + return EntityManager.TryGetComponent(wire.Owner, out TComponent? component) + ? GetLightState(wire, component) + : StatusLightState.Off; + } + + public abstract bool Cut(EntityUid user, Wire wire, TComponent component); + public abstract bool Mend(EntityUid user, Wire wire, TComponent component); + public abstract void Pulse(EntityUid user, Wire wire, TComponent component); + + public override bool Cut(EntityUid user, Wire wire) + { + base.Cut(user, wire); + return EntityManager.TryGetComponent(wire.Owner, out TComponent? component) && Cut(user, wire, component); + } + + public override bool Mend(EntityUid user, Wire wire) + { + base.Mend(user, wire); + return EntityManager.TryGetComponent(wire.Owner, out TComponent? component) && Mend(user, wire, component); + } + + public override void Pulse(EntityUid user, Wire wire) + { + base.Pulse(user, wire); + if (EntityManager.TryGetComponent(wire.Owner, out TComponent? component)) + Pulse(user, wire, component); + } +} diff --git a/Content.Server/Wires/DummyWireAction.cs b/Content.Server/Wires/DummyWireAction.cs deleted file mode 100644 index cbb7f69fbc..0000000000 --- a/Content.Server/Wires/DummyWireAction.cs +++ /dev/null @@ -1,44 +0,0 @@ -using Content.Shared.Wires; - -namespace Content.Server.Wires; - -// Exists so that dummy wires can be added. -// -// You *shouldn't* be adding these as raw -// wire actions, but it's here anyways as -// a serializable class for consistency. -// C'est la vie. -[DataDefinition] -public sealed class DummyWireAction : BaseWireAction -{ - public override object? StatusKey { get; } = null; - - public override StatusLightData? GetStatusLightData(Wire wire) => null; - public override bool AddWire(Wire wire, int count) => true; - - public override bool Cut(EntityUid user, Wire wire) - { - base.Cut(user, wire); - return true; - } - - public override bool Mend(EntityUid user, Wire wire) - { - base.Mend(user, wire); - return true; - } - - public override bool Pulse(EntityUid user, Wire wire) - { - base.Pulse(user, wire); - return true; - } - - // doesn't matter if you get any information off of this, - // if you really want to mess with dummy wires, you should - // probably code your own implementation? - private enum DummyWireActionIdentifier - { - Key, - } -} diff --git a/Content.Server/Wires/IWireAction.cs b/Content.Server/Wires/IWireAction.cs index 85639adc02..903ac0d347 100644 --- a/Content.Server/Wires/IWireAction.cs +++ b/Content.Server/Wires/IWireAction.cs @@ -41,7 +41,7 @@ public interface IWireAction public bool AddWire(Wire wire, int count); /// - /// What happens when this wire is cut. + /// What happens when this wire is cut. If this returns false, the wire will not actually get cut. /// /// The user attempting to interact with the wire. /// The wire being interacted with. @@ -49,7 +49,7 @@ public interface IWireAction public bool Cut(EntityUid user, Wire wire); /// - /// What happens when this wire is mended. + /// What happens when this wire is mended. If this returns false, the wire will not actually get cut. /// /// The user attempting to interact with the wire. /// The wire being interacted with. @@ -57,12 +57,11 @@ public interface IWireAction public bool Mend(EntityUid user, Wire wire); /// - /// What happens when this wire is pulsed. + /// This method gets called when the wire is pulsed.. /// /// The user attempting to interact with the wire. /// The wire being interacted with. - /// true if successful, false otherwise. - public bool Pulse(EntityUid user, Wire wire); + public void Pulse(EntityUid user, Wire wire); /// /// Used when a wire's state on an entity needs to be updated. diff --git a/Content.Server/Wires/WiresSystem.cs b/Content.Server/Wires/WiresSystem.cs index 19e64fd6c6..2595073db7 100644 --- a/Content.Server/Wires/WiresSystem.cs +++ b/Content.Server/Wires/WiresSystem.cs @@ -15,8 +15,6 @@ using Content.Shared.Tools.Components; using Content.Shared.Wires; using Robust.Server.GameObjects; using Robust.Server.Player; -using Robust.Shared.Audio; -using Robust.Shared.Player; using Robust.Shared.Prototypes; using Robust.Shared.Random; @@ -42,13 +40,9 @@ public sealed class WiresSystem : EntitySystem private const float ScrewTime = 1f; private float _toolTime = 0f; - private static DummyWireAction _dummyWire = new DummyWireAction(); - #region Initialization public override void Initialize() { - _dummyWire.Initialize(); - SubscribeLocalEvent(Reset); // this is a broadcast event @@ -133,6 +127,10 @@ public sealed class WiresSystem : EntitySystem var id = 0; foreach (var wire in wires.WiresList) { + wire.Id = id++; + if (wire.Action == null) + continue; + var wireType = wire.Action.GetType(); if (types.ContainsKey(wireType)) { @@ -143,9 +141,6 @@ public sealed class WiresSystem : EntitySystem types.Add(wireType, 1); } - wire.Id = id; - id++; - // don't care about the result, this should've // been handled in layout creation wire.Action.AddWire(wire, types[wireType]); @@ -165,25 +160,20 @@ public sealed class WiresSystem : EntitySystem { (int id, Wire d) = enumeratedList[i]; - var wireType = d.Action.GetType(); - if (types.ContainsKey(wireType)) + if (d.Action != null) { - types[wireType] += 1; - } - else - { - types.Add(wireType, 1); - } + var actionType = d.Action.GetType(); + if (types.ContainsKey(actionType)) + types[actionType] += 1; + else + types.Add(actionType, 1); - d.Id = i; - - if (!d.Action.AddWire(d, types[wireType])) - { - d.Action = _dummyWire; + d.Id = i; + if (!d.Action.AddWire(d, types[actionType])) + d.Action = null; } - + data.Add(id, new WireLayout.WireData(d.Letter, d.Color, i)); - wires.WiresList[i] = wireSet[id]; } @@ -214,13 +204,13 @@ public sealed class WiresSystem : EntitySystem for (var i = 1; i <= dummyWires; i++) { - wireSet.Add(CreateWire(uid, _dummyWire, wires.Count + i, layout, colors, letters)); + wireSet.Add(CreateWire(uid, null, wires.Count + i, layout, colors, letters)); } return wireSet; } - private Wire CreateWire(EntityUid uid, IWireAction action, int position, WireLayout? layout, List colors, List letters) + private Wire CreateWire(EntityUid uid, IWireAction? action, int position, WireLayout? layout, List colors, List letters) { WireLetter letter; WireColor color; @@ -402,7 +392,7 @@ public sealed class WiresSystem : EntitySystem UpdateUserInterface(uid); foreach (var wire in component.WiresList) { - wire.Action.Update(wire); + wire.Action?.Update(wire); } } @@ -592,8 +582,8 @@ public sealed class WiresSystem : EntitySystem clientList.Add(new ClientWire(entry.Id, entry.IsCut, entry.Color, entry.Letter)); - var statusData = entry.Action.GetStatusLightData(entry); - if (statusData != null && entry.Action.StatusKey != null) + var statusData = entry.Action?.GetStatusLightData(entry); + if (statusData != null && entry.Action?.StatusKey != null) { wires.Statuses[entry.Action.StatusKey] = (entry.OriginalPosition, statusData); } @@ -786,7 +776,7 @@ public sealed class WiresSystem : EntitySystem } _toolSystem.PlayToolSound(toolEntity, tool); - if (wire.Action.Cut(user, wire)) + if (wire.Action == null || wire.Action.Cut(user, wire)) { wire.IsCut = true; } @@ -807,7 +797,7 @@ public sealed class WiresSystem : EntitySystem } _toolSystem.PlayToolSound(toolEntity, tool); - if (wire.Action.Mend(user, wire)) + if (wire.Action == null || wire.Action.Mend(user, wire)) { wire.IsCut = false; } @@ -827,14 +817,14 @@ public sealed class WiresSystem : EntitySystem break; } - wire.Action.Pulse(user, wire); + wire.Action?.Pulse(user, wire); UpdateUserInterface(used); _audio.PlayPvs(wires.PulseSound, used); break; } - wire.Action.Update(wire); + wire.Action?.Update(wire); wires.WiresQueue.Remove(id); } @@ -991,10 +981,12 @@ public sealed class Wire [ViewVariables] public WireLetter Letter { get; } - // The action that this wire performs upon activation. - public IWireAction Action { get; set; } + /// + /// The action that this wire performs when mended, cut or puled. This also determines the status lights that this wire adds. + /// + public IWireAction? Action { get; set; } - public Wire(EntityUid owner, bool isCut, WireColor color, WireLetter letter, int position, IWireAction action) + public Wire(EntityUid owner, bool isCut, WireColor color, WireLetter letter, int position, IWireAction? action) { Owner = owner; IsCut = isCut; diff --git a/Content.Shared.Database/LogType.cs b/Content.Shared.Database/LogType.cs index ad6e6ac2e9..ffb5cd84ed 100644 --- a/Content.Shared.Database/LogType.cs +++ b/Content.Shared.Database/LogType.cs @@ -81,5 +81,6 @@ public enum LogType Stamina = 76, EntitySpawn = 77, AdminMessage = 78, - Anomaly = 79 + Anomaly = 79, + WireHacking = 80, } diff --git a/Resources/Locale/en-US/wires/wire-names.ftl b/Resources/Locale/en-US/wires/wire-names.ftl new file mode 100644 index 0000000000..642f6f45ed --- /dev/null +++ b/Resources/Locale/en-US/wires/wire-names.ftl @@ -0,0 +1,16 @@ + +# names that get displayed in the wire hacking hud & admin logs. + +wire-name-access = ACC +wire-name-arcade-overflow = LMTR +wire-name-air-alarm-panic = PANC +wire-name-device-net = NETW +wire-name-bolt-light = BLIT +wire-name-door-bolt = BOLT +wire-name-door-safety = SAFE +wire-name-door-timer = TIMR +wire-name-lock = LOCK +wire-name-power = POWR +wire-name-arcade-invincible = MNGR +wire-name-vending-contraband = MNGR +wire-name-vending-eject = VEND