Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PseudoItems #821

Merged
merged 3 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using Content.Shared.Nyanotrasen.Item.PseudoItem;

namespace Content.Client.Nyanotrasen.Item.PseudoItem;

public sealed class PseudoItemSystem : SharedPseudoItemSystem
{
}
206 changes: 44 additions & 162 deletions Content.Server/Nyanotrasen/Item/PseudoItem/PseudoItemSystem.cs
Original file line number Diff line number Diff line change
@@ -1,174 +1,56 @@
using Content.Server.DoAfter;
using Content.Server.DoAfter;
using Content.Server.Item;
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.Nyanotrasen.Item.PseudoItem;
using Content.Shared.Storage;
using Content.Shared.Tag;
using Content.Shared.Verbs;
using Robust.Shared.Containers;

namespace Content.Server.Item.PseudoItem;
namespace Content.Server.Nyanotrasen.Item.PseudoItem;

public sealed class PseudoItemSystem : EntitySystem
public sealed class PseudoItemSystem : SharedPseudoItemSystem
{
// [Dependency] private readonly StorageSystem _storageSystem = default!;
// [Dependency] private readonly ItemSystem _itemSystem = default!;
// [Dependency] private readonly DoAfterSystem _doAfter = default!;
// [Dependency] private readonly TagSystem _tagSystem = default!;
//
// [ValidatePrototypeId<TagPrototype>]
// private const string PreventTag = "PreventLabel";
//
// public override void Initialize()
// {
// base.Initialize();
// SubscribeLocalEvent<PseudoItemComponent, GetVerbsEvent<InnateVerb>>(AddInsertVerb);
// SubscribeLocalEvent<PseudoItemComponent, GetVerbsEvent<AlternativeVerb>>(AddInsertAltVerb);
// SubscribeLocalEvent<PseudoItemComponent, EntGotRemovedFromContainerMessage>(OnEntRemoved);
// 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)
// {
// if (!args.CanInteract || !args.CanAccess)
// return;
//
// if (component.Active)
// return;
//
// if (!TryComp<StorageComponent>(args.Target, out var targetStorage))
// return;
//
// if (component.Size > targetStorage.StorageCapacityMax - targetStorage.StorageUsed)
// return;
//
// if (Transform(args.Target).ParentUid == uid)
// return;
//
// InnateVerb verb = new()
// {
// Act = () =>
// {
// TryInsert(args.Target, uid, component, targetStorage);
// },
// Text = Loc.GetString("action-name-insert-self"),
// Priority = 2
// };
// args.Verbs.Add(verb);
// }
//
// private void AddInsertAltVerb(EntityUid uid, PseudoItemComponent component, GetVerbsEvent<AlternativeVerb> args)
// {
// if (!args.CanInteract || !args.CanAccess)
// return;
//
// if (args.User == args.Target)
// return;
//
// if (args.Hands == null)
// return;
//
// if (!TryComp<StorageComponent>(args.Hands.ActiveHandEntity, out var targetStorage))
// return;
//
// AlternativeVerb verb = new()
// {
// Act = () =>
// {
// StartInsertDoAfter(args.User, uid, args.Hands.ActiveHandEntity.Value, component);
// },
// Text = Loc.GetString("action-name-insert-other", ("target", Identity.Entity(args.Target, EntityManager))),
// Priority = 2
// };
// args.Verbs.Add(verb);
// }
//
// private void OnEntRemoved(EntityUid uid, PseudoItemComponent component, EntGotRemovedFromContainerMessage args)
// {
// if (!component.Active)
// return;
//
// RemComp<ItemComponent>(uid);
// component.Active = false;
// }
//
// private void OnGettingPickedUpAttempt(EntityUid uid, PseudoItemComponent component,
// GettingPickedUpAttemptEvent args)
// {
// if (args.User == args.Item)
// return;
//
// Transform(uid).AttachToGridOrMap();
// args.Cancel();
// }
//
// private void OnDropAttempt(EntityUid uid, PseudoItemComponent component, DropAttemptEvent args)
// {
// if (component.Active)
// args.Cancel();
// }
//
// private void OnDoAfter(EntityUid uid, PseudoItemComponent component, DoAfterEvent args)
// {
// if (args.Handled || args.Cancelled || args.Args.Used == null)
// return;
//
// args.Handled = TryInsert(args.Args.Used.Value, uid, component);
// }
//
// public bool TryInsert(EntityUid storageUid, EntityUid toInsert, PseudoItemComponent component,
// StorageComponent? storage = null)
// {
// if (!Resolve(storageUid, ref storage))
// return false;
//
// if (component.Size > storage.StorageCapacityMax - storage.StorageUsed)
// return false;
//
// var item = EnsureComp<ItemComponent>(toInsert);
// _tagSystem.TryAddTag(toInsert, PreventTag);
// _itemSystem.SetSize(toInsert, component.Size, item);
//
// if (!_storageSystem.Insert(storageUid, toInsert, out _, null, storage))
// {
// component.Active = false;
// RemComp<ItemComponent>(toInsert);
// return false;
// }
//
// component.Active = true;
// return true;
// }
//
// 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, toInsert, storageEntity)
// {
// BreakOnTargetMove = true,
// BreakOnUserMove = true,
// NeedHand = true
// };
//
// _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();
// }
[Dependency] private readonly StorageSystem _storage = default!;
[Dependency] private readonly ItemSystem _item = default!;
[Dependency] private readonly DoAfterSystem _doAfter = default!;


public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<PseudoItemComponent, GetVerbsEvent<AlternativeVerb>>(AddInsertAltVerb);
}

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;

if (args.Hands?.ActiveHandEntity == null)
return;

AlternativeVerb verb = new()
{
Act = () =>
{
StartInsertDoAfter(args.User, uid, args.Hands.ActiveHandEntity.Value, component);
},
Text = Loc.GetString("action-name-insert-other", ("target", Identity.Entity(args.Target, EntityManager))),
Priority = 2
};
args.Verbs.Add(verb);
}
}
5 changes: 3 additions & 2 deletions Content.Shared/Item/ItemComponent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Shared.Hands.Components;
using Content.Shared.Nyanotrasen.Item.PseudoItem;
DebugOk marked this conversation as resolved.
Show resolved Hide resolved
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
Expand All @@ -12,11 +13,11 @@ namespace Content.Shared.Item;
/// </summary>
[RegisterComponent]
[NetworkedComponent]
[Access(typeof(SharedItemSystem)), AutoGenerateComponentState(true)]
[Access(typeof(SharedItemSystem), typeof(SharedPseudoItemSystem)), AutoGenerateComponentState(true)] // DeltaV - Gave PseudoItem access
public sealed partial class ItemComponent : Component
{
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
[Access(typeof(SharedItemSystem))]
[Access(typeof(SharedItemSystem), typeof(SharedPseudoItemSystem))] // DeltaV - Gave PseudoItem access
public ProtoId<ItemSizePrototype> Size = "Small";

[Access(typeof(SharedItemSystem))]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

using Content.Shared.Item;
using Robust.Shared.Prototypes;

namespace Content.Shared.Nyanotrasen.Item.Components;
namespace Content.Shared.Nyanotrasen.Item.PseudoItem;

/// <summary>
/// For entities that behave like an item under certain conditions,
Expand All @@ -21,5 +20,8 @@ public sealed partial class PseudoItemComponent : Component
[DataField, AutoNetworkedField]
public List<Box2i>? Shape;

[DataField, AutoNetworkedField]
public Vector2i StoredOffset;

public bool Active = false;
}
Loading
Loading