From db1ff07821472cfca979254572473159473c6eef Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Tue, 5 Sep 2023 00:07:01 +1000 Subject: [PATCH] Weldable cleanup (#19809) --- .../Tools/Components/WeldableComponent.cs | 9 -- .../Visualizers/WeldableVisualizerSystem.cs | 1 - .../Tests/DoAfter/DoAfterCancellationTests.cs | 8 +- .../Tests/Weldable/WeldableTests.cs | 8 +- .../Systems/AdminVerbSystem.Smites.cs | 4 +- .../Unary/Components/GasVentPumpComponent.cs | 4 +- .../Components/GasVentScrubberComponent.cs | 3 - .../Unary/EntitySystems/GasVentPumpSystem.cs | 15 ++-- .../EntitySystems/GasVentScrubberSystem.cs | 13 ++- .../Construction/Conditions/StorageWelded.cs | 11 ++- Content.Server/Content.Server.csproj | 1 + Content.Server/Doors/Systems/DoorSystem.cs | 4 +- .../NPC/Systems/NPCUtilitySystem.cs | 4 +- Content.Server/Resist/ResistLockerSystem.cs | 18 ++-- .../EntitySystems/BluespaceLockerSystem.cs | 9 +- .../EntitySystems/EntityStorageSystem.cs | 9 +- .../Tools/Components/WeldableComponent.cs | 48 ---------- .../SharedEntityStorageComponent.cs | 11 +-- .../SharedEntityStorageSystem.cs | 34 +++---- .../Components/LayerChangeOnWeldComponent.cs | 7 +- .../Tools/Components/SharedWeldable.cs | 31 ++++++- .../Tools/Systems/WeldableAttemptEvent.cs | 17 ++++ .../Tools/Systems/WeldableChangedEvent.cs | 12 +++ .../Tools/Systems/WeldableSystem.cs | 88 +++++++------------ 24 files changed, 159 insertions(+), 210 deletions(-) delete mode 100644 Content.Client/Tools/Components/WeldableComponent.cs delete mode 100644 Content.Server/Tools/Components/WeldableComponent.cs rename {Content.Server => Content.Shared}/Tools/Components/LayerChangeOnWeldComponent.cs (71%) create mode 100644 Content.Shared/Tools/Systems/WeldableAttemptEvent.cs create mode 100644 Content.Shared/Tools/Systems/WeldableChangedEvent.cs rename {Content.Server => Content.Shared}/Tools/Systems/WeldableSystem.cs (70%) diff --git a/Content.Client/Tools/Components/WeldableComponent.cs b/Content.Client/Tools/Components/WeldableComponent.cs deleted file mode 100644 index 6e98327768..0000000000 --- a/Content.Client/Tools/Components/WeldableComponent.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Content.Shared.Tools.Components; - -namespace Content.Client.Tools.Components; - -[RegisterComponent] -public sealed partial class WeldableComponent : SharedWeldableComponent -{ - -} diff --git a/Content.Client/Tools/Visualizers/WeldableVisualizerSystem.cs b/Content.Client/Tools/Visualizers/WeldableVisualizerSystem.cs index b34c6ffc8a..6fc90b0da2 100644 --- a/Content.Client/Tools/Visualizers/WeldableVisualizerSystem.cs +++ b/Content.Client/Tools/Visualizers/WeldableVisualizerSystem.cs @@ -1,4 +1,3 @@ -using Content.Client.Tools.Components; using Content.Shared.Tools.Components; using Robust.Client.GameObjects; diff --git a/Content.IntegrationTests/Tests/DoAfter/DoAfterCancellationTests.cs b/Content.IntegrationTests/Tests/DoAfter/DoAfterCancellationTests.cs index 29cb6426c9..16255d0773 100644 --- a/Content.IntegrationTests/Tests/DoAfter/DoAfterCancellationTests.cs +++ b/Content.IntegrationTests/Tests/DoAfter/DoAfterCancellationTests.cs @@ -2,7 +2,7 @@ using System.Linq; using Content.IntegrationTests.Tests.Construction.Interaction; using Content.IntegrationTests.Tests.Interaction; using Content.IntegrationTests.Tests.Weldable; -using Content.Server.Tools.Components; +using Content.Shared.Tools.Components; namespace Content.IntegrationTests.Tests.DoAfter; @@ -100,11 +100,7 @@ public sealed class DoAfterCancellationTests : InteractionTest await SpawnTarget(WeldableTests.Locker); var comp = Comp(); - Assert.Multiple(() => - { - Assert.That(comp.Weldable, Is.True); - Assert.That(comp.IsWelded, Is.False); - }); + Assert.That(comp.IsWelded, Is.False); await Interact(Weld, awaitDoAfters: false); await RunTicks(1); diff --git a/Content.IntegrationTests/Tests/Weldable/WeldableTests.cs b/Content.IntegrationTests/Tests/Weldable/WeldableTests.cs index 504a51a33c..6227f3dee1 100644 --- a/Content.IntegrationTests/Tests/Weldable/WeldableTests.cs +++ b/Content.IntegrationTests/Tests/Weldable/WeldableTests.cs @@ -1,5 +1,5 @@ using Content.IntegrationTests.Tests.Interaction; -using Content.Server.Tools.Components; +using Content.Shared.Tools.Components; namespace Content.IntegrationTests.Tests.Weldable; @@ -16,11 +16,7 @@ public sealed class WeldableTests : InteractionTest await SpawnTarget(Locker); var comp = Comp(); - Assert.Multiple(() => - { - Assert.That(comp.Weldable, Is.True); - Assert.That(comp.IsWelded, Is.False); - }); + Assert.That(comp.IsWelded, Is.False); await Interact(Weld); Assert.That(comp.IsWelded, Is.True); diff --git a/Content.Server/Administration/Systems/AdminVerbSystem.Smites.cs b/Content.Server/Administration/Systems/AdminVerbSystem.Smites.cs index 45c754eba4..5d9eaa0f29 100644 --- a/Content.Server/Administration/Systems/AdminVerbSystem.Smites.cs +++ b/Content.Server/Administration/Systems/AdminVerbSystem.Smites.cs @@ -18,7 +18,6 @@ using Content.Server.Storage.Components; using Content.Server.Storage.EntitySystems; using Content.Server.Tabletop; using Content.Server.Tabletop.Components; -using Content.Server.Tools.Systems; using Content.Shared.Administration; using Content.Shared.Administration.Components; using Content.Shared.Body.Components; @@ -39,6 +38,7 @@ using Content.Shared.Movement.Systems; using Content.Shared.Nutrition.Components; using Content.Shared.Popups; using Content.Shared.Tabletop.Components; +using Content.Shared.Tools.Systems; using Content.Shared.Verbs; using Robust.Server.GameObjects; using Robust.Shared.Map; @@ -677,7 +677,7 @@ public sealed partial class AdminVerbSystem _entityStorageSystem.Insert(args.Target, locker, storage); _entityStorageSystem.ToggleOpen(args.Target, locker, storage); } - _weldableSystem.ForceWeldedState(locker, true); + _weldableSystem.SetWeldedState(locker, true); }, Impact = LogImpact.Extreme, Message = Loc.GetString("admin-smite-locker-stuff-description"), diff --git a/Content.Server/Atmos/Piping/Unary/Components/GasVentPumpComponent.cs b/Content.Server/Atmos/Piping/Unary/Components/GasVentPumpComponent.cs index 8a7f2dbe59..74d945a0b6 100644 --- a/Content.Server/Atmos/Piping/Unary/Components/GasVentPumpComponent.cs +++ b/Content.Server/Atmos/Piping/Unary/Components/GasVentPumpComponent.cs @@ -5,6 +5,7 @@ using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototy namespace Content.Server.Atmos.Piping.Unary.Components { + // The world if people documented their shit. [RegisterComponent] public sealed partial class GasVentPumpComponent : Component { @@ -14,9 +15,6 @@ namespace Content.Server.Atmos.Piping.Unary.Components [ViewVariables] public bool IsDirty { get; set; } = false; - [ViewVariables(VVAccess.ReadWrite)] - public bool Welded { get; set; } = false; - [ViewVariables(VVAccess.ReadWrite)] [DataField("inlet")] public string Inlet { get; set; } = "pipe"; diff --git a/Content.Server/Atmos/Piping/Unary/Components/GasVentScrubberComponent.cs b/Content.Server/Atmos/Piping/Unary/Components/GasVentScrubberComponent.cs index 64f916bf96..064077a8db 100644 --- a/Content.Server/Atmos/Piping/Unary/Components/GasVentScrubberComponent.cs +++ b/Content.Server/Atmos/Piping/Unary/Components/GasVentScrubberComponent.cs @@ -15,9 +15,6 @@ namespace Content.Server.Atmos.Piping.Unary.Components [ViewVariables] public bool IsDirty { get; set; } = false; - [ViewVariables(VVAccess.ReadWrite)] - public bool Welded { get; set; } = false; - [ViewVariables(VVAccess.ReadWrite)] [DataField("outlet")] public string OutletName { get; set; } = "pipe"; diff --git a/Content.Server/Atmos/Piping/Unary/EntitySystems/GasVentPumpSystem.cs b/Content.Server/Atmos/Piping/Unary/EntitySystems/GasVentPumpSystem.cs index 80bd7c39e0..2c95887198 100644 --- a/Content.Server/Atmos/Piping/Unary/EntitySystems/GasVentPumpSystem.cs +++ b/Content.Server/Atmos/Piping/Unary/EntitySystems/GasVentPumpSystem.cs @@ -11,13 +11,13 @@ using Content.Server.NodeContainer; using Content.Server.NodeContainer.EntitySystems; using Content.Server.NodeContainer.Nodes; using Content.Server.Power.Components; -using Content.Server.Tools.Systems; using Content.Shared.Atmos; using Content.Shared.Atmos.Monitor; using Content.Shared.Atmos.Piping.Unary.Components; using Content.Shared.Atmos.Visuals; using Content.Shared.Audio; using Content.Shared.Examine; +using Content.Shared.Tools.Systems; using JetBrains.Annotations; using Robust.Server.GameObjects; @@ -29,9 +29,10 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems [Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!; [Dependency] private readonly DeviceNetworkSystem _deviceNetSystem = default!; [Dependency] private readonly DeviceLinkSystem _signalSystem = default!; + [Dependency] private readonly NodeContainerSystem _nodeContainer = default!; [Dependency] private readonly SharedAmbientSoundSystem _ambientSoundSystem = default!; [Dependency] private readonly SharedAppearanceSystem _appearance = default!; - [Dependency] private readonly NodeContainerSystem _nodeContainer = default!; + [Dependency] private readonly WeldableSystem _weldable = default!; public override void Initialize() { @@ -53,7 +54,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems private void OnGasVentPumpUpdated(EntityUid uid, GasVentPumpComponent vent, AtmosDeviceUpdateEvent args) { //Bingo waz here - if (vent.Welded) + if (_weldable.IsWelded(uid)) { return; } @@ -82,7 +83,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems } var timeDelta = args.dt; - var pressureDelta = (float) timeDelta * vent.TargetPressureChange; + var pressureDelta = timeDelta * vent.TargetPressureChange; if (vent.PumpDirection == VentPumpDirection.Releasing && pipe.Air.Pressure > 0) { @@ -255,7 +256,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems return; _ambientSoundSystem.SetAmbience(uid, true); - if (vent.Welded) + if (_weldable.IsWelded(uid)) { _ambientSoundSystem.SetAmbience(uid, false); _appearance.SetData(uid, VentPumpVisuals.State, VentPumpState.Welded, appearance); @@ -311,10 +312,8 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems args.GasMixtures = gasMixDict; } - private void OnWeldChanged(EntityUid uid, GasVentPumpComponent component, WeldableChangedEvent args) + private void OnWeldChanged(EntityUid uid, GasVentPumpComponent component, ref WeldableChangedEvent args) { - var isWelded = args.IsWelded; - component.Welded = isWelded; UpdateState(uid, component); } } diff --git a/Content.Server/Atmos/Piping/Unary/EntitySystems/GasVentScrubberSystem.cs b/Content.Server/Atmos/Piping/Unary/EntitySystems/GasVentScrubberSystem.cs index 3d05e6e1cd..f7f13a4d33 100644 --- a/Content.Server/Atmos/Piping/Unary/EntitySystems/GasVentScrubberSystem.cs +++ b/Content.Server/Atmos/Piping/Unary/EntitySystems/GasVentScrubberSystem.cs @@ -10,12 +10,12 @@ using Content.Server.NodeContainer; using Content.Server.NodeContainer.EntitySystems; using Content.Server.NodeContainer.Nodes; using Content.Server.Power.Components; -using Content.Server.Tools.Systems; using Content.Shared.Atmos; using Content.Shared.Atmos.Piping.Unary.Visuals; using Content.Shared.Atmos.Monitor; using Content.Shared.Atmos.Piping.Unary.Components; using Content.Shared.Audio; +using Content.Shared.Tools.Systems; using JetBrains.Annotations; using Robust.Server.GameObjects; @@ -26,10 +26,11 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems { [Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!; [Dependency] private readonly DeviceNetworkSystem _deviceNetSystem = default!; + [Dependency] private readonly NodeContainerSystem _nodeContainer = default!; [Dependency] private readonly SharedAmbientSoundSystem _ambientSoundSystem = default!; [Dependency] private readonly TransformSystem _transformSystem = default!; [Dependency] private readonly SharedAppearanceSystem _appearance = default!; - [Dependency] private readonly NodeContainerSystem _nodeContainer = default!; + [Dependency] private readonly WeldableSystem _weldable = default!; public override void Initialize() { @@ -46,7 +47,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems private void OnVentScrubberUpdated(EntityUid uid, GasVentScrubberComponent scrubber, AtmosDeviceUpdateEvent args) { - if (scrubber.Welded) + if (_weldable.IsWelded(uid)) { return; } @@ -185,7 +186,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems return; _ambientSoundSystem.SetAmbience(uid, true); - if (scrubber.Welded) + if (_weldable.IsWelded(uid)) { _ambientSoundSystem.SetAmbience(uid, false); _appearance.SetData(uid, ScrubberVisuals.State, ScrubberState.Welded, appearance); @@ -205,10 +206,8 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems } } - private void OnWeldChanged(EntityUid uid, GasVentScrubberComponent component, WeldableChangedEvent args) + private void OnWeldChanged(EntityUid uid, GasVentScrubberComponent component, ref WeldableChangedEvent args) { - var isWelded = args.IsWelded; - component.Welded = isWelded; UpdateState(uid, component); } } diff --git a/Content.Server/Construction/Conditions/StorageWelded.cs b/Content.Server/Construction/Conditions/StorageWelded.cs index 576bb53946..8758a8617d 100644 --- a/Content.Server/Construction/Conditions/StorageWelded.cs +++ b/Content.Server/Construction/Conditions/StorageWelded.cs @@ -1,6 +1,7 @@ using Content.Server.Storage.Components; using Content.Shared.Construction; using Content.Shared.Examine; +using Content.Shared.Tools.Systems; using JetBrains.Annotations; namespace Content.Server.Construction.Conditions @@ -14,10 +15,7 @@ namespace Content.Server.Construction.Conditions public bool Condition(EntityUid uid, IEntityManager entityManager) { - if (!entityManager.TryGetComponent(uid, out EntityStorageComponent? entityStorageComponent)) - return false; - - return entityStorageComponent.IsWeldedShut == Welded; + return entityManager.System().IsWelded(uid); } public bool DoExamine(ExaminedEvent args) @@ -25,11 +23,12 @@ namespace Content.Server.Construction.Conditions var entMan = IoCManager.Resolve(); var entity = args.Examined; - if (!entMan.TryGetComponent(entity, out EntityStorageComponent? entityStorage)) return false; + if (!entMan.HasComponent(entity)) + return false; var metaData = entMan.GetComponent(entity); - if (entityStorage.IsWeldedShut != Welded) + if (entMan.System().IsWelded(entity) != Welded) { if (Welded) args.PushMarkup(Loc.GetString("construction-examine-condition-door-weld", ("entityName", metaData.EntityName)) + "\n"); diff --git a/Content.Server/Content.Server.csproj b/Content.Server/Content.Server.csproj index a2ccc769c9..3aba36c788 100644 --- a/Content.Server/Content.Server.csproj +++ b/Content.Server/Content.Server.csproj @@ -27,6 +27,7 @@ + diff --git a/Content.Server/Doors/Systems/DoorSystem.cs b/Content.Server/Doors/Systems/DoorSystem.cs index c16b2b6fec..1bb8a0505f 100644 --- a/Content.Server/Doors/Systems/DoorSystem.cs +++ b/Content.Server/Doors/Systems/DoorSystem.cs @@ -2,7 +2,6 @@ using Content.Server.Access; using Content.Server.Atmos.Components; using Content.Server.Atmos.EntitySystems; using Content.Server.Construction; -using Content.Server.Tools.Systems; using Content.Shared.Database; using Content.Shared.Doors; using Content.Shared.Doors.Components; @@ -18,6 +17,7 @@ using Content.Shared.Tools; using Robust.Shared.Physics.Components; using Robust.Shared.Physics.Events; using Content.Shared.DoAfter; +using Content.Shared.Tools.Systems; namespace Content.Server.Doors.Systems; @@ -139,7 +139,7 @@ public sealed class DoorSystem : SharedDoorSystem } } - private void OnWeldChanged(EntityUid uid, DoorComponent component, WeldableChangedEvent args) + private void OnWeldChanged(EntityUid uid, DoorComponent component, ref WeldableChangedEvent args) { if (component.State == DoorState.Closed) SetState(uid, DoorState.Welded, component); diff --git a/Content.Server/NPC/Systems/NPCUtilitySystem.cs b/Content.Server/NPC/Systems/NPCUtilitySystem.cs index 10354e1336..d9aec892ce 100644 --- a/Content.Server/NPC/Systems/NPCUtilitySystem.cs +++ b/Content.Server/NPC/Systems/NPCUtilitySystem.cs @@ -15,6 +15,7 @@ using Content.Shared.Hands.Components; using Content.Shared.Inventory; using Content.Shared.Mobs.Systems; using Content.Shared.Nutrition.Components; +using Content.Shared.Tools.Systems; using Content.Shared.Weapons.Melee; using Content.Shared.Weapons.Ranged.Components; using Content.Shared.Weapons.Ranged.Events; @@ -42,6 +43,7 @@ public sealed class NPCUtilitySystem : EntitySystem [Dependency] private readonly PuddleSystem _puddle = default!; [Dependency] private readonly SharedTransformSystem _transform = default!; [Dependency] private readonly SolutionContainerSystem _solutions = default!; + [Dependency] private readonly WeldableSystem _weldable = default!; private EntityQuery _xformQuery; @@ -195,7 +197,7 @@ public sealed class NPCUtilitySystem : EntitySystem { if (TryComp(container.Owner, out var storageComponent)) { - if (storageComponent is { IsWeldedShut: true, Open: false }) + if (storageComponent is { Open: false } && _weldable.IsWelded(container.Owner)) { return 0.0f; } diff --git a/Content.Server/Resist/ResistLockerSystem.cs b/Content.Server/Resist/ResistLockerSystem.cs index 4b433073ca..58b898ac96 100644 --- a/Content.Server/Resist/ResistLockerSystem.cs +++ b/Content.Server/Resist/ResistLockerSystem.cs @@ -6,15 +6,18 @@ using Content.Shared.Lock; using Content.Shared.Movement.Events; using Content.Shared.Popups; using Content.Shared.Resist; +using Content.Shared.Tools.Components; +using Content.Shared.Tools.Systems; namespace Content.Server.Resist; public sealed class ResistLockerSystem : EntitySystem { - [Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!; - [Dependency] private readonly PopupSystem _popupSystem = default!; - [Dependency] private readonly LockSystem _lockSystem = default!; [Dependency] private readonly EntityStorageSystem _entityStorage = default!; + [Dependency] private readonly LockSystem _lockSystem = default!; + [Dependency] private readonly PopupSystem _popupSystem = default!; + [Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!; + [Dependency] private readonly WeldableSystem _weldable = default!; public override void Initialize() { @@ -31,7 +34,7 @@ public sealed class ResistLockerSystem : EntitySystem if (!TryComp(uid, out EntityStorageComponent? storageComponent)) return; - if (TryComp(uid, out var lockComponent) && lockComponent.Locked || storageComponent.IsWeldedShut) + if (TryComp(uid, out var lockComponent) && lockComponent.Locked || _weldable.IsWelded(uid)) { AttemptResist(args.Entity, uid, storageComponent, component); } @@ -69,10 +72,11 @@ public sealed class ResistLockerSystem : EntitySystem component.IsResisting = false; - if (TryComp(uid, out var storageComponent)) + if (HasComp(uid)) { - if (storageComponent.IsWeldedShut) - storageComponent.IsWeldedShut = false; + WeldableComponent? weldable = null; + if (_weldable.IsWelded(uid, weldable)) + _weldable.SetWeldedState(uid, false, weldable); if (TryComp(args.Args.Target.Value, out var lockComponent)) _lockSystem.Unlock(uid, args.Args.User, lockComponent); diff --git a/Content.Server/Storage/EntitySystems/BluespaceLockerSystem.cs b/Content.Server/Storage/EntitySystems/BluespaceLockerSystem.cs index 4ac6d4798b..cd832f8f31 100644 --- a/Content.Server/Storage/EntitySystems/BluespaceLockerSystem.cs +++ b/Content.Server/Storage/EntitySystems/BluespaceLockerSystem.cs @@ -3,7 +3,6 @@ using Content.Server.Explosion.EntitySystems; using Content.Server.Resist; using Content.Server.Station.Components; using Content.Server.Storage.Components; -using Content.Server.Tools.Systems; using Content.Shared.Access.Components; using Content.Shared.Coordinates; using Content.Shared.DoAfter; @@ -11,6 +10,7 @@ using Content.Shared.Lock; using Content.Shared.Mind.Components; using Content.Shared.Storage.Components; using Content.Shared.Storage.EntitySystems; +using Content.Shared.Tools.Systems; using Robust.Shared.Random; using Robust.Shared.Timing; @@ -327,13 +327,12 @@ public sealed class BluespaceLockerSystem : EntitySystem } else { - if (target.Value.storageComponent.IsWeldedShut) + if (_weldableSystem.IsWelded(target.Value.uid)) { // It gets bluespaced open... - _weldableSystem.ForceWeldedState(target.Value.uid, false); - if (target.Value.storageComponent.IsWeldedShut) - target.Value.storageComponent.IsWeldedShut = false; + _weldableSystem.SetWeldedState(target.Value.uid, false); } + LockComponent? lockComponent = null; if (Resolve(target.Value.uid, ref lockComponent, false) && lockComponent.Locked) _lockSystem.Unlock(target.Value.uid, target.Value.uid, lockComponent); diff --git a/Content.Server/Storage/EntitySystems/EntityStorageSystem.cs b/Content.Server/Storage/EntitySystems/EntityStorageSystem.cs index 6281daab0d..a828c22d5b 100644 --- a/Content.Server/Storage/EntitySystems/EntityStorageSystem.cs +++ b/Content.Server/Storage/EntitySystems/EntityStorageSystem.cs @@ -3,7 +3,6 @@ using Content.Server.Atmos.EntitySystems; using Content.Server.Construction; using Content.Server.Construction.Components; using Content.Server.Storage.Components; -using Content.Server.Tools.Systems; using Content.Shared.Destructible; using Content.Shared.Foldable; using Content.Shared.Interaction; @@ -11,6 +10,7 @@ using Content.Shared.Lock; using Content.Shared.Movement.Events; using Content.Shared.Storage.Components; using Content.Shared.Storage.EntitySystems; +using Content.Shared.Tools.Systems; using Content.Shared.Verbs; using Robust.Shared.Containers; using Robust.Shared.GameStates; @@ -44,7 +44,6 @@ public sealed class EntityStorageSystem : SharedEntityStorageSystem SubscribeLocalEvent(OnMapInit); SubscribeLocalEvent(OnWeldableAttempt); - SubscribeLocalEvent(OnWelded); SubscribeLocalEvent(OnInsideInhale); SubscribeLocalEvent(OnInsideExhale); @@ -97,12 +96,6 @@ public sealed class EntityStorageSystem : SharedEntityStorageSystem } } - private void OnWelded(EntityUid uid, EntityStorageComponent component, WeldableChangedEvent args) - { - component.IsWeldedShut = args.IsWelded; - Dirty(component); - } - protected override void TakeGas(EntityUid uid, SharedEntityStorageComponent component) { if (!component.Airtight) diff --git a/Content.Server/Tools/Components/WeldableComponent.cs b/Content.Server/Tools/Components/WeldableComponent.cs deleted file mode 100644 index 16996481d5..0000000000 --- a/Content.Server/Tools/Components/WeldableComponent.cs +++ /dev/null @@ -1,48 +0,0 @@ -using Content.Server.Tools.Systems; -using Content.Shared.Tools; -using Content.Shared.Tools.Components; -using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; - -namespace Content.Server.Tools.Components; - -/// -/// Allows users to weld/unweld doors, crates and lockers. -/// -[RegisterComponent] -[Access(typeof(WeldableSystem))] -public sealed partial class WeldableComponent : SharedWeldableComponent -{ - /// - /// Tool quality for welding. - /// - [DataField("weldingQuality", customTypeSerializer: typeof(PrototypeIdSerializer))] - [ViewVariables(VVAccess.ReadWrite)] - public string WeldingQuality = "Welding"; - - /// - /// Whether this entity can ever be welded shut. - /// - [DataField("weldable")] - [ViewVariables(VVAccess.ReadWrite)] - public bool Weldable = true; - - /// - /// How much time does it take to weld/unweld entity. - /// - [DataField("time")] - [ViewVariables(VVAccess.ReadWrite)] - public TimeSpan WeldingTime = TimeSpan.FromSeconds(1f); - - /// - /// Shown when welded entity is examined. - /// - [DataField("weldedExamineMessage")] - [ViewVariables(VVAccess.ReadWrite)] - public string? WeldedExamineMessage = "weldable-component-examine-is-welded"; - - /// - /// Is this entity currently welded shut? - /// - [DataField("isWelded")] - public bool IsWelded; -} diff --git a/Content.Shared/Storage/Components/SharedEntityStorageComponent.cs b/Content.Shared/Storage/Components/SharedEntityStorageComponent.cs index a1a09c4d0c..db1d3bac9a 100644 --- a/Content.Shared/Storage/Components/SharedEntityStorageComponent.cs +++ b/Content.Shared/Storage/Components/SharedEntityStorageComponent.cs @@ -119,12 +119,6 @@ public abstract partial class SharedEntityStorageComponent : Component /// [ViewVariables] public Container Contents = default!; - - /// - /// Whether or not the storage has been welded shut - /// - [DataField("isWeldedShut"), ViewVariables(VVAccess.ReadWrite)] - public bool IsWeldedShut; } [Serializable, NetSerializable] @@ -140,16 +134,13 @@ public sealed class EntityStorageComponentState : ComponentState public float EnteringRange; - public bool IsWeldedShut; - - public EntityStorageComponentState(bool open, int capacity, bool isCollidableWhenOpen, bool openOnMove, float enteringRange, bool isWeldedShut) + public EntityStorageComponentState(bool open, int capacity, bool isCollidableWhenOpen, bool openOnMove, float enteringRange) { Open = open; Capacity = capacity; IsCollidableWhenOpen = isCollidableWhenOpen; OpenOnMove = openOnMove; EnteringRange = enteringRange; - IsWeldedShut = isWeldedShut; } } diff --git a/Content.Shared/Storage/EntitySystems/SharedEntityStorageSystem.cs b/Content.Shared/Storage/EntitySystems/SharedEntityStorageSystem.cs index 5e3a257d1c..b4c0a63979 100644 --- a/Content.Shared/Storage/EntitySystems/SharedEntityStorageSystem.cs +++ b/Content.Shared/Storage/EntitySystems/SharedEntityStorageSystem.cs @@ -12,6 +12,7 @@ using Content.Shared.Movement.Events; using Content.Shared.Placeable; using Content.Shared.Popups; using Content.Shared.Storage.Components; +using Content.Shared.Tools.Systems; using Content.Shared.Verbs; using Content.Shared.Wall; using Content.Shared.Whitelist; @@ -29,18 +30,19 @@ namespace Content.Shared.Storage.EntitySystems; public abstract class SharedEntityStorageSystem : EntitySystem { - [Dependency] private readonly IGameTiming _timing = default!; - [Dependency] private readonly INetManager _net = default!; - [Dependency] private readonly EntityLookupSystem _lookup = default!; - [Dependency] private readonly PlaceableSurfaceSystem _placeableSurface = default!; - [Dependency] private readonly SharedAppearanceSystem _appearance = default!; - [Dependency] private readonly SharedAudioSystem _audio = default!; - [Dependency] private readonly SharedContainerSystem _container = default!; - [Dependency] private readonly SharedInteractionSystem _interaction = default!; - [Dependency] private readonly SharedJointSystem _joints = default!; - [Dependency] private readonly SharedPhysicsSystem _physics = default!; + [Dependency] private readonly IGameTiming _timing = default!; + [Dependency] private readonly INetManager _net = default!; + [Dependency] private readonly EntityLookupSystem _lookup = default!; + [Dependency] private readonly PlaceableSurfaceSystem _placeableSurface = default!; + [Dependency] private readonly SharedAppearanceSystem _appearance = default!; + [Dependency] private readonly SharedAudioSystem _audio = default!; + [Dependency] private readonly SharedContainerSystem _container = default!; + [Dependency] private readonly SharedInteractionSystem _interaction = default!; + [Dependency] private readonly SharedJointSystem _joints = default!; + [Dependency] private readonly SharedPhysicsSystem _physics = default!; [Dependency] protected readonly SharedPopupSystem Popup = default!; - [Dependency] private readonly SharedTransformSystem _transform = default!; + [Dependency] private readonly SharedTransformSystem _transform = default!; + [Dependency] private readonly WeldableSystem _weldable = default!; public const string ContainerName = "entity_storage"; @@ -50,8 +52,7 @@ public abstract class SharedEntityStorageSystem : EntitySystem component.Capacity, component.IsCollidableWhenOpen, component.OpenOnMove, - component.EnteringRange, - component.IsWeldedShut); + component.EnteringRange); } protected void OnHandleState(EntityUid uid, SharedEntityStorageComponent component, ref ComponentHandleState args) @@ -63,7 +64,6 @@ public abstract class SharedEntityStorageSystem : EntitySystem component.IsCollidableWhenOpen = state.IsCollidableWhenOpen; component.OpenOnMove = state.OpenOnMove; component.EnteringRange = state.EnteringRange; - component.IsWeldedShut = state.IsWeldedShut; } protected virtual void OnComponentInit(EntityUid uid, SharedEntityStorageComponent component, ComponentInit args) @@ -323,10 +323,10 @@ public abstract class SharedEntityStorageSystem : EntitySystem if (!HasComp(user)) return false; - if (component.IsWeldedShut) + if (_weldable.IsWelded(target)) { - if (!silent && !component.Contents.Contains(user) && _net.IsServer) - Popup.PopupEntity(Loc.GetString("entity-storage-component-welded-shut-message"), target); + if (!silent && !component.Contents.Contains(user)) + Popup.PopupClient(Loc.GetString("entity-storage-component-welded-shut-message"), target, user); return false; } diff --git a/Content.Server/Tools/Components/LayerChangeOnWeldComponent.cs b/Content.Shared/Tools/Components/LayerChangeOnWeldComponent.cs similarity index 71% rename from Content.Server/Tools/Components/LayerChangeOnWeldComponent.cs rename to Content.Shared/Tools/Components/LayerChangeOnWeldComponent.cs index cfecc76a63..165cd41e69 100644 --- a/Content.Server/Tools/Components/LayerChangeOnWeldComponent.cs +++ b/Content.Shared/Tools/Components/LayerChangeOnWeldComponent.cs @@ -1,9 +1,10 @@ -using Content.Server.Tools.Systems; using Content.Shared.Physics; +using Content.Shared.Tools.Systems; +using Robust.Shared.GameStates; -namespace Content.Server.Tools.Components; +namespace Content.Shared.Tools.Components; -[RegisterComponent] +[RegisterComponent, NetworkedComponent] [Access(typeof(WeldableSystem))] public sealed partial class LayerChangeOnWeldComponent : Component { diff --git a/Content.Shared/Tools/Components/SharedWeldable.cs b/Content.Shared/Tools/Components/SharedWeldable.cs index 21056285a1..701bd4d8da 100644 --- a/Content.Shared/Tools/Components/SharedWeldable.cs +++ b/Content.Shared/Tools/Components/SharedWeldable.cs @@ -1,10 +1,39 @@ +using Robust.Shared.GameStates; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; namespace Content.Shared.Tools.Components; -public abstract partial class SharedWeldableComponent : Component +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] +public sealed partial class WeldableComponent : Component { + /// + /// Tool quality for welding. + /// + [DataField("weldingQuality", customTypeSerializer: typeof(PrototypeIdSerializer))] + [ViewVariables(VVAccess.ReadWrite)] + public string WeldingQuality = "Welding"; + /// + /// How much time does it take to weld/unweld entity. + /// + [DataField("time")] + [ViewVariables(VVAccess.ReadWrite)] + [AutoNetworkedField] + public TimeSpan WeldingTime = TimeSpan.FromSeconds(1f); + + /// + /// Shown when welded entity is examined. + /// + [DataField("weldedExamineMessage")] + [ViewVariables(VVAccess.ReadWrite)] + public string? WeldedExamineMessage = "weldable-component-examine-is-welded"; + + /// + /// Is this entity currently welded shut? + /// + [DataField("isWelded"), AutoNetworkedField] + public bool IsWelded; } [Serializable, NetSerializable] diff --git a/Content.Shared/Tools/Systems/WeldableAttemptEvent.cs b/Content.Shared/Tools/Systems/WeldableAttemptEvent.cs new file mode 100644 index 0000000000..a3b853422d --- /dev/null +++ b/Content.Shared/Tools/Systems/WeldableAttemptEvent.cs @@ -0,0 +1,17 @@ +namespace Content.Shared.Tools.Systems; + +/// +/// Checks that entity can be weld/unweld. +/// Raised twice: before do_after and after to check that entity still valid. +/// +public sealed class WeldableAttemptEvent : CancellableEntityEventArgs +{ + public readonly EntityUid User; + public readonly EntityUid Tool; + + public WeldableAttemptEvent(EntityUid user, EntityUid tool) + { + User = user; + Tool = tool; + } +} \ No newline at end of file diff --git a/Content.Shared/Tools/Systems/WeldableChangedEvent.cs b/Content.Shared/Tools/Systems/WeldableChangedEvent.cs new file mode 100644 index 0000000000..977e345ccd --- /dev/null +++ b/Content.Shared/Tools/Systems/WeldableChangedEvent.cs @@ -0,0 +1,12 @@ +using Content.Shared.Tools.Components; + +namespace Content.Shared.Tools.Systems; + +/// +/// Raised when has changed. +/// +[ByRefEvent] +public readonly record struct WeldableChangedEvent(bool IsWelded) +{ + public readonly bool IsWelded = IsWelded; +} diff --git a/Content.Server/Tools/Systems/WeldableSystem.cs b/Content.Shared/Tools/Systems/WeldableSystem.cs similarity index 70% rename from Content.Server/Tools/Systems/WeldableSystem.cs rename to Content.Shared/Tools/Systems/WeldableSystem.cs index 154c3ddffa..11ead6bba1 100644 --- a/Content.Server/Tools/Systems/WeldableSystem.cs +++ b/Content.Shared/Tools/Systems/WeldableSystem.cs @@ -1,29 +1,28 @@ -using Content.Server.Administration.Logs; -using Content.Server.Construction; -using Content.Server.Tools.Components; -using Content.Server.Wires; -using Content.Shared.Construction.Steps; +using Content.Shared.Administration.Logs; using Content.Shared.Database; -using Content.Shared.DoAfter; using Content.Shared.Examine; using Content.Shared.Interaction; -using Content.Shared.Tools; using Content.Shared.Tools.Components; -using Content.Shared.Tools.Systems; -using Content.Shared.Wires; using Robust.Shared.Physics; using Robust.Shared.Physics.Systems; -using System.Linq; +using LayerChangeOnWeldComponent = Content.Shared.Tools.Components.LayerChangeOnWeldComponent; -namespace Content.Server.Tools.Systems; +namespace Content.Shared.Tools.Systems; public sealed class WeldableSystem : EntitySystem { - [Dependency] private readonly IAdminLogManager _adminLogger = default!; + [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!; [Dependency] private readonly SharedToolSystem _toolSystem = default!; [Dependency] private readonly SharedAppearanceSystem _appearance = default!; [Dependency] private readonly SharedPhysicsSystem _physics = default!; - [Dependency] private readonly ConstructionSystem _construction = default!; + + public bool IsWelded(EntityUid uid, WeldableComponent? component = null) + { + if (!Resolve(uid, ref component, false)) + return false; + + return component.IsWelded; + } public override void Initialize() { @@ -43,12 +42,14 @@ 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 - if (_construction.GetCurrentNode(uid)?.Edges.Any(x => _construction.CheckConditions(uid, x.Conditions) - && x.Steps.Any(y => (y as ToolConstructionGraphStep)?.Tool == "Welding")) == true) + /* TODO: Whatever this is is not the way to do what you think you want to do. + if (Enumerable.Any(_construction.GetCurrentNode(uid)?.Edges, x => _construction.CheckConditions(uid, x.Conditions) + && Enumerable.Any(x.Steps, y => (y as ToolConstructionGraphStep)?.Tool == "Welding")) == true) { args.Handled = false; return; } + */ if (args.Handled) return; @@ -61,13 +62,9 @@ public sealed class WeldableSystem : EntitySystem if (!Resolve(uid, ref component)) return false; - // Basic checks - if (!component.Weldable) - return false; - // Other component systems var attempt = new WeldableAttemptEvent(user, tool); - RaiseLocalEvent(uid, attempt, true); + RaiseLocalEvent(uid, attempt); if (attempt.Cancelled) return false; @@ -100,16 +97,13 @@ public sealed class WeldableSystem : EntitySystem if (!CanWeld(uid, args.Used.Value, args.User, component)) return; - component.IsWelded = !component.IsWelded; - RaiseLocalEvent(uid, new WeldableChangedEvent(component.IsWelded), true); - - UpdateAppearance(uid, component); + SetWeldedState(uid, !component.IsWelded, component); // Log success _adminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(args.User):user} {(!component.IsWelded ? "un" : "")}welded {ToPrettyString(uid):target}"); } - private void OnWeldChanged(EntityUid uid, LayerChangeOnWeldComponent component, WeldableChangedEvent args) + private void OnWeldChanged(EntityUid uid, LayerChangeOnWeldComponent component, ref WeldableChangedEvent args) { if (!TryComp(uid, out var fixtures)) return; @@ -139,51 +133,31 @@ public sealed class WeldableSystem : EntitySystem _appearance.SetData(uid, WeldableVisuals.IsWelded, component.IsWelded, appearance); } - public void ForceWeldedState(EntityUid uid, bool state, WeldableComponent? component = null) + public void SetWeldedState(EntityUid uid, bool state, WeldableComponent? component = null) { if (!Resolve(uid, ref component)) return; + if (component.IsWelded == state) + return; + component.IsWelded = state; + var ev = new WeldableChangedEvent(component.IsWelded); - RaiseLocalEvent(uid, new WeldableChangedEvent(component.IsWelded)); - + RaiseLocalEvent(uid, ref ev); UpdateAppearance(uid, component); + Dirty(uid, component); } public void SetWeldingTime(EntityUid uid, TimeSpan time, WeldableComponent? component = null) { if (!Resolve(uid, ref component)) return; + + if (component.WeldingTime.Equals(time)) + return; + component.WeldingTime = time; - } -} - -/// -/// Checks that entity can be weld/unweld. -/// Raised twice: before do_after and after to check that entity still valid. -/// -public sealed class WeldableAttemptEvent : CancellableEntityEventArgs -{ - public readonly EntityUid User; - public readonly EntityUid Tool; - - public WeldableAttemptEvent(EntityUid user, EntityUid tool) - { - User = user; - Tool = tool; - } -} - -/// -/// Raised when has changed. -/// -public sealed class WeldableChangedEvent : EntityEventArgs -{ - public readonly bool IsWelded; - - public WeldableChangedEvent(bool isWelded) - { - IsWelded = isWelded; + Dirty(uid, component); } }