]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
caninsert entitystorage tweaks (#20589)
authorNemanja <98561806+EmoGarbage404@users.noreply.github.com>
Fri, 29 Sep 2023 03:55:29 +0000 (23:55 -0400)
committerGitHub <noreply@github.com>
Fri, 29 Sep 2023 03:55:29 +0000 (22:55 -0500)
Content.Server/Morgue/CrematoriumSystem.cs
Content.Server/StationEvents/Events/RandomEntityStorageSpawnRule.cs
Content.Server/Storage/EntitySystems/EntityStorageSystem.cs
Content.Shared/Storage/Components/SharedEntityStorageComponent.cs
Content.Shared/Storage/EntitySystems/SharedEntityStorageSystem.cs

index 5ef42ea00e83a75fab553ba75b7c01f3163e382b..d713b43f27aa2afded579878390a971417209727 100644 (file)
@@ -156,7 +156,7 @@ public sealed class CrematoriumSystem : EntitySystem
             ("victim", Identity.Entity(victim, EntityManager))),
             victim, Filter.PvsExcept(victim), true, PopupType.LargeCaution);
 
-        if (_entityStorage.CanInsert(uid))
+        if (_entityStorage.CanInsert(victim, uid))
         {
             _entityStorage.CloseStorage(uid);
             _standing.Down(victim, false);
index a9e8c437ec02ea9ca524c4ef529a13f51cea6da7..c3cd719cc4c98843a035d8d946cc21f323e0d7f6 100644 (file)
@@ -2,6 +2,7 @@ using Content.Server.GameTicking.Rules.Components;
 using Content.Server.StationEvents.Components;
 using Content.Server.Storage.Components;
 using Content.Server.Storage.EntitySystems;
+using Robust.Shared.Map;
 using Robust.Shared.Random;
 
 namespace Content.Server.StationEvents.Events;
@@ -17,7 +18,8 @@ public sealed class RandomEntityStorageSpawnRule : StationEventSystem<RandomEnti
         if (!TryGetRandomStation(out var station))
             return;
 
-        var validLockers = new List<(EntityUid, EntityStorageComponent, TransformComponent)>();
+        var validLockers = new List<(EntityUid, EntityStorageComponent)>();
+        var spawn = Spawn(comp.Prototype, MapCoordinates.Nullspace);
 
         var query = EntityQueryEnumerator<EntityStorageComponent, TransformComponent>();
         while (query.MoveNext(out var ent, out var storage, out var xform))
@@ -25,17 +27,19 @@ public sealed class RandomEntityStorageSpawnRule : StationEventSystem<RandomEnti
             if (StationSystem.GetOwningStation(ent, xform) != station)
                 continue;
 
-            if (!_entityStorage.CanInsert(ent, storage) || storage.Open)
+            if (!_entityStorage.CanInsert(spawn, ent, storage))
                 continue;
 
-            validLockers.Add((ent, storage, xform));
+            validLockers.Add((ent, storage));
         }
 
         if (validLockers.Count == 0)
+        {
+            Del(spawn);
             return;
+        }
 
