diff --git a/Content.Server/Contests/ContestsSystem.cs b/Content.Server/Contests/ContestsSystem.cs index 114b927cdf..5598716280 100644 --- a/Content.Server/Contests/ContestsSystem.cs +++ b/Content.Server/Contests/ContestsSystem.cs @@ -23,7 +23,7 @@ namespace Content.Server.Contests /// public float MassContest(EntityUid roller, EntityUid target, PhysicsComponent? rollerPhysics = null, PhysicsComponent? targetPhysics = null) { - if (!Resolve(roller, ref rollerPhysics) || !Resolve(target, ref targetPhysics)) + if (!Resolve(roller, ref rollerPhysics, false) || !Resolve(target, ref targetPhysics, false)) return 1f; if (rollerPhysics == null || targetPhysics == null) @@ -43,7 +43,7 @@ namespace Content.Server.Contests /// public float DamageContest(EntityUid roller, EntityUid target, DamageableComponent? rollerDamage = null, DamageableComponent? targetDamage = null) { - if (!Resolve(roller, ref rollerDamage) || !Resolve(target, ref targetDamage)) + if (!Resolve(roller, ref rollerDamage, false) || !Resolve(target, ref targetDamage, false)) return 1f; if (rollerDamage == null || targetDamage == null) diff --git a/Content.Server/Resist/CanEscapeInventoryComponent.cs b/Content.Server/Resist/CanEscapeInventoryComponent.cs index dd27b159af..6ba05bfec7 100644 --- a/Content.Server/Resist/CanEscapeInventoryComponent.cs +++ b/Content.Server/Resist/CanEscapeInventoryComponent.cs @@ -6,17 +6,11 @@ namespace Content.Server.Resist; public sealed class CanEscapeInventoryComponent : Component { /// - /// How long it takes to break out of storage. Default at 5 seconds. + /// Base doafter length for uncontested breakouts. /// [ViewVariables] - [DataField("resistTime")] - public float ResistTime = 5f; - - /// - /// For quick exit if the player attempts to move while already resisting - /// - [ViewVariables] - public bool IsResisting = false; + [DataField("baseResistTime")] + public float BaseResistTime = 5f; /// /// Cancellation token used to cancel the DoAfter if the mob is removed before it's complete diff --git a/Content.Server/Resist/EscapeInventorySystem.cs b/Content.Server/Resist/EscapeInventorySystem.cs index bbc7ff0513..47991b19c9 100644 --- a/Content.Server/Resist/EscapeInventorySystem.cs +++ b/Content.Server/Resist/EscapeInventorySystem.cs @@ -1,13 +1,14 @@ -using Content.Shared.Movement; using Content.Server.DoAfter; +using Content.Server.Contests; using Robust.Shared.Containers; using Content.Server.Popups; using Robust.Shared.Player; using Content.Shared.Storage; using Content.Shared.Inventory; -using Content.Shared.Hands.Components; +using Content.Shared.Hands.EntitySystems; using Content.Shared.ActionBlocker; using Content.Shared.Movement.Events; +using Content.Shared.Interaction.Events; namespace Content.Server.Resist; @@ -17,6 +18,13 @@ public sealed class EscapeInventorySystem : EntitySystem [Dependency] private readonly PopupSystem _popupSystem = default!; [Dependency] private readonly SharedContainerSystem _containerSystem = default!; [Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!; + [Dependency] private readonly SharedHandsSystem _handsSystem = default!; + [Dependency] private readonly ContestsSystem _contests = default!; + + /// + /// You can't escape the hands of an entity this many times more massive than you. + /// + public const float MaximumMassDisadvantage = 6f; public override void Initialize() { @@ -26,20 +34,38 @@ public sealed class EscapeInventorySystem : EntitySystem SubscribeLocalEvent(OnMoveAttempt); SubscribeLocalEvent(OnEscapeComplete); SubscribeLocalEvent(OnEscapeFail); + SubscribeLocalEvent(OnDropped); } private void OnRelayMovement(EntityUid uid, CanEscapeInventoryComponent component, ref MoveInputEvent args) { - //Prevents the user from creating multiple DoAfters if they're already resisting. - if (component.IsResisting == true) + if (component.CancelToken != null) return; - if (_containerSystem.TryGetContainingContainer(uid, out var container) - && (HasComp(container.Owner) || HasComp(container.Owner) || HasComp(container.Owner))) + if (!_containerSystem.TryGetContainingContainer(uid, out var container) || !_actionBlockerSystem.CanInteract(uid, container.Owner)) + return; + + // Contested + if (_handsSystem.IsHolding(container.Owner, uid, out var inHand)) { - if (_actionBlockerSystem.CanInteract(uid, container.Owner)) - AttemptEscape(uid, container.Owner, component); + var contestResults = _contests.MassContest(uid, container.Owner); + + // Inverse if we aren't going to divide by 0, otherwise just use a default multiplier of 1. + if (contestResults != 0) + contestResults = 1 / contestResults; + else + contestResults = 1; + + if (contestResults >= MaximumMassDisadvantage) + return; + + AttemptEscape(uid, container.Owner, component, contestResults); + return; } + + // Uncontested + if (HasComp(container.Owner) || HasComp(container.Owner)) + AttemptEscape(uid, container.Owner, component); } private void OnMoveAttempt(EntityUid uid, CanEscapeInventoryComponent component, UpdateCanMoveEvent args) @@ -48,10 +74,10 @@ public sealed class EscapeInventorySystem : EntitySystem args.Cancel(); } - private void AttemptEscape(EntityUid user, EntityUid container, CanEscapeInventoryComponent component) + private void AttemptEscape(EntityUid user, EntityUid container, CanEscapeInventoryComponent component, float multiplier = 1f) { component.CancelToken = new(); - var doAfterEventArgs = new DoAfterEventArgs(user, component.ResistTime, component.CancelToken.Token, container) + var doAfterEventArgs = new DoAfterEventArgs(user, component.BaseResistTime * multiplier, component.CancelToken.Token, container) { BreakOnTargetMove = false, BreakOnUserMove = false, @@ -62,7 +88,6 @@ public sealed class EscapeInventorySystem : EntitySystem UserCancelledEvent = new EscapeDoAfterCancel(), }; - component.IsResisting = true; _popupSystem.PopupEntity(Loc.GetString("escape-inventory-component-start-resisting"), user, Filter.Entities(user)); _popupSystem.PopupEntity(Loc.GetString("escape-inventory-component-start-resisting-target"), container, Filter.Entities(container)); _doAfterSystem.DoAfter(doAfterEventArgs); @@ -72,12 +97,17 @@ public sealed class EscapeInventorySystem : EntitySystem { //Drops the mob on the tile below the container Transform(uid).AttachParentToContainerOrGrid(EntityManager); - component.IsResisting = false; + component.CancelToken = null; } private void OnEscapeFail(EntityUid uid, CanEscapeInventoryComponent component, EscapeDoAfterCancel ev) { - component.IsResisting = false; + component.CancelToken = null; + } + + private void OnDropped(EntityUid uid, CanEscapeInventoryComponent component, DroppedEvent args) + { + component.CancelToken?.Cancel(); } private sealed class EscapeDoAfterComplete : EntityEventArgs { }