* Merge BreakOnWeightlessMove and BreakOnMove. Provide different theshold for weightless movement. * Adjust WeightlessMovementThresholds. Put a thing I forgot to put in the doafterargs. * Make DoAfterArgs only use OnMove to determine whether to check for movement and MoveThreshold to determine the threshold regardless of weightlessness. Gave DistanceThreshold a default value which will always be checked now. * Fix issue introduced by merge. * Use interaction system for determining whether a distance is within range * Fix incorrect doafter args introduced by previous merge. Forgor to commit these. * Exorcise ghost. The execution system should have been deleted when I merged previously. For a reason I cannot comprehend it came back, but only the execution system. * Exorcise ghost Pt. 2 * Allow for movement check to be overriden in zero g and adjust doafter args where needed. You can now override checking for movement in zero g with the BreakOnWeightlessMove bool. By default it will check. The following doafters were made to ignore the movement check in zero g: - Healing yourself with healing items, - Removing embedded projectiles, - Using tools like welders and crowbars * Adjust distance for cuffing/uncuffing to work. Make injections not break on weightless movement. * Fix evil incorrect and uneeded comments
95 lines
3.5 KiB
C#
95 lines
3.5 KiB
C#
using Content.Server.Popups;
|
|
using Content.Server.Storage.Components;
|
|
using Content.Shared.ActionBlocker;
|
|
using Content.Shared.DoAfter;
|
|
using Content.Shared.Hands.EntitySystems;
|
|
using Content.Shared.Interaction.Events;
|
|
using Content.Shared.Inventory;
|
|
using Content.Shared.Movement.Events;
|
|
using Content.Shared.Resist;
|
|
using Content.Shared.Storage;
|
|
using Robust.Shared.Containers;
|
|
|
|
namespace Content.Server.Resist;
|
|
|
|
public sealed class EscapeInventorySystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
|
|
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
|
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
|
|
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
|
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<CanEscapeInventoryComponent, MoveInputEvent>(OnRelayMovement);
|
|
SubscribeLocalEvent<CanEscapeInventoryComponent, EscapeInventoryEvent>(OnEscape);
|
|
SubscribeLocalEvent<CanEscapeInventoryComponent, DroppedEvent>(OnDropped);
|
|
}
|
|
|
|
private void OnRelayMovement(EntityUid uid, CanEscapeInventoryComponent component, ref MoveInputEvent args)
|
|
{
|
|
if (!args.HasDirectionalMovement)
|
|
return;
|
|
|
|
if (!_containerSystem.TryGetContainingContainer(uid, out var container) || !_actionBlockerSystem.CanInteract(uid, container.Owner))
|
|
return;
|
|
|
|
// 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;
|
|
}
|
|
|
|
// Contested
|
|
if (_handsSystem.IsHolding(container.Owner, uid, out _))
|
|
{
|
|
AttemptEscape(uid, container.Owner, component);
|
|
return;
|
|
}
|
|
|
|
// Uncontested
|
|
if (HasComp<StorageComponent>(container.Owner) || HasComp<InventoryComponent>(container.Owner) || HasComp<SecretStashComponent>(container.Owner))
|
|
AttemptEscape(uid, container.Owner, component);
|
|
}
|
|
|
|
private void AttemptEscape(EntityUid user, EntityUid container, CanEscapeInventoryComponent component, float multiplier = 1f)
|
|
{
|
|
if (component.IsEscaping)
|
|
return;
|
|
|
|
var doAfterEventArgs = new DoAfterArgs(EntityManager, user, component.BaseResistTime * multiplier, new EscapeInventoryEvent(), user, target: container)
|
|
{
|
|
BreakOnMove = true,
|
|
BreakOnDamage = true,
|
|
NeedHand = false
|
|
};
|
|
|
|
if (!_doAfterSystem.TryStartDoAfter(doAfterEventArgs, out component.DoAfter))
|
|
return;
|
|
|
|
_popupSystem.PopupEntity(Loc.GetString("escape-inventory-component-start-resisting"), user, user);
|
|
_popupSystem.PopupEntity(Loc.GetString("escape-inventory-component-start-resisting-target"), container, container);
|
|
}
|
|
|
|
private void OnEscape(EntityUid uid, CanEscapeInventoryComponent component, EscapeInventoryEvent args)
|
|
{
|
|
component.DoAfter = null;
|
|
|
|
if (args.Handled || args.Cancelled)
|
|
return;
|
|
|
|
_containerSystem.AttachParentToContainerOrGrid((uid, Transform(uid)));
|
|
args.Handled = true;
|
|
}
|
|
|
|
private void OnDropped(EntityUid uid, CanEscapeInventoryComponent component, DroppedEvent args)
|
|
{
|
|
if (component.DoAfter != null)
|
|
_doAfterSystem.Cancel(component.DoAfter);
|
|
}
|
|
}
|