From ded6b46b80ac299fd9c018807280ad0c8cd48e50 Mon Sep 17 00:00:00 2001
From: Booblesnoot42 <108703193+Booblesnoot42@users.noreply.github.com>
Date: Wed, 5 Feb 2025 09:46:21 -0500
Subject: [PATCH] Remove instant cryobed insertion (#34619)
* added optional delay to DragInsertContainerComponent
* comments
* Change EntryDelay on DragInsertContainerComponent to use TimeSpan + cleanup
* changed drag insert container comp to match naming conventions
---
.../DragInsertContainerComponent.cs | 12 ++++++
.../Containers/DragInsertContainerSystem.cs | 40 ++++++++++++++++++-
.../Structures/cryogenic_sleep_unit.yml | 1 +
3 files changed, 51 insertions(+), 2 deletions(-)
diff --git a/Content.Shared/Containers/DragInsertContainerComponent.cs b/Content.Shared/Containers/DragInsertContainerComponent.cs
index e4cae26fcb..23cf3f6558 100644
--- a/Content.Shared/Containers/DragInsertContainerComponent.cs
+++ b/Content.Shared/Containers/DragInsertContainerComponent.cs
@@ -17,4 +17,16 @@ public sealed partial class DragInsertContainerComponent : Component
///
[DataField, ViewVariables(VVAccess.ReadWrite)]
public bool UseVerbs = true;
+
+ ///
+ /// The delay in seconds before a drag will be completed.
+ ///
+ [DataField]
+ public TimeSpan EntryDelay = TimeSpan.Zero;
+
+ ///
+ /// If entry delay isn't zero, this sets whether an entity dragging itself into the container should be delayed.
+ ///
+ [DataField]
+ public bool DelaySelfEntry = false;
}
diff --git a/Content.Shared/Containers/DragInsertContainerSystem.cs b/Content.Shared/Containers/DragInsertContainerSystem.cs
index b7f5eb500b..8ccf003703 100644
--- a/Content.Shared/Containers/DragInsertContainerSystem.cs
+++ b/Content.Shared/Containers/DragInsertContainerSystem.cs
@@ -2,24 +2,28 @@ using Content.Shared.ActionBlocker;
using Content.Shared.Administration.Logs;
using Content.Shared.Climbing.Systems;
using Content.Shared.Database;
+using Content.Shared.DoAfter;
using Content.Shared.DragDrop;
using Content.Shared.Verbs;
using Robust.Shared.Containers;
+using Robust.Shared.Serialization;
namespace Content.Shared.Containers;
-public sealed class DragInsertContainerSystem : EntitySystem
+public sealed partial class DragInsertContainerSystem : EntitySystem
{
[Dependency] private readonly ISharedAdminLogManager _adminLog = default!;
[Dependency] private readonly ActionBlockerSystem _actionBlocker = default!;
[Dependency] private readonly ClimbSystem _climb = default!;
[Dependency] private readonly SharedContainerSystem _container = default!;
+ [Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent(OnDragDropOn, before: new []{ typeof(ClimbSystem)});
+ SubscribeLocalEvent(OnDragFinished);
SubscribeLocalEvent(OnCanDragDropOn);
SubscribeLocalEvent>(OnGetAlternativeVerb);
}
@@ -33,7 +37,34 @@ public sealed class DragInsertContainerSystem : EntitySystem
if (!_container.TryGetContainer(ent, comp.ContainerId, out var container))
return;
- args.Handled = Insert(args.Dragged, args.User, ent, container);
+ if (comp.EntryDelay <= TimeSpan.Zero ||
+ !comp.DelaySelfEntry && args.User == args.Dragged)
+ {
+ //instant insertion
+ args.Handled = Insert(args.Dragged, args.User, ent, container);
+ return;
+ }
+
+ //delayed insertion
+ var doAfterArgs = new DoAfterArgs(EntityManager, args.User, comp.EntryDelay, new DragInsertContainerDoAfterEvent(), ent, args.Dragged, ent)
+ {
+ BreakOnDamage = true,
+ BreakOnMove = true,
+ NeedHand = false,
+ };
+ _doAfter.TryStartDoAfter(doAfterArgs);
+ args.Handled = true;
+ }
+
+ private void OnDragFinished(Entity ent, ref DragInsertContainerDoAfterEvent args)
+ {
+ if (args.Handled || args.Cancelled || args.Args.Target == null)
+ return;
+
+ if (!_container.TryGetContainer(ent, ent.Comp.ContainerId, out var container))
+ return;
+
+ Insert(args.Args.Target.Value, args.User, ent, container);
}
private void OnCanDragDropOn(Entity ent, ref CanDropTargetEvent args)
@@ -117,4 +148,9 @@ public sealed class DragInsertContainerSystem : EntitySystem
_adminLog.Add(LogType.Action, LogImpact.Medium, $"{ToPrettyString(user):player} inserted {ToPrettyString(target):player} into container {ToPrettyString(containerEntity)}");
return true;
}
+
+ [Serializable, NetSerializable]
+ public sealed partial class DragInsertContainerDoAfterEvent : SimpleDoAfterEvent
+ {
+ }
}
diff --git a/Resources/Prototypes/Entities/Structures/cryogenic_sleep_unit.yml b/Resources/Prototypes/Entities/Structures/cryogenic_sleep_unit.yml
index e9e9294e63..6ba988dc80 100644
--- a/Resources/Prototypes/Entities/Structures/cryogenic_sleep_unit.yml
+++ b/Resources/Prototypes/Entities/Structures/cryogenic_sleep_unit.yml
@@ -25,6 +25,7 @@
canCollide: false
- type: DragInsertContainer
containerId: storage
+ entryDelay: 2
- type: ExitContainerOnMove
containerId: storage
- type: PointLight