2022-05-12 03:58:27 -04:00
|
|
|
using Content.Server.Popups;
|
2023-10-19 12:34:31 -07:00
|
|
|
using Content.Server.Storage.Components;
|
2022-05-19 11:29:02 -04:00
|
|
|
using Content.Shared.ActionBlocker;
|
2023-02-24 19:01:25 -05:00
|
|
|
using Content.Shared.DoAfter;
|
2023-10-19 12:34:31 -07:00
|
|
|
using Content.Shared.Hands.EntitySystems;
|
2022-08-10 04:37:20 -04:00
|
|
|
using Content.Shared.Interaction.Events;
|
2023-10-19 12:34:31 -07:00
|
|
|
using Content.Shared.Inventory;
|
|
|
|
|
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 Content.Shared.Storage;
|
|
|
|
|
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!;
|
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;
|
|
|
|
|
|
2022-08-10 04:37:20 -04: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
|
2023-09-11 21:20:46 +10: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
|
|
|
}
|
|
|
|
|
|
2022-08-10 04:37:20 -04:00
|
|
|
private 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;
|
|
|
|
|
|
2023-09-11 09:42:41 +10:00
|
|
|
var doAfterEventArgs = new DoAfterArgs(EntityManager, user, component.BaseResistTime * multiplier, new EscapeInventoryEvent(), user, target: container)
|
2022-05-12 03:58:27 -04:00
|
|
|
{
|
|
|
|
|
BreakOnTargetMove = false,
|
2023-02-28 19:51:42 -05:00
|
|
|
BreakOnUserMove = 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);
|
|
|
|
|
_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-10-19 12:34:31 -07:00
|
|
|
_containerSystem.AttachParentToContainerOrGrid((uid, Transform(uid)));
|
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
|
|
|
}
|
2022-05-12 03:58:27 -04:00
|
|
|
}
|