From 9e1607722dc77b497282be9bbe1ecb2b53a9162d Mon Sep 17 00:00:00 2001 From: Paul Ritter Date: Sat, 15 Jan 2022 03:26:37 +0100 Subject: [PATCH] removes componentdependencies (#6160) --- .../Cuffs/Components/CuffableComponent.cs | 17 ++--- .../Components/BlockGameArcadeComponent.cs | 4 +- .../Components/SpaceVillainArcadeComponent.cs | 16 ++--- .../Atmos/Components/GasTankComponent.cs | 6 +- .../Monitor/Components/AirAlarmComponent.cs | 42 ++++++----- .../Components/AtmosMonitorComponent.cs | 6 -- .../Monitor/Components/FireAlarmComponent.cs | 34 +++++---- .../Atmos/Monitor/Systems/AirAlarmSystem.cs | 2 +- .../Monitor/Systems/AtmosMonitoringSystem.cs | 55 +++++++-------- .../Botany/Components/PlantHolderComponent.cs | 29 ++++---- .../Components/SeedExtractorComponent.cs | 4 +- .../Buckle/Components/BuckleComponent.cs | 18 ++--- .../Buckle/Components/StrapComponent.cs | 5 +- .../Climbing/Components/ClimbingComponent.cs | 5 +- .../Clothing/Components/MagbootsComponent.cs | 14 ++-- .../Doors/Components/AirlockComponent.cs | 69 ++++++++----------- .../Doors/Components/FirelockComponent.cs | 7 +- .../Doors/Components/ServerDoorComponent.cs | 9 +-- Content.Server/Doors/Systems/AirlockSystem.cs | 13 ++-- .../Doors/Systems/FirelockSystem.cs | 8 +-- .../Light/Components/MatchstickComponent.cs | 6 -- .../Light/EntitySystems/MatchstickSystem.cs | 5 +- .../CrematoriumEntityStorageComponent.cs | 13 ++-- .../MorgueEntityStorageComponent.cs | 41 ++++++----- .../Power/Components/ApcComponent.cs | 4 +- .../Components/ExaminableBatteryComponent.cs | 10 +-- .../ContainmentFieldGeneratorComponent.cs | 11 ++- .../Components/EmitterComponent.cs | 4 -- .../Components/RadiationCollectorComponent.cs | 7 +- .../EntitySystems/EmitterSystem.cs | 12 ++-- .../Climbing/SharedClimbingComponent.cs | 19 ++--- Content.Shared/Doors/SharedDoorComponent.cs | 21 +++--- .../SharedPlayerInputMoverComponent.cs | 15 ++-- 33 files changed, 257 insertions(+), 274 deletions(-) diff --git a/Content.Client/Cuffs/Components/CuffableComponent.cs b/Content.Client/Cuffs/Components/CuffableComponent.cs index 9aca508033..3fa3866241 100644 --- a/Content.Client/Cuffs/Components/CuffableComponent.cs +++ b/Content.Client/Cuffs/Components/CuffableComponent.cs @@ -3,6 +3,7 @@ using Content.Shared.Cuffs.Components; using Robust.Client.GameObjects; using Robust.Client.Graphics; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -15,7 +16,7 @@ namespace Content.Client.Cuffs.Components [ViewVariables] private string? _currentRSI; - [ViewVariables] [ComponentDependency] private readonly SpriteComponent? _spriteComponent = null; + [Dependency] private readonly IEntityManager _entityManager = default!; public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) { @@ -26,10 +27,10 @@ namespace Content.Client.Cuffs.Components CanStillInteract = cuffState.CanStillInteract; - if (_spriteComponent != null) + if (_entityManager.TryGetComponent(Owner, out var spriteComponent)) { - _spriteComponent.LayerSetVisible(HumanoidVisualLayers.Handcuffs, cuffState.NumHandsCuffed > 0); - _spriteComponent.LayerSetColor(HumanoidVisualLayers.Handcuffs, cuffState.Color); + spriteComponent.LayerSetVisible(HumanoidVisualLayers.Handcuffs, cuffState.NumHandsCuffed > 0); + spriteComponent.LayerSetColor(HumanoidVisualLayers.Handcuffs, cuffState.Color); if (cuffState.NumHandsCuffed > 0) { @@ -39,12 +40,12 @@ namespace Content.Client.Cuffs.Components if (_currentRSI != null) { - _spriteComponent.LayerSetState(HumanoidVisualLayers.Handcuffs, new RSI.StateId(cuffState.IconState), new ResourcePath(_currentRSI)); + spriteComponent.LayerSetState(HumanoidVisualLayers.Handcuffs, new RSI.StateId(cuffState.IconState), new ResourcePath(_currentRSI)); } } else { - _spriteComponent.LayerSetState(HumanoidVisualLayers.Handcuffs, new RSI.StateId(cuffState.IconState)); // TODO: safety check to see if RSI contains the state? + spriteComponent.LayerSetState(HumanoidVisualLayers.Handcuffs, new RSI.StateId(cuffState.IconState)); // TODO: safety check to see if RSI contains the state? } } } @@ -53,8 +54,8 @@ namespace Content.Client.Cuffs.Components protected override void OnRemove() { base.OnRemove(); - - _spriteComponent?.LayerSetVisible(HumanoidVisualLayers.Handcuffs, false); + if (_entityManager.TryGetComponent(Owner, out var spriteComponent)) + spriteComponent.LayerSetVisible(HumanoidVisualLayers.Handcuffs, false); } } } diff --git a/Content.Server/Arcade/Components/BlockGameArcadeComponent.cs b/Content.Server/Arcade/Components/BlockGameArcadeComponent.cs index 24139d624b..68b8496f9b 100644 --- a/Content.Server/Arcade/Components/BlockGameArcadeComponent.cs +++ b/Content.Server/Arcade/Components/BlockGameArcadeComponent.cs @@ -23,9 +23,9 @@ namespace Content.Server.Arcade.Components public override string Name => "BlockGameArcade"; - [ComponentDependency] private readonly ApcPowerReceiverComponent? _powerReceiverComponent = default!; + [Dependency] private readonly IEntityManager _entityManager = default!; - private bool Powered => _powerReceiverComponent?.Powered ?? false; + private bool Powered => _entityManager.TryGetComponent(Owner, out var powerReceiverComponent) && powerReceiverComponent.Powered; private BoundUserInterface? UserInterface => Owner.GetUIOrNull(BlockGameUiKey.Key); private BlockGame? _game; diff --git a/Content.Server/Arcade/Components/SpaceVillainArcadeComponent.cs b/Content.Server/Arcade/Components/SpaceVillainArcadeComponent.cs index aa6c39d1bb..ab2d174d3c 100644 --- a/Content.Server/Arcade/Components/SpaceVillainArcadeComponent.cs +++ b/Content.Server/Arcade/Components/SpaceVillainArcadeComponent.cs @@ -30,10 +30,8 @@ namespace Content.Server.Arcade.Components { [Dependency] private readonly IRobustRandom _random = null!; - [ComponentDependency] private readonly ApcPowerReceiverComponent? _powerReceiverComponent = default!; - [ComponentDependency] private readonly WiresComponent? _wiresComponent = default!; - - private bool Powered => _powerReceiverComponent != null && _powerReceiverComponent.Powered; + [Dependency] private readonly IEntityManager _entityManager = default!; + private bool Powered => _entityManager.TryGetComponent(Owner, out var powerReceiverComponent) && powerReceiverComponent.Powered; [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(SpaceVillainArcadeUiKey.Key); [ViewVariables] private bool _overflowFlag; @@ -84,9 +82,9 @@ namespace Content.Server.Arcade.Components _game ??= new SpaceVillainGame(this); - if (_wiresComponent?.IsPanelOpen == true) + if (_entityManager.TryGetComponent(Owner, out var wiresComponent) && wiresComponent.IsPanelOpen) { - _wiresComponent.OpenInterface(actor.PlayerSession); + wiresComponent.OpenInterface(actor.PlayerSession); } else { @@ -205,13 +203,15 @@ namespace Content.Server.Arcade.Components public void IndicatorUpdate() { - _wiresComponent?.SetStatus(Indicators.HealthManager, + if (!_entityManager.TryGetComponent(Owner, out var wiresComponent)) return; + + wiresComponent.SetStatus(Indicators.HealthManager, new SharedWiresComponent.StatusLightData(Color.Purple, _playerInvincibilityFlag || _enemyInvincibilityFlag ? SharedWiresComponent.StatusLightState.BlinkingSlow : SharedWiresComponent.StatusLightState.On, "MNGR")); - _wiresComponent?.SetStatus(Indicators.HealthLimiter, + wiresComponent.SetStatus(Indicators.HealthLimiter, new SharedWiresComponent.StatusLightData(Color.Red, _overflowFlag ? SharedWiresComponent.StatusLightState.BlinkingSlow diff --git a/Content.Server/Atmos/Components/GasTankComponent.cs b/Content.Server/Atmos/Components/GasTankComponent.cs index 96834d48c3..b9dd51bf8c 100644 --- a/Content.Server/Atmos/Components/GasTankComponent.cs +++ b/Content.Server/Atmos/Components/GasTankComponent.cs @@ -43,7 +43,7 @@ namespace Content.Server.Atmos.Components private int _integrity = 3; - [ComponentDependency] private readonly ItemActionsComponent? _itemActions = null; + [Dependency] private readonly IEntityManager _entityManager = default!; [ViewVariables] private BoundUserInterface? _userInterface; @@ -190,8 +190,8 @@ namespace Content.Server.Atmos.Components CanConnectInternals = IsFunctional && internals != null }); - if (internals == null) return; - _itemActions?.GrantOrUpdate(ItemActionType.ToggleInternals, IsFunctional, IsConnected); + if (internals == null || !_entityManager.TryGetComponent(Owner, out var itemActions)) return; + itemActions.GrantOrUpdate(ItemActionType.ToggleInternals, IsFunctional, IsConnected); } private void UserInterfaceOnOnReceiveMessage(ServerBoundUserInterfaceMessage message) diff --git a/Content.Server/Atmos/Monitor/Components/AirAlarmComponent.cs b/Content.Server/Atmos/Monitor/Components/AirAlarmComponent.cs index 6b49a6082e..c0c48337f2 100644 --- a/Content.Server/Atmos/Monitor/Components/AirAlarmComponent.cs +++ b/Content.Server/Atmos/Monitor/Components/AirAlarmComponent.cs @@ -8,6 +8,7 @@ using Content.Server.VendingMachines; // TODO: Move this out of vending machines using Content.Server.WireHacking; using Content.Shared.Atmos.Monitor.Components; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; using Robust.Shared.Maths; using Robust.Shared.Network; using Robust.Shared.ViewVariables; @@ -19,10 +20,7 @@ namespace Content.Server.Atmos.Monitor.Components [RegisterComponent] public class AirAlarmComponent : Component, IWires { - [ComponentDependency] public readonly ApcPowerReceiverComponent? DeviceRecvComponent = default!; - [ComponentDependency] public readonly AtmosMonitorComponent? AtmosMonitorComponent = default!; - [ComponentDependency] public readonly DeviceNetworkComponent? DeviceNetComponent = default!; - [ComponentDependency] public readonly WiresComponent? WiresComponent = null; + [Dependency] private readonly IEntityManager _entMan = default!; private AirAlarmSystem? _airAlarmSystem; @@ -79,7 +77,7 @@ namespace Content.Server.Atmos.Monitor.Components if (_airAlarmSystem == null) _airAlarmSystem = EntitySystem.Get(); - if (WiresComponent == null) return; + if (!_entMan.TryGetComponent(Owner, out var wires)) return; var pwrLightState = (PowerPulsed, PowerCut) switch { (true, false) => StatusLightState.BlinkingFast, @@ -91,7 +89,7 @@ namespace Content.Server.Atmos.Monitor.Components var accessLight = new StatusLightData( Color.Green, - WiresComponent.IsWireCut(Wires.Access) ? StatusLightState.Off : StatusLightState.On, + wires.IsWireCut(Wires.Access) ? StatusLightState.Off : StatusLightState.On, "ACC" ); @@ -103,17 +101,17 @@ namespace Content.Server.Atmos.Monitor.Components var syncLightState = StatusLightState.BlinkingSlow; - if (AtmosMonitorComponent != null && !AtmosMonitorComponent.NetEnabled) + if (_entMan.TryGetComponent(Owner, out var atmosMonitorComponent) && !atmosMonitorComponent.NetEnabled) syncLightState = StatusLightState.Off; else if (DeviceData.Count != 0) syncLightState = StatusLightState.On; var syncLight = new StatusLightData(Color.Orange, syncLightState, "NET"); - WiresComponent.SetStatus(AirAlarmWireStatus.Power, powerLight); - WiresComponent.SetStatus(AirAlarmWireStatus.Access, accessLight); - WiresComponent.SetStatus(AirAlarmWireStatus.Panic, panicLight); - WiresComponent.SetStatus(AirAlarmWireStatus.DeviceSync, syncLight); + wires.SetStatus(AirAlarmWireStatus.Power, powerLight); + wires.SetStatus(AirAlarmWireStatus.Access, accessLight); + wires.SetStatus(AirAlarmWireStatus.Panic, panicLight); + wires.SetStatus(AirAlarmWireStatus.DeviceSync, syncLight); } private bool _powerCut; @@ -140,14 +138,14 @@ namespace Content.Server.Atmos.Monitor.Components private void SetPower() { - if (DeviceRecvComponent != null - && WiresComponent != null) - DeviceRecvComponent.PowerDisabled = PowerPulsed || PowerCut; + if (_entMan.TryGetComponent(Owner, out var receiverComponent) + && _entMan.HasComponent(Owner)) + receiverComponent.PowerDisabled = PowerPulsed || PowerCut; } public void WiresUpdate(WiresUpdateEventArgs args) { - if (DeviceNetComponent == null) return; + if (!_entMan.TryGetComponent(Owner, out var deviceNetworkComponent)) return; if (_airAlarmSystem == null) _airAlarmSystem = EntitySystem.Get(); @@ -167,7 +165,7 @@ namespace Content.Server.Atmos.Monitor.Components break; case Wires.Panic: if (CurrentMode != AirAlarmMode.Panic) - _airAlarmSystem.SetMode(Owner, DeviceNetComponent.Address, AirAlarmMode.Panic, true, false); + _airAlarmSystem.SetMode(Owner, deviceNetworkComponent.Address, AirAlarmMode.Panic, true, false); break; case Wires.DeviceSync: _airAlarmSystem.SyncAllDevices(Owner); @@ -184,14 +182,14 @@ namespace Content.Server.Atmos.Monitor.Components break; case Wires.Panic: if (CurrentMode == AirAlarmMode.Panic) - _airAlarmSystem.SetMode(Owner, DeviceNetComponent.Address, AirAlarmMode.Filtering, true, false); + _airAlarmSystem.SetMode(Owner, deviceNetworkComponent.Address, AirAlarmMode.Filtering, true, false); break; case Wires.Access: FullAccess = false; break; case Wires.DeviceSync: - if (AtmosMonitorComponent != null) - AtmosMonitorComponent.NetEnabled = true; + if (_entMan.TryGetComponent(Owner, out var atmosMonitorComponent)) + atmosMonitorComponent.NetEnabled = true; break; } @@ -201,10 +199,10 @@ namespace Content.Server.Atmos.Monitor.Components { case Wires.DeviceSync: DeviceData.Clear(); - if (AtmosMonitorComponent != null) + if (_entMan.TryGetComponent(Owner, out var atmosMonitorComponent)) { - AtmosMonitorComponent.NetworkAlarmStates.Clear(); - AtmosMonitorComponent.NetEnabled = false; + atmosMonitorComponent.NetworkAlarmStates.Clear(); + atmosMonitorComponent.NetEnabled = false; } break; diff --git a/Content.Server/Atmos/Monitor/Components/AtmosMonitorComponent.cs b/Content.Server/Atmos/Monitor/Components/AtmosMonitorComponent.cs index 3b7d31f32b..060ae31dc5 100644 --- a/Content.Server/Atmos/Monitor/Components/AtmosMonitorComponent.cs +++ b/Content.Server/Atmos/Monitor/Components/AtmosMonitorComponent.cs @@ -16,12 +16,6 @@ namespace Content.Server.Atmos.Monitor.Components { public override string Name => "AtmosMonitor"; - // Requires power. No logic related to this will be performed here, however, - // save for ensuring that the data is valid upon set. - // This is how the system discovers entities that are alarmable. - [ComponentDependency] public readonly ApcPowerReceiverComponent? PowerRecvComponent = default!; - [ComponentDependency] public readonly AtmosDeviceComponent? AtmosDeviceComponent = default!; - // Whether this monitor can send alarms, // or recieve atmos command events. // diff --git a/Content.Server/Atmos/Monitor/Components/FireAlarmComponent.cs b/Content.Server/Atmos/Monitor/Components/FireAlarmComponent.cs index 4f27139bfc..89088cba5c 100644 --- a/Content.Server/Atmos/Monitor/Components/FireAlarmComponent.cs +++ b/Content.Server/Atmos/Monitor/Components/FireAlarmComponent.cs @@ -9,6 +9,7 @@ using Content.Shared.Atmos.Monitor; using Content.Shared.Atmos.Monitor.Components; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Maths; using static Content.Shared.Wires.SharedWiresComponent; @@ -20,9 +21,7 @@ namespace Content.Server.Atmos.Monitor.Components [RegisterComponent] public class FireAlarmComponent : Component, IWires { - [ComponentDependency] public readonly ApcPowerReceiverComponent? DeviceRecvComponent = default!; - [ComponentDependency] public readonly AtmosMonitorComponent? AtmosMonitorComponent = default!; - [ComponentDependency] public readonly WiresComponent? WiresComponent = null; + [Dependency] private readonly IEntityManager _entMan = default!; private AtmosMonitorSystem? _atmosMonitorSystem; @@ -69,9 +68,8 @@ namespace Content.Server.Atmos.Monitor.Components private void SetPower() { - if (DeviceRecvComponent != null - && WiresComponent != null) - DeviceRecvComponent.PowerDisabled = PowerPulsed || PowerCut; + if (_entMan.TryGetComponent(Owner, out var receiverComponent) && _entMan.HasComponent(Owner)) + receiverComponent.PowerDisabled = PowerPulsed || PowerCut; } @@ -87,7 +85,7 @@ namespace Content.Server.Atmos.Monitor.Components public void UpdateWires() { - if (WiresComponent == null) return; + if (!_entMan.TryGetComponent(Owner, out var wiresComponent)) return; var powerLight = new StatusLightData(Color.Yellow, StatusLightState.On, "POWR"); @@ -98,14 +96,14 @@ namespace Content.Server.Atmos.Monitor.Components var syncLight = new StatusLightData(Color.Orange, StatusLightState.On, "NET"); - if (AtmosMonitorComponent != null) - if (!AtmosMonitorComponent.NetEnabled) + if (_entMan.TryGetComponent(Owner, out var atmosMonitorComponent)) + if (!atmosMonitorComponent.NetEnabled) syncLight = new StatusLightData(Color.Orange, StatusLightState.Off, "NET"); - else if (AtmosMonitorComponent.HighestAlarmInNetwork == AtmosMonitorAlarmType.Danger) + else if (atmosMonitorComponent.HighestAlarmInNetwork == AtmosMonitorAlarmType.Danger) syncLight = new StatusLightData(Color.Orange, StatusLightState.BlinkingFast, "NET"); - WiresComponent.SetStatus(FireAlarmWireStatus.Power, powerLight); - WiresComponent.SetStatus(FireAlarmWireStatus.Alarm, syncLight); + wiresComponent.SetStatus(FireAlarmWireStatus.Power, powerLight); + wiresComponent.SetStatus(FireAlarmWireStatus.Alarm, syncLight); } public void WiresUpdate(WiresUpdateEventArgs args) @@ -127,8 +125,8 @@ namespace Content.Server.Atmos.Monitor.Components _powerPulsedCancel.Token); break; case Wires.Alarm: - if (AtmosMonitorComponent != null) - _atmosMonitorSystem.Alert(Owner, AtmosMonitorAlarmType.Danger); + if (_entMan.TryGetComponent(Owner, out var atmosMonitorComponent)) + _atmosMonitorSystem.Alert(Owner, AtmosMonitorAlarmType.Danger, monitor: atmosMonitorComponent); break; } @@ -142,8 +140,8 @@ namespace Content.Server.Atmos.Monitor.Components PowerCut = false; break; case Wires.Alarm: - if (AtmosMonitorComponent != null) - AtmosMonitorComponent.NetEnabled = true; + if (_entMan.TryGetComponent(Owner, out var atmosMonitorComponent)) + atmosMonitorComponent.NetEnabled = true; break; } @@ -155,8 +153,8 @@ namespace Content.Server.Atmos.Monitor.Components PowerCut = true; break; case Wires.Alarm: - if (AtmosMonitorComponent != null) - AtmosMonitorComponent.NetEnabled = false; + if (_entMan.TryGetComponent(Owner, out var atmosMonitorComponent)) + atmosMonitorComponent.NetEnabled = false; break; } diff --git a/Content.Server/Atmos/Monitor/Systems/AirAlarmSystem.cs b/Content.Server/Atmos/Monitor/Systems/AirAlarmSystem.cs index 73010e26d7..e50a2ff90d 100644 --- a/Content.Server/Atmos/Monitor/Systems/AirAlarmSystem.cs +++ b/Content.Server/Atmos/Monitor/Systems/AirAlarmSystem.cs @@ -392,7 +392,7 @@ namespace Content.Server.Atmos.Monitor.Systems // _airAlarmDataSystem.UpdateDeviceData(uid, args.SenderAddress, data); // _uiSystem.TrySendUiMessage(uid, SharedAirAlarmInterfaceKey.Key, new AirAlarmUpdateDeviceDataMessage(args.SenderAddress, data)); - if (controller.WiresComponent != null) controller.UpdateWires(); + if (HasComp(uid)) controller.UpdateWires(); if (!controller.DeviceData.TryAdd(args.SenderAddress, data)) controller.DeviceData[args.SenderAddress] = data; diff --git a/Content.Server/Atmos/Monitor/Systems/AtmosMonitoringSystem.cs b/Content.Server/Atmos/Monitor/Systems/AtmosMonitoringSystem.cs index 1b846fda43..d1ffd1047c 100644 --- a/Content.Server/Atmos/Monitor/Systems/AtmosMonitoringSystem.cs +++ b/Content.Server/Atmos/Monitor/Systems/AtmosMonitoringSystem.cs @@ -98,10 +98,10 @@ namespace Content.Server.Atmos.Monitor.Systems private void OnAtmosMonitorStartup(EntityUid uid, AtmosMonitorComponent component, ComponentStartup args) { - if (component.PowerRecvComponent == null - && component.AtmosDeviceComponent != null) + if (!HasComp(uid) + && TryComp(uid, out var atmosDeviceComponent)) { - _atmosDeviceSystem.LeaveAtmosphere(component.AtmosDeviceComponent); + _atmosDeviceSystem.LeaveAtmosphere(atmosDeviceComponent); return; } @@ -204,28 +204,29 @@ namespace Content.Server.Atmos.Monitor.Systems private void OnPowerChangedEvent(EntityUid uid, AtmosMonitorComponent component, PowerChangedEvent args) { - if (!args.Powered) + if (TryComp(uid, out var atmosDeviceComponent)) { - if (component.AtmosDeviceComponent != null - && component.AtmosDeviceComponent.JoinedGrid != null) + if (!args.Powered) { - _atmosDeviceSystem.LeaveAtmosphere(component.AtmosDeviceComponent); - component.TileGas = null; - } + if (atmosDeviceComponent.JoinedGrid != null) + { + _atmosDeviceSystem.LeaveAtmosphere(atmosDeviceComponent); + component.TileGas = null; + } - // clear memory when power cycled - component.LastAlarmState = AtmosMonitorAlarmType.Normal; - component.NetworkAlarmStates.Clear(); - } - else if (args.Powered) - { - if (component.AtmosDeviceComponent != null - && component.AtmosDeviceComponent.JoinedGrid == null) + // clear memory when power cycled + component.LastAlarmState = AtmosMonitorAlarmType.Normal; + component.NetworkAlarmStates.Clear(); + } + else if (args.Powered) { - _atmosDeviceSystem.JoinAtmosphere(component.AtmosDeviceComponent); - var coords = Transform(component.Owner).Coordinates; - var air = _atmosphereSystem.GetTileMixture(coords); - component.TileGas = air; + if (atmosDeviceComponent.JoinedGrid == null) + { + _atmosDeviceSystem.JoinAtmosphere(atmosDeviceComponent); + var coords = Transform(component.Owner).Coordinates; + var air = _atmosphereSystem.GetTileMixture(coords); + component.TileGas = air; + } } } @@ -238,8 +239,8 @@ namespace Content.Server.Atmos.Monitor.Systems private void OnFireEvent(EntityUid uid, AtmosMonitorComponent component, TileFireEvent args) { - if (component.PowerRecvComponent == null - || !component.PowerRecvComponent.Powered) + if (!TryComp(uid, out var powerReceiverComponent) + || !powerReceiverComponent.Powered) return; // if we're monitoring for atmos fire, then we make it similar to a smoke detector @@ -261,15 +262,15 @@ namespace Content.Server.Atmos.Monitor.Systems private void OnAtmosUpdate(EntityUid uid, AtmosMonitorComponent component, AtmosDeviceUpdateEvent args) { - if (component.PowerRecvComponent == null - || !component.PowerRecvComponent.Powered) + if (!TryComp(uid, out var powerReceiverComponent) + || !powerReceiverComponent.Powered) return; // can't hurt // (in case something is making AtmosDeviceUpdateEvents // outside the typical device loop) - if (component.AtmosDeviceComponent == null - || component.AtmosDeviceComponent.JoinedGrid == null) + if (!TryComp(uid, out var atmosDeviceComponent) + || atmosDeviceComponent.JoinedGrid == null) return; // if we're not monitoring atmos, don't bother diff --git a/Content.Server/Botany/Components/PlantHolderComponent.cs b/Content.Server/Botany/Components/PlantHolderComponent.cs index 99ef0236d2..ee6c5ffb5f 100644 --- a/Content.Server/Botany/Components/PlantHolderComponent.cs +++ b/Content.Server/Botany/Components/PlantHolderComponent.cs @@ -46,7 +46,6 @@ namespace Content.Server.Botany.Components [Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly IEntityManager _entMan = default!; - [ComponentDependency] private readonly AppearanceComponent? _appearanceComponent = default!; public override string Name => "PlantHolder"; @@ -583,50 +582,50 @@ namespace Content.Server.Botany.Components { _updateSpriteAfterUpdate = false; - if (_appearanceComponent == null) + if (!_entMan.TryGetComponent(Owner, out var appearanceComponent)) return; if (Seed != null) { if (DrawWarnings) - _appearanceComponent.SetData(PlantHolderVisuals.HealthLight, Health <= (Seed.Endurance / 2f)); + appearanceComponent.SetData(PlantHolderVisuals.HealthLight, Health <= (Seed.Endurance / 2f)); if (Dead) { - _appearanceComponent.SetData(PlantHolderVisuals.Plant, + appearanceComponent.SetData(PlantHolderVisuals.Plant, new SpriteSpecifier.Rsi(Seed.PlantRsi, "dead")); } else if (Harvest) { - _appearanceComponent.SetData(PlantHolderVisuals.Plant, + appearanceComponent.SetData(PlantHolderVisuals.Plant, new SpriteSpecifier.Rsi(Seed.PlantRsi, "harvest")); } else if (Age < Seed.Maturation) { var growthStage = Math.Max(1, (int) ((Age * Seed.GrowthStages) / Seed.Maturation)); - _appearanceComponent.SetData(PlantHolderVisuals.Plant, + appearanceComponent.SetData(PlantHolderVisuals.Plant, new SpriteSpecifier.Rsi(Seed.PlantRsi, $"stage-{growthStage}")); _lastProduce = Age; } else { - _appearanceComponent.SetData(PlantHolderVisuals.Plant, + appearanceComponent.SetData(PlantHolderVisuals.Plant, new SpriteSpecifier.Rsi(Seed.PlantRsi, $"stage-{Seed.GrowthStages}")); } } else { - _appearanceComponent.SetData(PlantHolderVisuals.Plant, SpriteSpecifier.Invalid); - _appearanceComponent.SetData(PlantHolderVisuals.HealthLight, false); + appearanceComponent.SetData(PlantHolderVisuals.Plant, SpriteSpecifier.Invalid); + appearanceComponent.SetData(PlantHolderVisuals.HealthLight, false); } if (!DrawWarnings) return; - _appearanceComponent.SetData(PlantHolderVisuals.WaterLight, WaterLevel <= 10); - _appearanceComponent.SetData(PlantHolderVisuals.NutritionLight, NutritionLevel <= 2); - _appearanceComponent.SetData(PlantHolderVisuals.AlertLight, + appearanceComponent.SetData(PlantHolderVisuals.WaterLight, WaterLevel <= 10); + appearanceComponent.SetData(PlantHolderVisuals.NutritionLight, NutritionLevel <= 2); + appearanceComponent.SetData(PlantHolderVisuals.AlertLight, WeedLevel >= 5 || PestLevel >= 5 || Toxins >= 40 || ImproperHeat || ImproperLight || ImproperPressure || _missingGas > 0); - _appearanceComponent.SetData(PlantHolderVisuals.HarvestLight, Harvest); + appearanceComponent.SetData(PlantHolderVisuals.HarvestLight, Harvest); } public void CheckForDivergence(bool modified) @@ -735,10 +734,10 @@ namespace Content.Server.Botany.Components var targetEntity = Owner; var solutionEntity = usingItem; - + SoundSystem.Play(Filter.Pvs(usingItem), spray.SpraySound.GetSound(), usingItem, AudioHelpers.WithVariation(0.125f)); - + var split = solutionSystem.Drain(solutionEntity, solution, amount); diff --git a/Content.Server/Botany/Components/SeedExtractorComponent.cs b/Content.Server/Botany/Components/SeedExtractorComponent.cs index 82b1d1825d..f7f30ac41d 100644 --- a/Content.Server/Botany/Components/SeedExtractorComponent.cs +++ b/Content.Server/Botany/Components/SeedExtractorComponent.cs @@ -12,8 +12,6 @@ namespace Content.Server.Botany.Components [RegisterComponent] public class SeedExtractorComponent : Component, IInteractUsing { - [ComponentDependency] private readonly ApcPowerReceiverComponent? _powerReceiver = default!; - [Dependency] private readonly IEntityManager _entMan = default!; [Dependency] private readonly IRobustRandom _random = default!; @@ -25,7 +23,7 @@ namespace Content.Server.Botany.Components async Task IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs) { - if (!_powerReceiver?.Powered ?? false) + if (!_entMan.TryGetComponent(Owner, out var powerReceiverComponent) || !powerReceiverComponent.Powered) return false; if (_entMan.TryGetComponent(eventArgs.Using, out ProduceComponent? produce) && produce.Seed != null) diff --git a/Content.Server/Buckle/Components/BuckleComponent.cs b/Content.Server/Buckle/Components/BuckleComponent.cs index d0542dfe14..02169ab846 100644 --- a/Content.Server/Buckle/Components/BuckleComponent.cs +++ b/Content.Server/Buckle/Components/BuckleComponent.cs @@ -11,6 +11,7 @@ using Content.Shared.Popups; using Content.Shared.Pulling.Components; using Content.Shared.Standing; using Content.Shared.Stunnable; +using Robust.Server.GameObjects; using Robust.Shared.Audio; using Robust.Shared.Containers; using Robust.Shared.GameObjects; @@ -34,9 +35,6 @@ namespace Content.Server.Buckle.Components [Dependency] private readonly IEntityManager _entMan = default!; [Dependency] private readonly IGameTiming _gameTiming = default!; - [ComponentDependency] public readonly AppearanceComponent? Appearance = null; - [ComponentDependency] private readonly MobStateComponent? _mobState = null; - [DataField("size")] private int _size = 100; @@ -234,7 +232,8 @@ namespace Content.Server.Buckle.Components return false; } - Appearance?.SetData(BuckleVisuals.Buckled, true); + if(_entMan.TryGetComponent(Owner, out var appearance)) + appearance.SetData(BuckleVisuals.Buckled, true); ReAttach(strap); @@ -324,10 +323,11 @@ namespace Content.Server.Buckle.Components xform.Coordinates = oldBuckledXform.Coordinates.Offset(oldBuckledTo.UnbuckleOffset); } - Appearance?.SetData(BuckleVisuals.Buckled, false); + if(_entMan.TryGetComponent(Owner, out var appearance)) + appearance.SetData(BuckleVisuals.Buckled, false); if (_entMan.HasComponent(Owner) - || (_mobState?.IsIncapacitated() ?? false)) + | _entMan.TryGetComponent(Owner, out var mobState) && mobState.IsIncapacitated()) { EntitySystem.Get().Down(Owner); } @@ -336,7 +336,7 @@ namespace Content.Server.Buckle.Components EntitySystem.Get().Stand(Owner); } - _mobState?.CurrentState?.EnterState(Owner, _entMan); + mobState?.CurrentState?.EnterState(Owner, _entMan); UpdateBuckleStatus(); @@ -397,9 +397,9 @@ namespace Content.Server.Buckle.Components if (BuckledTo != null && _entMan.GetComponent(BuckledTo.Owner).LocalRotation.GetCardinalDir() == Direction.North && - BuckledTo.SpriteComponent != null) + _entMan.TryGetComponent(BuckledTo.Owner, out var spriteComponent)) { - drawDepth = BuckledTo.SpriteComponent.DrawDepth - 1; + drawDepth = spriteComponent.DrawDepth - 1; } return new BuckleComponentState(Buckled, drawDepth, LastEntityBuckledTo, DontCollide); diff --git a/Content.Server/Buckle/Components/StrapComponent.cs b/Content.Server/Buckle/Components/StrapComponent.cs index 81f0e79d31..205ec8f11c 100644 --- a/Content.Server/Buckle/Components/StrapComponent.cs +++ b/Content.Server/Buckle/Components/StrapComponent.cs @@ -20,7 +20,7 @@ namespace Content.Server.Buckle.Components [ComponentReference(typeof(SharedStrapComponent))] public class StrapComponent : SharedStrapComponent, IInteractHand, ISerializationHooks, IDestroyAct { - [ComponentDependency] public readonly SpriteComponent? SpriteComponent = null; + [Dependency] private readonly IEntityManager _entityManager = default!; private readonly HashSet _buckledEntities = new(); @@ -153,7 +153,8 @@ namespace Content.Server.Buckle.Components _occupiedSize += buckle.Size; - buckle.Appearance?.SetData(StrapVisuals.RotationAngle, _rotation); + if(_entityManager.TryGetComponent(buckle.Owner, out var appearanceComponent)) + appearanceComponent.SetData(StrapVisuals.RotationAngle, _rotation); // Update the visuals of the strap object if (IoCManager.Resolve().TryGetComponent(Owner, out var appearance)) diff --git a/Content.Server/Climbing/Components/ClimbingComponent.cs b/Content.Server/Climbing/Components/ClimbingComponent.cs index 8bcc497b4d..5be4761a88 100644 --- a/Content.Server/Climbing/Components/ClimbingComponent.cs +++ b/Content.Server/Climbing/Components/ClimbingComponent.cs @@ -14,6 +14,7 @@ namespace Content.Server.Climbing.Components public class ClimbingComponent : SharedClimbingComponent { [Dependency] private readonly IGameTiming _gameTiming = default!; + [Dependency] private readonly IEntityManager _entityManager = default!; public override bool IsClimbing { @@ -73,7 +74,7 @@ namespace Content.Server.Climbing.Components /// public void TryMoveTo(Vector2 from, Vector2 to) { - if (Body == null) return; + if (!_entityManager.TryGetComponent(Owner, out var physicsComponent)) return; var velocity = (to - from).Length; @@ -82,7 +83,7 @@ namespace Content.Server.Climbing.Components // Since there are bodies with different masses: // mass * 5 seems enough to move entity // instead of launching cats like rockets against the walls with constant impulse value. - Body.ApplyLinearImpulse((to - from).Normalized * velocity * Body.Mass * 5); + physicsComponent.ApplyLinearImpulse((to - from).Normalized * velocity * physicsComponent.Mass * 5); OwnerIsTransitioning = true; EntitySystem.Get().UnsetTransitionBoolAfterBufferTime(Owner, this); diff --git a/Content.Server/Clothing/Components/MagbootsComponent.cs b/Content.Server/Clothing/Components/MagbootsComponent.cs index 6da933b159..418f071019 100644 --- a/Content.Server/Clothing/Components/MagbootsComponent.cs +++ b/Content.Server/Clothing/Components/MagbootsComponent.cs @@ -20,9 +20,7 @@ namespace Content.Server.Clothing.Components [ComponentReference(typeof(SharedMagbootsComponent))] public sealed class MagbootsComponent : SharedMagbootsComponent, IActivate { - [ComponentDependency] private SharedItemComponent? _item = null; - [ComponentDependency] private ItemActionsComponent? _itemActions = null; - [ComponentDependency] private SpriteComponent? _sprite = null; + [Dependency] private readonly IEntityManager _entMan = default!; private bool _on; @@ -40,10 +38,12 @@ namespace Content.Server.Clothing.Components EntitySystem.Get().UpdateMagbootEffects(container.Owner, Owner, true, this); } - _itemActions?.Toggle(ItemActionType.ToggleMagboots, On); - if (_item != null) - _item.EquippedPrefix = On ? "on" : null; - _sprite?.LayerSetState(0, On ? "icon-on" : "icon"); + if(_entMan.TryGetComponent(Owner, out var itemActions)) + itemActions.Toggle(ItemActionType.ToggleMagboots, On); + if (_entMan.TryGetComponent(Owner, out var item)) + item.EquippedPrefix = On ? "on" : null; + if(_entMan.TryGetComponent(Owner, out var sprite)) + sprite.LayerSetState(0, On ? "icon-on" : "icon"); OnChanged(); Dirty(); } diff --git a/Content.Server/Doors/Components/AirlockComponent.cs b/Content.Server/Doors/Components/AirlockComponent.cs index 48f6f060b2..ff7fbf775d 100644 --- a/Content.Server/Doors/Components/AirlockComponent.cs +++ b/Content.Server/Doors/Components/AirlockComponent.cs @@ -23,20 +23,10 @@ namespace Content.Server.Doors.Components [RegisterComponent] public class AirlockComponent : Component, IWires { + [Dependency] private readonly IEntityManager _entityManager = default!; + public override string Name => "Airlock"; - [ComponentDependency] - public readonly ServerDoorComponent? DoorComponent = null; - - [ComponentDependency] - public readonly AppearanceComponent? AppearanceComponent = null; - - [ComponentDependency] - public readonly ApcPowerReceiverComponent? ReceiverComponent = null; - - [ComponentDependency] - public readonly WiresComponent? WiresComponent = null; - /// /// Sound to play when the bolts on the airlock go up. /// @@ -98,7 +88,7 @@ namespace Content.Server.Doors.Components private bool BoltLightsVisible { get => _boltLightsWirePulsed && BoltsDown && IsPowered() - && DoorComponent != null && DoorComponent.State == SharedDoorComponent.DoorState.Closed; + && _entityManager.TryGetComponent(Owner, out var doorComponent) && doorComponent.State == SharedDoorComponent.DoorState.Closed; set { _boltLightsWirePulsed = value; @@ -122,9 +112,10 @@ namespace Content.Server.Doors.Components { base.Initialize(); - if (ReceiverComponent != null && AppearanceComponent != null) + if (_entityManager.TryGetComponent(Owner, out var receiverComponent) && + _entityManager.TryGetComponent(Owner, out var appearanceComponent)) { - AppearanceComponent.SetData(DoorVisuals.Powered, ReceiverComponent.Powered); + appearanceComponent.SetData(DoorVisuals.Powered, receiverComponent.Powered); } } @@ -140,23 +131,23 @@ namespace Content.Server.Doors.Components public bool IsPowered() { - return ReceiverComponent == null || ReceiverComponent.Powered; + return _entityManager.TryGetComponent(Owner, out var receiverComponent) && receiverComponent.Powered; } public void UpdateBoltLightStatus() { - if (AppearanceComponent != null) + if (_entityManager.TryGetComponent(Owner, out var appearanceComponent)) { - AppearanceComponent.SetData(DoorVisuals.BoltLights, BoltLightsVisible); + appearanceComponent.SetData(DoorVisuals.BoltLights, BoltLightsVisible); } } public void UpdateWiresStatus() { - if (WiresComponent == null) return; + if (_entityManager.TryGetComponent(Owner, out var wiresComponent)) return; - var mainPowerCut = WiresComponent.IsWireCut(Wires.MainPower); - var backupPowerCut = WiresComponent.IsWireCut(Wires.BackupPower); + var mainPowerCut = wiresComponent.IsWireCut(Wires.MainPower); + var backupPowerCut = wiresComponent.IsWireCut(Wires.BackupPower); var statusLightState = PowerWiresPulsed ? StatusLightState.BlinkingFast : StatusLightState.On; StatusLightData powerLight; if (mainPowerCut && backupPowerCut) @@ -190,42 +181,42 @@ namespace Content.Server.Doors.Components new StatusLightData(Color.Red, Safety ? StatusLightState.On : StatusLightState.Off, "SAFETY"); - WiresComponent.SetStatus(AirlockWireStatus.PowerIndicator, powerLight); - WiresComponent.SetStatus(AirlockWireStatus.BoltIndicator, boltStatus); - WiresComponent.SetStatus(AirlockWireStatus.BoltLightIndicator, boltLightsStatus); - WiresComponent.SetStatus(AirlockWireStatus.AIControlIndicator, new StatusLightData(Color.Purple, StatusLightState.BlinkingSlow, "AI CTRL")); - WiresComponent.SetStatus(AirlockWireStatus.TimingIndicator, timingStatus); - WiresComponent.SetStatus(AirlockWireStatus.SafetyIndicator, safetyStatus); + wiresComponent.SetStatus(AirlockWireStatus.PowerIndicator, powerLight); + wiresComponent.SetStatus(AirlockWireStatus.BoltIndicator, boltStatus); + wiresComponent.SetStatus(AirlockWireStatus.BoltLightIndicator, boltLightsStatus); + wiresComponent.SetStatus(AirlockWireStatus.AIControlIndicator, new StatusLightData(Color.Purple, StatusLightState.BlinkingSlow, "AI CTRL")); + wiresComponent.SetStatus(AirlockWireStatus.TimingIndicator, timingStatus); + wiresComponent.SetStatus(AirlockWireStatus.SafetyIndicator, safetyStatus); } private void UpdatePowerCutStatus() { - if (ReceiverComponent == null) + if (!_entityManager.TryGetComponent(Owner, out var receiverComponent)) { return; } if (PowerWiresPulsed) { - ReceiverComponent.PowerDisabled = true; + receiverComponent.PowerDisabled = true; return; } - if (WiresComponent == null) + if (!_entityManager.TryGetComponent(Owner, out var wiresComponent)) { return; } - ReceiverComponent.PowerDisabled = - WiresComponent.IsWireCut(Wires.MainPower) && - WiresComponent.IsWireCut(Wires.BackupPower); + receiverComponent.PowerDisabled = + wiresComponent.IsWireCut(Wires.MainPower) && + wiresComponent.IsWireCut(Wires.BackupPower); } private void PowerDeviceOnOnPowerStateChanged(PowerChangedMessage e) { - if (AppearanceComponent != null) + if (_entityManager.TryGetComponent(Owner, out var appearanceComponent)) { - AppearanceComponent.SetData(DoorVisuals.Powered, e.Powered); + appearanceComponent.SetData(DoorVisuals.Powered, e.Powered); } // BoltLights also got out @@ -290,7 +281,7 @@ namespace Content.Server.Doors.Components public void WiresUpdate(WiresUpdateEventArgs args) { - if (DoorComponent == null) + if (!_entityManager.TryGetComponent(Owner, out var doorComponent)) { return; } @@ -328,7 +319,7 @@ namespace Content.Server.Doors.Components break; case Wires.Timing: AutoCloseDelayModifier = 0.5f; - DoorComponent.RefreshAutoClose(); + doorComponent.RefreshAutoClose(); break; case Wires.Safety: Safety = !Safety; @@ -351,7 +342,7 @@ namespace Content.Server.Doors.Components break; case Wires.Timing: AutoClose = true; - DoorComponent.RefreshAutoClose(); + doorComponent.RefreshAutoClose(); break; case Wires.Safety: Safety = true; @@ -371,7 +362,7 @@ namespace Content.Server.Doors.Components break; case Wires.Timing: AutoClose = false; - DoorComponent.RefreshAutoClose(); + doorComponent.RefreshAutoClose(); break; case Wires.Safety: Safety = false; diff --git a/Content.Server/Doors/Components/FirelockComponent.cs b/Content.Server/Doors/Components/FirelockComponent.cs index 7634a0d3b1..43a0dc50bd 100644 --- a/Content.Server/Doors/Components/FirelockComponent.cs +++ b/Content.Server/Doors/Components/FirelockComponent.cs @@ -18,9 +18,6 @@ namespace Content.Server.Doors.Components public override string Name => "Firelock"; - [ComponentDependency] - public readonly ServerDoorComponent? DoorComponent = null; - /// /// Pry time modifier to be used when the firelock is currently closed due to fire or pressure. /// @@ -30,9 +27,9 @@ namespace Content.Server.Doors.Components public bool EmergencyPressureStop() { - if (DoorComponent != null && DoorComponent.State == SharedDoorComponent.DoorState.Open && DoorComponent.CanCloseGeneric()) + if (_entMan.TryGetComponent(Owner, out var doorComp) && doorComp.State == SharedDoorComponent.DoorState.Open && doorComp.CanCloseGeneric()) { - DoorComponent.Close(); + doorComp.Close(); if (_entMan.TryGetComponent(Owner, out AirtightComponent? airtight)) { EntitySystem.Get().SetAirblocked(airtight, true); diff --git a/Content.Server/Doors/Components/ServerDoorComponent.cs b/Content.Server/Doors/Components/ServerDoorComponent.cs index b3a17c9a19..381634b4e5 100644 --- a/Content.Server/Doors/Components/ServerDoorComponent.cs +++ b/Content.Server/Doors/Components/ServerDoorComponent.cs @@ -24,6 +24,7 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Maths; +using Robust.Shared.Physics; using Robust.Shared.Player; using Robust.Shared.Prototypes; using Robust.Shared.Serialization.Manager.Attributes; @@ -557,19 +558,19 @@ namespace Content.Server.Doors.Components /// True if we crushed somebody, false if we did not. private bool TryCrush() { - if (PhysicsComponent == null) + if (!_entMan.TryGetComponent(Owner, out PhysicsComponent physicsComponent) || physicsComponent is not IPhysBody body) { return false; } - var collidingentities = PhysicsComponent.GetCollidingEntities(Vector2.Zero, false); + var collidingentities = body.GetCollidingEntities(Vector2.Zero, false); if (!collidingentities.Any()) { return false; } - var doorAABB = PhysicsComponent.GetWorldAABB(); + var doorAABB = body.GetWorldAABB(); var hitsomebody = false; // Crush @@ -718,7 +719,7 @@ namespace Content.Server.Doors.Components // no interaction occurred return false; } - + _beingWelded = true; // perform a do-after delay diff --git a/Content.Server/Doors/Systems/AirlockSystem.cs b/Content.Server/Doors/Systems/AirlockSystem.cs index 14ef8d6a95..a938ef2368 100644 --- a/Content.Server/Doors/Systems/AirlockSystem.cs +++ b/Content.Server/Doors/Systems/AirlockSystem.cs @@ -1,5 +1,6 @@ using Content.Server.Doors.Components; using Content.Server.Power.Components; +using Content.Server.WireHacking; using Content.Shared.Doors; using Content.Shared.Popups; using Robust.Server.GameObjects; @@ -29,9 +30,9 @@ namespace Content.Server.Doors.Systems private void OnPowerChanged(EntityUid uid, AirlockComponent component, PowerChangedEvent args) { - if (component.AppearanceComponent != null) + if (TryComp(uid, out var appearanceComponent)) { - component.AppearanceComponent.SetData(DoorVisuals.Powered, args.Powered); + appearanceComponent.SetData(DoorVisuals.Powered, args.Powered); } // BoltLights also got out @@ -41,9 +42,9 @@ namespace Content.Server.Doors.Systems private void OnStateChanged(EntityUid uid, AirlockComponent component, DoorStateChangedEvent args) { // Only show the maintenance panel if the airlock is closed - if (component.WiresComponent != null) + if (TryComp(uid, out var wiresComponent)) { - component.WiresComponent.IsPanelVisible = + wiresComponent.IsPanelVisible = component.OpenPanelVisible || args.State != SharedDoorComponent.DoorState.Open; } @@ -87,10 +88,10 @@ namespace Content.Server.Doors.Systems private void OnDoorClickShouldActivate(EntityUid uid, AirlockComponent component, DoorClickShouldActivateEvent args) { - if (component.WiresComponent != null && component.WiresComponent.IsPanelOpen && + if (TryComp(uid, out var wiresComponent) && wiresComponent.IsPanelOpen && EntityManager.TryGetComponent(args.Args.User, out ActorComponent? actor)) { - component.WiresComponent.OpenInterface(actor.PlayerSession); + wiresComponent.OpenInterface(actor.PlayerSession); args.Handled = true; } } diff --git a/Content.Server/Doors/Systems/FirelockSystem.cs b/Content.Server/Doors/Systems/FirelockSystem.cs index fedd2a4d2a..3350ae0187 100644 --- a/Content.Server/Doors/Systems/FirelockSystem.cs +++ b/Content.Server/Doors/Systems/FirelockSystem.cs @@ -50,7 +50,7 @@ namespace Content.Server.Doors.Systems private void OnBeforeDoorPry(EntityUid uid, FirelockComponent component, BeforeDoorPryEvent args) { - if (component.DoorComponent == null || component.DoorComponent.State != SharedDoorComponent.DoorState.Closed) + if (!TryComp(uid, out var doorComponent) || doorComponent.State != SharedDoorComponent.DoorState.Closed) { return; } @@ -81,12 +81,12 @@ namespace Content.Server.Doors.Systems private void OnAtmosAlarm(EntityUid uid, FirelockComponent component, AtmosMonitorAlarmEvent args) { - if (component.DoorComponent == null) return; + if (!TryComp(uid, out var doorComponent)) return; if (args.HighestNetworkType == AtmosMonitorAlarmType.Normal) { - if (component.DoorComponent.State == SharedDoorComponent.DoorState.Closed) - component.DoorComponent.Open(); + if (doorComponent.State == SharedDoorComponent.DoorState.Closed) + doorComponent.Open(); } else if (args.HighestNetworkType == AtmosMonitorAlarmType.Danger) { diff --git a/Content.Server/Light/Components/MatchstickComponent.cs b/Content.Server/Light/Components/MatchstickComponent.cs index 2d66607dac..591537e6f4 100644 --- a/Content.Server/Light/Components/MatchstickComponent.cs +++ b/Content.Server/Light/Components/MatchstickComponent.cs @@ -32,11 +32,5 @@ namespace Content.Server.Light.Components /// Sound played when you ignite the matchstick. /// [DataField("igniteSound", required: true)] public SoundSpecifier IgniteSound = default!; - - /// - /// Point light component. Gives matches a glow in dark effect. - /// - [ComponentDependency] - public readonly PointLightComponent? PointLightComponent = default!; } } diff --git a/Content.Server/Light/EntitySystems/MatchstickSystem.cs b/Content.Server/Light/EntitySystems/MatchstickSystem.cs index 48cb3b5ee9..80ba6e8a6c 100644 --- a/Content.Server/Light/EntitySystems/MatchstickSystem.cs +++ b/Content.Server/Light/EntitySystems/MatchstickSystem.cs @@ -6,6 +6,7 @@ using Content.Shared.Interaction; using Content.Shared.Item; using Content.Shared.Smoking; using Content.Shared.Temperature; +using Robust.Server.GameObjects; using Robust.Shared.Audio; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -85,9 +86,9 @@ namespace Content.Server.Light.EntitySystems { component.CurrentState = value; - if (component.PointLightComponent != null) + if (TryComp(component.Owner, out var pointLightComponent)) { - component.PointLightComponent.Enabled = component.CurrentState == SmokableState.Lit; + pointLightComponent.Enabled = component.CurrentState == SmokableState.Lit; } if (EntityManager.TryGetComponent(component.Owner, out SharedItemComponent? item)) diff --git a/Content.Server/Morgue/Components/CrematoriumEntityStorageComponent.cs b/Content.Server/Morgue/Components/CrematoriumEntityStorageComponent.cs index 807d6e54e8..713ce90e47 100644 --- a/Content.Server/Morgue/Components/CrematoriumEntityStorageComponent.cs +++ b/Content.Server/Morgue/Components/CrematoriumEntityStorageComponent.cs @@ -50,16 +50,16 @@ namespace Content.Server.Morgue.Components void IExamine.Examine(FormattedMessage message, bool inDetailsRange) { - if (Appearance == null) return; + if (_entities.TryGetComponent(Owner, out var appearance)) return; if (inDetailsRange) { - if (Appearance.TryGetData(CrematoriumVisuals.Burning, out bool isBurning) && isBurning) + if (appearance.TryGetData(CrematoriumVisuals.Burning, out bool isBurning) && isBurning) { message.AddMarkup(Loc.GetString("crematorium-entity-storage-component-on-examine-details-is-burning", ("owner", Owner)) + "\n"); } - if (Appearance.TryGetData(MorgueVisuals.HasContents, out bool hasContents) && hasContents) + if (appearance.TryGetData(MorgueVisuals.HasContents, out bool hasContents) && hasContents) { message.AddMarkup(Loc.GetString("crematorium-entity-storage-component-on-examine-details-has-contents")); } @@ -96,7 +96,8 @@ namespace Content.Server.Morgue.Components if (Open) CloseStorage(); - Appearance?.SetData(CrematoriumVisuals.Burning, true); + if(_entities.TryGetComponent(Owner, out AppearanceComponent appearanceComponent)) + appearanceComponent.SetData(CrematoriumVisuals.Burning, true); Cooking = true; SoundSystem.Play(Filter.Pvs(Owner), _crematingSound.GetSound(), Owner); @@ -108,8 +109,8 @@ namespace Content.Server.Morgue.Components { if (_entities.Deleted(Owner)) return; - - Appearance?.SetData(CrematoriumVisuals.Burning, false); + if(_entities.TryGetComponent(Owner, out appearanceComponent)) + appearanceComponent.SetData(CrematoriumVisuals.Burning, false); Cooking = false; if (Contents.ContainedEntities.Count > 0) diff --git a/Content.Server/Morgue/Components/MorgueEntityStorageComponent.cs b/Content.Server/Morgue/Components/MorgueEntityStorageComponent.cs index 47c4ec78c0..a56efbcd0d 100644 --- a/Content.Server/Morgue/Components/MorgueEntityStorageComponent.cs +++ b/Content.Server/Morgue/Components/MorgueEntityStorageComponent.cs @@ -56,13 +56,11 @@ namespace Content.Server.Morgue.Components [DataField("occupantHasSoulAlarmSound")] private SoundSpecifier _occupantHasSoulAlarmSound = new SoundPathSpecifier("/Audio/Weapons/Guns/EmptyAlarm/smg_empty_alarm.ogg"); - [ViewVariables] - [ComponentDependency] protected readonly AppearanceComponent? Appearance = null; - protected override void Initialize() { base.Initialize(); - Appearance?.SetData(MorgueVisuals.Open, false); + if(_entMan.TryGetComponent(Owner, out var appearance)) + appearance.SetData(MorgueVisuals.Open, false); TrayContainer = Owner.EnsureContainer("morgue_tray", out _); } @@ -97,10 +95,13 @@ namespace Content.Server.Morgue.Components protected override void OpenStorage() { - Appearance?.SetData(MorgueVisuals.Open, true); - Appearance?.SetData(MorgueVisuals.HasContents, false); - Appearance?.SetData(MorgueVisuals.HasMob, false); - Appearance?.SetData(MorgueVisuals.HasSoul, false); + if (_entMan.TryGetComponent(Owner, out var appearance)) + { + appearance.SetData(MorgueVisuals.Open, true); + appearance.SetData(MorgueVisuals.HasContents, false); + appearance.SetData(MorgueVisuals.HasMob, false); + appearance.SetData(MorgueVisuals.HasSoul, false); + } if (_tray == null) { @@ -131,16 +132,21 @@ namespace Content.Server.Morgue.Components if (!hasSoul && _entMan.TryGetComponent(entity, out var actor) && actor.PlayerSession != null) hasSoul = true; } - Appearance?.SetData(MorgueVisuals.HasContents, count > 0); - Appearance?.SetData(MorgueVisuals.HasMob, hasMob); - Appearance?.SetData(MorgueVisuals.HasSoul, hasSoul); + + if (_entMan.TryGetComponent(Owner, out var appearance)) + { + appearance.SetData(MorgueVisuals.HasContents, count > 0); + appearance.SetData(MorgueVisuals.HasMob, hasMob); + appearance.SetData(MorgueVisuals.HasSoul, hasSoul); + } } protected override void CloseStorage() { base.CloseStorage(); - Appearance?.SetData(MorgueVisuals.Open, false); + if (_entMan.TryGetComponent(Owner, out var appearance)) + appearance.SetData(MorgueVisuals.Open, false); CheckContents(); if (_tray != null) @@ -168,7 +174,8 @@ namespace Content.Server.Morgue.Components { CheckContents(); - if (DoSoulBeep && Appearance != null && Appearance.TryGetData(MorgueVisuals.HasSoul, out bool hasSoul) && hasSoul) + if (DoSoulBeep && _entMan.TryGetComponent(Owner, out var appearance) && + appearance.TryGetData(MorgueVisuals.HasSoul, out bool hasSoul) && hasSoul) { SoundSystem.Play(Filter.Pvs(Owner), _occupantHasSoulAlarmSound.GetSound(), Owner); } @@ -176,19 +183,19 @@ namespace Content.Server.Morgue.Components void IExamine.Examine(FormattedMessage message, bool inDetailsRange) { - if (Appearance == null) return; + if (!_entMan.TryGetComponent(Owner, out var appearance)) return; if (inDetailsRange) { - if (Appearance.TryGetData(MorgueVisuals.HasSoul, out bool hasSoul) && hasSoul) + if (appearance.TryGetData(MorgueVisuals.HasSoul, out bool hasSoul) && hasSoul) { message.AddMarkup(Loc.GetString("morgue-entity-storage-component-on-examine-details-body-has-soul")); } - else if (Appearance.TryGetData(MorgueVisuals.HasMob, out bool hasMob) && hasMob) + else if (appearance.TryGetData(MorgueVisuals.HasMob, out bool hasMob) && hasMob) { message.AddMarkup(Loc.GetString("morgue-entity-storage-component-on-examine-details-body-has-no-soul")); } - else if (Appearance.TryGetData(MorgueVisuals.HasContents, out bool hasContents) && hasContents) + else if (appearance.TryGetData(MorgueVisuals.HasContents, out bool hasContents) && hasContents) { message.AddMarkup(Loc.GetString("morgue-entity-storage-component-on-examine-details-has-contents")); } diff --git a/Content.Server/Power/Components/ApcComponent.cs b/Content.Server/Power/Components/ApcComponent.cs index f4da006a30..582e6f9a5a 100644 --- a/Content.Server/Power/Components/ApcComponent.cs +++ b/Content.Server/Power/Components/ApcComponent.cs @@ -59,8 +59,6 @@ namespace Content.Server.Power.Components public BatteryComponent? Battery => _entMan.TryGetComponent(Owner, out BatteryComponent? batteryComponent) ? batteryComponent : null; - [ComponentDependency] private AccessReaderComponent? _accessReader = null; - protected override void Initialize() { base.Initialize(); @@ -92,7 +90,7 @@ namespace Content.Server.Power.Components return; var accessSystem = EntitySystem.Get(); - if (_accessReader == null || accessSystem.IsAllowed(_accessReader, attached)) + if (_entMan.TryGetComponent(Owner, out var accessReaderComponent) || accessSystem.IsAllowed(accessReaderComponent, attached)) { MainBreakerEnabled = !MainBreakerEnabled; _entMan.GetComponent(Owner).CanDischarge = MainBreakerEnabled; diff --git a/Content.Server/Power/Components/ExaminableBatteryComponent.cs b/Content.Server/Power/Components/ExaminableBatteryComponent.cs index 4f62721128..ec8a44ebce 100644 --- a/Content.Server/Power/Components/ExaminableBatteryComponent.cs +++ b/Content.Server/Power/Components/ExaminableBatteryComponent.cs @@ -1,5 +1,6 @@ using Content.Shared.Examine; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -13,19 +14,18 @@ namespace Content.Server.Power.Components { public override string Name => "ExaminableBattery"; - [ViewVariables] - [ComponentDependency] private BatteryComponent? _battery = default!; + [Dependency] private readonly IEntityManager _entityManager = default!; void IExamine.Examine(FormattedMessage message, bool inDetailsRange) { - if (_battery == null) + if (_entityManager.TryGetComponent(Owner, out var batteryComponent)) return; if (inDetailsRange) { - var effectiveMax = _battery.MaxCharge; + var effectiveMax = batteryComponent.MaxCharge; if (effectiveMax == 0) effectiveMax = 1; - var chargeFraction = _battery.CurrentCharge / effectiveMax; + var chargeFraction = batteryComponent.CurrentCharge / effectiveMax; var chargePercentRounded = (int) (chargeFraction * 100); message.AddMarkup( Loc.GetString( diff --git a/Content.Server/Singularity/Components/ContainmentFieldGeneratorComponent.cs b/Content.Server/Singularity/Components/ContainmentFieldGeneratorComponent.cs index bbe9a0a190..3a02cc6d4d 100644 --- a/Content.Server/Singularity/Components/ContainmentFieldGeneratorComponent.cs +++ b/Content.Server/Singularity/Components/ContainmentFieldGeneratorComponent.cs @@ -58,9 +58,6 @@ namespace Content.Server.Singularity.Components } } - [ComponentDependency] private readonly PhysicsComponent? _collidableComponent = default; - [ComponentDependency] private readonly PointLightComponent? _pointLightComponent = default; - private Tuple? _connection1; private Tuple? _connection2; @@ -69,7 +66,7 @@ namespace Content.Server.Singularity.Components public void OnAnchoredChanged() { - if(_collidableComponent?.BodyType != BodyType.Static) + if(_entMan.TryGetComponent(Owner, out var physicsComponent) && physicsComponent.BodyType != BodyType.Static) { _connection1?.Item2.Dispose(); _connection2?.Item2.Dispose(); @@ -91,7 +88,7 @@ namespace Content.Server.Singularity.Components private bool TryGenerateFieldConnection([NotNullWhen(true)] ref Tuple? propertyFieldTuple) { if (propertyFieldTuple != null) return false; - if(_collidableComponent?.BodyType != BodyType.Static) return false; + if(_entMan.TryGetComponent(Owner, out var physicsComponent) && physicsComponent.BodyType != BodyType.Static) return false; foreach (var direction in new[] {Direction.North, Direction.East, Direction.South, Direction.West}) { @@ -166,10 +163,10 @@ namespace Content.Server.Singularity.Components public void UpdateConnectionLights() { - if (_pointLightComponent != null) + if (_entMan.TryGetComponent(Owner, out var pointLightComponent)) { bool hasAnyConnection = (_connection1 != null) || (_connection2 != null); - _pointLightComponent.Enabled = hasAnyConnection; + pointLightComponent.Enabled = hasAnyConnection; } } diff --git a/Content.Server/Singularity/Components/EmitterComponent.cs b/Content.Server/Singularity/Components/EmitterComponent.cs index 6a1de068d7..d77a5231d9 100644 --- a/Content.Server/Singularity/Components/EmitterComponent.cs +++ b/Content.Server/Singularity/Components/EmitterComponent.cs @@ -13,10 +13,6 @@ namespace Content.Server.Singularity.Components [RegisterComponent] public class EmitterComponent : Component { - [ComponentDependency] public readonly AppearanceComponent? Appearance = default; - [ComponentDependency] public readonly AccessReaderComponent? AccessReader = default; - [ComponentDependency] public readonly PowerConsumerComponent? PowerConsumer = default; - public override string Name => "Emitter"; public CancellationTokenSource? TimerCancel; diff --git a/Content.Server/Singularity/Components/RadiationCollectorComponent.cs b/Content.Server/Singularity/Components/RadiationCollectorComponent.cs index b1c70ea84d..cb48749b24 100644 --- a/Content.Server/Singularity/Components/RadiationCollectorComponent.cs +++ b/Content.Server/Singularity/Components/RadiationCollectorComponent.cs @@ -16,6 +16,7 @@ namespace Content.Server.Singularity.Components public class RadiationCollectorComponent : Component, IInteractHand, IRadiationAct { [Dependency] private readonly IGameTiming _gameTiming = default!; + [Dependency] private readonly IEntityManager _entMan = default!; public override string Name => "RadiationCollector"; private bool _enabled; @@ -32,8 +33,6 @@ namespace Content.Server.Singularity.Components } } - [ComponentDependency] private readonly BatteryComponent? _batteryComponent = default!; - bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs) { var curTime = _gameTiming.CurTime; @@ -66,9 +65,9 @@ namespace Content.Server.Singularity.Components // But the previous logic would also make the radiation collectors never ever stop providing energy. // And since frameTime was used there, I'm assuming that this is what the intent was. // This still won't stop things being potentially hilarously unbalanced though. - if (_batteryComponent != null) + if (_entMan.TryGetComponent(Owner, out var batteryComponent)) { - _batteryComponent!.CurrentCharge += frameTime * radiation.RadsPerSecond * 3000f; + batteryComponent.CurrentCharge += frameTime * radiation.RadsPerSecond * 3000f; } } diff --git a/Content.Server/Singularity/EntitySystems/EmitterSystem.cs b/Content.Server/Singularity/EntitySystems/EmitterSystem.cs index 91baa74975..62536da68f 100644 --- a/Content.Server/Singularity/EntitySystems/EmitterSystem.cs +++ b/Content.Server/Singularity/EntitySystems/EmitterSystem.cs @@ -1,6 +1,7 @@ using System; using System.Threading; using Content.Server.Administration.Logs; +using Content.Server.Power.Components; using Content.Server.Power.EntitySystems; using Content.Server.Projectiles.Components; using Content.Server.Singularity.Components; @@ -94,7 +95,7 @@ namespace Content.Server.Singularity.EntitySystems public void SwitchOff(EmitterComponent component) { component.IsOn = false; - if (component.PowerConsumer != null) component.PowerConsumer.DrawRate = 0; + if (TryComp(component.Owner, out var powerConsumer)) powerConsumer.DrawRate = 0; PowerOff(component); UpdateAppearance(component); } @@ -102,7 +103,7 @@ namespace Content.Server.Singularity.EntitySystems public void SwitchOn(EmitterComponent component) { component.IsOn = true; - if (component.PowerConsumer != null) component.PowerConsumer.DrawRate = component.PowerUseActive; + if (TryComp(component.Owner, out var powerConsumer)) powerConsumer.DrawRate = component.PowerUseActive; // Do not directly PowerOn(). // OnReceivedPowerChanged will get fired due to DrawRate change which will turn it on. UpdateAppearance(component); @@ -149,7 +150,8 @@ namespace Content.Server.Singularity.EntitySystems // and thus not firing DebugTools.Assert(component.IsPowered); DebugTools.Assert(component.IsOn); - DebugTools.Assert(component.PowerConsumer != null && (component.PowerConsumer.DrawRate <= component.PowerConsumer.ReceivedPower)); + DebugTools.Assert(TryComp(component.Owner, out var powerConsumer) && + powerConsumer.DrawRate <= powerConsumer.ReceivedPower); Fire(component); @@ -205,7 +207,7 @@ namespace Content.Server.Singularity.EntitySystems private void UpdateAppearance(EmitterComponent component) { - if (component.Appearance == null) + if (!TryComp(component.Owner, out var appearanceComponent)) { return; } @@ -224,7 +226,7 @@ namespace Content.Server.Singularity.EntitySystems state = EmitterVisualState.Off; } - component.Appearance.SetData(EmitterVisuals.VisualState, state); + appearanceComponent.SetData(EmitterVisuals.VisualState, state); } } } diff --git a/Content.Shared/Climbing/SharedClimbingComponent.cs b/Content.Shared/Climbing/SharedClimbingComponent.cs index a9e8458e43..121472f8f1 100644 --- a/Content.Shared/Climbing/SharedClimbingComponent.cs +++ b/Content.Shared/Climbing/SharedClimbingComponent.cs @@ -3,6 +3,7 @@ using Content.Shared.ActionBlocker; using Content.Shared.Physics; using Robust.Shared.GameObjects; using Robust.Shared.GameStates; +using Robust.Shared.IoC; using Robust.Shared.Physics; using Robust.Shared.Serialization; using Robust.Shared.ViewVariables; @@ -12,15 +13,17 @@ namespace Content.Shared.Climbing [NetworkedComponent()] public abstract class SharedClimbingComponent : Component { + [Dependency] private readonly IEntityManager _entMan = default!; + public sealed override string Name => "Climbing"; protected bool IsOnClimbableThisFrame { get { - if (Body == null) return false; + if (!_entMan.TryGetComponent(Owner, out var physicsComponent)) return false; - foreach (var entity in Body.GetBodiesIntersecting()) + foreach (var entity in physicsComponent.GetBodiesIntersecting()) { if ((entity.CollisionLayer & (int) CollisionGroup.SmallImpassable) != 0) return true; } @@ -37,22 +40,20 @@ namespace Content.Shared.Climbing { if (_ownerIsTransitioning == value) return; _ownerIsTransitioning = value; - if (Body == null) return; + if (!_entMan.TryGetComponent(Owner, out var physicsComponent)) return; if (value) { - Body.BodyType = BodyType.Dynamic; + physicsComponent.BodyType = BodyType.Dynamic; } else { - Body.BodyType = BodyType.KinematicController; + physicsComponent.BodyType = BodyType.KinematicController; } } } private bool _ownerIsTransitioning = false; - [ComponentDependency] protected PhysicsComponent? Body; - protected TimeSpan StartClimbTime = TimeSpan.Zero; /// @@ -78,9 +79,9 @@ namespace Content.Shared.Climbing private void ToggleSmallPassable(bool value) { // Hope the mob has one fixture - if (Body == null || Body.Deleted) return; + if (!_entMan.TryGetComponent(Owner, out var physicsComponent) || physicsComponent.Deleted) return; - foreach (var fixture in Body.Fixtures) + foreach (var fixture in physicsComponent.Fixtures) { if (value) { diff --git a/Content.Shared/Doors/SharedDoorComponent.cs b/Content.Shared/Doors/SharedDoorComponent.cs index efc643b344..f97229abcf 100644 --- a/Content.Shared/Doors/SharedDoorComponent.cs +++ b/Content.Shared/Doors/SharedDoorComponent.cs @@ -16,15 +16,11 @@ namespace Content.Shared.Doors { public override string Name => "Door"; - [ComponentDependency] - protected readonly AppearanceComponent? AppearanceComponent = null; - - [ComponentDependency] - protected readonly IPhysBody? PhysicsComponent = null; - [Dependency] protected readonly IGameTiming _gameTiming = default!; + [Dependency] private readonly IEntityManager _entMan = default!; + [ViewVariables] private DoorState _state = DoorState.Closed; /// @@ -104,7 +100,10 @@ namespace Content.Shared.Doors protected void SetAppearance(DoorVisualState state) { - AppearanceComponent?.SetData(DoorVisuals.VisualState, state); + if (_entMan.TryGetComponent(Owner, out var appearanceComponent)) + { + appearanceComponent.SetData(DoorVisuals.VisualState, state); + } } /// @@ -112,9 +111,9 @@ namespace Content.Shared.Doors /// protected virtual void OnPartialOpen() { - if (PhysicsComponent != null) + if (_entMan.TryGetComponent(Owner, out var physicsComponent)) { - PhysicsComponent.CanCollide = false; + physicsComponent.CanCollide = false; } // we can't be crushing anyone anymore, since we're opening CurrentlyCrushing.Clear(); @@ -125,9 +124,9 @@ namespace Content.Shared.Doors /// protected virtual void OnPartialClose() { - if (PhysicsComponent != null) + if (_entMan.TryGetComponent(Owner, out var physicsComponent)) { - PhysicsComponent.CanCollide = true; + physicsComponent.CanCollide = true; } } diff --git a/Content.Shared/Movement/Components/SharedPlayerInputMoverComponent.cs b/Content.Shared/Movement/Components/SharedPlayerInputMoverComponent.cs index f07b9651aa..608d388fdc 100644 --- a/Content.Shared/Movement/Components/SharedPlayerInputMoverComponent.cs +++ b/Content.Shared/Movement/Components/SharedPlayerInputMoverComponent.cs @@ -38,8 +38,7 @@ namespace Content.Shared.Movement.Components [Dependency] private readonly IConfigurationManager _configurationManager = default!; [Dependency] private readonly IGameTiming _gameTiming = default!; - - [ComponentDependency] private readonly MovementSpeedModifierComponent? _movementSpeed = default!; + [Dependency] private readonly IEntityManager _entityManager = default!; public override string Name => "PlayerInputMover"; @@ -53,9 +52,17 @@ namespace Content.Shared.Movement.Components [ViewVariables] public Angle LastGridAngle { get; set; } = new(0); - public float CurrentWalkSpeed => _movementSpeed?.CurrentWalkSpeed ?? MovementSpeedModifierComponent.DefaultBaseWalkSpeed; + public float CurrentWalkSpeed => + _entityManager.TryGetComponent(Owner, + out var movementSpeedModifierComponent) + ? movementSpeedModifierComponent.CurrentWalkSpeed + : MovementSpeedModifierComponent.DefaultBaseWalkSpeed; - public float CurrentSprintSpeed => _movementSpeed?.CurrentSprintSpeed ?? MovementSpeedModifierComponent.DefaultBaseSprintSpeed; + public float CurrentSprintSpeed => + _entityManager.TryGetComponent(Owner, + out var movementSpeedModifierComponent) + ? movementSpeedModifierComponent.CurrentSprintSpeed + : MovementSpeedModifierComponent.DefaultBaseSprintSpeed; public bool Sprinting => !HasFlag(_heldMoveButtons, MoveButtons.Walk);