diff --git a/Content.Server/Containers/ContainerExt.cs b/Content.Server/Containers/ContainerExt.cs index c66bc7b8f5..69e763d1db 100644 --- a/Content.Server/Containers/ContainerExt.cs +++ b/Content.Server/Containers/ContainerExt.cs @@ -9,13 +9,14 @@ namespace Content.Server.Containers { public static int CountPrototypeOccurencesRecursive(this ContainerManagerComponent mgr, string prototypeId) { + var entMan = IoCManager.Resolve(); int total = 0; foreach (var container in mgr.GetAllContainers()) { foreach (var entity in container.ContainedEntities) { - if (IoCManager.Resolve().GetComponent(entity).EntityPrototype?.ID == prototypeId) total++; - if(!IoCManager.Resolve().TryGetComponent(entity, out var component)) continue; + if (entMan.GetComponent(entity).EntityPrototype?.ID == prototypeId) total++; + if(!entMan.TryGetComponent(entity, out var component)) continue; total += component.CountPrototypeOccurencesRecursive(prototypeId); } } diff --git a/Content.Server/Coordinates/Helpers/SnapgridHelper.cs b/Content.Server/Coordinates/Helpers/SnapgridHelper.cs index 55d8c9705a..8121a064f1 100644 --- a/Content.Server/Coordinates/Helpers/SnapgridHelper.cs +++ b/Content.Server/Coordinates/Helpers/SnapgridHelper.cs @@ -7,17 +7,18 @@ namespace Content.Server.Coordinates.Helpers { public static class SnapgridHelper { - public static void SnapToGrid(this EntityUid entity, IEntityManager? entityManager = null, IMapManager? mapManager = null) + public static void SnapToGrid(this EntityUid entity, IEntityManager? entMan = null, IMapManager? mapManager = null) { - IoCManager.Resolve().GetComponent(entity).Coordinates = IoCManager.Resolve().GetComponent(entity).Coordinates.SnapToGrid(entityManager, mapManager); + IoCManager.Resolve(ref entMan, ref mapManager); + var transform = entMan.GetComponent(entity); + transform.Coordinates = transform.Coordinates.SnapToGrid(entMan, mapManager); } - public static EntityCoordinates SnapToGrid(this EntityCoordinates coordinates, IEntityManager? entityManager = null, IMapManager? mapManager = null) + public static EntityCoordinates SnapToGrid(this EntityCoordinates coordinates, IEntityManager? entMan = null, IMapManager? mapManager = null) { - entityManager ??= IoCManager.Resolve(); - mapManager ??= IoCManager.Resolve(); + IoCManager.Resolve(ref entMan, ref mapManager); - var gridId = coordinates.GetGridId(entityManager); + var gridId = coordinates.GetGridId(entMan); var tileSize = 1f; diff --git a/Content.Server/Crayon/CrayonComponent.cs b/Content.Server/Crayon/CrayonComponent.cs index e7a1c32df7..c58fc4d15c 100644 --- a/Content.Server/Crayon/CrayonComponent.cs +++ b/Content.Server/Crayon/CrayonComponent.cs @@ -29,6 +29,7 @@ namespace Content.Server.Crayon [RegisterComponent] public class CrayonComponent : SharedCrayonComponent, IAfterInteract, IUse, IDropped, ISerializationHooks { + [Dependency] private readonly IEntityManager _entMan = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!; [DataField("useSound")] @@ -91,7 +92,7 @@ namespace Content.Server.Crayon // Opens the selection window bool IUse.UseEntity(UseEntityEventArgs eventArgs) { - if (IoCManager.Resolve().TryGetComponent(eventArgs.User, out ActorComponent? actor)) + if (_entMan.TryGetComponent(eventArgs.User, out ActorComponent? actor)) { UserInterface?.Toggle(actor.PlayerSession); if (UserInterface?.SessionHasOpen(actor.PlayerSession) == true) @@ -119,7 +120,7 @@ namespace Content.Server.Crayon return true; } - if (!eventArgs.ClickLocation.IsValid(IoCManager.Resolve())) + if (!eventArgs.ClickLocation.IsValid(_entMan)) { eventArgs.User.PopupMessage(Loc.GetString("crayon-interact-invalid-location")); return true; @@ -140,7 +141,7 @@ namespace Content.Server.Crayon void IDropped.Dropped(DroppedEventArgs eventArgs) { - if (IoCManager.Resolve().TryGetComponent(eventArgs.User, out ActorComponent? actor)) + if (_entMan.TryGetComponent(eventArgs.User, out ActorComponent? actor)) UserInterface?.Close(actor.PlayerSession); } } diff --git a/Content.Server/Cuffs/Components/CuffableComponent.cs b/Content.Server/Cuffs/Components/CuffableComponent.cs index bebaa03f37..3c15fdbb6c 100644 --- a/Content.Server/Cuffs/Components/CuffableComponent.cs +++ b/Content.Server/Cuffs/Components/CuffableComponent.cs @@ -25,6 +25,8 @@ namespace Content.Server.Cuffs.Components [ComponentReference(typeof(SharedCuffableComponent))] public class CuffableComponent : SharedCuffableComponent { + [Dependency] private readonly IEntityManager _entMan = default!; + /// /// How many of this entity's hands are currently cuffed. /// @@ -64,7 +66,7 @@ namespace Content.Server.Cuffs.Components if (CuffedHandCount > 0) { - if (IoCManager.Resolve().TryGetComponent(LastAddedCuffs, out var cuffs)) + if (_entMan.TryGetComponent(LastAddedCuffs, out var cuffs)) { return new CuffableComponentState(CuffedHandCount, CanStillInteract, @@ -89,7 +91,7 @@ namespace Content.Server.Cuffs.Components /// public bool TryAddNewCuffs(EntityUid user, EntityUid handcuff) { - if (!IoCManager.Resolve().HasComponent(handcuff)) + if (!_entMan.HasComponent(handcuff)) { Logger.Warning($"Handcuffs being applied to player are missing a {nameof(HandcuffComponent)}!"); return false; @@ -102,14 +104,14 @@ namespace Content.Server.Cuffs.Components } // Success! - if (IoCManager.Resolve().TryGetComponent(user, out HandsComponent? handsComponent) && handsComponent.IsHolding(handcuff)) + if (_entMan.TryGetComponent(user, out HandsComponent? handsComponent) && handsComponent.IsHolding(handcuff)) { // Good lord handscomponent is scuffed, I hope some smug person will fix it someday handsComponent.Drop(handcuff); } Container.Insert(handcuff); - CanStillInteract = IoCManager.Resolve().TryGetComponent(Owner, out HandsComponent? ownerHands) && ownerHands.HandNames.Count() > CuffedHandCount; + CanStillInteract = _entMan.TryGetComponent(Owner, out HandsComponent? ownerHands) && ownerHands.HandNames.Count() > CuffedHandCount; OnCuffedStateChanged?.Invoke(); UpdateAlert(); @@ -129,7 +131,7 @@ namespace Content.Server.Cuffs.Components /// public void UpdateHeldItems() { - if (!IoCManager.Resolve().TryGetComponent(Owner, out HandsComponent? handsComponent)) return; + if (!_entMan.TryGetComponent(Owner, out HandsComponent? handsComponent)) return; var itemCount = handsComponent.GetAllHeldItems().Count(); var freeHandCount = handsComponent.HandNames.Count() - CuffedHandCount; @@ -156,7 +158,7 @@ namespace Content.Server.Cuffs.Components /// private void UpdateAlert() { - if (IoCManager.Resolve().TryGetComponent(Owner, out ServerAlertsComponent? status)) + if (_entMan.TryGetComponent(Owner, out ServerAlertsComponent? status)) { if (CanStillInteract) { @@ -198,14 +200,14 @@ namespace Content.Server.Cuffs.Components } } - if (!IoCManager.Resolve().TryGetComponent(cuffsToRemove, out var cuff)) + if (!_entMan.TryGetComponent(cuffsToRemove, out var cuff)) { Logger.Warning($"A user is trying to remove handcuffs without a {nameof(HandcuffComponent)}. This should never happen!"); return; } var attempt = new UncuffAttemptEvent(user, Owner); - IoCManager.Resolve().EventBus.RaiseLocalEvent(user, attempt); + _entMan.EventBus.RaiseLocalEvent(user, attempt); if (attempt.Cancelled) { @@ -257,23 +259,23 @@ namespace Content.Server.Cuffs.Components SoundSystem.Play(Filter.Pvs(Owner), cuff.EndUncuffSound.GetSound(), Owner); Container.ForceRemove(cuffsToRemove); - IoCManager.Resolve().GetComponent(cuffsToRemove).AttachToGridOrMap(); - IoCManager.Resolve().GetComponent(cuffsToRemove).WorldPosition = IoCManager.Resolve().GetComponent(Owner).WorldPosition; + _entMan.GetComponent(cuffsToRemove).AttachToGridOrMap(); + _entMan.GetComponent(cuffsToRemove).WorldPosition = _entMan.GetComponent(Owner).WorldPosition; if (cuff.BreakOnRemove) { cuff.Broken = true; - IoCManager.Resolve().GetComponent(cuffsToRemove).EntityName = cuff.BrokenName; - IoCManager.Resolve().GetComponent(cuffsToRemove).EntityDescription = cuff.BrokenDesc; + _entMan.GetComponent(cuffsToRemove).EntityName = cuff.BrokenName; + _entMan.GetComponent(cuffsToRemove).EntityDescription = cuff.BrokenDesc; - if (IoCManager.Resolve().TryGetComponent(cuffsToRemove, out var sprite) && cuff.BrokenState != null) + if (_entMan.TryGetComponent(cuffsToRemove, out var sprite) && cuff.BrokenState != null) { sprite.LayerSetState(0, cuff.BrokenState); // TODO: safety check to see if RSI contains the state? } } - CanStillInteract = IoCManager.Resolve().TryGetComponent(Owner, out HandsComponent? handsComponent) && handsComponent.HandNames.Count() > CuffedHandCount; + CanStillInteract = _entMan.TryGetComponent(Owner, out HandsComponent? handsComponent) && handsComponent.HandNames.Count() > CuffedHandCount; OnCuffedStateChanged?.Invoke(); UpdateAlert(); Dirty(); diff --git a/Content.Server/Damage/Commands/HurtCommand.cs b/Content.Server/Damage/Commands/HurtCommand.cs index 77dcbfdd2f..c5b1e28525 100644 --- a/Content.Server/Damage/Commands/HurtCommand.cs +++ b/Content.Server/Damage/Commands/HurtCommand.cs @@ -82,7 +82,7 @@ namespace Content.Server.Damage.Commands string[] args, [NotNullWhen(true)] out Damage? func) { - + var entMan = IoCManager.Resolve(); if (!int.TryParse(args[1], out var amount)) { @@ -99,7 +99,7 @@ namespace Content.Server.Damage.Commands var damage = new DamageSpecifier(damageGroup, amount); EntitySystem.Get().TryChangeDamage(entity, damage, ignoreResistances); - shell.WriteLine($"Damaged entity {IoCManager.Resolve().GetComponent(entity).EntityName} with id {entity} for {amount} {damageGroup} damage{(ignoreResistances ? ", ignoring resistances." : ".")}"); + shell.WriteLine($"Damaged entity {entMan.GetComponent(entity).EntityName} with id {entity} for {amount} {damageGroup} damage{(ignoreResistances ? ", ignoring resistances." : ".")}"); }; return true; @@ -112,7 +112,7 @@ namespace Content.Server.Damage.Commands var damage = new DamageSpecifier(damageType, amount); EntitySystem.Get().TryChangeDamage(entity, damage, ignoreResistances); - shell.WriteLine($"Damaged entity {IoCManager.Resolve().GetComponent(entity).EntityName} with id {entity} for {amount} {damageType} damage{(ignoreResistances ? ", ignoring resistances." : ".")}"); + shell.WriteLine($"Damaged entity {entMan.GetComponent(entity).EntityName} with id {entity} for {amount} {damageType} damage{(ignoreResistances ? ", ignoring resistances." : ".")}"); }; return true; @@ -137,6 +137,8 @@ namespace Content.Server.Damage.Commands EntityUid entity; Damage? damageFunc; + var entMan = IoCManager.Resolve(); + switch (args.Length) { // Check if we have enough for the dmg types to show @@ -190,9 +192,9 @@ namespace Content.Server.Damage.Commands return; } - if (!IoCManager.Resolve().TryGetComponent(entity, out DamageableComponent? damageable)) + if (!entMan.TryGetComponent(entity, out DamageableComponent? damageable)) { - shell.WriteLine($"Entity {IoCManager.Resolve().GetComponent(entity).EntityName} with id {entity} does not have a {nameof(DamageableComponent)}."); + shell.WriteLine($"Entity {entMan.GetComponent(entity).EntityName} with id {entity} does not have a {nameof(DamageableComponent)}."); return; } diff --git a/Content.Server/Disposal/Tube/Components/DisposalEntryComponent.cs b/Content.Server/Disposal/Tube/Components/DisposalEntryComponent.cs index 980f44e051..aaf9be47dd 100644 --- a/Content.Server/Disposal/Tube/Components/DisposalEntryComponent.cs +++ b/Content.Server/Disposal/Tube/Components/DisposalEntryComponent.cs @@ -15,14 +15,16 @@ namespace Content.Server.Disposal.Tube.Components [ComponentReference(typeof(IDisposalTubeComponent))] public class DisposalEntryComponent : DisposalTubeComponent { + [Dependency] private readonly IEntityManager _entMan = default!; + private const string HolderPrototypeId = "DisposalHolder"; public override string Name => "DisposalEntry"; public bool TryInsert(DisposalUnitComponent from) { - var holder = IoCManager.Resolve().SpawnEntity(HolderPrototypeId, IoCManager.Resolve().GetComponent(Owner).MapPosition); - var holderComponent = IoCManager.Resolve().GetComponent(holder); + var holder = _entMan.SpawnEntity(HolderPrototypeId, _entMan.GetComponent(Owner).MapPosition); + var holderComponent = _entMan.GetComponent(holder); foreach (var entity in from.ContainedEntities.ToArray()) { @@ -37,7 +39,7 @@ namespace Content.Server.Disposal.Tube.Components protected override Direction[] ConnectableDirections() { - return new[] {IoCManager.Resolve().GetComponent(Owner).LocalRotation.GetDir()}; + return new[] {_entMan.GetComponent(Owner).LocalRotation.GetDir()}; } /// diff --git a/Content.Server/Disposal/Tube/Components/DisposalJunctionComponent.cs b/Content.Server/Disposal/Tube/Components/DisposalJunctionComponent.cs index 2da7497048..1f420ef9e1 100644 --- a/Content.Server/Disposal/Tube/Components/DisposalJunctionComponent.cs +++ b/Content.Server/Disposal/Tube/Components/DisposalJunctionComponent.cs @@ -14,6 +14,7 @@ namespace Content.Server.Disposal.Tube.Components [ComponentReference(typeof(IDisposalTubeComponent))] public class DisposalJunctionComponent : DisposalTubeComponent { + [Dependency] private readonly IEntityManager _entMan = default!; [Dependency] private readonly IRobustRandom _random = default!; /// @@ -27,14 +28,14 @@ namespace Content.Server.Disposal.Tube.Components protected override Direction[] ConnectableDirections() { - var direction = IoCManager.Resolve().GetComponent(Owner).LocalRotation; + var direction = _entMan.GetComponent(Owner).LocalRotation; return _degrees.Select(degree => new Angle(degree.Theta + direction.Theta).GetDir()).ToArray(); } public override Direction NextDirection(DisposalHolderComponent holder) { - var next = IoCManager.Resolve().GetComponent(Owner).LocalRotation.GetDir(); + var next = _entMan.GetComponent(Owner).LocalRotation.GetDir(); var directions = ConnectableDirections().Skip(1).ToArray(); if (holder.PreviousDirectionFrom == Direction.Invalid || diff --git a/Content.Server/Disposal/Tube/Components/DisposalRouterComponent.cs b/Content.Server/Disposal/Tube/Components/DisposalRouterComponent.cs index 0e7a59072b..4a5c5df272 100644 --- a/Content.Server/Disposal/Tube/Components/DisposalRouterComponent.cs +++ b/Content.Server/Disposal/Tube/Components/DisposalRouterComponent.cs @@ -29,6 +29,8 @@ namespace Content.Server.Disposal.Tube.Components [ComponentReference(typeof(IDisposalTubeComponent))] public class DisposalRouterComponent : DisposalJunctionComponent, IActivate { + [Dependency] private readonly IEntityManager _entMan = default!; + public override string Name => "DisposalRouter"; [ViewVariables] @@ -36,7 +38,7 @@ namespace Content.Server.Disposal.Tube.Components [ViewVariables] public bool Anchored => - !IoCManager.Resolve().TryGetComponent(Owner, out IPhysBody? physics) || + !_entMan.TryGetComponent(Owner, out IPhysBody? physics) || physics.BodyType == BodyType.Static; [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(DisposalRouterUiKey.Key); @@ -52,7 +54,7 @@ namespace Content.Server.Disposal.Tube.Components return directions[1]; } - return IoCManager.Resolve().GetComponent(Owner).LocalRotation.GetDir(); + return _entMan.GetComponent(Owner).LocalRotation.GetDir(); } protected override void Initialize() @@ -160,12 +162,12 @@ namespace Content.Server.Disposal.Tube.Components /// Data relevant to the event such as the actor which triggered it. void IActivate.Activate(ActivateEventArgs args) { - if (!IoCManager.Resolve().TryGetComponent(args.User, out ActorComponent? actor)) + if (!_entMan.TryGetComponent(args.User, out ActorComponent? actor)) { return; } - if (!IoCManager.Resolve().TryGetComponent(args.User, out HandsComponent? hands)) + if (!_entMan.TryGetComponent(args.User, out HandsComponent? hands)) { Owner.PopupMessage(args.User, Loc.GetString("disposal-router-window-tag-input-activate-no-hands")); return; diff --git a/Content.Server/Disposal/Tube/Components/DisposalTaggerComponent.cs b/Content.Server/Disposal/Tube/Components/DisposalTaggerComponent.cs index 9c9dc10c0b..1c354acd59 100644 --- a/Content.Server/Disposal/Tube/Components/DisposalTaggerComponent.cs +++ b/Content.Server/Disposal/Tube/Components/DisposalTaggerComponent.cs @@ -26,6 +26,8 @@ namespace Content.Server.Disposal.Tube.Components [ComponentReference(typeof(IDisposalTubeComponent))] public class DisposalTaggerComponent : DisposalTransitComponent, IActivate { + [Dependency] private readonly IEntityManager _entMan = default!; + public override string Name => "DisposalTagger"; [ViewVariables(VVAccess.ReadWrite)] @@ -33,7 +35,7 @@ namespace Content.Server.Disposal.Tube.Components [ViewVariables] public bool Anchored => - !IoCManager.Resolve().TryGetComponent(Owner, out PhysicsComponent? physics) || + !_entMan.TryGetComponent(Owner, out PhysicsComponent? physics) || physics.BodyType == BodyType.Static; [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(DisposalTaggerUiKey.Key); @@ -126,12 +128,12 @@ namespace Content.Server.Disposal.Tube.Components /// Data relevant to the event such as the actor which triggered it. void IActivate.Activate(ActivateEventArgs args) { - if (!IoCManager.Resolve().TryGetComponent(args.User, out ActorComponent? actor)) + if (!_entMan.TryGetComponent(args.User, out ActorComponent? actor)) { return; } - if (!IoCManager.Resolve().TryGetComponent(args.User, out HandsComponent? hands)) + if (!_entMan.TryGetComponent(args.User, out HandsComponent? hands)) { Owner.PopupMessage(args.User, Loc.GetString("disposal-tagger-window-activate-no-hands")); return; diff --git a/Content.Server/Disposal/Tube/Components/DisposalTubeComponent.cs b/Content.Server/Disposal/Tube/Components/DisposalTubeComponent.cs index b0964e49d4..c815119c90 100644 --- a/Content.Server/Disposal/Tube/Components/DisposalTubeComponent.cs +++ b/Content.Server/Disposal/Tube/Components/DisposalTubeComponent.cs @@ -20,6 +20,8 @@ namespace Content.Server.Disposal.Tube.Components { public abstract class DisposalTubeComponent : Component, IDisposalTubeComponent, IBreakAct { + [Dependency] private readonly IEntityManager _entMan = default!; + public static readonly TimeSpan ClangDelay = TimeSpan.FromSeconds(0.5); public TimeSpan LastClang; @@ -35,7 +37,7 @@ namespace Content.Server.Disposal.Tube.Components [ViewVariables] private bool Anchored => - !IoCManager.Resolve().TryGetComponent(Owner, out PhysicsComponent? physics) || + !_entMan.TryGetComponent(Owner, out PhysicsComponent? physics) || physics.BodyType == BodyType.Static; /// @@ -88,7 +90,7 @@ namespace Content.Server.Disposal.Tube.Components foreach (var entity in Contents.ContainedEntities.ToArray()) { - if (!IoCManager.Resolve().TryGetComponent(entity, out DisposalHolderComponent? holder)) + if (!_entMan.TryGetComponent(entity, out DisposalHolderComponent? holder)) { continue; } @@ -106,7 +108,7 @@ namespace Content.Server.Disposal.Tube.Components private void UpdateVisualState() { - if (!IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearance)) + if (!_entMan.TryGetComponent(Owner, out AppearanceComponent? appearance)) { return; } @@ -122,7 +124,7 @@ namespace Content.Server.Disposal.Tube.Components public void AnchoredChanged() { - if (!IoCManager.Resolve().TryGetComponent(Owner, out PhysicsComponent? physics)) + if (!_entMan.TryGetComponent(Owner, out PhysicsComponent? physics)) { return; } diff --git a/Content.Server/Disposal/Unit/Components/DisposalHolderComponent.cs b/Content.Server/Disposal/Unit/Components/DisposalHolderComponent.cs index 62f344e79b..aab960bba6 100644 --- a/Content.Server/Disposal/Unit/Components/DisposalHolderComponent.cs +++ b/Content.Server/Disposal/Unit/Components/DisposalHolderComponent.cs @@ -18,6 +18,8 @@ namespace Content.Server.Disposal.Unit.Components [RegisterComponent] public class DisposalHolderComponent : Component, IGasMixtureHolder { + [Dependency] private readonly IEntityManager _entMan = default!; + public override string Name => "DisposalHolder"; public Container Container = null!; @@ -79,8 +81,8 @@ namespace Content.Server.Disposal.Unit.Components return false; } - return IoCManager.Resolve().HasComponent(entity) || - IoCManager.Resolve().HasComponent(entity); + return _entMan.HasComponent(entity) || + _entMan.HasComponent(entity); } public bool TryInsert(EntityUid entity) @@ -90,7 +92,7 @@ namespace Content.Server.Disposal.Unit.Components return false; } - if (IoCManager.Resolve().TryGetComponent(entity, out IPhysBody? physics)) + if (_entMan.TryGetComponent(entity, out IPhysBody? physics)) { physics.CanCollide = false; } diff --git a/Content.Server/Doors/Components/FirelockComponent.cs b/Content.Server/Doors/Components/FirelockComponent.cs index 84ba57c50e..7634a0d3b1 100644 --- a/Content.Server/Doors/Components/FirelockComponent.cs +++ b/Content.Server/Doors/Components/FirelockComponent.cs @@ -14,6 +14,8 @@ namespace Content.Server.Doors.Components [RegisterComponent] public class FirelockComponent : Component { + [Dependency] private readonly IEntityManager _entMan = default!; + public override string Name => "Firelock"; [ComponentDependency] @@ -31,7 +33,7 @@ namespace Content.Server.Doors.Components if (DoorComponent != null && DoorComponent.State == SharedDoorComponent.DoorState.Open && DoorComponent.CanCloseGeneric()) { DoorComponent.Close(); - if (IoCManager.Resolve().TryGetComponent(Owner, out AirtightComponent? airtight)) + if (_entMan.TryGetComponent(Owner, out AirtightComponent? airtight)) { EntitySystem.Get().SetAirblocked(airtight, true); } @@ -47,7 +49,7 @@ namespace Content.Server.Doors.Components var minMoles = float.MaxValue; var maxMoles = 0f; - foreach (var adjacent in atmosphereSystem.GetAdjacentTileMixtures(IoCManager.Resolve().GetComponent(Owner).Coordinates)) + foreach (var adjacent in atmosphereSystem.GetAdjacentTileMixtures(_entMan.GetComponent(Owner).Coordinates)) { var moles = adjacent.TotalMoles; if (moles < minMoles) @@ -63,7 +65,7 @@ namespace Content.Server.Doors.Components { var atmosphereSystem = EntitySystem.Get(); - if (!atmosphereSystem.TryGetGridAndTile(IoCManager.Resolve().GetComponent(Owner).Coordinates, out var tuple)) + if (!atmosphereSystem.TryGetGridAndTile(_entMan.GetComponent(Owner).Coordinates, out var tuple)) return false; if (atmosphereSystem.GetTileMixture(tuple.Value.Grid, tuple.Value.Tile) == null) @@ -72,7 +74,7 @@ namespace Content.Server.Doors.Components if (atmosphereSystem.IsHotspotActive(tuple.Value.Grid, tuple.Value.Tile)) return true; - foreach (var adjacent in atmosphereSystem.GetAdjacentTiles(IoCManager.Resolve().GetComponent(Owner).Coordinates)) + foreach (var adjacent in atmosphereSystem.GetAdjacentTiles(_entMan.GetComponent(Owner).Coordinates)) { if (atmosphereSystem.IsHotspotActive(tuple.Value.Grid, adjacent)) return true; diff --git a/Content.Server/Doors/Components/ServerDoorComponent.cs b/Content.Server/Doors/Components/ServerDoorComponent.cs index 6948a336c0..c0acc07b1e 100644 --- a/Content.Server/Doors/Components/ServerDoorComponent.cs +++ b/Content.Server/Doors/Components/ServerDoorComponent.cs @@ -38,6 +38,8 @@ namespace Content.Server.Doors.Components [ComponentReference(typeof(SharedDoorComponent))] public class ServerDoorComponent : SharedDoorComponent, IActivate, IInteractUsing, IMapInit { + [Dependency] private readonly IEntityManager _entMan = default!; + [ViewVariables] [DataField("board", customTypeSerializer:typeof(PrototypeIdSerializer))] private string? _boardPrototype; @@ -77,7 +79,7 @@ namespace Content.Server.Doors.Components _ => throw new ArgumentOutOfRangeException(), }; - IoCManager.Resolve().EventBus.RaiseLocalEvent(Owner, new DoorStateChangedEvent(State), false); + _entMan.EventBus.RaiseLocalEvent(Owner, new DoorStateChangedEvent(State), false); _autoCloseCancelTokenSource?.Cancel(); Dirty(); @@ -219,7 +221,7 @@ namespace Content.Server.Doors.Components { if (!CanWeldShut) { - Logger.Warning("{0} prototype loaded with incompatible flags: 'welded' is true, but door cannot be welded.", IoCManager.Resolve().GetComponent(Owner).EntityName); + Logger.Warning("{0} prototype loaded with incompatible flags: 'welded' is true, but door cannot be welded.", _entMan.GetComponent(Owner).EntityName); return; } SetAppearance(DoorVisualState.Welded); @@ -242,7 +244,7 @@ namespace Content.Server.Doors.Components { if (IsWeldedShut) { - Logger.Warning("{0} prototype loaded with incompatible flags: 'welded' and 'startOpen' are both true.", IoCManager.Resolve().GetComponent(Owner).EntityName); + Logger.Warning("{0} prototype loaded with incompatible flags: 'welded' and 'startOpen' are both true.", _entMan.GetComponent(Owner).EntityName); return; } QuickOpen(false); @@ -257,7 +259,7 @@ namespace Content.Server.Doors.Components return; var ev = new DoorClickShouldActivateEvent(eventArgs); - IoCManager.Resolve().EventBus.RaiseLocalEvent(Owner, ev, false); + _entMan.EventBus.RaiseLocalEvent(Owner, ev, false); if (ev.Handled) return; @@ -276,7 +278,7 @@ namespace Content.Server.Doors.Components public void TryOpen(EntityUid user = default) { var msg = new DoorOpenAttemptEvent(); - IoCManager.Resolve().EventBus.RaiseLocalEvent(Owner, msg); + _entMan.EventBus.RaiseLocalEvent(Owner, msg); if (msg.Cancelled) return; @@ -289,7 +291,7 @@ namespace Content.Server.Doors.Components { Open(); - if (IoCManager.Resolve().TryGetComponent(user, out HandsComponent? hands) && hands.Count == 0) + if (_entMan.TryGetComponent(user, out HandsComponent? hands) && hands.Count == 0) { SoundSystem.Play(Filter.Pvs(Owner), _tryOpenDoorSound.GetSound(), Owner, AudioParams.Default.WithVolume(-2)); @@ -308,7 +310,7 @@ namespace Content.Server.Doors.Components return false; } - if (!IoCManager.Resolve().TryGetComponent(Owner, out AccessReader? access)) + if (!_entMan.TryGetComponent(Owner, out AccessReader? access)) { return true; } @@ -332,7 +334,7 @@ namespace Content.Server.Doors.Components /// private bool HasAccessType(string accessType) { - if (IoCManager.Resolve().TryGetComponent(Owner, out AccessReader? access)) + if (_entMan.TryGetComponent(Owner, out AccessReader? access)) { return access.AccessLists.Any(list => list.Contains(accessType)); } @@ -353,7 +355,7 @@ namespace Content.Server.Doors.Components } var ev = new BeforeDoorOpenedEvent(); - IoCManager.Resolve().EventBus.RaiseLocalEvent(Owner, ev, false); + _entMan.EventBus.RaiseLocalEvent(Owner, ev, false); return !ev.Cancelled; } @@ -363,12 +365,12 @@ namespace Content.Server.Doors.Components public void Open() { State = DoorState.Opening; - if (Occludes && IoCManager.Resolve().TryGetComponent(Owner, out OccluderComponent? occluder)) + if (Occludes && _entMan.TryGetComponent(Owner, out OccluderComponent? occluder)) { occluder.Enabled = false; } - if (ChangeAirtight && IoCManager.Resolve().TryGetComponent(Owner, out AirtightComponent? airtight)) + if (ChangeAirtight && _entMan.TryGetComponent(Owner, out AirtightComponent? airtight)) { EntitySystem.Get().SetAirblocked(airtight, false); } @@ -396,17 +398,17 @@ namespace Content.Server.Doors.Components { base.OnPartialOpen(); - if (ChangeAirtight && IoCManager.Resolve().TryGetComponent(Owner, out AirtightComponent? airtight)) + if (ChangeAirtight && _entMan.TryGetComponent(Owner, out AirtightComponent? airtight)) { EntitySystem.Get().SetAirblocked(airtight, false); } - IoCManager.Resolve().EventBus.RaiseEvent(EventSource.Local, new AccessReaderChangeMessage(Owner, false)); + _entMan.EventBus.RaiseEvent(EventSource.Local, new AccessReaderChangeMessage(Owner, false)); } private void QuickOpen(bool refresh) { - if (Occludes && IoCManager.Resolve().TryGetComponent(Owner, out OccluderComponent? occluder)) + if (Occludes && _entMan.TryGetComponent(Owner, out OccluderComponent? occluder)) { occluder.Enabled = false; } @@ -423,7 +425,7 @@ namespace Content.Server.Doors.Components public void TryClose(EntityUid user = default) { var msg = new DoorCloseAttemptEvent(); - IoCManager.Resolve().EventBus.RaiseLocalEvent(Owner, msg); + _entMan.EventBus.RaiseLocalEvent(Owner, msg); if (msg.Cancelled) return; @@ -443,7 +445,7 @@ namespace Content.Server.Doors.Components return false; } - if (!IoCManager.Resolve().TryGetComponent(Owner, out AccessReader? access)) + if (!_entMan.TryGetComponent(Owner, out AccessReader? access)) { return true; } @@ -459,7 +461,7 @@ namespace Content.Server.Doors.Components public bool CanCloseGeneric() { var ev = new BeforeDoorClosedEvent(); - IoCManager.Resolve().EventBus.RaiseLocalEvent(Owner, ev, false); + _entMan.EventBus.RaiseLocalEvent(Owner, ev, false); if (ev.Cancelled) return false; @@ -469,7 +471,7 @@ namespace Content.Server.Doors.Components private bool SafetyCheck() { var ev = new DoorSafetyEnabledEvent(); - IoCManager.Resolve().EventBus.RaiseLocalEvent(Owner, ev, false); + _entMan.EventBus.RaiseLocalEvent(Owner, ev, false); return ev.Safety || _inhibitCrush; } @@ -481,7 +483,7 @@ namespace Content.Server.Doors.Components { var safety = SafetyCheck(); - if (safety && IoCManager.Resolve().TryGetComponent(Owner, out PhysicsComponent? physicsComponent)) + if (safety && _entMan.TryGetComponent(Owner, out PhysicsComponent? physicsComponent)) { var broadPhaseSystem = EntitySystem.Get(); @@ -525,7 +527,7 @@ namespace Content.Server.Doors.Components OnPartialClose(); await Timer.Delay(CloseTimeTwo, _stateChangeCancelTokenSource.Token); - if (Occludes && IoCManager.Resolve().TryGetComponent(Owner, out OccluderComponent? occluder)) + if (Occludes && _entMan.TryGetComponent(Owner, out OccluderComponent? occluder)) { occluder.Enabled = true; } @@ -541,12 +543,12 @@ namespace Content.Server.Doors.Components // if safety is off, crushes people inside of the door, temporarily turning off collisions with them while doing so. var becomeairtight = ChangeAirtight && (SafetyCheck() || !TryCrush()); - if (becomeairtight && IoCManager.Resolve().TryGetComponent(Owner, out AirtightComponent? airtight)) + if (becomeairtight && _entMan.TryGetComponent(Owner, out AirtightComponent? airtight)) { EntitySystem.Get().SetAirblocked(airtight, true); } - IoCManager.Resolve().EventBus.RaiseEvent(EventSource.Local, new AccessReaderChangeMessage(Owner, true)); + _entMan.EventBus.RaiseEvent(EventSource.Local, new AccessReaderChangeMessage(Owner, true)); } /// @@ -581,7 +583,7 @@ namespace Content.Server.Doors.Components hitsomebody = true; CurrentlyCrushing.Add(e.Owner); - if (IoCManager.Resolve().HasComponent(e.Owner)) + if (_entMan.HasComponent(e.Owner)) EntitySystem.Get().TryChangeDamage(e.Owner, CrushDamage); EntitySystem.Get().TryParalyze(e.Owner, TimeSpan.FromSeconds(DoorStunTime), true); @@ -602,7 +604,7 @@ namespace Content.Server.Doors.Components public void Deny() { var ev = new BeforeDoorDeniedEvent(); - IoCManager.Resolve().EventBus.RaiseLocalEvent(Owner, ev, false); + _entMan.EventBus.RaiseLocalEvent(Owner, ev, false); if (ev.Cancelled) return; @@ -649,14 +651,14 @@ namespace Content.Server.Doors.Components return; var autoev = new BeforeDoorAutoCloseEvent(); - IoCManager.Resolve().EventBus.RaiseLocalEvent(Owner, autoev, false); + _entMan.EventBus.RaiseLocalEvent(Owner, autoev, false); if (autoev.Cancelled) return; _autoCloseCancelTokenSource = new(); var ev = new DoorGetCloseTimeModifierEvent(); - IoCManager.Resolve().EventBus.RaiseLocalEvent(Owner, ev, false); + _entMan.EventBus.RaiseLocalEvent(Owner, ev, false); var realCloseTime = AutoCloseDelay * ev.CloseTimeModifier; Owner.SpawnRepeatingTimer(realCloseTime, async () => @@ -671,7 +673,7 @@ namespace Content.Server.Doors.Components async Task IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs) { - if(!IoCManager.Resolve().TryGetComponent(eventArgs.Using, out ToolComponent? tool)) + if(!_entMan.TryGetComponent(eventArgs.Using, out ToolComponent? tool)) { return false; } @@ -682,10 +684,10 @@ namespace Content.Server.Doors.Components if (tool.Qualities.Contains(_pryingQuality) && !IsWeldedShut) { var ev = new DoorGetPryTimeModifierEvent(); - IoCManager.Resolve().EventBus.RaiseLocalEvent(Owner, ev, false); + _entMan.EventBus.RaiseLocalEvent(Owner, ev, false); var canEv = new BeforeDoorPryEvent(eventArgs); - IoCManager.Resolve().EventBus.RaiseLocalEvent(Owner, canEv, false); + _entMan.EventBus.RaiseLocalEvent(Owner, canEv, false); if (canEv.Cancelled) return false; @@ -694,7 +696,7 @@ namespace Content.Server.Doors.Components if (successfulPry && !IsWeldedShut) { - IoCManager.Resolve().EventBus.RaiseLocalEvent(Owner, new OnDoorPryEvent(eventArgs), false); + _entMan.EventBus.RaiseLocalEvent(Owner, new OnDoorPryEvent(eventArgs), false); if (State == DoorState.Closed) { Open(); @@ -708,7 +710,7 @@ namespace Content.Server.Doors.Components } // for welding doors - if (CanWeldShut && IoCManager.Resolve().TryGetComponent(tool.Owner, out WelderComponent? welder) && welder.Lit) + if (CanWeldShut && _entMan.TryGetComponent(tool.Owner, out WelderComponent? welder) && welder.Lit) { if(!_beingWelded) { @@ -743,7 +745,7 @@ namespace Content.Server.Doors.Components private void CreateDoorElectronicsBoard() { // Ensure that the construction component is aware of the board container. - if (IoCManager.Resolve().TryGetComponent(Owner, out ConstructionComponent? construction)) + if (_entMan.TryGetComponent(Owner, out ConstructionComponent? construction)) EntitySystem.Get().AddContainer(Owner, "board", construction); // We don't do anything if this is null or empty. diff --git a/Content.Server/Explosion/Components/ClusterFlashComponent.cs b/Content.Server/Explosion/Components/ClusterFlashComponent.cs index f9128ba8cb..1635880c7d 100644 --- a/Content.Server/Explosion/Components/ClusterFlashComponent.cs +++ b/Content.Server/Explosion/Components/ClusterFlashComponent.cs @@ -18,6 +18,8 @@ namespace Content.Server.Explosion.Components [RegisterComponent] public sealed class ClusterFlashComponent : Component, IInteractUsing, IUse { + [Dependency] private readonly IEntityManager _entMan = default!; + public override string Name => "ClusterFlash"; private Container _grenadesContainer = default!; @@ -59,7 +61,7 @@ namespace Content.Server.Explosion.Components async Task IInteractUsing.InteractUsing(InteractUsingEventArgs args) { if (_grenadesContainer.ContainedEntities.Count >= _maxGrenades || - !IoCManager.Resolve().HasComponent(args.Using)) + !_entMan.HasComponent(args.Using)) return false; _grenadesContainer.Insert(args.Using); @@ -92,7 +94,7 @@ namespace Content.Server.Explosion.Components return false; Owner.SpawnTimer((int) (_delay * 1000), () => { - 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) return; _countDown = true; var random = IoCManager.Resolve(); @@ -115,14 +117,14 @@ namespace Content.Server.Explosion.Components grenade.SpawnTimer(delay, () => { - if ((!IoCManager.Resolve().EntityExists(grenade) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(grenade).EntityLifeStage) >= EntityLifeStage.Deleted) + if ((!_entMan.EntityExists(grenade) ? EntityLifeStage.Deleted : _entMan.GetComponent(grenade).EntityLifeStage) >= EntityLifeStage.Deleted) return; EntitySystem.Get().Trigger(grenade, eventArgs.User); }); } - IoCManager.Resolve().DeleteEntity(Owner); + _entMan.DeleteEntity(Owner); }); return true; } @@ -134,7 +136,7 @@ namespace Content.Server.Explosion.Components if (_unspawnedCount > 0) { _unspawnedCount--; - grenade = IoCManager.Resolve().SpawnEntity(_fillPrototype, IoCManager.Resolve().GetComponent(Owner).MapPosition); + grenade = _entMan.SpawnEntity(_fillPrototype, _entMan.GetComponent(Owner).MapPosition); return true; } @@ -154,7 +156,7 @@ namespace Content.Server.Explosion.Components private void UpdateAppearance() { - if (!IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearance)) return; + if (!_entMan.TryGetComponent(Owner, out AppearanceComponent? appearance)) return; appearance.SetData(ClusterFlashVisuals.GrenadesCounter, _grenadesContainer.ContainedEntities.Count + _unspawnedCount); } diff --git a/Content.Server/Explosion/Components/ExplosionLaunchedComponent.cs b/Content.Server/Explosion/Components/ExplosionLaunchedComponent.cs index 85ca431d3a..32f3e95ea4 100644 --- a/Content.Server/Explosion/Components/ExplosionLaunchedComponent.cs +++ b/Content.Server/Explosion/Components/ExplosionLaunchedComponent.cs @@ -9,19 +9,21 @@ namespace Content.Server.Explosion.Components [RegisterComponent] public class ExplosionLaunchedComponent : Component, IExAct { + [Dependency] private readonly IEntityManager _entMan = default!; + public override string Name => "ExplosionLaunched"; void IExAct.OnExplosion(ExplosionEventArgs eventArgs) { - if ((!IoCManager.Resolve().EntityExists(Owner) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(Owner).EntityLifeStage) >= EntityLifeStage.Deleted) + if (_entMan.Deleted(Owner)) return; var sourceLocation = eventArgs.Source; - var targetLocation = IoCManager.Resolve().GetComponent(eventArgs.Target).Coordinates; + var targetLocation = _entMan.GetComponent(eventArgs.Target).Coordinates; if (sourceLocation.Equals(targetLocation)) return; - var offset = (targetLocation.ToMapPos(IoCManager.Resolve()) - sourceLocation.ToMapPos(IoCManager.Resolve())); + var offset = (targetLocation.ToMapPos(_entMan) - sourceLocation.ToMapPos(_entMan)); //Don't throw if the direction is center (0,0) if (offset == Vector2.Zero) return; diff --git a/Content.Server/Extinguisher/FireExtinguisherComponent.cs b/Content.Server/Extinguisher/FireExtinguisherComponent.cs index 26e8a9382c..240777dc2a 100644 --- a/Content.Server/Extinguisher/FireExtinguisherComponent.cs +++ b/Content.Server/Extinguisher/FireExtinguisherComponent.cs @@ -20,6 +20,8 @@ namespace Content.Server.Extinguisher [RegisterComponent] public class FireExtinguisherComponent : SharedFireExtinguisherComponent, IAfterInteract, IUse, IActivate, IDropped { + [Dependency] private readonly IEntityManager _entMan = default!; + public override string Name => "FireExtinguisher"; [DataField("refillSound")] @@ -58,7 +60,7 @@ namespace Content.Server.Extinguisher } if (eventArgs.Target is not {Valid: true} target || - !IoCManager.Resolve().HasComponent(target) || + !_entMan.HasComponent(target) || !solutionContainerSystem.TryGetDrainableSolution(target, out var targetSolution) || !solutionContainerSystem.TryGetDrainableSolution(Owner, out var container)) { @@ -103,13 +105,13 @@ namespace Content.Server.Extinguisher _safety = state; - if (IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearance)) + if (_entMan.TryGetComponent(Owner, out AppearanceComponent? appearance)) appearance.SetData(FireExtinguisherVisuals.Safety, _safety); } void IDropped.Dropped(DroppedEventArgs eventArgs) { - if (_hasSafety && IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearance)) + if (_hasSafety && _entMan.TryGetComponent(Owner, out AppearanceComponent? appearance)) appearance.SetData(FireExtinguisherVisuals.Safety, _safety); } } diff --git a/Content.Server/Fluids/Components/BucketComponent.cs b/Content.Server/Fluids/Components/BucketComponent.cs index bf86cddefc..90fc0677b4 100644 --- a/Content.Server/Fluids/Components/BucketComponent.cs +++ b/Content.Server/Fluids/Components/BucketComponent.cs @@ -23,6 +23,8 @@ namespace Content.Server.Fluids.Components [RegisterComponent] public class BucketComponent : Component, IInteractUsing { + [Dependency] private readonly IEntityManager _entMan = default!; + public override string Name => "Bucket"; public const string SolutionName = "bucket"; @@ -56,7 +58,7 @@ namespace Content.Server.Fluids.Components var solutionsSys = EntitySystem.Get(); if (!solutionsSys.TryGetSolution(Owner, SolutionName, out var contents) || _currentlyUsing.Contains(eventArgs.Using) || - !IoCManager.Resolve().TryGetComponent(eventArgs.Using, out MopComponent? mopComponent) || + !_entMan.TryGetComponent(eventArgs.Using, out MopComponent? mopComponent) || mopComponent.Mopping) { return false; @@ -87,7 +89,7 @@ namespace Content.Server.Fluids.Components _currentlyUsing.Remove(eventArgs.Using); if (result == DoAfterStatus.Cancelled || - (!IoCManager.Resolve().EntityExists(Owner) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(Owner).EntityLifeStage) >= EntityLifeStage.Deleted || + (!_entMan.EntityExists(Owner) ? EntityLifeStage.Deleted : _entMan.GetComponent(Owner).EntityLifeStage) >= EntityLifeStage.Deleted || mopComponent.Deleted || CurrentVolume <= 0 || !Owner.InRangeUnobstructed(mopComponent.Owner)) diff --git a/Content.Server/Fluids/Components/MopComponent.cs b/Content.Server/Fluids/Components/MopComponent.cs index c728e27c35..94463897ba 100644 --- a/Content.Server/Fluids/Components/MopComponent.cs +++ b/Content.Server/Fluids/Components/MopComponent.cs @@ -130,7 +130,7 @@ namespace Content.Server.Fluids.Components Mopping = false; if (result == DoAfterStatus.Cancelled || - (!IoCManager.Resolve().EntityExists(Owner) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(Owner).EntityLifeStage) >= EntityLifeStage.Deleted || + (!_entities.EntityExists(Owner) ? EntityLifeStage.Deleted : _entities.GetComponent(Owner).EntityLifeStage) >= EntityLifeStage.Deleted || puddleComponent.Deleted) return false; @@ -145,7 +145,7 @@ namespace Content.Server.Fluids.Components // is the puddle cleaned? if (puddleSolution.TotalVolume - transferAmount <= 0) { - IoCManager.Resolve().DeleteEntity(puddleComponent.Owner); + _entities.DeleteEntity(puddleComponent.Owner); // After cleaning the puddle, make a new puddle with solution from the mop as a "wet floor". Then evaporate it slowly. // we do this WITHOUT adding to the existing puddle. Otherwise we have might have water puddles with the vomit sprite. diff --git a/Content.Server/Fluids/Components/SprayComponent.cs b/Content.Server/Fluids/Components/SprayComponent.cs index 2fbcbbca98..e9c3433fed 100644 --- a/Content.Server/Fluids/Components/SprayComponent.cs +++ b/Content.Server/Fluids/Components/SprayComponent.cs @@ -31,6 +31,7 @@ namespace Content.Server.Fluids.Components public const float SprayDistance = 3f; public const string SolutionName = "spray"; + [Dependency] private readonly IEntityManager _entMan = default!; [Dependency] private readonly IGameTiming _gameTiming = default!; [DataField("transferAmount")] @@ -99,8 +100,8 @@ namespace Content.Server.Fluids.Components if(curTime < _cooldownEnd) return true; - var playerPos = IoCManager.Resolve().GetComponent(eventArgs.User).Coordinates; - var entManager = IoCManager.Resolve(); + var playerPos = _entMan.GetComponent(eventArgs.User).Coordinates; + var entManager = _entMan; if (eventArgs.ClickLocation.GetGridId(entManager) != playerPos.GetGridId(entManager)) return true; @@ -124,10 +125,10 @@ namespace Content.Server.Fluids.Components var diffNorm = diffPos.Normalized; var diffLength = diffPos.Length; - var target = IoCManager.Resolve().GetComponent(eventArgs.User).Coordinates.Offset((diffNorm + rotation.ToVec()).Normalized * diffLength + quarter); + var target = _entMan.GetComponent(eventArgs.User).Coordinates.Offset((diffNorm + rotation.ToVec()).Normalized * diffLength + quarter); - if (target.TryDistance(IoCManager.Resolve(), playerPos, out var distance) && distance > SprayDistance) - target = IoCManager.Resolve().GetComponent(eventArgs.User).Coordinates.Offset(diffNorm * SprayDistance); + if (target.TryDistance(_entMan, playerPos, out var distance) && distance > SprayDistance) + target = _entMan.GetComponent(eventArgs.User).Coordinates.Offset(diffNorm * SprayDistance); var solution = EntitySystem.Get().SplitSolution(Owner, contents, _transferAmount); @@ -135,24 +136,24 @@ namespace Content.Server.Fluids.Components break; var vapor = entManager.SpawnEntity(_vaporPrototype, playerPos.Offset(distance < 1 ? quarter : threeQuarters)); - IoCManager.Resolve().GetComponent(vapor).LocalRotation = rotation; + _entMan.GetComponent(vapor).LocalRotation = rotation; - if (IoCManager.Resolve().TryGetComponent(vapor, out AppearanceComponent? appearance)) + if (_entMan.TryGetComponent(vapor, out AppearanceComponent? appearance)) { appearance.SetData(VaporVisuals.Color, contents.Color.WithAlpha(1f)); appearance.SetData(VaporVisuals.State, true); } // Add the solution to the vapor and actually send the thing - var vaporComponent = IoCManager.Resolve().GetComponent(vapor); + var vaporComponent = _entMan.GetComponent(vapor); var vaporSystem = EntitySystem.Get(); vaporSystem.TryAddSolution(vaporComponent, solution); // impulse direction is defined in world-coordinates, not local coordinates - var impulseDirection = IoCManager.Resolve().GetComponent(vapor).WorldRotation.ToVec(); + var impulseDirection = _entMan.GetComponent(vapor).WorldRotation.ToVec(); vaporSystem.Start(vaporComponent, impulseDirection, _sprayVelocity, target, _sprayAliveTime); - if (_impulse > 0f && IoCManager.Resolve().TryGetComponent(eventArgs.User, out IPhysBody? body)) + if (_impulse > 0f && _entMan.TryGetComponent(eventArgs.User, out IPhysBody? body)) { body.ApplyLinearImpulse(-impulseDirection * _impulse); } @@ -163,7 +164,7 @@ namespace Content.Server.Fluids.Components _lastUseTime = curTime; _cooldownEnd = _lastUseTime + TimeSpan.FromSeconds(_cooldownTime); - if (IoCManager.Resolve().TryGetComponent(Owner, out ItemCooldownComponent? cooldown)) + if (_entMan.TryGetComponent(Owner, out ItemCooldownComponent? cooldown)) { cooldown.CooldownStart = _lastUseTime; cooldown.CooldownEnd = _cooldownEnd; diff --git a/Content.Server/GameTicking/GameTicker.RoundFlow.cs b/Content.Server/GameTicking/GameTicker.RoundFlow.cs index 5fe4938ecb..1cd48d0180 100644 --- a/Content.Server/GameTicking/GameTicker.RoundFlow.cs +++ b/Content.Server/GameTicking/GameTicker.RoundFlow.cs @@ -278,7 +278,7 @@ namespace Content.Server.GameTicking if (mind.CharacterName != null) playerIcName = mind.CharacterName; else if (mind.CurrentEntity != null) - playerIcName = IoCManager.Resolve().GetComponent(mind.CurrentEntity.Value).EntityName; + playerIcName = EntityManager.GetComponent(mind.CurrentEntity.Value).EntityName; var playerEndRoundInfo = new RoundEndMessageEvent.RoundEndPlayerInfo() { @@ -369,7 +369,7 @@ namespace Content.Server.GameTicking { // TODO: Maybe something less naive here? // FIXME: Actually, definitely. - IoCManager.Resolve().DeleteEntity(entity); + EntityManager.DeleteEntity(entity); } _mapManager.Restart(); diff --git a/Content.Server/GameTicking/Presets/GamePreset.cs b/Content.Server/GameTicking/Presets/GamePreset.cs index fa6ef63a06..f9cb77de42 100644 --- a/Content.Server/GameTicking/Presets/GamePreset.cs +++ b/Content.Server/GameTicking/Presets/GamePreset.cs @@ -76,8 +76,7 @@ namespace Content.Server.GameTicking.Presets } } - var entityManager = IoCManager.Resolve(); - var ghost = entityManager.SpawnEntity("MobObserver", position.ToMap(entityManager)); + var ghost = entities.SpawnEntity("MobObserver", position.ToMap(entities)); // Try setting the ghost entity name to either the character name or the player name. // If all else fails, it'll default to the default entity prototype name, "observer". @@ -87,7 +86,7 @@ namespace Content.Server.GameTicking.Presets else if (!string.IsNullOrWhiteSpace(mind.Session?.Name)) entities.GetComponent(ghost).EntityName = mind.Session.Name; - var ghostComponent = IoCManager.Resolve().GetComponent(ghost); + var ghostComponent = entities.GetComponent(ghost); if (mind.TimeOfDeath.HasValue) { diff --git a/Content.Server/Ghost/Components/GhostRadioComponent.cs b/Content.Server/Ghost/Components/GhostRadioComponent.cs index 1d064702dc..382424b138 100644 --- a/Content.Server/Ghost/Components/GhostRadioComponent.cs +++ b/Content.Server/Ghost/Components/GhostRadioComponent.cs @@ -15,6 +15,7 @@ namespace Content.Server.Ghost.Components public class GhostRadioComponent : Component, IRadio { [Dependency] private readonly IServerNetManager _netManager = default!; + [Dependency] private readonly IEntityManager _entMan = default!; public override string Name => "GhostRadio"; @@ -25,7 +26,7 @@ namespace Content.Server.Ghost.Components public void Receive(string message, int channel, EntityUid speaker) { - if (!IoCManager.Resolve().TryGetComponent(Owner, out ActorComponent? actor)) + if (!_entMan.TryGetComponent(Owner, out ActorComponent? actor)) return; var playerChannel = actor.PlayerSession.ConnectedClient; @@ -35,7 +36,7 @@ namespace Content.Server.Ghost.Components msg.Channel = ChatChannel.Radio; msg.Message = message; //Square brackets are added here to avoid issues with escaping - msg.MessageWrap = Loc.GetString("chat-radio-message-wrap", ("channel", $"\\[{channel}\\]"), ("name", Name: IoCManager.Resolve().GetComponent(speaker).EntityName)); + msg.MessageWrap = Loc.GetString("chat-radio-message-wrap", ("channel", $"\\[{channel}\\]"), ("name", Name: _entMan.GetComponent(speaker).EntityName)); _netManager.ServerSendMessage(msg, playerChannel); } diff --git a/Content.Server/Ghost/Roles/Components/GhostRoleMobSpawnerComponent.cs b/Content.Server/Ghost/Roles/Components/GhostRoleMobSpawnerComponent.cs index f75c4f273c..fda3a82772 100644 --- a/Content.Server/Ghost/Roles/Components/GhostRoleMobSpawnerComponent.cs +++ b/Content.Server/Ghost/Roles/Components/GhostRoleMobSpawnerComponent.cs @@ -16,6 +16,8 @@ namespace Content.Server.Ghost.Roles.Components [RegisterComponent, ComponentReference(typeof(GhostRoleComponent))] public class GhostRoleMobSpawnerComponent : GhostRoleComponent { + [Dependency] private readonly IEntityManager _entMan = default!; + public override string Name => "GhostRoleMobSpawner"; [ViewVariables(VVAccess.ReadWrite)] [DataField("deleteOnSpawn")] @@ -40,10 +42,10 @@ namespace Content.Server.Ghost.Roles.Components if (string.IsNullOrEmpty(Prototype)) throw new NullReferenceException("Prototype string cannot be null or empty!"); - var mob = IoCManager.Resolve().SpawnEntity(Prototype, IoCManager.Resolve().GetComponent(Owner).Coordinates); + var mob = _entMan.SpawnEntity(Prototype, _entMan.GetComponent(Owner).Coordinates); if (MakeSentient) - MakeSentientCommand.MakeSentient(mob, IoCManager.Resolve()); + MakeSentientCommand.MakeSentient(mob, _entMan); mob.EnsureComponent(); @@ -56,7 +58,7 @@ namespace Content.Server.Ghost.Roles.Components Taken = true; if (_deleteOnSpawn) - IoCManager.Resolve().DeleteEntity(Owner); + _entMan.DeleteEntity(Owner); return true; } diff --git a/Content.Server/Headset/HeadsetComponent.cs b/Content.Server/Headset/HeadsetComponent.cs index 92970f1e6c..7ebed04056 100644 --- a/Content.Server/Headset/HeadsetComponent.cs +++ b/Content.Server/Headset/HeadsetComponent.cs @@ -22,6 +22,7 @@ namespace Content.Server.Headset public class HeadsetComponent : Component, IListen, IRadio, IExamine #pragma warning restore 618 { + [Dependency] private readonly IEntityManager _entMan = default!; [Dependency] private readonly IServerNetManager _netManager = default!; public override string Name => "Headset"; @@ -59,7 +60,7 @@ namespace Content.Server.Headset { if (Owner.TryGetContainer(out var container)) { - if (!IoCManager.Resolve().TryGetComponent(container.Owner, out ActorComponent? actor)) + if (!_entMan.TryGetComponent(container.Owner, out ActorComponent? actor)) return; var playerChannel = actor.PlayerSession.ConnectedClient; @@ -69,7 +70,7 @@ namespace Content.Server.Headset msg.Channel = ChatChannel.Radio; msg.Message = message; //Square brackets are added here to avoid issues with escaping - msg.MessageWrap = Loc.GetString("chat-radio-message-wrap", ("channel", $"\\[{channel}\\]"), ("name", Name: IoCManager.Resolve().GetComponent(source).EntityName)); + msg.MessageWrap = Loc.GetString("chat-radio-message-wrap", ("channel", $"\\[{channel}\\]"), ("name", Name: _entMan.GetComponent(source).EntityName)); _netManager.ServerSendMessage(msg, playerChannel); } } diff --git a/Content.Server/Instruments/InstrumentComponent.cs b/Content.Server/Instruments/InstrumentComponent.cs index bd8b50bb13..36538a75f7 100644 --- a/Content.Server/Instruments/InstrumentComponent.cs +++ b/Content.Server/Instruments/InstrumentComponent.cs @@ -11,6 +11,8 @@ namespace Content.Server.Instruments; [RegisterComponent, ComponentReference(typeof(SharedInstrumentComponent))] public sealed class InstrumentComponent : SharedInstrumentComponent { + [Dependency] private readonly IEntityManager _entMan = default!; + [ViewVariables] public float Timer = 0f; @@ -23,9 +25,10 @@ public sealed class InstrumentComponent : SharedInstrumentComponent [ViewVariables] public int MidiEventCount = 0; + // TODO Instruments: Make this ECS public IPlayerSession? InstrumentPlayer => - IoCManager.Resolve().GetComponentOrNull(Owner)?.CurrentSingleUser - ?? IoCManager.Resolve().GetComponentOrNull(Owner)?.PlayerSession; + _entMan.GetComponentOrNull(Owner)?.CurrentSingleUser + ?? _entMan.GetComponentOrNull(Owner)?.PlayerSession; [ViewVariables] public BoundUserInterface? UserInterface => Owner.GetUIOrNull(InstrumentUiKey.Key); } diff --git a/Content.Server/Inventory/Components/DebugEquipComponent.cs b/Content.Server/Inventory/Components/DebugEquipComponent.cs index 00d27af966..9f648aa886 100644 --- a/Content.Server/Inventory/Components/DebugEquipComponent.cs +++ b/Content.Server/Inventory/Components/DebugEquipComponent.cs @@ -13,26 +13,28 @@ namespace Content.Server.Inventory.Components [RegisterComponent] public class DebugEquipComponent : Component, IEquipped, IEquippedHand, IUnequipped, IUnequippedHand { + [Dependency] private readonly IEntityManager _entMan = default!; + public override string Name => "DebugEquip"; void IEquipped.Equipped(EquippedEventArgs eventArgs) { - eventArgs.User.PopupMessage("equipped " + IoCManager.Resolve().GetComponent(Owner).EntityName); + eventArgs.User.PopupMessage("equipped " + _entMan.GetComponent(Owner).EntityName); } void IEquippedHand.EquippedHand(EquippedHandEventArgs eventArgs) { - eventArgs.User.PopupMessage("equipped hand " + IoCManager.Resolve().GetComponent(Owner).EntityName); + eventArgs.User.PopupMessage("equipped hand " + _entMan.GetComponent(Owner).EntityName); } void IUnequipped.Unequipped(UnequippedEventArgs eventArgs) { - eventArgs.User.PopupMessage("unequipped " + IoCManager.Resolve().GetComponent(Owner).EntityName); + eventArgs.User.PopupMessage("unequipped " + _entMan.GetComponent(Owner).EntityName); } void IUnequippedHand.UnequippedHand(UnequippedHandEventArgs eventArgs) { - eventArgs.User.PopupMessage("unequipped hand" + IoCManager.Resolve().GetComponent(Owner).EntityName); + eventArgs.User.PopupMessage("unequipped hand" + _entMan.GetComponent(Owner).EntityName); } } } diff --git a/Content.Server/Inventory/InventoryHelpers.cs b/Content.Server/Inventory/InventoryHelpers.cs index 59a4472df7..72434e4476 100644 --- a/Content.Server/Inventory/InventoryHelpers.cs +++ b/Content.Server/Inventory/InventoryHelpers.cs @@ -16,7 +16,7 @@ namespace Content.Server.Inventory var user = inventory.Owner; // Let's do nothing if the owner of the inventory has been deleted. - if ((!IoCManager.Resolve().EntityExists(user) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(user).EntityLifeStage) >= EntityLifeStage.Deleted) + if ((!entityManager.EntityExists(user) ? EntityLifeStage.Deleted : entityManager.GetComponent(user).EntityLifeStage) >= EntityLifeStage.Deleted) return false; // If we don't have that slot or there's already an item there, we do nothing. @@ -28,17 +28,17 @@ namespace Content.Server.Inventory return false; // Let's spawn this first... - var item = entityManager.SpawnEntity(prototype, IoCManager.Resolve().GetComponent(user).MapPosition); + var item = entityManager.SpawnEntity(prototype, entityManager.GetComponent(user).MapPosition); // Helper method that deletes the item and returns false. bool DeleteItem() { - IoCManager.Resolve().DeleteEntity(item); + entityManager.DeleteEntity(item); return false; } // If this doesn't have an item component, then we can't do anything with it. - if (!IoCManager.Resolve().TryGetComponent(item, out ItemComponent? itemComp)) + if (!entityManager.TryGetComponent(item, out ItemComponent? itemComp)) return DeleteItem(); // We finally try to equip the item, otherwise we delete it. diff --git a/Content.Server/Jobs/GiveItemOnHolidaySpecial.cs b/Content.Server/Jobs/GiveItemOnHolidaySpecial.cs index 4f5b85a7b6..59dc087740 100644 --- a/Content.Server/Jobs/GiveItemOnHolidaySpecial.cs +++ b/Content.Server/Jobs/GiveItemOnHolidaySpecial.cs @@ -29,9 +29,11 @@ namespace Content.Server.Jobs if (!EntitySystem.Get().IsCurrentlyHoliday(Holiday)) return; - var entity = IoCManager.Resolve().SpawnEntity(Prototype, IoCManager.Resolve().GetComponent(mob).Coordinates); + var entMan = IoCManager.Resolve(); - if (!IoCManager.Resolve().TryGetComponent(entity, out ItemComponent? item) || !IoCManager.Resolve().TryGetComponent(mob, out HandsComponent? hands)) + var entity = entMan.SpawnEntity(Prototype, entMan.GetComponent(mob).Coordinates); + + if (!entMan.TryGetComponent(entity, out ItemComponent? item) || !entMan.TryGetComponent(mob, out HandsComponent? hands)) return; hands.PutInHand(item, false); diff --git a/Content.Server/Kitchen/Components/KitchenSpikeComponent.cs b/Content.Server/Kitchen/Components/KitchenSpikeComponent.cs index 7f9be4d5c2..11802518ee 100644 --- a/Content.Server/Kitchen/Components/KitchenSpikeComponent.cs +++ b/Content.Server/Kitchen/Components/KitchenSpikeComponent.cs @@ -22,6 +22,8 @@ namespace Content.Server.Kitchen.Components [ComponentReference(typeof(IActivate))] public class KitchenSpikeComponent : SharedKitchenSpikeComponent, IActivate, ISuicideAct { + [Dependency] private readonly IEntityManager _entMan = default!; + private int _meatParts; private string? _meatPrototype; private string _meatSource1p = "?"; @@ -40,8 +42,8 @@ namespace Content.Server.Kitchen.Components if (!string.IsNullOrEmpty(_meatPrototype)) { - var meat = IoCManager.Resolve().SpawnEntity(_meatPrototype, IoCManager.Resolve().GetComponent(Owner).Coordinates); - IoCManager.Resolve().GetComponent(meat).EntityName = _meatName; + var meat = _entMan.SpawnEntity(_meatPrototype, _entMan.GetComponent(Owner).Coordinates); + _entMan.GetComponent(meat).EntityName = _meatName; } if (_meatParts != 0) @@ -67,7 +69,7 @@ namespace Content.Server.Kitchen.Components private void UpdateAppearance() { - if (IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearance)) + if (_entMan.TryGetComponent(Owner, out AppearanceComponent? appearance)) { appearance.SetData(KitchenSpikeVisuals.Status, (_meatParts > 0) ? KitchenSpikeStatus.Bloody : KitchenSpikeStatus.Empty); } @@ -83,7 +85,7 @@ namespace Content.Server.Kitchen.Components return false; } - if (!IoCManager.Resolve().TryGetComponent(victim, out butcherable)) + if (!_entMan.TryGetComponent(victim, out butcherable)) { Owner.PopupMessage(user, Loc.GetString("comp-kitchen-spike-deny-butcher", ("victim", victim), ("this", Owner))); return false; @@ -106,7 +108,7 @@ namespace Content.Server.Kitchen.Components return; // Prevent dead from being spiked TODO: Maybe remove when rounds can be played and DOT is implemented - if (IoCManager.Resolve().TryGetComponent(victim, out var state) && + if (_entMan.TryGetComponent(victim, out var state) && !state.IsDead()) { Owner.PopupMessage(user, Loc.GetString("comp-kitchen-spike-deny-not-dead", ("victim", victim))); @@ -154,7 +156,7 @@ namespace Content.Server.Kitchen.Components Owner.PopupMessageEveryone(Loc.GetString("comp-kitchen-spike-kill", ("user", user), ("victim", victim))); // TODO: Need to be able to leave them on the spike to do DoT, see ss13. - IoCManager.Resolve().DeleteEntity((EntityUid) victim); + _entMan.DeleteEntity((EntityUid) victim); SoundSystem.Play(Filter.Pvs(Owner), SpikeSound.GetSound(), Owner); } diff --git a/Content.Server/Lathe/Components/LatheComponent.cs b/Content.Server/Lathe/Components/LatheComponent.cs index 75b4edb4a6..a1800ce947 100644 --- a/Content.Server/Lathe/Components/LatheComponent.cs +++ b/Content.Server/Lathe/Components/LatheComponent.cs @@ -23,6 +23,8 @@ namespace Content.Server.Lathe.Components [ComponentReference(typeof(IActivate))] public class LatheComponent : SharedLatheComponent, IInteractUsing, IActivate { + [Dependency] private readonly IEntityManager _entMan = default!; + public const int VolumePerSheet = 100; [ViewVariables] @@ -42,7 +44,7 @@ namespace Content.Server.Lathe.Components [ViewVariables] private LatheRecipePrototype? _producingRecipe; [ViewVariables] - private bool Powered => !IoCManager.Resolve().TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered; + private bool Powered => !_entMan.TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered; private static readonly TimeSpan InsertionTime = TimeSpan.FromSeconds(0.9f); @@ -75,20 +77,20 @@ namespace Content.Server.Lathe.Components } break; case LatheSyncRequestMessage _: - if (!IoCManager.Resolve().HasComponent(Owner)) return; + if (!_entMan.HasComponent(Owner)) return; UserInterface?.SendMessage(new LatheFullQueueMessage(GetIdQueue())); if (_producingRecipe != null) UserInterface?.SendMessage(new LatheProducingRecipeMessage(_producingRecipe.ID)); break; case LatheServerSelectionMessage _: - if (!IoCManager.Resolve().TryGetComponent(Owner, out ResearchClientComponent? researchClient)) return; + if (!_entMan.TryGetComponent(Owner, out ResearchClientComponent? researchClient)) return; researchClient.OpenUserInterface(message.Session); break; case LatheServerSyncMessage _: - if (!IoCManager.Resolve().TryGetComponent(Owner, out TechnologyDatabaseComponent? database) - || !IoCManager.Resolve().TryGetComponent(Owner, out ProtolatheDatabaseComponent? protoDatabase)) return; + if (!_entMan.TryGetComponent(Owner, out TechnologyDatabaseComponent? database) + || !_entMan.TryGetComponent(Owner, out ProtolatheDatabaseComponent? protoDatabase)) return; if (database.SyncWithServer()) protoDatabase.Sync(); @@ -101,7 +103,7 @@ namespace Content.Server.Lathe.Components internal bool Produce(LatheRecipePrototype recipe) { - if (Producing || !Powered || !CanProduce(recipe) || !IoCManager.Resolve().TryGetComponent(Owner, out MaterialStorageComponent? storage)) return false; + if (Producing || !Powered || !CanProduce(recipe) || !_entMan.TryGetComponent(Owner, out MaterialStorageComponent? storage)) return false; UserInterface?.SendMessage(new LatheFullQueueMessage(GetIdQueue())); @@ -123,7 +125,7 @@ namespace Content.Server.Lathe.Components { Producing = false; _producingRecipe = null; - IoCManager.Resolve().SpawnEntity(recipe.Result, IoCManager.Resolve().GetComponent(Owner).Coordinates); + _entMan.SpawnEntity(recipe.Result, _entMan.GetComponent(Owner).Coordinates); UserInterface?.SendMessage(new LatheStoppedProducingRecipeMessage()); State = LatheState.Base; SetAppearance(LatheVisualState.Idle); @@ -139,7 +141,7 @@ namespace Content.Server.Lathe.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) { @@ -151,12 +153,12 @@ namespace Content.Server.Lathe.Components async Task IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs) { - if (!IoCManager.Resolve().TryGetComponent(Owner, out MaterialStorageComponent? storage) - || !IoCManager.Resolve().TryGetComponent(eventArgs.Using, out MaterialComponent? material)) return false; + if (!_entMan.TryGetComponent(Owner, out MaterialStorageComponent? storage) + || !_entMan.TryGetComponent(eventArgs.Using, out MaterialComponent? material)) return false; var multiplier = 1; - if (IoCManager.Resolve().TryGetComponent(eventArgs.Using, out StackComponent? stack)) multiplier = stack.Count; + if (_entMan.TryGetComponent(eventArgs.Using, out StackComponent? stack)) multiplier = stack.Count; var totalAmount = 0; @@ -202,14 +204,14 @@ namespace Content.Server.Lathe.Components SetAppearance(LatheVisualState.Idle); }); - IoCManager.Resolve().DeleteEntity(eventArgs.Using); + _entMan.DeleteEntity(eventArgs.Using); return true; } private void SetAppearance(LatheVisualState state) { - if (IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearance)) + if (_entMan.TryGetComponent(Owner, out AppearanceComponent? appearance)) { appearance.SetData(PowerDeviceVisuals.VisualState, state); } diff --git a/Content.Server/Light/Components/EmergencyLightComponent.cs b/Content.Server/Light/Components/EmergencyLightComponent.cs index d4ba9c4b3d..23fd78c9eb 100644 --- a/Content.Server/Light/Components/EmergencyLightComponent.cs +++ b/Content.Server/Light/Components/EmergencyLightComponent.cs @@ -21,6 +21,8 @@ namespace Content.Server.Light.Components public class EmergencyLightComponent : SharedEmergencyLightComponent, IExamine #pragma warning restore 618 { + [Dependency] private readonly IEntityManager _entMan = default!; + [ViewVariables] private EmergencyLightState State { @@ -31,7 +33,7 @@ namespace Content.Server.Light.Components return; _state = value; - IoCManager.Resolve().EventBus.RaiseEvent(EventSource.Local, new EmergencyLightMessage(this, _state)); + _entMan.EventBus.RaiseEvent(EventSource.Local, new EmergencyLightMessage(this, _state)); } } @@ -60,7 +62,7 @@ namespace Content.Server.Light.Components /// public void UpdateState() { - if (!IoCManager.Resolve().TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver)) + if (!_entMan.TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver)) { return; } @@ -80,7 +82,7 @@ namespace Content.Server.Light.Components public void OnUpdate(float frameTime) { - if ((!IoCManager.Resolve().EntityExists(Owner) || !IoCManager.Resolve().TryGetComponent(Owner, out BatteryComponent? battery) || IoCManager.Resolve().GetComponent(Owner).EntityPaused)) + if ((!_entMan.EntityExists(Owner) || !_entMan.TryGetComponent(Owner, out BatteryComponent? battery) || _entMan.GetComponent(Owner).EntityPaused)) { return; } @@ -98,7 +100,7 @@ namespace Content.Server.Light.Components battery.CurrentCharge += _chargingWattage * frameTime * _chargingEfficiency; if (battery.IsFullyCharged) { - if (IoCManager.Resolve().TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver)) + if (_entMan.TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver)) { receiver.Load = 1; } @@ -110,23 +112,23 @@ namespace Content.Server.Light.Components private void TurnOff() { - if (IoCManager.Resolve().TryGetComponent(Owner, out PointLightComponent? light)) + if (_entMan.TryGetComponent(Owner, out PointLightComponent? light)) { light.Enabled = false; } - if (IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearance)) + if (_entMan.TryGetComponent(Owner, out AppearanceComponent? appearance)) appearance.SetData(EmergencyLightVisuals.On, false); } private void TurnOn() { - if (IoCManager.Resolve().TryGetComponent(Owner, out PointLightComponent? light)) + if (_entMan.TryGetComponent(Owner, out PointLightComponent? light)) { light.Enabled = true; } - if (IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearance)) + if (_entMan.TryGetComponent(Owner, out AppearanceComponent? appearance)) appearance.SetData(EmergencyLightVisuals.On, true); } diff --git a/Content.Server/Light/Components/ExpendableLightComponent.cs b/Content.Server/Light/Components/ExpendableLightComponent.cs index cda164a995..2e4b05ddd2 100644 --- a/Content.Server/Light/Components/ExpendableLightComponent.cs +++ b/Content.Server/Light/Components/ExpendableLightComponent.cs @@ -17,6 +17,8 @@ namespace Content.Server.Light.Components [RegisterComponent] public class ExpendableLightComponent : SharedExpendableLightComponent, IUse { + [Dependency] private readonly IEntityManager _entMan = default!; + /// /// Status of light, whether or not it is emitting light. /// @@ -36,14 +38,14 @@ namespace Content.Server.Light.Components { base.Initialize(); - if (IoCManager.Resolve().TryGetComponent(Owner, out var item)) + if (_entMan.TryGetComponent(Owner, out var item)) { item.EquippedPrefix = "unlit"; } CurrentState = ExpendableLightState.BrandNew; Owner.EnsureComponent(); - IoCManager.Resolve().TryGetComponent(Owner, out _appearance); + _entMan.TryGetComponent(Owner, out _appearance); } /// @@ -53,7 +55,7 @@ namespace Content.Server.Light.Components { if (!Activated && CurrentState == ExpendableLightState.BrandNew) { - if (IoCManager.Resolve().TryGetComponent(Owner, out var item)) + if (_entMan.TryGetComponent(Owner, out var item)) { item.EquippedPrefix = "lit"; } @@ -92,7 +94,7 @@ namespace Content.Server.Light.Components private void UpdateSpriteAndSounds(bool on) { - if (IoCManager.Resolve().TryGetComponent(Owner, out SpriteComponent? sprite)) + if (_entMan.TryGetComponent(Owner, out SpriteComponent? sprite)) { switch (CurrentState) { @@ -126,7 +128,7 @@ namespace Content.Server.Light.Components } } - if (IoCManager.Resolve().TryGetComponent(Owner, out ClothingComponent? clothing)) + if (_entMan.TryGetComponent(Owner, out ClothingComponent? clothing)) { clothing.ClothingEquippedPrefix = on ? "Activated" : string.Empty; } @@ -155,13 +157,13 @@ namespace Content.Server.Light.Components case ExpendableLightState.Fading: CurrentState = ExpendableLightState.Dead; - IoCManager.Resolve().GetComponent(Owner).EntityName = SpentName; - IoCManager.Resolve().GetComponent(Owner).EntityDescription = SpentDesc; + _entMan.GetComponent(Owner).EntityName = SpentName; + _entMan.GetComponent(Owner).EntityDescription = SpentDesc; UpdateSpriteAndSounds(Activated); UpdateVisualizer(); - if (IoCManager.Resolve().TryGetComponent(Owner, out var item)) + if (_entMan.TryGetComponent(Owner, out var item)) { item.EquippedPrefix = "unlit"; } diff --git a/Content.Server/Light/Components/HandheldLightComponent.cs b/Content.Server/Light/Components/HandheldLightComponent.cs index aeffe30419..dc8b6d7560 100644 --- a/Content.Server/Light/Components/HandheldLightComponent.cs +++ b/Content.Server/Light/Components/HandheldLightComponent.cs @@ -34,6 +34,8 @@ namespace Content.Server.Light.Components internal sealed class HandheldLightComponent : SharedHandheldLightComponent, IUse, IExamine, IInteractUsing #pragma warning restore 618 { + [Dependency] private readonly IEntityManager _entMan = default!; + [ViewVariables(VVAccess.ReadWrite)] [DataField("wattage")] public float Wattage { get; set; } = 3f; [ViewVariables] private PowerCellSlotComponent _cellSlot = default!; private PowerCellComponent? Cell => _cellSlot.Cell; @@ -70,7 +72,7 @@ namespace Content.Server.Light.Components protected override void OnRemove() { base.OnRemove(); - IoCManager.Resolve().EventBus.QueueEvent(EventSource.Local, new DeactivateHandheldLightMessage(this)); + _entMan.EventBus.QueueEvent(EventSource.Local, new DeactivateHandheldLightMessage(this)); } async Task IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs) @@ -118,7 +120,7 @@ namespace Content.Server.Light.Components SetState(false); Activated = false; UpdateLightAction(); - IoCManager.Resolve().EventBus.QueueEvent(EventSource.Local, new DeactivateHandheldLightMessage(this)); + _entMan.EventBus.QueueEvent(EventSource.Local, new DeactivateHandheldLightMessage(this)); if (makeNoise) { @@ -157,7 +159,7 @@ namespace Content.Server.Light.Components Activated = true; UpdateLightAction(); SetState(true); - IoCManager.Resolve().EventBus.QueueEvent(EventSource.Local, new ActivateHandheldLightMessage(this)); + _entMan.EventBus.QueueEvent(EventSource.Local, new ActivateHandheldLightMessage(this)); SoundSystem.Play(Filter.Pvs(Owner), TurnOnSound.GetSound(), Owner); return true; @@ -165,22 +167,22 @@ namespace Content.Server.Light.Components private void SetState(bool on) { - if (IoCManager.Resolve().TryGetComponent(Owner, out SpriteComponent? sprite)) + if (_entMan.TryGetComponent(Owner, out SpriteComponent? sprite)) { sprite.LayerSetVisible(1, on); } - if (IoCManager.Resolve().TryGetComponent(Owner, out PointLightComponent? light)) + if (_entMan.TryGetComponent(Owner, out PointLightComponent? light)) { light.Enabled = on; } - if (IoCManager.Resolve().TryGetComponent(Owner, out ClothingComponent? clothing)) + if (_entMan.TryGetComponent(Owner, out ClothingComponent? clothing)) { clothing.ClothingEquippedPrefix = Loc.GetString(on ? "on" : "off"); } - if (IoCManager.Resolve().TryGetComponent(Owner, out ItemComponent? item)) + if (_entMan.TryGetComponent(Owner, out ItemComponent? item)) { item.EquippedPrefix = Loc.GetString(on ? "on" : "off"); } @@ -199,7 +201,7 @@ namespace Content.Server.Light.Components return; } - var appearanceComponent = IoCManager.Resolve().GetComponent(Owner); + var appearanceComponent = _entMan.GetComponent(Owner); if (Cell.MaxCharge - Cell.CurrentCharge < Cell.MaxCharge * 0.70) { diff --git a/Content.Server/Medical/Components/HealingComponent.cs b/Content.Server/Medical/Components/HealingComponent.cs index 12fd1d3cea..d3b7ade405 100644 --- a/Content.Server/Medical/Components/HealingComponent.cs +++ b/Content.Server/Medical/Components/HealingComponent.cs @@ -19,6 +19,8 @@ namespace Content.Server.Medical.Components [RegisterComponent] public class HealingComponent : Component, IAfterInteract { + [Dependency] private readonly IEntityManager _entMan = default!; + public override string Name => "Healing"; [DataField("damage", required: true)] @@ -40,7 +42,7 @@ namespace Content.Server.Medical.Components return false; } - if (!IoCManager.Resolve().TryGetComponent(eventArgs.Target.Value, out DamageableComponent? targetDamage)) + if (!_entMan.TryGetComponent(eventArgs.Target.Value, out DamageableComponent? targetDamage)) { return true; } @@ -60,7 +62,7 @@ namespace Content.Server.Medical.Components return true; } - if (IoCManager.Resolve().TryGetComponent(Owner, out var stack) && !EntitySystem.Get().Use(Owner, 1, stack)) + if (_entMan.TryGetComponent(Owner, out var stack) && !EntitySystem.Get().Use(Owner, 1, stack)) { return true; } diff --git a/Content.Server/Medical/Components/MedicalScannerComponent.cs b/Content.Server/Medical/Components/MedicalScannerComponent.cs index 80c8b9a176..2ff3235ab9 100644 --- a/Content.Server/Medical/Components/MedicalScannerComponent.cs +++ b/Content.Server/Medical/Components/MedicalScannerComponent.cs @@ -28,6 +28,7 @@ namespace Content.Server.Medical.Components [ComponentReference(typeof(SharedMedicalScannerComponent))] public class MedicalScannerComponent : SharedMedicalScannerComponent, IActivate, IDestroyAct { + [Dependency] private readonly IEntityManager _entMan = default!; [Dependency] private readonly IServerPreferencesManager _prefsManager = null!; public static readonly TimeSpan InternalOpenAttemptDelay = TimeSpan.FromSeconds(0.5); @@ -36,7 +37,7 @@ namespace Content.Server.Medical.Components private ContainerSlot _bodyContainer = default!; [ViewVariables] - private bool Powered => !IoCManager.Resolve().TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered; + private bool Powered => !_entMan.TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered; [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(MedicalScannerUiKey.Key); @@ -71,7 +72,7 @@ namespace Content.Server.Medical.Components var body = _bodyContainer.ContainedEntity; if (body == null) { - if (IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearance)) + if (_entMan.TryGetComponent(Owner, out AppearanceComponent? appearance)) { appearance?.SetData(MedicalScannerVisuals.Status, MedicalScannerStatus.Open); } @@ -79,7 +80,7 @@ namespace Content.Server.Medical.Components return EmptyUIState; } - if (!IoCManager.Resolve().TryGetComponent(body.Value, out DamageableComponent? damageable)) + if (!_entMan.TryGetComponent(body.Value, out DamageableComponent? damageable)) { return EmptyUIState; } @@ -90,7 +91,7 @@ namespace Content.Server.Medical.Components } var cloningSystem = EntitySystem.Get(); - var scanned = IoCManager.Resolve().TryGetComponent(_bodyContainer.ContainedEntity.Value, out MindComponent? mindComponent) && + var scanned = _entMan.TryGetComponent(_bodyContainer.ContainedEntity.Value, out MindComponent? mindComponent) && mindComponent.Mind != null && cloningSystem.HasDnaScan(mindComponent.Mind); @@ -136,7 +137,7 @@ namespace Content.Server.Medical.Components if (body == null) return MedicalScannerStatus.Open; - var state = IoCManager.Resolve().GetComponentOrNull(body.Value); + var state = _entMan.GetComponentOrNull(body.Value); return state == null ? MedicalScannerStatus.Open : GetStatusFromDamageState(state); } @@ -146,7 +147,7 @@ namespace Content.Server.Medical.Components private void UpdateAppearance() { - if (IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearance)) + if (_entMan.TryGetComponent(Owner, out AppearanceComponent? appearance)) { appearance.SetData(MedicalScannerVisuals.Status, GetStatus()); } @@ -154,7 +155,7 @@ namespace Content.Server.Medical.Components void IActivate.Activate(ActivateEventArgs args) { - if (!IoCManager.Resolve().TryGetComponent(args.User, out ActorComponent? actor)) + if (!_entMan.TryGetComponent(args.User, out ActorComponent? actor)) { return; } @@ -198,7 +199,7 @@ namespace Content.Server.Medical.Components { var cloningSystem = EntitySystem.Get(); - if (!IoCManager.Resolve().TryGetComponent(_bodyContainer.ContainedEntity.Value, out MindComponent? mindComp) || mindComp.Mind == null) + if (!_entMan.TryGetComponent(_bodyContainer.ContainedEntity.Value, out MindComponent? mindComp) || mindComp.Mind == null) { obj.Session.AttachedEntity.Value.PopupMessageCursor(Loc.GetString("medical-scanner-component-msg-no-soul")); break; diff --git a/Content.Server/Mind/Components/MindComponent.cs b/Content.Server/Mind/Components/MindComponent.cs index e39478324b..386ee396a9 100644 --- a/Content.Server/Mind/Components/MindComponent.cs +++ b/Content.Server/Mind/Components/MindComponent.cs @@ -22,6 +22,8 @@ namespace Content.Server.Mind.Components public class MindComponent : Component, IExamine #pragma warning restore 618 { + [Dependency] private readonly IEntityManager _entMan = default!; + /// public override string Name => "Mind"; @@ -59,7 +61,7 @@ namespace Content.Server.Mind.Components public void InternalEjectMind() { if (!Deleted) - IoCManager.Resolve().EventBus.RaiseLocalEvent(Owner, new MindRemovedMessage()); + _entMan.EventBus.RaiseLocalEvent(Owner, new MindRemovedMessage()); Mind = null; } @@ -71,7 +73,7 @@ namespace Content.Server.Mind.Components public void InternalAssignMind(Mind value) { Mind = value; - IoCManager.Resolve().EventBus.RaiseLocalEvent(Owner, new MindAddedMessage()); + _entMan.EventBus.RaiseLocalEvent(Owner, new MindAddedMessage()); } protected override void Shutdown() @@ -86,7 +88,7 @@ namespace Content.Server.Mind.Components { if (Mind?.VisitingEntity is {Valid: true} visiting) { - if (IoCManager.Resolve().TryGetComponent(visiting, out GhostComponent? ghost)) + if (_entMan.TryGetComponent(visiting, out GhostComponent? ghost)) { EntitySystem.Get().SetCanReturnToBody(ghost, false); } @@ -95,27 +97,27 @@ namespace Content.Server.Mind.Components } else if (GhostOnShutdown) { - var spawnPosition = IoCManager.Resolve().GetComponent(Owner).Coordinates; + var spawnPosition = _entMan.GetComponent(Owner).Coordinates; // Use a regular timer here because the entity has probably been deleted. Timer.Spawn(0, () => { // Async this so that we don't throw if the grid we're on is being deleted. var mapMan = IoCManager.Resolve(); - var gridId = spawnPosition.GetGridId(IoCManager.Resolve()); + var gridId = spawnPosition.GetGridId(_entMan); if (gridId == GridId.Invalid || !mapMan.GridExists(gridId)) { spawnPosition = EntitySystem.Get().GetObserverSpawnPoint(); } - var ghost = IoCManager.Resolve().SpawnEntity("MobObserver", spawnPosition); - var ghostComponent = IoCManager.Resolve().GetComponent(ghost); + var ghost = _entMan.SpawnEntity("MobObserver", spawnPosition); + var ghostComponent = _entMan.GetComponent(ghost); EntitySystem.Get().SetCanReturnToBody(ghostComponent, false); if (Mind != null) { string? val = Mind.CharacterName ?? string.Empty; - IoCManager.Resolve().GetComponent(ghost).EntityName = val; + _entMan.GetComponent(ghost).EntityName = val; Mind.TransferTo(ghost); } }); @@ -131,7 +133,7 @@ namespace Content.Server.Mind.Components } var dead = - IoCManager.Resolve().TryGetComponent(Owner, out var state) && + _entMan.TryGetComponent(Owner, out var state) && state.IsDead(); if (!HasMind) diff --git a/Content.Server/Mining/Components/AsteroidRockComponent.cs b/Content.Server/Mining/Components/AsteroidRockComponent.cs index 25c80109a5..5d03c68b85 100644 --- a/Content.Server/Mining/Components/AsteroidRockComponent.cs +++ b/Content.Server/Mining/Components/AsteroidRockComponent.cs @@ -17,6 +17,7 @@ namespace Content.Server.Mining.Components [RegisterComponent] public class AsteroidRockComponent : Component, IInteractUsing { + [Dependency] private readonly IEntityManager _entMan = default!; [Dependency] private readonly IRobustRandom _random = default!; public override string Name => "AsteroidRock"; @@ -25,7 +26,7 @@ namespace Content.Server.Mining.Components protected override void Initialize() { base.Initialize(); - if (IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearance)) + if (_entMan.TryGetComponent(Owner, out AppearanceComponent? appearance)) { appearance.SetData(AsteroidRockVisuals.State, _random.Pick(SpriteStates)); } @@ -34,12 +35,12 @@ namespace Content.Server.Mining.Components async Task IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs) { var item = eventArgs.Using; - if (!IoCManager.Resolve().TryGetComponent(item, out MeleeWeaponComponent? meleeWeaponComponent)) + if (!_entMan.TryGetComponent(item, out MeleeWeaponComponent? meleeWeaponComponent)) return false; EntitySystem.Get().TryChangeDamage(Owner, meleeWeaponComponent.Damage); - if (!IoCManager.Resolve().TryGetComponent(item, out PickaxeComponent? pickaxeComponent)) + if (!_entMan.TryGetComponent(item, out PickaxeComponent? pickaxeComponent)) return true; SoundSystem.Play(Filter.Pvs(Owner), pickaxeComponent.MiningSound.GetSound(), Owner, AudioParams.Default); diff --git a/Content.Server/Morgue/Components/MorgueEntityStorageComponent.cs b/Content.Server/Morgue/Components/MorgueEntityStorageComponent.cs index 33e5de4c9f..1900b36a47 100644 --- a/Content.Server/Morgue/Components/MorgueEntityStorageComponent.cs +++ b/Content.Server/Morgue/Components/MorgueEntityStorageComponent.cs @@ -33,6 +33,8 @@ namespace Content.Server.Morgue.Components public class MorgueEntityStorageComponent : EntityStorageComponent, IExamine #pragma warning restore 618 { + [Dependency] private readonly IEntityManager _entMan = default!; + public override string Name => "MorgueEntityStorage"; [ViewVariables(VVAccess.ReadWrite)] @@ -65,13 +67,13 @@ namespace Content.Server.Morgue.Components public override Vector2 ContentsDumpPosition() { if (_tray != null) - return IoCManager.Resolve().GetComponent(_tray).WorldPosition; + return _entMan.GetComponent(_tray).WorldPosition; return base.ContentsDumpPosition(); } protected override bool AddToContents(EntityUid entity) { - if (IoCManager.Resolve().HasComponent(entity) && !EntitySystem.Get().IsDown(entity)) + if (_entMan.HasComponent(entity) && !EntitySystem.Get().IsDown(entity)) return false; return base.AddToContents(entity); } @@ -79,7 +81,7 @@ namespace Content.Server.Morgue.Components public override bool CanOpen(EntityUid user, bool silent = false) { if (!Owner.InRangeUnobstructed( - IoCManager.Resolve().GetComponent(Owner).Coordinates.Offset(IoCManager.Resolve().GetComponent(Owner).LocalRotation.GetCardinalDir()), + _entMan.GetComponent(Owner).Coordinates.Offset(_entMan.GetComponent(Owner).LocalRotation.GetCardinalDir()), collisionMask: CollisionGroup.Impassable | CollisionGroup.VaultImpassable )) { @@ -100,7 +102,7 @@ namespace Content.Server.Morgue.Components if (_tray == null) { - _tray = IoCManager.Resolve().SpawnEntity(_trayPrototypeId, IoCManager.Resolve().GetComponent(Owner).Coordinates); + _tray = _entMan.SpawnEntity(_trayPrototypeId, _entMan.GetComponent(Owner).Coordinates); var trayComp = _tray.EnsureComponent(); trayComp.Morgue = Owner; } @@ -109,7 +111,7 @@ namespace Content.Server.Morgue.Components TrayContainer?.Remove(_tray); } - IoCManager.Resolve().GetComponent(_tray).Coordinates = new EntityCoordinates(Owner, 0, -1); + _entMan.GetComponent(_tray).Coordinates = new EntityCoordinates(Owner, 0, -1); base.OpenStorage(); } @@ -122,9 +124,9 @@ namespace Content.Server.Morgue.Components foreach (var entity in Contents.ContainedEntities) { count++; - if (!hasMob && IoCManager.Resolve().HasComponent(entity)) + if (!hasMob && _entMan.HasComponent(entity)) hasMob = true; - if (!hasSoul && IoCManager.Resolve().TryGetComponent(entity, out var actor) && actor.PlayerSession != null) + if (!hasSoul && _entMan.TryGetComponent(entity, out var actor) && actor.PlayerSession != null) hasSoul = true; } Appearance?.SetData(MorgueVisuals.HasContents, count > 0);