2024-03-27 16:56:45 +07:00
|
|
|
using Content.Server._White.Carrying;
|
2022-05-12 03:58:27 -04:00
|
|
|
using Content.Server.Popups;
|
2024-03-31 04:21:18 +01:00
|
|
|
using Content.Shared.Storage.Components;
|
2023-05-10 01:11:06 +06:00
|
|
|
using Content.Shared.Storage;
|
|
|
|
|
using Content.Shared.Inventory;
|
|
|
|
|
using Content.Shared.Hands.EntitySystems;
|
2022-05-19 11:29:02 -04:00
|
|
|
using Content.Shared.ActionBlocker;
|
2023-02-24 19:01:25 -05:00
|
|
|
using Content.Shared.DoAfter;
|
2022-08-10 04:37:20 -04:00
|
|
|
using Content.Shared.Interaction.Events;
|
2023-10-19 12:34:31 -07:00
|
|
|
using Content.Shared.Movement.Events;
|
2023-04-03 13:13:48 +12:00
|
|
|
using Content.Shared.Resist;
|
2023-10-19 12:34:31 -07:00
|
|
|
using Robust.Shared.Containers;
|
2022-05-12 03:58:27 -04:00
|
|
|
|
|
|
|
|
namespace Content.Server.Resist;
|
|
|
|
|
|
|
|
|
|
public sealed class EscapeInventorySystem : EntitySystem
|
|
|
|
|
{
|
2023-04-03 13:13:48 +12:00
|
|
|
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
|
2022-05-12 03:58:27 -04:00
|
|
|
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
|
|
|
|
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
|
2022-05-19 11:29:02 -04:00
|
|
|
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
2022-08-10 04:37:20 -04:00
|
|
|
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
|
2023-05-10 01:11:06 +06:00
|
|
|
[Dependency] private readonly CarryingSystem _carryingSystem = default!;
|
2022-08-10 04:37:20 -04:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// You can't escape the hands of an entity this many times more massive than you.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public const float MaximumMassDisadvantage = 6f;
|
2022-05-12 03:58:27 -04:00
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
2022-07-16 13:51:52 +10:00
|
|
|
SubscribeLocalEvent<CanEscapeInventoryComponent, MoveInputEvent>(OnRelayMovement);
|
2023-04-03 13:13:48 +12:00
|
|
|
SubscribeLocalEvent<CanEscapeInventoryComponent, EscapeInventoryEvent>(OnEscape);
|
2022-08-10 04:37:20 -04:00
|
|
|
SubscribeLocalEvent<CanEscapeInventoryComponent, DroppedEvent>(OnDropped);
|
2022-05-12 03:58:27 -04:00
|
|
|
}
|
|
|
|
|
|
2022-07-16 13:51:52 +10:00
|
|
|
private void OnRelayMovement(EntityUid uid, CanEscapeInventoryComponent component, ref MoveInputEvent args)
|
2022-05-12 03:58:27 -04:00
|
|
|
{
|
2024-02-02 21:14:20 -05:00
|
|
|
if (!args.HasDirectionalMovement)
|
|
|
|
|
return;
|
|
|
|
|
|
2024-03-27 16:56:45 +07:00
|
|
|
if (!_containerSystem.TryGetContainingContainer(uid, out var container) ||
|
|
|
|
|
!_actionBlockerSystem.CanInteract(uid, container.Owner))
|
2022-05-12 03:58:27 -04:00
|
|
|
return;
|
|
|
|
|
|
2024-01-25 09:01:13 -05:00
|
|
|
// Make sure there's nothing stopped the removal (like being glued)
|
|
|
|
|
if (!_containerSystem.CanRemove(uid, container))
|
|
|
|
|
{
|
|
|
|
|
_popupSystem.PopupEntity(Loc.GetString("escape-inventory-component-failed-resisting"), uid, uid);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-10 04:37:20 -04:00
|
|
|
// Contested
|
2024-02-21 17:39:52 +11:00
|
|
|
if (_handsSystem.IsHolding(container.Owner, uid, out _))
|
2022-05-12 03:58:27 -04:00
|
|
|
{
|
2024-02-21 17:39:52 +11:00
|
|
|
AttemptEscape(uid, container.Owner, component);
|
2022-08-10 04:37:20 -04:00
|
|
|
return;
|
2022-05-12 03:58:27 -04:00
|
|
|
}
|
2022-08-10 04:37:20 -04:00
|
|
|
|
|
|
|
|
// Uncontested
|
2024-03-27 16:56:45 +07:00
|
|
|
if (HasComp<StorageComponent>(container.Owner) || HasComp<InventoryComponent>(container.Owner) ||
|
|
|
|
|
HasComp<SecretStashComponent>(container.Owner))
|
2022-08-10 04:37:20 -04:00
|
|
|
AttemptEscape(uid, container.Owner, component);
|
2022-05-12 03:58:27 -04:00
|
|
|
}
|
|
|
|
|
|
2024-03-27 16:56:45 +07:00
|
|
|
public void AttemptEscape(
|
|
|
|
|
EntityUid user,
|
|
|
|
|
EntityUid container,
|
|
|
|
|
CanEscapeInventoryComponent component,
|
|
|
|
|
float multiplier = 1f)
|
2022-05-12 03:58:27 -04:00
|
|
|
{
|
2023-02-28 19:51:42 -05:00
|
|
|
if (component.IsEscaping)
|
|
|
|
|
return;
|
|
|
|
|
|
2024-03-27 16:56:45 +07:00
|
|
|
var doAfterEventArgs = new DoAfterArgs(EntityManager, user, component.BaseResistTime * multiplier,
|
|
|
|
|
new EscapeInventoryEvent(), user, target: container)
|
2022-05-12 03:58:27 -04:00
|
|
|
{
|
2024-03-19 12:09:00 +02:00
|
|
|
BreakOnMove = true,
|
2022-05-12 03:58:27 -04:00
|
|
|
BreakOnDamage = true,
|
2023-02-24 19:01:25 -05:00
|
|
|
NeedHand = false
|
2022-05-12 03:58:27 -04:00
|
|
|
};
|
|
|
|
|
|
2023-04-03 13:13:48 +12:00
|
|
|
if (!_doAfterSystem.TryStartDoAfter(doAfterEventArgs, out component.DoAfter))
|
|
|
|
|
return;
|
|
|
|
|
|
2022-12-19 10:41:47 +13:00
|
|
|
_popupSystem.PopupEntity(Loc.GetString("escape-inventory-component-start-resisting"), user, user);
|
2024-03-27 16:56:45 +07:00
|
|
|
_popupSystem.PopupEntity(Loc.GetString("escape-inventory-component-start-resisting-target"), container,
|
|
|
|
|
container);
|
2022-05-12 03:58:27 -04:00
|
|
|
}
|
|
|
|
|
|
2023-04-03 13:13:48 +12:00
|
|
|
private void OnEscape(EntityUid uid, CanEscapeInventoryComponent component, EscapeInventoryEvent args)
|
2022-05-12 03:58:27 -04:00
|
|
|
{
|
2023-04-03 13:13:48 +12:00
|
|
|
component.DoAfter = null;
|
2023-02-28 19:51:42 -05:00
|
|
|
|
2023-04-03 13:13:48 +12:00
|
|
|
if (args.Handled || args.Cancelled)
|
2023-02-24 19:01:25 -05:00
|
|
|
return;
|
|
|
|
|
|
2023-05-10 01:11:06 +06:00
|
|
|
if (TryComp<BeingCarriedComponent>(uid, out var carried))
|
|
|
|
|
{
|
|
|
|
|
_carryingSystem.DropCarried(carried.Carrier, uid);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-19 12:34:31 -07:00
|
|
|
_containerSystem.AttachParentToContainerOrGrid((uid, Transform(uid)));
|
2023-05-10 01:11:06 +06:00
|
|
|
|
2023-02-24 19:01:25 -05:00
|
|
|
args.Handled = true;
|
2022-08-10 04:37:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnDropped(EntityUid uid, CanEscapeInventoryComponent component, DroppedEvent args)
|
|
|
|
|
{
|
2023-04-03 13:13:48 +12:00
|
|
|
if (component.DoAfter != null)
|
|
|
|
|
_doAfterSystem.Cancel(component.DoAfter);
|
2023-02-24 19:01:25 -05:00
|
|
|
}
|
2024-03-27 16:56:45 +07:00
|
|
|
}
|