Make parcelwrap able to wrap humanoids (#40911)

* parcel

* help, I'm being forced to add admin abuse features

* review
This commit is contained in:
slarticodefast
2025-10-15 22:19:34 +02:00
committed by GitHub
parent 7755009fe3
commit 9562e009bf
10 changed files with 192 additions and 77 deletions

View File

@@ -1,7 +1,9 @@
using Content.Shared.DoAfter;
using Content.Shared.IdentityManagement;
using Content.Shared.Interaction;
using Content.Shared.Item;
using Content.Shared.ParcelWrap.Components;
using Content.Shared.Popups;
using Content.Shared.Verbs;
using Robust.Shared.Utility;
@@ -59,9 +61,26 @@ public sealed partial class ParcelWrappingSystem
private bool TryStartWrapDoAfter(EntityUid user, Entity<ParcelWrapComponent> wrapper, EntityUid target)
{
var duration = wrapper.Comp.WrapDelay;
if (TryComp<ParcelWrapOverrideComponent>(target, out var overrideComp) && overrideComp.WrapDelay != null)
duration = overrideComp.WrapDelay.Value;
// In case the target is a player inform them with a popup.
if (target == user)
{
var selfMsg = Loc.GetString("parcel-wrap-popup-being-wrapped-self");
_popup.PopupClient(selfMsg, user, user);
}
else
{
var othersMsg = Loc.GetString("parcel-wrap-popup-being-wrapped", ("user", Identity.Entity(user, EntityManager)));
_popup.PopupEntity(othersMsg, target, target, PopupType.MediumCaution);
}
return _doAfter.TryStartDoAfter(new DoAfterArgs(EntityManager,
user,
wrapper.Comp.WrapDelay,
duration,
new ParcelWrapItemDoAfterEvent(),
wrapper, // Raise the event on the wrapper because that's what the event handler expects.
target,
@@ -81,18 +100,34 @@ public sealed partial class ParcelWrappingSystem
/// <param name="target">The entity being wrapped.</param>
private void WrapInternal(EntityUid user, Entity<ParcelWrapComponent> wrapper, EntityUid target)
{
if (_net.IsServer)
// Consume a `use` on the wrapper, and delete the wrapper if it's empty.
_charges.TryUseCharges(wrapper.Owner, 1);
if (_charges.IsEmpty(wrapper.Owner))
PredictedQueueDel(wrapper);
// Play a wrapping sound.
_audio.PlayPredicted(wrapper.Comp.WrapSound, target, user);
if (_net.IsClient)
return; // Predicted spawns can't be interacted with yet.
EntityUid spawned;
var targetTransform = Transform(target);
// Check if the target has a pre-defined parcel type to be used.
if (TryComp<ParcelWrapOverrideComponent>(target, out var overrideComp))
{
var spawned = Spawn(wrapper.Comp.ParcelPrototype, Transform(target).Coordinates);
spawned = Spawn(overrideComp.ParcelPrototype, targetTransform.Coordinates);
}
else // Create a parcel with the same size and generic sprites instead.
{
spawned = Spawn(wrapper.Comp.ParcelPrototype, targetTransform.Coordinates);
// If this wrap maintains the size when wrapping, set the parcel's size to the target's size. Otherwise use the
// wrap's fallback size.
TryComp(target, out ItemComponent? targetItemComp);
var size = wrapper.Comp.FallbackItemSize;
if (wrapper.Comp.WrappedItemsMaintainSize && targetItemComp is not null)
{
size = targetItemComp.Size;
}
// ParcelWrap's spawned entity should always have an `ItemComp`. As of writing, the only use has it hardcoded on
// its prototype.
@@ -103,33 +138,28 @@ public sealed partial class ParcelWrappingSystem
// If this wrap maintains the shape when wrapping and the item has a shape override, copy the shape override to
// the parcel.
if (wrapper.Comp.WrappedItemsMaintainShape && targetItemComp is { Shape: { } shape })
{
_item.SetShape(spawned, shape, item);
}
// If the target's in a container, try to put the parcel in its place in the container.
if (_container.TryGetContainingContainer((target, null, null), out var containerOfTarget))
{
_container.Remove(target, containerOfTarget);
_container.InsertOrDrop((spawned, null, null), containerOfTarget);
}
// Insert the target into the parcel.
var parcel = EnsureComp<WrappedParcelComponent>(spawned);
if (!_container.Insert(target, parcel.Contents))
{
DebugTools.Assert(
$"Failed to insert target entity into newly spawned parcel. target={PrettyPrint.PrintUserFacing(target)}");
QueueDel(spawned);
}
}
// Consume a `use` on the wrapper, and delete the wrapper if it's empty.
_charges.TryUseCharges(wrapper.Owner, 1);
if (_net.IsServer && _charges.IsEmpty(wrapper.Owner))
QueueDel(wrapper);
_transform.SetLocalRotation(spawned, targetTransform.LocalRotation);
// Play a wrapping sound.
_audio.PlayPredicted(wrapper.Comp.WrapSound, target, user);
// If the target is in a container, try to put the parcel in its place in the container.
if (_container.TryGetContainingContainer((target, null, null), out var containerOfTarget))
{
_container.Remove(target, containerOfTarget);
_container.InsertOrDrop((spawned, null, null), containerOfTarget);
}
// Insert the target into the parcel.
var parcel = EnsureComp<WrappedParcelComponent>(spawned);
parcel.CanSelfUnwrap = wrapper.Comp.CanSelfUnwrap;
Dirty(spawned, parcel);
if (!_container.Insert(target, parcel.Contents))
{
DebugTools.Assert(
$"Failed to insert target entity into newly spawned parcel. target={PrettyPrint.PrintUserFacing(target)}");
PredictedDel(spawned);
}
}
}