diff --git a/Content.Client/DoAfter/DoAfterSystem.cs b/Content.Client/DoAfter/DoAfterSystem.cs index 62828c3bd6..0ae04263fe 100644 --- a/Content.Client/DoAfter/DoAfterSystem.cs +++ b/Content.Client/DoAfter/DoAfterSystem.cs @@ -31,7 +31,7 @@ namespace Content.Client.DoAfter /// public const float ExcessTime = 0.5f; - private EntityUid _attachedEntity; + private EntityUid? _attachedEntity; public override void Initialize() { @@ -51,7 +51,8 @@ namespace Content.Client.DoAfter var currentTime = _gameTiming.CurTime; // Can't see any I guess? - if (_attachedEntity == default || (!EntityManager.EntityExists(_attachedEntity) ? EntityLifeStage.Deleted : EntityManager.GetComponent(_attachedEntity).EntityLifeStage) >= EntityLifeStage.Deleted) + if (_attachedEntity is not {Valid: true} entity || + (!EntityManager.EntityExists(_attachedEntity.Value) ? EntityLifeStage.Deleted : EntityManager.GetComponent(entity).EntityLifeStage) >= EntityLifeStage.Deleted) return; var viewbox = _eyeManager.GetWorldViewport().Enlarged(2.0f); @@ -62,19 +63,19 @@ namespace Content.Client.DoAfter var compPos = EntityManager.GetComponent(comp.Owner).WorldPosition; if (doAfters.Count == 0 || - EntityManager.GetComponent(comp.Owner).MapID != EntityManager.GetComponent(_attachedEntity).MapID || + EntityManager.GetComponent(comp.Owner).MapID != EntityManager.GetComponent(entity).MapID || !viewbox.Contains(compPos)) { comp.Disable(); continue; } - var range = (compPos - EntityManager.GetComponent(_attachedEntity).WorldPosition).Length + + var range = (compPos - EntityManager.GetComponent(entity).WorldPosition).Length + 0.01f; if (comp.Owner != _attachedEntity && !ExamineSystemShared.InRangeUnOccluded( - EntityManager.GetComponent(_attachedEntity).MapPosition, + EntityManager.GetComponent(entity).MapPosition, EntityManager.GetComponent(comp.Owner).MapPosition, range, entity => entity == comp.Owner || entity == _attachedEntity)) { diff --git a/Content.Client/HealthOverlay/HealthOverlaySystem.cs b/Content.Client/HealthOverlay/HealthOverlaySystem.cs index 65aa6a5ae4..d7106ae05e 100644 --- a/Content.Client/HealthOverlay/HealthOverlaySystem.cs +++ b/Content.Client/HealthOverlay/HealthOverlaySystem.cs @@ -15,9 +15,10 @@ namespace Content.Client.HealthOverlay public class HealthOverlaySystem : EntitySystem { [Dependency] private readonly IEyeManager _eyeManager = default!; + [Dependency] private readonly IEntityManager _entities = default!; private readonly Dictionary _guis = new(); - private EntityUid _attachedEntity; + private EntityUid? _attachedEntity; private bool _enabled; public bool Enabled @@ -72,7 +73,7 @@ namespace Content.Client.HealthOverlay return; } - if (_attachedEntity == null || (!IoCManager.Resolve().EntityExists(_attachedEntity) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(_attachedEntity).EntityLifeStage) >= EntityLifeStage.Deleted) + if (_attachedEntity == null || (!_entities.EntityExists(_attachedEntity.Value) ? EntityLifeStage.Deleted : _entities.GetComponent(_attachedEntity.Value).EntityLifeStage) >= EntityLifeStage.Deleted) { return; } @@ -83,8 +84,8 @@ namespace Content.Client.HealthOverlay { var entity = mobState.Owner; - if (IoCManager.Resolve().GetComponent(_attachedEntity).MapID != IoCManager.Resolve().GetComponent(entity).MapID || - !viewBox.Contains(IoCManager.Resolve().GetComponent(entity).WorldPosition)) + if (_entities.GetComponent(_attachedEntity.Value).MapID != _entities.GetComponent(entity).MapID || + !viewBox.Contains(_entities.GetComponent(entity).WorldPosition)) { if (_guis.TryGetValue(entity, out var oldGui)) { diff --git a/Content.Client/Physics/Controllers/MoverController.cs b/Content.Client/Physics/Controllers/MoverController.cs index 1b01341cf9..e9fbeafee1 100644 --- a/Content.Client/Physics/Controllers/MoverController.cs +++ b/Content.Client/Physics/Controllers/MoverController.cs @@ -44,8 +44,7 @@ namespace Content.Client.Physics.Controllers // If we're being pulled then we won't predict anything and will receive server lerps so it looks way smoother. if (EntityManager.TryGetComponent(player, out SharedPullableComponent? pullableComp)) { - var puller = pullableComp.Puller; - if (puller != default && EntityManager.TryGetComponent(puller, out var pullerBody)) + if (pullableComp.Puller is {Valid: true} puller && EntityManager.TryGetComponent(puller, out var pullerBody)) { pullerBody.Predict = false; body.Predict = false; @@ -55,9 +54,7 @@ namespace Content.Client.Physics.Controllers // If we're pulling a mob then make sure that isn't predicted so it doesn't fuck our velocity up. if (EntityManager.TryGetComponent(player, out SharedPullerComponent? pullerComp)) { - var pulling = pullerComp.Pulling; - - if (pulling != default && + if (pullerComp.Pulling is {Valid: true} pulling && EntityManager.HasComponent(pulling) && EntityManager.TryGetComponent(pulling, out PhysicsComponent? pullingBody)) { diff --git a/Content.IntegrationTests/Tests/MindEntityDeletionTest.cs b/Content.IntegrationTests/Tests/MindEntityDeletionTest.cs index 4498f0b34e..6ae1c26fe3 100644 --- a/Content.IntegrationTests/Tests/MindEntityDeletionTest.cs +++ b/Content.IntegrationTests/Tests/MindEntityDeletionTest.cs @@ -91,14 +91,14 @@ namespace Content.IntegrationTests.Tests server.Post(() => { - IoCManager.Resolve().DeleteEntity((EntityUid) playerEnt); + IoCManager.Resolve().DeleteEntity(playerEnt); }); server.RunTicks(1); server.Assert(() => { - Assert.That(IoCManager.Resolve().EntityExists(mind.CurrentEntity), Is.True); + Assert.That(IoCManager.Resolve().EntityExists(mind.CurrentEntity!.Value), Is.True); }); await server.WaitIdleAsync(); @@ -149,7 +149,7 @@ namespace Content.IntegrationTests.Tests server.Assert(() => { - Assert.That(IoCManager.Resolve().EntityExists(mind.CurrentEntity), Is.True); + Assert.That(IoCManager.Resolve().EntityExists(mind.CurrentEntity!.Value), Is.True); Assert.That(mind.CurrentEntity, Is.Not.EqualTo(playerEnt)); }); diff --git a/Content.Server/Chat/Commands/MeCommand.cs b/Content.Server/Chat/Commands/MeCommand.cs index 5884ae9f9d..9041df60b1 100644 --- a/Content.Server/Chat/Commands/MeCommand.cs +++ b/Content.Server/Chat/Commands/MeCommand.cs @@ -49,7 +49,7 @@ namespace Content.Server.Chat.Commands return; } - chat.EntityMe(mindComponent.OwnedEntity, action); + chat.EntityMe(mindComponent.OwnedEntity.Value, action); } } } diff --git a/Content.Server/Chat/Commands/SayCommand.cs b/Content.Server/Chat/Commands/SayCommand.cs index 6d6034532b..8f6b5d33ab 100644 --- a/Content.Server/Chat/Commands/SayCommand.cs +++ b/Content.Server/Chat/Commands/SayCommand.cs @@ -62,11 +62,11 @@ namespace Content.Server.Chat.Commands return; } - var emote = chatSanitizer.TrySanitizeOutSmilies(message, mindComponent.OwnedEntity, out var sanitized, out var emoteStr); + var emote = chatSanitizer.TrySanitizeOutSmilies(message, mindComponent.OwnedEntity.Value, out var sanitized, out var emoteStr); if (sanitized.Length != 0) - chat.EntitySay(mindComponent.OwnedEntity, sanitized); + chat.EntitySay(mindComponent.OwnedEntity.Value, sanitized); if (emote) - chat.EntityMe(mindComponent.OwnedEntity, emoteStr!); + chat.EntityMe(mindComponent.OwnedEntity.Value, emoteStr!); } } diff --git a/Content.Server/Chemistry/EntitySystems/SolutionContainerSystem.cs b/Content.Server/Chemistry/EntitySystems/SolutionContainerSystem.cs index 26fbabdfe9..fde645a7dd 100644 --- a/Content.Server/Chemistry/EntitySystems/SolutionContainerSystem.cs +++ b/Content.Server/Chemistry/EntitySystems/SolutionContainerSystem.cs @@ -288,10 +288,10 @@ namespace Content.Server.Chemistry.EntitySystems UpdateChemicals(uid, solution); } - public FixedPoint2 GetReagentQuantity(EntityUid Owner, string reagentId) + public FixedPoint2 GetReagentQuantity(EntityUid owner, string reagentId) { var reagentQuantity = FixedPoint2.New(0); - if (EntityManager.EntityExists(Owner) + if (EntityManager.EntityExists(owner) && IoCManager.Resolve().TryGetComponent(owner, out SolutionContainerManagerComponent? managerComponent)) { foreach (var solution in managerComponent.Solutions.Values) diff --git a/Content.Server/Chemistry/EntitySystems/TransformableContainerSystem.cs b/Content.Server/Chemistry/EntitySystems/TransformableContainerSystem.cs index 9fd7d8c331..3541867bcc 100644 --- a/Content.Server/Chemistry/EntitySystems/TransformableContainerSystem.cs +++ b/Content.Server/Chemistry/EntitySystems/TransformableContainerSystem.cs @@ -22,10 +22,10 @@ namespace Content.Server.Chemistry.EntitySystems SubscribeLocalEvent(OnSolutionChange); } - private void OnSolutionChange(EntityUid uid, TransformableContainerComponent component, + private void OnSolutionChange(EntityUid owner, TransformableContainerComponent component, SolutionChangedEvent args) { - if (!_solutionsSystem.TryGetFitsInDispenser(uid, out var solution)) + if (!_solutionsSystem.TryGetFitsInDispenser(owner, out var solution)) return; //Transform container into initial state when emptied if (component.CurrentReagent != null && solution.Contents.Count == 0) @@ -50,15 +50,14 @@ namespace Content.Server.Chemistry.EntitySystems var spriteSpec = new SpriteSpecifier.Rsi( new ResourcePath("Objects/Consumable/Drinks/" + proto.SpriteReplacementPath), "icon"); - var Owner - if (IoCManager.Resolve().TryGetComponent(ownerEntity, out SpriteComponent? sprite)) + if (IoCManager.Resolve().TryGetComponent(owner, out SpriteComponent? sprite)) { sprite?.LayerSetSprite(0, spriteSpec); } string val = proto.Name + " glass"; - IoCManager.Resolve().GetComponent(ownerEntity).EntityName = val; - IoCManager.Resolve().GetComponent(ownerEntity).EntityDescription = proto.Description; + IoCManager.Resolve().GetComponent(owner).EntityName = val; + IoCManager.Resolve().GetComponent(owner).EntityDescription = proto.Description; component.CurrentReagent = proto; component.Transformed = true; } diff --git a/Content.Server/Chemistry/ReagentEffects/DoAction.cs b/Content.Server/Chemistry/ReagentEffects/DoAction.cs index 29a6ee575b..9e83cb30f4 100644 --- a/Content.Server/Chemistry/ReagentEffects/DoAction.cs +++ b/Content.Server/Chemistry/ReagentEffects/DoAction.cs @@ -27,7 +27,7 @@ public class DoAction : ReagentEffect if (actions.IsGranted(proto.ActionType)) { var attempt = new ActionAttempt(proto); - attempt.DoInstantAction(args.args.SolutionEntity) + attempt.DoInstantAction(args.SolutionEntity); } } } diff --git a/Content.Server/Climbing/Components/ClimbableComponent.cs b/Content.Server/Climbing/Components/ClimbableComponent.cs index f5d687ef97..4dcb0c58cc 100644 --- a/Content.Server/Climbing/Components/ClimbableComponent.cs +++ b/Content.Server/Climbing/Components/ClimbableComponent.cs @@ -22,6 +22,8 @@ namespace Content.Server.Climbing.Components [ComponentReference(typeof(IClimbable))] public class ClimbableComponent : SharedClimbableComponent { + [Dependency] private readonly IEntityManager _entities = default!; + /// /// The time it takes to climb onto the entity. /// @@ -35,7 +37,7 @@ namespace Content.Server.Climbing.Components if (!Owner.EnsureComponent(out PhysicsComponent _)) { - Logger.Warning($"Entity {IoCManager.Resolve().GetComponent(Owner).EntityName} at {IoCManager.Resolve().GetComponent(Owner).MapPosition} didn't have a {nameof(PhysicsComponent)}"); + Logger.Warning($"Entity {_entities.GetComponent(Owner).EntityName} at {_entities.GetComponent(Owner).MapPosition} didn't have a {nameof(PhysicsComponent)}"); } } @@ -73,8 +75,8 @@ namespace Content.Server.Climbing.Components return false; } - if (!IoCManager.Resolve().HasComponent(user) || - !IoCManager.Resolve().TryGetComponent(user, out SharedBodyComponent? body)) + if (!_entities.HasComponent(user) || + !_entities.TryGetComponent(user, out SharedBodyComponent? body)) { reason = Loc.GetString("comp-climbable-cant-climb"); return false; @@ -113,7 +115,7 @@ namespace Content.Server.Climbing.Components return false; } - if (target == null || !IoCManager.Resolve().HasComponent(dragged)) + if (target == null || !_entities.HasComponent(dragged)) { reason = Loc.GetString("comp-climbable-cant-climb"); return false; @@ -158,14 +160,14 @@ namespace Content.Server.Climbing.Components var result = await EntitySystem.Get().WaitDoAfter(doAfterEventArgs); - if (result != DoAfterStatus.Cancelled && IoCManager.Resolve().TryGetComponent(entityToMove, out PhysicsComponent? body) && body.Fixtures.Count >= 1) + if (result != DoAfterStatus.Cancelled && _entities.TryGetComponent(entityToMove, out PhysicsComponent? body) && body.Fixtures.Count >= 1) { - var entityPos = IoCManager.Resolve().GetComponent(entityToMove).WorldPosition; + var entityPos = _entities.GetComponent(entityToMove).WorldPosition; - var direction = (IoCManager.Resolve().GetComponent(Owner).WorldPosition - entityPos).Normalized; - var endPoint = IoCManager.Resolve().GetComponent(Owner).WorldPosition; + var direction = (_entities.GetComponent(Owner).WorldPosition - entityPos).Normalized; + var endPoint = _entities.GetComponent(Owner).WorldPosition; - var climbMode = IoCManager.Resolve().GetComponent(entityToMove); + var climbMode = _entities.GetComponent(entityToMove); climbMode.IsClimbing = true; if (MathF.Abs(direction.X) < 0.6f) // user climbed mostly vertically so lets make it a clean straight line @@ -190,9 +192,9 @@ namespace Content.Server.Climbing.Components } } - public async void TryClimb(EntityUiduser) + public async void TryClimb(EntityUid user) { - if (!IoCManager.Resolve().TryGetComponent(user, out ClimbingComponent? climbingComponent) || climbingComponent.IsClimbing) + if (!_entities.TryGetComponent(user, out ClimbingComponent? climbingComponent) || climbingComponent.IsClimbing) return; var doAfterEventArgs = new DoAfterEventArgs(user, _climbDelay, default, Owner) @@ -205,24 +207,24 @@ namespace Content.Server.Climbing.Components var result = await EntitySystem.Get().WaitDoAfter(doAfterEventArgs); - if (result != DoAfterStatus.Cancelled && IoCManager.Resolve().TryGetComponent(user, out PhysicsComponent? body) && body.Fixtures.Count >= 1) + if (result != DoAfterStatus.Cancelled && _entities.TryGetComponent(user, out PhysicsComponent? body) && body.Fixtures.Count >= 1) { // TODO: Remove the copy-paste code - var userPos = IoCManager.Resolve().GetComponent(user).WorldPosition; + var userPos = _entities.GetComponent(user).WorldPosition; - var direction = (IoCManager.Resolve().GetComponent(Owner).WorldPosition - userPos).Normalized; - var endPoint = IoCManager.Resolve().GetComponent(Owner).WorldPosition; + var direction = (_entities.GetComponent(Owner).WorldPosition - userPos).Normalized; + var endPoint = _entities.GetComponent(Owner).WorldPosition; - var climbMode = IoCManager.Resolve().GetComponent(user); + var climbMode = _entities.GetComponent(user); climbMode.IsClimbing = true; if (MathF.Abs(direction.X) < 0.6f) // user climbed mostly vertically so lets make it a clean straight line { - endPoint = new Vector2(IoCManager.Resolve().GetComponent(user).WorldPosition.X, endPoint.Y); + endPoint = new Vector2(_entities.GetComponent(user).WorldPosition.X, endPoint.Y); } else if (MathF.Abs(direction.Y) < 0.6f) // user climbed mostly horizontally so lets make it a clean straight line { - endPoint = new Vector2(endPoint.X, IoCManager.Resolve().GetComponent(user).WorldPosition.Y); + endPoint = new Vector2(endPoint.X, _entities.GetComponent(user).WorldPosition.Y); } climbMode.TryMoveTo(userPos, endPoint); diff --git a/Content.Server/Cloning/CloningSystem.cs b/Content.Server/Cloning/CloningSystem.cs index f90dd57d17..28089177c9 100644 --- a/Content.Server/Cloning/CloningSystem.cs +++ b/Content.Server/Cloning/CloningSystem.cs @@ -34,9 +34,9 @@ namespace Content.Server.Cloning internal void TransferMindToClone(Mind.Mind mind) { - if (!ClonesWaitingForMind.TryGetValue(mind, out var entityUid) || - !EntityManager.EntityExists(entityUid) || - !IoCManager.Resolve().TryGetComponent(entity, out MindComponent? mindComp) || + if (!ClonesWaitingForMind.TryGetValue(mind, out var entity) || + !EntityManager.EntityExists(entity) || + !EntityManager.TryGetComponent(entity, out MindComponent? mindComp) || mindComp.Mind != null) return; @@ -48,7 +48,7 @@ namespace Content.Server.Cloning private void HandleActivate(EntityUid uid, CloningPodComponent component, ActivateInWorldEvent args) { if (!component.Powered || - !IoCManager.Resolve().TryGetComponent(args.User, out ActorComponent? actor)) + !EntityManager.TryGetComponent(args.User, out ActorComponent? actor)) { return; } @@ -60,10 +60,10 @@ namespace Content.Server.Cloning { if (component.Parent == EntityUid.Invalid || !EntityManager.EntityExists(component.Parent) || - !IoCManager.Resolve().TryGetComponent(parent, out var cloningPodComponent) || + !EntityManager.TryGetComponent(component.Parent, out var cloningPodComponent) || component.Owner != cloningPodComponent.BodyContainer?.ContainedEntity) { - IoCManager.Resolve().RemoveComponent(component.Owner); + EntityManager.RemoveComponent(component.Owner); return; } diff --git a/Content.Server/Cloning/Components/CloningPodComponent.cs b/Content.Server/Cloning/Components/CloningPodComponent.cs index dbab695dab..bf6b961a39 100644 --- a/Content.Server/Cloning/Components/CloningPodComponent.cs +++ b/Content.Server/Cloning/Components/CloningPodComponent.cs @@ -23,10 +23,12 @@ namespace Content.Server.Cloning.Components public class CloningPodComponent : SharedCloningPodComponent { [Dependency] private readonly IPlayerManager _playerManager = null!; + [Dependency] private readonly IEntityManager _entities = default!; + [Dependency] private readonly EuiManager _euiManager = null!; [ViewVariables] - public bool Powered => !IoCManager.Resolve().TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered; + public bool Powered => !_entities.TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered; [ViewVariables] public BoundUserInterface? UserInterface => @@ -70,7 +72,7 @@ namespace Content.Server.Cloning.Components private void UpdateAppearance() { - if (IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearance)) + if (_entities.TryGetComponent(Owner, out AppearanceComponent? appearance)) { appearance.SetData(CloningPodVisuals.Status, Status); } @@ -105,12 +107,12 @@ namespace Content.Server.Cloning.Components var mind = dna.Mind; - if (cloningSystem.ClonesWaitingForMind.TryGetValue(mind, out var cloneUid)) + if (cloningSystem.ClonesWaitingForMind.TryGetValue(mind, out var clone)) { - if (IoCManager.Resolve().EntityExists(cloneUid) && - IoCManager.Resolve().TryGetComponent(clone, out var cloneState) && + if (_entities.EntityExists(clone) && + _entities.TryGetComponent(clone, out var cloneState) && !cloneState.IsDead() && - IoCManager.Resolve().TryGetComponent(clone, out MindComponent? cloneMindComp) && + _entities.TryGetComponent(clone, out MindComponent? cloneMindComp) && (cloneMindComp.Mind == null || cloneMindComp.Mind == mind)) { obj.Session.AttachedEntity?.PopupMessageCursor(Loc.GetString("cloning-pod-component-msg-already-cloning")); @@ -121,7 +123,7 @@ namespace Content.Server.Cloning.Components } if (mind.OwnedEntity != null && - IoCManager.Resolve().TryGetComponent(mind.OwnedEntity, out var state) && + _entities.TryGetComponent(mind.OwnedEntity.Value, out var state) && !state.IsDead()) { obj.Session.AttachedEntity?.PopupMessageCursor(Loc.GetString("cloning-pod-component-msg-already-alive")); @@ -135,13 +137,13 @@ namespace Content.Server.Cloning.Components return; // If we can't track down the client, we can't offer transfer. That'd be quite bad. } - var mob = IoCManager.Resolve().SpawnEntity("MobHuman", IoCManager.Resolve().GetComponent(Owner).MapPosition); + var mob = _entities.SpawnEntity("MobHuman", _entities.GetComponent(Owner).MapPosition); EntitySystem.Get().UpdateFromProfile(mob, dna.Profile); - IoCManager.Resolve().GetComponent(mob).EntityName = dna.Profile.Name; + _entities.GetComponent(mob).EntityName = dna.Profile.Name; - var cloneMindReturn = IoCManager.Resolve().AddComponent(mob); + var cloneMindReturn = _entities.AddComponent(mob); cloneMindReturn.Mind = mind; cloneMindReturn.Parent = Owner; @@ -167,12 +169,11 @@ namespace Content.Server.Cloning.Components public void Eject() { - var entity = BodyContainer.ContainedEntity; - if (entity == null || CloningProgress < CloningTime) + if (BodyContainer.ContainedEntity is not {Valid: true} entity || CloningProgress < CloningTime) return; - IoCManager.Resolve().RemoveComponent(entity); - BodyContainer.Remove(entity!); + _entities.RemoveComponent(entity); + BodyContainer.Remove(entity); CapturedMind = null; CloningProgress = 0f; UpdateStatus(CloningPodStatus.Idle); diff --git a/Content.Server/Clothing/Components/ClothingComponent.cs b/Content.Server/Clothing/Components/ClothingComponent.cs index 762e7a75f0..101af363e8 100644 --- a/Content.Server/Clothing/Components/ClothingComponent.cs +++ b/Content.Server/Clothing/Components/ClothingComponent.cs @@ -21,6 +21,8 @@ namespace Content.Server.Clothing.Components [NetworkedComponent()] public class ClothingComponent : ItemComponent, IUse { + [Dependency] private readonly IEntityManager _entities = default!; + public override string Name => "Clothing"; [ViewVariables] @@ -60,8 +62,8 @@ namespace Content.Server.Clothing.Components bool IUse.UseEntity(UseEntityEventArgs eventArgs) { if (!_quickEquipEnabled) return false; - if (!IoCManager.Resolve().TryGetComponent(eventArgs.User, out InventoryComponent? inv) - || !IoCManager.Resolve().TryGetComponent(eventArgs.User, out HandsComponent? hands)) return false; + if (!_entities.TryGetComponent(eventArgs.User, out InventoryComponent? inv) + || !_entities.TryGetComponent(eventArgs.User, out HandsComponent? hands)) return false; foreach (var (slot, flag) in SlotMasks) { @@ -79,14 +81,14 @@ namespace Content.Server.Clothing.Components { hands.Drop(item.Owner); inv.Equip(slot, item); - hands.PutInHand(IoCManager.Resolve().GetComponent(Owner)); + hands.PutInHand(_entities.GetComponent(Owner)); } } else { hands.Drop(Owner); if (!TryEquip(inv, slot, eventArgs.User)) - hands.PutInHand(IoCManager.Resolve().GetComponent(Owner)); + hands.PutInHand(_entities.GetComponent(Owner)); } return true; @@ -95,7 +97,7 @@ namespace Content.Server.Clothing.Components return false; } - public bool TryEquip(InventoryComponent inv, Slots slot, EntityUiduser) + public bool TryEquip(InventoryComponent inv, Slots slot, EntityUid user) { if (!inv.Equip(slot, this, true, out var reason)) { diff --git a/Content.Server/Clothing/Components/MagbootsComponent.cs b/Content.Server/Clothing/Components/MagbootsComponent.cs index 8e987943a4..ba73bc992d 100644 --- a/Content.Server/Clothing/Components/MagbootsComponent.cs +++ b/Content.Server/Clothing/Components/MagbootsComponent.cs @@ -47,7 +47,7 @@ namespace Content.Server.Clothing.Components } } - public void Toggle(EntityUiduser) + public void Toggle(EntityUid user) { On = !On; } diff --git a/Content.Server/Containers/EmptyOnMachineDeconstructSystem.cs b/Content.Server/Containers/EmptyOnMachineDeconstructSystem.cs index 91497ceae9..414b12f276 100644 --- a/Content.Server/Containers/EmptyOnMachineDeconstructSystem.cs +++ b/Content.Server/Containers/EmptyOnMachineDeconstructSystem.cs @@ -1,8 +1,8 @@ using Content.Server.Construction.Components; +using Content.Shared.Containers.ItemSlots; using JetBrains.Annotations; using Robust.Shared.Containers; using Robust.Shared.GameObjects; -using Content.Shared.Containers.ItemSlots; using Robust.Shared.IoC; namespace Content.Server.Containers @@ -27,7 +27,7 @@ namespace Content.Server.Containers foreach (var slot in component.Slots.Values) { if (slot.EjectOnDeconstruct && slot.Item != null) - slot.ContainerSlot.Remove(slot.Item); + slot.ContainerSlot.Remove(slot.Item.Value); } } diff --git a/Content.Server/Cuffs/Components/HandcuffComponent.cs b/Content.Server/Cuffs/Components/HandcuffComponent.cs index 89280f37b6..eedbf35fa8 100644 --- a/Content.Server/Cuffs/Components/HandcuffComponent.cs +++ b/Content.Server/Cuffs/Components/HandcuffComponent.cs @@ -24,6 +24,8 @@ namespace Content.Server.Cuffs.Components [ComponentReference(typeof(SharedHandcuffComponent))] public class HandcuffComponent : SharedHandcuffComponent, IAfterInteract { + [Dependency] private readonly IEntityManager _entities = default!; + /// /// The time it takes to apply a to an entity. /// @@ -146,7 +148,9 @@ namespace Content.Server.Cuffs.Components { if (_cuffing) return true; - if (eventArgs.Target == null || !EntitySystem.Get().CanUse(eventArgs.User) || !IoCManager.Resolve().TryGetComponent(eventArgs.Target, out var cuffed)) + if (eventArgs.Target is not {Valid: true} target || + !EntitySystem.Get().CanUse(eventArgs.User) || + !_entities.TryGetComponent(eventArgs.Target.Value, out var cuffed)) { return false; } @@ -163,7 +167,7 @@ namespace Content.Server.Cuffs.Components return true; } - if (!IoCManager.Resolve().TryGetComponent(eventArgs.Target, out var hands)) + if (!_entities.TryGetComponent(target, out var hands)) { eventArgs.User.PopupMessage(Loc.GetString("handcuff-component-target-has-no-hands-error",("targetName", eventArgs.Target))); return true; @@ -182,11 +186,11 @@ namespace Content.Server.Cuffs.Components } eventArgs.User.PopupMessage(Loc.GetString("handcuff-component-start-cuffing-target-message",("targetName", eventArgs.Target))); - eventArgs.User.PopupMessage(eventArgs.Target, Loc.GetString("handcuff-component-start-cuffing-by-other-message",("otherName", eventArgs.User))); + eventArgs.User.PopupMessage(target, Loc.GetString("handcuff-component-start-cuffing-by-other-message",("otherName", eventArgs.User))); SoundSystem.Play(Filter.Pvs(Owner), StartCuffSound.GetSound(), Owner); - TryUpdateCuff(eventArgs.User, eventArgs.Target, cuffed); + TryUpdateCuff(eventArgs.User, target, cuffed); return true; } @@ -197,7 +201,7 @@ namespace Content.Server.Cuffs.Components { var cuffTime = CuffTime; - if (IoCManager.Resolve().HasComponent(target)) + if (_entities.HasComponent(target)) { cuffTime = MathF.Max(0.1f, cuffTime - StunBonus); } diff --git a/Content.Server/Cuffs/CuffableSystem.cs b/Content.Server/Cuffs/CuffableSystem.cs index 204a92428b..f16eb8839f 100644 --- a/Content.Server/Cuffs/CuffableSystem.cs +++ b/Content.Server/Cuffs/CuffableSystem.cs @@ -55,7 +55,7 @@ namespace Content.Server.Cuffs { return; } - if (!EntityManager.EntityExists(args.User) + if (!EntityManager.EntityExists(args.User)) { // Should this even be possible? args.Cancel(); @@ -66,7 +66,7 @@ namespace Content.Server.Cuffs if (args.User == args.Target) { // This UncuffAttemptEvent check should probably be In MobStateSystem, not here? - if (IoCManager.Resolve().TryGetComponent(userEntity, out var state)) + if (IoCManager.Resolve().TryGetComponent(args.User, out var state)) { // Manually check this. if (state.IsIncapacitated()) @@ -83,14 +83,14 @@ namespace Content.Server.Cuffs else { // Check if the user can interact. - if (!_actionBlockerSystem.CanInteract(userEntity)) + if (!_actionBlockerSystem.CanInteract(args.User)) { args.Cancel(); } } if (args.Cancelled) { - _popupSystem.PopupEntity(Loc.GetString("cuffable-component-cannot-interact-message"), args.Target, Filter.Entities(userEntity)); + _popupSystem.PopupEntity(Loc.GetString("cuffable-component-cannot-interact-message"), args.Target, Filter.Entities(args.User)); } } diff --git a/Content.Server/Damage/Commands/HurtCommand.cs b/Content.Server/Damage/Commands/HurtCommand.cs index d9c9c94cb8..77dcbfdd2f 100644 --- a/Content.Server/Damage/Commands/HurtCommand.cs +++ b/Content.Server/Damage/Commands/HurtCommand.cs @@ -43,16 +43,13 @@ namespace Content.Server.Damage.Commands private delegate void Damage(EntityUid entity, bool ignoreResistances); - private bool TryParseEntity(IConsoleShell shell, IPlayerSession? player, string arg, - [NotNullWhen(true)] out EntityUid entity) + private bool TryParseEntity(IConsoleShell shell, IPlayerSession? player, string arg, out EntityUid entity) { - entity = null; + entity = default; if (arg == "_") { - var playerEntity = player?.AttachedEntity; - - if (playerEntity == null) + if (player?.AttachedEntity is not {Valid: true} playerEntity) { shell.WriteLine($"You must have a player entity to use this command without specifying an entity.\n{Help}"); return false; @@ -62,23 +59,20 @@ namespace Content.Server.Damage.Commands return true; } - if (!EntityUid.TryParse(arg, out var entityUid)) + if (!EntityUid.TryParse(arg, out entity)) { shell.WriteLine($"{arg} is not a valid entity uid.\n{Help}"); - return false; } var entityManager = IoCManager.Resolve(); - if (!entityManager.EntityExists(entityUid) + if (!entityManager.EntityExists(entity)) { - shell.WriteLine($"No entity found with uid {entityUid}"); - + shell.WriteLine($"No entity found with uid {entity}"); return false; } - entity = parsedEntity; return true; } diff --git a/Content.Server/DeviceNetwork/Systems/WiredNetworkSystem.cs b/Content.Server/DeviceNetwork/Systems/WiredNetworkSystem.cs index 3e23796215..6c34bafb39 100644 --- a/Content.Server/DeviceNetwork/Systems/WiredNetworkSystem.cs +++ b/Content.Server/DeviceNetwork/Systems/WiredNetworkSystem.cs @@ -1,7 +1,6 @@ using Content.Server.DeviceNetwork.Components; using JetBrains.Annotations; using Robust.Shared.GameObjects; -using Robust.Shared.IoC; namespace Content.Server.DeviceNetwork.Systems { @@ -19,10 +18,7 @@ namespace Content.Server.DeviceNetwork.Systems /// private void OnBeforePacketSent(EntityUid uid, WiredNetworkComponent component, BeforePacketSentEvent args) { - args.Sender - uid - - if (IoCManager.Resolve().GetComponent(receiver).GridID != IoCManager.Resolve().GetComponent(sender).GridID) + if (EntityManager.GetComponent(uid).GridID != EntityManager.GetComponent(args.Sender).GridID) { args.Cancel(); } diff --git a/Content.Server/DeviceNetwork/Systems/WirelessNetworkSystem.cs b/Content.Server/DeviceNetwork/Systems/WirelessNetworkSystem.cs index 398aa51b49..d85bff0736 100644 --- a/Content.Server/DeviceNetwork/Systems/WirelessNetworkSystem.cs +++ b/Content.Server/DeviceNetwork/Systems/WirelessNetworkSystem.cs @@ -1,7 +1,6 @@ using Content.Server.DeviceNetwork.Components; using JetBrains.Annotations; using Robust.Shared.GameObjects; -using Robust.Shared.IoC; namespace Content.Server.DeviceNetwork.Systems { @@ -19,13 +18,11 @@ namespace Content.Server.DeviceNetwork.Systems /// private void OnBeforePacketSent(EntityUid uid, WirelessNetworkComponent component, BeforePacketSentEvent args) { - var sender = args.Sender - - var ownPosition = IoCManager.Resolve().GetComponent(component.Owner).WorldPosition; - var position = IoCManager.Resolve().GetComponent(sender).WorldPosition; + var ownPosition = EntityManager.GetComponent(component.Owner).WorldPosition; + var position = EntityManager.GetComponent(args.Sender).WorldPosition; var distance = (ownPosition - position).Length; - if(IoCManager.Resolve().TryGetComponent(sender, out var sendingComponent) && distance > sendingComponent.Range) + if (EntityManager.TryGetComponent(args.Sender, out var sendingComponent) && distance > sendingComponent.Range) { args.Cancel(); } diff --git a/Content.Server/Disposal/Tube/DisposalTubeSystem.cs b/Content.Server/Disposal/Tube/DisposalTubeSystem.cs index 27e2f06bef..afe16e7e59 100644 --- a/Content.Server/Disposal/Tube/DisposalTubeSystem.cs +++ b/Content.Server/Disposal/Tube/DisposalTubeSystem.cs @@ -68,9 +68,8 @@ namespace Content.Server.Disposal.Tube return; } - var uid component.LastClang = _gameTiming.CurTime; - SoundSystem.Play(Filter.Pvs(entity), component.ClangSound.GetSound(), entity); + SoundSystem.Play(Filter.Pvs(uid), component.ClangSound.GetSound(), uid); } private static void BodyTypeChanged( diff --git a/Content.Server/Disposal/TubeConnectionsCommand.cs b/Content.Server/Disposal/TubeConnectionsCommand.cs index 666ca60349..0a7d023c36 100644 --- a/Content.Server/Disposal/TubeConnectionsCommand.cs +++ b/Content.Server/Disposal/TubeConnectionsCommand.cs @@ -38,13 +38,13 @@ namespace Content.Server.Disposal } var entityManager = IoCManager.Resolve(); - if (!entityManager.EntityExists(id) + if (!entityManager.EntityExists(id)) { shell.WriteLine(Loc.GetString("shell-could-not-find-entity-with-uid",("uid", id))); return; } - if (!IoCManager.Resolve().TryGetComponent(entity, out IDisposalTubeComponent? tube)) + if (!entityManager.TryGetComponent(id, out IDisposalTubeComponent? tube)) { shell.WriteLine(Loc.GetString("shell-entity-with-uid-lacks-component", ("uid", id), @@ -52,7 +52,7 @@ namespace Content.Server.Disposal return; } - tube.PopupDirections(player.AttachedEntity); + tube.PopupDirections(player.AttachedEntity.Value); } } } diff --git a/Content.Server/Disposal/Unit/Components/DisposalUnitComponent.cs b/Content.Server/Disposal/Unit/Components/DisposalUnitComponent.cs index e1bbcf5439..54c63038c8 100644 --- a/Content.Server/Disposal/Unit/Components/DisposalUnitComponent.cs +++ b/Content.Server/Disposal/Unit/Components/DisposalUnitComponent.cs @@ -108,12 +108,12 @@ namespace Content.Server.Disposal.Unit.Components public void OnUiReceiveMessage(ServerBoundUserInterfaceMessage obj) { - if (obj.Session.AttachedEntity == null) + if (obj.Session.AttachedEntity is not {Valid: true} player) { return; } - if (!PlayerCanUse(obj.Session.AttachedEntity)) + if (!PlayerCanUse(player)) { return; } diff --git a/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs b/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs index 21c0692511..ad6b660274 100644 --- a/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs +++ b/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs @@ -116,7 +116,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems private void DoInsertDisposalUnit(DoInsertDisposalUnitEvent ev) { - var toInsert = ev.ToInsert + var toInsert = ev.ToInsert; if (!EntityManager.TryGetComponent(ev.Unit, out DisposalUnitComponent? unit)) { diff --git a/Content.Server/Electrocution/ElectrocutionSystem.cs b/Content.Server/Electrocution/ElectrocutionSystem.cs index 506c4a74a5..a8194623d0 100644 --- a/Content.Server/Electrocution/ElectrocutionSystem.cs +++ b/Content.Server/Electrocution/ElectrocutionSystem.cs @@ -392,17 +392,17 @@ namespace Content.Server.Electrocution visited.Add(entity); if (EntityManager.TryGetComponent(entity, out SharedPullableComponent? pullable) - && pullable.Puller != default - && !visited.Contains(pullable.Puller)) + && pullable.Puller is {Valid: true} pullerId + && !visited.Contains(pullerId)) { - GetChainedElectrocutionTargetsRecurse(pullable.Puller, depth + 1, visited, all); + GetChainedElectrocutionTargetsRecurse(pullerId, depth + 1, visited, all); } if (EntityManager.TryGetComponent(entity, out SharedPullerComponent? puller) - && puller.Pulling != default - && !visited.Contains(puller.Pulling)) + && puller.Pulling is {Valid: true} pullingId + && !visited.Contains(pullingId)) { - GetChainedElectrocutionTargetsRecurse(puller.Pulling, depth + 1, visited, all); + GetChainedElectrocutionTargetsRecurse(pullingId, depth + 1, visited, all); } } diff --git a/Content.Server/EntityList/SpawnEntityListCommand.cs b/Content.Server/EntityList/SpawnEntityListCommand.cs index 5574a6213e..6da3bac523 100644 --- a/Content.Server/EntityList/SpawnEntityListCommand.cs +++ b/Content.Server/EntityList/SpawnEntityListCommand.cs @@ -49,7 +49,7 @@ namespace Content.Server.EntityList foreach (var entity in prototype.Entities(prototypeManager)) { - entityManager.SpawnEntity(entity.ID, IoCManager.Resolve().GetComponent(player.AttachedEntity).Coordinates); + entityManager.SpawnEntity(entity.ID, entityManager.GetComponent(player.AttachedEntity.Value).Coordinates); i++; } diff --git a/Content.Server/Examine/ExamineSystem.cs b/Content.Server/Examine/ExamineSystem.cs index 303009423e..eb91139539 100644 --- a/Content.Server/Examine/ExamineSystem.cs +++ b/Content.Server/Examine/ExamineSystem.cs @@ -32,10 +32,9 @@ namespace Content.Server.Examine { var player = (IPlayerSession) eventArgs.SenderSession; var session = eventArgs.SenderSession; - var playerEnt = session.AttachedEntity; var channel = player.ConnectedClient; - if (playerEnt == default + if (session.AttachedEntity is not {Valid: true} playerEnt || !EntityManager.EntityExists(request.EntityUid) || !CanExamine(playerEnt, request.EntityUid)) { diff --git a/Content.Server/Explosion/EntitySystems/ExplosionSystem.cs b/Content.Server/Explosion/EntitySystems/ExplosionSystem.cs index 102fbcd4e8..fcd52df36d 100644 --- a/Content.Server/Explosion/EntitySystems/ExplosionSystem.cs +++ b/Content.Server/Explosion/EntitySystems/ExplosionSystem.cs @@ -81,12 +81,13 @@ namespace Content.Server.Explosion.EntitySystems foreach (var player in players) { - if (!player.AttachedEntity.Valid || !EntityManager.TryGetComponent(player.AttachedEntity, out CameraRecoilComponent? recoil)) + if (player.AttachedEntity is not {Valid: true} playerEntity || + !EntityManager.TryGetComponent(playerEntity, out CameraRecoilComponent? recoil)) { continue; } - var playerPos = EntityManager.GetComponent(player.AttachedEntity).WorldPosition; + var playerPos = EntityManager.GetComponent(playerEntity).WorldPosition; var delta = epicenter.ToMapPos(EntityManager) - playerPos; //Change if zero. Will result in a NaN later breaking camera shake if not changed diff --git a/Content.Server/Flash/FlashSystem.cs b/Content.Server/Flash/FlashSystem.cs index 1355d2f2ea..20ff2cf67e 100644 --- a/Content.Server/Flash/FlashSystem.cs +++ b/Content.Server/Flash/FlashSystem.cs @@ -48,7 +48,7 @@ namespace Content.Server.Flash } args.Handled = true; - foreach (EntityUide in args.HitEntities) + foreach (var e in args.HitEntities) { Flash(e, args.User, uid, comp.FlashDuration, comp.SlowTo); } @@ -81,7 +81,7 @@ namespace Content.Server.Flash } } - private bool UseFlash(FlashComponent comp, EntityUiduser) + private bool UseFlash(FlashComponent comp, EntityUid user) { if (comp.HasUses) { @@ -135,15 +135,11 @@ namespace Content.Server.Flash if (displayPopup && user != null && target != user) { // TODO Resolving the EntityUidhere bad. - if(EntityManager.EntityExists(user.Value) - && EntityManager.EntityExists(target) - - userEntity.PopupMessage(targetEntity, - Loc.GetString( - "flash-component-user-blinds-you", - ("user", userEntity) - ) - ); + if (EntityManager.EntityExists(user.Value) && EntityManager.EntityExists(target)) + { + user.Value.PopupMessage(target, Loc.GetString("flash-component-user-blinds-you", + ("user", user.Value))); + } } } diff --git a/Content.Server/Fluids/Components/MopComponent.cs b/Content.Server/Fluids/Components/MopComponent.cs index 097c9a83ad..dd4fcc386c 100644 --- a/Content.Server/Fluids/Components/MopComponent.cs +++ b/Content.Server/Fluids/Components/MopComponent.cs @@ -23,6 +23,8 @@ namespace Content.Server.Fluids.Components [RegisterComponent] public class MopComponent : Component, IAfterInteract { + [Dependency] private readonly IEntityManager _entities = default!; + public override string Name => "Mop"; public const string SolutionName = "mop"; @@ -101,7 +103,7 @@ namespace Content.Server.Fluids.Components return false; } - if (eventArgs.Target == null) + if (eventArgs.Target is not {Valid: true} target) { // Drop the liquid on the mop on to the ground solutionSystem.SplitSolution(Owner, contents, FixedPoint2.Min(ResidueAmount, CurrentVolume)) @@ -109,13 +111,13 @@ namespace Content.Server.Fluids.Components return true; } - if (!IoCManager.Resolve().TryGetComponent(eventArgs.Target, out PuddleComponent? puddleComponent) || + if (!_entities.TryGetComponent(target, out PuddleComponent? puddleComponent) || !solutionSystem.TryGetSolution(((IComponent) puddleComponent).Owner, puddleComponent.SolutionName, out var puddleSolution)) return false; // So if the puddle has 20 units we mop in 2 seconds. Don't just store CurrentVolume given it can change so need to re-calc it anyway. var doAfterArgs = new DoAfterEventArgs(eventArgs.User, _mopSpeed * puddleSolution.CurrentVolume.Float() / 10.0f, - target: eventArgs.Target) + target: target) { BreakOnUserMove = true, BreakOnStun = true, @@ -152,7 +154,7 @@ namespace Content.Server.Fluids.Components else { // remove solution from the puddle - solutionSystem.SplitSolution(eventArgs.Target, puddleSolution, transferAmount); + solutionSystem.SplitSolution(target, puddleSolution, transferAmount); // and from the mop solutionSystem.SplitSolution(Owner, contents, transferAmount); diff --git a/Content.Server/GameTicking/Commands/MappingCommand.cs b/Content.Server/GameTicking/Commands/MappingCommand.cs index 457b1ae9e0..0edea9a995 100644 --- a/Content.Server/GameTicking/Commands/MappingCommand.cs +++ b/Content.Server/GameTicking/Commands/MappingCommand.cs @@ -18,6 +18,8 @@ namespace Content.Server.GameTicking.Commands [AdminCommand(AdminFlags.Server | AdminFlags.Mapping)] class MappingCommand : IConsoleCommand { + [Dependency] private readonly IEntityManager _entities = default!; + public string Command => "mapping"; public string Description => "Creates and teleports you to a new uninitialized map for mapping."; public string Help => $"Usage: {Command} / {Command} "; @@ -76,9 +78,11 @@ namespace Content.Server.GameTicking.Commands shell.ExecuteCommand($"addmap {mapId} false"); shell.ExecuteCommand($"loadbp {mapId} \"{CommandParsing.Escape(mapName)}\" true"); - EntityUid tempQualifier = player.AttachedEntity; - if ((tempQualifier != null ? IoCManager.Resolve().GetComponent(tempQualifier).EntityPrototype : null)?.ID != "AdminObserver") + if (player.AttachedEntity is {Valid: true} playerEntity && + _entities.GetComponent(playerEntity).EntityPrototype?.ID != "AdminObserver") + { shell.ExecuteCommand("aghost"); + } shell.ExecuteCommand($"tp 0 0 {mapId}"); shell.RemoteExecuteCommand("showmarkers"); diff --git a/Content.Server/GameTicking/GameTicker.RoundFlow.cs b/Content.Server/GameTicking/GameTicker.RoundFlow.cs index 34ff901b66..5fe4938ecb 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).EntityName; + playerIcName = IoCManager.Resolve().GetComponent(mind.CurrentEntity.Value).EntityName; var playerEndRoundInfo = new RoundEndMessageEvent.RoundEndPlayerInfo() { diff --git a/Content.Server/GameTicking/Presets/GamePreset.cs b/Content.Server/GameTicking/Presets/GamePreset.cs index 4f4904432a..55eb5b0b26 100644 --- a/Content.Server/GameTicking/Presets/GamePreset.cs +++ b/Content.Server/GameTicking/Presets/GamePreset.cs @@ -19,6 +19,8 @@ namespace Content.Server.GameTicking.Presets /// public abstract class GamePreset { + [Dependency] private readonly IEntityManager _entities = default!; + public abstract bool Start(IReadOnlyList readyPlayers, bool force = false); public virtual string ModeTitle => "Sandbox"; public virtual string Description => "Secret!"; @@ -39,7 +41,7 @@ namespace Content.Server.GameTicking.Presets { var playerEntity = mind.OwnedEntity; - if (playerEntity != default && IoCManager.Resolve().HasComponent(playerEntity)) + if (playerEntity != default && IoCManager.Resolve().HasComponent(playerEntity.Value)) return false; if (mind.VisitingEntity != default) @@ -47,7 +49,9 @@ namespace Content.Server.GameTicking.Presets mind.UnVisit(); } - var position = (playerEntity != null ? IoCManager.Resolve().GetComponent(playerEntity) : null).Coordinates ?? EntitySystem.Get().GetObserverSpawnPoint(); + var position = playerEntity is {Valid: true} + ? _entities.GetComponent(playerEntity.Value).Coordinates + : EntitySystem.Get().GetObserverSpawnPoint(); // Ok, so, this is the master place for the logic for if ghosting is "too cheaty" to allow returning. // There's no reason at this time to move it to any other place, especially given that the 'side effects required' situations would also have to be moved. // + If CharacterDeadPhysically applies, we're physically dead. Therefore, ghosting OK, and we can return (this is critical for gibbing) @@ -58,7 +62,7 @@ namespace Content.Server.GameTicking.Presets // (If the mob survives, that's a bug. Ghosting is kept regardless.) var canReturn = canReturnGlobal && mind.CharacterDeadPhysically; - if (playerEntity != null && canReturnGlobal && IoCManager.Resolve().TryGetComponent(playerEntity, out MobStateComponent? mobState)) + if (playerEntity != default && canReturnGlobal && IoCManager.Resolve().TryGetComponent(playerEntity.Value, out MobStateComponent? mobState)) { if (mobState.IsCritical()) { @@ -67,7 +71,7 @@ namespace Content.Server.GameTicking.Presets //todo: what if they dont breathe lol //cry deeply DamageSpecifier damage = new(IoCManager.Resolve().Index("Asphyxiation"), 200); - EntitySystem.Get().TryChangeDamage(playerEntity, damage, true); + EntitySystem.Get().TryChangeDamage(playerEntity.Value, damage, true); } } diff --git a/Content.Server/GameTicking/Presets/PresetSuspicion.cs b/Content.Server/GameTicking/Presets/PresetSuspicion.cs index 21cce723bd..0963bb3ed4 100644 --- a/Content.Server/GameTicking/Presets/PresetSuspicion.cs +++ b/Content.Server/GameTicking/Presets/PresetSuspicion.cs @@ -1,16 +1,12 @@ using System.Collections.Generic; using Content.Server.Chat.Managers; using Content.Server.GameTicking.Rules; -using Content.Server.Inventory.Components; -using Content.Server.Items; using Content.Server.Players; using Content.Server.Suspicion; using Content.Server.Suspicion.Roles; using Content.Server.Traitor.Uplink; using Content.Server.Traitor.Uplink.Account; -using Content.Server.Traitor.Uplink.Components; using Content.Shared.CCVar; -using Content.Shared.Inventory; using Content.Shared.Roles; using Content.Shared.Traitor.Uplink; using Robust.Server.Player; @@ -121,7 +117,7 @@ namespace Content.Server.GameTicking.Presets // try to place uplink if (!EntityManager.EntitySysManager.GetEntitySystem() - .AddUplink(mind.OwnedEntity, uplinkAccount)) + .AddUplink(mind.OwnedEntity!.Value, uplinkAccount)) continue; } diff --git a/Content.Server/GameTicking/Presets/PresetTraitor.cs b/Content.Server/GameTicking/Presets/PresetTraitor.cs index 135419da4a..fb85f34af7 100644 --- a/Content.Server/GameTicking/Presets/PresetTraitor.cs +++ b/Content.Server/GameTicking/Presets/PresetTraitor.cs @@ -3,19 +3,14 @@ using System.Collections.Generic; using System.Linq; using Content.Server.Chat.Managers; using Content.Server.GameTicking.Rules; -using Content.Server.Inventory.Components; -using Content.Server.Items; using Content.Server.Objectives.Interfaces; -using Content.Server.PDA; using Content.Server.Players; using Content.Server.Roles; using Content.Server.Traitor; using Content.Server.Traitor.Uplink; using Content.Server.Traitor.Uplink.Account; -using Content.Server.Traitor.Uplink.Components; using Content.Shared.CCVar; using Content.Shared.Dataset; -using Content.Shared.Inventory; using Content.Shared.Traitor.Uplink; using Robust.Server.Player; using Robust.Shared.Configuration; @@ -131,7 +126,7 @@ namespace Content.Server.GameTicking.Presets accounts.AddNewAccount(uplinkAccount); if (!EntityManager.EntitySysManager.GetEntitySystem() - .AddUplink(mind.OwnedEntity, uplinkAccount)) + .AddUplink(mind.OwnedEntity!.Value, uplinkAccount)) continue; var traitorRole = new TraitorRole(mind); diff --git a/Content.Server/GameTicking/Presets/PresetTraitorDeathMatch.cs b/Content.Server/GameTicking/Presets/PresetTraitorDeathMatch.cs index a183fb4ad2..22df8b5b09 100644 --- a/Content.Server/GameTicking/Presets/PresetTraitorDeathMatch.cs +++ b/Content.Server/GameTicking/Presets/PresetTraitorDeathMatch.cs @@ -80,50 +80,50 @@ namespace Content.Server.GameTicking.Presets // Delete anything that may contain "dangerous" role-specific items. // (This includes the PDA, as everybody gets the captain PDA in this mode for true-all-access reasons.) - if (mind.OwnedEntity != null && IoCManager.Resolve().TryGetComponent(mind.OwnedEntity, out InventoryComponent? inventory)) + if (mind.OwnedEntity is {Valid: true} owned && _entityManager.TryGetComponent(owned, out InventoryComponent? inventory)) { var victimSlots = new[] {EquipmentSlotDefines.Slots.IDCARD, EquipmentSlotDefines.Slots.BELT, EquipmentSlotDefines.Slots.BACKPACK}; foreach (var slot in victimSlots) { if (inventory.TryGetSlotItem(slot, out ItemComponent? vItem)) - IoCManager.Resolve().DeleteEntity(vItem.Owner); + _entityManager.DeleteEntity(vItem.Owner); } // Replace their items: // pda - var newPDA = _entityManager.SpawnEntity(PDAPrototypeName, IoCManager.Resolve().GetComponent(mind.OwnedEntity).Coordinates); - inventory.Equip(EquipmentSlotDefines.Slots.IDCARD, IoCManager.Resolve().GetComponent(newPDA)); + var newPDA = _entityManager.SpawnEntity(PDAPrototypeName, _entityManager.GetComponent(owned).Coordinates); + inventory.Equip(EquipmentSlotDefines.Slots.IDCARD, _entityManager.GetComponent(newPDA)); // belt - var newTmp = _entityManager.SpawnEntity(BeltPrototypeName, IoCManager.Resolve().GetComponent(mind.OwnedEntity).Coordinates); - inventory.Equip(EquipmentSlotDefines.Slots.BELT, IoCManager.Resolve().GetComponent(newTmp)); + var newTmp = _entityManager.SpawnEntity(BeltPrototypeName, _entityManager.GetComponent(owned).Coordinates); + inventory.Equip(EquipmentSlotDefines.Slots.BELT, _entityManager.GetComponent(newTmp)); // backpack - newTmp = _entityManager.SpawnEntity(BackpackPrototypeName, IoCManager.Resolve().GetComponent(mind.OwnedEntity).Coordinates); - inventory.Equip(EquipmentSlotDefines.Slots.BACKPACK, IoCManager.Resolve().GetComponent(newTmp)); + newTmp = _entityManager.SpawnEntity(BackpackPrototypeName, _entityManager.GetComponent(owned).Coordinates); + inventory.Equip(EquipmentSlotDefines.Slots.BACKPACK, _entityManager.GetComponent(newTmp)); // Like normal traitors, they need access to a traitor account. - var uplinkAccount = new UplinkAccount(startingBalance, mind.OwnedEntity); + var uplinkAccount = new UplinkAccount(startingBalance, owned); var accounts = _entityManager.EntitySysManager.GetEntitySystem(); accounts.AddNewAccount(uplinkAccount); _entityManager.EntitySysManager.GetEntitySystem() - .AddUplink(mind.OwnedEntity, uplinkAccount, newPDA); + .AddUplink(owned, uplinkAccount, newPDA); - _allOriginalNames[uplinkAccount] = IoCManager.Resolve().GetComponent(mind.OwnedEntity).EntityName; + _allOriginalNames[uplinkAccount] = _entityManager.GetComponent(owned).EntityName; // The PDA needs to be marked with the correct owner. - var pda = IoCManager.Resolve().GetComponent(newPDA); + var pda = _entityManager.GetComponent(newPDA); _entityManager.EntitySysManager.GetEntitySystem() - .SetOwner(pda, IoCManager.Resolve().GetComponent(mind.OwnedEntity).EntityName); - IoCManager.Resolve().AddComponent(newPDA).UserId = mind.UserId; + .SetOwner(pda, _entityManager.GetComponent(owned).EntityName); + _entityManager.AddComponent(newPDA).UserId = mind.UserId; } // Finally, it would be preferrable if they spawned as far away from other players as reasonably possible. - if (mind.OwnedEntity != null && FindAnyIsolatedSpawnLocation(mind, out var bestTarget)) + if (mind.OwnedEntity != default && FindAnyIsolatedSpawnLocation(mind, out var bestTarget)) { - IoCManager.Resolve().GetComponent(mind.OwnedEntity).Coordinates = bestTarget; + _entityManager.GetComponent(mind.OwnedEntity.Value).Coordinates = bestTarget; } else { @@ -151,7 +151,7 @@ namespace Content.Server.GameTicking.Presets var avoidMeEntity = avoidMeMind.OwnedEntity; if (avoidMeEntity == null) continue; - if (IoCManager.Resolve().TryGetComponent(avoidMeEntity, out MobStateComponent? mobState)) + if (_entityManager.TryGetComponent(avoidMeEntity.Value, out MobStateComponent? mobState)) { // Does have mob state component; if critical or dead, they don't really matter for spawn checks if (mobState.IsCritical() || mobState.IsDead()) @@ -162,7 +162,7 @@ namespace Content.Server.GameTicking.Presets // Doesn't have mob state component. Assume something interesting is going on and don't count this as someone to avoid. continue; } - existingPlayerPoints.Add(IoCManager.Resolve().GetComponent(avoidMeEntity).Coordinates); + existingPlayerPoints.Add(_entityManager.GetComponent(avoidMeEntity.Value).Coordinates); } // Iterate over each possible spawn point, comparing to the existing player points. @@ -176,18 +176,18 @@ namespace Content.Server.GameTicking.Presets var atmosphereSystem = EntitySystem.Get(); foreach (var entity in ents) { - if (!atmosphereSystem.IsTileMixtureProbablySafe(IoCManager.Resolve().GetComponent(entity).Coordinates)) + if (!atmosphereSystem.IsTileMixtureProbablySafe(_entityManager.GetComponent(entity).Coordinates)) continue; var distanceFromNearest = float.PositiveInfinity; foreach (var existing in existingPlayerPoints) { - if (IoCManager.Resolve().GetComponent(entity).Coordinates.TryDistance(_entityManager, existing, out var dist)) + if (_entityManager.GetComponent(entity).Coordinates.TryDistance(_entityManager, existing, out var dist)) distanceFromNearest = Math.Min(distanceFromNearest, dist); } if (bestTargetDistanceFromNearest < distanceFromNearest) { - bestTarget = IoCManager.Resolve().GetComponent(entity).Coordinates; + bestTarget = _entityManager.GetComponent(entity).Coordinates; bestTargetDistanceFromNearest = distanceFromNearest; foundATarget = true; } @@ -197,8 +197,7 @@ namespace Content.Server.GameTicking.Presets public override bool OnGhostAttempt(Mind.Mind mind, bool canReturnGlobal) { - var entity = mind.OwnedEntity; - if ((entity != null) && IoCManager.Resolve().TryGetComponent(entity, out MobStateComponent? mobState)) + if (mind.OwnedEntity is {Valid: true} entity && _entityManager.TryGetComponent(entity, out MobStateComponent? mobState)) { if (mobState.IsCritical()) { @@ -208,7 +207,7 @@ namespace Content.Server.GameTicking.Presets } else if (!mobState.IsDead()) { - if (IoCManager.Resolve().HasComponent(entity)) + if (_entityManager.HasComponent(entity)) { return false; } diff --git a/Content.Server/GameTicking/Rules/RuleDeathMatch.cs b/Content.Server/GameTicking/Rules/RuleDeathMatch.cs index 699404bfee..0a51de949c 100644 --- a/Content.Server/GameTicking/Rules/RuleDeathMatch.cs +++ b/Content.Server/GameTicking/Rules/RuleDeathMatch.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Threading; using Content.Server.Chat.Managers; using Content.Shared.CCVar; @@ -62,9 +60,8 @@ namespace Content.Server.GameTicking.Rules IPlayerSession? winner = null; foreach (var playerSession in _playerManager.ServerSessions) { - var playerEntity = playerSession.AttachedEntity; - if (playerEntity == null - || !IoCManager.Resolve().TryGetComponent(playerEntity, out MobStateComponent? state)) + if (playerSession.AttachedEntity is not {Valid: true} playerEntity + || !_entityManager.TryGetComponent(playerEntity, out MobStateComponent? state)) { continue; } diff --git a/Content.Server/GameTicking/Rules/RuleSuspicion.cs b/Content.Server/GameTicking/Rules/RuleSuspicion.cs index d3c41fb117..cb6f34735a 100644 --- a/Content.Server/GameTicking/Rules/RuleSuspicion.cs +++ b/Content.Server/GameTicking/Rules/RuleSuspicion.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Threading; using Content.Server.Chat.Managers; using Content.Server.Doors; @@ -35,6 +33,7 @@ namespace Content.Server.GameTicking.Rules [Dependency] private readonly IChatManager _chatManager = default!; [Dependency] private readonly IConfigurationManager _cfg = default!; [Dependency] private readonly IGameTiming _timing = default!; + [Dependency] private readonly IEntityManager _entities = default!; [DataField("addedSound")] private SoundSpecifier _addedSound = new SoundPathSpecifier("/Audio/Misc/tatoralert.ogg"); @@ -90,9 +89,9 @@ namespace Content.Server.GameTicking.Rules foreach (var playerSession in _playerManager.ServerSessions) { - if (playerSession.AttachedEntity == null - || !IoCManager.Resolve().TryGetComponent(playerSession.AttachedEntity, out MobStateComponent? mobState) - || !IoCManager.Resolve().HasComponent(playerSession.AttachedEntity)) + if (playerSession.AttachedEntity is not {Valid: true} playerEntity + || !_entities.TryGetComponent(playerEntity, out MobStateComponent? mobState) + || !_entities.HasComponent(playerEntity)) { continue; } diff --git a/Content.Server/Ghost/Components/GhostRadioComponent.cs b/Content.Server/Ghost/Components/GhostRadioComponent.cs index 1f8d25f85d..468e33b8ea 100644 --- a/Content.Server/Ghost/Components/GhostRadioComponent.cs +++ b/Content.Server/Ghost/Components/GhostRadioComponent.cs @@ -23,7 +23,7 @@ namespace Content.Server.Ghost.Components public IReadOnlyList Channels => _channels; - public void Receive(string message, int channel, EntityUidspeaker) + public void Receive(string message, int channel, EntityUid speaker) { if (!IoCManager.Resolve().TryGetComponent(Owner, out ActorComponent? actor)) return; @@ -39,6 +39,6 @@ namespace Content.Server.Ghost.Components _netManager.ServerSendMessage(msg, playerChannel); } - public void Broadcast(string message, EntityUidspeaker) { } + public void Broadcast(string message, EntityUid speaker) { } } } diff --git a/Content.Server/Ghost/GhostSystem.cs b/Content.Server/Ghost/GhostSystem.cs index ad3d563209..758fb7e864 100644 --- a/Content.Server/Ghost/GhostSystem.cs +++ b/Content.Server/Ghost/GhostSystem.cs @@ -64,7 +64,7 @@ namespace Content.Server.Ghost visibility.Layer |= (int) VisibilityFlags.Ghost; visibility.Layer &= ~(int) VisibilityFlags.Normal; - if (IoCManager.Resolve().TryGetComponent(component.Owner, out EyeComponent? eye)) + if (EntityManager.TryGetComponent(component.Owner, out EyeComponent? eye)) { eye.VisibilityMask |= (uint) VisibilityFlags.Ghost; } @@ -75,17 +75,17 @@ namespace Content.Server.Ghost private void OnGhostShutdown(EntityUid uid, GhostComponent component, ComponentShutdown args) { // Perf: If the entity is deleting itself, no reason to change these back. - if ((!IoCManager.Resolve().EntityExists(component.Owner) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(component.Owner).EntityLifeStage) < EntityLifeStage.Terminating) + if ((!EntityManager.EntityExists(component.Owner) ? EntityLifeStage.Deleted : EntityManager.GetComponent(component.Owner).EntityLifeStage) < EntityLifeStage.Terminating) { // Entity can't be seen by ghosts anymore. - if (IoCManager.Resolve().TryGetComponent(component.Owner, out VisibilityComponent? visibility)) + if (EntityManager.TryGetComponent(component.Owner, out VisibilityComponent? visibility)) { visibility.Layer &= ~(int) VisibilityFlags.Ghost; visibility.Layer |= (int) VisibilityFlags.Normal; } // Entity can't see ghosts anymore. - if (IoCManager.Resolve().TryGetComponent(component.Owner, out EyeComponent? eye)) + if (EntityManager.TryGetComponent(component.Owner, out EyeComponent? eye)) { eye.VisibilityMask &= ~(uint) VisibilityFlags.Ghost; } @@ -114,10 +114,8 @@ namespace Content.Server.Ghost private void OnGhostWarpsRequest(GhostWarpsRequestEvent msg, EntitySessionEventArgs args) { - var entity = args.SenderSession.AttachedEntity; - - if (entity == null || - !IoCManager.Resolve().HasComponent(entity)) + if (args.SenderSession.AttachedEntity is not {Valid: true} entity || + !EntityManager.HasComponent(entity)) { Logger.Warning($"User {args.SenderSession.Name} sent a {nameof(GhostWarpsRequestEvent)} without being a ghost."); return; @@ -129,12 +127,10 @@ namespace Content.Server.Ghost private void OnGhostReturnToBodyRequest(GhostReturnToBodyRequest msg, EntitySessionEventArgs args) { - var entity = args.SenderSession.AttachedEntity; - - if (entity == null || - !IoCManager.Resolve().TryGetComponent(entity, out GhostComponent? ghost) || + if (args.SenderSession.AttachedEntity is not {Valid: true} attached || + !EntityManager.TryGetComponent(attached, out GhostComponent? ghost) || !ghost.CanReturnToBody || - !IoCManager.Resolve().TryGetComponent(entity, out ActorComponent? actor)) + !EntityManager.TryGetComponent(attached, out ActorComponent? actor)) { Logger.Warning($"User {args.SenderSession.Name} sent an invalid {nameof(GhostReturnToBodyRequest)}"); return; @@ -145,8 +141,8 @@ namespace Content.Server.Ghost private void OnGhostWarpToLocationRequest(GhostWarpToLocationRequestEvent msg, EntitySessionEventArgs args) { - if (args.SenderSession.AttachedEntity == null || - !IoCManager.Resolve().TryGetComponent(args.SenderSession.AttachedEntity, out GhostComponent? ghost)) + if (args.SenderSession.AttachedEntity is not {Valid: true} attached || + !EntityManager.TryGetComponent(attached, out GhostComponent? ghost)) { Logger.Warning($"User {args.SenderSession.Name} tried to warp to {msg.Name} without being a ghost."); return; @@ -154,7 +150,7 @@ namespace Content.Server.Ghost if (FindLocation(msg.Name) is { } warp) { - IoCManager.Resolve().GetComponent(ghost.Owner).Coordinates = IoCManager.Resolve().GetComponent(warp.Owner).Coordinates; + EntityManager.GetComponent(ghost.Owner).Coordinates = EntityManager.GetComponent(warp.Owner).Coordinates; } Logger.Warning($"User {args.SenderSession.Name} tried to warp to an invalid warp: {msg.Name}"); @@ -162,32 +158,32 @@ namespace Content.Server.Ghost private void OnGhostWarpToTargetRequest(GhostWarpToTargetRequestEvent msg, EntitySessionEventArgs args) { - if (args.SenderSession.AttachedEntity == null || - !IoCManager.Resolve().TryGetComponent(args.SenderSession.AttachedEntity, out GhostComponent? ghost)) + if (args.SenderSession.AttachedEntity is not {Valid: true} attached || + !EntityManager.TryGetComponent(attached, out GhostComponent? ghost)) { Logger.Warning($"User {args.SenderSession.Name} tried to warp to {msg.Target} without being a ghost."); return; } - if (!EntityManager.EntityExists(msg.Target) + if (!EntityManager.EntityExists(msg.Target)) { Logger.Warning($"User {args.SenderSession.Name} tried to warp to an invalid entity id: {msg.Target}"); return; } - IoCManager.Resolve().GetComponent(ghost.Owner).Coordinates = IoCManager.Resolve().GetComponent(entity).Coordinates; + EntityManager.GetComponent(ghost.Owner).Coordinates = EntityManager.GetComponent(msg.Target).Coordinates; } private void DeleteEntity(EntityUid uid) { if (!EntityManager.EntityExists(uid) - || (!IoCManager.Resolve().EntityExists(entity) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(entity).EntityLifeStage) >= EntityLifeStage.Deleted - || (!IoCManager.Resolve().EntityExists(entity) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(entity).EntityLifeStage) == EntityLifeStage.Terminating) + || (!EntityManager.EntityExists(uid) ? EntityLifeStage.Deleted : EntityManager.GetComponent(uid).EntityLifeStage) >= EntityLifeStage.Deleted + || (!EntityManager.EntityExists(uid) ? EntityLifeStage.Deleted : EntityManager.GetComponent(uid).EntityLifeStage) == EntityLifeStage.Terminating) return; - if (IoCManager.Resolve().TryGetComponent(entity, out var mind)) + if (EntityManager.TryGetComponent(uid, out var mind)) mind.GhostOnShutdown = false; - IoCManager.Resolve().DeleteEntity((EntityUid) entity); + EntityManager.DeleteEntity(uid); } private IEnumerable GetLocationNames() @@ -220,9 +216,9 @@ namespace Content.Server.Ghost foreach (var player in _playerManager.Sessions) { - if (player.AttachedEntity != null) + if (player.AttachedEntity is {Valid: true} attached) { - players.Add(player.AttachedEntity, IoCManager.Resolve().GetComponent(player.AttachedEntity).EntityName); + players.Add(attached, EntityManager.GetComponent(attached).EntityName); } } diff --git a/Content.Server/Ghost/Roles/GhostRoleSystem.cs b/Content.Server/Ghost/Roles/GhostRoleSystem.cs index 8c068d23a5..36c04f748c 100644 --- a/Content.Server/Ghost/Roles/GhostRoleSystem.cs +++ b/Content.Server/Ghost/Roles/GhostRoleSystem.cs @@ -6,17 +6,17 @@ using Content.Server.Ghost.Roles.Components; using Content.Server.Ghost.Roles.UI; using Content.Server.Players; using Content.Shared.GameTicking; -using Content.Shared.Ghost.Roles; using Content.Shared.Ghost; +using Content.Shared.Ghost.Roles; using JetBrains.Annotations; using Robust.Server.GameObjects; using Robust.Server.Player; using Robust.Shared.Console; +using Robust.Shared.Enums; using Robust.Shared.GameObjects; using Robust.Shared.IoC; -using Robust.Shared.ViewVariables; using Robust.Shared.Utility; -using Robust.Shared.Enums; +using Robust.Shared.ViewVariables; namespace Content.Server.Ghost.Roles { @@ -59,7 +59,8 @@ namespace Content.Server.Ghost.Roles public void OpenEui(IPlayerSession session) { - if (session.AttachedEntity == null || !IoCManager.Resolve().HasComponent(session.AttachedEntity)) + if (session.AttachedEntity is not {Valid: true} attached || + !EntityManager.HasComponent(attached)) return; if(_openUis.ContainsKey(session)) @@ -194,7 +195,7 @@ namespace Content.Server.Ghost.Roles { // Close the session of any player that has a ghost roles window open and isn't a ghost anymore. if (!_openUis.ContainsKey(message.Player)) return; - if (IoCManager.Resolve().HasComponent(message.Entity)) return; + if (EntityManager.HasComponent(message.Entity)) return; CloseEui(message.Player); } diff --git a/Content.Server/Gravity/EntitySystems/GravityShakeSystem.cs b/Content.Server/Gravity/EntitySystems/GravityShakeSystem.cs index f44433d6bd..04e2902968 100644 --- a/Content.Server/Gravity/EntitySystems/GravityShakeSystem.cs +++ b/Content.Server/Gravity/EntitySystems/GravityShakeSystem.cs @@ -79,9 +79,9 @@ namespace Content.Server.Gravity.EntitySystems { foreach (var player in _playerManager.Sessions) { - if (player.AttachedEntity == null - || IoCManager.Resolve().GetComponent(player.AttachedEntity).GridID != gridId - || !IoCManager.Resolve().TryGetComponent(player.AttachedEntity, out CameraRecoilComponent? recoil)) + if (player.AttachedEntity is not {Valid: true} attached + || EntityManager.GetComponent(attached).GridID != gridId + || !EntityManager.TryGetComponent(attached, out CameraRecoilComponent? recoil)) { continue; } diff --git a/Content.Server/Gravity/EntitySystems/WeightlessSystem.cs b/Content.Server/Gravity/EntitySystems/WeightlessSystem.cs index d652761f43..6708340cbf 100644 --- a/Content.Server/Gravity/EntitySystems/WeightlessSystem.cs +++ b/Content.Server/Gravity/EntitySystems/WeightlessSystem.cs @@ -34,15 +34,14 @@ namespace Content.Server.Gravity.EntitySystems public void AddAlert(ServerAlertsComponent status) { - var gridId = IoCManager.Resolve().GetComponent(status.Owner).GridID; + var gridId = EntityManager.GetComponent(status.Owner).GridID; var alerts = _alerts.GetOrNew(gridId); alerts.Add(status); - if (_mapManager.TryGetGrid(IoCManager.Resolve().GetComponent(status.Owner).GridID, out var grid)) + if (_mapManager.TryGetGrid(EntityManager.GetComponent(status.Owner).GridID, out var grid)) { - var gridgrid.GridEntityId - if (IoCManager.Resolve().GetComponent(gridEntity).Enabled) + if (EntityManager.GetComponent(grid.GridEntityId).Enabled) { RemoveWeightless(status); } @@ -55,7 +54,7 @@ namespace Content.Server.Gravity.EntitySystems public void RemoveAlert(ServerAlertsComponent status) { - var grid = IoCManager.Resolve().GetComponent(status.Owner).GridID; + var grid = EntityManager.GetComponent(status.Owner).GridID; if (!_alerts.TryGetValue(grid, out var statuses)) { return; @@ -99,13 +98,13 @@ namespace Content.Server.Gravity.EntitySystems private void EntParentChanged(ref EntParentChangedMessage ev) { - if (!IoCManager.Resolve().TryGetComponent(ev.Entity, out ServerAlertsComponent? status)) + if (!EntityManager.TryGetComponent(ev.Entity, out ServerAlertsComponent? status)) { return; } - if (ev.OldParent != null && - IoCManager.Resolve().TryGetComponent(ev.OldParent, out IMapGridComponent? mapGrid)) + if (ev.OldParent is {Valid: true} old && + EntityManager.TryGetComponent(old, out IMapGridComponent? mapGrid)) { var oldGrid = mapGrid.GridIndex; @@ -115,7 +114,7 @@ namespace Content.Server.Gravity.EntitySystems } } - var newGrid = IoCManager.Resolve().GetComponent(ev.Entity).GridID; + var newGrid = EntityManager.GetComponent(ev.Entity).GridID; var newStatuses = _alerts.GetOrNew(newGrid); newStatuses.Add(status); diff --git a/Content.Server/Hands/Components/HandsComponent.cs b/Content.Server/Hands/Components/HandsComponent.cs index 1f387b3485..ba07419840 100644 --- a/Content.Server/Hands/Components/HandsComponent.cs +++ b/Content.Server/Hands/Components/HandsComponent.cs @@ -31,6 +31,7 @@ namespace Content.Server.Hands.Components #pragma warning restore 618 { [Dependency] private readonly IEntitySystemManager _entitySystemManager = default!; + [Dependency] private readonly IEntityManager _entities = default!; [DataField("disarmedSound")] SoundSpecifier _disarmedSound = new SoundPathSpecifier("/Audio/Effects/thudswoosh.ogg"); @@ -38,27 +39,27 @@ namespace Content.Server.Hands.Components protected override void OnHeldEntityRemovedFromHand(EntityUid heldEntity, HandState handState) { - if (IoCManager.Resolve().TryGetComponent(heldEntity, out ItemComponent? item)) + if (_entities.TryGetComponent(heldEntity, out ItemComponent? item)) { item.RemovedFromSlot(); _entitySystemManager.GetEntitySystem().UnequippedHandInteraction(Owner, heldEntity, handState); } - if (IoCManager.Resolve().TryGetComponent(heldEntity, out SpriteComponent? sprite)) + if (_entities.TryGetComponent(heldEntity, out SpriteComponent? sprite)) { - sprite.RenderOrder = IoCManager.Resolve().CurrentTick.Value; + sprite.RenderOrder = _entities.CurrentTick.Value; } } protected override void HandlePickupAnimation(EntityUid entity) { - var initialPosition = EntityCoordinates.FromMap(IoCManager.Resolve().GetComponent(Owner).Parent?.Owner ?? Owner, IoCManager.Resolve().GetComponent(entity).MapPosition); + var initialPosition = EntityCoordinates.FromMap(_entities.GetComponent(Owner).Parent?.Owner ?? Owner, _entities.GetComponent(entity).MapPosition); - var finalPosition = IoCManager.Resolve().GetComponent(Owner).LocalPosition; + var finalPosition = _entities.GetComponent(Owner).LocalPosition; if (finalPosition.EqualsApprox(initialPosition.Position)) return; - IoCManager.Resolve().EntityNetManager!.SendSystemNetworkMessage( + _entities.EntityNetManager!.SendSystemNetworkMessage( new PickupAnimationMessage(entity, finalPosition, initialPosition)); } @@ -106,13 +107,13 @@ namespace Content.Server.Hands.Components { if (ActiveHand != null && Drop(ActiveHand, false)) { - source.PopupMessageOtherClients(Loc.GetString("hands-component-disarm-success-others-message", ("disarmer", Name: IoCManager.Resolve().GetComponent(source).EntityName), ("disarmed", Name: IoCManager.Resolve().GetComponent(target).EntityName))); - source.PopupMessageCursor(Loc.GetString("hands-component-disarm-success-message", ("disarmed", Name: IoCManager.Resolve().GetComponent(target).EntityName))); + source.PopupMessageOtherClients(Loc.GetString("hands-component-disarm-success-others-message", ("disarmer", Name: _entities.GetComponent(source).EntityName), ("disarmed", Name: _entities.GetComponent(target).EntityName))); + source.PopupMessageCursor(Loc.GetString("hands-component-disarm-success-message", ("disarmed", Name: _entities.GetComponent(target).EntityName))); } else { - source.PopupMessageOtherClients(Loc.GetString("hands-component-shove-success-others-message", ("shover", Name: IoCManager.Resolve().GetComponent(source).EntityName), ("shoved", Name: IoCManager.Resolve().GetComponent(target).EntityName))); - source.PopupMessageCursor(Loc.GetString("hands-component-shove-success-message", ("shoved", Name: IoCManager.Resolve().GetComponent(target).EntityName))); + source.PopupMessageOtherClients(Loc.GetString("hands-component-shove-success-others-message", ("shover", Name: _entities.GetComponent(source).EntityName), ("shoved", Name: _entities.GetComponent(target).EntityName))); + source.PopupMessageCursor(Loc.GetString("hands-component-shove-success-message", ("shoved", Name: _entities.GetComponent(target).EntityName))); } } } @@ -123,8 +124,8 @@ namespace Content.Server.Hands.Components private bool BreakPulls() { // What is this API?? - if (!IoCManager.Resolve().TryGetComponent(Owner, out SharedPullerComponent? puller) - || puller.Pulling == null || !IoCManager.Resolve().TryGetComponent(puller.Pulling, out SharedPullableComponent? pullable)) + if (!_entities.TryGetComponent(Owner, out SharedPullerComponent? puller) + || puller.Pulling is not {Valid: true} pulling || !_entities.TryGetComponent(puller.Pulling.Value, out SharedPullableComponent? pullable)) return false; return _entitySystemManager.GetEntitySystem().TryStopPull(pullable); @@ -163,7 +164,7 @@ namespace Content.Server.Hands.Components if (!TryGetHeldEntity(handName, out var heldEntity)) return null; - IoCManager.Resolve().TryGetComponent(heldEntity, out ItemComponent? item); + _entities.TryGetComponent(heldEntity, out ItemComponent? item); return item; } @@ -177,7 +178,7 @@ namespace Content.Server.Hands.Components if (!TryGetHeldEntity(handName, out var heldEntity)) return false; - return IoCManager.Resolve().TryGetComponent(heldEntity, out item); + return _entities.TryGetComponent(heldEntity, out item); } /// @@ -190,7 +191,7 @@ namespace Content.Server.Hands.Components if (!TryGetActiveHeldEntity(out var heldEntity)) return null; - IoCManager.Resolve().TryGetComponent(heldEntity, out ItemComponent? item); + _entities.TryGetComponent(heldEntity, out ItemComponent? item); return item; } } @@ -199,7 +200,7 @@ namespace Content.Server.Hands.Components { foreach (var entity in GetAllHeldEntities()) { - if (IoCManager.Resolve().TryGetComponent(entity, out ItemComponent? item)) + if (_entities.TryGetComponent(entity, out ItemComponent? item)) yield return item; } } diff --git a/Content.Server/Hands/Systems/HandsSystem.cs b/Content.Server/Hands/Systems/HandsSystem.cs index c9060bd148..2eaec30feb 100644 --- a/Content.Server/Hands/Systems/HandsSystem.cs +++ b/Content.Server/Hands/Systems/HandsSystem.cs @@ -14,8 +14,10 @@ using Content.Shared.Hands; using Content.Shared.Hands.Components; using Content.Shared.Input; using Content.Shared.Physics.Pull; +using Content.Shared.Popups; using JetBrains.Annotations; using Robust.Server.Player; +using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.Input.Binding; using Robust.Shared.IoC; @@ -187,9 +189,7 @@ namespace Content.Server.Hands.Systems if (session is not IPlayerSession playerSession) return false; - var playerEnt = playerSession.AttachedEntity; - - if (playerEnt == default || !EntityManager.EntityExists(playerEnt)) + if (playerSession.AttachedEntity is not {Valid: true} playerEnt || !EntityManager.EntityExists(playerEnt)) return false; return EntityManager.TryGetComponent(playerEnt, out hands); @@ -216,9 +216,7 @@ namespace Content.Server.Hands.Systems if (session is not IPlayerSession playerSession) return false; - var playerEnt = playerSession.AttachedEntity; - - if (playerEnt == default || + if (playerSession.AttachedEntity is not {Valid: true} playerEnt || !EntityManager.EntityExists(playerEnt) || playerEnt.IsInContainer() || !EntityManager.TryGetComponent(playerEnt, out SharedHandsComponent? hands) || @@ -230,10 +228,10 @@ namespace Content.Server.Hands.Systems { var splitStack = _stackSystem.Split(throwEnt, 1, EntityManager.GetComponent(playerEnt).Coordinates, stack); - if (!splitStack.Valid) + if (splitStack is not {Valid: true}) return false; - throwEnt = splitStack; + throwEnt = splitStack.Value; } else if (!hands.Drop(throwEnt)) return false; @@ -265,9 +263,7 @@ namespace Content.Server.Hands.Systems if (session is not IPlayerSession playerSession) return; - var plyEnt = playerSession.AttachedEntity; - - if (plyEnt == default || !EntityManager.EntityExists(plyEnt)) + if (playerSession.AttachedEntity is not {Valid: true} plyEnt || !EntityManager.EntityExists(plyEnt)) return; if (!EntityManager.TryGetComponent(plyEnt, out SharedHandsComponent? hands) || diff --git a/Content.Server/Headset/HeadsetComponent.cs b/Content.Server/Headset/HeadsetComponent.cs index fb459a490d..92970f1e6c 100644 --- a/Content.Server/Headset/HeadsetComponent.cs +++ b/Content.Server/Headset/HeadsetComponent.cs @@ -50,12 +50,12 @@ namespace Content.Server.Headset _radioSystem = EntitySystem.Get(); } - public bool CanListen(string message, EntityUidsource) + public bool CanListen(string message, EntityUid source) { return RadioRequested; } - public void Receive(string message, int channel, EntityUidsource) + public void Receive(string message, int channel, EntityUid source) { if (Owner.TryGetContainer(out var container)) { @@ -74,12 +74,12 @@ namespace Content.Server.Headset } } - public void Listen(string message, EntityUidspeaker) + public void Listen(string message, EntityUid speaker) { Broadcast(message, speaker); } - public void Broadcast(string message, EntityUidspeaker) + public void Broadcast(string message, EntityUid speaker) { _radioSystem.SpreadMessage(this, speaker, message, BroadcastFrequency); RadioRequested = false; diff --git a/Content.Server/Instruments/InstrumentSystem.cs b/Content.Server/Instruments/InstrumentSystem.cs index 986109672e..9919cae3ee 100644 --- a/Content.Server/Instruments/InstrumentSystem.cs +++ b/Content.Server/Instruments/InstrumentSystem.cs @@ -150,13 +150,11 @@ public sealed partial class InstrumentSystem : SharedInstrumentSystem || instrument.LaggedBatches >= MaxMidiLaggedBatches) && instrument.InstrumentPlayer != null && instrument.RespectMidiLimits) { - var mob = instrument.InstrumentPlayer.AttachedEntity; - // Just in case Clean(((IComponent) instrument).Owner); instrument.UserInterface?.CloseAll(); - if (mob != null) + if (instrument.InstrumentPlayer.AttachedEntity is {Valid: true} mob) { _stunSystem.TryParalyze(mob, TimeSpan.FromSeconds(1)); diff --git a/Content.Server/Interaction/InteractionSystem.cs b/Content.Server/Interaction/InteractionSystem.cs index cf93a10061..3883b7554a 100644 --- a/Content.Server/Interaction/InteractionSystem.cs +++ b/Content.Server/Interaction/InteractionSystem.cs @@ -5,7 +5,6 @@ using System.Threading.Tasks; using Content.Server.Administration.Logs; using Content.Server.CombatMode; using Content.Server.Hands.Components; -using Content.Server.Items; using Content.Server.Pulling; using Content.Server.Storage.Components; using Content.Shared.ActionBlocker; @@ -70,7 +69,7 @@ namespace Content.Server.Interaction } #region Client Input Validation - private bool ValidateClientInput(ICommonSession? session, EntityCoordinates coords, EntityUid uid, [NotNullWhen(true)] out EntityUid userEntity) + private bool ValidateClientInput(ICommonSession? session, EntityCoordinates coords, EntityUid uid, [NotNullWhen(true)] out EntityUid? userEntity) { userEntity = null; @@ -89,7 +88,7 @@ namespace Content.Server.Interaction userEntity = ((IPlayerSession?) session)?.AttachedEntity; - if (userEntity == null || !IoCManager.Resolve().EntityExists(userEntity)) + if (userEntity == null || !EntityManager.EntityExists(userEntity.Value)) { Logger.WarningS("system.interaction", $"Client sent interaction with no attached entity. Session={session}"); @@ -101,10 +100,10 @@ namespace Content.Server.Interaction public override bool CanAccessViaStorage(EntityUid user, EntityUid target) { - if (!EntityManager.EntityExists(target) + if (!EntityManager.EntityExists(target)) return false; - if (!entity.TryGetContainer(out var container)) + if (!target.TryGetContainer(out var container)) return false; if (!EntityManager.TryGetComponent(container.Owner, out ServerStorageComponent storage)) @@ -127,7 +126,7 @@ namespace Content.Server.Interaction /// private void HandleInteractInventorySlotEvent(InteractInventorySlotEvent msg, EntitySessionEventArgs args) { - if (!EntityManager.EntityExists(msg.ItemUid) + if (!EntityManager.EntityExists(msg.ItemUid)) { Logger.WarningS("system.interaction", $"Client sent inventory interaction with an invalid target item. Session={args.SenderSession}"); @@ -135,7 +134,7 @@ namespace Content.Server.Interaction } // client sanitization - if (!ValidateClientInput(args.SenderSession, IoCManager.Resolve().GetComponent(item).Coordinates, msg.ItemUid, out var userEntity)) + if (!ValidateClientInput(args.SenderSession, EntityManager.GetComponent(msg.ItemUid).Coordinates, msg.ItemUid, out var userEntity)) { Logger.InfoS("system.interaction", $"Inventory interaction validation failed. Session={args.SenderSession}"); return; @@ -143,10 +142,10 @@ namespace Content.Server.Interaction if (msg.AltInteract) // Use 'UserInteraction' function - behaves as if the user alt-clicked the item in the world. - UserInteraction(userEntity, IoCManager.Resolve().GetComponent(item).Coordinates, msg.ItemUid, msg.AltInteract); + UserInteraction(userEntity.Value, EntityManager.GetComponent(msg.ItemUid).Coordinates, msg.ItemUid, msg.AltInteract); else // User used 'E'. We want to activate it, not simulate clicking on the item - InteractionActivate(userEntity, item); + InteractionActivate(userEntity.Value, msg.ItemUid); } #region Drag drop @@ -158,15 +157,15 @@ namespace Content.Server.Interaction return; } - if (!_actionBlockerSystem.CanInteract(userEntity)) + if (!_actionBlockerSystem.CanInteract(userEntity.Value)) return; - if (!EntityManager.EntityExists(msg.Dropped) + if (!EntityManager.EntityExists(msg.Dropped)) return; - if (!EntityManager.EntityExists(msg.Target) + if (!EntityManager.EntityExists(msg.Target)) return; - var interactionArgs = new DragDropEvent(userEntity, msg.DropLocation, dropped, target); + var interactionArgs = new DragDropEvent(userEntity.Value, msg.DropLocation, msg.Dropped, msg.Target); // must be in range of both the target and the object they are drag / dropping // Client also does this check but ya know we gotta validate it. @@ -174,8 +173,8 @@ namespace Content.Server.Interaction return; // trigger dragdrops on the dropped entity - RaiseLocalEvent(dropped, interactionArgs); - foreach (var dragDrop in IoCManager.Resolve().GetComponents(dropped)) + RaiseLocalEvent(msg.Dropped, interactionArgs); + foreach (var dragDrop in EntityManager.GetComponents(msg.Dropped)) { if (dragDrop.CanDrop(interactionArgs) && dragDrop.Drop(interactionArgs)) @@ -185,8 +184,8 @@ namespace Content.Server.Interaction } // trigger dragdropons on the targeted entity - RaiseLocalEvent(target, interactionArgs, false); - foreach (var dragDropOn in IoCManager.Resolve().GetComponents(target)) + RaiseLocalEvent(msg.Target, interactionArgs, false); + foreach (var dragDropOn in EntityManager.GetComponents(msg.Target)) { if (dragDropOn.CanDragDropOn(interactionArgs) && dragDropOn.DragDropOn(interactionArgs)) @@ -206,10 +205,10 @@ namespace Content.Server.Interaction return false; } - if (!EntityManager.EntityExists(uid) + if (!EntityManager.EntityExists(uid)) return false; - InteractionActivate(user, used); + InteractionActivate(user.Value, uid); return true; } #endregion @@ -223,8 +222,8 @@ namespace Content.Server.Interaction return true; } - if (IoCManager.Resolve().TryGetComponent(userEntity, out CombatModeComponent? combatMode) && combatMode.IsInCombatMode) - DoAttack(userEntity, coords, true); + if (EntityManager.TryGetComponent(userEntity.Value, out CombatModeComponent? combatMode) && combatMode.IsInCombatMode) + DoAttack(userEntity.Value, coords, true); return true; } @@ -238,7 +237,7 @@ namespace Content.Server.Interaction /// internal void AiUseInteraction(EntityUid entity, EntityCoordinates coords, EntityUid uid) { - if (IoCManager.Resolve().HasComponent(entity)) + if (EntityManager.HasComponent(entity)) throw new InvalidOperationException(); UserInteraction(entity, coords, uid); @@ -253,7 +252,7 @@ namespace Content.Server.Interaction return true; } - UserInteraction(userEntity, coords, uid); + UserInteraction(userEntity.Value, coords, uid); return true; } @@ -267,7 +266,7 @@ namespace Content.Server.Interaction return true; } - UserInteraction(userEntity, coords, uid, altInteract : true ); + UserInteraction(userEntity.Value, coords, uid, altInteract : true ); return true; } @@ -283,16 +282,16 @@ namespace Content.Server.Interaction if (userEntity == uid) return false; - if (!EntityManager.EntityExists(uid) + if (!EntityManager.EntityExists(uid)) return false; - if (!InRangeUnobstructed(userEntity, pulledObject, popup: true)) + if (!InRangeUnobstructed(userEntity.Value, uid, popup: true)) return false; - if (!IoCManager.Resolve().TryGetComponent(pulledObject, out SharedPullableComponent? pull)) + if (!EntityManager.TryGetComponent(uid, out SharedPullableComponent? pull)) return false; - return _pullSystem.TogglePull(userEntity, pull); + return _pullSystem.TogglePull(userEntity.Value, pull); } /// @@ -304,12 +303,12 @@ namespace Content.Server.Interaction /// Whether to use default or alternative interactions (usually as a result of /// alt+clicking). If combat mode is enabled, the alternative action is to perform the default non-combat /// interaction. Having an item in the active hand also disables alternative interactions. - public async void UserInteraction(EntityUid user, EntityCoordinates coordinates, EntityUid clickedUid, bool altInteract = false) + public async void UserInteraction(EntityUid user, EntityCoordinates coordinates, EntityUid target, bool altInteract = false) { // TODO COMBAT Consider using alt-interact for advanced combat? maybe alt-interact disarms? - if (!altInteract && IoCManager.Resolve().TryGetComponent(user, out CombatModeComponent? combatMode) && combatMode.IsInCombatMode) + if (!altInteract && EntityManager.TryGetComponent(user, out CombatModeComponent? combatMode) && combatMode.IsInCombatMode) { - DoAttack(user, coordinates, false, clickedUid); + DoAttack(user, coordinates, false, target); return; } @@ -319,32 +318,29 @@ namespace Content.Server.Interaction if (!_actionBlockerSystem.CanInteract(user)) return; - // Get entity clicked upon from UID if valid UID, if not assume no entity clicked upon and null - EntityManager.EntityExists(clickedUid); - // Check if interacted entity is in the same container, the direct child, or direct parent of the user. // This is bypassed IF the interaction happened through an item slot (e.g., backpack UI) - if (target != null && !user.IsInSameOrParentContainer(target) && !CanAccessViaStorage(user, target)) + if (target != default && !user.IsInSameOrParentContainer(target) && !CanAccessViaStorage(user, target)) { Logger.WarningS("system.interaction", - $"User entity named {IoCManager.Resolve().GetComponent(user).EntityName} clicked on object {IoCManager.Resolve().GetComponent(target).EntityName} that isn't the parent, child, or in the same container"); + $"User entity named {EntityManager.GetComponent(user).EntityName} clicked on object {EntityManager.GetComponent(target).EntityName} that isn't the parent, child, or in the same container"); return; } // Verify user has a hand, and find what object they are currently holding in their active hand - if (!IoCManager.Resolve().TryGetComponent(user, out var hands)) + if (!EntityManager.TryGetComponent(user, out var hands)) return; var item = hands.GetActiveHand?.Owner; // TODO: Replace with body interaction range when we get something like arm length or telekinesis or something. var inRangeUnobstructed = user.InRangeUnobstructed(coordinates, ignoreInsideBlocker: true); - if (target == null || !inRangeUnobstructed) + if (target == default || !inRangeUnobstructed) { if (item == null) return; - if (!await InteractUsingRanged(user, item, target, coordinates, inRangeUnobstructed) && + if (!await InteractUsingRanged(user, item.Value, target, coordinates, inRangeUnobstructed) && !inRangeUnobstructed) { var message = Loc.GetString("interaction-system-user-interaction-cannot-reach"); @@ -362,7 +358,7 @@ namespace Content.Server.Interaction else if (item != null && item != target) // We are performing a standard interaction with an item, and the target isn't the same as the item // currently in our hand. We will use the item in our hand on the nearby object via InteractUsing - await InteractUsing(user, item, target, coordinates); + await InteractUsing(user, item.Value, target, coordinates); else if (item == null) // Since our hand is empty we will use InteractHand/Activate InteractHand(user, target); @@ -372,10 +368,10 @@ namespace Content.Server.Interaction private bool ValidateInteractAndFace(EntityUid user, EntityCoordinates coordinates) { // Verify user is on the same map as the entity they clicked on - if (coordinates.GetMapId(_entityManager) != IoCManager.Resolve().GetComponent(user).MapID) + if (coordinates.GetMapId(_entityManager) != EntityManager.GetComponent(user).MapID) { Logger.WarningS("system.interaction", - $"User entity named {IoCManager.Resolve().GetComponent(user).EntityName} clicked on a map they aren't located on"); + $"User entity named {EntityManager.GetComponent(user).EntityName} clicked on a map they aren't located on"); return false; } @@ -403,7 +399,7 @@ namespace Content.Server.Interaction var interactHandEventArgs = new InteractHandEventArgs(user, target); - var interactHandComps = IoCManager.Resolve().GetComponents(target).ToList(); + var interactHandComps = EntityManager.GetComponents(target).ToList(); foreach (var interactHandComp in interactHandComps) { // If an InteractHand returns a status completion we finish our interaction @@ -433,7 +429,7 @@ namespace Content.Server.Interaction if (rangedMsg.Handled) return true; - var rangedInteractions = IoCManager.Resolve().GetComponents(target).ToList(); + var rangedInteractions = EntityManager.GetComponents(target).ToList(); var rangedInteractionEventArgs = new RangedInteractEventArgs(user, used, clickLocation); // See if we have a ranged interaction @@ -458,18 +454,13 @@ namespace Content.Server.Interaction if (!_actionBlockerSystem.CanAttack(user)) return; - EntityUid targetEnt = null; - if (!wideAttack) { - // Get entity clicked upon from UID if valid UID, if not assume no entity clicked upon and null - EntityManager.EntityExists(targetUid); - // Check if interacted entity is in the same container, the direct child, or direct parent of the user. - if (targetEnt != null && !user.IsInSameOrParentContainer(targetEnt) && !CanAccessViaStorage(user, targetEnt)) + if (targetUid != default && !user.IsInSameOrParentContainer(targetUid) && !CanAccessViaStorage(user, targetUid)) { Logger.WarningS("system.interaction", - $"User entity named {IoCManager.Resolve().GetComponent(user).EntityName} clicked on object {IoCManager.Resolve().GetComponent(targetEnt).EntityName} that isn't the parent, child, or in the same container"); + $"User entity named {EntityManager.GetComponent(user).EntityName} clicked on object {EntityManager.GetComponent(targetUid).EntityName} that isn't the parent, child, or in the same container"); return; } @@ -479,11 +470,9 @@ namespace Content.Server.Interaction } // Verify user has a hand, and find what object they are currently holding in their active hand - if (IoCManager.Resolve().TryGetComponent(user, out var hands)) + if (EntityManager.TryGetComponent(user, out var hands)) { - var item = hands.GetActiveHand?.Owner; - - if (item != null) + if (hands.GetActiveHand?.Owner is {Valid: true} item) { if (wideAttack) { @@ -503,10 +492,10 @@ namespace Content.Server.Interaction if (ev.Handled) { - if (targetEnt != null) + if (targetUid != default) { _adminLogSystem.Add(LogType.AttackArmedClick, LogImpact.Medium, - $"{user} attacked {targetEnt} with {item} at {coordinates}"); + $"{user} attacked {targetUid} with {item} at {coordinates}"); } else { @@ -518,12 +507,10 @@ namespace Content.Server.Interaction } } } - else if (!wideAttack && - (targetEnt != null || EntityManager.EntityExists(targetUid) && - IoCManager.Resolve().HasComponent(targetEnt)) + else if (!wideAttack && targetUid != default) { // We pick up items if our hand is empty, even if we're in combat mode. - InteractHand(user, targetEnt); + InteractHand(user, targetUid); return; } } @@ -543,10 +530,10 @@ namespace Content.Server.Interaction RaiseLocalEvent(user, ev, false); if (ev.Handled) { - if (targetEnt != null) + if (targetUid != default) { _adminLogSystem.Add(LogType.AttackUnarmedClick, LogImpact.Medium, - $"{user} attacked {targetEnt} at {coordinates}"); + $"{user} attacked {targetUid} at {coordinates}"); } else { diff --git a/Content.Server/Interaction/TilePryCommand.cs b/Content.Server/Interaction/TilePryCommand.cs index cfb13f57e6..1fc66c87c4 100644 --- a/Content.Server/Interaction/TilePryCommand.cs +++ b/Content.Server/Interaction/TilePryCommand.cs @@ -16,6 +16,8 @@ namespace Content.Server.Interaction [AdminCommand(AdminFlags.Debug)] class TilePryCommand : IConsoleCommand { + [Dependency] private readonly IEntityManager _entities = default!; + public string Command => "tilepry"; public string Description => "Pries up all tiles in a radius around the user."; public string Help => $"Usage: {Command} "; @@ -47,9 +49,9 @@ namespace Content.Server.Interaction } var mapManager = IoCManager.Resolve(); - var playerGrid = IoCManager.Resolve().GetComponent(player.AttachedEntity).GridID; + var playerGrid = _entities.GetComponent(player.AttachedEntity.Value).GridID; var mapGrid = mapManager.GetGrid(playerGrid); - var playerPosition = IoCManager.Resolve().GetComponent(player.AttachedEntity).Coordinates; + var playerPosition = _entities.GetComponent(player.AttachedEntity.Value).Coordinates; var tileDefinitionManager = IoCManager.Resolve(); for (var i = -radius; i <= radius; i++) diff --git a/Content.Server/Inventory/Components/InventoryComponent.cs b/Content.Server/Inventory/Components/InventoryComponent.cs index 993b563ff6..7bbc4e0e28 100644 --- a/Content.Server/Inventory/Components/InventoryComponent.cs +++ b/Content.Server/Inventory/Components/InventoryComponent.cs @@ -32,6 +32,7 @@ namespace Content.Server.Inventory.Components public class InventoryComponent : SharedInventoryComponent, IExAct { [Dependency] private readonly IEntitySystemManager _entitySystemManager = default!; + [Dependency] private readonly IEntityManager _entities = default!; [ViewVariables] private readonly Dictionary _slotContainers = new(); @@ -62,7 +63,7 @@ namespace Content.Server.Inventory.Components { if (TryGetSlotItem(slot, out ItemComponent? item)) { - IoCManager.Resolve().DeleteEntity(item.Owner); + _entities.DeleteEntity(item.Owner); } RemoveSlot(slot); @@ -105,7 +106,7 @@ namespace Content.Server.Inventory.Components public IEnumerable LookupItems() where T : Component { return _slotContainers.Values - .SelectMany(x => x.ContainedEntities.Select(e => IoCManager.Resolve().GetComponentOrNull(e))) + .SelectMany(x => x.ContainedEntities.Select(e => _entities.GetComponentOrNull(e))) .Where(x => x != null); } @@ -117,14 +118,14 @@ namespace Content.Server.Inventory.Components } var containedEntity = _slotContainers[slot].ContainedEntity; - if ((containedEntity != null ? (!IoCManager.Resolve().EntityExists(containedEntity) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(containedEntity).EntityLifeStage) >= EntityLifeStage.Deleted : null) == true) + if (containedEntity != null && _entities.GetComponent(containedEntity.Value).EntityDeleted) { _slotContainers.Remove(slot); containedEntity = null; Dirty(); } - return (containedEntity != null ? IoCManager.Resolve().GetComponent(containedEntity) : null); + return containedEntity.HasValue ? _entities.GetComponent(containedEntity.Value) : null; } public bool TryGetSlotItem(Slots slot, [NotNullWhen(true)] out T? itemComponent) where T : ItemComponent @@ -186,7 +187,7 @@ namespace Content.Server.Inventory.Components Equip(slot, item, mobCheck, out var _); public bool Equip(Slots slot, EntityUid entity, bool mobCheck = true) => - Equip(slot, IoCManager.Resolve().GetComponent(entity), mobCheck); + Equip(slot, _entities.GetComponent(entity), mobCheck); /// /// Checks whether an item can be put in the specified slot. @@ -218,7 +219,7 @@ namespace Content.Server.Inventory.Components } } - if (IoCManager.Resolve().TryGetComponent(Owner, out IInventoryController? controller)) + if (_entities.TryGetComponent(Owner, out IInventoryController? controller)) { pass = controller.CanEquip(slot, item.Owner, pass, out var controllerReason); reason = controllerReason ?? reason; @@ -244,7 +245,7 @@ namespace Content.Server.Inventory.Components CanEquip(slot, item, mobCheck, out var _); public bool CanEquip(Slots slot, EntityUid entity, bool mobCheck = true) => - CanEquip(slot, IoCManager.Resolve().GetComponent(entity), mobCheck); + CanEquip(slot, _entities.GetComponent(entity), mobCheck); /// /// Drops the item in a slot. @@ -260,9 +261,8 @@ namespace Content.Server.Inventory.Components } var inventorySlot = _slotContainers[slot]; - var entity = inventorySlot.ContainedEntity; - if (entity == null) + if (inventorySlot.ContainedEntity is not {Valid: true} entity) { return false; } @@ -273,7 +273,7 @@ namespace Content.Server.Inventory.Components } // TODO: The item should be dropped to the container our owner is in, if any. - IoCManager.Resolve().GetComponent(entity).AttachParentToContainerOrGrid(); + _entities.GetComponent(entity).AttachParentToContainerOrGrid(); _entitySystemManager.GetEntitySystem().UnequippedInteraction(Owner, entity, slot); @@ -294,16 +294,15 @@ namespace Content.Server.Inventory.Components public void ForceUnequip(Slots slot) { var inventorySlot = _slotContainers[slot]; - var entity = inventorySlot.ContainedEntity; - if (entity == null) + if (inventorySlot.ContainedEntity is not {Valid: true} entity) { return; } - var item = IoCManager.Resolve().GetComponent(entity); + var item = _entities.GetComponent(entity); inventorySlot.ForceRemove(entity); - var itemTransform = IoCManager.Resolve().GetComponent(entity); + var itemTransform = _entities.GetComponent(entity); itemTransform.AttachParentToContainerOrGrid(); @@ -328,7 +327,7 @@ namespace Content.Server.Inventory.Components return false; var inventorySlot = _slotContainers[slot]; - return inventorySlot.ContainedEntity != null && inventorySlot.CanRemove(inventorySlot.ContainedEntity); + return inventorySlot.ContainedEntity != null && inventorySlot.CanRemove(inventorySlot.ContainedEntity.Value); } /// @@ -404,7 +403,7 @@ namespace Content.Server.Inventory.Components if (container is not ContainerSlot slot || !_slotContainers.ContainsValue(slot)) return; - if (IoCManager.Resolve().TryGetComponent(entity, out ItemComponent? itemComp)) + if (_entities.TryGetComponent(entity, out ItemComponent? itemComp)) { itemComp.RemovedFromSlot(); } @@ -424,10 +423,10 @@ namespace Content.Server.Inventory.Components { case ClientInventoryUpdate.Equip: { - var hands = IoCManager.Resolve().GetComponent(Owner); + var hands = _entities.GetComponent(Owner); var activeHand = hands.ActiveHand; var activeItem = hands.GetActiveHand; - if (activeHand != null && activeItem != null && IoCManager.Resolve().TryGetComponent(activeItem.Owner, out ItemComponent? item)) + if (activeHand != null && activeItem != null && _entities.TryGetComponent(activeItem.Owner, out ItemComponent? item)) { hands.TryDropNoInteraction(); if (!Equip(msg.Inventoryslot, item, true, out var reason)) @@ -442,7 +441,7 @@ namespace Content.Server.Inventory.Components case ClientInventoryUpdate.Use: { var interactionSystem = _entitySystemManager.GetEntitySystem(); - var hands = IoCManager.Resolve().GetComponent(Owner); + var hands = _entities.GetComponent(Owner); var activeHand = hands.GetActiveHand; var itemContainedInSlot = GetSlotItem(msg.Inventoryslot); if (itemContainedInSlot != null) @@ -462,7 +461,7 @@ namespace Content.Server.Inventory.Components } case ClientInventoryUpdate.Hover: { - var hands = IoCManager.Resolve().GetComponent(Owner); + var hands = _entities.GetComponent(Owner); var activeHand = hands.GetActiveHand; if (activeHand != null && GetSlotItem(msg.Inventoryslot) == null) { @@ -504,7 +503,7 @@ namespace Content.Server.Inventory.Components if (!HasSlot(msg.Slot)) // client input sanitization return; var item = GetSlotItem(msg.Slot); - if (item != null && IoCManager.Resolve().TryGetComponent(item.Owner, out ServerStorageComponent? storage)) + if (item != null && _entities.TryGetComponent(item.Owner, out ServerStorageComponent? storage)) storage.OpenStorageUI(Owner); break; } @@ -515,9 +514,9 @@ namespace Content.Server.Inventory.Components var list = new List>(); foreach (var (slot, container) in _slotContainers) { - if (container != null && container.ContainedEntity != null) + if (container is {ContainedEntity: { }}) { - list.Add(new KeyValuePair(slot, container.ContainedEntity)); + list.Add(new KeyValuePair(slot, container.ContainedEntity.Value)); } } @@ -538,7 +537,7 @@ namespace Content.Server.Inventory.Components { foreach (var entity in slot.ContainedEntities) { - var exActs = IoCManager.Resolve().GetComponents(entity).ToList(); + var exActs = _entities.GetComponents(entity).ToList(); foreach (var exAct in exActs) { exAct.OnExplosion(eventArgs); @@ -549,7 +548,7 @@ namespace Content.Server.Inventory.Components public override bool IsEquipped(EntityUid item) { - if (item == null) return false; + if (item == default) return false; foreach (var containerSlot in _slotContainers.Values) { // we don't want a recursive check here diff --git a/Content.Server/Jobs/AddComponentSpecial.cs b/Content.Server/Jobs/AddComponentSpecial.cs index 4bf1c87c3d..b154a52c80 100644 --- a/Content.Server/Jobs/AddComponentSpecial.cs +++ b/Content.Server/Jobs/AddComponentSpecial.cs @@ -13,7 +13,7 @@ namespace Content.Server.Jobs [DataField("component", required:true)] public string Component { get; } = string.Empty; - public override void AfterEquip(EntityUidmob) + public override void AfterEquip(EntityUid mob) { // Yes, this will throw if your component is invalid. var component = (Component)IoCManager.Resolve().GetComponent(Component); diff --git a/Content.Server/Jobs/GiveItemOnHolidaySpecial.cs b/Content.Server/Jobs/GiveItemOnHolidaySpecial.cs index 2233e6952e..4f5b85a7b6 100644 --- a/Content.Server/Jobs/GiveItemOnHolidaySpecial.cs +++ b/Content.Server/Jobs/GiveItemOnHolidaySpecial.cs @@ -21,7 +21,7 @@ namespace Content.Server.Jobs [DataField("prototype", customTypeSerializer:typeof(PrototypeIdSerializer))] public string Prototype { get; } = string.Empty; - public override void AfterEquip(EntityUidmob) + public override void AfterEquip(EntityUid mob) { if (string.IsNullOrEmpty(Holiday) || string.IsNullOrEmpty(Prototype)) return; diff --git a/Content.Server/Kitchen/Components/KitchenSpikeComponent.cs b/Content.Server/Kitchen/Components/KitchenSpikeComponent.cs index f7bc1c25c6..7f9be4d5c2 100644 --- a/Content.Server/Kitchen/Components/KitchenSpikeComponent.cs +++ b/Content.Server/Kitchen/Components/KitchenSpikeComponent.cs @@ -95,7 +95,7 @@ namespace Content.Server.Kitchen.Components return true; } - public async void TrySpike(EntityUid victim, EntityUiduser) + public async void TrySpike(EntityUid victim, EntityUid user) { var victimUid = (EntityUid) victim; if (_beingButchered.Contains(victimUid)) return; diff --git a/Content.Server/Kitchen/Components/MicrowaveComponent.cs b/Content.Server/Kitchen/Components/MicrowaveComponent.cs index d638618367..714ce9c912 100644 --- a/Content.Server/Kitchen/Components/MicrowaveComponent.cs +++ b/Content.Server/Kitchen/Components/MicrowaveComponent.cs @@ -37,6 +37,8 @@ namespace Content.Server.Kitchen.Components [ComponentReference(typeof(IActivate))] public class MicrowaveComponent : SharedMicrowaveComponent, IActivate, IInteractUsing, ISuicideAct, IBreakAct { + [Dependency] private readonly IEntityManager _entities = default!; + [Dependency] private readonly RecipeManager _recipeManager = default!; #region YAMLSERIALIZE @@ -66,7 +68,7 @@ namespace Content.Server.Kitchen.Components /// [ViewVariables] private uint _currentCookTimerTime = 1; - private bool Powered => !IoCManager.Resolve().TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered; + private bool Powered => !_entities.TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered; private bool HasContents => EntitySystem.Get() .TryGetSolution(Owner, SolutionName, out var solution) && @@ -204,7 +206,7 @@ namespace Content.Server.Kitchen.Components finalState = MicrowaveVisualState.Broken; } - if (IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearance)) + if (_entities.TryGetComponent(Owner, out AppearanceComponent? appearance)) { appearance.SetData(PowerDeviceVisuals.VisualState, finalState); } @@ -218,7 +220,7 @@ namespace Content.Server.Kitchen.Components void IActivate.Activate(ActivateEventArgs eventArgs) { - if (!IoCManager.Resolve().TryGetComponent(eventArgs.User, out ActorComponent? actor) || !Powered) + if (!_entities.TryGetComponent(eventArgs.User, out ActorComponent? actor) || !Powered) { return; } @@ -241,15 +243,13 @@ namespace Content.Server.Kitchen.Components return false; } - var itemEntity = IoCManager.Resolve().GetComponent(eventArgs.User).GetActiveHand?.Owner; - - if (itemEntity == null) + if (_entities.GetComponent(eventArgs.User).GetActiveHand?.Owner is not {Valid: true} itemEntity) { eventArgs.User.PopupMessage(Loc.GetString("microwave-component-interact-using-no-active-hand")); return false; } - if (IoCManager.Resolve().TryGetComponent(itemEntity, out var attackPourable)) + if (_entities.TryGetComponent(itemEntity, out var attackPourable)) { var solutionsSystem = EntitySystem.Get(); if (!solutionsSystem.TryGetDrainableSolution(itemEntity, out var attackSolution)) @@ -284,7 +284,7 @@ namespace Content.Server.Kitchen.Components return true; } - if (!IoCManager.Resolve().TryGetComponent(itemEntity, typeof(ItemComponent), out var food)) + if (!_entities.TryGetComponent(itemEntity, typeof(ItemComponent), out var food)) { Owner.PopupMessage(eventArgs.User, "microwave-component-interact-using-transfer-fail"); return false; @@ -310,18 +310,19 @@ namespace Content.Server.Kitchen.Components var solidsDict = new Dictionary(); foreach (var item in _storage.ContainedEntities) { - if (IoCManager.Resolve().GetComponent(item).EntityPrototype == null) + var metaData = _entities.GetComponent(item); + if (metaData.EntityPrototype == null) { continue; } - if (solidsDict.ContainsKey(IoCManager.Resolve().GetComponent(item).EntityPrototype.ID)) + if (solidsDict.ContainsKey(metaData.EntityPrototype.ID)) { - solidsDict[IoCManager.Resolve().GetComponent(item).EntityPrototype.ID]++; + solidsDict[metaData.EntityPrototype.ID]++; } else { - solidsDict.Add(IoCManager.Resolve().GetComponent(item).EntityPrototype.ID, 1); + solidsDict.Add(metaData.EntityPrototype.ID, 1); } } @@ -364,13 +365,13 @@ namespace Content.Server.Kitchen.Components if (recipeToCook != null) { SubtractContents(recipeToCook); - IoCManager.Resolve().SpawnEntity(recipeToCook.Result, IoCManager.Resolve().GetComponent(Owner).Coordinates); + _entities.SpawnEntity(recipeToCook.Result, _entities.GetComponent(Owner).Coordinates); } else { VaporizeReagents(); VaporizeSolids(); - IoCManager.Resolve().SpawnEntity(_badRecipeName, IoCManager.Resolve().GetComponent(Owner).Coordinates); + _entities.SpawnEntity(_badRecipeName, _entities.GetComponent(Owner).Coordinates); } } @@ -409,7 +410,7 @@ namespace Content.Server.Kitchen.Components { var item = _storage.ContainedEntities.ElementAt(i); _storage.Remove(item); - IoCManager.Resolve().DeleteEntity(item); + _entities.DeleteEntity(item); } } @@ -423,9 +424,9 @@ namespace Content.Server.Kitchen.Components private void EjectSolid(EntityUid entityId) { - if (IoCManager.Resolve().EntityExists(entityId)) + if (_entities.EntityExists(entityId)) { - _storage.Remove(IoCManager.Resolve().GetEntity(entityId)); + _storage.Remove(entityId); } } @@ -449,15 +450,16 @@ namespace Content.Server.Kitchen.Components { foreach (var item in _storage.ContainedEntities) { - if (IoCManager.Resolve().GetComponent(item).EntityPrototype == null) + var metaData = _entities.GetComponent(item); + if (metaData.EntityPrototype == null) { continue; } - if (IoCManager.Resolve().GetComponent(item).EntityPrototype.ID == recipeSolid.Key) + if (metaData.EntityPrototype.ID == recipeSolid.Key) { _storage.Remove(item); - IoCManager.Resolve().DeleteEntity(item); + _entities.DeleteEntity(item); break; } } @@ -515,7 +517,7 @@ namespace Content.Server.Kitchen.Components { var headCount = 0; - if (IoCManager.Resolve().TryGetComponent(victim, out var body)) + if (_entities.TryGetComponent(victim, out var body)) { var headSlots = body.GetSlotsOfType(BodyPartType.Head); diff --git a/Content.Server/Kitchen/EntitySystems/ReagentGrinderSystem.cs b/Content.Server/Kitchen/EntitySystems/ReagentGrinderSystem.cs index 9f3c1153e9..3d8f1d82ea 100644 --- a/Content.Server/Kitchen/EntitySystems/ReagentGrinderSystem.cs +++ b/Content.Server/Kitchen/EntitySystems/ReagentGrinderSystem.cs @@ -21,6 +21,7 @@ using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Log; using Robust.Shared.Player; +using Robust.Shared.Utility; namespace Content.Server.Kitchen.EntitySystems { @@ -52,7 +53,7 @@ namespace Content.Server.Kitchen.EntitySystems { if (args.Handled) return; - if (!IoCManager.Resolve().HasComponent(args.User)) + if (!EntityManager.HasComponent(args.User)) { component.Owner.PopupMessage(args.User, Loc.GetString("reagent-grinder-component-interact-using-no-hands")); @@ -60,7 +61,7 @@ namespace Content.Server.Kitchen.EntitySystems return; } - EntityUidheldEnt = args.Used; + var heldEnt = args.Used; // First, check if user is trying to insert a beaker. // No promise it will be a beaker right now, but whatever. @@ -71,7 +72,7 @@ namespace Content.Server.Kitchen.EntitySystems component.HeldBeaker = beaker; EnqueueUiUpdate(component); //We are done, return. Insert the beaker and exit! - if (IoCManager.Resolve().TryGetComponent(component.Owner, out AppearanceComponent? appearance)) + if (EntityManager.TryGetComponent(component.Owner, out AppearanceComponent? appearance)) { appearance.SetData(SharedReagentGrinderComponent.ReagentGrinderVisualState.BeakerAttached, component.BeakerContainer.ContainedEntity != null); @@ -83,7 +84,7 @@ namespace Content.Server.Kitchen.EntitySystems } //Next, see if the user is trying to insert something they want to be ground/juiced. - if (!IoCManager.Resolve().TryGetComponent(heldEnt, out ExtractableComponent? juice)) + if (!EntityManager.TryGetComponent(heldEnt, out ExtractableComponent? juice)) { //Entity did NOT pass the whitelist for grind/juice. //Wouldn't want the clown grinding up the Captain's ID card now would you? @@ -111,7 +112,7 @@ namespace Content.Server.Kitchen.EntitySystems { if (args.Handled) return; - if (!IoCManager.Resolve().TryGetComponent(args.User, out ActorComponent? actor)) + if (!EntityManager.TryGetComponent(args.User, out ActorComponent? actor)) { return; } @@ -159,18 +160,18 @@ namespace Content.Server.Kitchen.EntitySystems switch (message.Message) { case SharedReagentGrinderComponent.ReagentGrinderGrindStartMessage msg: - if (!IoCManager.Resolve().TryGetComponent(component.Owner, out ApcPowerReceiverComponent? receiver) || + if (!EntityManager.TryGetComponent(component.Owner, out ApcPowerReceiverComponent? receiver) || !receiver.Powered) break; ClickSound(component); - DoWork(component, message.Session.AttachedEntity!, + DoWork(component, message.Session.AttachedEntity!.Value, SharedReagentGrinderComponent.GrinderProgram.Grind); break; case SharedReagentGrinderComponent.ReagentGrinderJuiceStartMessage msg: - if (!IoCManager.Resolve().TryGetComponent(component.Owner, out ApcPowerReceiverComponent? receiver2) || + if (!EntityManager.TryGetComponent(component.Owner, out ApcPowerReceiverComponent? receiver2) || !receiver2.Powered) break; ClickSound(component); - DoWork(component, message.Session.AttachedEntity!, + DoWork(component, message.Session.AttachedEntity!.Value, SharedReagentGrinderComponent.GrinderProgram.Juice); break; @@ -191,10 +192,10 @@ namespace Content.Server.Kitchen.EntitySystems break; case SharedReagentGrinderComponent.ReagentGrinderEjectChamberContentMessage msg: - if (component.Chamber.ContainedEntities.TryFirstOrDefault(x => x == msg.EntityID, out var ent)) + if (component.Chamber.ContainedEntities.TryFirstOrNull(x => x == msg.EntityID, out var ent)) { - component.Chamber.Remove(ent); - SharedEntityExtensions.RandomOffset(ent, 0.4f); + component.Chamber.Remove(ent.Value); + SharedEntityExtensions.RandomOffset(ent.Value, 0.4f); EnqueueUiUpdate(component); ClickSound(component); } @@ -224,7 +225,7 @@ namespace Content.Server.Kitchen.EntitySystems { foreach (var entity in comp.Chamber.ContainedEntities) { - if (canJuice || !IoCManager.Resolve().TryGetComponent(entity, out ExtractableComponent? component)) continue; + if (canJuice || !EntityManager.TryGetComponent(entity, out ExtractableComponent? component)) continue; canJuice = component.JuiceSolution != null; canGrind = component.GrindableSolution != null @@ -237,7 +238,7 @@ namespace Content.Server.Kitchen.EntitySystems ( comp.Busy, comp.BeakerContainer.ContainedEntity != null, - IoCManager.Resolve().TryGetComponent(comp.Owner, out ApcPowerReceiverComponent? receiver) && receiver.Powered, + EntityManager.TryGetComponent(comp.Owner, out ApcPowerReceiverComponent? receiver) && receiver.Powered, canJuice, canGrind, comp.Chamber.ContainedEntities.Select(item => item).ToArray(), @@ -251,25 +252,26 @@ namespace Content.Server.Kitchen.EntitySystems /// Tries to eject whatever is in the beaker slot. Puts the item in the user's hands or failing that on top /// of the grinder. /// - private void EjectBeaker(ReagentGrinderComponent component, EntityUid user) + private void EjectBeaker(ReagentGrinderComponent component, EntityUid? user) { if (component.BeakerContainer.ContainedEntity == null || component.HeldBeaker == null || component.Busy) return; - var beaker = component.BeakerContainer.ContainedEntity; - if (beaker is null) + if (component.BeakerContainer.ContainedEntity is not {Valid: true} beaker) return; component.BeakerContainer.Remove(beaker); - if (user == null || !IoCManager.Resolve().TryGetComponent(user, out var hands) || - !IoCManager.Resolve().TryGetComponent(beaker, out var item)) + if (user == null || + !EntityManager.TryGetComponent(user.Value, out var hands) || + !EntityManager.TryGetComponent(beaker, out var item)) return; + hands.PutInHandOrDrop(item); component.HeldBeaker = null; EnqueueUiUpdate(component); - if (IoCManager.Resolve().TryGetComponent(component.Owner, out AppearanceComponent? appearance)) + if (EntityManager.TryGetComponent(component.Owner, out AppearanceComponent? appearance)) { appearance.SetData(SharedReagentGrinderComponent.ReagentGrinderVisualState.BeakerAttached, component.BeakerContainer.ContainedEntity != null); @@ -284,7 +286,7 @@ namespace Content.Server.Kitchen.EntitySystems SharedReagentGrinderComponent.GrinderProgram program) { //Have power, are we busy, chamber has anything to grind, a beaker for the grounds to go? - if (!IoCManager.Resolve().TryGetComponent(component.Owner, out ApcPowerReceiverComponent? receiver) || !receiver.Powered || + if (!EntityManager.TryGetComponent(component.Owner, out ApcPowerReceiverComponent? receiver) || !receiver.Powered || component.Busy || component.Chamber.ContainedEntities.Count <= 0 || component.BeakerContainer.ContainedEntity == null || component.HeldBeaker == null) { @@ -306,7 +308,7 @@ namespace Content.Server.Kitchen.EntitySystems { foreach (var item in component.Chamber.ContainedEntities.ToList()) { - if (!IoCManager.Resolve().TryGetComponent(item, out ExtractableComponent? extract) + if (!EntityManager.TryGetComponent(item, out ExtractableComponent? extract) || extract.GrindableSolution == null || !_solutionsSystem.TryGetSolution(item, extract.GrindableSolution, out var solution)) continue; @@ -315,9 +317,9 @@ namespace Content.Server.Kitchen.EntitySystems if (component.HeldBeaker.CurrentVolume + solution.CurrentVolume * juiceEvent.Scalar > component.HeldBeaker.MaxVolume) continue; solution.ScaleSolution(juiceEvent.Scalar); - _solutionsSystem.TryAddSolution(beakerEntity, component.HeldBeaker, solution); - _solutionsSystem.RemoveAllSolution(beakerEntity, solution); - IoCManager.Resolve().DeleteEntity(item); + _solutionsSystem.TryAddSolution(beakerEntity.Value, component.HeldBeaker, solution); + _solutionsSystem.RemoveAllSolution(beakerEntity.Value, solution); + EntityManager.DeleteEntity(item); } component.Busy = false; @@ -332,14 +334,14 @@ namespace Content.Server.Kitchen.EntitySystems { foreach (var item in component.Chamber.ContainedEntities.ToList()) { - if (!IoCManager.Resolve().TryGetComponent(item, out var juiceMe) + if (!EntityManager.TryGetComponent(item, out var juiceMe) || juiceMe.JuiceSolution == null) { Logger.Warning("Couldn't find a juice solution on entityUid:{0}", item); continue; } var juiceEvent = new ExtractableScalingEvent(); // default of scalar is always 1.0 - if (IoCManager.Resolve().HasComponent(item)) + if (EntityManager.HasComponent(item)) { RaiseLocalEvent(item, juiceEvent); } @@ -348,8 +350,8 @@ namespace Content.Server.Kitchen.EntitySystems juiceMe.JuiceSolution.TotalVolume * juiceEvent.Scalar > component.HeldBeaker.MaxVolume) continue; juiceMe.JuiceSolution.ScaleSolution(juiceEvent.Scalar); - _solutionsSystem.TryAddSolution(beakerEntity, component.HeldBeaker, juiceMe.JuiceSolution); - IoCManager.Resolve().DeleteEntity(item); + _solutionsSystem.TryAddSolution(beakerEntity.Value, component.HeldBeaker, juiceMe.JuiceSolution); + EntityManager.DeleteEntity(item); } bui?.SendMessage(new SharedReagentGrinderComponent.ReagentGrinderWorkCompleteMessage()); diff --git a/Content.Server/Labels/Label/HandLabelerSystem.cs b/Content.Server/Labels/Label/HandLabelerSystem.cs index d5e9ac8a65..fdd3adb611 100644 --- a/Content.Server/Labels/Label/HandLabelerSystem.cs +++ b/Content.Server/Labels/Label/HandLabelerSystem.cs @@ -34,10 +34,10 @@ namespace Content.Server.Labels private void AfterInteractOn(EntityUid uid, HandLabelerComponent handLabeler, AfterInteractEvent args) { - if (args.Target == null || !handLabeler.Whitelist.IsValid(args.Target)) + if (args.Target is not {Valid: true} target || !handLabeler.Whitelist.IsValid(target)) return; - AddLabelTo(uid, handLabeler, args.Target, out string? result); + AddLabelTo(uid, handLabeler, target, out string? result); if (result != null) handLabeler.Owner.PopupMessage(args.User, result); } diff --git a/Content.Server/Labels/Label/LabelSystem.cs b/Content.Server/Labels/Label/LabelSystem.cs index d75e6d3bf7..d5eb619def 100644 --- a/Content.Server/Labels/Label/LabelSystem.cs +++ b/Content.Server/Labels/Label/LabelSystem.cs @@ -62,7 +62,7 @@ namespace Content.Server.Labels private void OnExamined(EntityUid uid, PaperLabelComponent comp, ExaminedEvent args) { - if (comp.LabelSlot.Item == null) + if (comp.LabelSlot.Item is not {Valid: true} item) return; if (!args.IsInDetailsRange) @@ -71,7 +71,7 @@ namespace Content.Server.Labels return; } - if (!EntityManager.TryGetComponent(comp.LabelSlot.Item, out PaperComponent paper)) + if (!EntityManager.TryGetComponent(item, out PaperComponent paper)) // Assuming yaml has the correct entity whitelist, this should not happen. return; diff --git a/Content.Server/Light/Components/HandheldLightComponent.cs b/Content.Server/Light/Components/HandheldLightComponent.cs index e46b95da19..aeffe30419 100644 --- a/Content.Server/Light/Components/HandheldLightComponent.cs +++ b/Content.Server/Light/Components/HandheldLightComponent.cs @@ -102,7 +102,7 @@ namespace Content.Server.Light.Components /// Illuminates the light if it is not active, extinguishes it if it is active. /// /// True if the light's status was toggled, false otherwise. - public bool ToggleStatus(EntityUiduser) + public bool ToggleStatus(EntityUid user) { if (!EntitySystem.Get().CanUse(user)) return false; return Activated ? TurnOff() : TurnOn(user); @@ -128,7 +128,7 @@ namespace Content.Server.Light.Components return true; } - public bool TurnOn(EntityUiduser) + public bool TurnOn(EntityUid user) { if (Activated) { diff --git a/Content.Server/Light/EntitySystems/MatchstickSystem.cs b/Content.Server/Light/EntitySystems/MatchstickSystem.cs index 6b974d14ed..3557453428 100644 --- a/Content.Server/Light/EntitySystems/MatchstickSystem.cs +++ b/Content.Server/Light/EntitySystems/MatchstickSystem.cs @@ -58,7 +58,7 @@ namespace Content.Server.Light.EntitySystems args.IsHot = component.CurrentState == SmokableState.Lit; } - public void Ignite(MatchstickComponent component, EntityUiduser) + public void Ignite(MatchstickComponent component, EntityUid user) { // Play Sound SoundSystem.Play( diff --git a/Content.Server/Light/EntitySystems/PoweredLightSystem.cs b/Content.Server/Light/EntitySystems/PoweredLightSystem.cs index 71bdfb210d..a443c9eca1 100644 --- a/Content.Server/Light/EntitySystems/PoweredLightSystem.cs +++ b/Content.Server/Light/EntitySystems/PoweredLightSystem.cs @@ -154,7 +154,7 @@ namespace Content.Server.Light.EntitySystems return false; // try to insert bulb in container - if (!light.LightBulbContainer.Insert(EntityManager.GetEntity(bulbUid))) + if (!light.LightBulbContainer.Insert(bulbUid)) return false; UpdateLight(uid, light); @@ -172,24 +172,22 @@ namespace Content.Server.Light.EntitySystems return null; // check if light has bulb - var bulbUid = GetBulb(uid, light); - if (bulbUid == null) + if (GetBulb(uid, light) is not {Valid: true} bulb) return null; // try to remove bulb from container - var bulbbulbUid.Value - if (!light.LightBulbContainer.Remove(bulbEnt)) + if (!light.LightBulbContainer.Remove(bulb)) return null; // try to place bulb in hands if (userUid != null) { if (EntityManager.TryGetComponent(userUid.Value, out SharedHandsComponent? hands)) - hands.TryPutInActiveHandOrAny(bulbEnt); + hands.TryPutInActiveHandOrAny(bulb); } UpdateLight(uid, light); - return bulbUid; + return bulb; } /// diff --git a/Content.Server/MachineLinking/Events/LinkAttemptEvent.cs b/Content.Server/MachineLinking/Events/LinkAttemptEvent.cs index 7adb0122b6..593311c613 100644 --- a/Content.Server/MachineLinking/Events/LinkAttemptEvent.cs +++ b/Content.Server/MachineLinking/Events/LinkAttemptEvent.cs @@ -5,7 +5,7 @@ namespace Content.Server.MachineLinking.Events { public class LinkAttemptEvent : CancellableEntityEventArgs { - public readonly EntityUid Attemptee, + public readonly EntityUid Attemptee; public readonly SignalTransmitterComponent TransmitterComponent; public readonly string TransmitterPort; public readonly SignalReceiverComponent ReceiverComponent; diff --git a/Content.Server/MachineLinking/System/SignalLinkerSystem.cs b/Content.Server/MachineLinking/System/SignalLinkerSystem.cs index 3f3f5bccb3..35a868db32 100644 --- a/Content.Server/MachineLinking/System/SignalLinkerSystem.cs +++ b/Content.Server/MachineLinking/System/SignalLinkerSystem.cs @@ -13,7 +13,6 @@ using Content.Shared.MachineLinking; using Content.Shared.Popups; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; -using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Utility; @@ -81,8 +80,8 @@ namespace Content.Server.MachineLinking.System { if (args.Handled) return; - if (!IoCManager.Resolve().TryGetComponent(args.Used, out var linker) || !linker.Port.HasValue || - !IoCManager.Resolve().TryGetComponent(args.User, out ActorComponent? actor) || + if (!EntityManager.TryGetComponent(args.Used, out var linker) || !linker.Port.HasValue || + !EntityManager.TryGetComponent(args.User, out ActorComponent? actor) || !linker.Port.Value.transmitter.Outputs.TryGetPort(linker.Port.Value.port, out var port)) { return; @@ -121,15 +120,15 @@ namespace Content.Server.MachineLinking.System { case SignalPortSelected portSelected: if (msg.Session.AttachedEntity == null || - !IoCManager.Resolve().TryGetComponent(msg.Session.AttachedEntity, out HandsComponent? hands) || + !EntityManager.TryGetComponent(msg.Session.AttachedEntity.Value, out HandsComponent? hands) || !hands.TryGetActiveHeldEntity(out var heldEntity) || - !IoCManager.Resolve().TryGetComponent(heldEntity, out SignalLinkerComponent? signalLinkerComponent) || - !_interaction.InRangeUnobstructed(msg.Session.AttachedEntity, component.Owner, ignoreInsideBlocker: true) || + !EntityManager.TryGetComponent(heldEntity, out SignalLinkerComponent? signalLinkerComponent) || + !_interaction.InRangeUnobstructed(msg.Session.AttachedEntity.Value, component.Owner, ignoreInsideBlocker: true) || !signalLinkerComponent.Port.HasValue || !signalLinkerComponent.Port.Value.transmitter.Outputs.ContainsPort(signalLinkerComponent.Port .Value.port) || !component.Inputs.ContainsPort(portSelected.Port)) return; - LinkerInteraction(msg.Session.AttachedEntity, signalLinkerComponent.Port.Value.transmitter, + LinkerInteraction(msg.Session.AttachedEntity.Value, signalLinkerComponent.Port.Value.transmitter, signalLinkerComponent.Port.Value.port, component, portSelected.Port); break; } @@ -161,12 +160,12 @@ namespace Content.Server.MachineLinking.System { case SignalPortSelected portSelected: if (msg.Session.AttachedEntity == null || - !IoCManager.Resolve().TryGetComponent(msg.Session.AttachedEntity, out HandsComponent? hands) || + !EntityManager.TryGetComponent(msg.Session.AttachedEntity.Value, out HandsComponent? hands) || !hands.TryGetActiveHeldEntity(out var heldEntity) || - !IoCManager.Resolve().TryGetComponent(heldEntity, out SignalLinkerComponent? signalLinkerComponent) || - !_interaction.InRangeUnobstructed(msg.Session.AttachedEntity, component.Owner, ignoreInsideBlocker: true)) + !EntityManager.TryGetComponent(heldEntity, out SignalLinkerComponent? signalLinkerComponent) || + !_interaction.InRangeUnobstructed(msg.Session.AttachedEntity.Value, component.Owner, ignoreInsideBlocker: true)) return; - LinkerSaveInteraction(msg.Session.AttachedEntity, signalLinkerComponent, component, + LinkerSaveInteraction(msg.Session.AttachedEntity.Value, signalLinkerComponent, component, portSelected.Port); break; } @@ -177,8 +176,8 @@ namespace Content.Server.MachineLinking.System { if (args.Handled) return; - if (!IoCManager.Resolve().TryGetComponent(args.Used, out var linker) || - !IoCManager.Resolve().TryGetComponent(args.User, out ActorComponent? actor)) + if (!EntityManager.TryGetComponent(args.Used, out var linker) || + !EntityManager.TryGetComponent(args.User, out ActorComponent? actor)) { return; } @@ -277,15 +276,15 @@ namespace Content.Server.MachineLinking.System private bool IsInRange(SignalTransmitterComponent transmitterComponent, SignalReceiverComponent receiverComponent) { - if (IoCManager.Resolve().TryGetComponent(transmitterComponent.Owner, out var transmitterPowerReceiverComponent) && - IoCManager.Resolve().TryGetComponent(receiverComponent.Owner, out var receiverPowerReceiverComponent) + if (EntityManager.TryGetComponent(transmitterComponent.Owner, out var transmitterPowerReceiverComponent) && + EntityManager.TryGetComponent(receiverComponent.Owner, out var receiverPowerReceiverComponent) ) //&& todo are they on the same powernet? { return true; } - return IoCManager.Resolve().GetComponent(transmitterComponent.Owner).MapPosition.InRange( - IoCManager.Resolve().GetComponent(receiverComponent.Owner).MapPosition, 30f); + return EntityManager.GetComponent(transmitterComponent.Owner).MapPosition.InRange( + EntityManager.GetComponent(receiverComponent.Owner).MapPosition, 30f); } } } diff --git a/Content.Server/MachineLinking/System/TriggerOnSignalReceivedSystem.cs b/Content.Server/MachineLinking/System/TriggerOnSignalReceivedSystem.cs index 6a117e05c3..de992a855f 100644 --- a/Content.Server/MachineLinking/System/TriggerOnSignalReceivedSystem.cs +++ b/Content.Server/MachineLinking/System/TriggerOnSignalReceivedSystem.cs @@ -19,7 +19,7 @@ namespace Content.Server.MachineLinking.System private void OnSignalReceived(EntityUid uid, TriggerOnSignalReceivedComponent component, SignalReceivedEvent args) { - _trigger.Trigger(uid) + _trigger.Trigger(uid); } } } diff --git a/Content.Server/Medical/Components/HealingComponent.cs b/Content.Server/Medical/Components/HealingComponent.cs index e4e132c417..12fd1d3cea 100644 --- a/Content.Server/Medical/Components/HealingComponent.cs +++ b/Content.Server/Medical/Components/HealingComponent.cs @@ -2,7 +2,6 @@ using System.Threading.Tasks; using Content.Server.Administration.Logs; using Content.Server.Stack; using Content.Shared.ActionBlocker; -using Content.Shared.Administration.Logs; using Content.Shared.Damage; using Content.Shared.Damage.Prototypes; using Content.Shared.Database; @@ -41,7 +40,7 @@ namespace Content.Server.Medical.Components return false; } - if (!IoCManager.Resolve().TryGetComponent(eventArgs.Target, out DamageableComponent? targetDamage)) + if (!IoCManager.Resolve().TryGetComponent(eventArgs.Target.Value, out DamageableComponent? targetDamage)) { return true; } @@ -66,7 +65,7 @@ namespace Content.Server.Medical.Components return true; } - var healed = EntitySystem.Get().TryChangeDamage(eventArgs.Target, Damage, true); + var healed = EntitySystem.Get().TryChangeDamage(eventArgs.Target.Value, Damage, true); if (healed == null) return true; diff --git a/Content.Server/Medical/Components/MedicalScannerComponent.cs b/Content.Server/Medical/Components/MedicalScannerComponent.cs index 861f6098ac..6a8c660f60 100644 --- a/Content.Server/Medical/Components/MedicalScannerComponent.cs +++ b/Content.Server/Medical/Components/MedicalScannerComponent.cs @@ -79,7 +79,7 @@ namespace Content.Server.Medical.Components return EmptyUIState; } - if (!IoCManager.Resolve().TryGetComponent(body, out DamageableComponent? damageable)) + if (!IoCManager.Resolve().TryGetComponent(body.Value, out DamageableComponent? damageable)) { return EmptyUIState; } @@ -90,7 +90,7 @@ namespace Content.Server.Medical.Components } var cloningSystem = EntitySystem.Get(); - var scanned = IoCManager.Resolve().TryGetComponent(_bodyContainer.ContainedEntity, out MindComponent? mindComponent) && + var scanned = IoCManager.Resolve().TryGetComponent(_bodyContainer.ContainedEntity.Value, out MindComponent? mindComponent) && mindComponent.Mind != null && cloningSystem.HasDnaScan(mindComponent.Mind); @@ -136,7 +136,7 @@ namespace Content.Server.Medical.Components if (body == null) return MedicalScannerStatus.Open; - var state = IoCManager.Resolve().GetComponentOrNull(body); + var state = IoCManager.Resolve().GetComponentOrNull(body.Value); return state == null ? MedicalScannerStatus.Open : GetStatusFromDamageState(state); } @@ -165,7 +165,7 @@ namespace Content.Server.Medical.Components UserInterface?.Open(actor.PlayerSession); } - public void InsertBody(EntityUiduser) + public void InsertBody(EntityUid user) { _bodyContainer.Insert(user); UpdateUserInterface(); @@ -174,12 +174,11 @@ namespace Content.Server.Medical.Components public void EjectBody() { - var containedEntity = _bodyContainer.ContainedEntity; - if (containedEntity == null) return; - _bodyContainer.Remove(containedEntity); + if (_bodyContainer.ContainedEntity is not {Valid: true} contained) return; + _bodyContainer.Remove(contained); UpdateUserInterface(); UpdateAppearance(); - EntitySystem.Get().ForciblySetClimbing(containedEntity); + EntitySystem.Get().ForciblySetClimbing(contained); } public void Update(float frameTime) @@ -199,7 +198,7 @@ namespace Content.Server.Medical.Components { var cloningSystem = EntitySystem.Get(); - if (!IoCManager.Resolve().TryGetComponent(_bodyContainer.ContainedEntity, out MindComponent? mindComp) || mindComp.Mind == null) + if (!IoCManager.Resolve().TryGetComponent(_bodyContainer.ContainedEntity.Value, out MindComponent? mindComp) || mindComp.Mind == null) { obj.Session.AttachedEntity?.PopupMessageCursor(Loc.GetString("medical-scanner-component-msg-no-soul")); break; diff --git a/Content.Server/Mind/Mind.cs b/Content.Server/Mind/Mind.cs index 4a156cdb62..09368d1d3f 100644 --- a/Content.Server/Mind/Mind.cs +++ b/Content.Server/Mind/Mind.cs @@ -67,7 +67,7 @@ namespace Content.Server.Mind [ViewVariables] public EntityUid VisitingEntity { get; private set; } - [ViewVariables] public EntityUid CurrentEntity => VisitingEntity.IsValid() ? VisitingEntity : OwnedEntity; + [ViewVariables] public EntityUid? CurrentEntity => VisitingEntity.IsValid() ? VisitingEntity : OwnedEntity; [ViewVariables(VVAccess.ReadWrite)] public string? CharacterName { get; set; } @@ -90,7 +90,7 @@ namespace Content.Server.Mind /// Can be null. /// [ViewVariables] - public EntityUid OwnedEntity => OwnedComponent?.Owner ?? default; + public EntityUid? OwnedEntity => OwnedComponent?.Owner; /// /// An enumerable over all the roles this mind has. @@ -155,7 +155,7 @@ namespace Content.Server.Mind // This can be null if they're deleted (spike / brain nom) if (OwnedEntity == default) return true; - var targetMobState = IoCManager.Resolve().GetComponentOrNull(OwnedEntity); + var targetMobState = IoCManager.Resolve().GetComponentOrNull(OwnedEntity.Value); // This can be null if it's a brain (this happens very often) // Brains are the result of gibbing so should definitely count as dead if (targetMobState == null) @@ -184,7 +184,10 @@ namespace Content.Server.Mind role.Greet(); var message = new RoleAddedEvent(role); - IoCManager.Resolve().EventBus.RaiseLocalEvent(OwnedEntity, message); + if (OwnedEntity != default) + { + IoCManager.Resolve().EventBus.RaiseLocalEvent(OwnedEntity.Value, message); + } return role; } @@ -206,7 +209,11 @@ namespace Content.Server.Mind _roles.Remove(role); var message = new RoleRemovedEvent(role); - IoCManager.Resolve().EventBus.RaiseLocalEvent(OwnedEntity, message); + + if (OwnedEntity != default) + { + IoCManager.Resolve().EventBus.RaiseLocalEvent(OwnedEntity.Value, message); + } } public bool HasRole() where T : Role diff --git a/Content.Server/Morgue/Components/CrematoriumEntityStorageComponent.cs b/Content.Server/Morgue/Components/CrematoriumEntityStorageComponent.cs index d386d1ea28..1cb455bff7 100644 --- a/Content.Server/Morgue/Components/CrematoriumEntityStorageComponent.cs +++ b/Content.Server/Morgue/Components/CrematoriumEntityStorageComponent.cs @@ -32,6 +32,8 @@ namespace Content.Server.Morgue.Components public class CrematoriumEntityStorageComponent : MorgueEntityStorageComponent, IExamine, ISuicideAct #pragma warning restore 618 { + [Dependency] private readonly IEntityManager _entities = default!; + public override string Name => "CrematoriumEntityStorage"; [DataField("cremateStartSound")] private SoundSpecifier _cremateStartSound = new SoundPathSpecifier("/Audio/Items/lighter1.ogg"); @@ -104,7 +106,7 @@ namespace Content.Server.Morgue.Components _cremateCancelToken = new CancellationTokenSource(); Owner.SpawnTimer(_burnMilis, () => { - if ((!IoCManager.Resolve().EntityExists(Owner) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(Owner).EntityLifeStage) >= EntityLifeStage.Deleted) + if ((!_entities.EntityExists(Owner) ? EntityLifeStage.Deleted : _entities.GetComponent(Owner).EntityLifeStage) >= EntityLifeStage.Deleted) return; Appearance?.SetData(CrematoriumVisuals.Burning, false); @@ -116,10 +118,10 @@ namespace Content.Server.Morgue.Components { var item = Contents.ContainedEntities[i]; Contents.Remove(item); - IoCManager.Resolve().DeleteEntity(item); + _entities.DeleteEntity(item); } - var ash = IoCManager.Resolve().SpawnEntity("Ash", IoCManager.Resolve().GetComponent(Owner).Coordinates); + var ash = _entities.SpawnEntity("Ash", _entities.GetComponent(Owner).Coordinates); Contents.Insert(ash); } @@ -132,13 +134,13 @@ namespace Content.Server.Morgue.Components SuicideKind ISuicideAct.Suicide(EntityUid victim, IChatManager chat) { - if (IoCManager.Resolve().TryGetComponent(victim, out ActorComponent? actor) && actor.PlayerSession.ContentData()?.Mind is {} mind) + if (_entities.TryGetComponent(victim, out ActorComponent? actor) && actor.PlayerSession.ContentData()?.Mind is {} mind) { EntitySystem.Get().OnGhostAttempt(mind, false); - if (mind.OwnedEntity.Valid) + if (mind.OwnedEntity is {Valid: true} entity) { - mind.OwnedEntity.PopupMessage(Loc.GetString("crematorium-entity-storage-component-suicide-message")); + entity.PopupMessage(Loc.GetString("crematorium-entity-storage-component-suicide-message")); } } @@ -151,7 +153,7 @@ namespace Content.Server.Morgue.Components } else { - IoCManager.Resolve().DeleteEntity(victim); + _entities.DeleteEntity(victim); } Cremate(); diff --git a/Content.Server/Nutrition/Hungry.cs b/Content.Server/Nutrition/Hungry.cs index 80ec6d604c..e36505a9f9 100644 --- a/Content.Server/Nutrition/Hungry.cs +++ b/Content.Server/Nutrition/Hungry.cs @@ -12,6 +12,8 @@ namespace Content.Server.Nutrition [AdminCommand(AdminFlags.Debug)] public class Hungry : IConsoleCommand { + [Dependency] private readonly IEntityManager _entities = default!; + public string Command => "hungry"; public string Description => "Makes you hungry."; public string Help => $"{Command}"; @@ -25,13 +27,13 @@ namespace Content.Server.Nutrition return; } - if (player.AttachedEntity == null) + if (player.AttachedEntity is not {Valid: true} playerEntity) { shell.WriteLine("You cannot use this command without an entity."); return; } - if (!IoCManager.Resolve().TryGetComponent(player.AttachedEntity, out HungerComponent? hunger)) + if (!_entities.TryGetComponent(playerEntity, out HungerComponent? hunger)) { shell.WriteLine($"Your entity does not have a {nameof(HungerComponent)} component."); return; diff --git a/Content.Server/Objectives/Conditions/KillPersonCondition.cs b/Content.Server/Objectives/Conditions/KillPersonCondition.cs index 83e8bc8563..5fe620a2d5 100644 --- a/Content.Server/Objectives/Conditions/KillPersonCondition.cs +++ b/Content.Server/Objectives/Conditions/KillPersonCondition.cs @@ -20,10 +20,10 @@ namespace Content.Server.Objectives.Conditions if (Target == null) return Loc.GetString("objective-condition-kill-person-title", ("targetName", targetName)); - if(Target.CharacterName != null) + if (Target.CharacterName != null) targetName = Target.CharacterName; - else if (Target.OwnedEntity != null) - targetName = IoCManager.Resolve().GetComponent(Target.OwnedEntity).EntityName; + else if (Target.OwnedEntity is {Valid: true} owned) + targetName = IoCManager.Resolve().GetComponent(owned).EntityName; return Loc.GetString("objective-condition-kill-person-title", ("targetName", targetName)); } diff --git a/Content.Server/Objectives/Conditions/StealCondition.cs b/Content.Server/Objectives/Conditions/StealCondition.cs index d16df78333..e4190f96a5 100644 --- a/Content.Server/Objectives/Conditions/StealCondition.cs +++ b/Content.Server/Objectives/Conditions/StealCondition.cs @@ -57,8 +57,8 @@ namespace Content.Server.Objectives.Conditions { get { - if (_mind?.OwnedEntity == null) return 0f; - if (!IoCManager.Resolve().TryGetComponent(_mind.OwnedEntity, out var containerManagerComponent)) return 0f; + if (_mind?.OwnedEntity is not {Valid: true} owned) return 0f; + if (!IoCManager.Resolve().TryGetComponent(owned, out var containerManagerComponent)) return 0f; float count = containerManagerComponent.CountPrototypeOccurencesRecursive(_prototypeId); return count/_amount; diff --git a/Content.Server/PDA/PDASystem.cs b/Content.Server/PDA/PDASystem.cs index a0bcebb971..05df412da7 100644 --- a/Content.Server/PDA/PDASystem.cs +++ b/Content.Server/PDA/PDASystem.cs @@ -110,7 +110,7 @@ namespace Content.Server.PDA UpdatePDAUserInterface(pda); } - private bool OpenUI(PDAComponent pda, EntityUiduser) + private bool OpenUI(PDAComponent pda, EntityUid user) { if (!IoCManager.Resolve().TryGetComponent(user, out ActorComponent? actor)) return false; @@ -145,7 +145,7 @@ namespace Content.Server.PDA private void OnUIMessage(PDAComponent pda, ServerBoundUserInterfaceMessage msg) { // cast EntityUid? to EntityUid - if (msg.Session.AttachedEntity is not EntityUid playerUid) + if (msg.Session.AttachedEntity is not { } playerUid) return; switch (msg.Message) diff --git a/Content.Server/ParticleAccelerator/Components/ParticleAcceleratorControlBoxComponent.cs b/Content.Server/ParticleAccelerator/Components/ParticleAcceleratorControlBoxComponent.cs index c1f7aac15f..b168c4d2d7 100644 --- a/Content.Server/ParticleAccelerator/Components/ParticleAcceleratorControlBoxComponent.cs +++ b/Content.Server/ParticleAccelerator/Components/ParticleAcceleratorControlBoxComponent.cs @@ -152,8 +152,8 @@ namespace Content.Server.ParticleAccelerator.Components } - if (!obj.Session.AttachedEntity.Valid || - !EntitySystem.Get().CanInteract(obj.Session.AttachedEntity)) + if (obj.Session.AttachedEntity is not {Valid: true} attached || + !EntitySystem.Get().CanInteract(attached)) { return; } diff --git a/Content.Server/Physics/Controllers/PullController.cs b/Content.Server/Physics/Controllers/PullController.cs index c381f491c4..3625850847 100644 --- a/Content.Server/Physics/Controllers/PullController.cs +++ b/Content.Server/Physics/Controllers/PullController.cs @@ -2,11 +2,9 @@ using System.Collections.Generic; using Content.Shared.Pulling; using Robust.Shared.GameObjects; -using Robust.Shared.IoC; +using Robust.Shared.Maths; using Robust.Shared.Physics; using Robust.Shared.Physics.Controllers; -using Robust.Shared.Maths; -using Robust.Shared.Utility; namespace Content.Server.Physics.Controllers { @@ -66,32 +64,31 @@ namespace Content.Server.Physics.Controllers continue; } - var puller = pullable.Puller; - if (puller == null) + if (pullable.Puller is not {Valid: true} puller) { continue; } // Now that's over with... - var pullerPosition = IoCManager.Resolve().GetComponent(puller).MapPosition; - var movingTo = pullable.MovingTo.Value.ToMap(IoCManager.Resolve()); + var pullerPosition = EntityManager.GetComponent(puller).MapPosition; + var movingTo = pullable.MovingTo.Value.ToMap(EntityManager); if (movingTo.MapId != pullerPosition.MapId) { _pullableSystem.StopMoveTo(pullable); continue; } - if (!IoCManager.Resolve().TryGetComponent(pullable.Owner, out var physics) || + if (!EntityManager.TryGetComponent(pullable.Owner, out var physics) || physics.BodyType == BodyType.Static || - movingTo.MapId != IoCManager.Resolve().GetComponent(pullable.Owner).MapID) + movingTo.MapId != EntityManager.GetComponent(pullable.Owner).MapID) { _pullableSystem.StopMoveTo(pullable); continue; } var movingPosition = movingTo.Position; - var ownerPosition = IoCManager.Resolve().GetComponent(pullable.Owner).MapPosition.Position; + var ownerPosition = EntityManager.GetComponent(pullable.Owner).MapPosition.Position; var diff = movingPosition - ownerPosition; var diffLength = diff.Length; @@ -119,7 +116,7 @@ namespace Content.Server.Physics.Controllers var impulse = accel * physics.Mass * frameTime; physics.ApplyLinearImpulse(impulse); - if (IoCManager.Resolve().TryGetComponent(puller, out var pullerPhysics)) + if (EntityManager.TryGetComponent(puller, out var pullerPhysics)) { pullerPhysics.WakeBody(); pullerPhysics.ApplyLinearImpulse(-impulse); diff --git a/Content.Server/PneumaticCannon/PneumaticCannonSystem.cs b/Content.Server/PneumaticCannon/PneumaticCannonSystem.cs index f5775d2b74..0e2f6762a6 100644 --- a/Content.Server/PneumaticCannon/PneumaticCannonSystem.cs +++ b/Content.Server/PneumaticCannon/PneumaticCannonSystem.cs @@ -305,7 +305,7 @@ namespace Content.Server.PneumaticCannon args.Verbs.Add(ejectItems); } - public void TryRemoveGasTank(PneumaticCannonComponent component, EntityUiduser) + public void TryRemoveGasTank(PneumaticCannonComponent component, EntityUid user) { if (component.GasTankSlot.ContainedEntity == null) { @@ -328,7 +328,7 @@ namespace Content.Server.PneumaticCannon } } - public void TryEjectAllItems(PneumaticCannonComponent component, EntityUiduser) + public void TryEjectAllItems(PneumaticCannonComponent component, EntityUid user) { if (IoCManager.Resolve().TryGetComponent(component.Owner, out var storage)) { diff --git a/Content.Server/Power/Components/BaseCharger.cs b/Content.Server/Power/Components/BaseCharger.cs index 5486d5f920..a657da4ce3 100644 --- a/Content.Server/Power/Components/BaseCharger.cs +++ b/Content.Server/Power/Components/BaseCharger.cs @@ -88,7 +88,7 @@ namespace Content.Server.Power.Components /// This will remove the item directly into the user's hand / floor /// /// - public void RemoveItem(EntityUiduser) + public void RemoveItem(EntityUid user) { var heldItem = Container.ContainedEntity; if (heldItem == null) diff --git a/Content.Server/Radio/Components/HandheldRadioComponent.cs b/Content.Server/Radio/Components/HandheldRadioComponent.cs index c55da536b2..df8e354ffb 100644 --- a/Content.Server/Radio/Components/HandheldRadioComponent.cs +++ b/Content.Server/Radio/Components/HandheldRadioComponent.cs @@ -63,7 +63,7 @@ namespace Content.Server.Radio.Components _chatManager.EntitySay(Owner, message); } - public bool Use(EntityUiduser) + public bool Use(EntityUid user) { RadioOn = !RadioOn; diff --git a/Content.Server/Radio/Components/IListen.cs b/Content.Server/Radio/Components/IListen.cs index 8bb6fba7f3..f5cbe090f5 100644 --- a/Content.Server/Radio/Components/IListen.cs +++ b/Content.Server/Radio/Components/IListen.cs @@ -10,8 +10,8 @@ namespace Content.Server.Radio.Components { int ListenRange { get; } - bool CanListen(string message, EntityUidsource); + bool CanListen(string message, EntityUid source); - void Listen(string message, EntityUidspeaker); + void Listen(string message, EntityUid speaker); } } diff --git a/Content.Server/Radio/Components/IRadio.cs b/Content.Server/Radio/Components/IRadio.cs index 5e9f2becdd..85897fa566 100644 --- a/Content.Server/Radio/Components/IRadio.cs +++ b/Content.Server/Radio/Components/IRadio.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Robust.Shared.GameObjects; namespace Content.Server.Radio.Components { @@ -6,8 +7,8 @@ namespace Content.Server.Radio.Components { IReadOnlyList Channels { get; } - void Receive(string message, int channel, EntityUidspeaker); + void Receive(string message, int channel, EntityUid speaker); - void Broadcast(string message, EntityUidspeaker); + void Broadcast(string message, EntityUid speaker); } } diff --git a/Content.Server/Rotatable/RotatableSystem.cs b/Content.Server/Rotatable/RotatableSystem.cs index d1f8019b82..d60b844f17 100644 --- a/Content.Server/Rotatable/RotatableSystem.cs +++ b/Content.Server/Rotatable/RotatableSystem.cs @@ -74,7 +74,7 @@ namespace Content.Server.Rotatable /// /// Replace a flippable entity with it's flipped / mirror-symmetric entity. /// - public static void TryFlip(FlippableComponent component, EntityUiduser) + public static void TryFlip(FlippableComponent component, EntityUid user) { if (IoCManager.Resolve().TryGetComponent(component.Owner, out IPhysBody? physics) && physics.BodyType == BodyType.Static) diff --git a/Content.Server/Storage/Components/SecretStashComponent.cs b/Content.Server/Storage/Components/SecretStashComponent.cs index 30a98e34ee..5521d7d402 100644 --- a/Content.Server/Storage/Components/SecretStashComponent.cs +++ b/Content.Server/Storage/Components/SecretStashComponent.cs @@ -18,6 +18,8 @@ namespace Content.Server.Storage.Components [RegisterComponent] public class SecretStashComponent : Component, IDestroyAct { + [Dependency] private readonly IEntityManager _entities = default!; + public override string Name => "SecretStash"; [ViewVariables] [DataField("maxItemSize")] @@ -76,22 +78,22 @@ namespace Content.Server.Storage.Components /// /// /// True if user recieved item - public bool TryGetItem(EntityUiduser) + public bool TryGetItem(EntityUid user) { - if (_itemContainer.ContainedEntity == null) + if (_itemContainer.ContainedEntity is not {Valid: true} contained) return false; Owner.PopupMessage(user, Loc.GetString("comp-secret-stash-action-get-item-found-something", ("stash", SecretPartName))); if (IoCManager.Resolve().TryGetComponent(user, out HandsComponent? hands)) { - if (!IoCManager.Resolve().TryGetComponent(_itemContainer.ContainedEntity, out ItemComponent? item)) + if (!IoCManager.Resolve().TryGetComponent(contained, out ItemComponent? item)) return false; hands.PutInHandOrDrop(item); } - else if (_itemContainer.Remove(_itemContainer.ContainedEntity)) + else if (_itemContainer.Remove(contained)) { - IoCManager.Resolve().GetComponent(_itemContainer.ContainedEntity).Coordinates = IoCManager.Resolve().GetComponent(Owner).Coordinates; + IoCManager.Resolve().GetComponent(contained).Coordinates = IoCManager.Resolve().GetComponent(Owner).Coordinates; } return true; @@ -109,9 +111,9 @@ namespace Content.Server.Storage.Components public void OnDestroy(DestructionEventArgs eventArgs) { // drop item inside - if (_itemContainer.ContainedEntity != null) + if (_itemContainer.ContainedEntity is {Valid: true} contained) { - IoCManager.Resolve().GetComponent(_itemContainer.ContainedEntity).Coordinates = IoCManager.Resolve().GetComponent(Owner).Coordinates; + _entities.GetComponent(contained).Coordinates = _entities.GetComponent(Owner).Coordinates; } } } diff --git a/Content.Server/Storage/Components/ServerStorageComponent.cs b/Content.Server/Storage/Components/ServerStorageComponent.cs index a880527ac2..f2286998db 100644 --- a/Content.Server/Storage/Components/ServerStorageComponent.cs +++ b/Content.Server/Storage/Components/ServerStorageComponent.cs @@ -452,9 +452,7 @@ namespace Content.Server.Storage.Components { EnsureInitialCalculated(); - var player = session.AttachedEntity; - - if (!player.Valid) + if (session.AttachedEntity is not {Valid: true} player) { break; } @@ -491,9 +489,7 @@ namespace Content.Server.Storage.Components { EnsureInitialCalculated(); - var player = session.AttachedEntity; - - if (player == null) + if (session.AttachedEntity is not {Valid: true} player) { break; } @@ -570,7 +566,7 @@ namespace Content.Server.Storage.Components // Pick up all entities in a radius around the clicked location. // The last half of the if is because carpets exist and this is terrible - if (_areaInsert && (eventArgs.Target == null || !_entityManager.HasComponent(eventArgs.Target))) + if (_areaInsert && (eventArgs.Target == null || !_entityManager.HasComponent(eventArgs.Target.Value))) { var validStorables = new List(); foreach (var entity in IoCManager.Resolve().GetEntitiesInRange(eventArgs.ClickLocation, _areaInsertRadius, LookupFlags.None)) diff --git a/Content.Server/Storage/EntitySystems/StorageSystem.cs b/Content.Server/Storage/EntitySystems/StorageSystem.cs index a881ded3b1..e89668278a 100644 --- a/Content.Server/Storage/EntitySystems/StorageSystem.cs +++ b/Content.Server/Storage/EntitySystems/StorageSystem.cs @@ -151,13 +151,13 @@ namespace Content.Server.Storage.EntitySystems var attachedEntity = session.AttachedEntity; // The component manages the set of sessions, so this invalid session should be removed soon. - if (attachedEntity == null || !IoCManager.Resolve().EntityExists(attachedEntity)) + if (attachedEntity == null || !IoCManager.Resolve().EntityExists(attachedEntity.Value)) continue; - if (storageMap != IoCManager.Resolve().GetComponent(attachedEntity).MapID) + if (storageMap != IoCManager.Resolve().GetComponent(attachedEntity.Value).MapID) continue; - var distanceSquared = (storagePos - IoCManager.Resolve().GetComponent(attachedEntity).WorldPosition).LengthSquared; + var distanceSquared = (storagePos - IoCManager.Resolve().GetComponent(attachedEntity.Value).WorldPosition).LengthSquared; if (distanceSquared > InteractionSystem.InteractionRangeSquared) { storageComp.UnsubscribeSession(session); diff --git a/Content.Server/Strip/StrippableComponent.cs b/Content.Server/Strip/StrippableComponent.cs index 47e7ce68d4..2222f83238 100644 --- a/Content.Server/Strip/StrippableComponent.cs +++ b/Content.Server/Strip/StrippableComponent.cs @@ -25,6 +25,8 @@ namespace Content.Server.Strip [ComponentReference(typeof(SharedStrippableComponent))] public sealed class StrippableComponent : SharedStrippableComponent { + [Dependency] private readonly IEntityManager _entities = default!; + public const float StripDelay = 2f; // TODO: This component needs localization. @@ -45,17 +47,17 @@ namespace Content.Server.Strip Owner.EnsureComponentWarn(); Owner.EnsureComponentWarn(); - if (IoCManager.Resolve().TryGetComponent(Owner, out CuffableComponent? cuffed)) + if (_entities.TryGetComponent(Owner, out CuffableComponent? cuffed)) { cuffed.OnCuffedStateChanged += UpdateSubscribed; } - if (IoCManager.Resolve().TryGetComponent(Owner, out InventoryComponent? inventory)) + if (_entities.TryGetComponent(Owner, out InventoryComponent? inventory)) { inventory.OnItemChanged += UpdateSubscribed; } - if (IoCManager.Resolve().TryGetComponent(Owner, out HandsComponent? hands)) + if (_entities.TryGetComponent(Owner, out HandsComponent? hands)) { hands.OnItemChanged += UpdateSubscribed; } @@ -80,7 +82,7 @@ namespace Content.Server.Strip public override bool Drop(DragDropEvent args) { - if (!IoCManager.Resolve().TryGetComponent(args.User, out ActorComponent? actor)) return false; + if (!_entities.TryGetComponent(args.User, out ActorComponent? actor)) return false; OpenUserInterface(actor.PlayerSession); return true; @@ -90,14 +92,15 @@ namespace Content.Server.Strip { var dictionary = new Dictionary(); - if (!IoCManager.Resolve().TryGetComponent(Owner, out CuffableComponent? cuffed)) + if (!_entities.TryGetComponent(Owner, out CuffableComponent? cuffed)) { return dictionary; } - foreach (EntityUid entity in cuffed.StoredEntities) + foreach (var entity in cuffed.StoredEntities) { - dictionary.Add(entity, entity.Name); + var name = _entities.GetComponent(entity).EntityName; + dictionary.Add(entity, name); } return dictionary; @@ -107,7 +110,7 @@ namespace Content.Server.Strip { var dictionary = new Dictionary(); - if (!IoCManager.Resolve().TryGetComponent(Owner, out InventoryComponent? inventory)) + if (!_entities.TryGetComponent(Owner, out InventoryComponent? inventory)) { return dictionary; } @@ -117,7 +120,7 @@ namespace Content.Server.Strip var name = "None"; if (inventory.GetSlotItem(slot) is { } item) - name = item.Owner.Name; + name = _entities.GetComponent(item.Owner).EntityName; dictionary[slot] = name; } @@ -129,7 +132,7 @@ namespace Content.Server.Strip { var dictionary = new Dictionary(); - if (!IoCManager.Resolve().TryGetComponent(Owner, out HandsComponent? hands)) + if (!_entities.TryGetComponent(Owner, out HandsComponent? hands)) { return dictionary; } @@ -138,13 +141,13 @@ namespace Content.Server.Strip { var owner = hands.GetItem(hand)?.Owner; - if ((owner != null ? IoCManager.Resolve().HasComponent(owner) : (bool?) null) ?? true) + if (!owner.HasValue || _entities.HasComponent(owner.Value)) { dictionary[hand] = "None"; continue; } - dictionary[hand] = owner.Name; + dictionary[hand] = _entities.GetComponent(owner.Value).EntityName; } return dictionary; @@ -160,8 +163,8 @@ namespace Content.Server.Strip /// private async void PlaceActiveHandItemInInventory(EntityUid user, Slots slot) { - var inventory = IoCManager.Resolve().GetComponent(Owner); - var userHands = IoCManager.Resolve().GetComponent(user); + var inventory = _entities.GetComponent(Owner); + var userHands = _entities.GetComponent(user); var item = userHands.GetActiveHand; bool Check() @@ -225,8 +228,8 @@ namespace Content.Server.Strip /// private async void PlaceActiveHandItemInHands(EntityUid user, string hand) { - var hands = IoCManager.Resolve().GetComponent(Owner); - var userHands = IoCManager.Resolve().GetComponent(user); + var hands = _entities.GetComponent(Owner); + var userHands = _entities.GetComponent(user); var item = userHands.GetActiveHand; bool Check() @@ -291,8 +294,8 @@ namespace Content.Server.Strip /// private async void TakeItemFromInventory(EntityUid user, Slots slot) { - var inventory = IoCManager.Resolve().GetComponent(Owner); - var userHands = IoCManager.Resolve().GetComponent(user); + var inventory = _entities.GetComponent(Owner); + var userHands = _entities.GetComponent(user); bool Check() { @@ -347,8 +350,8 @@ namespace Content.Server.Strip /// private async void TakeItemFromHands(EntityUid user, string hand) { - var hands = IoCManager.Resolve().GetComponent(Owner); - var userHands = IoCManager.Resolve().GetComponent(user); + var hands = _entities.GetComponent(Owner); + var userHands = _entities.GetComponent(user); bool Check() { @@ -364,7 +367,7 @@ namespace Content.Server.Strip return false; } - if (IoCManager.Resolve().HasComponent(heldItem.Owner)) + if (_entities.HasComponent(heldItem.Owner)) return false; if (!hands.CanDrop(hand, false)) @@ -398,8 +401,9 @@ namespace Content.Server.Strip private void HandleUserInterfaceMessage(ServerBoundUserInterfaceMessage obj) { - var user = obj.Session.AttachedEntity; - if (user == null || !IoCManager.Resolve().TryGetComponent(user, out HandsComponent? userHands)) return; + if (obj.Session.AttachedEntity is not {Valid: true} user || + !_entities.TryGetComponent(user, out HandsComponent? userHands)) + return; var placingItem = userHands.GetActiveHand != null; @@ -407,7 +411,7 @@ namespace Content.Server.Strip { case StrippingInventoryButtonPressed inventoryMessage: - if (IoCManager.Resolve().TryGetComponent(Owner, out var inventory)) + if (_entities.TryGetComponent(Owner, out var inventory)) { if (inventory.TryGetSlotItem(inventoryMessage.Slot, out ItemComponent? _)) placingItem = false; @@ -421,7 +425,7 @@ namespace Content.Server.Strip case StrippingHandButtonPressed handMessage: - if (IoCManager.Resolve().TryGetComponent(Owner, out var hands)) + if (_entities.TryGetComponent(Owner, out var hands)) { if (hands.TryGetItem(handMessage.Hand, out _)) placingItem = false; @@ -435,7 +439,7 @@ namespace Content.Server.Strip case StrippingHandcuffButtonPressed handcuffMessage: - if (IoCManager.Resolve().TryGetComponent(Owner, out var cuffed)) + if (_entities.TryGetComponent(Owner, out var cuffed)) { foreach (var entity in cuffed.StoredEntities) { diff --git a/Content.Server/Stunnable/StunbatonSystem.cs b/Content.Server/Stunnable/StunbatonSystem.cs index dfda1a94f3..1225c293e5 100644 --- a/Content.Server/Stunnable/StunbatonSystem.cs +++ b/Content.Server/Stunnable/StunbatonSystem.cs @@ -10,6 +10,7 @@ using Content.Shared.Audio; using Content.Shared.Examine; using Content.Shared.Interaction; using Content.Shared.Jittering; +using Content.Shared.Popups; using Content.Shared.StatusEffect; using Content.Shared.Stunnable; using Content.Shared.Throwing; @@ -167,7 +168,7 @@ namespace Content.Server.Stunnable comp.Activated = false; } - private void TurnOn(StunbatonComponent comp, EntityUiduser) + private void TurnOn(StunbatonComponent comp, EntityUid user) { if (comp.Activated) { diff --git a/Content.Server/Traitor/Uplink/UplinkSystem.cs b/Content.Server/Traitor/Uplink/UplinkSystem.cs index cdbbfcad77..a8f3405c0f 100644 --- a/Content.Server/Traitor/Uplink/UplinkSystem.cs +++ b/Content.Server/Traitor/Uplink/UplinkSystem.cs @@ -205,7 +205,7 @@ namespace Content.Server.Traitor.Uplink return true; } - private EntityUid FindUplinkTarget(EntityUiduser) + private EntityUid FindUplinkTarget(EntityUid user) { // Try to find PDA in inventory if (IoCManager.Resolve().TryGetComponent(user, out InventoryComponent? inventory)) diff --git a/Content.Server/UserInterface/ActivatableUISystem.cs b/Content.Server/UserInterface/ActivatableUISystem.cs index 504986ba35..4e94b78b30 100644 --- a/Content.Server/UserInterface/ActivatableUISystem.cs +++ b/Content.Server/UserInterface/ActivatableUISystem.cs @@ -133,7 +133,7 @@ namespace Content.Server.UserInterface public class ActivatableUIOpenAttemptEvent : CancellableEntityEventArgs { - public EntityUidUser { get; } + public EntityUid user { get; } public ActivatableUIOpenAttemptEvent(EntityUidwho) { User = who; diff --git a/Content.Server/Weapon/Melee/MeleeWeaponSystem.cs b/Content.Server/Weapon/Melee/MeleeWeaponSystem.cs index 1cf192c5e9..839ca470f0 100644 --- a/Content.Server/Weapon/Melee/MeleeWeaponSystem.cs +++ b/Content.Server/Weapon/Melee/MeleeWeaponSystem.cs @@ -208,18 +208,18 @@ namespace Content.Server.Weapon.Melee return; } - if (!args.Target.Valid) + if (!args.Target.HasValue) return; var location = IoCManager.Resolve().GetComponent(args.User).Coordinates; var diff = args.ClickLocation.ToMapPos(IoCManager.Resolve()) - location.ToMapPos(IoCManager.Resolve()); var angle = Angle.FromWorldVec(diff); - var hitEvent = new MeleeInteractEvent(args.Target, args.User); + var hitEvent = new MeleeInteractEvent(args.Target.Value, args.User); RaiseLocalEvent(owner, hitEvent, false); if (!hitEvent.CanInteract) return; - SendAnimation(comp.ClickArc, angle, args.User, owner, new List() { args.Target }, comp.ClickAttackEffect, false); + SendAnimation(comp.ClickArc, angle, args.User, owner, new List() { args.Target.Value }, comp.ClickAttackEffect, false); comp.LastAttackTime = curTime; comp.CooldownEnd = comp.LastAttackTime + TimeSpan.FromSeconds(comp.CooldownTime); diff --git a/Content.Server/Weapon/Ranged/Ammunition/Components/AmmoBoxComponent.cs b/Content.Server/Weapon/Ranged/Ammunition/Components/AmmoBoxComponent.cs index 3bb0b83d4e..080f2acd58 100644 --- a/Content.Server/Weapon/Ranged/Ammunition/Components/AmmoBoxComponent.cs +++ b/Content.Server/Weapon/Ranged/Ammunition/Components/AmmoBoxComponent.cs @@ -22,6 +22,8 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components public sealed class AmmoBoxComponent : Component, IInteractUsing, IUse, IInteractHand, IMapInit, IExamine #pragma warning restore 618 { + [Dependency] private readonly IEntityManager _entities = default!; + public override string Name => "AmmoBox"; [DataField("caliber")] @@ -73,7 +75,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components private void UpdateAppearance() { - if (IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearanceComponent)) + if (_entities.TryGetComponent(Owner, out AppearanceComponent? appearanceComponent)) { appearanceComponent.SetData(MagazineBarrelVisuals.MagLoaded, true); appearanceComponent.SetData(AmmoVisuals.AmmoCount, AmmoLeft); @@ -81,7 +83,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components } } - public EntityUid TakeAmmo() + public EntityUid? TakeAmmo() { if (_spawnedAmmo.TryPop(out var ammo)) { @@ -91,10 +93,10 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components if (_unspawnedCount > 0) { - ammo = IoCManager.Resolve().SpawnEntity(_fillPrototype, IoCManager.Resolve().GetComponent(Owner).Coordinates); + ammo = _entities.SpawnEntity(_fillPrototype, _entities.GetComponent(Owner).Coordinates); // when dumping from held ammo box, this detaches the spawned ammo from the player. - IoCManager.Resolve().GetComponent(ammo).AttachParentToContainerOrGrid(); + _entities.GetComponent(ammo).AttachParentToContainerOrGrid(); _unspawnedCount--; } @@ -104,7 +106,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components public bool TryInsertAmmo(EntityUid user, EntityUid entity) { - if (!IoCManager.Resolve().TryGetComponent(entity, out AmmoComponent? ammoComponent)) + if (!_entities.TryGetComponent(entity, out AmmoComponent? ammoComponent)) { return false; } @@ -129,12 +131,12 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components async Task IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs) { - if (IoCManager.Resolve().HasComponent(eventArgs.Using)) + if (_entities.HasComponent(eventArgs.Using)) { return TryInsertAmmo(eventArgs.User, eventArgs.Using); } - if (IoCManager.Resolve().TryGetComponent(eventArgs.Using, out RangedMagazineComponent? rangedMagazine)) + if (_entities.TryGetComponent(eventArgs.Using, out RangedMagazineComponent? rangedMagazine)) { for (var i = 0; i < Math.Max(10, rangedMagazine.ShotsLeft); i++) { @@ -158,21 +160,19 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components return false; } - private bool TryUse(EntityUiduser) + private bool TryUse(EntityUid user) { - if (!IoCManager.Resolve().TryGetComponent(user, out HandsComponent? handsComponent)) + if (!_entities.TryGetComponent(user, out HandsComponent? handsComponent)) { return false; } - var ammo = TakeAmmo(); - - if (ammo == null) + if (TakeAmmo() is not { } ammo) { return false; } - if (IoCManager.Resolve().TryGetComponent(ammo, out ItemComponent? item)) + if (_entities.TryGetComponent(ammo, out ItemComponent? item)) { if (!handsComponent.CanPutInHand(item)) { @@ -194,8 +194,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components for (var i = 0; i < Math.Min(count, Capacity); i++) { - var ammo = TakeAmmo(); - if (ammo == null) + if (TakeAmmo() is not { } ammo) { break; } diff --git a/Content.Server/Weapon/Ranged/Barrels/Components/ServerMagazineBarrelComponent.cs b/Content.Server/Weapon/Ranged/Barrels/Components/ServerMagazineBarrelComponent.cs index bdf400ddfe..e809b03a54 100644 --- a/Content.Server/Weapon/Ranged/Barrels/Components/ServerMagazineBarrelComponent.cs +++ b/Content.Server/Weapon/Ranged/Barrels/Components/ServerMagazineBarrelComponent.cs @@ -319,7 +319,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components return true; } - public void RemoveMagazine(EntityUiduser) + public void RemoveMagazine(EntityUid user) { var mag = MagazineContainer.ContainedEntity; diff --git a/Content.Server/Weapon/Ranged/Barrels/Components/ServerRangedBarrelComponent.cs b/Content.Server/Weapon/Ranged/Barrels/Components/ServerRangedBarrelComponent.cs index cee5df72fb..989c73a6dd 100644 --- a/Content.Server/Weapon/Ranged/Barrels/Components/ServerRangedBarrelComponent.cs +++ b/Content.Server/Weapon/Ranged/Barrels/Components/ServerRangedBarrelComponent.cs @@ -259,24 +259,27 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components /// /// /// - public void EjectCasing( + public static void EjectCasing( EntityUid entity, bool playSound = true, + Direction[]? ejectDirections = null, IRobustRandom? robustRandom = null, IPrototypeManager? prototypeManager = null, - Direction[]? ejectDirections = null) + IEntityManager? entities = null) { - robustRandom ??= IoCManager.Resolve(); + IoCManager.Resolve(ref robustRandom, ref prototypeManager, ref entities); + ejectDirections ??= new[] {Direction.East, Direction.North, Direction.NorthWest, Direction.South, Direction.SouthEast, Direction.West}; const float ejectOffset = 1.8f; - var ammo = _entities.GetComponent(entity); + var ammo = entities.GetComponent(entity); var offsetPos = ((robustRandom.NextFloat() - 0.5f) * ejectOffset, (robustRandom.NextFloat() - 0.5f) * ejectOffset); - _entities.GetComponent(entity).Coordinates = _entities.GetComponent(entity).Coordinates.Offset(offsetPos); - _entities.GetComponent(entity).LocalRotation = robustRandom.Pick(ejectDirections).ToAngle(); + entities.GetComponent(entity).Coordinates = entities.GetComponent(entity).Coordinates.Offset(offsetPos); + entities.GetComponent(entity).LocalRotation = robustRandom.Pick(ejectDirections).ToAngle(); - SoundSystem.Play(Filter.Broadcast(), ammo.SoundCollectionEject.GetSound(), _entities.GetComponent(entity).Coordinates, AudioParams.Default.WithVolume(-1)); + var coordinates = entities.GetComponent(entity).Coordinates; + SoundSystem.Play(Filter.Broadcast(), ammo.SoundCollectionEject.GetSound(), coordinates, AudioParams.Default.WithVolume(-1)); } /// @@ -284,7 +287,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components /// Wraps EjectCasing to make it less toxic for bulk ejections /// /// - public void EjectCasings(IEnumerable entities) + public static void EjectCasings(IEnumerable entities) { var robustRandom = IoCManager.Resolve(); var prototypeManager = IoCManager.Resolve(); @@ -294,7 +297,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components foreach (var entity in entities) { - EjectCasing(entity, playSound, robustRandom, prototypeManager, ejectDirections); + EjectCasing(entity, playSound, ejectDirections, robustRandom, prototypeManager); soundPlayCount++; if (soundPlayCount > 3) { diff --git a/Content.Shared/Pulling/Components/PullableComponent.cs b/Content.Shared/Pulling/Components/PullableComponent.cs index 0aa80c48c1..3aca72a317 100644 --- a/Content.Shared/Pulling/Components/PullableComponent.cs +++ b/Content.Shared/Pulling/Components/PullableComponent.cs @@ -24,7 +24,7 @@ namespace Content.Shared.Pulling.Components /// The current entity pulling this component. /// SharedPullingStateManagementSystem should be writing this. This means definitely not you. /// - public EntityUid Puller { get; set; } + public EntityUid? Puller { get; set; } /// /// The pull joint. /// SharedPullingStateManagementSystem should be writing this. This means probably not you. diff --git a/Content.Shared/Pulling/Components/SharedPullerComponent.cs b/Content.Shared/Pulling/Components/SharedPullerComponent.cs index 793137cf53..efb84aca80 100644 --- a/Content.Shared/Pulling/Components/SharedPullerComponent.cs +++ b/Content.Shared/Pulling/Components/SharedPullerComponent.cs @@ -17,7 +17,7 @@ namespace Content.Shared.Pulling.Components public float SprintSpeedModifier => Pulling == default ? 1.0f : 0.75f; [ViewVariables] - public EntityUid Pulling { get; set; } + public EntityUid? Pulling { get; set; } protected override void Shutdown() { diff --git a/Content.Shared/Pulling/Systems/SharedPullableSystem.cs b/Content.Shared/Pulling/Systems/SharedPullableSystem.cs index c5b698b8d5..7c4d1bf85c 100644 --- a/Content.Shared/Pulling/Systems/SharedPullableSystem.cs +++ b/Content.Shared/Pulling/Systems/SharedPullableSystem.cs @@ -20,7 +20,7 @@ namespace Content.Shared.Pulling.Systems private void OnRelayMoveInput(EntityUid uid, SharedPullableComponent component, RelayMoveInputEvent args) { var entity = args.Session.AttachedEntity; - if (!entity.IsValid() || !_blocker.CanMove(entity)) return; + if (!entity.HasValue || !_blocker.CanMove(entity.Value)) return; _pullSystem.TryStopPull(component); } } diff --git a/Content.Shared/Verbs/SharedVerbSystem.cs b/Content.Shared/Verbs/SharedVerbSystem.cs index e6457e200c..9d9e76c373 100644 --- a/Content.Shared/Verbs/SharedVerbSystem.cs +++ b/Content.Shared/Verbs/SharedVerbSystem.cs @@ -41,7 +41,7 @@ namespace Content.Shared.Verbs // call ActionBlocker checks, just cache it for the verb request. var canInteract = force || _actionBlockerSystem.CanInteract(user); - EntityUid? @using = null; + EntityUid @using = default; if (EntityManager.TryGetComponent(user, out SharedHandsComponent? hands) && (force || _actionBlockerSystem.CanUse(user))) { hands.TryGetActiveHeldEntity(out @using); @@ -49,9 +49,9 @@ namespace Content.Shared.Verbs // Check whether the "Held" entity is a virtual pull entity. If yes, set that as the entity being "Used". // This allows you to do things like buckle a dragged person onto a surgery table, without click-dragging // their sprite. - if (@using != null && EntityManager.TryGetComponent(@using.Value, out var pull)) + if (@using != default && EntityManager.TryGetComponent(@using, out var pull)) { - @using = pull.BlockingEntity + @using = pull.BlockingEntity; } } @@ -110,25 +110,25 @@ namespace Content.Shared.Verbs } } - public void LogVerb(Verb verb, EntityUid userUid, EntityUid targetUid, bool forced) + public void LogVerb(Verb verb, EntityUid user, EntityUid target, bool forced) { // first get the held item. again. EntityUid usedUid = default; - if (EntityManager.TryGetComponent(userUid, out SharedHandsComponent? hands) && + if (EntityManager.TryGetComponent(user, out SharedHandsComponent? hands) && hands.TryGetActiveHeldEntity(out var heldEntity)) { usedUid = heldEntity; - if (usedUid != null && EntityManager.TryGetComponent(usedUid.Value, out HandVirtualItemComponent? pull)) + if (usedUid != default && EntityManager.TryGetComponent(usedUid, out HandVirtualItemComponent? pull)) usedUid = pull.BlockingEntity; } // get all the entities - if (!userUid.IsValid() || !targetUid.IsValid()) + if (!user.IsValid() || !target.IsValid()) return; EntityUid? used = null; - if (usedUid != null) - EntityManager.EntityExists(usedUid.Value); + if (usedUid != default) + EntityManager.EntityExists(usedUid); // then prepare the basic log message body var verbText = $"{verb.Category?.Text} {verb.Text}".Trim(); @@ -137,7 +137,7 @@ namespace Content.Shared.Verbs : $"executed '{verbText}' verb targeting "; // then log with entity information - if (usedUidused != null) + if (used != null) _logSystem.Add(LogType.Verb, verb.Impact, $"{user} {logText} {target} while holding {used}"); else