diff --git a/Content.Client/Commands/HideMechanismsCommand.cs b/Content.Client/Commands/HideMechanismsCommand.cs index 88100a0f8c..e9c2073b20 100644 --- a/Content.Client/Commands/HideMechanismsCommand.cs +++ b/Content.Client/Commands/HideMechanismsCommand.cs @@ -15,6 +15,7 @@ namespace Content.Client.Commands public void Execute(IConsoleShell shell, string argStr, string[] args) { var entityManager = IoCManager.Resolve(); + var containerSys = entityManager.System(); var organs = entityManager.EntityQuery(true); foreach (var part in organs) @@ -27,7 +28,7 @@ namespace Content.Client.Commands sprite.ContainerOccluded = false; var tempParent = part.Owner; - while (tempParent.TryGetContainer(out var container)) + while (containerSys.TryGetContainingContainer(tempParent, out var container)) { if (!container.ShowContents) { diff --git a/Content.Client/Instruments/UI/InstrumentMenu.xaml.cs b/Content.Client/Instruments/UI/InstrumentMenu.xaml.cs index b50ab96251..201b7b6304 100644 --- a/Content.Client/Instruments/UI/InstrumentMenu.xaml.cs +++ b/Content.Client/Instruments/UI/InstrumentMenu.xaml.cs @@ -174,8 +174,9 @@ namespace Content.Client.Instruments.UI if (localPlayer.ControlledEntity == instrumentEnt) return true; + var container = _owner.Entities.System(); // If we're a handheld instrument, we might be in a container. Get it just in case. - instrumentEnt.TryGetContainerMan(out var conMan); + container.TryGetContainingContainer(instrumentEnt, out var conMan); // If the instrument is handheld and we're not holding it, we return. if ((instrument.Handheld && (conMan == null || conMan.Owner != localPlayer.ControlledEntity))) diff --git a/Content.Client/Interactable/InteractionSystem.cs b/Content.Client/Interactable/InteractionSystem.cs index cdfd3aa54f..0af8830e9a 100644 --- a/Content.Client/Interactable/InteractionSystem.cs +++ b/Content.Client/Interactable/InteractionSystem.cs @@ -6,15 +6,17 @@ namespace Content.Client.Interactable { public sealed class InteractionSystem : SharedInteractionSystem { + [Dependency] private readonly SharedContainerSystem _container = default!; + public override bool CanAccessViaStorage(EntityUid user, EntityUid target) { if (!EntityManager.EntityExists(target)) return false; - if (!target.TryGetContainer(out var container)) + if (!_container.TryGetContainingContainer(target, out var container)) return false; - if (!TryComp(container.Owner, out StorageComponent? storage)) + if (!HasComp(container.Owner)) return false; // we don't check if the user can access the storage entity itself. This should be handed by the UI system. diff --git a/Content.Server/Containers/EmptyOnMachineDeconstructSystem.cs b/Content.Server/Containers/EmptyOnMachineDeconstructSystem.cs index 234408c3ba..c0cae8fdf7 100644 --- a/Content.Server/Containers/EmptyOnMachineDeconstructSystem.cs +++ b/Content.Server/Containers/EmptyOnMachineDeconstructSystem.cs @@ -11,6 +11,8 @@ namespace Content.Server.Containers [UsedImplicitly] public sealed class EmptyOnMachineDeconstructSystem : EntitySystem { + [Dependency] private readonly SharedContainerSystem _container = default!; + public override void Initialize() { base.Initialize(); @@ -33,12 +35,12 @@ namespace Content.Server.Containers { if (!EntityManager.TryGetComponent(uid, out var mComp)) return; - var baseCoords = EntityManager.GetComponent(component.Owner).Coordinates; + var baseCoords = EntityManager.GetComponent(uid).Coordinates; foreach (var v in component.Containers) { if (mComp.TryGetContainer(v, out var container)) { - container.EmptyContainer(true, baseCoords); + _container.EmptyContainer(container, true, baseCoords); } } } diff --git a/Content.Server/Destructible/DestructibleSystem.cs b/Content.Server/Destructible/DestructibleSystem.cs index b9c260a7d9..0ef0d621f3 100644 --- a/Content.Server/Destructible/DestructibleSystem.cs +++ b/Content.Server/Destructible/DestructibleSystem.cs @@ -16,6 +16,7 @@ using Content.Shared.Destructible; using Content.Shared.FixedPoint; using JetBrains.Annotations; using Robust.Server.GameObjects; +using Robust.Shared.Containers; using Robust.Shared.Prototypes; using Robust.Shared.Random; @@ -36,6 +37,7 @@ namespace Content.Server.Destructible [Dependency] public readonly TriggerSystem TriggerSystem = default!; [Dependency] public readonly SolutionContainerSystem SolutionContainerSystem = default!; [Dependency] public readonly PuddleSystem PuddleSystem = default!; + [Dependency] public readonly SharedContainerSystem ContainerSystem = default!; [Dependency] public readonly IPrototypeManager PrototypeManager = default!; [Dependency] public readonly IComponentFactory ComponentFactory = default!; [Dependency] public readonly IAdminLogManager _adminLogger = default!; diff --git a/Content.Server/Destructible/Thresholds/Behaviors/EmptyAllContainersBehaviour.cs b/Content.Server/Destructible/Thresholds/Behaviors/EmptyAllContainersBehaviour.cs index 406e7bf7e2..e696ad9258 100644 --- a/Content.Server/Destructible/Thresholds/Behaviors/EmptyAllContainersBehaviour.cs +++ b/Content.Server/Destructible/Thresholds/Behaviors/EmptyAllContainersBehaviour.cs @@ -15,7 +15,7 @@ namespace Content.Server.Destructible.Thresholds.Behaviors foreach (var container in containerManager.GetAllContainers()) { - container.EmptyContainer(true, system.EntityManager.GetComponent(owner).Coordinates); + system.ContainerSystem.EmptyContainer(container, true, system.EntityManager.GetComponent(owner).Coordinates); } } } diff --git a/Content.Server/Guardian/GuardianSystem.cs b/Content.Server/Guardian/GuardianSystem.cs index f34b765ac7..118574db3f 100644 --- a/Content.Server/Guardian/GuardianSystem.cs +++ b/Content.Server/Guardian/GuardianSystem.cs @@ -31,6 +31,7 @@ namespace Content.Server.Guardian [Dependency] private readonly SharedHandsSystem _handsSystem = default!; [Dependency] private readonly SharedAudioSystem _audio = default!; [Dependency] private readonly BodySystem _bodySystem = default!; + [Dependency] private readonly SharedContainerSystem _container = default!; public override void Initialize() { @@ -88,7 +89,7 @@ namespace Content.Server.Guardian private void OnHostInit(EntityUid uid, GuardianHostComponent component, ComponentInit args) { - component.GuardianContainer = uid.EnsureContainer("GuardianContainer"); + component.GuardianContainer = _container.EnsureContainer(uid, "GuardianContainer"); _actionSystem.AddAction(uid, ref component.ActionEntity, component.Action); } diff --git a/Content.Server/Hands/Systems/HandsSystem.cs b/Content.Server/Hands/Systems/HandsSystem.cs index 1cae95c78e..298aa57ccf 100644 --- a/Content.Server/Hands/Systems/HandsSystem.cs +++ b/Content.Server/Hands/Systems/HandsSystem.cs @@ -169,9 +169,9 @@ namespace Content.Server.Hands.Systems if (playerSession.AttachedEntity is not {Valid: true} player || !Exists(player) || - player.IsInContainer() || + ContainerSystem.IsEntityInContainer(player) || !TryComp(player, out HandsComponent? hands) || - hands.ActiveHandEntity is not EntityUid throwEnt || + hands.ActiveHandEntity is not { } throwEnt || !_actionBlockerSystem.CanThrow(player, throwEnt)) return false; diff --git a/Content.Server/Nutrition/EntitySystems/SmokingSystem.cs b/Content.Server/Nutrition/EntitySystems/SmokingSystem.cs index 772e872110..96c7f8a64c 100644 --- a/Content.Server/Nutrition/EntitySystems/SmokingSystem.cs +++ b/Content.Server/Nutrition/EntitySystems/SmokingSystem.cs @@ -2,7 +2,6 @@ using Content.Server.Atmos.EntitySystems; using Content.Server.Body.Components; using Content.Server.Body.Systems; using Content.Server.Chemistry.EntitySystems; -using Content.Server.Nutrition.Components; using Content.Shared.Nutrition.Components; using Content.Shared.Chemistry; using Content.Shared.Chemistry.Reagent; @@ -29,11 +28,12 @@ namespace Content.Server.Nutrition.EntitySystems [Dependency] private readonly InventorySystem _inventorySystem = default!; [Dependency] private readonly ClothingSystem _clothing = default!; [Dependency] private readonly SharedItemSystem _items = default!; + [Dependency] private readonly SharedContainerSystem _container = default!; [Dependency] private readonly SharedAppearanceSystem _appearance = default!; private const float UpdateTimer = 3f; - private float _timer = 0f; + private float _timer; /// /// We keep a list of active smokables, because iterating all existing smokables would be dumb. @@ -130,8 +130,8 @@ namespace Content.Server.Nutrition.EntitySystems // This is awful. I hate this so much. // TODO: Please, someone refactor containers and free me from this bullshit. - if (!smokable.Owner.TryGetContainerMan(out var containerManager) || - !(_inventorySystem.TryGetSlotEntity(containerManager.Owner, "mask", out var inMaskSlotUid) && inMaskSlotUid == smokable.Owner) || + if (!_container.TryGetContainingContainer(uid, out var containerManager) || + !(_inventorySystem.TryGetSlotEntity(containerManager.Owner, "mask", out var inMaskSlotUid) && inMaskSlotUid == uid) || !TryComp(containerManager.Owner, out BloodstreamComponent? bloodstream)) { continue; diff --git a/Content.Server/Resist/EscapeInventorySystem.cs b/Content.Server/Resist/EscapeInventorySystem.cs index eb7c4c8478..ea603084b5 100644 --- a/Content.Server/Resist/EscapeInventorySystem.cs +++ b/Content.Server/Resist/EscapeInventorySystem.cs @@ -80,7 +80,7 @@ public sealed class EscapeInventorySystem : EntitySystem if (!_doAfterSystem.TryStartDoAfter(doAfterEventArgs, out component.DoAfter)) return; - Dirty(component); + Dirty(user, component); _popupSystem.PopupEntity(Loc.GetString("escape-inventory-component-start-resisting"), user, user); _popupSystem.PopupEntity(Loc.GetString("escape-inventory-component-start-resisting-target"), container, container); } @@ -88,12 +88,12 @@ public sealed class EscapeInventorySystem : EntitySystem private void OnEscape(EntityUid uid, CanEscapeInventoryComponent component, EscapeInventoryEvent args) { component.DoAfter = null; - Dirty(component); + Dirty(uid, component); if (args.Handled || args.Cancelled) return; - Transform(uid).AttachParentToContainerOrGrid(EntityManager); + _containerSystem.AttachParentToContainerOrGrid(Transform(uid)); args.Handled = true; } diff --git a/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Drop.cs b/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Drop.cs index e43f2561a1..06d6526566 100644 --- a/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Drop.cs +++ b/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Drop.cs @@ -6,10 +6,8 @@ using Robust.Shared.Map; namespace Content.Shared.Hands.EntitySystems; -public abstract partial class SharedHandsSystem : EntitySystem +public abstract partial class SharedHandsSystem { - [Dependency] private readonly SharedContainerSystem _container = default!; - private void InitializeDrop() { SubscribeLocalEvent(HandleEntityRemoved); @@ -23,10 +21,10 @@ public abstract partial class SharedHandsSystem : EntitySystem } var gotUnequipped = new GotUnequippedHandEvent(uid, args.Entity, hand); - RaiseLocalEvent(args.Entity, gotUnequipped, false); + RaiseLocalEvent(args.Entity, gotUnequipped); var didUnequip = new DidUnequipHandEvent(uid, args.Entity, hand); - RaiseLocalEvent(uid, didUnequip, false); + RaiseLocalEvent(uid, didUnequip); } /// @@ -37,7 +35,7 @@ public abstract partial class SharedHandsSystem : EntitySystem if (hand.Container?.ContainedEntity is not {} held) return false; - if (!_container.CanRemove(held, hand.Container)) + if (!ContainerSystem.CanRemove(held, hand.Container)) return false; if (checkActionBlocker && !_actionBlocker.CanDrop(uid)) @@ -90,7 +88,7 @@ public abstract partial class SharedHandsSystem : EntitySystem var userXform = Transform(uid); var itemXform = Transform(entity); - var isInContainer = _containerSystem.IsEntityInContainer(uid); + var isInContainer = ContainerSystem.IsEntityInContainer(uid); if (targetDropLocation == null || isInContainer) { @@ -98,14 +96,14 @@ public abstract partial class SharedHandsSystem : EntitySystem // TODO recursively check upwards for containers if (!isInContainer - || !_containerSystem.TryGetContainingContainer(userXform.ParentUid, uid, out var container, skipExistCheck: true) + || !ContainerSystem.TryGetContainingContainer(userXform.ParentUid, uid, out var container, skipExistCheck: true) || !container.Insert(entity, EntityManager, itemXform)) - itemXform.AttachToGridOrMap(); + TransformSystem.AttachToGridOrMap(entity, itemXform); return true; } - var target = targetDropLocation.Value.ToMap(EntityManager); - itemXform.WorldPosition = GetFinalDropCoordinates(uid, userXform.MapPosition, target); + var target = targetDropLocation.Value.ToMap(EntityManager, TransformSystem); + TransformSystem.SetWorldPosition(userXform, GetFinalDropCoordinates(uid, userXform.MapPosition, target)); return true; } @@ -123,7 +121,7 @@ public abstract partial class SharedHandsSystem : EntitySystem if (!CanDropHeld(uid, hand, checkActionBlocker)) return false; - if (!_container.CanInsert(entity, targetContainer)) + if (!ContainerSystem.CanInsert(entity, targetContainer)) return false; DoDrop(uid, hand, false, handsComp); @@ -171,12 +169,12 @@ public abstract partial class SharedHandsSystem : EntitySystem return; } - Dirty(handsComp); + Dirty(uid, handsComp); if (doDropInteraction) _interactionSystem.DroppedInteraction(uid, entity); if (hand == handsComp.ActiveHand) - RaiseLocalEvent(entity, new HandDeselectedEvent(uid), false); + RaiseLocalEvent(entity, new HandDeselectedEvent(uid)); } } diff --git a/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Pickup.cs b/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Pickup.cs index 278470c4a2..0171b9f70c 100644 --- a/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Pickup.cs +++ b/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Pickup.cs @@ -180,7 +180,7 @@ public abstract partial class SharedHandsSystem : EntitySystem return false; // check can insert (including raising attempt events). - return _containerSystem.CanInsert(entity, handContainer); + return ContainerSystem.CanInsert(entity, handContainer); } /// @@ -202,7 +202,7 @@ public abstract partial class SharedHandsSystem : EntitySystem { // TODO make this check upwards for any container, and parent to that. // Currently this just checks the direct parent, so items can still teleport through containers. - Transform(entity).AttachParentToContainerOrGrid(EntityManager); + ContainerSystem.AttachParentToContainerOrGrid(Transform(entity)); } } diff --git a/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Virtual.cs b/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Virtual.cs index 36498d929b..b83ec8c128 100644 --- a/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Virtual.cs +++ b/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Virtual.cs @@ -12,7 +12,7 @@ public abstract partial class SharedHandsSystem private void OnVirtualAfter(EntityUid uid, HandVirtualItemComponent component, ref AfterAutoHandleStateEvent args) { // update hands GUI with new entity. - if (_containerSystem.IsEntityInContainer(uid)) + if (ContainerSystem.IsEntityInContainer(uid)) _items.VisualsChanged(uid); } } diff --git a/Content.Shared/Hands/EntitySystems/SharedHandsSystem.cs b/Content.Shared/Hands/EntitySystems/SharedHandsSystem.cs index af53b2625c..9f7623329e 100644 --- a/Content.Shared/Hands/EntitySystems/SharedHandsSystem.cs +++ b/Content.Shared/Hands/EntitySystems/SharedHandsSystem.cs @@ -11,11 +11,11 @@ using Robust.Shared.Input.Binding; namespace Content.Shared.Hands.EntitySystems; -public abstract partial class SharedHandsSystem : EntitySystem +public abstract partial class SharedHandsSystem { [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!; [Dependency] private readonly ActionBlockerSystem _actionBlocker = default!; - [Dependency] private readonly SharedContainerSystem _containerSystem = default!; + [Dependency] protected readonly SharedContainerSystem ContainerSystem = default!; [Dependency] private readonly SharedInteractionSystem _interactionSystem = default!; [Dependency] private readonly SharedItemSystem _items = default!; [Dependency] private readonly SharedStorageSystem _storage = default!; @@ -47,7 +47,7 @@ public abstract partial class SharedHandsSystem : EntitySystem if (handsComp.Hands.ContainsKey(handName)) return; - var container = _containerSystem.EnsureContainer(uid, handName); + var container = ContainerSystem.EnsureContainer(uid, handName); container.OccludesLight = false; var newHand = new Hand(handName, handLocation, container); @@ -57,8 +57,8 @@ public abstract partial class SharedHandsSystem : EntitySystem if (handsComp.ActiveHand == null) SetActiveHand(uid, newHand, handsComp); - RaiseLocalEvent(uid, new HandCountChangedEvent(uid), false); - Dirty(handsComp); + RaiseLocalEvent(uid, new HandCountChangedEvent(uid)); + Dirty(uid, handsComp); } public virtual void RemoveHand(EntityUid uid, string handName, HandsComponent? handsComp = null) @@ -76,8 +76,8 @@ public abstract partial class SharedHandsSystem : EntitySystem if (handsComp.ActiveHand == hand) TrySetActiveHand(uid, handsComp.SortedHands.FirstOrDefault(), handsComp); - RaiseLocalEvent(uid, new HandCountChangedEvent(uid), false); - Dirty(handsComp); + RaiseLocalEvent(uid, new HandCountChangedEvent(uid)); + Dirty(uid, handsComp); } /// @@ -169,7 +169,7 @@ public abstract partial class SharedHandsSystem : EntitySystem if (name == handsComp.ActiveHand?.Name) continue; - if (handsComp.Hands[name].HeldEntity is EntityUid held) + if (handsComp.Hands[name].HeldEntity is { } held) yield return held; } } @@ -206,8 +206,8 @@ public abstract partial class SharedHandsSystem : EntitySystem if (hand == handComp.ActiveHand) return false; - if (handComp.ActiveHand?.HeldEntity is EntityUid held) - RaiseLocalEvent(held, new HandDeselectedEvent(uid), false); + if (handComp.ActiveHand?.HeldEntity is { } held) + RaiseLocalEvent(held, new HandDeselectedEvent(uid)); if (hand == null) { @@ -219,8 +219,9 @@ public abstract partial class SharedHandsSystem : EntitySystem OnHandSetActive?.Invoke(handComp); if (hand.HeldEntity != null) - RaiseLocalEvent(hand.HeldEntity.Value, new HandSelectedEvent(uid), false); - Dirty(handComp); + RaiseLocalEvent(hand.HeldEntity.Value, new HandSelectedEvent(uid)); + + Dirty(uid, handComp); return true; }