From cdc8336695a04a2678360393d41d33f86a2b452e Mon Sep 17 00:00:00 2001 From: Vera Aguilera Puerto Date: Wed, 8 Dec 2021 17:32:32 +0100 Subject: [PATCH] Even more resolve removals. --- .../Components/MovedByPressureComponent.cs | 2 +- .../Nutrition/Components/HungerComponent.cs | 7 ++-- .../Nutrition/Components/ThirstComponent.cs | 7 ++-- .../Nutrition/EntitySystems/SmokingSystem.cs | 2 +- Content.Server/PDA/PDAExtensions.cs | 14 ++++---- Content.Server/Paper/PaperComponent.cs | 12 ++++--- .../ParticleAcceleratorControlBoxComponent.cs | 29 ++++++++-------- .../Components/ParticleProjectileComponent.cs | 14 ++++---- .../Physics/Controllers/ConveyorController.cs | 5 +-- .../Physics/Controllers/MoverController.cs | 8 ++--- .../Controllers/SingularityController.cs | 2 +- .../Components/RandomPottedPlantComponent.cs | 6 ++-- .../Components/PointingArrowComponent.cs | 12 ++++--- .../Power/Components/ApcComponent.cs | 19 ++++++----- .../Components/ApcPowerReceiverComponent.cs | 6 ++-- .../Power/Components/BaseCharger.cs | 16 +++++---- .../Components/BaseNetConnectorComponent.cs | 4 ++- .../Power/Components/CableComponent.cs | 8 +++-- .../Power/Components/CablePlacerComponent.cs | 9 ++--- Content.Server/Power/SMES/SmesComponent.cs | 9 ++--- .../Components/HitscanComponent.cs | 15 ++++---- .../Radiation/RadiationPulseComponent.cs | 5 +-- .../Radiation/RadiationPulseSystem.cs | 9 ++--- .../Components/RecyclableComponent.cs | 6 ++-- .../Recycling/Components/RecyclerComponent.cs | 8 +++-- .../Components/ResearchConsoleComponent.cs | 11 +++--- .../Sandbox/Commands/ColorNetworkCommand.cs | 2 +- .../ContainmentFieldGeneratorComponent.cs | 12 ++++--- .../Components/ServerSingularityComponent.cs | 6 ++-- .../Components/SingularityGenerator.cs | 5 +-- .../Components/ConditionalSpawnerComponent.cs | 5 +-- .../Components/RandomSpawnerComponent.cs | 11 +++--- .../StationEvents/Events/PowerGridCheck.cs | 6 ++-- .../StationEvents/Events/RadiationStorm.cs | 6 ++-- .../CursedEntityStorageComponent.cs | 5 +-- .../Components/EntityStorageComponent.cs | 34 ++++++++++--------- .../Components/SecretStashComponent.cs | 16 ++++----- .../Components/StorageFillComponent.cs | 6 ++-- .../Suspicion/SuspicionRoleComponent.cs | 6 ++-- .../Tiles/FloorTileItemComponent.cs | 7 ++-- Content.Server/Toilet/ToiletComponent.cs | 18 +++++----- .../Tools/Components/TilePryingComponent.cs | 7 ++-- .../TraitorDeathMatchRedemptionComponent.cs | 16 +++++---- .../VendingMachineComponent.cs | 19 ++++++----- .../Ammunition/Components/AmmoComponent.cs | 5 +-- .../Components/SpeedLoaderComponent.cs | 16 +++++---- .../Barrels/Components/PumpBarrelComponent.cs | 14 ++++---- .../Components/RevolverBarrelComponent.cs | 11 +++--- .../Ranged/ServerRangedWeaponComponent.cs | 13 +++---- .../Weapon/WeaponCapacitorChargerComponent.cs | 10 +++--- Content.Server/Window/WindowComponent.cs | 7 ++-- .../Behaviors/Item/IItemActionBehavior.cs | 7 ++-- .../Components/SharedBodyPartComponent.cs | 26 +++++++------- .../Components/SharedMechanismComponent.cs | 10 +++--- .../Hands/Components/SharedHandsComponent.cs | 24 +++++++------ .../Helpers/SharedUnoccludedExtensions.cs | 30 +++++++++------- Content.Shared/Item/SharedItemComponent.cs | 8 +++-- Content.Shared/Lathe/SharedLatheComponent.cs | 5 +-- .../MobState/Components/MobStateComponent.cs | 8 +++-- .../Movement/SharedMoverController.cs | 10 +++--- .../Storage/SharedStorageComponent.cs | 6 ++-- 61 files changed, 364 insertions(+), 278 deletions(-) diff --git a/Content.Server/Atmos/Components/MovedByPressureComponent.cs b/Content.Server/Atmos/Components/MovedByPressureComponent.cs index e1b3e347f9..0d3d85a5e8 100644 --- a/Content.Server/Atmos/Components/MovedByPressureComponent.cs +++ b/Content.Server/Atmos/Components/MovedByPressureComponent.cs @@ -119,7 +119,7 @@ namespace Content.Server.Atmos.Components public static bool IsMovedByPressure(this EntityUid entity, [NotNullWhen(true)] out MovedByPressureComponent? moved) { - return _entMan.TryGetComponent(entity, out moved) && + return IoCManager.Resolve().TryGetComponent(entity, out moved) && moved.Enabled; } } diff --git a/Content.Server/Nutrition/Components/HungerComponent.cs b/Content.Server/Nutrition/Components/HungerComponent.cs index 196b733075..743f074459 100644 --- a/Content.Server/Nutrition/Components/HungerComponent.cs +++ b/Content.Server/Nutrition/Components/HungerComponent.cs @@ -23,6 +23,7 @@ namespace Content.Server.Nutrition.Components [RegisterComponent] public sealed class HungerComponent : SharedHungerComponent { + [Dependency] private readonly IEntityManager _entMan = default!; [Dependency] private readonly IRobustRandom _random = default!; private float _accumulatedFrameTime; @@ -88,13 +89,13 @@ namespace Content.Server.Nutrition.Components { // Revert slow speed if required if (_lastHungerThreshold == HungerThreshold.Starving && _currentHungerThreshold != HungerThreshold.Dead && - IoCManager.Resolve().TryGetComponent(Owner, out MovementSpeedModifierComponent? movementSlowdownComponent)) + _entMan.TryGetComponent(Owner, out MovementSpeedModifierComponent? movementSlowdownComponent)) { EntitySystem.Get().RefreshMovementSpeedModifiers(Owner); } // Update UI - IoCManager.Resolve().TryGetComponent(Owner, out ServerAlertsComponent? alertsComponent); + _entMan.TryGetComponent(Owner, out ServerAlertsComponent? alertsComponent); if (HungerThresholdAlertTypes.TryGetValue(_currentHungerThreshold, out var alertId)) { @@ -185,7 +186,7 @@ namespace Content.Server.Nutrition.Components return; // --> Current Hunger is below dead threshold - if (!IoCManager.Resolve().TryGetComponent(Owner, out MobStateComponent? mobState)) + if (!_entMan.TryGetComponent(Owner, out MobStateComponent? mobState)) return; if (!mobState.IsDead()) diff --git a/Content.Server/Nutrition/Components/ThirstComponent.cs b/Content.Server/Nutrition/Components/ThirstComponent.cs index f5956bdc1a..fadf84772a 100644 --- a/Content.Server/Nutrition/Components/ThirstComponent.cs +++ b/Content.Server/Nutrition/Components/ThirstComponent.cs @@ -23,6 +23,7 @@ namespace Content.Server.Nutrition.Components [RegisterComponent] public sealed class ThirstComponent : SharedThirstComponent { + [Dependency] private readonly IEntityManager _entMan = default!; [Dependency] private readonly IRobustRandom _random = default!; private float _accumulatedFrameTime; @@ -87,13 +88,13 @@ namespace Content.Server.Nutrition.Components { // Revert slow speed if required if (_lastThirstThreshold == ThirstThreshold.Parched && _currentThirstThreshold != ThirstThreshold.Dead && - IoCManager.Resolve().TryGetComponent(Owner, out MovementSpeedModifierComponent? movementSlowdownComponent)) + _entMan.TryGetComponent(Owner, out MovementSpeedModifierComponent? movementSlowdownComponent)) { EntitySystem.Get().RefreshMovementSpeedModifiers(Owner); } // Update UI - IoCManager.Resolve().TryGetComponent(Owner, out ServerAlertsComponent? alertsComponent); + _entMan.TryGetComponent(Owner, out ServerAlertsComponent? alertsComponent); if (ThirstThresholdAlertTypes.TryGetValue(_currentThirstThreshold, out var alertId)) { @@ -182,7 +183,7 @@ namespace Content.Server.Nutrition.Components return; // --> Current Hunger is below dead threshold - if (!IoCManager.Resolve().TryGetComponent(Owner, out MobStateComponent? mobState)) + if (!_entMan.TryGetComponent(Owner, out MobStateComponent? mobState)) return; if (!mobState.IsDead()) diff --git a/Content.Server/Nutrition/EntitySystems/SmokingSystem.cs b/Content.Server/Nutrition/EntitySystems/SmokingSystem.cs index a0dd8fa600..c3051db172 100644 --- a/Content.Server/Nutrition/EntitySystems/SmokingSystem.cs +++ b/Content.Server/Nutrition/EntitySystems/SmokingSystem.cs @@ -96,7 +96,7 @@ namespace Content.Server.Nutrition.EntitySystems // This is awful. I hate this so much. // TODO: Please, someone refactor containers and free me from this bullshit. if (!smokable.Owner.TryGetContainerMan(out var containerManager) || - !IoCManager.Resolve().TryGetComponent(containerManager.Owner, out BloodstreamComponent? bloodstream)) + !EntityManager.TryGetComponent(containerManager.Owner, out BloodstreamComponent? bloodstream)) continue; _reactiveSystem.ReactionEntity(containerManager.Owner, ReactionMethod.Ingestion, inhaledSolution); diff --git a/Content.Server/PDA/PDAExtensions.cs b/Content.Server/PDA/PDAExtensions.cs index 68c11f8a0f..8787dc5165 100644 --- a/Content.Server/PDA/PDAExtensions.cs +++ b/Content.Server/PDA/PDAExtensions.cs @@ -19,18 +19,20 @@ namespace Content.Server.PDA { IdCardComponent? firstIdInPda = null; - if (IoCManager.Resolve().TryGetComponent(player, out HandsComponent? hands)) + var entMan = IoCManager.Resolve(); + + if (entMan.TryGetComponent(player, out HandsComponent? hands)) { foreach (var item in hands.GetAllHeldItems()) { if (firstIdInPda == null && - IoCManager.Resolve().TryGetComponent(item.Owner, out PDAComponent? pda) && + entMan.TryGetComponent(item.Owner, out PDAComponent? pda) && pda.ContainedID != null) { firstIdInPda = pda.ContainedID; } - if (IoCManager.Resolve().TryGetComponent(item.Owner, out IdCardComponent? card)) + if (entMan.TryGetComponent(item.Owner, out IdCardComponent? card)) { return card; } @@ -44,18 +46,18 @@ namespace Content.Server.PDA IdCardComponent? firstIdInInventory = null; - if (IoCManager.Resolve().TryGetComponent(player, out InventoryComponent? inventory)) + if (entMan.TryGetComponent(player, out InventoryComponent? inventory)) { foreach (var item in inventory.GetAllHeldItems()) { if (firstIdInInventory == null && - IoCManager.Resolve().TryGetComponent(item, out PDAComponent? pda) && + entMan.TryGetComponent(item, out PDAComponent? pda) && pda.ContainedID != null) { firstIdInInventory = pda.ContainedID; } - if (IoCManager.Resolve().TryGetComponent(item, out IdCardComponent? card)) + if (entMan.TryGetComponent(item, out IdCardComponent? card)) { return card; } diff --git a/Content.Server/Paper/PaperComponent.cs b/Content.Server/Paper/PaperComponent.cs index 4fcdb6938b..e99520c72e 100644 --- a/Content.Server/Paper/PaperComponent.cs +++ b/Content.Server/Paper/PaperComponent.cs @@ -19,6 +19,8 @@ namespace Content.Server.Paper public class PaperComponent : SharedPaperComponent, IExamine, IInteractUsing, IUse #pragma warning restore 618 { + [Dependency] private readonly IEntityManager _entMan = default!; + private PaperAction _mode; [DataField("content")] public string Content { get; set; } = ""; @@ -43,7 +45,7 @@ namespace Content.Server.Paper Content = content + '\n'; UpdateUserInterface(); - if (!IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearance)) + if (!_entMan.TryGetComponent(Owner, out AppearanceComponent? appearance)) return; var status = string.IsNullOrWhiteSpace(content) @@ -74,7 +76,7 @@ namespace Content.Server.Paper bool IUse.UseEntity(UseEntityEventArgs eventArgs) { - if (!IoCManager.Resolve().TryGetComponent(eventArgs.User, out ActorComponent? actor)) + if (!_entMan.TryGetComponent(eventArgs.User, out ActorComponent? actor)) return false; _mode = PaperAction.Read; @@ -91,12 +93,12 @@ namespace Content.Server.Paper Content += msg.Text + '\n'; - if (IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearance)) + if (_entMan.TryGetComponent(Owner, out AppearanceComponent? appearance)) { appearance.SetData(PaperVisuals.Status, PaperStatus.Written); } - IoCManager.Resolve().GetComponent(Owner).EntityDescription = ""; + _entMan.GetComponent(Owner).EntityDescription = ""; UpdateUserInterface(); } @@ -104,7 +106,7 @@ namespace Content.Server.Paper { if (!eventArgs.Using.HasTag("Write")) return false; - if (!IoCManager.Resolve().TryGetComponent(eventArgs.User, out ActorComponent? actor)) + if (!_entMan.TryGetComponent(eventArgs.User, out ActorComponent? actor)) return false; _mode = PaperAction.Write; diff --git a/Content.Server/ParticleAccelerator/Components/ParticleAcceleratorControlBoxComponent.cs b/Content.Server/ParticleAccelerator/Components/ParticleAcceleratorControlBoxComponent.cs index b168c4d2d7..d4d757127b 100644 --- a/Content.Server/ParticleAccelerator/Components/ParticleAcceleratorControlBoxComponent.cs +++ b/Content.Server/ParticleAccelerator/Components/ParticleAcceleratorControlBoxComponent.cs @@ -36,6 +36,7 @@ namespace Content.Server.ParticleAccelerator.Components [RegisterComponent] public class ParticleAcceleratorControlBoxComponent : ParticleAcceleratorPartComponent, IActivate, IWires { + [Dependency] private readonly IEntityManager _entMan = default!; [Dependency] private readonly IMapManager _mapManager = default!; public override string Name => "ParticleAcceleratorControlBox"; @@ -221,12 +222,12 @@ namespace Content.Server.ParticleAccelerator.Components void IActivate.Activate(ActivateEventArgs eventArgs) { - if (!IoCManager.Resolve().TryGetComponent(eventArgs.User, out ActorComponent? actor)) + if (!_entMan.TryGetComponent(eventArgs.User, out ActorComponent? actor)) { return; } - if (IoCManager.Resolve().TryGetComponent(Owner, out var wires) && wires.IsPanelOpen) + if (_entMan.TryGetComponent(Owner, out var wires) && wires.IsPanelOpen) { wires.OpenInterface(actor.PlayerSession); } @@ -333,7 +334,7 @@ namespace Content.Server.ParticleAccelerator.Components private void UpdateWireStatus() { - if (!IoCManager.Resolve().TryGetComponent(Owner, out WiresComponent? wires)) + if (!_entMan.TryGetComponent(Owner, out WiresComponent? wires)) { return; } @@ -383,13 +384,13 @@ namespace Content.Server.ParticleAccelerator.Components _partEmitterRight = null; // Find fuel chamber first by scanning cardinals. - if (IoCManager.Resolve().GetComponent(Owner).Anchored) + if (_entMan.GetComponent(Owner).Anchored) { - var grid = _mapManager.GetGrid(IoCManager.Resolve().GetComponent(Owner).GridID); - var coords = IoCManager.Resolve().GetComponent(Owner).Coordinates; + var grid = _mapManager.GetGrid(_entMan.GetComponent(Owner).GridID); + var coords = _entMan.GetComponent(Owner).Coordinates; foreach (var maybeFuel in grid.GetCardinalNeighborCells(coords)) { - if (IoCManager.Resolve().TryGetComponent(maybeFuel, out _partFuelChamber)) + if (_entMan.TryGetComponent(maybeFuel, out _partFuelChamber)) { break; } @@ -405,7 +406,7 @@ namespace Content.Server.ParticleAccelerator.Components // Align ourselves to match fuel chamber orientation. // This means that if you mess up the orientation of the control box it's not a big deal, // because the sprite is far from obvious about the orientation. - IoCManager.Resolve().GetComponent(Owner).LocalRotation = IoCManager.Resolve().GetComponent(_partFuelChamber.Owner).LocalRotation; + _entMan.GetComponent(Owner).LocalRotation = _entMan.GetComponent(_partFuelChamber.Owner).LocalRotation; var offsetEndCap = RotateOffset((1, 1)); var offsetPowerBox = RotateOffset((1, -1)); @@ -451,7 +452,7 @@ namespace Content.Server.ParticleAccelerator.Components Vector2i RotateOffset(in Vector2i vec) { - var rot = new Angle(IoCManager.Resolve().GetComponent(Owner).LocalRotation); + var rot = new Angle(_entMan.GetComponent(Owner).LocalRotation); return (Vector2i) rot.RotateVec(vec); } } @@ -459,11 +460,11 @@ namespace Content.Server.ParticleAccelerator.Components private bool ScanPart(Vector2i offset, [NotNullWhen(true)] out T? part) where T : ParticleAcceleratorPartComponent { - var grid = _mapManager.GetGrid(IoCManager.Resolve().GetComponent(Owner).GridID); - var coords = IoCManager.Resolve().GetComponent(Owner).Coordinates; + var grid = _mapManager.GetGrid(_entMan.GetComponent(Owner).GridID); + var coords = _entMan.GetComponent(Owner).Coordinates; foreach (var ent in grid.GetOffset(coords, offset)) { - if (IoCManager.Resolve().TryGetComponent(ent, out part) && !part.Deleted) + if (_entMan.TryGetComponent(ent, out part) && !part.Deleted) { return true; } @@ -576,7 +577,7 @@ namespace Content.Server.ParticleAccelerator.Components private void UpdateAppearance() { - if (IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearance)) + if (_entMan.TryGetComponent(Owner, out AppearanceComponent? appearance)) { appearance.SetData(ParticleAcceleratorVisuals.VisualState, _apcPowerReceiverComponent!.Powered @@ -682,7 +683,7 @@ namespace Content.Server.ParticleAccelerator.Components private void UpdatePartVisualState(ParticleAcceleratorPartComponent? component) { - if (component == null || !IoCManager.Resolve().TryGetComponent(component.Owner, out var appearanceComponent)) + if (component == null || !_entMan.TryGetComponent(component.Owner, out var appearanceComponent)) { return; } diff --git a/Content.Server/ParticleAccelerator/Components/ParticleProjectileComponent.cs b/Content.Server/ParticleAccelerator/Components/ParticleProjectileComponent.cs index d3a134a347..6fabcf499f 100644 --- a/Content.Server/ParticleAccelerator/Components/ParticleProjectileComponent.cs +++ b/Content.Server/ParticleAccelerator/Components/ParticleProjectileComponent.cs @@ -13,6 +13,8 @@ namespace Content.Server.ParticleAccelerator.Components [RegisterComponent] public class ParticleProjectileComponent : Component { + [Dependency] private readonly IEntityManager _entMan = default!; + public override string Name => "ParticleProjectile"; public ParticleAcceleratorPowerState State; @@ -20,21 +22,21 @@ namespace Content.Server.ParticleAccelerator.Components { State = state; - if (!IoCManager.Resolve().TryGetComponent(Owner, out var physicsComponent)) + if (!_entMan.TryGetComponent(Owner, out var physicsComponent)) { Logger.Error("ParticleProjectile tried firing, but it was spawned without a CollidableComponent"); return; } physicsComponent.BodyStatus = BodyStatus.InAir; - if (!IoCManager.Resolve().TryGetComponent(Owner, out var projectileComponent)) + if (!_entMan.TryGetComponent(Owner, out var projectileComponent)) { Logger.Error("ParticleProjectile tried firing, but it was spawned without a ProjectileComponent"); return; } projectileComponent.IgnoreEntity(firer); - if (!IoCManager.Resolve().TryGetComponent(Owner, out var singuloFoodComponent)) + if (!_entMan.TryGetComponent(Owner, out var singuloFoodComponent)) { Logger.Error("ParticleProjectile tried firing, but it was spawned without a SinguloFoodComponent"); return; @@ -59,7 +61,7 @@ namespace Content.Server.ParticleAccelerator.Components _ => "0" }; - if (!IoCManager.Resolve().TryGetComponent(Owner, out var spriteComponent)) + if (!_entMan.TryGetComponent(Owner, out var spriteComponent)) { Logger.Error("ParticleProjectile tried firing, but it was spawned without a SpriteComponent"); return; @@ -69,8 +71,8 @@ namespace Content.Server.ParticleAccelerator.Components physicsComponent .LinearVelocity = angle.ToWorldVec() * 20f; - IoCManager.Resolve().GetComponent(Owner).LocalRotation = angle; - Timer.Spawn(3000, () => IoCManager.Resolve().DeleteEntity(Owner)); + _entMan.GetComponent(Owner).LocalRotation = angle; + Timer.Spawn(3000, () => _entMan.DeleteEntity(Owner)); } } } diff --git a/Content.Server/Physics/Controllers/ConveyorController.cs b/Content.Server/Physics/Controllers/ConveyorController.cs index 55bafecf2f..146a2985ed 100644 --- a/Content.Server/Physics/Controllers/ConveyorController.cs +++ b/Content.Server/Physics/Controllers/ConveyorController.cs @@ -41,11 +41,12 @@ namespace Content.Server.Physics.Controllers } var direction = system.GetAngle(comp).ToVec(); - var ownerPos = IoCManager.Resolve().GetComponent(comp.Owner).WorldPosition; + var entMan = IoCManager.Resolve(); + var ownerPos = entMan.GetComponent(comp.Owner).WorldPosition; foreach (var (entity, physics) in EntitySystem.Get().GetEntitiesToMove(comp)) { - var itemRelativeToConveyor = IoCManager.Resolve().GetComponent(entity).WorldPosition - ownerPos; + var itemRelativeToConveyor = entMan.GetComponent(entity).WorldPosition - ownerPos; physics.LinearVelocity += Convey(direction, comp.Speed, frameTime, itemRelativeToConveyor); } } diff --git a/Content.Server/Physics/Controllers/MoverController.cs b/Content.Server/Physics/Controllers/MoverController.cs index f35ba06dbb..21ee487a22 100644 --- a/Content.Server/Physics/Controllers/MoverController.cs +++ b/Content.Server/Physics/Controllers/MoverController.cs @@ -270,7 +270,7 @@ namespace Content.Server.Physics.Controllers { if (!mover.Owner.HasTag("FootstepSound")) return; - var transform = IoCManager.Resolve().GetComponent(mover.Owner); + var transform = EntityManager.GetComponent(mover.Owner); var coordinates = transform.Coordinates; var gridId = coordinates.GetGridId(EntityManager); var distanceNeeded = mover.Sprinting ? StepSoundMoveDistanceRunning : StepSoundMoveDistanceWalking; @@ -302,9 +302,9 @@ namespace Content.Server.Physics.Controllers mobMover.StepSoundDistance -= distanceNeeded; - if (IoCManager.Resolve().TryGetComponent(mover.Owner, out var inventory) + if (EntityManager.TryGetComponent(mover.Owner, out var inventory) && inventory.TryGetSlotItem(EquipmentSlotDefines.Slots.SHOES, out var item) - && IoCManager.Resolve().TryGetComponent(item.Owner, out var modifier)) + && EntityManager.TryGetComponent(item.Owner, out var modifier)) { modifier.PlayFootstep(); } @@ -351,7 +351,7 @@ namespace Content.Server.Physics.Controllers SoundSystem.Play( Filter.Pvs(coordinates), soundToPlay, - IoCManager.Resolve().GetComponent(mover).Coordinates, + EntityManager.GetComponent(mover).Coordinates, sprinting ? AudioParams.Default.WithVolume(0.75f) : null); } } diff --git a/Content.Server/Physics/Controllers/SingularityController.cs b/Content.Server/Physics/Controllers/SingularityController.cs index 551a52d76c..eb905f468d 100644 --- a/Content.Server/Physics/Controllers/SingularityController.cs +++ b/Content.Server/Physics/Controllers/SingularityController.cs @@ -21,7 +21,7 @@ namespace Content.Server.Physics.Controllers foreach (var (singularity, physics) in EntityManager.EntityQuery()) { - if (IoCManager.Resolve().HasComponent(singularity.Owner) || + if (EntityManager.HasComponent(singularity.Owner) || singularity.BeingDeletedByAnotherSingularity) continue; singularity.MoveAccumulator -= frameTime; diff --git a/Content.Server/Plants/Components/RandomPottedPlantComponent.cs b/Content.Server/Plants/Components/RandomPottedPlantComponent.cs index 1453fabd13..d3e2a42f57 100644 --- a/Content.Server/Plants/Components/RandomPottedPlantComponent.cs +++ b/Content.Server/Plants/Components/RandomPottedPlantComponent.cs @@ -11,6 +11,8 @@ namespace Content.Server.Plants.Components [RegisterComponent] public class RandomPottedPlantComponent : Component, IMapInit { + [Dependency] private readonly IEntityManager _entMan = default!; + public override string Name => "RandomPottedPlant"; private static readonly string[] RegularPlantStates; @@ -61,7 +63,7 @@ namespace Content.Server.Plants.Components if (_selectedState != null) { - IoCManager.Resolve().GetComponent(Owner).LayerSetState(0, _selectedState); + _entMan.GetComponent(Owner).LayerSetState(0, _selectedState); } } @@ -72,7 +74,7 @@ namespace Content.Server.Plants.Components var list = _plastic ? PlasticPlantStates : RegularPlantStates; _selectedState = random.Pick(list); - IoCManager.Resolve().GetComponent(Owner).LayerSetState(0, _selectedState); + _entMan.GetComponent(Owner).LayerSetState(0, _selectedState); } } } diff --git a/Content.Server/Pointing/Components/PointingArrowComponent.cs b/Content.Server/Pointing/Components/PointingArrowComponent.cs index eabd5e8f08..f914ba684c 100644 --- a/Content.Server/Pointing/Components/PointingArrowComponent.cs +++ b/Content.Server/Pointing/Components/PointingArrowComponent.cs @@ -11,6 +11,8 @@ namespace Content.Server.Pointing.Components [RegisterComponent] public class PointingArrowComponent : SharedPointingArrowComponent { + [Dependency] private readonly IEntityManager _entMan = default!; + /// /// The current amount of seconds left on this arrow. /// @@ -58,7 +60,7 @@ namespace Content.Server.Pointing.Components { base.Startup(); - if (IoCManager.Resolve().TryGetComponent(Owner, out SpriteComponent? sprite)) + if (_entMan.TryGetComponent(Owner, out SpriteComponent? sprite)) { sprite.DrawDepth = (int) DrawDepth.Overlays; } @@ -67,7 +69,7 @@ namespace Content.Server.Pointing.Components public void Update(float frameTime) { var movement = _speed * frameTime * (_up ? 1 : -1); - IoCManager.Resolve().GetComponent(Owner).LocalPosition += (0, movement); + _entMan.GetComponent(Owner).LocalPosition += (0, movement); _duration -= frameTime; _currentStep -= frameTime; @@ -76,12 +78,12 @@ namespace Content.Server.Pointing.Components { if (_rogue) { - IoCManager.Resolve().RemoveComponent(Owner); - IoCManager.Resolve().AddComponent(Owner); + _entMan.RemoveComponent(Owner); + _entMan.AddComponent(Owner); return; } - IoCManager.Resolve().DeleteEntity(Owner); + _entMan.DeleteEntity(Owner); return; } diff --git a/Content.Server/Power/Components/ApcComponent.cs b/Content.Server/Power/Components/ApcComponent.cs index d035104d6c..dd8b3bf215 100644 --- a/Content.Server/Power/Components/ApcComponent.cs +++ b/Content.Server/Power/Components/ApcComponent.cs @@ -24,6 +24,7 @@ namespace Content.Server.Power.Components [ComponentReference(typeof(IActivate))] public class ApcComponent : BaseApcNetComponent, IActivate { + [Dependency] private readonly IEntityManager _entMan = default!; [Dependency] private readonly IGameTiming _gameTiming = default!; public override string Name => "Apc"; @@ -56,7 +57,7 @@ namespace Content.Server.Power.Components [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(ApcUiKey.Key); - public BatteryComponent? Battery => IoCManager.Resolve().TryGetComponent(Owner, out BatteryComponent? batteryComponent) ? batteryComponent : null; + public BatteryComponent? Battery => _entMan.TryGetComponent(Owner, out BatteryComponent? batteryComponent) ? batteryComponent : null; [ComponentDependency] private AccessReader? _accessReader = null; @@ -94,7 +95,7 @@ namespace Content.Server.Power.Components if (_accessReader == null || accessSystem.IsAllowed(_accessReader, attached)) { MainBreakerEnabled = !MainBreakerEnabled; - IoCManager.Resolve().GetComponent(Owner).CanDischarge = MainBreakerEnabled; + _entMan.GetComponent(Owner).CanDischarge = MainBreakerEnabled; _uiDirty = true; SoundSystem.Play(Filter.Pvs(Owner), _onReceiveMessageSound.GetSound(), Owner, AudioParams.Default.WithVolume(-2f)); @@ -113,12 +114,12 @@ namespace Content.Server.Power.Components _lastChargeState = newState; _lastChargeStateChange = _gameTiming.CurTime; - if (IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearance)) + if (_entMan.TryGetComponent(Owner, out AppearanceComponent? appearance)) { appearance.SetData(ApcVisuals.ChargeState, newState); } - if (IoCManager.Resolve().TryGetComponent(Owner, out SharedPointLightComponent? light)) + if (_entMan.TryGetComponent(Owner, out SharedPointLightComponent? light)) { light.Color = newState switch { @@ -131,7 +132,7 @@ namespace Content.Server.Power.Components } } - IoCManager.Resolve().TryGetComponent(Owner, out BatteryComponent? battery); + _entMan.TryGetComponent(Owner, out BatteryComponent? battery); var newCharge = battery?.CurrentCharge; if (newCharge != null && newCharge != _lastCharge && _lastChargeChange + TimeSpan.FromSeconds(VisualsChangeDelay) < _gameTiming.CurTime) @@ -158,7 +159,7 @@ namespace Content.Server.Power.Components private ApcChargeState CalcChargeState() { - if (!IoCManager.Resolve().TryGetComponent(Owner, out BatteryComponent? battery)) + if (!_entMan.TryGetComponent(Owner, out BatteryComponent? battery)) { return ApcChargeState.Lack; } @@ -170,7 +171,7 @@ namespace Content.Server.Power.Components return ApcChargeState.Full; } - var netBattery = IoCManager.Resolve().GetComponent(Owner); + var netBattery = _entMan.GetComponent(Owner); var delta = netBattery.CurrentSupply - netBattery.CurrentReceiving; return delta < 0 ? ApcChargeState.Charging : ApcChargeState.Lack; @@ -182,7 +183,7 @@ namespace Content.Server.Power.Components if (bat == null) return ApcExternalPowerState.None; - var netBat = IoCManager.Resolve().GetComponent(Owner); + var netBat = _entMan.GetComponent(Owner); if (netBat.CurrentReceiving == 0 && netBat.LoadingNetworkDemand != 0) { return ApcExternalPowerState.None; @@ -199,7 +200,7 @@ namespace Content.Server.Power.Components void IActivate.Activate(ActivateEventArgs eventArgs) { - if (!IoCManager.Resolve().TryGetComponent(eventArgs.User, out ActorComponent? actor)) + if (!_entMan.TryGetComponent(eventArgs.User, out ActorComponent? actor)) { return; } diff --git a/Content.Server/Power/Components/ApcPowerReceiverComponent.cs b/Content.Server/Power/Components/ApcPowerReceiverComponent.cs index 9d54dd386d..4a0ae9a80a 100644 --- a/Content.Server/Power/Components/ApcPowerReceiverComponent.cs +++ b/Content.Server/Power/Components/ApcPowerReceiverComponent.cs @@ -24,6 +24,8 @@ namespace Content.Server.Power.Components public class ApcPowerReceiverComponent : Component, IExamine #pragma warning restore 618 { + [Dependency] private readonly IEntityManager _entMan = default!; + public override string Name => "ApcPowerReceiver"; [ViewVariables] @@ -85,9 +87,9 @@ namespace Content.Server.Power.Components #pragma warning disable 618 SendMessage(new PowerChangedMessage(Powered)); #pragma warning restore 618 - IoCManager.Resolve().EventBus.RaiseLocalEvent(Owner, new PowerChangedEvent(Powered, NetworkLoad.ReceivingPower)); + _entMan.EventBus.RaiseLocalEvent(Owner, new PowerChangedEvent(Powered, NetworkLoad.ReceivingPower)); - if (IoCManager.Resolve().TryGetComponent(Owner, out var appearance)) + if (_entMan.TryGetComponent(Owner, out var appearance)) { appearance.SetData(PowerDeviceVisuals.Powered, Powered); } diff --git a/Content.Server/Power/Components/BaseCharger.cs b/Content.Server/Power/Components/BaseCharger.cs index f393984765..e874bf6b07 100644 --- a/Content.Server/Power/Components/BaseCharger.cs +++ b/Content.Server/Power/Components/BaseCharger.cs @@ -19,6 +19,8 @@ namespace Content.Server.Power.Components [ComponentReference(typeof(IInteractUsing))] public abstract class BaseCharger : Component, IActivate, IInteractUsing { + [Dependency] private readonly IEntityManager _entMan = default!; + [ViewVariables] private BatteryComponent? _heldBattery; @@ -97,12 +99,12 @@ namespace Content.Server.Power.Components Container.Remove(heldItem); _heldBattery = null; - if (IoCManager.Resolve().TryGetComponent(user, out HandsComponent? handsComponent)) + if (_entMan.TryGetComponent(user, out HandsComponent? handsComponent)) { - handsComponent.PutInHandOrDrop(IoCManager.Resolve().GetComponent(heldItem)); + handsComponent.PutInHandOrDrop(_entMan.GetComponent(heldItem)); } - if (IoCManager.Resolve().TryGetComponent(heldItem, out ServerBatteryBarrelComponent? batteryBarrelComponent)) + if (_entMan.TryGetComponent(heldItem, out ServerBatteryBarrelComponent? batteryBarrelComponent)) { batteryBarrelComponent.UpdateAppearance(); } @@ -117,7 +119,7 @@ namespace Content.Server.Power.Components private CellChargerStatus GetStatus() { - if (IoCManager.Resolve().TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) && + if (_entMan.TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) && !receiver.Powered) { return CellChargerStatus.Off; @@ -160,13 +162,13 @@ namespace Content.Server.Power.Components // Not called UpdateAppearance just because it messes with the load var status = GetStatus(); if (_status == status || - !IoCManager.Resolve().TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver)) + !_entMan.TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver)) { return; } _status = status; - IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearance); + _entMan.TryGetComponent(Owner, out AppearanceComponent? appearance); switch (_status) { @@ -205,7 +207,7 @@ namespace Content.Server.Power.Components private void TransferPower(float frameTime) { - if (IoCManager.Resolve().TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) && + if (_entMan.TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) && !receiver.Powered) { return; diff --git a/Content.Server/Power/Components/BaseNetConnectorComponent.cs b/Content.Server/Power/Components/BaseNetConnectorComponent.cs index 1737a1412d..cbf232abc2 100644 --- a/Content.Server/Power/Components/BaseNetConnectorComponent.cs +++ b/Content.Server/Power/Components/BaseNetConnectorComponent.cs @@ -18,6 +18,8 @@ namespace Content.Server.Power.Components public abstract class BaseNetConnectorComponent : Component, IBaseNetConnectorComponent { + [Dependency] private readonly IEntityManager _entMan = default!; + [ViewVariables(VVAccess.ReadWrite)] public Voltage Voltage { get => _voltage; set => SetVoltage(value); } [DataField("voltage")] @@ -68,7 +70,7 @@ namespace Content.Server.Power.Components private bool TryFindNet([NotNullWhen(true)] out TNetType? foundNet) { - if (IoCManager.Resolve().TryGetComponent(Owner, out var container)) + if (_entMan.TryGetComponent(Owner, out var container)) { var compatibleNet = container.Nodes.Values .Where(node => (NodeId == null || NodeId == node.Name) && node.NodeGroupID == (NodeGroupID) Voltage) diff --git a/Content.Server/Power/Components/CableComponent.cs b/Content.Server/Power/Components/CableComponent.cs index 0205722fd8..3260c81a1a 100644 --- a/Content.Server/Power/Components/CableComponent.cs +++ b/Content.Server/Power/Components/CableComponent.cs @@ -18,6 +18,8 @@ namespace Content.Server.Power.Components [RegisterComponent] public class CableComponent : Component, IInteractUsing { + [Dependency] private readonly IEntityManager _entMan = default!; + public override string Name => "Cable"; [ViewVariables] @@ -45,11 +47,11 @@ namespace Content.Server.Power.Components if (EntitySystem.Get().TryDoElectrifiedAct(Owner, eventArgs.User)) return false; - IoCManager.Resolve().DeleteEntity(Owner); - var droppedEnt = IoCManager.Resolve().SpawnEntity(_cableDroppedOnCutPrototype, eventArgs.ClickLocation); + _entMan.DeleteEntity(Owner); + var droppedEnt = _entMan.SpawnEntity(_cableDroppedOnCutPrototype, eventArgs.ClickLocation); // TODO: Literally just use a prototype that has a single thing in the stack, it's not that complicated... - if (IoCManager.Resolve().TryGetComponent(droppedEnt, out var stack)) + if (_entMan.TryGetComponent(droppedEnt, out var stack)) EntitySystem.Get().SetCount(droppedEnt, 1, stack); return true; diff --git a/Content.Server/Power/Components/CablePlacerComponent.cs b/Content.Server/Power/Components/CablePlacerComponent.cs index 4372c20dda..d054654692 100644 --- a/Content.Server/Power/Components/CablePlacerComponent.cs +++ b/Content.Server/Power/Components/CablePlacerComponent.cs @@ -15,6 +15,7 @@ namespace Content.Server.Power.Components [RegisterComponent] internal class CablePlacerComponent : Component, IAfterInteract { + [Dependency] private readonly IEntityManager _entMan = default!; [Dependency] private readonly IMapManager _mapManager = default!; /// @@ -40,7 +41,7 @@ namespace Content.Server.Power.Components if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true)) return false; - if(!_mapManager.TryGetGrid(eventArgs.ClickLocation.GetGridId(IoCManager.Resolve()), out var grid)) + if(!_mapManager.TryGetGrid(eventArgs.ClickLocation.GetGridId(_entMan), out var grid)) return false; var snapPos = grid.TileIndicesFor(eventArgs.ClickLocation); @@ -51,17 +52,17 @@ namespace Content.Server.Power.Components foreach (var anchored in grid.GetAnchoredEntities(snapPos)) { - if (IoCManager.Resolve().TryGetComponent(anchored, out var wire) && wire.CableType == _blockingCableType) + if (_entMan.TryGetComponent(anchored, out var wire) && wire.CableType == _blockingCableType) { return false; } } - if (IoCManager.Resolve().TryGetComponent(Owner, out var stack) + if (_entMan.TryGetComponent(Owner, out var stack) && !EntitySystem.Get().Use(Owner, 1, stack)) return false; - IoCManager.Resolve().SpawnEntity(_cablePrototypeID, grid.GridTileToLocal(snapPos)); + _entMan.SpawnEntity(_cablePrototypeID, grid.GridTileToLocal(snapPos)); return true; } } diff --git a/Content.Server/Power/SMES/SmesComponent.cs b/Content.Server/Power/SMES/SmesComponent.cs index 74fe513cb9..9b606f6759 100644 --- a/Content.Server/Power/SMES/SmesComponent.cs +++ b/Content.Server/Power/SMES/SmesComponent.cs @@ -18,6 +18,7 @@ namespace Content.Server.Power.SMES [RegisterComponent] public class SmesComponent : Component { + [Dependency] private readonly IEntityManager _entMan = default!; [Dependency] private readonly IGameTiming _gameTiming = default!; public override string Name => "Smes"; @@ -47,7 +48,7 @@ namespace Content.Server.Power.SMES _lastChargeLevel = newLevel; _lastChargeLevelChange = _gameTiming.CurTime; - if (IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearance)) + if (_entMan.TryGetComponent(Owner, out AppearanceComponent? appearance)) { appearance.SetData(SmesVisuals.LastChargeLevel, newLevel); } @@ -59,7 +60,7 @@ namespace Content.Server.Power.SMES _lastChargeState = newChargeState; _lastChargeStateChange = _gameTiming.CurTime; - if (IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearance)) + if (_entMan.TryGetComponent(Owner, out AppearanceComponent? appearance)) { appearance.SetData(SmesVisuals.LastChargeState, newChargeState); } @@ -68,7 +69,7 @@ namespace Content.Server.Power.SMES private int GetNewChargeLevel() { - if (!IoCManager.Resolve().TryGetComponent(Owner, out BatteryComponent? battery)) + if (!_entMan.TryGetComponent(Owner, out BatteryComponent? battery)) { return 0; } @@ -78,7 +79,7 @@ namespace Content.Server.Power.SMES private ChargeState GetNewChargeState() { - var battery = IoCManager.Resolve().GetComponent(Owner); + var battery = _entMan.GetComponent(Owner); return (battery.CurrentSupply - battery.CurrentReceiving) switch { > 0 => ChargeState.Discharging, diff --git a/Content.Server/Projectiles/Components/HitscanComponent.cs b/Content.Server/Projectiles/Components/HitscanComponent.cs index e802b512cf..5364ef0656 100644 --- a/Content.Server/Projectiles/Components/HitscanComponent.cs +++ b/Content.Server/Projectiles/Components/HitscanComponent.cs @@ -21,6 +21,7 @@ namespace Content.Server.Projectiles.Components [RegisterComponent] public class HitscanComponent : Component { + [Dependency] private readonly IEntityManager _entMan = default!; [Dependency] private readonly IGameTiming _gameTiming = default!; public override string Name => "Hitscan"; @@ -56,12 +57,12 @@ namespace Content.Server.Projectiles.Components var mapManager = IoCManager.Resolve(); // We'll get the effects relative to the grid / map of the firer - var gridOrMap = IoCManager.Resolve().GetComponent(user).GridID == GridId.Invalid ? mapManager.GetMapEntityId(IoCManager.Resolve().GetComponent(user).MapID) : - mapManager.GetGrid(IoCManager.Resolve().GetComponent(user).GridID).GridEntityId; + var gridOrMap = _entMan.GetComponent(user).GridID == GridId.Invalid ? mapManager.GetMapEntityId(_entMan.GetComponent(user).MapID) : + mapManager.GetGrid(_entMan.GetComponent(user).GridID).GridEntityId; - var parentXform = IoCManager.Resolve().GetComponent(gridOrMap); + var parentXform = _entMan.GetComponent(gridOrMap); - var localCoordinates = new EntityCoordinates(gridOrMap, parentXform.InvWorldMatrix.Transform(IoCManager.Resolve().GetComponent(user).WorldPosition)); + var localCoordinates = new EntityCoordinates(gridOrMap, parentXform.InvWorldMatrix.Transform(_entMan.GetComponent(user).WorldPosition)); var localAngle = angle - parentXform.WorldRotation; var afterEffect = AfterEffects(localCoordinates, localAngle, distance, 1.0f); @@ -96,9 +97,9 @@ namespace Content.Server.Projectiles.Components Owner.SpawnTimer((int) _deathTime.TotalMilliseconds, () => { - if (!((!IoCManager.Resolve().EntityExists(Owner) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(Owner).EntityLifeStage) >= EntityLifeStage.Deleted)) + if (!((!_entMan.EntityExists(Owner) ? EntityLifeStage.Deleted : _entMan.GetComponent(Owner).EntityLifeStage) >= EntityLifeStage.Deleted)) { - IoCManager.Resolve().DeleteEntity(Owner); + _entMan.DeleteEntity(Owner); } }); } @@ -161,7 +162,7 @@ namespace Content.Server.Projectiles.Components EffectSprite = _impactFlash, Born = _startTime, DeathTime = _deathTime, - Coordinates = IoCManager.Resolve().GetComponent(Owner).Coordinates.Offset(angle.ToVec() * distance), + Coordinates = _entMan.GetComponent(Owner).Coordinates.Offset(angle.ToVec() * distance), //Rotated from east facing Rotation = (float) angle.FlipPositive(), Color = Vector4.Multiply(new Vector4(255, 255, 255, 750), ColorModifier), diff --git a/Content.Server/Radiation/RadiationPulseComponent.cs b/Content.Server/Radiation/RadiationPulseComponent.cs index a83d968d29..85dc0a33ca 100644 --- a/Content.Server/Radiation/RadiationPulseComponent.cs +++ b/Content.Server/Radiation/RadiationPulseComponent.cs @@ -15,6 +15,7 @@ namespace Content.Server.Radiation [ComponentReference(typeof(SharedRadiationPulseComponent))] public sealed class RadiationPulseComponent : SharedRadiationPulseComponent { + [Dependency] private readonly IEntityManager _entMan = default!; [Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly IRobustRandom _random = default!; @@ -107,11 +108,11 @@ namespace Content.Server.Radiation public void Update(float frameTime) { - if (!Decay || (!IoCManager.Resolve().EntityExists(Owner) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(Owner).EntityLifeStage) >= EntityLifeStage.Deleted) + if (!Decay || (!_entMan.EntityExists(Owner) ? EntityLifeStage.Deleted : _entMan.GetComponent(Owner).EntityLifeStage) >= EntityLifeStage.Deleted) return; if (_duration <= 0f) - IoCManager.Resolve().QueueDeleteEntity(Owner); + _entMan.QueueDeleteEntity(Owner); _duration -= frameTime; } diff --git a/Content.Server/Radiation/RadiationPulseSystem.cs b/Content.Server/Radiation/RadiationPulseSystem.cs index eef664fcd4..b42f923b28 100644 --- a/Content.Server/Radiation/RadiationPulseSystem.cs +++ b/Content.Server/Radiation/RadiationPulseSystem.cs @@ -12,6 +12,7 @@ namespace Content.Server.Radiation [UsedImplicitly] public sealed class RadiationPulseSystem : EntitySystem { + [Dependency] private readonly IEntityManager _entMan = default!; [Dependency] private readonly IEntityLookup _lookup = default!; private const float RadiationCooldown = 0.5f; @@ -33,16 +34,16 @@ namespace Content.Server.Radiation comp.Update(RadiationCooldown); var ent = comp.Owner; - if ((!IoCManager.Resolve().EntityExists(ent) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(ent).EntityLifeStage) >= EntityLifeStage.Deleted) continue; + if ((!_entMan.EntityExists(ent) ? EntityLifeStage.Deleted : _entMan.GetComponent(ent).EntityLifeStage) >= EntityLifeStage.Deleted) continue; - foreach (var entity in _lookup.GetEntitiesInRange(IoCManager.Resolve().GetComponent(ent).Coordinates, comp.Range)) + foreach (var entity in _lookup.GetEntitiesInRange(_entMan.GetComponent(ent).Coordinates, comp.Range)) { // For now at least still need this because it uses a list internally then returns and this may be deleted before we get to it. - if ((!IoCManager.Resolve().EntityExists(entity) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(entity).EntityLifeStage) >= EntityLifeStage.Deleted) continue; + if ((!_entMan.EntityExists(entity) ? EntityLifeStage.Deleted : _entMan.GetComponent(entity).EntityLifeStage) >= EntityLifeStage.Deleted) continue; // Note: Radiation is liable for a refactor (stinky Sloth coding a basic version when he did StationEvents) // so this ToArray doesn't really matter. - foreach (var radiation in IoCManager.Resolve().GetComponents(entity).ToArray()) + foreach (var radiation in _entMan.GetComponents(entity).ToArray()) { radiation.RadiationAct(RadiationCooldown, comp); } diff --git a/Content.Server/Recycling/Components/RecyclableComponent.cs b/Content.Server/Recycling/Components/RecyclableComponent.cs index 89834beb0b..df546fe876 100644 --- a/Content.Server/Recycling/Components/RecyclableComponent.cs +++ b/Content.Server/Recycling/Components/RecyclableComponent.cs @@ -8,6 +8,8 @@ namespace Content.Server.Recycling.Components [RegisterComponent] public class RecyclableComponent : Component { + [Dependency] private readonly IEntityManager _entMan = default!; + public override string Name => "Recyclable"; /// @@ -33,12 +35,12 @@ namespace Content.Server.Recycling.Components { for (var i = 0; i < Math.Max(_amount * efficiency, 1); i++) { - IoCManager.Resolve().SpawnEntity(_prototype, IoCManager.Resolve().GetComponent(Owner).Coordinates); + _entMan.SpawnEntity(_prototype, _entMan.GetComponent(Owner).Coordinates); } } - IoCManager.Resolve().QueueDeleteEntity(Owner); + _entMan.QueueDeleteEntity(Owner); } } } diff --git a/Content.Server/Recycling/Components/RecyclerComponent.cs b/Content.Server/Recycling/Components/RecyclerComponent.cs index e4608a1f5f..bc01f03034 100644 --- a/Content.Server/Recycling/Components/RecyclerComponent.cs +++ b/Content.Server/Recycling/Components/RecyclerComponent.cs @@ -21,6 +21,8 @@ namespace Content.Server.Recycling.Components [Friend(typeof(RecyclerSystem))] public class RecyclerComponent : Component, ISuicideAct { + [Dependency] private readonly IEntityManager _entMan = default!; + public override string Name => "Recycler"; /// @@ -39,7 +41,7 @@ namespace Content.Server.Recycling.Components private void Clean() { - if (IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearance)) + if (_entMan.TryGetComponent(Owner, out AppearanceComponent? appearance)) { appearance.SetData(RecyclerVisuals.Bloody, false); } @@ -47,7 +49,7 @@ namespace Content.Server.Recycling.Components SuicideKind ISuicideAct.Suicide(EntityUid victim, IChatManager chat) { - if (IoCManager.Resolve().TryGetComponent(victim, out ActorComponent? actor) && actor.PlayerSession.ContentData()?.Mind is {} mind) + if (_entMan.TryGetComponent(victim, out ActorComponent? actor) && actor.PlayerSession.ContentData()?.Mind is {} mind) { EntitySystem.Get().OnGhostAttempt(mind, false); mind.OwnedEntity?.PopupMessage(Loc.GetString("recycler-component-suicide-message")); @@ -55,7 +57,7 @@ namespace Content.Server.Recycling.Components victim.PopupMessageOtherClients(Loc.GetString("recycler-component-suicide-message-others", ("victim",victim))); - if (IoCManager.Resolve().TryGetComponent(victim, out var body)) + if (_entMan.TryGetComponent(victim, out var body)) { body.Gib(true); } diff --git a/Content.Server/Research/Components/ResearchConsoleComponent.cs b/Content.Server/Research/Components/ResearchConsoleComponent.cs index 46ac37cb7c..ef9c6a35b8 100644 --- a/Content.Server/Research/Components/ResearchConsoleComponent.cs +++ b/Content.Server/Research/Components/ResearchConsoleComponent.cs @@ -22,12 +22,13 @@ namespace Content.Server.Research.Components [ComponentReference(typeof(IActivate))] public class ResearchConsoleComponent : SharedResearchConsoleComponent, IActivate { + [Dependency] private readonly IEntityManager _entMan = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!; [DataField("sound")] private SoundSpecifier _soundCollectionName = new SoundCollectionSpecifier("keyboard"); - [ViewVariables] private bool Powered => !IoCManager.Resolve().TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered; + [ViewVariables] private bool Powered => !_entMan.TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered; [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(ResearchConsoleUiKey.Key); @@ -47,9 +48,9 @@ namespace Content.Server.Research.Components private void UserInterfaceOnOnReceiveMessage(ServerBoundUserInterfaceMessage message) { - if (!IoCManager.Resolve().TryGetComponent(Owner, out TechnologyDatabaseComponent? database)) + if (!_entMan.TryGetComponent(Owner, out TechnologyDatabaseComponent? database)) return; - if (!IoCManager.Resolve().TryGetComponent(Owner, out ResearchClientComponent? client)) + if (!_entMan.TryGetComponent(Owner, out ResearchClientComponent? client)) return; if (!Powered) return; @@ -90,7 +91,7 @@ namespace Content.Server.Research.Components private ResearchConsoleBoundInterfaceState GetNewUiState() { - if (!IoCManager.Resolve().TryGetComponent(Owner, out ResearchClientComponent? client) || + if (!_entMan.TryGetComponent(Owner, out ResearchClientComponent? client) || client.Server == null) return new ResearchConsoleBoundInterfaceState(default, default); @@ -111,7 +112,7 @@ namespace Content.Server.Research.Components void IActivate.Activate(ActivateEventArgs eventArgs) { - if (!IoCManager.Resolve().TryGetComponent(eventArgs.User, out ActorComponent? actor)) + if (!_entMan.TryGetComponent(eventArgs.User, out ActorComponent? actor)) return; if (!Powered) { diff --git a/Content.Server/Sandbox/Commands/ColorNetworkCommand.cs b/Content.Server/Sandbox/Commands/ColorNetworkCommand.cs index 59a4537cda..80d511a27a 100644 --- a/Content.Server/Sandbox/Commands/ColorNetworkCommand.cs +++ b/Content.Server/Sandbox/Commands/ColorNetworkCommand.cs @@ -55,7 +55,7 @@ namespace Content.Server.Sandbox.Commands return; } - if (!IoCManager.Resolve().TryGetComponent(eUid, out NodeContainerComponent? nodeContainerComponent)) + if (!entityManager.TryGetComponent(eUid, out NodeContainerComponent? nodeContainerComponent)) { shell.WriteLine(Loc.GetString("shell-entity-is-not-node-container")); return; diff --git a/Content.Server/Singularity/Components/ContainmentFieldGeneratorComponent.cs b/Content.Server/Singularity/Components/ContainmentFieldGeneratorComponent.cs index dd7c353cc8..bbe9a0a190 100644 --- a/Content.Server/Singularity/Components/ContainmentFieldGeneratorComponent.cs +++ b/Content.Server/Singularity/Components/ContainmentFieldGeneratorComponent.cs @@ -17,6 +17,8 @@ namespace Content.Server.Singularity.Components [ComponentReference(typeof(SharedContainmentFieldGeneratorComponent))] public class ContainmentFieldGeneratorComponent : SharedContainmentFieldGeneratorComponent { + [Dependency] private readonly IEntityManager _entMan = default!; + private int _powerBuffer; [ViewVariables] @@ -95,9 +97,9 @@ namespace Content.Server.Singularity.Components { if (_connection1?.Item1 == direction || _connection2?.Item1 == direction) continue; - var dirVec = IoCManager.Resolve().GetComponent(Owner).WorldRotation.RotateVec(direction.ToVec()); - var ray = new CollisionRay(IoCManager.Resolve().GetComponent(Owner).WorldPosition, dirVec, (int) CollisionGroup.MobMask); - var rawRayCastResults = EntitySystem.Get().IntersectRay(IoCManager.Resolve().GetComponent(Owner).MapID, ray, 4.5f, Owner, false); + var dirVec = _entMan.GetComponent(Owner).WorldRotation.RotateVec(direction.ToVec()); + var ray = new CollisionRay(_entMan.GetComponent(Owner).WorldPosition, dirVec, (int) CollisionGroup.MobMask); + var rawRayCastResults = EntitySystem.Get().IntersectRay(_entMan.GetComponent(Owner).MapID, ray, 4.5f, Owner, false); var rayCastResults = rawRayCastResults as RayCastResults[] ?? rawRayCastResults.ToArray(); if(!rayCastResults.Any()) continue; @@ -113,11 +115,11 @@ namespace Content.Server.Singularity.Components } if(closestResult == null) continue; var ent = closestResult.Value.HitEntity; - if (!IoCManager.Resolve().TryGetComponent(ent, out var fieldGeneratorComponent) || + if (!_entMan.TryGetComponent(ent, out var fieldGeneratorComponent) || fieldGeneratorComponent.Owner == Owner || !fieldGeneratorComponent.HasFreeConnections() || IsConnectedWith(fieldGeneratorComponent) || - !IoCManager.Resolve().TryGetComponent(ent, out var collidableComponent) || + !_entMan.TryGetComponent(ent, out var collidableComponent) || collidableComponent.BodyType != BodyType.Static) { continue; diff --git a/Content.Server/Singularity/Components/ServerSingularityComponent.cs b/Content.Server/Singularity/Components/ServerSingularityComponent.cs index 14a4dfc007..1fa0a855bf 100644 --- a/Content.Server/Singularity/Components/ServerSingularityComponent.cs +++ b/Content.Server/Singularity/Components/ServerSingularityComponent.cs @@ -14,6 +14,8 @@ namespace Content.Server.Singularity.Components [ComponentReference(typeof(SharedSingularityComponent))] public class ServerSingularityComponent : SharedSingularityComponent { + [Dependency] private readonly IEntityManager _entMan = default!; + private SharedSingularitySystem _singularitySystem = default!; [ViewVariables(VVAccess.ReadWrite)] @@ -27,7 +29,7 @@ namespace Content.Server.Singularity.Components _energy = value; if (_energy <= 0) { - IoCManager.Resolve().DeleteEntity(Owner); + _entMan.DeleteEntity(Owner); return; } @@ -92,7 +94,7 @@ namespace Content.Server.Singularity.Components protected override void Shutdown() { base.Shutdown(); - SoundSystem.Play(Filter.Pvs(Owner), _singularityCollapsingSound.GetSound(), IoCManager.Resolve().GetComponent(Owner).Coordinates); + SoundSystem.Play(Filter.Pvs(Owner), _singularityCollapsingSound.GetSound(), _entMan.GetComponent(Owner).Coordinates); } } } diff --git a/Content.Server/Singularity/Components/SingularityGenerator.cs b/Content.Server/Singularity/Components/SingularityGenerator.cs index 91a281d9a6..fbf93e7ba7 100644 --- a/Content.Server/Singularity/Components/SingularityGenerator.cs +++ b/Content.Server/Singularity/Components/SingularityGenerator.cs @@ -7,6 +7,8 @@ namespace Content.Server.Singularity.Components [RegisterComponent] public class SingularityGeneratorComponent : Component { + [Dependency] private readonly IEntityManager _entMan = default!; + public override string Name => "SingularityGenerator"; [ViewVariables] private int _power; @@ -21,8 +23,7 @@ namespace Content.Server.Singularity.Components _power = value; if (_power > 15) { - var entityManager = IoCManager.Resolve(); - entityManager.SpawnEntity("Singularity", IoCManager.Resolve().GetComponent(Owner).Coordinates); + _entMan.SpawnEntity("Singularity", _entMan.GetComponent(Owner).Coordinates); //dont delete ourselves, just wait to get eaten } } diff --git a/Content.Server/Spawners/Components/ConditionalSpawnerComponent.cs b/Content.Server/Spawners/Components/ConditionalSpawnerComponent.cs index 85ab8301e9..31a1b566be 100644 --- a/Content.Server/Spawners/Components/ConditionalSpawnerComponent.cs +++ b/Content.Server/Spawners/Components/ConditionalSpawnerComponent.cs @@ -12,6 +12,7 @@ namespace Content.Server.Spawners.Components [RegisterComponent] public class ConditionalSpawnerComponent : Component, IMapInit { + [Dependency] private readonly IEntityManager _entMan = default!; [Dependency] private readonly IRobustRandom _robustRandom = default!; public override string Name => "ConditionalSpawner"; @@ -61,8 +62,8 @@ namespace Content.Server.Spawners.Components return; } - if(!((!IoCManager.Resolve().EntityExists(Owner) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(Owner).EntityLifeStage) >= EntityLifeStage.Deleted)) - IoCManager.Resolve().SpawnEntity(_robustRandom.Pick(Prototypes), IoCManager.Resolve().GetComponent(Owner).Coordinates); + if(_entMan.Deleted(Owner)) + _entMan.SpawnEntity(_robustRandom.Pick(Prototypes), _entMan.GetComponent(Owner).Coordinates); } public virtual void MapInit() diff --git a/Content.Server/Spawners/Components/RandomSpawnerComponent.cs b/Content.Server/Spawners/Components/RandomSpawnerComponent.cs index 7b0ae6490c..5c1ac36e25 100644 --- a/Content.Server/Spawners/Components/RandomSpawnerComponent.cs +++ b/Content.Server/Spawners/Components/RandomSpawnerComponent.cs @@ -12,6 +12,7 @@ namespace Content.Server.Spawners.Components [RegisterComponent] public class RandomSpawnerComponent : ConditionalSpawnerComponent { + [Dependency] private readonly IEntityManager _entMan = default!; [Dependency] private readonly IRobustRandom _robustRandom = default!; public override string Name => "RandomSpawner"; @@ -32,7 +33,7 @@ namespace Content.Server.Spawners.Components { if (RarePrototypes.Count > 0 && (RareChance == 1.0f || _robustRandom.Prob(RareChance))) { - IoCManager.Resolve().SpawnEntity(_robustRandom.Pick(RarePrototypes), IoCManager.Resolve().GetComponent(Owner).Coordinates); + _entMan.SpawnEntity(_robustRandom.Pick(RarePrototypes), _entMan.GetComponent(Owner).Coordinates); return; } @@ -47,15 +48,15 @@ namespace Content.Server.Spawners.Components return; } - if(!((!IoCManager.Resolve().EntityExists(Owner) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(Owner).EntityLifeStage) >= EntityLifeStage.Deleted)) + if(!((!_entMan.EntityExists(Owner) ? EntityLifeStage.Deleted : _entMan.GetComponent(Owner).EntityLifeStage) >= EntityLifeStage.Deleted)) { var random = IoCManager.Resolve(); var x_negative = random.Prob(0.5f) ? -1 : 1; var y_negative = random.Prob(0.5f) ? -1 : 1; - var entity = IoCManager.Resolve().SpawnEntity(_robustRandom.Pick(Prototypes), IoCManager.Resolve().GetComponent(Owner).Coordinates); - IoCManager.Resolve().GetComponent(entity).LocalPosition += new Vector2(random.NextFloat() * Offset * x_negative, random.NextFloat() * Offset * y_negative); + var entity = _entMan.SpawnEntity(_robustRandom.Pick(Prototypes), _entMan.GetComponent(Owner).Coordinates); + _entMan.GetComponent(entity).LocalPosition += new Vector2(random.NextFloat() * Offset * x_negative, random.NextFloat() * Offset * y_negative); } } @@ -63,7 +64,7 @@ namespace Content.Server.Spawners.Components public override void MapInit() { Spawn(); - IoCManager.Resolve().DeleteEntity(Owner); + _entMan.DeleteEntity(Owner); } } } diff --git a/Content.Server/StationEvents/Events/PowerGridCheck.cs b/Content.Server/StationEvents/Events/PowerGridCheck.cs index 93c424e644..b9e65a5bbe 100644 --- a/Content.Server/StationEvents/Events/PowerGridCheck.cs +++ b/Content.Server/StationEvents/Events/PowerGridCheck.cs @@ -51,11 +51,13 @@ namespace Content.Server.StationEvents.Events public override void Shutdown() { + var entMan = IoCManager.Resolve(); + foreach (var entity in _powered) { - if ((!IoCManager.Resolve().EntityExists(entity) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(entity).EntityLifeStage) >= EntityLifeStage.Deleted) continue; + if (entMan.Deleted(entity)) continue; - if (IoCManager.Resolve().TryGetComponent(entity, out ApcPowerReceiverComponent? powerReceiverComponent)) + if (entMan.TryGetComponent(entity, out ApcPowerReceiverComponent? powerReceiverComponent)) { powerReceiverComponent.PowerDisabled = false; } diff --git a/Content.Server/StationEvents/Events/RadiationStorm.cs b/Content.Server/StationEvents/Events/RadiationStorm.cs index 34bd8455a0..fc4dc173a4 100644 --- a/Content.Server/StationEvents/Events/RadiationStorm.cs +++ b/Content.Server/StationEvents/Events/RadiationStorm.cs @@ -89,15 +89,15 @@ namespace Content.Server.StationEvents.Events return; var pulse = _entityManager.SpawnEntity("RadiationPulse", coordinates); - IoCManager.Resolve().GetComponent(pulse).DoPulse(); + _entityManager.GetComponent(pulse).DoPulse(); ResetTimeUntilPulse(); } - public static void SpawnPulseAt(EntityCoordinates at) + public void SpawnPulseAt(EntityCoordinates at) { var pulse = IoCManager.Resolve() .SpawnEntity("RadiationPulse", at); - IoCManager.Resolve().GetComponent(pulse).DoPulse(); + _entityManager.GetComponent(pulse).DoPulse(); } private bool TryFindRandomGrid(IMapGrid mapGrid, out EntityCoordinates coordinates) diff --git a/Content.Server/Storage/Components/CursedEntityStorageComponent.cs b/Content.Server/Storage/Components/CursedEntityStorageComponent.cs index 56c39043d8..061e471b28 100644 --- a/Content.Server/Storage/Components/CursedEntityStorageComponent.cs +++ b/Content.Server/Storage/Components/CursedEntityStorageComponent.cs @@ -17,6 +17,7 @@ namespace Content.Server.Storage.Components [RegisterComponent] public class CursedEntityStorageComponent : EntityStorageComponent { + [Dependency] private readonly IEntityManager _entMan = default!; [Dependency] private readonly IRobustRandom _robustRandom = default!; public override string Name => "CursedEntityStorage"; @@ -31,7 +32,7 @@ namespace Content.Server.Storage.Components // No contents, we do nothing if (Contents.ContainedEntities.Count == 0) return; - var lockers = IoCManager.Resolve().EntityQuery().Select(c => c.Owner).ToList(); + var lockers = _entMan.EntityQuery().Select(c => c.Owner).ToList(); if (lockers.Contains(Owner)) lockers.Remove(Owner); @@ -40,7 +41,7 @@ namespace Content.Server.Storage.Components if (lockerEnt == null) return; // No valid lockers anywhere. - var locker = IoCManager.Resolve().GetComponent(lockerEnt); + var locker = _entMan.GetComponent(lockerEnt); if (locker.Open) locker.TryCloseStorage(Owner); diff --git a/Content.Server/Storage/Components/EntityStorageComponent.cs b/Content.Server/Storage/Components/EntityStorageComponent.cs index 72e58cea4b..3bdd3cf325 100644 --- a/Content.Server/Storage/Components/EntityStorageComponent.cs +++ b/Content.Server/Storage/Components/EntityStorageComponent.cs @@ -33,6 +33,8 @@ namespace Content.Server.Storage.Components [ComponentReference(typeof(IStorageComponent))] public class EntityStorageComponent : Component, IActivate, IStorageComponent, IInteractUsing, IDestroyAct, IExAct { + [Dependency] private readonly IEntityManager _entMan = default!; + public override string Name => "EntityStorage"; private const float MaxSize = 1.0f; // maximum width or height of an entity allowed inside the storage. @@ -148,7 +150,7 @@ namespace Content.Server.Storage.Components Contents.ShowContents = _showContents; Contents.OccludesLight = _occludesLight; - if (IoCManager.Resolve().TryGetComponent(Owner, out var surface)) + if (_entMan.TryGetComponent(Owner, out var surface)) { EntitySystem.Get().SetPlaceable(Owner, Open, surface); } @@ -169,7 +171,7 @@ namespace Content.Server.Storage.Components return false; } - if (IoCManager.Resolve().TryGetComponent(Owner, out var @lock) && @lock.Locked) + if (_entMan.TryGetComponent(Owner, out var @lock) && @lock.Locked) { if (!silent) Owner.PopupMessage(user, Loc.GetString("entity-storage-component-locked-message")); return false; @@ -214,14 +216,14 @@ namespace Content.Server.Storage.Components // 5. if this is NOT AN ITEM, then mobs can always be eaten unless unless a previous law prevents it // Let's not insert admin ghosts, yeah? This is really a a hack and should be replaced by attempt events - if (IoCManager.Resolve().HasComponent(entity)) + if (_entMan.HasComponent(entity)) continue; // checks - var targetIsItem = IoCManager.Resolve().HasComponent(entity); - var targetIsMob = IoCManager.Resolve().HasComponent(entity); - var storageIsItem = IoCManager.Resolve().HasComponent(Owner); + var targetIsItem = _entMan.HasComponent(entity); + var targetIsMob = _entMan.HasComponent(entity); + var storageIsItem = _entMan.HasComponent(Owner); var allowedToEat = false; @@ -266,7 +268,7 @@ namespace Content.Server.Storage.Components private void UpdateAppearance() { - if (IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearance)) + if (_entMan.TryGetComponent(Owner, out AppearanceComponent? appearance)) { appearance.SetData(StorageVisuals.CanWeld, _canWeldShut); appearance.SetData(StorageVisuals.Welded, _isWeldedShut); @@ -275,7 +277,7 @@ namespace Content.Server.Storage.Components private void ModifyComponents() { - if (!_isCollidableWhenOpen && IoCManager.Resolve().TryGetComponent(Owner, out var manager)) + if (!_isCollidableWhenOpen && _entMan.TryGetComponent(Owner, out var manager)) { if (Open) { @@ -293,12 +295,12 @@ namespace Content.Server.Storage.Components } } - if (IoCManager.Resolve().TryGetComponent(Owner, out var surface)) + if (_entMan.TryGetComponent(Owner, out var surface)) { EntitySystem.Get().SetPlaceable(Owner, Open, surface); } - if (IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearance)) + if (_entMan.TryGetComponent(Owner, out AppearanceComponent? appearance)) { appearance.SetData(StorageVisuals.Open, Open); } @@ -307,7 +309,7 @@ namespace Content.Server.Storage.Components protected virtual bool AddToContents(EntityUid entity) { if (entity == Owner) return false; - if (IoCManager.Resolve().TryGetComponent(entity, out IPhysBody? entityPhysicsComponent)) + if (_entMan.TryGetComponent(entity, out IPhysBody? entityPhysicsComponent)) { if (MaxSize < entityPhysicsComponent.GetWorldAABB().Size.X || MaxSize < entityPhysicsComponent.GetWorldAABB().Size.Y) @@ -321,7 +323,7 @@ namespace Content.Server.Storage.Components public virtual Vector2 ContentsDumpPosition() { - return IoCManager.Resolve().GetComponent(Owner).WorldPosition; + return _entMan.GetComponent(Owner).WorldPosition; } private void EmptyContents() @@ -330,8 +332,8 @@ namespace Content.Server.Storage.Components { if (Contents.Remove(contained)) { - IoCManager.Resolve().GetComponent(contained).WorldPosition = ContentsDumpPosition(); - if (IoCManager.Resolve().TryGetComponent(contained, out var physics)) + _entMan.GetComponent(contained).WorldPosition = ContentsDumpPosition(); + if (_entMan.TryGetComponent(contained, out var physics)) { physics.CanCollide = true; } @@ -365,7 +367,7 @@ namespace Content.Server.Storage.Components // Trying to add while open just dumps it on the ground below us. if (Open) { - var entMan = IoCManager.Resolve(); + var entMan = _entMan; entMan.GetComponent(entity).WorldPosition = entMan.GetComponent(Owner).WorldPosition; return true; } @@ -453,7 +455,7 @@ namespace Content.Server.Storage.Components var containedEntities = Contents.ContainedEntities.ToList(); foreach (var entity in containedEntities) { - var exActs = IoCManager.Resolve().GetComponents(entity).ToArray(); + var exActs = _entMan.GetComponents(entity).ToArray(); foreach (var exAct in exActs) { exAct.OnExplosion(eventArgs); diff --git a/Content.Server/Storage/Components/SecretStashComponent.cs b/Content.Server/Storage/Components/SecretStashComponent.cs index 5521d7d402..30e8992a59 100644 --- a/Content.Server/Storage/Components/SecretStashComponent.cs +++ b/Content.Server/Storage/Components/SecretStashComponent.cs @@ -18,7 +18,7 @@ namespace Content.Server.Storage.Components [RegisterComponent] public class SecretStashComponent : Component, IDestroyAct { - [Dependency] private readonly IEntityManager _entities = default!; + [Dependency] private readonly IEntityManager _entMan = default!; public override string Name => "SecretStash"; @@ -30,7 +30,7 @@ namespace Content.Server.Storage.Components [ViewVariables] private ContainerSlot _itemContainer = default!; - public string SecretPartName => _secretPartNameOverride ?? Loc.GetString("comp-secret-stash-secret-part-name", ("name", IoCManager.Resolve().GetComponent(Owner).EntityName)); + public string SecretPartName => _secretPartNameOverride ?? Loc.GetString("comp-secret-stash-secret-part-name", ("name", _entMan.GetComponent(Owner).EntityName)); protected override void Initialize() { @@ -52,7 +52,7 @@ namespace Content.Server.Storage.Components return false; } - if (!IoCManager.Resolve().TryGetComponent(itemToHide, out ItemComponent? item)) + if (!_entMan.TryGetComponent(itemToHide, out ItemComponent? item)) return false; if (item.Size > _maxItemSize) @@ -62,7 +62,7 @@ namespace Content.Server.Storage.Components return false; } - if (!IoCManager.Resolve().TryGetComponent(user, out HandsComponent? hands)) + if (!_entMan.TryGetComponent(user, out HandsComponent? hands)) return false; if (!hands.Drop(itemToHide, _itemContainer)) @@ -85,15 +85,15 @@ namespace Content.Server.Storage.Components Owner.PopupMessage(user, Loc.GetString("comp-secret-stash-action-get-item-found-something", ("stash", SecretPartName))); - if (IoCManager.Resolve().TryGetComponent(user, out HandsComponent? hands)) + if (_entMan.TryGetComponent(user, out HandsComponent? hands)) { - if (!IoCManager.Resolve().TryGetComponent(contained, out ItemComponent? item)) + if (!_entMan.TryGetComponent(contained, out ItemComponent? item)) return false; hands.PutInHandOrDrop(item); } else if (_itemContainer.Remove(contained)) { - IoCManager.Resolve().GetComponent(contained).Coordinates = IoCManager.Resolve().GetComponent(Owner).Coordinates; + _entMan.GetComponent(contained).Coordinates = _entMan.GetComponent(Owner).Coordinates; } return true; @@ -113,7 +113,7 @@ namespace Content.Server.Storage.Components // drop item inside if (_itemContainer.ContainedEntity is {Valid: true} contained) { - _entities.GetComponent(contained).Coordinates = _entities.GetComponent(Owner).Coordinates; + _entMan.GetComponent(contained).Coordinates = _entMan.GetComponent(Owner).Coordinates; } } } diff --git a/Content.Server/Storage/Components/StorageFillComponent.cs b/Content.Server/Storage/Components/StorageFillComponent.cs index 3e01d3f707..84c1823ca3 100644 --- a/Content.Server/Storage/Components/StorageFillComponent.cs +++ b/Content.Server/Storage/Components/StorageFillComponent.cs @@ -15,6 +15,8 @@ namespace Content.Server.Storage.Components [RegisterComponent] public sealed class StorageFillComponent : Component, IMapInit { + [Dependency] private readonly IEntityManager _entMan = default!; + public override string Name => "StorageFill"; [DataField("contents")] private List _contents = new(); @@ -28,7 +30,7 @@ namespace Content.Server.Storage.Components return; } - if (!IoCManager.Resolve().TryGetComponent(Owner, out IStorageComponent? storage)) + if (!_entMan.TryGetComponent(Owner, out IStorageComponent? storage)) { Logger.Error($"StorageFillComponent couldn't find any StorageComponent ({Owner})"); return; @@ -48,7 +50,7 @@ namespace Content.Server.Storage.Components continue; } - var entMan = IoCManager.Resolve(); + var entMan = _entMan; var transform = entMan.GetComponent(Owner); for (var i = 0; i < storageItem.Amount; i++) diff --git a/Content.Server/Suspicion/SuspicionRoleComponent.cs b/Content.Server/Suspicion/SuspicionRoleComponent.cs index 4554d20b8b..df51ff8537 100644 --- a/Content.Server/Suspicion/SuspicionRoleComponent.cs +++ b/Content.Server/Suspicion/SuspicionRoleComponent.cs @@ -22,6 +22,8 @@ namespace Content.Server.Suspicion public class SuspicionRoleComponent : SharedSuspicionRoleComponent, IExamine #pragma warning restore 618 { + [Dependency] private readonly IEntityManager _entMan = default!; + private Role? _role; [ViewVariables] private readonly HashSet _allies = new(); @@ -60,7 +62,7 @@ namespace Content.Server.Suspicion public bool IsDead() { - return IoCManager.Resolve().TryGetComponent(Owner, out MobStateComponent? state) && + return _entMan.TryGetComponent(Owner, out MobStateComponent? state) && state.IsDead(); } @@ -76,7 +78,7 @@ namespace Content.Server.Suspicion public void SyncRoles() { - if (!IoCManager.Resolve().TryGetComponent(Owner, out MindComponent? mind) || + if (!_entMan.TryGetComponent(Owner, out MindComponent? mind) || !mind.HasMind) { return; diff --git a/Content.Server/Tiles/FloorTileItemComponent.cs b/Content.Server/Tiles/FloorTileItemComponent.cs index d7bdc4c295..825cdcb71a 100644 --- a/Content.Server/Tiles/FloorTileItemComponent.cs +++ b/Content.Server/Tiles/FloorTileItemComponent.cs @@ -20,6 +20,7 @@ namespace Content.Server.Tiles [RegisterComponent] public class FloorTileItemComponent : Component, IAfterInteract { + [Dependency] private readonly IEntityManager _entMan = default!; [Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!; public override string Name => "FloorTile"; @@ -58,16 +59,16 @@ namespace Content.Server.Tiles if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true)) return true; - if (!IoCManager.Resolve().TryGetComponent(Owner, out StackComponent? stack)) + if (!_entMan.TryGetComponent(Owner, out StackComponent? stack)) return true; var mapManager = IoCManager.Resolve(); var location = eventArgs.ClickLocation.AlignWithClosestGridTile(); - var locationMap = location.ToMap(IoCManager.Resolve()); + var locationMap = location.ToMap(_entMan); if (locationMap.MapId == MapId.Nullspace) return true; - mapManager.TryGetGrid(location.GetGridId(IoCManager.Resolve()), out var mapGrid); + mapManager.TryGetGrid(location.GetGridId(_entMan), out var mapGrid); if (_outputTiles == null) return true; diff --git a/Content.Server/Toilet/ToiletComponent.cs b/Content.Server/Toilet/ToiletComponent.cs index a753d902a9..b44f600799 100644 --- a/Content.Server/Toilet/ToiletComponent.cs +++ b/Content.Server/Toilet/ToiletComponent.cs @@ -34,6 +34,8 @@ namespace Content.Server.Toilet IInteractHand, IMapInit, IExamine, ISuicideAct #pragma warning restore 618 { + [Dependency] private readonly IEntityManager _entMan = default!; + public sealed override string Name => "Toilet"; private const float PryLidTime = 1f; @@ -67,7 +69,7 @@ namespace Content.Server.Toilet async Task IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs) { // are player trying place or lift of cistern lid? - if (IoCManager.Resolve().TryGetComponent(eventArgs.Using, out ToolComponent? tool) + if (_entMan.TryGetComponent(eventArgs.Using, out ToolComponent? tool) && tool.Qualities.Contains(_pryingQuality)) { // check if someone is already prying this toilet @@ -111,7 +113,7 @@ namespace Content.Server.Toilet // just want to up/down seat? // check that nobody seats on seat right now - if (IoCManager.Resolve().TryGetComponent(Owner, out StrapComponent? strap)) + if (_entMan.TryGetComponent(Owner, out StrapComponent? strap)) { if (strap.BuckledEntities.Count != 0) return false; @@ -142,7 +144,7 @@ namespace Content.Server.Toilet private void UpdateSprite() { - if (IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearance)) + if (_entMan.TryGetComponent(Owner, out AppearanceComponent? appearance)) { appearance.SetData(ToiletVisuals.LidOpen, LidOpen); appearance.SetData(ToiletVisuals.SeatUp, IsSeatUp); @@ -152,23 +154,23 @@ namespace Content.Server.Toilet SuicideKind ISuicideAct.Suicide(EntityUid victim, IChatManager chat) { // check that victim even have head - if (IoCManager.Resolve().TryGetComponent(victim, out var body) && + if (_entMan.TryGetComponent(victim, out var body) && body.HasPartOfType(BodyPartType.Head)) { - var othersMessage = Loc.GetString("toilet-component-suicide-head-message-others", ("victim",Name: IoCManager.Resolve().GetComponent(victim).EntityName),("owner", Name: IoCManager.Resolve().GetComponent(Owner).EntityName)); + var othersMessage = Loc.GetString("toilet-component-suicide-head-message-others", ("victim",Name: _entMan.GetComponent(victim).EntityName),("owner", Name: _entMan.GetComponent(Owner).EntityName)); victim.PopupMessageOtherClients(othersMessage); - var selfMessage = Loc.GetString("toilet-component-suicide-head-message", ("owner", Name: IoCManager.Resolve().GetComponent(Owner).EntityName)); + var selfMessage = Loc.GetString("toilet-component-suicide-head-message", ("owner", Name: _entMan.GetComponent(Owner).EntityName)); victim.PopupMessage(selfMessage); return SuicideKind.Asphyxiation; } else { - var othersMessage = Loc.GetString("toilet-component-suicide-message-others",("victim", Name: IoCManager.Resolve().GetComponent(victim).EntityName),("owner", Name: IoCManager.Resolve().GetComponent(Owner).EntityName)); + var othersMessage = Loc.GetString("toilet-component-suicide-message-others",("victim", Name: _entMan.GetComponent(victim).EntityName),("owner", Name: _entMan.GetComponent(Owner).EntityName)); victim.PopupMessageOtherClients(othersMessage); - var selfMessage = Loc.GetString("toilet-component-suicide-message", ("owner",Name: IoCManager.Resolve().GetComponent(Owner).EntityName)); + var selfMessage = Loc.GetString("toilet-component-suicide-message", ("owner",Name: _entMan.GetComponent(Owner).EntityName)); victim.PopupMessage(selfMessage); return SuicideKind.Blunt; diff --git a/Content.Server/Tools/Components/TilePryingComponent.cs b/Content.Server/Tools/Components/TilePryingComponent.cs index 108848d0b3..37123df84b 100644 --- a/Content.Server/Tools/Components/TilePryingComponent.cs +++ b/Content.Server/Tools/Components/TilePryingComponent.cs @@ -14,6 +14,7 @@ namespace Content.Server.Tools.Components [RegisterComponent] public class TilePryingComponent : Component, IAfterInteract { + [Dependency] private readonly IEntityManager _entMan = default!; [Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!; [Dependency] private readonly IMapManager _mapManager = default!; @@ -33,10 +34,10 @@ namespace Content.Server.Tools.Components public async void TryPryTile(EntityUid user, EntityCoordinates clickLocation) { - if (!IoCManager.Resolve().TryGetComponent(Owner, out var tool) && _toolComponentNeeded) + if (!_entMan.TryGetComponent(Owner, out var tool) && _toolComponentNeeded) return; - if (!_mapManager.TryGetGrid(clickLocation.GetGridId(IoCManager.Resolve()), out var mapGrid)) + if (!_mapManager.TryGetGrid(clickLocation.GetGridId(_entMan), out var mapGrid)) return; var tile = mapGrid.GetTileRef(clickLocation); @@ -54,7 +55,7 @@ namespace Content.Server.Tools.Components if (_toolComponentNeeded && !await EntitySystem.Get().UseTool(Owner, user, null, 0f, 0f, _qualityNeeded, toolComponent:tool)) return; - coordinates.PryTile(IoCManager.Resolve(), _mapManager); + coordinates.PryTile(_entMan, _mapManager); } } } diff --git a/Content.Server/TraitorDeathMatch/Components/TraitorDeathMatchRedemptionComponent.cs b/Content.Server/TraitorDeathMatch/Components/TraitorDeathMatchRedemptionComponent.cs index 654562cf1d..12fea6870f 100644 --- a/Content.Server/TraitorDeathMatch/Components/TraitorDeathMatchRedemptionComponent.cs +++ b/Content.Server/TraitorDeathMatch/Components/TraitorDeathMatchRedemptionComponent.cs @@ -15,19 +15,21 @@ namespace Content.Server.TraitorDeathMatch.Components [RegisterComponent] public class TraitorDeathMatchRedemptionComponent : Component, IInteractUsing { + [Dependency] private readonly IEntityManager _entMan = default!; + /// public override string Name => "TraitorDeathMatchRedemption"; async Task IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs) { - if (!IoCManager.Resolve().TryGetComponent(eventArgs.User, out var userInv)) + if (!_entMan.TryGetComponent(eventArgs.User, out var userInv)) { Owner.PopupMessage(eventArgs.User, Loc.GetString("traitor-death-match-redemption-component-interact-using-main-message", ("secondMessage", Loc.GetString("traitor-death-match-redemption-component-interact-using-no-inventory-message")))); return false; } - if (!IoCManager.Resolve().TryGetComponent(eventArgs.User, out var userMindComponent)) + if (!_entMan.TryGetComponent(eventArgs.User, out var userMindComponent)) { Owner.PopupMessage(eventArgs.User, Loc.GetString("traitor-death-match-redemption-component-interact-using-main-message", ("secondMessage", Loc.GetString("traitor-death-match-redemption-component-interact-using-no-mind-message")))); @@ -42,14 +44,14 @@ namespace Content.Server.TraitorDeathMatch.Components return false; } - if (!IoCManager.Resolve().TryGetComponent(eventArgs.Using, out var victimUplink)) + if (!_entMan.TryGetComponent(eventArgs.Using, out var victimUplink)) { Owner.PopupMessage(eventArgs.User, Loc.GetString("traitor-death-match-redemption-component-interact-using-main-message", ("secondMessage", Loc.GetString("traitor-death-match-redemption-component-interact-using-no-pda-message")))); return false; } - if (!IoCManager.Resolve().TryGetComponent(eventArgs.Using, out var victimPDAOwner)) + if (!_entMan.TryGetComponent(eventArgs.Using, out var victimPDAOwner)) { Owner.PopupMessage(eventArgs.User, Loc.GetString("traitor-death-match-redemption-component-interact-using-main-message", ("secondMessage", Loc.GetString("traitor-death-match-redemption-component-interact-using-no-pda-owner-message")))); @@ -66,7 +68,7 @@ namespace Content.Server.TraitorDeathMatch.Components UplinkComponent? userUplink = null; if (userInv.GetSlotItem(EquipmentSlotDefines.Slots.IDCARD)?.Owner is {Valid: true} userPDAEntity) - if (IoCManager.Resolve().TryGetComponent(userPDAEntity, out var userUplinkComponent)) + if (_entMan.TryGetComponent(userPDAEntity, out var userUplinkComponent)) userUplink = userUplinkComponent; if (userUplink == null) @@ -104,12 +106,12 @@ namespace Content.Server.TraitorDeathMatch.Components } // 4 is the per-PDA bonus amount. - var accounts = IoCManager.Resolve().EntitySysManager.GetEntitySystem(); + var accounts = _entMan.EntitySysManager.GetEntitySystem(); var transferAmount = victimAccount.Balance + 4; accounts.SetBalance(victimAccount, 0); accounts.AddToBalance(userAccount, transferAmount); - IoCManager.Resolve().DeleteEntity(victimUplink.Owner); + _entMan.DeleteEntity(victimUplink.Owner); Owner.PopupMessage(eventArgs.User, Loc.GetString("traitor-death-match-redemption-component-interact-using-success-message", ("tcAmount", transferAmount))); return true; diff --git a/Content.Server/VendingMachines/VendingMachineComponent.cs b/Content.Server/VendingMachines/VendingMachineComponent.cs index cd0f07f226..192e8611f8 100644 --- a/Content.Server/VendingMachines/VendingMachineComponent.cs +++ b/Content.Server/VendingMachines/VendingMachineComponent.cs @@ -29,6 +29,7 @@ namespace Content.Server.VendingMachines [ComponentReference(typeof(IActivate))] public class VendingMachineComponent : SharedVendingMachineComponent, IActivate, IBreakAct, IWires { + [Dependency] private readonly IEntityManager _entMan = default!; [Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!; @@ -38,7 +39,7 @@ namespace Content.Server.VendingMachines private string _packPrototypeId = string.Empty; private string _spriteName = ""; - private bool Powered => !IoCManager.Resolve().TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered; + private bool Powered => !_entMan.TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered; private bool _broken; [DataField("soundVend")] @@ -54,14 +55,14 @@ namespace Content.Server.VendingMachines void IActivate.Activate(ActivateEventArgs eventArgs) { - if(!IoCManager.Resolve().TryGetComponent(eventArgs.User, out ActorComponent? actor)) + if(!_entMan.TryGetComponent(eventArgs.User, out ActorComponent? actor)) { return; } if (!Powered) return; - var wires = IoCManager.Resolve().GetComponent(Owner); + var wires = _entMan.GetComponent(Owner); if (wires.IsPanelOpen) { wires.OpenInterface(actor.PlayerSession); @@ -79,12 +80,12 @@ namespace Content.Server.VendingMachines return; } - IoCManager.Resolve().GetComponent(Owner).EntityName = packPrototype.Name; + _entMan.GetComponent(Owner).EntityName = packPrototype.Name; _animationDuration = TimeSpan.FromSeconds(packPrototype.AnimationDuration); _spriteName = packPrototype.SpriteName; if (!string.IsNullOrEmpty(_spriteName)) { - var spriteComponent = IoCManager.Resolve().GetComponent(Owner); + var spriteComponent = _entMan.GetComponent(Owner); const string vendingMachineRSIPath = "Structures/Machines/VendingMachines/{0}.rsi"; spriteComponent.BaseRSIPath = string.Format(vendingMachineRSIPath, _spriteName); } @@ -106,7 +107,7 @@ namespace Content.Server.VendingMachines UserInterface.OnReceiveMessage += UserInterfaceOnOnReceiveMessage; } - if (IoCManager.Resolve().TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver)) + if (_entMan.TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver)) { TrySetVisualState(receiver.Powered ? VendingMachineVisualState.Normal : VendingMachineVisualState.Off); } @@ -182,7 +183,7 @@ namespace Content.Server.VendingMachines { _ejecting = false; TrySetVisualState(VendingMachineVisualState.Normal); - IoCManager.Resolve().SpawnEntity(id, IoCManager.Resolve().GetComponent(Owner).Coordinates); + _entMan.SpawnEntity(id, _entMan.GetComponent(Owner).Coordinates); }); SoundSystem.Play(Filter.Pvs(Owner), _soundVend.GetSound(), Owner, AudioParams.Default.WithVolume(-2f)); @@ -190,7 +191,7 @@ namespace Content.Server.VendingMachines private void TryEject(string id, EntityUid? sender) { - if (IoCManager.Resolve().TryGetComponent(Owner, out var accessReader)) + if (_entMan.TryGetComponent(Owner, out var accessReader)) { var accessSystem = EntitySystem.Get(); if (sender == null || !accessSystem.IsAllowed(accessReader, sender.Value)) @@ -232,7 +233,7 @@ namespace Content.Server.VendingMachines finalState = VendingMachineVisualState.Off; } - if (IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearance)) + if (_entMan.TryGetComponent(Owner, out AppearanceComponent? appearance)) { appearance.SetData(VendingMachineVisuals.VisualState, finalState); } diff --git a/Content.Server/Weapon/Ranged/Ammunition/Components/AmmoComponent.cs b/Content.Server/Weapon/Ranged/Ammunition/Components/AmmoComponent.cs index d5ee001c85..a12ca95d19 100644 --- a/Content.Server/Weapon/Ranged/Ammunition/Components/AmmoComponent.cs +++ b/Content.Server/Weapon/Ranged/Ammunition/Components/AmmoComponent.cs @@ -25,6 +25,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components public class AmmoComponent : Component, IExamine, ISerializationHooks #pragma warning restore 618 { + [Dependency] private readonly IEntityManager _entMan = default!; [Dependency] private readonly IGameTiming _gameTiming = default!; public override string Name => "Ammo"; @@ -117,12 +118,12 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components } _spent = true; - if (IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearanceComponent)) + if (_entMan.TryGetComponent(Owner, out AppearanceComponent? appearanceComponent)) { appearanceComponent.SetData(AmmoVisuals.Spent, true); } - var entity = IoCManager.Resolve().SpawnEntity(_projectileId, spawnAt); + var entity = _entMan.SpawnEntity(_projectileId, spawnAt); return entity; } diff --git a/Content.Server/Weapon/Ranged/Ammunition/Components/SpeedLoaderComponent.cs b/Content.Server/Weapon/Ranged/Ammunition/Components/SpeedLoaderComponent.cs index b35f1d9fb8..5105f106b6 100644 --- a/Content.Server/Weapon/Ranged/Ammunition/Components/SpeedLoaderComponent.cs +++ b/Content.Server/Weapon/Ranged/Ammunition/Components/SpeedLoaderComponent.cs @@ -20,6 +20,8 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components [RegisterComponent] public class SpeedLoaderComponent : Component, IAfterInteract, IInteractUsing, IMapInit, IUse { + [Dependency] private readonly IEntityManager _entMan = default!; + public override string Name => "SpeedLoader"; [DataField("caliber")] @@ -59,7 +61,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components private void UpdateAppearance() { - if (IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearanceComponent)) + if (_entMan.TryGetComponent(Owner, out AppearanceComponent? appearanceComponent)) { appearanceComponent?.SetData(MagazineBarrelVisuals.MagLoaded, true); appearanceComponent?.SetData(AmmoVisuals.AmmoCount, AmmoLeft); @@ -69,7 +71,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components public bool TryInsertAmmo(EntityUid user, EntityUid entity) { - if (!IoCManager.Resolve().TryGetComponent(entity, out AmmoComponent? ammoComponent)) + if (!_entMan.TryGetComponent(entity, out AmmoComponent? ammoComponent)) { return false; } @@ -95,7 +97,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components private bool UseEntity(EntityUid user) { - if (!IoCManager.Resolve().TryGetComponent(user, out HandsComponent? handsComponent)) + if (!_entMan.TryGetComponent(user, out HandsComponent? handsComponent)) { return false; } @@ -106,7 +108,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components return false; } - var itemComponent = IoCManager.Resolve().GetComponent(ammo); + var itemComponent = _entMan.GetComponent(ammo); if (!handsComponent.CanPutInHand(itemComponent)) { ServerRangedBarrelComponent.EjectCasing(ammo); @@ -130,7 +132,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components if (_unspawnedCount > 0) { - entity = IoCManager.Resolve().SpawnEntity(_fillPrototype, IoCManager.Resolve().GetComponent(Owner).Coordinates); + entity = _entMan.SpawnEntity(_fillPrototype, _entMan.GetComponent(Owner).Coordinates); _unspawnedCount--; } @@ -147,7 +149,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components // This area is dirty but not sure of an easier way to do it besides add an interface or somethin var changed = false; - var entities = IoCManager.Resolve(); + var entities = _entMan; if (entities.TryGetComponent(eventArgs.Target.Value, out RevolverBarrelComponent? revolverBarrel)) { for (var i = 0; i < Capacity; i++) @@ -169,7 +171,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components break; } } - else if (IoCManager.Resolve().TryGetComponent(eventArgs.Target.Value, out BoltActionBarrelComponent? boltActionBarrel)) + else if (_entMan.TryGetComponent(eventArgs.Target.Value, out BoltActionBarrelComponent? boltActionBarrel)) { for (var i = 0; i < Capacity; i++) { diff --git a/Content.Server/Weapon/Ranged/Barrels/Components/PumpBarrelComponent.cs b/Content.Server/Weapon/Ranged/Barrels/Components/PumpBarrelComponent.cs index fe4c146299..6b90cf9917 100644 --- a/Content.Server/Weapon/Ranged/Barrels/Components/PumpBarrelComponent.cs +++ b/Content.Server/Weapon/Ranged/Barrels/Components/PumpBarrelComponent.cs @@ -27,6 +27,8 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components [NetworkedComponent()] public sealed class PumpBarrelComponent : ServerRangedBarrelComponent, IUse, IInteractUsing, IMapInit, ISerializationHooks { + [Dependency] private readonly IEntityManager _entMan = default!; + public override string Name => "PumpBarrel"; public override int ShotsLeft @@ -85,7 +87,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components // (Is one chambered?, is the bullet spend) var chamber = (chamberedExists, false); - if (chamberedExists && IoCManager.Resolve().TryGetComponent(_chamberContainer.ContainedEntity!.Value, out var ammo)) + if (chamberedExists && _entMan.TryGetComponent(_chamberContainer.ContainedEntity!.Value, out var ammo)) { chamber.Item2 = ammo.Spent; } @@ -124,7 +126,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components _unspawnedCount--; } - if (IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearanceComponent)) + if (_entMan.TryGetComponent(Owner, out AppearanceComponent? appearanceComponent)) { _appearanceComponent = appearanceComponent; } @@ -159,7 +161,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components if (_chamberContainer.ContainedEntity is not {Valid: true} chamberEntity) return null; - return IoCManager.Resolve().GetComponentOrNull(chamberEntity)?.TakeBullet(spawnAt); + return _entMan.GetComponentOrNull(chamberEntity)?.TakeBullet(spawnAt); } private void Cycle(bool manual = false) @@ -167,7 +169,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components if (_chamberContainer.ContainedEntity is {Valid: true} chamberedEntity) { _chamberContainer.Remove(chamberedEntity); - var ammoComponent = IoCManager.Resolve().GetComponent(chamberedEntity); + var ammoComponent = _entMan.GetComponent(chamberedEntity); if (!ammoComponent.Caseless) { EjectCasing(chamberedEntity); @@ -183,7 +185,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components if (_unspawnedCount > 0) { _unspawnedCount--; - var ammoEntity = IoCManager.Resolve().SpawnEntity(_fillPrototype, IoCManager.Resolve().GetComponent(Owner).Coordinates); + var ammoEntity = _entMan.SpawnEntity(_fillPrototype, _entMan.GetComponent(Owner).Coordinates); _chamberContainer.Insert(ammoEntity); } @@ -198,7 +200,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components public bool TryInsertBullet(InteractUsingEventArgs eventArgs) { - if (!IoCManager.Resolve().TryGetComponent(eventArgs.Using, out AmmoComponent? ammoComponent)) + if (!_entMan.TryGetComponent(eventArgs.Using, out AmmoComponent? ammoComponent)) { return false; } diff --git a/Content.Server/Weapon/Ranged/Barrels/Components/RevolverBarrelComponent.cs b/Content.Server/Weapon/Ranged/Barrels/Components/RevolverBarrelComponent.cs index 09ca4e45c6..6966a64f88 100644 --- a/Content.Server/Weapon/Ranged/Barrels/Components/RevolverBarrelComponent.cs +++ b/Content.Server/Weapon/Ranged/Barrels/Components/RevolverBarrelComponent.cs @@ -24,6 +24,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components [NetworkedComponent()] public sealed class RevolverBarrelComponent : ServerRangedBarrelComponent, IUse, IInteractUsing, ISerializationHooks { + [Dependency] private readonly IEntityManager _entMan = default!; [Dependency] private readonly IRobustRandom _random = default!; public override string Name => "RevolverBarrel"; @@ -81,7 +82,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components { slotsSpent[i] = null; var ammoEntity = _ammoSlots[i]; - if (ammoEntity != default && IoCManager.Resolve().TryGetComponent(ammoEntity, out AmmoComponent? ammo)) + if (ammoEntity != default && _entMan.TryGetComponent(ammoEntity, out AmmoComponent? ammo)) { slotsSpent[i] = ammo.Spent; } @@ -113,7 +114,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components for (var i = 0; i < _unspawnedCount; i++) { - var entity = IoCManager.Resolve().SpawnEntity(_fillPrototype, IoCManager.Resolve().GetComponent(Owner).Coordinates); + var entity = _entMan.SpawnEntity(_fillPrototype, _entMan.GetComponent(Owner).Coordinates); _ammoSlots[idx] = entity; _ammoContainer.Insert(entity); idx++; @@ -125,7 +126,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components private void UpdateAppearance() { - if (!IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearance)) + if (!_entMan.TryGetComponent(Owner, out AppearanceComponent? appearance)) { return; } @@ -138,7 +139,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components public bool TryInsertBullet(EntityUid user, EntityUid entity) { - if (!IoCManager.Resolve().TryGetComponent(entity, out AmmoComponent? ammoComponent)) + if (!_entMan.TryGetComponent(entity, out AmmoComponent? ammoComponent)) { return false; } @@ -208,7 +209,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components EntityUid? bullet = null; if (ammo != default) { - var ammoComponent = IoCManager.Resolve().GetComponent(ammo); + var ammoComponent = _entMan.GetComponent(ammo); bullet = ammoComponent.TakeBullet(spawnAt); if (ammoComponent.Caseless) { diff --git a/Content.Server/Weapon/Ranged/ServerRangedWeaponComponent.cs b/Content.Server/Weapon/Ranged/ServerRangedWeaponComponent.cs index ae2cdb74a7..ec4e3d6a71 100644 --- a/Content.Server/Weapon/Ranged/ServerRangedWeaponComponent.cs +++ b/Content.Server/Weapon/Ranged/ServerRangedWeaponComponent.cs @@ -30,6 +30,7 @@ namespace Content.Server.Weapon.Ranged [RegisterComponent] public sealed class ServerRangedWeaponComponent : SharedRangedWeaponComponent, IHandSelected { + [Dependency] private readonly IEntityManager _entMan = default!; [Dependency] private readonly IMapManager _mapManager = default!; [Dependency] private readonly IGameTiming _gameTiming = default!; @@ -143,12 +144,12 @@ namespace Content.Server.Weapon.Ranged /// Target position on the map to shoot at. private void TryFire(EntityUid user, Vector2 targetPos) { - if (!IoCManager.Resolve().TryGetComponent(user, out HandsComponent? hands) || hands.GetActiveHand?.Owner != Owner) + if (!_entMan.TryGetComponent(user, out HandsComponent? hands) || hands.GetActiveHand?.Owner != Owner) { return; } - if (!IoCManager.Resolve().TryGetComponent(user, out CombatModeComponent? combat) || !combat.IsInCombatMode) + if (!_entMan.TryGetComponent(user, out CombatModeComponent? combat) || !combat.IsInCombatMode) { return; } @@ -176,21 +177,21 @@ namespace Content.Server.Weapon.Ranged // Apply salt to the wound ("Honk!") SoundSystem.Play( Filter.Pvs(Owner), _clumsyWeaponHandlingSound.GetSound(), - IoCManager.Resolve().GetComponent(Owner).Coordinates, AudioParams.Default.WithMaxDistance(5)); + _entMan.GetComponent(Owner).Coordinates, AudioParams.Default.WithMaxDistance(5)); SoundSystem.Play( Filter.Pvs(Owner), _clumsyWeaponShotSound.GetSound(), - IoCManager.Resolve().GetComponent(Owner).Coordinates, AudioParams.Default.WithMaxDistance(5)); + _entMan.GetComponent(Owner).Coordinates, AudioParams.Default.WithMaxDistance(5)); user.PopupMessage(Loc.GetString("server-ranged-weapon-component-try-fire-clumsy")); - IoCManager.Resolve().DeleteEntity(Owner); + _entMan.DeleteEntity(Owner); return; } if (_canHotspot) { - EntitySystem.Get().HotspotExpose(IoCManager.Resolve().GetComponent(user).Coordinates, 700, 50); + EntitySystem.Get().HotspotExpose(_entMan.GetComponent(user).Coordinates, 700, 50); } FireHandler?.Invoke(user, targetPos); } diff --git a/Content.Server/Weapon/WeaponCapacitorChargerComponent.cs b/Content.Server/Weapon/WeaponCapacitorChargerComponent.cs index 0407634442..3f0563ee03 100644 --- a/Content.Server/Weapon/WeaponCapacitorChargerComponent.cs +++ b/Content.Server/Weapon/WeaponCapacitorChargerComponent.cs @@ -15,17 +15,19 @@ namespace Content.Server.Weapon [ComponentReference(typeof(BaseCharger))] public sealed class WeaponCapacitorChargerComponent : BaseCharger { + [Dependency] private readonly IEntityManager _entMan = default!; + public override string Name => "WeaponCapacitorCharger"; public override bool IsEntityCompatible(EntityUid entity) { - return IoCManager.Resolve().TryGetComponent(entity, out ServerBatteryBarrelComponent? battery) && battery.PowerCell != null || - IoCManager.Resolve().TryGetComponent(entity, out PowerCellSlotComponent? slot) && slot.HasCell; + return _entMan.TryGetComponent(entity, out ServerBatteryBarrelComponent? battery) && battery.PowerCell != null || + _entMan.TryGetComponent(entity, out PowerCellSlotComponent? slot) && slot.HasCell; } protected override BatteryComponent? GetBatteryFrom(EntityUid entity) { - if (IoCManager.Resolve().TryGetComponent(entity, out PowerCellSlotComponent? slot)) + if (_entMan.TryGetComponent(entity, out PowerCellSlotComponent? slot)) { if (slot.Cell != null) { @@ -33,7 +35,7 @@ namespace Content.Server.Weapon } } - if (IoCManager.Resolve().TryGetComponent(entity, out ServerBatteryBarrelComponent? battery)) + if (_entMan.TryGetComponent(entity, out ServerBatteryBarrelComponent? battery)) { if (battery.PowerCell != null) { diff --git a/Content.Server/Window/WindowComponent.cs b/Content.Server/Window/WindowComponent.cs index d1f4669a9f..150e00a0a8 100644 --- a/Content.Server/Window/WindowComponent.cs +++ b/Content.Server/Window/WindowComponent.cs @@ -27,6 +27,7 @@ namespace Content.Server.Window public class WindowComponent : SharedWindowComponent, IExamine, IInteractHand #pragma warning restore 618 { + [Dependency] private readonly IEntityManager _entMan = default!; [Dependency] private readonly IGameTiming _gameTiming = default!; [ViewVariables(VVAccess.ReadWrite)] private TimeSpan _lastKnockTime; @@ -43,8 +44,8 @@ namespace Content.Server.Window void IExamine.Examine(FormattedMessage message, bool inDetailsRange) { - if (!IoCManager.Resolve().TryGetComponent(Owner, out DamageableComponent? damageable) || - !IoCManager.Resolve().TryGetComponent(Owner, out DestructibleComponent? destructible)) + if (!_entMan.TryGetComponent(Owner, out DamageableComponent? damageable) || + !_entMan.TryGetComponent(Owner, out DestructibleComponent? destructible)) { return; } @@ -104,7 +105,7 @@ namespace Content.Server.Window SoundSystem.Play( Filter.Pvs(eventArgs.Target), _knockSound.GetSound(), - IoCManager.Resolve().GetComponent(eventArgs.Target).Coordinates, AudioHelpers.WithVariation(0.05f)); + _entMan.GetComponent(eventArgs.Target).Coordinates, AudioHelpers.WithVariation(0.05f)); eventArgs.Target.PopupMessageEveryone(Loc.GetString("comp-window-knock")); _lastKnockTime = _gameTiming.CurTime; diff --git a/Content.Shared/Actions/Behaviors/Item/IItemActionBehavior.cs b/Content.Shared/Actions/Behaviors/Item/IItemActionBehavior.cs index 864310906c..d185eb6281 100644 --- a/Content.Shared/Actions/Behaviors/Item/IItemActionBehavior.cs +++ b/Content.Shared/Actions/Behaviors/Item/IItemActionBehavior.cs @@ -41,10 +41,11 @@ namespace Content.Shared.Actions.Behaviors.Item Performer = performer; ActionType = actionType; Item = item; - if (!IoCManager.Resolve().TryGetComponent(Item, out ItemActions)) + var entMan = IoCManager.Resolve(); + if (!entMan.TryGetComponent(Item, out ItemActions)) { - throw new InvalidOperationException($"performer {IoCManager.Resolve().GetComponent(performer).EntityName} tried to perform item action {actionType} " + - $" for item {IoCManager.Resolve().GetComponent(Item).EntityName} but the item had no ItemActionsComponent," + + throw new InvalidOperationException($"performer {entMan.GetComponent(performer).EntityName} tried to perform item action {actionType} " + + $" for item {entMan.GetComponent(Item).EntityName} but the item had no ItemActionsComponent," + " which should never occur"); } } diff --git a/Content.Shared/Body/Components/SharedBodyPartComponent.cs b/Content.Shared/Body/Components/SharedBodyPartComponent.cs index 6e496125b6..03ccea1019 100644 --- a/Content.Shared/Body/Components/SharedBodyPartComponent.cs +++ b/Content.Shared/Body/Components/SharedBodyPartComponent.cs @@ -18,6 +18,8 @@ namespace Content.Shared.Body.Components [NetworkedComponent()] public abstract class SharedBodyPartComponent : Component, IBodyPartContainer { + [Dependency] private readonly IEntityManager _entMan = default!; + public override string Name => "BodyPart"; private SharedBodyComponent? _body; @@ -109,11 +111,11 @@ namespace Content.Shared.Body.Components public BodyPartSymmetry Symmetry { get; private set; } = BodyPartSymmetry.None; [ViewVariables] - public ISurgeryData? SurgeryDataComponent => IoCManager.Resolve().GetComponentOrNull(Owner); + public ISurgeryData? SurgeryDataComponent => _entMan.GetComponentOrNull(Owner); protected virtual void OnAddMechanism(SharedMechanismComponent mechanism) { - var prototypeId = IoCManager.Resolve().GetComponent(mechanism.Owner).EntityPrototype!.ID; + var prototypeId = _entMan.GetComponent(mechanism.Owner).EntityPrototype!.ID; if (!_mechanismIds.Contains(prototypeId)) { @@ -128,7 +130,7 @@ namespace Content.Shared.Body.Components protected virtual void OnRemoveMechanism(SharedMechanismComponent mechanism) { - _mechanismIds.Remove(IoCManager.Resolve().GetComponent(mechanism.Owner).EntityPrototype!.ID); + _mechanismIds.Remove(_entMan.GetComponent(mechanism.Owner).EntityPrototype!.ID); mechanism.Part = null; SizeUsed -= mechanism.Size; @@ -267,7 +269,7 @@ namespace Content.Shared.Body.Components { if (RemoveMechanism(mechanism)) { - IoCManager.Resolve().GetComponent(mechanism.Owner).Coordinates = coordinates; + _entMan.GetComponent(mechanism.Owner).Coordinates = coordinates; return true; } @@ -292,34 +294,34 @@ namespace Content.Shared.Body.Components return false; } - IoCManager.Resolve().DeleteEntity(mechanism.Owner); + _entMan.DeleteEntity(mechanism.Owner); return true; } private void AddedToBody(SharedBodyComponent body) { - IoCManager.Resolve().GetComponent(Owner).LocalRotation = 0; - IoCManager.Resolve().GetComponent(Owner).AttachParent(body.Owner); + _entMan.GetComponent(Owner).LocalRotation = 0; + _entMan.GetComponent(Owner).AttachParent(body.Owner); OnAddedToBody(body); foreach (var mechanism in _mechanisms) { - IoCManager.Resolve().EventBus.RaiseLocalEvent(mechanism.Owner, new AddedToBodyEvent(body)); + _entMan.EventBus.RaiseLocalEvent(mechanism.Owner, new AddedToBodyEvent(body)); } } private void RemovedFromBody(SharedBodyComponent old) { - if (!IoCManager.Resolve().GetComponent(Owner).Deleted) + if (!_entMan.GetComponent(Owner).Deleted) { - IoCManager.Resolve().GetComponent(Owner).AttachToGridOrMap(); + _entMan.GetComponent(Owner).AttachToGridOrMap(); } OnRemovedFromBody(old); foreach (var mechanism in _mechanisms) { - IoCManager.Resolve().EventBus.RaiseLocalEvent(mechanism.Owner, new RemovedFromBodyEvent(old)); + _entMan.EventBus.RaiseLocalEvent(mechanism.Owner, new RemovedFromBodyEvent(old)); } } @@ -358,7 +360,7 @@ namespace Content.Shared.Body.Components return _mechanisms; } - entityManager ??= IoCManager.Resolve(); + entityManager ??= _entMan; var mechanisms = new List(MechanismIds.Length); diff --git a/Content.Shared/Body/Components/SharedMechanismComponent.cs b/Content.Shared/Body/Components/SharedMechanismComponent.cs index c8bc821454..811521887b 100644 --- a/Content.Shared/Body/Components/SharedMechanismComponent.cs +++ b/Content.Shared/Body/Components/SharedMechanismComponent.cs @@ -10,6 +10,8 @@ namespace Content.Shared.Body.Components { public abstract class SharedMechanismComponent : Component, ISerializationHooks { + [Dependency] private readonly IEntityManager _entMan = default!; + public override string Name => "Mechanism"; protected readonly Dictionary OptionsCache = new(); @@ -37,11 +39,11 @@ namespace Content.Shared.Body.Components { if (old.Body == null) { - IoCManager.Resolve().EventBus.RaiseLocalEvent(Owner, new RemovedFromPartEvent(old)); + _entMan.EventBus.RaiseLocalEvent(Owner, new RemovedFromPartEvent(old)); } else { - IoCManager.Resolve().EventBus.RaiseLocalEvent(Owner, new RemovedFromPartInBodyEvent(old.Body, old)); + _entMan.EventBus.RaiseLocalEvent(Owner, new RemovedFromPartInBodyEvent(old.Body, old)); } } @@ -49,11 +51,11 @@ namespace Content.Shared.Body.Components { if (value.Body == null) { - IoCManager.Resolve().EventBus.RaiseLocalEvent(Owner, new AddedToPartEvent(value)); + _entMan.EventBus.RaiseLocalEvent(Owner, new AddedToPartEvent(value)); } else { - IoCManager.Resolve().EventBus.RaiseLocalEvent(Owner, new AddedToPartInBodyEvent(value.Body, value)); + _entMan.EventBus.RaiseLocalEvent(Owner, new AddedToPartInBodyEvent(value.Body, value)); } } } diff --git a/Content.Shared/Hands/Components/SharedHandsComponent.cs b/Content.Shared/Hands/Components/SharedHandsComponent.cs index 4ad07c3b61..fe009019e8 100644 --- a/Content.Shared/Hands/Components/SharedHandsComponent.cs +++ b/Content.Shared/Hands/Components/SharedHandsComponent.cs @@ -23,6 +23,8 @@ namespace Content.Shared.Hands.Components [NetworkedComponent] public abstract class SharedHandsComponent : Component { + [Dependency] private readonly IEntityManager _entMan = default!; + public sealed override string Name => "Hands"; public event Action? OnItemChanged; //TODO: Try to replace C# event @@ -96,12 +98,12 @@ namespace Content.Shared.Hands.Components UpdateHandVisualizer(); Dirty(); - IoCManager.Resolve().EventBus.RaiseEvent(EventSource.Local, new HandsModifiedMessage { Hands = this }); + _entMan.EventBus.RaiseEvent(EventSource.Local, new HandsModifiedMessage { Hands = this }); } public void UpdateHandVisualizer() { - var entMan = IoCManager.Resolve(); + var entMan = _entMan; if (!entMan.TryGetComponent(Owner, out AppearanceComponent? appearance)) return; @@ -377,7 +379,7 @@ namespace Content.Shared.Hands.Components if (!TryGetHand(handName, out var hand)) return false; - return TryDropHeldEntity(hand, IoCManager.Resolve().GetComponent(Owner).Coordinates, checkActionBlocker); + return TryDropHeldEntity(hand, _entMan.GetComponent(Owner).Coordinates, checkActionBlocker); } /// @@ -388,7 +390,7 @@ namespace Content.Shared.Hands.Components if (!TryGetHandHoldingEntity(entity, out var hand)) return false; - return TryDropHeldEntity(hand, IoCManager.Resolve().GetComponent(Owner).Coordinates, checkActionBlocker); + return TryDropHeldEntity(hand, _entMan.GetComponent(Owner).Coordinates, checkActionBlocker); } /// @@ -481,7 +483,7 @@ namespace Content.Shared.Hands.Components EntitySystem.Get().DroppedInteraction(Owner, heldEntity); - IoCManager.Resolve().GetComponent(heldEntity).WorldPosition = GetFinalDropCoordinates(targetDropLocation); + _entMan.GetComponent(heldEntity).WorldPosition = GetFinalDropCoordinates(targetDropLocation); OnItemChanged?.Invoke(); } @@ -491,8 +493,8 @@ namespace Content.Shared.Hands.Components /// private Vector2 GetFinalDropCoordinates(EntityCoordinates targetCoords) { - var origin = IoCManager.Resolve().GetComponent(Owner).MapPosition; - var target = targetCoords.ToMap(IoCManager.Resolve()); + var origin = _entMan.GetComponent(Owner).MapPosition; + var target = targetCoords.ToMap(_entMan); var dropVector = target.Position - origin.Position; var requestedDropDistance = dropVector.Length; @@ -530,7 +532,7 @@ namespace Content.Shared.Hands.Components /// private void DropHeldEntityToFloor(Hand hand) { - DropHeldEntity(hand, IoCManager.Resolve().GetComponent(Owner).Coordinates); + DropHeldEntity(hand, _entMan.GetComponent(Owner).Coordinates); } private bool CanPutHeldEntityIntoContainer(Hand hand, IContainer targetContainer, bool checkActionBlocker) @@ -654,7 +656,7 @@ namespace Content.Shared.Hands.Components if (hand.Name == ActiveHand) SelectActiveHeldEntity(); - IoCManager.Resolve().GetComponent(entity).LocalPosition = Vector2.Zero; + _entMan.GetComponent(entity).LocalPosition = Vector2.Zero; OnItemChanged?.Invoke(); @@ -772,7 +774,7 @@ namespace Content.Shared.Hands.Components private void HandCountChanged() { - IoCManager.Resolve().EventBus.RaiseEvent(EventSource.Local, new HandCountChangedEvent(Owner)); + _entMan.EventBus.RaiseEvent(EventSource.Local, new HandCountChangedEvent(Owner)); } /// @@ -791,7 +793,7 @@ namespace Content.Shared.Hands.Components var entity = item.Owner; if (!TryPutInActiveHandOrAny(entity, checkActionBlocker)) - IoCManager.Resolve().GetComponent(entity).Coordinates = IoCManager.Resolve().GetComponent(Owner).Coordinates; + _entMan.GetComponent(entity).Coordinates = _entMan.GetComponent(Owner).Coordinates; } /// diff --git a/Content.Shared/Interaction/Helpers/SharedUnoccludedExtensions.cs b/Content.Shared/Interaction/Helpers/SharedUnoccludedExtensions.cs index 57817841fb..03e22dba5f 100644 --- a/Content.Shared/Interaction/Helpers/SharedUnoccludedExtensions.cs +++ b/Content.Shared/Interaction/Helpers/SharedUnoccludedExtensions.cs @@ -203,8 +203,9 @@ namespace Content.Shared.Interaction.Helpers Ignored? predicate = null, bool ignoreInsideBlocker = true) { - var originPosition = origin.ToMap(IoCManager.Resolve()); - var otherPosition = IoCManager.Resolve().GetComponent(other).MapPosition; + var entMan = IoCManager.Resolve(); + var originPosition = origin.ToMap(entMan); + var otherPosition = entMan.GetComponent(other).MapPosition; return ExamineSystemShared.InRangeUnOccluded(originPosition, otherPosition, range, predicate, ignoreInsideBlocker); @@ -217,8 +218,9 @@ namespace Content.Shared.Interaction.Helpers Ignored? predicate = null, bool ignoreInsideBlocker = true) { - var originPosition = origin.ToMap(IoCManager.Resolve()); - var otherPosition = IoCManager.Resolve().GetComponent(other.Owner).MapPosition; + var entMan = IoCManager.Resolve(); + var originPosition = origin.ToMap(entMan); + var otherPosition = entMan.GetComponent(other.Owner).MapPosition; return ExamineSystemShared.InRangeUnOccluded(originPosition, otherPosition, range, predicate, ignoreInsideBlocker); @@ -231,8 +233,9 @@ namespace Content.Shared.Interaction.Helpers Ignored? predicate = null, bool ignoreInsideBlocker = true) { - var originPosition = origin.ToMap(IoCManager.Resolve()); - var otherPosition = IoCManager.Resolve().GetComponent(other.Owner).MapPosition; + var entMan = IoCManager.Resolve(); + var originPosition = origin.ToMap(entMan); + var otherPosition = entMan.GetComponent(other.Owner).MapPosition; return ExamineSystemShared.InRangeUnOccluded(originPosition, otherPosition, range, predicate, ignoreInsideBlocker); @@ -246,7 +249,7 @@ namespace Content.Shared.Interaction.Helpers bool ignoreInsideBlocker = true, IEntityManager? entityManager = null) { - entityManager ??= IoCManager.Resolve(); + IoCManager.Resolve(ref entityManager); var originPosition = origin.ToMap(entityManager); var otherPosition = other.ToMap(entityManager); @@ -263,7 +266,7 @@ namespace Content.Shared.Interaction.Helpers bool ignoreInsideBlocker = true, IEntityManager? entityManager = null) { - entityManager ??= IoCManager.Resolve(); + IoCManager.Resolve(ref entityManager); var originPosition = origin.ToMap(entityManager); @@ -280,7 +283,8 @@ namespace Content.Shared.Interaction.Helpers Ignored? predicate = null, bool ignoreInsideBlocker = true) { - var otherPosition = IoCManager.Resolve().GetComponent(other).MapPosition; + var entMan = IoCManager.Resolve(); + var otherPosition = entMan.GetComponent(other).MapPosition; return ExamineSystemShared.InRangeUnOccluded(origin, otherPosition, range, predicate, ignoreInsideBlocker); @@ -293,7 +297,8 @@ namespace Content.Shared.Interaction.Helpers Ignored? predicate = null, bool ignoreInsideBlocker = true) { - var otherPosition = IoCManager.Resolve().GetComponent(other.Owner).MapPosition; + var entMan = IoCManager.Resolve(); + var otherPosition = entMan.GetComponent(other.Owner).MapPosition; return ExamineSystemShared.InRangeUnOccluded(origin, otherPosition, range, predicate, ignoreInsideBlocker); @@ -306,7 +311,8 @@ namespace Content.Shared.Interaction.Helpers Ignored? predicate = null, bool ignoreInsideBlocker = true) { - var otherPosition = IoCManager.Resolve().GetComponent(other.Owner).MapPosition; + var entMan = IoCManager.Resolve(); + var otherPosition = entMan.GetComponent(other.Owner).MapPosition; return ExamineSystemShared.InRangeUnOccluded(origin, otherPosition, range, predicate, ignoreInsideBlocker); @@ -320,7 +326,7 @@ namespace Content.Shared.Interaction.Helpers bool ignoreInsideBlocker = true, IEntityManager? entityManager = null) { - entityManager ??= IoCManager.Resolve(); + IoCManager.Resolve(ref entityManager); var otherPosition = other.ToMap(entityManager); diff --git a/Content.Shared/Item/SharedItemComponent.cs b/Content.Shared/Item/SharedItemComponent.cs index 995ee70ff9..bd86f8e983 100644 --- a/Content.Shared/Item/SharedItemComponent.cs +++ b/Content.Shared/Item/SharedItemComponent.cs @@ -22,6 +22,8 @@ namespace Content.Shared.Item [NetworkedComponent()] public abstract class SharedItemComponent : Component, IEquipped, IUnequipped, IInteractHand { + [Dependency] private readonly IEntityManager _entMan = default!; + public override string Name => "Item"; /// @@ -115,10 +117,10 @@ namespace Content.Shared.Item if (!EntitySystem.Get().CanPickup(user)) return false; - if (IoCManager.Resolve().GetComponent(user).MapID != IoCManager.Resolve().GetComponent(Owner).MapID) + if (_entMan.GetComponent(user).MapID != _entMan.GetComponent(Owner).MapID) return false; - if (!IoCManager.Resolve().TryGetComponent(Owner, out IPhysBody? physics) || physics.BodyType == BodyType.Static) + if (!_entMan.TryGetComponent(Owner, out IPhysBody? physics) || physics.BodyType == BodyType.Static) return false; return user.InRangeUnobstructed(Owner, ignoreInsideBlocker: true, popup: popup); @@ -141,7 +143,7 @@ namespace Content.Shared.Item if (!CanPickup(user)) return false; - if (!IoCManager.Resolve().TryGetComponent(user, out SharedHandsComponent? hands)) + if (!_entMan.TryGetComponent(user, out SharedHandsComponent? hands)) return false; var activeHand = hands.ActiveHand; diff --git a/Content.Shared/Lathe/SharedLatheComponent.cs b/Content.Shared/Lathe/SharedLatheComponent.cs index dd7963c4ae..e8a428b078 100644 --- a/Content.Shared/Lathe/SharedLatheComponent.cs +++ b/Content.Shared/Lathe/SharedLatheComponent.cs @@ -12,14 +12,15 @@ namespace Content.Shared.Lathe [NetworkedComponent()] public class SharedLatheComponent : Component { + [Dependency] private readonly IEntityManager _entMan = default!; [Dependency] protected readonly IPrototypeManager PrototypeManager = default!; public override string Name => "Lathe"; public bool CanProduce(LatheRecipePrototype recipe, int quantity = 1) { - if (!IoCManager.Resolve().TryGetComponent(Owner, out SharedMaterialStorageComponent? storage) - || !IoCManager.Resolve().TryGetComponent(Owner, out SharedLatheDatabaseComponent? database)) return false; + if (!_entMan.TryGetComponent(Owner, out SharedMaterialStorageComponent? storage) + || !_entMan.TryGetComponent(Owner, out SharedLatheDatabaseComponent? database)) return false; if (!database.Contains(recipe)) return false; diff --git a/Content.Shared/MobState/Components/MobStateComponent.cs b/Content.Shared/MobState/Components/MobStateComponent.cs index 484f354611..697849abe5 100644 --- a/Content.Shared/MobState/Components/MobStateComponent.cs +++ b/Content.Shared/MobState/Components/MobStateComponent.cs @@ -26,6 +26,8 @@ namespace Content.Shared.MobState.Components [NetworkedComponent] public class MobStateComponent : Component { + [Dependency] private readonly IEntityManager _entMan = default!; + public override string Name => "MobState"; /// @@ -60,13 +62,13 @@ namespace Content.Shared.MobState.Components else { // Initialize with some amount of damage, defaulting to 0. - UpdateState(IoCManager.Resolve().GetComponentOrNull(Owner)?.TotalDamage ?? FixedPoint2.Zero); + UpdateState(_entMan.GetComponentOrNull(Owner)?.TotalDamage ?? FixedPoint2.Zero); } } protected override void OnRemove() { - if (IoCManager.Resolve().TryGetComponent(Owner, out SharedAlertsComponent? status)) + if (_entMan.TryGetComponent(Owner, out SharedAlertsComponent? status)) { status.ClearAlert(AlertType.HumanHealth); } @@ -289,7 +291,7 @@ namespace Content.Shared.MobState.Components /// private void SetMobState(IMobState? old, (IMobState state, FixedPoint2 threshold)? current) { - var entMan = IoCManager.Resolve(); + var entMan = _entMan; if (!current.HasValue) { diff --git a/Content.Shared/Movement/SharedMoverController.cs b/Content.Shared/Movement/SharedMoverController.cs index 7abec6b40c..2bd560c096 100644 --- a/Content.Shared/Movement/SharedMoverController.cs +++ b/Content.Shared/Movement/SharedMoverController.cs @@ -67,7 +67,7 @@ namespace Content.Shared.Movement { var (walkDir, sprintDir) = mover.VelocityDir; - var transform = IoCManager.Resolve().GetComponent(mover.Owner); + var transform = EntityManager.GetComponent(mover.Owner); var parentRotation = transform.Parent!.WorldRotation; // Regular movement. @@ -105,7 +105,7 @@ namespace Content.Shared.Movement } UsedMobMovement[mover.Owner] = true; - var transform = IoCManager.Resolve().GetComponent(mover.Owner); + var transform = EntityManager.GetComponent(mover.Owner); var weightless = mover.Owner.IsWeightless(physicsComponent, mapManager: _mapManager, entityManager: _entityManager); var (walkDir, sprintDir) = mover.VelocityDir; @@ -164,9 +164,9 @@ namespace Content.Shared.Movement protected bool UseMobMovement(PhysicsComponent body) { return body.BodyStatus == BodyStatus.OnGround && - IoCManager.Resolve().HasComponent(body.Owner) && + EntityManager.HasComponent(body.Owner) && // If we're being pulled then don't mess with our velocity. - (!IoCManager.Resolve().TryGetComponent(body.Owner, out SharedPullableComponent? pullable) || !pullable.BeingPulled) && + (!EntityManager.TryGetComponent(body.Owner, out SharedPullableComponent? pullable) || !pullable.BeingPulled) && _blocker.CanMove((body).Owner); } @@ -186,7 +186,7 @@ namespace Content.Shared.Movement !otherCollider.CanCollide || ((collider.CollisionMask & otherCollider.CollisionLayer) == 0 && (otherCollider.CollisionMask & collider.CollisionLayer) == 0) || - (IoCManager.Resolve().TryGetComponent(otherCollider.Owner, out SharedPullableComponent? pullable) && pullable.BeingPulled)) + (EntityManager.TryGetComponent(otherCollider.Owner, out SharedPullableComponent? pullable) && pullable.BeingPulled)) { continue; } diff --git a/Content.Shared/Storage/SharedStorageComponent.cs b/Content.Shared/Storage/SharedStorageComponent.cs index afa6cf25b2..dd2a1ba6d6 100644 --- a/Content.Shared/Storage/SharedStorageComponent.cs +++ b/Content.Shared/Storage/SharedStorageComponent.cs @@ -16,6 +16,8 @@ namespace Content.Shared.Storage [NetworkedComponent()] public abstract class SharedStorageComponent : Component, IDraggable { + [Dependency] private readonly IEntityManager _entMan = default!; + public override string Name => "Storage"; public abstract IReadOnlyList? StoredEntities { get; } @@ -29,7 +31,7 @@ namespace Content.Shared.Storage bool IDraggable.CanDrop(CanDropEvent args) { - return IoCManager.Resolve().TryGetComponent(args.Target, out PlaceableSurfaceComponent? placeable) && + return _entMan.TryGetComponent(args.Target, out PlaceableSurfaceComponent? placeable) && placeable.IsPlaceable; } @@ -52,7 +54,7 @@ namespace Content.Shared.Storage { if (Remove(storedEntity)) { - IoCManager.Resolve().GetComponent(storedEntity).WorldPosition = eventArgs.DropLocation.Position; + _entMan.GetComponent(storedEntity).WorldPosition = eventArgs.DropLocation.Position; } }