-        var (locker, storageComp, xformComp) = RobustRandom.Pick(validLockers);
-        var spawn = Spawn(comp.Prototype, xformComp.Coordinates);
+        var (locker, storageComp) = RobustRandom.Pick(validLockers);
         if (!_entityStorage.Insert(spawn, locker, storageComp))
         {
             Del(spawn);
index a828c22d5b9d49efec12c45af703e295ce2af67e..cbd4883b4cdf73d2919bf0f257d0aff70a85cd88 100644 (file)
@@ -128,7 +128,7 @@ public sealed class EntityStorageSystem : SharedEntityStorageSystem
 
     private TileRef? GetOffsetTileRef(EntityUid uid, EntityStorageComponent component)
     {
-        var targetCoordinates = new EntityCoordinates(uid, component.EnteringOffset).ToMap(EntityManager);
+        var targetCoordinates = new EntityCoordinates(uid, component.EnteringOffset).ToMap(EntityManager, TransformSystem);
 
         if (_map.TryFindGridAt(targetCoordinates, out _, out var grid))
         {
index db1d3bac9aff39e9a675e86ae1cd91e2af7bd448..80f38188ea966147133737653074ee8fb3e7d116 100644 (file)
@@ -27,19 +27,19 @@ public abstract partial class SharedEntityStorageComponent : Component
     /// <summary>
     ///     Collision masks that were removed from ANY layer when the storage was opened;
     /// </summary>
-    [DataField("removedMasks")]
+    [DataField]
     public int RemovedMasks;
 
     /// <summary>
     /// The total amount of items that can fit in one entitystorage
     /// </summary>
-    [DataField("capacity")]
+    [DataField, ViewVariables(VVAccess.ReadWrite)]
     public int Capacity = 30;
 
     /// <summary>
     /// Whether or not the entity still has collision when open
     /// </summary>
-    [DataField("isCollidableWhenOpen")]
+    [DataField, ViewVariables(VVAccess.ReadWrite)]
     public bool IsCollidableWhenOpen;
 
     /// <summary>
@@ -47,71 +47,70 @@ public abstract partial class SharedEntityStorageComponent : Component
     /// If false, it prevents the storage from opening when the entity inside of it moves.
     /// This is for objects that you want the player to move while inside, like large cardboard boxes, without opening the storage.
     /// </summary>
-    [ViewVariables(VVAccess.ReadWrite)]
-    [DataField("openOnMove")]
+    [DataField, ViewVariables(VVAccess.ReadWrite)]
     public bool OpenOnMove = true;
 
     //The offset for where items are emptied/vacuumed for the EntityStorage.
-    [DataField("enteringOffset")]
+    [DataField, ViewVariables(VVAccess.ReadWrite)]
     public Vector2 EnteringOffset = new(0, 0);
 
     //The collision groups checked, so that items are depositied or grabbed from inside walls.
-    [DataField("enteringOffsetCollisionFlags")]
+    [DataField, ViewVariables(VVAccess.ReadWrite)]
     public CollisionGroup EnteringOffsetCollisionFlags = CollisionGroup.Impassable | CollisionGroup.MidImpassable;
 
     /// <summary>
     /// How close you have to be to the "entering" spot to be able to enter
     /// </summary>
-    [DataField("enteringRange")]
+    [DataField, ViewVariables(VVAccess.ReadWrite)]
     public float EnteringRange = 0.18f;
 
     /// <summary>
     /// Whether or not to show the contents when the storage is closed
     /// </summary>
-    [DataField("showContents")]
+    [DataField, ViewVariables(VVAccess.ReadWrite)]
     public bool ShowContents;
 
     /// <summary>
     /// Whether or not light is occluded by the storage
     /// </summary>
-    [DataField("occludesLight")]
+    [DataField, ViewVariables(VVAccess.ReadWrite)]
     public bool OccludesLight = true;
 
     /// <summary>
     /// Whether or not all the contents stored should be deleted with the entitystorage
     /// </summary>
-    [DataField("deleteContentsOnDestruction"), ViewVariables(VVAccess.ReadWrite)]
+    [DataField, ViewVariables(VVAccess.ReadWrite)]
     public bool DeleteContentsOnDestruction;
 
     /// <summary>
     /// Whether or not the container is sealed and traps air inside of it
     /// </summary>
-    [DataField("airtight"), ViewVariables(VVAccess.ReadWrite)]
+    [DataField, ViewVariables(VVAccess.ReadWrite)]
     public bool Airtight = true;
 
     /// <summary>
     /// Whether or not the entitystorage is open or closed
     /// </summary>
-    [DataField("open")]
+    [DataField]
     public bool Open;
 
     /// <summary>
     /// The sound made when closed
     /// </summary>
-    [DataField("closeSound")]
+    [DataField]
     public SoundSpecifier CloseSound = new SoundPathSpecifier("/Audio/Effects/closetclose.ogg");
 
     /// <summary>
     /// The sound made when open
     /// </summary>
-    [DataField("openSound")]
+    [DataField]
     public SoundSpecifier OpenSound = new SoundPathSpecifier("/Audio/Effects/closetopen.ogg");
 
     /// <summary>
     ///     Whitelist for what entities are allowed to be inserted into this container. If this is not null, the
     ///     standard requirement that the entity must be an item or mob is waived.
     /// </summary>
-    [DataField("whitelist")]
+    [DataField]
     public EntityWhitelist? Whitelist;
 
     /// <summary>
index b4c0a639799f3094d156b07eee986a77fd6f79ff..7553fb6c9cc096cdb6f3106877010c42dd57413f 100644 (file)
@@ -15,7 +15,6 @@ using Content.Shared.Storage.Components;
 using Content.Shared.Tools.Systems;
 using Content.Shared.Verbs;
 using Content.Shared.Wall;
-using Content.Shared.Whitelist;
 using Robust.Shared.Containers;
 using Robust.Shared.GameStates;
 using Robust.Shared.Map;
@@ -41,7 +40,7 @@ public abstract class SharedEntityStorageSystem : EntitySystem
     [Dependency] private   readonly SharedJointSystem _joints = default!;
     [Dependency] private   readonly SharedPhysicsSystem _physics = default!;
     [Dependency] protected readonly SharedPopupSystem Popup = default!;
-    [Dependency] private   readonly SharedTransformSystem _transform = default!;
+    [Dependency] protected readonly SharedTransformSystem TransformSystem = default!;
     [Dependency] private   readonly WeldableSystem _weldable = default!;
 
     public const string ContainerName = "entity_storage";
@@ -103,7 +102,7 @@ public abstract class SharedEntityStorageSystem : EntitySystem
     protected void OnDestruction(EntityUid uid, SharedEntityStorageComponent component, DestructionEventArgs args)
     {
         component.Open = true;
-        Dirty(component);
+        Dirty(uid, component);
         if (!component.DeleteContentsOnDestruction)
         {
             EmptyContents(uid, component);
@@ -199,7 +198,7 @@ public abstract class SharedEntityStorageSystem : EntitySystem
         var beforeev = new StorageBeforeOpenEvent();
         RaiseLocalEvent(uid, ref beforeev);
         component.Open = true;
-        Dirty(component);
+        Dirty(uid, component);
         EmptyContents(uid, component);
         ModifyComponents(uid, component);
         if (_net.IsClient && _timing.IsFirstTimePredicted)
@@ -215,7 +214,7 @@ public abstract class SharedEntityStorageSystem : EntitySystem
             return;
 
         component.Open = false;
-        Dirty(component);
+        Dirty(uid, component);
 
         var targetCoordinates = new EntityCoordinates(uid, component.EnteringOffset);
 
@@ -228,7 +227,7 @@ public abstract class SharedEntityStorageSystem : EntitySystem
         {
             if (!ev.BypassChecks.Contains(entity))
             {
-                if (!CanFit(entity, uid, component.Whitelist))
+                if (!CanInsert(entity, uid, component))
                     continue;
             }
 
@@ -256,7 +255,7 @@ public abstract class SharedEntityStorageSystem : EntitySystem
 
         if (component.Open)
         {
-            _transform.SetWorldPosition(toInsert, _transform.GetWorldPosition(container));
+            TransformSystem.SetWorldPosition(toInsert, TransformSystem.GetWorldPosition(container));
             return true;
         }
 
@@ -276,12 +275,12 @@ public abstract class SharedEntityStorageSystem : EntitySystem
 
         RemComp<InsideEntityStorageComponent>(toRemove);
         component.Contents.Remove(toRemove, EntityManager);
-        var pos = _transform.GetWorldPosition(xform) + _transform.GetWorldRotation(xform).RotateVec(component.EnteringOffset);
-        _transform.SetWorldPosition(toRemove, pos);
+        var pos = TransformSystem.GetWorldPosition(xform) + TransformSystem.GetWorldRotation(xform).RotateVec(component.EnteringOffset);
+        TransformSystem.SetWorldPosition(toRemove, pos);
         return true;
     }
 
-    public bool CanInsert(EntityUid container, SharedEntityStorageComponent? component = null)
+    public bool CanInsert(EntityUid toInsert, EntityUid container, SharedEntityStorageComponent? component = null)
     {
         if (!ResolveStorage(container, ref component))
             return false;
@@ -292,7 +291,7 @@ public abstract class SharedEntityStorageSystem : EntitySystem
         if (component.Contents.ContainedEntities.Count >= component.Capacity)
             return false;
 
-        return true;
+        return CanFit(toInsert, container, component);
     }
 
     public bool TryOpenStorage(EntityUid user, EntityUid target, bool silent = false)
@@ -376,8 +375,11 @@ public abstract class SharedEntityStorageSystem : EntitySystem
         return Insert(toAdd, container, component);
     }
 
-    public bool CanFit(EntityUid toInsert, EntityUid container, EntityWhitelist? whitelist)
+    private bool CanFit(EntityUid toInsert, EntityUid container, SharedEntityStorageComponent? component = null)
     {
+        if (!Resolve(container, ref component))
+            return false;
+
         // conditions are complicated because of pizzabox-related issues, so follow this guide
         // 0. Accomplish your goals at all costs.
         // 1. AddToContents can block anything
@@ -395,7 +397,7 @@ public abstract class SharedEntityStorageSystem : EntitySystem
 
         var targetIsMob = HasComp<BodyComponent>(toInsert);
         var storageIsItem = HasComp<ItemComponent>(container);
-        var allowedToEat = whitelist?.IsValid(toInsert) ?? HasComp<ItemComponent>(toInsert);
+        var allowedToEat = component.Whitelist?.IsValid(toInsert) ?? HasComp<ItemComponent>(toInsert);
 
         // BEFORE REPLACING THIS WITH, I.E. A PROPERTY:
         // Make absolutely 100% sure you have worked out how to stop people ending up in backpacks.