diff --git a/Content.Server/Atmos/Monitor/Systems/AirAlarmSystem.cs b/Content.Server/Atmos/Monitor/Systems/AirAlarmSystem.cs index 3221bb99e7..b41b6a4245 100644 --- a/Content.Server/Atmos/Monitor/Systems/AirAlarmSystem.cs +++ b/Content.Server/Atmos/Monitor/Systems/AirAlarmSystem.cs @@ -5,6 +5,7 @@ using Content.Server.DeviceNetwork.Components; using Content.Server.DeviceNetwork.Systems; using Content.Server.Popups; using Content.Server.Power.Components; +using Content.Server.Power.EntitySystems; using Content.Server.Wires; using Content.Shared.Access.Components; using Content.Shared.Access.Systems; @@ -201,7 +202,7 @@ namespace Content.Server.Atmos.Monitor.Systems return; } - if (EntityManager.TryGetComponent(uid, out ApcPowerReceiverComponent recv) && !recv.Powered) + if (!this.IsPowered(uid, EntityManager)) return; _uiSystem.GetUiOrNull(component.Owner, SharedAirAlarmInterfaceKey.Key)?.Open(actor.PlayerSession); diff --git a/Content.Server/Atmos/Monitor/Systems/AtmosMonitoringSystem.cs b/Content.Server/Atmos/Monitor/Systems/AtmosMonitoringSystem.cs index 6cf5b65e36..49981da3df 100644 --- a/Content.Server/Atmos/Monitor/Systems/AtmosMonitoringSystem.cs +++ b/Content.Server/Atmos/Monitor/Systems/AtmosMonitoringSystem.cs @@ -6,6 +6,7 @@ using Content.Server.DeviceNetwork; using Content.Server.DeviceNetwork.Components; using Content.Server.DeviceNetwork.Systems; using Content.Server.Power.Components; +using Content.Server.Power.EntitySystems; using Content.Shared.Atmos; using Content.Shared.Atmos.Monitor; using Robust.Shared.Audio; @@ -229,8 +230,7 @@ namespace Content.Server.Atmos.Monitor.Systems private void OnFireEvent(EntityUid uid, AtmosMonitorComponent component, ref TileFireEvent args) { - if (!TryComp(uid, out var powerReceiverComponent) - || !powerReceiverComponent.Powered) + if (!this.IsPowered(uid, EntityManager)) return; // if we're monitoring for atmos fire, then we make it similar to a smoke detector @@ -252,8 +252,7 @@ namespace Content.Server.Atmos.Monitor.Systems private void OnAtmosUpdate(EntityUid uid, AtmosMonitorComponent component, AtmosDeviceUpdateEvent args) { - if (!TryComp(uid, out var powerReceiverComponent) - || !powerReceiverComponent.Powered) + if (!this.IsPowered(uid, EntityManager)) return; // can't hurt diff --git a/Content.Server/Atmos/Monitor/Systems/FireAlarmSystem.cs b/Content.Server/Atmos/Monitor/Systems/FireAlarmSystem.cs index 2895367420..829728c504 100644 --- a/Content.Server/Atmos/Monitor/Systems/FireAlarmSystem.cs +++ b/Content.Server/Atmos/Monitor/Systems/FireAlarmSystem.cs @@ -1,6 +1,7 @@ using Content.Server.AlertLevel; using Content.Server.Atmos.Monitor.Components; using Content.Server.Power.Components; +using Content.Server.Power.EntitySystems; using Content.Shared.AlertLevel; using Content.Shared.Atmos.Monitor; using Content.Shared.Interaction; @@ -27,8 +28,7 @@ namespace Content.Server.Atmos.Monitor.Systems if (EntityManager.TryGetComponent(args.User, out ActorComponent? actor) && EntityManager.TryGetComponent(uid, out AtmosMonitorComponent? monitor) - && EntityManager.TryGetComponent(uid, out ApcPowerReceiverComponent? power) - && power.Powered) + && this.IsPowered(uid, EntityManager)) { if (monitor.HighestAlarmInNetwork == AtmosMonitorAlarmType.Normal) { diff --git a/Content.Server/Bed/BedSystem.cs b/Content.Server/Bed/BedSystem.cs index 6936fcfdbe..ff890495fe 100644 --- a/Content.Server/Bed/BedSystem.cs +++ b/Content.Server/Bed/BedSystem.cs @@ -6,6 +6,7 @@ using Content.Shared.Buckle.Components; using Content.Shared.Body.Components; using Content.Shared.Bed; using Content.Server.Power.Components; +using Content.Server.Power.EntitySystems; using Content.Shared.Emag.Systems; using Content.Shared.MobState.Components; @@ -78,7 +79,7 @@ namespace Content.Server.Bed if (!TryComp(args.BuckledEntity, out var body)) return; - if (TryComp(uid, out var power) && !power.Powered) + if (!this.IsPowered(uid, EntityManager)) return; var metabolicEvent = new ApplyMetabolicMultiplierEvent() diff --git a/Content.Server/Botany/Systems/SeedExtractorSystem.cs b/Content.Server/Botany/Systems/SeedExtractorSystem.cs index 3f2b41de2e..6f2f890154 100644 --- a/Content.Server/Botany/Systems/SeedExtractorSystem.cs +++ b/Content.Server/Botany/Systems/SeedExtractorSystem.cs @@ -1,6 +1,7 @@ using Content.Server.Botany.Components; using Content.Server.Popups; using Content.Server.Power.Components; +using Content.Server.Power.EntitySystems; using Content.Shared.Interaction; using Robust.Shared.Player; using Robust.Shared.Random; @@ -22,29 +23,27 @@ public sealed class SeedExtractorSystem : EntitySystem private void OnInteractUsing(EntityUid uid, SeedExtractorComponent component, InteractUsingEvent args) { - if (!TryComp(uid, out var powerReceiverComponent) || !powerReceiverComponent.Powered) + if (!this.IsPowered(uid, EntityManager)) return; - if (TryComp(args.Used, out ProduceComponent? produce)) + if (!TryComp(args.Used, out ProduceComponent? produce)) return; + if (!_botanySystem.TryGetSeed(produce, out var seed)) + return; + + _popupSystem.PopupCursor(Loc.GetString("seed-extractor-component-interact-message",("name", args.Used)), + Filter.Entities(args.User)); + + QueueDel(args.Used); + + var random = _random.Next(component.MinSeeds, component.MaxSeeds); + var coords = Transform(uid).Coordinates; + + if (random > 1) + seed.Unique = false; + + for (var i = 0; i < random; i++) { - if (!_botanySystem.TryGetSeed(produce, out var seed)) - return; - - _popupSystem.PopupCursor(Loc.GetString("seed-extractor-component-interact-message",("name", args.Used)), - Filter.Entities(args.User)); - - QueueDel(args.Used); - - var random = _random.Next(component.MinSeeds, component.MaxSeeds); - var coords = Transform(uid).Coordinates; - - if (random > 1) - seed.Unique = false; - - for (var i = 0; i < random; i++) - { - _botanySystem.SpawnSeedPacket(seed, coords); - } + _botanySystem.SpawnSeedPacket(seed, coords); } } } diff --git a/Content.Server/Conveyor/ConveyorSystem.cs b/Content.Server/Conveyor/ConveyorSystem.cs index ab009ca9e3..7925c7730d 100644 --- a/Content.Server/Conveyor/ConveyorSystem.cs +++ b/Content.Server/Conveyor/ConveyorSystem.cs @@ -1,6 +1,7 @@ using Content.Server.MachineLinking.Events; using Content.Server.MachineLinking.System; using Content.Server.Power.Components; +using Content.Server.Power.EntitySystems; using Content.Server.Recycling; using Content.Server.Recycling.Components; using Content.Shared.Conveyor; @@ -34,17 +35,9 @@ namespace Content.Server.Conveyor private void UpdateAppearance(ConveyorComponent component) { - if (EntityManager.TryGetComponent(component.Owner, out var appearance)) - { - if (EntityManager.TryGetComponent(component.Owner, out var receiver) && receiver.Powered) - { - appearance.SetData(ConveyorVisuals.State, component.State); - } - else - { - appearance.SetData(ConveyorVisuals.State, ConveyorState.Off); - } - } + if (!EntityManager.TryGetComponent(component.Owner, out var appearance)) return; + var isPowered = this.IsPowered(component.Owner, EntityManager); + appearance.SetData(ConveyorVisuals.State, isPowered ? component.State : ConveyorState.Off); } private void OnSignalReceived(EntityUid uid, ConveyorComponent component, SignalReceivedEvent args) @@ -74,23 +67,9 @@ namespace Content.Server.Conveyor public bool CanRun(ConveyorComponent component) { - if (component.State == ConveyorState.Off) - { - return false; - } - - if (EntityManager.TryGetComponent(component.Owner, out ApcPowerReceiverComponent? receiver) && - !receiver.Powered) - { - return false; - } - - if (EntityManager.HasComponent(component.Owner)) - { - return false; - } - - return true; + return component.State != ConveyorState.Off && + !EntityManager.HasComponent(component.Owner) && + this.IsPowered(component.Owner, EntityManager); } } } diff --git a/Content.Server/Disease/DiseaseDiagnosisSystem.cs b/Content.Server/Disease/DiseaseDiagnosisSystem.cs index 5d76f5297d..2024d3aefe 100644 --- a/Content.Server/Disease/DiseaseDiagnosisSystem.cs +++ b/Content.Server/Disease/DiseaseDiagnosisSystem.cs @@ -10,6 +10,7 @@ using Content.Server.Hands.Components; using Content.Server.Nutrition.EntitySystems; using Content.Server.Paper; using Content.Server.Power.Components; +using Content.Server.Power.EntitySystems; using Robust.Shared.Random; using Robust.Shared.Player; using Robust.Shared.Audio; @@ -139,7 +140,7 @@ namespace Content.Server.Disease if (args.Handled || !args.CanReach) return; - if (HasComp(uid) || TryComp(uid, out var power) && !power.Powered) + if (HasComp(uid) || !this.IsPowered(uid, EntityManager)) return; if (!HasComp(args.User) || HasComp(args.Used)) // Don't want to accidentally breach wrenching or whatever @@ -171,7 +172,7 @@ namespace Content.Server.Disease if (args.Handled || !args.CanReach) return; - if (HasComp(uid) || TryComp(uid, out var power) && !power.Powered) + if (HasComp(uid) || !this.IsPowered(uid, EntityManager)) return; if (!HasComp(args.User) || HasComp(args.Used)) //This check ensures tools don't break without yaml ordering jank @@ -323,8 +324,8 @@ namespace Content.Server.Disease /// private void OnDiagnoserFinished(EntityUid uid, DiseaseDiagnoserComponent component, DiseaseMachineFinishedEvent args) { - var power = Comp(uid); - UpdateAppearance(uid, power.Powered, false); + var isPowered = this.IsPowered(uid, EntityManager); + UpdateAppearance(uid, isPowered, false); // spawn a piece of paper. var printed = EntityManager.SpawnEntity(args.Machine.MachineOutput, Transform(uid).Coordinates); @@ -353,8 +354,7 @@ namespace Content.Server.Disease /// private void OnVaccinatorFinished(EntityUid uid, DiseaseVaccineCreatorComponent component, DiseaseMachineFinishedEvent args) { - var power = Comp(uid); - UpdateAppearance(uid, power.Powered, false); + UpdateAppearance(uid, this.IsPowered(uid, EntityManager), false); // spawn a vaccine var vaxx = EntityManager.SpawnEntity(args.Machine.MachineOutput, Transform(uid).Coordinates); diff --git a/Content.Server/Electrocution/ElectrocutionSystem.cs b/Content.Server/Electrocution/ElectrocutionSystem.cs index 68813515c4..6c0b85661e 100644 --- a/Content.Server/Electrocution/ElectrocutionSystem.cs +++ b/Content.Server/Electrocution/ElectrocutionSystem.cs @@ -183,9 +183,7 @@ namespace Content.Server.Electrocution // Does it use APC power for its electrification check? Check if it's powered, and then // attempt an electrocution if all the checks succeed. - if (electrified.UsesApcPower && - (!TryComp(uid, out ApcPowerReceiverComponent? power) - || !power.Powered)) + if (electrified.UsesApcPower && !this.IsPowered(uid, EntityManager)) { return false; } diff --git a/Content.Server/Kitchen/EntitySystems/ReagentGrinderSystem.cs b/Content.Server/Kitchen/EntitySystems/ReagentGrinderSystem.cs index df75f7a0ba..92aa41bfd5 100644 --- a/Content.Server/Kitchen/EntitySystems/ReagentGrinderSystem.cs +++ b/Content.Server/Kitchen/EntitySystems/ReagentGrinderSystem.cs @@ -3,6 +3,7 @@ using Content.Server.Chemistry.EntitySystems; using Content.Server.Kitchen.Components; using Content.Server.Kitchen.Events; using Content.Server.Power.Components; +using Content.Server.Power.EntitySystems; using Content.Server.Stack; using Content.Server.UserInterface; using Content.Shared.Containers.ItemSlots; @@ -122,7 +123,7 @@ namespace Content.Server.Kitchen.EntitySystems { _itemSlotsSystem.RemoveItemSlot(uid, component.BeakerSlot); } - + private void OnUIMessageReceived(EntityUid uid, ReagentGrinderComponent component, ServerBoundUserInterfaceMessage message) { @@ -134,16 +135,14 @@ namespace Content.Server.Kitchen.EntitySystems switch (message.Message) { case SharedReagentGrinderComponent.ReagentGrinderGrindStartMessage msg: - if (!EntityManager.TryGetComponent(component.Owner, out ApcPowerReceiverComponent? receiver) || - !receiver.Powered) break; + if (!this.IsPowered(component.Owner, EntityManager)) break; ClickSound(component); DoWork(component, attached, SharedReagentGrinderComponent.GrinderProgram.Grind); break; case SharedReagentGrinderComponent.ReagentGrinderJuiceStartMessage msg: - if (!EntityManager.TryGetComponent(component.Owner, out ApcPowerReceiverComponent? receiver2) || - !receiver2.Powered) break; + if (!this.IsPowered(component.Owner, EntityManager)) break; ClickSound(component); DoWork(component, attached, SharedReagentGrinderComponent.GrinderProgram.Juice); @@ -206,7 +205,7 @@ namespace Content.Server.Kitchen.EntitySystems ( comp.Busy, comp.BeakerSlot.HasItem, - EntityManager.TryGetComponent(comp.Owner, out ApcPowerReceiverComponent? receiver) && receiver.Powered, + this.IsPowered(comp.Owner, EntityManager), canJuice, canGrind, comp.Chamber.ContainedEntities.Select(item => item).ToArray(), @@ -224,7 +223,7 @@ namespace Content.Server.Kitchen.EntitySystems SharedReagentGrinderComponent.GrinderProgram program) { //Have power, are we busy, chamber has anything to grind, a beaker for the grounds to go? - if (!EntityManager.TryGetComponent(component.Owner, out ApcPowerReceiverComponent? receiver) || !receiver.Powered || + if (!this.IsPowered(component.Owner, EntityManager) || component.Busy || component.Chamber.ContainedEntities.Count <= 0 || component.BeakerSlot.Item is not EntityUid beakerEntity || component.BeakerSolution == null) diff --git a/Content.Server/Lathe/LatheSystem.cs b/Content.Server/Lathe/LatheSystem.cs index a457a07fc6..dcd7426fcc 100644 --- a/Content.Server/Lathe/LatheSystem.cs +++ b/Content.Server/Lathe/LatheSystem.cs @@ -7,6 +7,7 @@ using Content.Shared.Interaction; using Content.Server.Materials; using Content.Server.Popups; using Content.Server.Power.Components; +using Content.Server.Power.EntitySystems; using Content.Server.Stack; using Content.Server.UserInterface; using Robust.Server.GameObjects; @@ -171,7 +172,7 @@ namespace Content.Server.Lathe return; } - if (TryComp(component.Owner, out var receiver) && !receiver.Powered) + if (!this.IsPowered(component.Owner, EntityManager)) { FinishProducing(recipe, component, false); return; @@ -247,7 +248,7 @@ namespace Content.Server.Lathe /// private void UserInterfaceOnOnReceiveMessage(EntityUid uid, LatheComponent component, ServerBoundUserInterfaceMessage message) { - if (TryComp(uid, out var receiver) && !receiver.Powered) + if (!this.IsPowered(uid, EntityManager)) return; switch (message.Message) diff --git a/Content.Server/Medical/MedicalScannerSystem.cs b/Content.Server/Medical/MedicalScannerSystem.cs index a01c4f36cc..cd8c42dbda 100644 --- a/Content.Server/Medical/MedicalScannerSystem.cs +++ b/Content.Server/Medical/MedicalScannerSystem.cs @@ -4,6 +4,7 @@ using Content.Server.Medical.Components; using Content.Server.Mind.Components; using Content.Server.Popups; using Content.Server.Power.Components; +using Content.Server.Power.EntitySystems; using Content.Server.Preferences.Managers; using Content.Shared.ActionBlocker; using Content.Shared.CharacterAppearance.Components; @@ -57,7 +58,7 @@ namespace Content.Server.Medical private void OnActivated(EntityUid uid, MedicalScannerComponent scannerComponent, ActivateInWorldEvent args) { - if (!IsPowered(scannerComponent)) + if (!this.IsPowered(uid, EntityManager)) return; UpdateUserInterface(uid, scannerComponent); @@ -164,10 +165,8 @@ namespace Content.Server.Medical private void UpdateUserInterface(EntityUid uid, MedicalScannerComponent scannerComponent) { - if (!IsPowered(scannerComponent)) - { + if (!this.IsPowered(uid, EntityManager)) return; - } var newState = GetUserInterfaceState(uid, scannerComponent); scannerComponent.UserInterface?.SetState(newState); @@ -175,7 +174,7 @@ namespace Content.Server.Medical private MedicalScannerStatus GetStatus(MedicalScannerComponent scannerComponent) { - if (IsPowered(scannerComponent)) + if (this.IsPowered(scannerComponent.Owner, EntityManager)) { var body = scannerComponent.BodyContainer.ContainedEntity; if (body == null) @@ -191,15 +190,6 @@ namespace Content.Server.Medical return MedicalScannerStatus.Off; } - public bool IsPowered(MedicalScannerComponent scannerComponent) - { - if (TryComp(scannerComponent.Owner, out var receiver)) - { - return receiver.Powered; - } - return false; - } - public bool IsOccupied(MedicalScannerComponent scannerComponent) { return scannerComponent.BodyContainer.ContainedEntity != null; diff --git a/Content.Server/Power/EntitySystems/ActivatableUIRequiresPowerSystem.cs b/Content.Server/Power/EntitySystems/ActivatableUIRequiresPowerSystem.cs index 003c419d9a..a436c8d517 100644 --- a/Content.Server/Power/EntitySystems/ActivatableUIRequiresPowerSystem.cs +++ b/Content.Server/Power/EntitySystems/ActivatableUIRequiresPowerSystem.cs @@ -21,13 +21,11 @@ namespace Content.Server.Power.EntitySystems private void OnActivate(EntityUid uid, ActivatableUIRequiresPowerComponent component, ActivatableUIOpenAttemptEvent args) { if (args.Cancelled) return; - if (EntityManager.TryGetComponent(uid, out var power) && !power.Powered) - { - if (TryComp(uid, out var wires) && wires.IsPanelOpen) - return; - args.User.PopupMessageCursor(Loc.GetString("base-computer-ui-component-not-powered", ("machine", uid))); - args.Cancel(); - } + if (this.IsPowered(uid, EntityManager)) return; + if (TryComp(uid, out var wires) && wires.IsPanelOpen) + return; + args.User.PopupMessageCursor(Loc.GetString("base-computer-ui-component-not-powered", ("machine", uid))); + args.Cancel(); } private void OnPowerChanged(EntityUid uid, ActivatableUIRequiresPowerComponent component, PowerChangedEvent args) diff --git a/Content.Server/Power/EntitySystems/StaticPowerSystem.cs b/Content.Server/Power/EntitySystems/StaticPowerSystem.cs new file mode 100644 index 0000000000..74b94113d1 --- /dev/null +++ b/Content.Server/Power/EntitySystems/StaticPowerSystem.cs @@ -0,0 +1,13 @@ +using Content.Server.Power.Components; + +namespace Content.Server.Power.EntitySystems; + +public static class StaticPowerSystem +{ + // Using this makes the call shorter. + // ReSharper disable once UnusedParameter.Global + public static bool IsPowered(this EntitySystem system, EntityUid uid, IEntityManager entManager, ApcPowerReceiverComponent? receiver = null) + { + return entManager.TryGetComponent(uid, out receiver) && receiver.Powered; + } +} diff --git a/Content.Server/Recycling/RecyclerSystem.cs b/Content.Server/Recycling/RecyclerSystem.cs index 1dbece4cad..c77f5111a1 100644 --- a/Content.Server/Recycling/RecyclerSystem.cs +++ b/Content.Server/Recycling/RecyclerSystem.cs @@ -3,6 +3,7 @@ using Content.Server.GameTicking; using Content.Server.Players; using Content.Server.Popups; using Content.Server.Power.Components; +using Content.Server.Power.EntitySystems; using Content.Server.Recycling.Components; using Content.Shared.Audio; using Content.Shared.Body.Components; @@ -120,9 +121,8 @@ namespace Content.Server.Recycling private bool CanGib(RecyclerComponent component, EntityUid entity) { - // TODO: Power needs a helper for this jeez return HasComp(entity) && !component.Safe && - TryComp(component.Owner, out var receiver) && receiver.Powered; + this.IsPowered(component.Owner, EntityManager); } public void Bloodstain(RecyclerComponent component) diff --git a/Content.Server/Remotes/DoorRemoteSystem.cs b/Content.Server/Remotes/DoorRemoteSystem.cs index ac41f19370..95b292ddae 100644 --- a/Content.Server/Remotes/DoorRemoteSystem.cs +++ b/Content.Server/Remotes/DoorRemoteSystem.cs @@ -15,7 +15,6 @@ namespace Content.Server.Remotes public sealed class DoorRemoteSystem : EntitySystem { [Dependency] private readonly SharedPopupSystem _popupSystem = default!; - [Dependency] private readonly SharedDoorSystem _sharedDoorSystem = default!; [Dependency] private readonly DoorSystem _doorSystem = default!; [Dependency] private readonly SharedInteractionSystem _interactionSystem = default!; [Dependency] private readonly SharedAirlockSystem _sharedAirlockSystem = default!; @@ -49,21 +48,23 @@ namespace Content.Server.Remotes private void OnAfterInteract(EntityUid uid, DoorRemoteComponent component, AfterInteractEvent args) { - if (args.Handled + if (!args.CanReach || + args.Handled || args.Target == null || !TryComp(args.Target, out var doorComponent) // If it isn't a door we don't use it || !HasComp(args.Target) // Remotes do not work on doors without access requirements || !TryComp(args.Target, out var airlockComponent) // Remotes only work on airlocks + // TODO: Why the fuck is this -1f || !_interactionSystem.InRangeUnobstructed(args.User, doorComponent.Owner, -1f, CollisionGroup.Opaque)) { return; } args.Handled = true; - + if (component.Mode == DoorRemoteComponent.OperatingMode.OpenClose) { - _sharedDoorSystem.TryToggleDoor(doorComponent.Owner, user: args.Used); + _doorSystem.TryToggleDoor(doorComponent.Owner, user: args.Used); } if (component.Mode == DoorRemoteComponent.OperatingMode.ToggleBolts @@ -77,11 +78,11 @@ namespace Content.Server.Remotes { if (doorComponent.State != DoorState.Open) { - _sharedDoorSystem.Deny(airlockComponent.Owner, user: args.User); + _doorSystem.Deny(airlockComponent.Owner, user: args.User); } else if (doorComponent.DenySound != null) { - SoundSystem.Play(Filter.Pvs(args.Target.Value), doorComponent.DenySound.GetSound(), args.Target.Value); + SoundSystem.Play(Filter.Pvs(args.Target.Value, entityManager: EntityManager), doorComponent.DenySound.GetSound(), args.Target.Value); } } } diff --git a/Content.Server/Shuttles/EntitySystems/ShuttleConsoleSystem.cs b/Content.Server/Shuttles/EntitySystems/ShuttleConsoleSystem.cs index 3012c2a133..b6c6ab55b1 100644 --- a/Content.Server/Shuttles/EntitySystems/ShuttleConsoleSystem.cs +++ b/Content.Server/Shuttles/EntitySystems/ShuttleConsoleSystem.cs @@ -1,5 +1,6 @@ using Content.Server.Popups; using Content.Server.Power.Components; +using Content.Server.Power.EntitySystems; using Content.Server.Shuttles.Components; using Content.Shared.ActionBlocker; using Content.Shared.Alert; @@ -51,7 +52,7 @@ namespace Content.Server.Shuttles.EntitySystems { Text = Loc.GetString("shuttle-mode-toggle"), Act = () => ToggleShuttleMode(args.User, component, shuttle), - Disabled = !xform.Anchored || EntityManager.TryGetComponent(uid, out ApcPowerReceiverComponent? receiver) && !receiver.Powered, + Disabled = !xform.Anchored || !this.IsPowered(uid, EntityManager), }; args.Verbs.Add(verb); @@ -60,7 +61,7 @@ namespace Content.Server.Shuttles.EntitySystems private void ToggleShuttleMode(EntityUid user, ShuttleConsoleComponent consoleComponent, ShuttleComponent shuttleComponent, TransformComponent? consoleXform = null) { // Re-validate - if (EntityManager.TryGetComponent(consoleComponent.Owner, out ApcPowerReceiverComponent? receiver) && !receiver.Powered) return; + if (!this.IsPowered(consoleComponent.Owner, EntityManager)) return; if (!Resolve(consoleComponent.Owner, ref consoleXform)) return; diff --git a/Content.Server/Shuttles/EntitySystems/ThrusterSystem.cs b/Content.Server/Shuttles/EntitySystems/ThrusterSystem.cs index 39b7f9000e..8979877f44 100644 --- a/Content.Server/Shuttles/EntitySystems/ThrusterSystem.cs +++ b/Content.Server/Shuttles/EntitySystems/ThrusterSystem.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Runtime.CompilerServices; using Content.Server.Audio; using Content.Server.Power.Components; +using Content.Server.Power.EntitySystems; using Content.Server.Shuttles.Components; using Content.Shared.Damage; using Content.Shared.Examine; @@ -367,8 +368,7 @@ namespace Content.Server.Shuttles.EntitySystems var xform = Transform(uid); - if (!xform.Anchored || - EntityManager.TryGetComponent(uid, out ApcPowerReceiverComponent? receiver) && !receiver.Powered) + if (!xform.Anchored ||!this.IsPowered(uid, EntityManager)) { return false; } diff --git a/Content.Server/VendingMachines/VendingMachineEjectItemWireAction.cs b/Content.Server/VendingMachines/VendingMachineEjectItemWireAction.cs index c6bf752267..b0c7e8cd51 100644 --- a/Content.Server/VendingMachines/VendingMachineEjectItemWireAction.cs +++ b/Content.Server/VendingMachines/VendingMachineEjectItemWireAction.cs @@ -1,4 +1,3 @@ -using Content.Server.VendingMachines.Systems; using Content.Server.Wires; using Content.Shared.VendingMachines; using Content.Shared.Wires; diff --git a/Content.Server/VendingMachines/VendingMachineSystem.cs b/Content.Server/VendingMachines/VendingMachineSystem.cs index b2c404533a..e974c0eb50 100644 --- a/Content.Server/VendingMachines/VendingMachineSystem.cs +++ b/Content.Server/VendingMachines/VendingMachineSystem.cs @@ -1,20 +1,21 @@ -using Robust.Shared.Audio; -using Robust.Shared.Player; using System.Linq; using Content.Server.Popups; using Content.Server.Power.Components; +using Content.Server.Power.EntitySystems; using Content.Shared.Access.Components; using Content.Shared.Access.Systems; -using Content.Shared.VendingMachines; -using Robust.Server.GameObjects; -using Robust.Shared.Prototypes; -using Robust.Shared.Random; using Content.Shared.Destructible; using Content.Shared.Emag.Systems; -using static Content.Shared.VendingMachines.SharedVendingMachineComponent; using Content.Shared.Throwing; +using Content.Shared.VendingMachines; +using Robust.Server.GameObjects; +using Robust.Shared.Audio; +using Robust.Shared.Player; +using Robust.Shared.Prototypes; +using Robust.Shared.Random; +using static Content.Shared.VendingMachines.SharedVendingMachineComponent; -namespace Content.Server.VendingMachines.Systems +namespace Content.Server.VendingMachines { public sealed class VendingMachineSystem : EntitySystem { @@ -49,7 +50,7 @@ namespace Content.Server.VendingMachines.Systems private void OnInventoryRequestMessage(EntityUid uid, VendingMachineComponent component, InventorySyncRequestMessage args) { - if (!IsPowered(uid, component)) + if (!this.IsPowered(uid, EntityManager)) return; var inventory = new List(component.Inventory); @@ -62,7 +63,7 @@ namespace Content.Server.VendingMachines.Systems private void OnInventoryEjectMessage(EntityUid uid, VendingMachineComponent component, VendingMachineEjectMessage args) { - if (!IsPowered(uid, component)) + if (!this.IsPowered(uid, EntityManager)) return; if (args.Session.AttachedEntity is not { Valid: true } entity || Deleted(entity)) @@ -91,18 +92,6 @@ namespace Content.Server.VendingMachines.Systems args.Handled = true; } - public bool IsPowered(EntityUid uid, VendingMachineComponent? vendComponent = null) - { - if (!Resolve(uid, ref vendComponent)) - return false; - - if (!TryComp(vendComponent.Owner, out var receiver)) - { - return false; - } - return receiver.Powered; - } - public void InitializeFromPrototype(EntityUid uid, VendingMachineComponent? vendComponent = null) { if (!Resolve(uid, ref vendComponent)) @@ -201,7 +190,7 @@ namespace Content.Server.VendingMachines.Systems if (!Resolve(uid, ref vendComponent)) return; - if (vendComponent.Ejecting || vendComponent.Broken || !IsPowered(uid, vendComponent)) + if (vendComponent.Ejecting || vendComponent.Broken || !this.IsPowered(uid, EntityManager)) { return; } @@ -276,7 +265,7 @@ namespace Content.Server.VendingMachines.Systems { finalState = VendingMachineVisualState.Eject; } - else if (!IsPowered(uid, vendComponent)) + else if (!this.IsPowered(uid, EntityManager)) { finalState = VendingMachineVisualState.Off; } diff --git a/Content.Server/Wires/BaseWireAction.cs b/Content.Server/Wires/BaseWireAction.cs index a58afd0ad2..c41c19fb09 100644 --- a/Content.Server/Wires/BaseWireAction.cs +++ b/Content.Server/Wires/BaseWireAction.cs @@ -1,4 +1,5 @@ using Content.Server.Power.Components; +using Content.Server.Power.EntitySystems; using Content.Shared.Wires; namespace Content.Server.Wires; @@ -17,7 +18,7 @@ public abstract class BaseWireAction : IWireAction { EntityManager = IoCManager.Resolve(); - WiresSystem = EntitySystem.Get(); + WiresSystem = EntityManager.EntitySysManager.GetEntitySystem(); } public virtual bool AddWire(Wire wire, int count) => count == 1; @@ -38,14 +39,8 @@ public abstract class BaseWireAction : IWireAction /// Utility function to check if this given entity is powered. /// /// true if powered, false otherwise - public bool IsPowered(EntityUid uid) + protected bool IsPowered(EntityUid uid) { - if (!EntityManager.TryGetComponent(uid, out var power) - || power.PowerDisabled) // there's some kind of race condition here? - { - return false; - } - - return power.Powered; + return WiresSystem.IsPowered(uid, EntityManager); } }