diff --git a/Content.Server/AI/Operators/Inventory/CloseStorageOperator.cs b/Content.Server/AI/Operators/Inventory/CloseStorageOperator.cs index 193b45077e..7822411274 100644 --- a/Content.Server/AI/Operators/Inventory/CloseStorageOperator.cs +++ b/Content.Server/AI/Operators/Inventory/CloseStorageOperator.cs @@ -1,6 +1,7 @@ using Content.Server.AI.Utility; using Content.Server.AI.WorldState.States.Inventory; using Content.Server.GameObjects.Components; +using Content.Server.GameObjects.Components.Items.Storage; using Content.Server.GameObjects.EntitySystems; using Content.Server.Utility; using Robust.Shared.Interfaces.GameObjects; diff --git a/Content.Server/AI/Operators/Inventory/OpenStorageOperator.cs b/Content.Server/AI/Operators/Inventory/OpenStorageOperator.cs index c7c21ae3f2..f90046ea45 100644 --- a/Content.Server/AI/Operators/Inventory/OpenStorageOperator.cs +++ b/Content.Server/AI/Operators/Inventory/OpenStorageOperator.cs @@ -1,6 +1,7 @@ using Content.Server.AI.Utility; using Content.Server.AI.WorldState.States.Inventory; using Content.Server.GameObjects.Components; +using Content.Server.GameObjects.Components.Items.Storage; using Content.Server.GameObjects.EntitySystems; using Content.Server.Utility; using Content.Shared.GameObjects.EntitySystems; diff --git a/Content.Server/AI/Utility/Considerations/Containers/TargetAccessibleCon.cs b/Content.Server/AI/Utility/Considerations/Containers/TargetAccessibleCon.cs index 4265db6abd..f502fddb00 100644 --- a/Content.Server/AI/Utility/Considerations/Containers/TargetAccessibleCon.cs +++ b/Content.Server/AI/Utility/Considerations/Containers/TargetAccessibleCon.cs @@ -3,6 +3,7 @@ using Content.Server.AI.WorldState; using Content.Server.AI.WorldState.States; using Content.Server.GameObjects; using Content.Server.GameObjects.Components; +using Content.Server.GameObjects.Components.Items.Storage; using Robust.Shared.Containers; namespace Content.Server.AI.Utility.Considerations.Containers diff --git a/Content.Server/AI/WorldState/States/Clothing/NearbyClothingState.cs b/Content.Server/AI/WorldState/States/Clothing/NearbyClothingState.cs index 83a54abee1..4d231273fa 100644 --- a/Content.Server/AI/WorldState/States/Clothing/NearbyClothingState.cs +++ b/Content.Server/AI/WorldState/States/Clothing/NearbyClothingState.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using Content.Server.AI.Utils; using Content.Server.GameObjects; using Content.Server.GameObjects.Components; +using Content.Server.GameObjects.Components.Items.Storage; using Content.Server.GameObjects.Components.Movement; using JetBrains.Annotations; using Robust.Shared.Containers; diff --git a/Content.Server/AI/WorldState/States/Inventory/LastOpenedStorageState.cs b/Content.Server/AI/WorldState/States/Inventory/LastOpenedStorageState.cs index 636cb8ea63..973faf3115 100644 --- a/Content.Server/AI/WorldState/States/Inventory/LastOpenedStorageState.cs +++ b/Content.Server/AI/WorldState/States/Inventory/LastOpenedStorageState.cs @@ -1,4 +1,5 @@ using Content.Server.GameObjects.Components; +using Content.Server.GameObjects.Components.Items.Storage; using Robust.Shared.Interfaces.GameObjects; using Logger = Robust.Shared.Log.Logger; diff --git a/Content.Server/AI/WorldState/States/Nutrition/NearbyDrinkState.cs b/Content.Server/AI/WorldState/States/Nutrition/NearbyDrinkState.cs index bfee177d69..a2be3e46f2 100644 --- a/Content.Server/AI/WorldState/States/Nutrition/NearbyDrinkState.cs +++ b/Content.Server/AI/WorldState/States/Nutrition/NearbyDrinkState.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using Content.Server.AI.Utils; using Content.Server.GameObjects.Components; +using Content.Server.GameObjects.Components.Items.Storage; using Content.Server.GameObjects.Components.Movement; using Content.Server.GameObjects.Components.Nutrition; using JetBrains.Annotations; diff --git a/Content.Server/AI/WorldState/States/Nutrition/NearbyFoodState.cs b/Content.Server/AI/WorldState/States/Nutrition/NearbyFoodState.cs index e33bca5a0c..168f9c0897 100644 --- a/Content.Server/AI/WorldState/States/Nutrition/NearbyFoodState.cs +++ b/Content.Server/AI/WorldState/States/Nutrition/NearbyFoodState.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using Content.Server.AI.Utils; using Content.Server.GameObjects.Components; +using Content.Server.GameObjects.Components.Items.Storage; using Content.Server.GameObjects.Components.Movement; using Content.Server.GameObjects.Components.Nutrition; using JetBrains.Annotations; diff --git a/Content.Server/GameObjects/Components/Explosion/FlashExplosiveComponent.cs b/Content.Server/GameObjects/Components/Explosion/FlashExplosiveComponent.cs index 02789749bf..f2538c200a 100644 --- a/Content.Server/GameObjects/Components/Explosion/FlashExplosiveComponent.cs +++ b/Content.Server/GameObjects/Components/Explosion/FlashExplosiveComponent.cs @@ -1,3 +1,4 @@ +using Content.Server.GameObjects.Components.Items.Storage; using Content.Server.GameObjects.Components.Weapon; using Content.Server.GameObjects.EntitySystems; using Robust.Server.GameObjects.EntitySystems; diff --git a/Content.Server/GameObjects/Components/Items/Storage/EntityStorageComponent.cs b/Content.Server/GameObjects/Components/Items/Storage/EntityStorageComponent.cs index 6eae6bf66f..ac784f7e52 100644 --- a/Content.Server/GameObjects/Components/Items/Storage/EntityStorageComponent.cs +++ b/Content.Server/GameObjects/Components/Items/Storage/EntityStorageComponent.cs @@ -1,8 +1,6 @@ using System; using System.Linq; using Content.Server.GameObjects.Components.Interactable; -using Content.Server.GameObjects.Components.Items.Storage; -using Content.Server.GameObjects.Components.Sound; using Content.Server.GameObjects.EntitySystems; using Content.Shared.GameObjects; using Content.Shared.GameObjects.Components.Interactable; @@ -25,12 +23,12 @@ using Robust.Shared.Maths; using Robust.Shared.Serialization; using Robust.Shared.ViewVariables; -namespace Content.Server.GameObjects.Components +namespace Content.Server.GameObjects.Components.Items.Storage { [RegisterComponent] [ComponentReference(typeof(IActivate))] [ComponentReference(typeof(IStorageComponent))] - public class EntityStorageComponent : Component, IActivate, IStorageComponent, IInteractUsing, IDestroyAct + public class EntityStorageComponent : Component, IActivate, IStorageComponent, IInteractUsing, IDestroyAct, IActionBlocker { public override string Name => "EntityStorage"; @@ -40,13 +38,13 @@ namespace Content.Server.GameObjects.Components private TimeSpan _lastInternalOpenAttempt; [ViewVariables] - private int StorageCapacityMax; + private int _storageCapacityMax; [ViewVariables] - private bool IsCollidableWhenOpen; + private bool _isCollidableWhenOpen; [ViewVariables] - private Container Contents; + private Container _contents; [ViewVariables] - private IEntityQuery entityQuery; + private IEntityQuery _entityQuery; private bool _showContents; private bool _open; private bool _isWeldedShut; @@ -63,7 +61,7 @@ namespace Content.Server.GameObjects.Components set { _showContents = value; - Contents.ShowContents = _showContents; + _contents.ShowContents = _showContents; } } @@ -96,10 +94,10 @@ namespace Content.Server.GameObjects.Components public override void Initialize() { base.Initialize(); - Contents = ContainerManagerComponent.Ensure(nameof(EntityStorageComponent), Owner); - entityQuery = new IntersectingEntityQuery(Owner); + _contents = ContainerManagerComponent.Ensure(nameof(EntityStorageComponent), Owner); + _entityQuery = new IntersectingEntityQuery(Owner); - Contents.ShowContents = _showContents; + _contents.ShowContents = _showContents; if (Owner.TryGetComponent(out var placeableSurfaceComponent)) { @@ -112,8 +110,8 @@ namespace Content.Server.GameObjects.Components { base.ExposeData(serializer); - serializer.DataField(ref StorageCapacityMax, "Capacity", 30); - serializer.DataField(ref IsCollidableWhenOpen, "IsCollidableWhenOpen", false); + serializer.DataField(ref _storageCapacityMax, "Capacity", 30); + serializer.DataField(ref _isCollidableWhenOpen, "IsCollidableWhenOpen", false); serializer.DataField(ref _showContents, "showContents", false); serializer.DataField(ref _open, "open", false); serializer.DataField(this, a => a.IsWeldedShut, "IsWeldedShut", false); @@ -146,7 +144,7 @@ namespace Content.Server.GameObjects.Components private void CloseStorage() { Open = false; - var entities = Owner.EntityManager.GetEntities(entityQuery); + var entities = Owner.EntityManager.GetEntities(_entityQuery); var count = 0; foreach (var entity in entities) { @@ -163,7 +161,7 @@ namespace Content.Server.GameObjects.Components continue; } count++; - if (count >= StorageCapacityMax) + if (count >= _storageCapacityMax) { break; } @@ -180,12 +178,11 @@ namespace Content.Server.GameObjects.Components EmptyContents(); ModifyComponents(); EntitySystem.Get().PlayFromEntity("/Audio/machines/closetopen.ogg", Owner); - } private void ModifyComponents() { - if (!IsCollidableWhenOpen && Owner.TryGetComponent(out var collidableComponent)) + if (!_isCollidableWhenOpen && Owner.TryGetComponent(out var collidableComponent)) { var physShape = collidableComponent.PhysicsShapes[0]; if (Open) @@ -242,7 +239,7 @@ namespace Content.Server.GameObjects.Components entity.Transform.WorldPosition += new Vector2(0, collidableComponent.WorldAABB.Top - entityCollidableComponent.WorldAABB.Top); } } - if (Contents.CanInsert(entity)) + if (_contents.CanInsert(entity)) { // Because Insert sets the local position to (0,0), and we want to keep the contents spread out, // we re-apply the world position after inserting. @@ -255,7 +252,7 @@ namespace Content.Server.GameObjects.Components { worldPos = entity.Transform.WorldPosition; } - Contents.Insert(entity); + _contents.Insert(entity); entity.Transform.WorldPosition = worldPos; if (entityCollidableComponent != null) { @@ -268,9 +265,9 @@ namespace Content.Server.GameObjects.Components private void EmptyContents() { - foreach (var contained in Contents.ContainedEntities.ToArray()) + foreach (var contained in _contents.ContainedEntities.ToArray()) { - if(Contents.Remove(contained)) + if(_contents.Remove(contained)) { if (contained.TryGetComponent(out var entityCollidableComponent)) { @@ -317,7 +314,7 @@ namespace Content.Server.GameObjects.Components /// public bool Remove(IEntity entity) { - return Contents.CanRemove(entity); + return _contents.CanRemove(entity); } /// @@ -330,7 +327,7 @@ namespace Content.Server.GameObjects.Components return true; } - return Contents.Insert(entity); + return _contents.Insert(entity); } /// @@ -341,12 +338,12 @@ namespace Content.Server.GameObjects.Components return true; } - if (Contents.ContainedEntities.Count >= StorageCapacityMax) + if (_contents.ContainedEntities.Count >= _storageCapacityMax) { return false; } - return Contents.CanInsert(entity); + return _contents.CanInsert(entity); } [Verb] diff --git a/Content.Server/GameObjects/Components/Mobs/BuckleComponent.cs b/Content.Server/GameObjects/Components/Mobs/BuckleComponent.cs index 493a21e320..efd7bd76e9 100644 --- a/Content.Server/GameObjects/Components/Mobs/BuckleComponent.cs +++ b/Content.Server/GameObjects/Components/Mobs/BuckleComponent.cs @@ -9,6 +9,7 @@ using Content.Shared.GameObjects.Components.Strap; using Content.Shared.GameObjects.EntitySystems; using JetBrains.Annotations; using Robust.Server.GameObjects; +using Robust.Server.GameObjects.Components.Container; using Robust.Server.GameObjects.EntitySystems; using Robust.Shared.GameObjects; using Robust.Shared.Interfaces.GameObjects; @@ -59,6 +60,22 @@ namespace Content.Server.GameObjects.Components.Mobs } } + private bool IsContained() + { + var parent = Owner.Transform.Parent; + if (parent == null) + { + return false; + } + + if (parent.Owner.TryGetComponent(out ContainerManagerComponent container)) + { + return container.ContainsEntity(Owner); + } + + return false; + } + private bool TryBuckle(IEntity user, IEntity to) { if (user == null || user == to) @@ -76,7 +93,8 @@ namespace Content.Server.GameObjects.Components.Mobs var strapPosition = Owner.Transform.MapPosition; var range = SharedInteractionSystem.InteractionRange / 2; - if (!InteractionChecks.InRangeUnobstructed(user, strapPosition, range)) + if (!InteractionChecks.InRangeUnobstructed(user, strapPosition, range) || + IsContained()) { _notifyManager.PopupMessage(user, user, Loc.GetString("You can't reach there!")); diff --git a/Content.Server/GameObjects/Components/Strap/StrapComponent.cs b/Content.Server/GameObjects/Components/Strap/StrapComponent.cs index 9060193c1f..6a0a10c797 100644 --- a/Content.Server/GameObjects/Components/Strap/StrapComponent.cs +++ b/Content.Server/GameObjects/Components/Strap/StrapComponent.cs @@ -149,6 +149,16 @@ namespace Content.Server.GameObjects.Components.Strap OccupiedSize = 0; } + bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs) + { + if (!eventArgs.User.TryGetComponent(out BuckleComponent buckle)) + { + return false; + } + + return buckle.ToggleBuckle(eventArgs.User, Owner); + } + [Verb] private sealed class StrapVerb : Verb { @@ -201,15 +211,5 @@ namespace Content.Server.GameObjects.Components.Strap buckle.ToggleBuckle(user, component.Owner); } } - - bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs) - { - if (!eventArgs.User.TryGetComponent(out BuckleComponent buckle)) - { - return false; - } - - return buckle.ToggleBuckle(eventArgs.User, Owner); - } } }