Skip to content

Commit

Permalink
Prevent pseudoitems from being transferred between bags (#553)
Browse files Browse the repository at this point in the history
* Update PseudoItemSystem.cs

* Rider full cleanup

* Also abort in sharedstorage

* Make the comp shared

* Why drop the bags?
  • Loading branch information
DebugOk authored Dec 29, 2023
1 parent 2246b2e commit 985b2f9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
38 changes: 26 additions & 12 deletions Content.Server/Nyanotrasen/Item/PseudoItem/PseudoItemSystem.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
using System.Threading;
using Content.Shared.Verbs;
using Content.Shared.Item;
using Content.Shared.Hands;
using Content.Server.DoAfter;
using Content.Server.Storage.EntitySystems;
using Content.Shared.DoAfter;
using Content.Shared.Hands;
using Content.Shared.IdentityManagement;
using Content.Shared.Item;
using Content.Shared.Item.PseudoItem;
using Content.Shared.Storage;
using Content.Server.Storage.EntitySystems;
using Content.Server.DoAfter;
using Content.Shared.Tag;
using Content.Shared.Verbs;
using Robust.Shared.Containers;

namespace Content.Server.Item.PseudoItem;
public sealed partial class PseudoItemSystem : EntitySystem

public sealed class PseudoItemSystem : EntitySystem
{
[Dependency] private readonly StorageSystem _storageSystem = default!;
[Dependency] private readonly ItemSystem _itemSystem = default!;
Expand All @@ -31,6 +31,7 @@ public override void Initialize()
SubscribeLocalEvent<PseudoItemComponent, GettingPickedUpAttemptEvent>(OnGettingPickedUpAttempt);
SubscribeLocalEvent<PseudoItemComponent, DropAttemptEvent>(OnDropAttempt);
SubscribeLocalEvent<PseudoItemComponent, PseudoItemInsertDoAfterEvent>(OnDoAfter);
SubscribeLocalEvent<PseudoItemComponent, ContainerGettingInsertedAttemptEvent>(OnInsertAttempt);
}

private void AddInsertVerb(EntityUid uid, PseudoItemComponent component, GetVerbsEvent<InnateVerb> args)
Expand Down Expand Up @@ -97,7 +98,8 @@ private void OnEntRemoved(EntityUid uid, PseudoItemComponent component, EntGotRe
component.Active = false;
}

private void OnGettingPickedUpAttempt(EntityUid uid, PseudoItemComponent component, GettingPickedUpAttemptEvent args)
private void OnGettingPickedUpAttempt(EntityUid uid, PseudoItemComponent component,
GettingPickedUpAttemptEvent args)
{
if (args.User == args.Item)
return;
Expand All @@ -111,6 +113,7 @@ private void OnDropAttempt(EntityUid uid, PseudoItemComponent component, DropAtt
if (component.Active)
args.Cancel();
}

private void OnDoAfter(EntityUid uid, PseudoItemComponent component, DoAfterEvent args)
{
if (args.Handled || args.Cancelled || args.Args.Used == null)
Expand All @@ -119,7 +122,8 @@ private void OnDoAfter(EntityUid uid, PseudoItemComponent component, DoAfterEven
args.Handled = TryInsert(args.Args.Used.Value, uid, component);
}

public bool TryInsert(EntityUid storageUid, EntityUid toInsert, PseudoItemComponent component, StorageComponent? storage = null)
public bool TryInsert(EntityUid storageUid, EntityUid toInsert, PseudoItemComponent component,
StorageComponent? storage = null)
{
if (!Resolve(storageUid, ref storage))
return false;
Expand All @@ -139,16 +143,17 @@ public bool TryInsert(EntityUid storageUid, EntityUid toInsert, PseudoItemCompon
}

component.Active = true;
Transform(storageUid).AttachToGridOrMap();
return true;
}
private void StartInsertDoAfter(EntityUid inserter, EntityUid toInsert, EntityUid storageEntity, PseudoItemComponent? pseudoItem = null)

private void StartInsertDoAfter(EntityUid inserter, EntityUid toInsert, EntityUid storageEntity,
PseudoItemComponent? pseudoItem = null)
{
if (!Resolve(toInsert, ref pseudoItem))
return;

var ev = new PseudoItemInsertDoAfterEvent();
var args = new DoAfterArgs(EntityManager, inserter, 5f, ev, toInsert, target: toInsert, used: storageEntity)
var args = new DoAfterArgs(EntityManager, inserter, 5f, ev, toInsert, toInsert, storageEntity)
{
BreakOnTargetMove = true,
BreakOnUserMove = true,
Expand All @@ -157,4 +162,13 @@ private void StartInsertDoAfter(EntityUid inserter, EntityUid toInsert, EntityUi

_doAfter.TryStartDoAfter(args);
}

private void OnInsertAttempt(EntityUid uid, PseudoItemComponent component,
ContainerGettingInsertedAttemptEvent args)
{
if (!component.Active)
return;
// This hopefully shouldn't trigger, but this is a failsafe just in case so we dont bluespace them cats
args.Cancel();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

namespace Content.Server.Item.PseudoItem;
namespace Content.Shared.Item.PseudoItem;

/// <summary>
/// For entities that behave like an item under certain conditions,
Expand Down
4 changes: 4 additions & 0 deletions Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Content.Shared.Implants.Components;
using Content.Shared.Interaction;
using Content.Shared.Item;
using Content.Shared.Item.PseudoItem;
using Content.Shared.Lock;
using Content.Shared.Placeable;
using Content.Shared.Popups;
Expand Down Expand Up @@ -439,6 +440,9 @@ public void TransferEntities(EntityUid source, EntityUid target, EntityUid? user

foreach (var entity in entities.ToArray())
{
if (HasComp<PseudoItemComponent>(entity)) // Nyanotrasen - They dont transfer properly
continue;

Insert(target, entity, out _, user: user, targetComp, playSound: false);
}

Expand Down

0 comments on commit 985b2f9

Please sign in to comment.