diff --git a/Content.Server/Nyanotrasen/Carrying/CarryingSystem.cs b/Content.Server/Nyanotrasen/Carrying/CarryingSystem.cs index 2cd608716b7..2ef6bc4712c 100644 --- a/Content.Server/Nyanotrasen/Carrying/CarryingSystem.cs +++ b/Content.Server/Nyanotrasen/Carrying/CarryingSystem.cs @@ -6,6 +6,7 @@ using Content.Server.Resist; using Content.Server.Popups; using Content.Server.Contests; +using Content.Server.Item.PseudoItem; using Content.Shared.Climbing; // Shared instead of Server using Content.Shared.Mobs; using Content.Shared.DoAfter; @@ -23,11 +24,14 @@ using Content.Shared.Pulling.Components; using Content.Shared.Standing; using Content.Shared.ActionBlocker; +using Content.Shared.Item; +using Content.Shared.Item.PseudoItem; using Content.Shared.Mind.Components; using Content.Shared.Throwing; using Content.Shared.Physics.Pull; using Content.Shared.Mobs.Systems; using Content.Shared.Popups; +using Content.Shared.Storage; using Robust.Shared.Map.Components; namespace Content.Server.Carrying @@ -45,7 +49,7 @@ public sealed class CarryingSystem : EntitySystem [Dependency] private readonly PopupSystem _popupSystem = default!; [Dependency] private readonly ContestsSystem _contests = default!; [Dependency] private readonly MovementSpeedModifierSystem _movementSpeed = default!; - [Dependency] private readonly RespiratorSystem _respirator = default!; + [Dependency] private readonly PseudoItemSystem _pseudoItem = default!; public override void Initialize() { @@ -64,6 +68,7 @@ public override void Initialize() SubscribeLocalEvent(OnStartClimb); SubscribeLocalEvent(OnBuckleChange); SubscribeLocalEvent(OnDoAfter); + SubscribeLocalEvent>(AddInsertCarriedVerb); // Frontier } @@ -217,13 +222,7 @@ private void OnDoAfter(EntityUid uid, CarriableComponent component, CarryDoAfter private void StartCarryDoAfter(EntityUid carrier, EntityUid carried, CarriableComponent component) { - TimeSpan length = TimeSpan.FromSeconds(3); - - var mod = _contests.MassContest(carrier, carried); - - if (mod != 0) - length /= mod; - + var length = GetPickupDuration(carrier, carried); // Frontier: instead of in-line calculation, use a separate function if (length >= TimeSpan.FromSeconds(9)) { _popupSystem.PopupEntity(Loc.GetString("carry-too-heavy"), carried, carrier, Shared.Popups.PopupType.SmallCaution); @@ -344,5 +343,58 @@ public override void Update(float frameTime) } query.Dispose(); } + + public TimeSpan GetPickupDuration(EntityUid carrier, EntityUid carried) + { + TimeSpan length = TimeSpan.FromSeconds(3); + + var mod = _contests.MassContest(carrier, carried); + if (mod != 0) + length /= mod; + + return length; + } + + public bool TryCarry(EntityUid carrier, EntityUid toCarry, CarriableComponent? carriedComp = null) + { + if (!Resolve(toCarry, ref carriedComp, false)) + return false; + + if (!CanCarry(carrier, toCarry, carriedComp)) + return false; + + // The second one means that carrier *is also* inside a bag. + if (HasComp(carrier) || HasComp(carrier)) + return false; + + if (GetPickupDuration(carrier, toCarry) > TimeSpan.FromSeconds(9)) + return false; + + Carry(carrier, toCarry); + + return true; + } + + private void AddInsertCarriedVerb(EntityUid uid, CarryingComponent component, GetVerbsEvent args) + { + var toInsert = args.Using; + if (toInsert is not { Valid: true } || !args.CanAccess || !TryComp(toInsert, out var pseudoItem)) + return; + + if (!TryComp(args.Target, out var storage) || storage.StorageUsed + pseudoItem.Size > storage.StorageCapacityMax) + return; + + InnateVerb verb = new() + { + Act = () => + { + DropCarried(uid, toInsert.Value); + _pseudoItem.TryInsert(args.Target, toInsert.Value, pseudoItem, storage); + }, + Text = Loc.GetString("action-name-insert-other", ("target", toInsert)), + Priority = 2 + }; + args.Verbs.Add(verb); + } } } diff --git a/Content.Server/Nyanotrasen/Item/PseudoItem/PseudoItemSystem.cs b/Content.Server/Nyanotrasen/Item/PseudoItem/PseudoItemSystem.cs index 9f5bd596d76..9d4b3def87a 100644 --- a/Content.Server/Nyanotrasen/Item/PseudoItem/PseudoItemSystem.cs +++ b/Content.Server/Nyanotrasen/Item/PseudoItem/PseudoItemSystem.cs @@ -1,3 +1,4 @@ +using Content.Server.Carrying; using Content.Server.DoAfter; using Content.Server.Storage.EntitySystems; using Content.Shared.DoAfter; @@ -18,6 +19,7 @@ public sealed class PseudoItemSystem : EntitySystem [Dependency] private readonly ItemSystem _itemSystem = default!; [Dependency] private readonly DoAfterSystem _doAfter = default!; [Dependency] private readonly TagSystem _tagSystem = default!; + [Dependency] private readonly CarryingSystem _carrying = default!; [ValidatePrototypeId] private const string PreventTag = "PreventLabel"; @@ -104,6 +106,17 @@ private void OnGettingPickedUpAttempt(EntityUid uid, PseudoItemComponent compone if (args.User == args.Item) return; + // Frontier: prevent people from pushing each other from a bag + if (HasComp(args.User)) + return; + + // Frontier: try to carry the person when taking them out of a bag. + if (_carrying.TryCarry(args.User, uid)) + { + args.Cancel(); + return; + } + Transform(uid).AttachToGridOrMap(); args.Cancel(); }