Skip to content

Commit

Permalink
Remove instant cryobed insertion (#34619)
Browse files Browse the repository at this point in the history
* added optional delay to DragInsertContainerComponent

* comments

* Change EntryDelay on DragInsertContainerComponent to use TimeSpan + cleanup

* changed drag insert container comp to match naming conventions
  • Loading branch information
Booblesnoot42 authored Feb 5, 2025
1 parent 214fb24 commit ded6b46
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
12 changes: 12 additions & 0 deletions Content.Shared/Containers/DragInsertContainerComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,16 @@ public sealed partial class DragInsertContainerComponent : Component
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public bool UseVerbs = true;

/// <summary>
/// The delay in seconds before a drag will be completed.
/// </summary>
[DataField]
public TimeSpan EntryDelay = TimeSpan.Zero;

/// <summary>
/// If entry delay isn't zero, this sets whether an entity dragging itself into the container should be delayed.
/// </summary>
[DataField]
public bool DelaySelfEntry = false;
}
40 changes: 38 additions & 2 deletions Content.Shared/Containers/DragInsertContainerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,28 @@
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<DragInsertContainerComponent, DragDropTargetEvent>(OnDragDropOn, before: new []{ typeof(ClimbSystem)});
SubscribeLocalEvent<DragInsertContainerComponent, DragInsertContainerDoAfterEvent>(OnDragFinished);
SubscribeLocalEvent<DragInsertContainerComponent, CanDropTargetEvent>(OnCanDragDropOn);
SubscribeLocalEvent<DragInsertContainerComponent, GetVerbsEvent<AlternativeVerb>>(OnGetAlternativeVerb);
}
Expand All @@ -33,7 +37,34 @@ private void OnDragDropOn(Entity<DragInsertContainerComponent> ent, ref DragDrop
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<DragInsertContainerComponent> 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<DragInsertContainerComponent> ent, ref CanDropTargetEvent args)
Expand Down Expand Up @@ -117,4 +148,9 @@ public bool Insert(EntityUid target, EntityUid user, EntityUid containerEntity,
_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
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
canCollide: false
- type: DragInsertContainer
containerId: storage
entryDelay: 2
- type: ExitContainerOnMove
containerId: storage
- type: PointLight
Expand Down

0 comments on commit ded6b46

Please sign in to comment.