]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Weight based AreaInsert and Dumpable delay, a janitor qol tweak (#24899)
authorKrunklehorn <42424291+Krunklehorn@users.noreply.github.com>
Sat, 2 Mar 2024 13:57:44 +0000 (08:57 -0500)
committerGitHub <noreply@github.com>
Sat, 2 Mar 2024 13:57:44 +0000 (00:57 +1100)
Weight based delay, retuned average, fixed comments

Content.Shared/Storage/Components/DumpableComponent.cs
Content.Shared/Storage/EntitySystems/DumpableSystem.cs
Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs
Content.Shared/Storage/StorageComponent.cs

index f10a935fb9250053ca9c797f90963c308da9db7b..ecf5f17ea99464fb0207e951590a0a4b6bdfe4d6 100644 (file)
@@ -1,4 +1,5 @@
 using Content.Shared.DoAfter;
+using Content.Shared.Storage.EntitySystems;
 using Robust.Shared.Audio;
 using Robust.Shared.GameStates;
 using Robust.Shared.Serialization;
@@ -24,7 +25,7 @@ public sealed partial class DumpableComponent : Component
     /// How long each item adds to the doafter.
     /// </summary>
     [DataField("delayPerItem"), AutoNetworkedField]
-    public TimeSpan DelayPerItem = TimeSpan.FromSeconds(0.2);
+    public TimeSpan DelayPerItem = TimeSpan.FromSeconds(SharedStorageSystem.AreaInsertDelayPerItem);
 
     /// <summary>
     /// The multiplier modifier
index c87174ba88c41d08a54802fbc05aae6eb2bb1051..04f7231416f39601d39e71e528ee6ce7541b06cb 100644 (file)
@@ -2,11 +2,13 @@ using System.Linq;
 using Content.Shared.Disposal;
 using Content.Shared.DoAfter;
 using Content.Shared.Interaction;
+using Content.Shared.Item;
 using Content.Shared.Placeable;
 using Content.Shared.Storage.Components;
 using Content.Shared.Verbs;
 using Robust.Shared.Audio.Systems;
 using Robust.Shared.Containers;
+using Robust.Shared.Prototypes;
 using Robust.Shared.Random;
 using Robust.Shared.Utility;
 
@@ -14,6 +16,7 @@ namespace Content.Shared.Storage.EntitySystems;
 
 public sealed class DumpableSystem : EntitySystem
 {
+    [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
     [Dependency] private readonly IRobustRandom _random = default!;
     [Dependency] private readonly SharedAudioSystem _audio = default!;
     [Dependency] private readonly SharedContainerSystem _container = default!;
@@ -113,7 +116,20 @@ public sealed class DumpableSystem : EntitySystem
         if (!TryComp<StorageComponent>(storageUid, out var storage))
             return;
 
-        var delay = storage.Container.ContainedEntities.Count * (float) dumpable.DelayPerItem.TotalSeconds * dumpable.Multiplier;
+        var delay = 0f;
+
+        foreach (var entity in storage.Container.ContainedEntities)
+        {
+            if (!TryComp<ItemComponent>(entity, out var itemComp) ||
+                !_prototypeManager.TryIndex(itemComp.Size, out var itemSize))
+            {
+                continue;
+            }
+
+            delay += itemSize.Weight;
+        }
+
+        delay *= (float) dumpable.DelayPerItem.TotalSeconds * dumpable.Multiplier;
 
         _doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, userUid, delay, new DumpableDoAfterEvent(), storageUid, target: targetUid, used: storageUid)
         {
index 4be2b59ecef2ed51518d4ec075d8c89b2fc54acd..c26419998604c77f3a3b5469f9da1a57d856a7a8 100644 (file)
@@ -54,6 +54,8 @@ public abstract class SharedStorageSystem : EntitySystem
     [ValidatePrototypeId<ItemSizePrototype>]
     public const string DefaultStorageMaxItemSize = "Normal";
 
+    public const float AreaInsertDelayPerItem = 0.075f;
+
     private ItemSizePrototype _defaultStorageMaxItemSize = default!;
 
     public bool CheckingCanInsert;
@@ -258,11 +260,14 @@ public abstract class SharedStorageSystem : EntitySystem
         if (storageComp.AreaInsert && (args.Target == null || !HasComp<ItemComponent>(args.Target.Value)))
         {
             var validStorables = new List<EntityUid>();
+            var delay = 0f;
 
             foreach (var entity in _entityLookupSystem.GetEntitiesInRange(args.ClickLocation, storageComp.AreaInsertRadius, LookupFlags.Dynamic | LookupFlags.Sundries))
             {
                 if (entity == args.User
-                    || !_itemQuery.HasComponent(entity)
+                    // || !_itemQuery.HasComponent(entity)
+                    || !TryComp<ItemComponent>(entity, out var itemComp) // Need comp to get item size to get weight
+                    || !_prototype.TryIndex(itemComp.Size, out var itemSize)
                     || !CanInsert(uid, entity, out _, storageComp)
                     || !_interactionSystem.InRangeUnobstructed(args.User, entity))
                 {
@@ -270,12 +275,13 @@ public abstract class SharedStorageSystem : EntitySystem
                 }
 
                 validStorables.Add(entity);
+                delay += itemSize.Weight * AreaInsertDelayPerItem;
             }
 
             //If there's only one then let's be generous
             if (validStorables.Count > 1)
             {
-                var doAfterArgs = new DoAfterArgs(EntityManager, args.User, 0.2f * validStorables.Count, new AreaPickupDoAfterEvent(GetNetEntityList(validStorables)), uid, target: uid)
+                var doAfterArgs = new DoAfterArgs(EntityManager, args.User, delay, new AreaPickupDoAfterEvent(GetNetEntityList(validStorables)), uid, target: uid)
                 {
                     BreakOnDamage = true,
                     BreakOnUserMove = true,
index 35f7955349cf3dd03ec3722592fcc6e1c217f8fc..98e80de0253ddd83c4076963598f35632fc1a7f0 100644 (file)
@@ -47,13 +47,13 @@ namespace Content.Shared.Storage
 
         // TODO: Make area insert its own component.
         [DataField]
-        public bool QuickInsert; // Can insert storables by "attacking" them with the storage entity
+        public bool QuickInsert; // Can insert storables by clicking them with the storage entity
 
         [DataField]
         public bool ClickInsert = true; // Can insert stuff by clicking the storage entity with it
 
         [DataField]
-        public bool AreaInsert;  // "Attacking" with the storage entity causes it to insert all nearby storables after a delay
+        public bool AreaInsert; // Clicking with the storage entity causes it to insert all nearby storables after a delay
 
         [DataField]
         public int AreaInsertRadius = 1;