Delta-v/Content.Server/Nyanotrasen/Item/PseudoItem/PseudoItemSystem.cs

81 lines
2.9 KiB
C#
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Content.Server.Popups;
using Content.Shared.Bed.Sleep;
using Content.Shared._DV.Carrying;
using Content.Shared.IdentityManagement;
using Content.Shared.Item;
using Content.Shared.Nyanotrasen.Item.PseudoItem;
using Content.Shared.Storage;
using Content.Shared.Verbs;
using Content.Server.Hands.Systems;
namespace Content.Server.Nyanotrasen.Item.PseudoItem;
public sealed class PseudoItemSystem : SharedPseudoItemSystem
{
[Dependency] private readonly CarryingSystem _carrying = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly HandsSystem _hands = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<PseudoItemComponent, GetVerbsEvent<AlternativeVerb>>(AddInsertAltVerb);
SubscribeLocalEvent<PseudoItemComponent, TryingToSleepEvent>(OnTrySleeping);
}
private void AddInsertAltVerb(EntityUid uid, PseudoItemComponent component, GetVerbsEvent<AlternativeVerb> args)
{
if (!args.CanInteract || !args.CanAccess)
return;
if (component.Active)
return;
if (!TryComp<StorageComponent>(args.Using, out var targetStorage))
return;
if (!CheckItemFits((uid, component), (args.Using.Value, targetStorage)))
return;
var activeItem = _hands.GetActiveItem(args.User);
if (!activeItem.HasValue || activeItem != args.Using)
return;
AlternativeVerb verb = new()
{
Act = () =>
{
StartInsertDoAfter(args.User, uid, activeItem.Value, component);
},
Text = Loc.GetString("action-name-insert-other", ("target", Identity.Entity(args.Target, EntityManager))),
Priority = 2
};
args.Verbs.Add(verb);
}
protected override void OnGettingPickedUpAttempt(EntityUid uid, PseudoItemComponent component, GettingPickedUpAttemptEvent args)
{
// Floof - changed this a bit to actually start a do-after
// Try to pick the entity up instead first
if (args.User != args.Item
&& TryComp<CarriableComponent>(uid, out var carriable)
&& _carrying.CanCarry(args.User, (uid, carriable)))
{
_carrying.StartCarryDoAfter(args.User, (uid, carriable));
args.Cancel();
return;
}
// If could not pick up, just take it out onto the ground as per default
base.OnGettingPickedUpAttempt(uid, component, args);
}
// Show a popup when a pseudo-item falls asleep inside a bag.
private void OnTrySleeping(EntityUid uid, PseudoItemComponent component, TryingToSleepEvent args)
{
var parent = Transform(uid).ParentUid;
if (!HasComp<SleepingComponent>(uid) && parent is { Valid: true } && HasComp<AllowsSleepInsideComponent>(parent))
_popup.PopupEntity(Loc.GetString("popup-sleep-in-bag", ("entity", uid)), uid);
}
}