diff --git a/Content.Server/Storage/Components/EntityStorageComponent.cs b/Content.Server/Storage/Components/EntityStorageComponent.cs index ce0ad41c74..1f12339d87 100644 --- a/Content.Server/Storage/Components/EntityStorageComponent.cs +++ b/Content.Server/Storage/Components/EntityStorageComponent.cs @@ -61,7 +61,7 @@ public sealed class EntityStorageComponent : Component, IGasMixtureHolder [DataField("occludesLight")] public bool OccludesLight = true; - [DataField("deleteContentsOnDestruction")] + [DataField("deleteContentsOnDestruction"), ViewVariables(VVAccess.ReadWrite)] public bool DeleteContentsOnDestruction = false; /// diff --git a/Content.Server/Storage/EntitySystems/EntityStorageSystem.cs b/Content.Server/Storage/EntitySystems/EntityStorageSystem.cs index 649d082552..64d189c185 100644 --- a/Content.Server/Storage/EntitySystems/EntityStorageSystem.cs +++ b/Content.Server/Storage/EntitySystems/EntityStorageSystem.cs @@ -46,8 +46,9 @@ public sealed class EntityStorageSystem : EntitySystem SubscribeLocalEvent(OnWeldableAttempt); SubscribeLocalEvent(OnWelded); SubscribeLocalEvent(OnLockToggleAttempt); - SubscribeLocalEvent(OnDestroy); + SubscribeLocalEvent(OnDestruction); + SubscribeLocalEvent(OnRemoved); SubscribeLocalEvent(OnInsideInhale); SubscribeLocalEvent(OnInsideExhale); SubscribeLocalEvent(OnInsideExposed); @@ -115,11 +116,19 @@ public sealed class EntityStorageSystem : EntitySystem args.Cancelled = true; } - private void OnDestroy(EntityUid uid, EntityStorageComponent component, DestructionEventArgs args) + private void OnDestruction(EntityUid uid, EntityStorageComponent component, DestructionEventArgs args) { component.Open = true; if (!component.DeleteContentsOnDestruction) + { EmptyContents(uid, component); + return; + } + + foreach (var ent in new List(component.Contents.ContainedEntities)) + { + EntityManager.DeleteEntity(ent); + } } public void ToggleOpen(EntityUid user, EntityUid target, EntityStorageComponent? component = null) @@ -146,12 +155,7 @@ public sealed class EntityStorageSystem : EntitySystem var containedArr = component.Contents.ContainedEntities.ToArray(); foreach (var contained in containedArr) { - if (!component.Contents.Remove(contained)) - continue; - - RemComp(contained); - Transform(contained).WorldPosition = - uidXform.WorldPosition + uidXform.WorldRotation.RotateVec(component.EnteringOffset); + Remove(contained, uid, component, uidXform); } } @@ -192,9 +196,6 @@ public sealed class EntityStorageSystem : EntitySystem if (!AddToContents(entity, uid, component)) continue; - var inside = EnsureComp(entity); - inside.Storage = uid; - count++; if (count >= component.Capacity) break; @@ -218,15 +219,20 @@ public sealed class EntityStorageSystem : EntitySystem return true; } + var inside = EnsureComp(toInsert); + inside.Storage = container; return component.Contents.Insert(toInsert, EntityManager); } - public bool Remove(EntityUid toRemove, EntityUid container, EntityStorageComponent? component = null) + public bool Remove(EntityUid toRemove, EntityUid container, EntityStorageComponent? component = null, TransformComponent? xform = null) { - if (!Resolve(container, ref component)) + if (!Resolve(container, ref component, ref xform, false)) return false; - return component.Contents.Remove(toRemove, EntityManager); + RemComp(toRemove); + component.Contents.Remove(toRemove, EntityManager); + Transform(toRemove).WorldPosition = xform.WorldPosition + xform.WorldRotation.RotateVec(component.EnteringOffset); + return true; } public bool CanInsert(EntityUid container, EntityStorageComponent? component = null) @@ -434,6 +440,13 @@ public sealed class EntityStorageSystem : EntitySystem return null; } + private void OnRemoved(EntityUid uid, InsideEntityStorageComponent component, EntGotRemovedFromContainerMessage args) + { + if (args.Container.Owner != component.Storage) + return; + RemComp(uid, component); + } + #region Gas mix event handlers private void OnInsideInhale(EntityUid uid, InsideEntityStorageComponent component, InhaleLocationEvent args) diff --git a/Resources/Prototypes/Catalog/Fills/Crates/npc.yml b/Resources/Prototypes/Catalog/Fills/Crates/npc.yml index ad623ae507..0f126a86ce 100644 --- a/Resources/Prototypes/Catalog/Fills/Crates/npc.yml +++ b/Resources/Prototypes/Catalog/Fills/Crates/npc.yml @@ -151,6 +151,7 @@ - type: entity id: CrateNPCHamster parent: CrateRodentCage + suffix: Filled components: - type: StorageFill contents: @@ -159,6 +160,7 @@ - type: entity id: CrateNPCHamlet parent: CrateRodentCage + suffix: Hamlet components: - type: StorageFill contents: diff --git a/Resources/Prototypes/Entities/Structures/Storage/Crates/crates.yml b/Resources/Prototypes/Entities/Structures/Storage/Crates/crates.yml index 3876b77ee3..b3bb245763 100644 --- a/Resources/Prototypes/Entities/Structures/Storage/Crates/crates.yml +++ b/Resources/Prototypes/Entities/Structures/Storage/Crates/crates.yml @@ -312,6 +312,9 @@ acts: [ "Destruction" ] - type: Physics bodyType: Dynamic + - type: EntityStorage + capacity: 500 + airtight: false - type: Fixtures fixtures: - shape: