Skip to content

Commit

Permalink
Carrying & PseudoItem != 0 now.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mnemotechnician committed Jan 20, 2024
1 parent 2d255e1 commit 739f3f9
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 8 deletions.
68 changes: 60 additions & 8 deletions Content.Server/Nyanotrasen/Carrying/CarryingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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()
{
Expand All @@ -64,6 +68,7 @@ public override void Initialize()
SubscribeLocalEvent<BeingCarriedComponent, StartClimbEvent>(OnStartClimb);
SubscribeLocalEvent<BeingCarriedComponent, BuckleChangeEvent>(OnBuckleChange);
SubscribeLocalEvent<CarriableComponent, CarryDoAfterEvent>(OnDoAfter);
SubscribeLocalEvent<CarryingComponent, GetVerbsEvent<InnateVerb>>(AddInsertCarriedVerb); // Frontier
}


Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<BeingCarriedComponent>(carrier) || HasComp<ItemComponent>(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<InnateVerb> args)
{
var toInsert = args.Using;
if (toInsert is not { Valid: true } || !args.CanAccess || !TryComp<PseudoItemComponent>(toInsert, out var pseudoItem))
return;

if (!TryComp<StorageComponent>(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);
}
}
}
13 changes: 13 additions & 0 deletions Content.Server/Nyanotrasen/Item/PseudoItem/PseudoItemSystem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Server.Carrying;
using Content.Server.DoAfter;
using Content.Server.Storage.EntitySystems;
using Content.Shared.DoAfter;
Expand All @@ -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<TagPrototype>]
private const string PreventTag = "PreventLabel";
Expand Down Expand Up @@ -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<ItemComponent>(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();
}
Expand Down

0 comments on commit 739f3f9

Please sign in to comment.