Fix misc virtual item issues (#5980)
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
using Content.Server.Hands.Components;
|
||||
using Content.Shared.Hands;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -13,16 +12,6 @@ namespace Content.Server.Hands.Systems
|
||||
{
|
||||
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<HandVirtualItemComponent, DroppedEvent>(HandleItemDropped);
|
||||
SubscribeLocalEvent<HandVirtualItemComponent, UnequippedHandEvent>(HandleItemUnequipped);
|
||||
|
||||
SubscribeLocalEvent<HandVirtualItemComponent, BeforeInteractEvent>(HandleBeforeInteract);
|
||||
}
|
||||
|
||||
public bool TrySpawnVirtualItemInHand(EntityUid blockingEnt, EntityUid user)
|
||||
{
|
||||
if (EntityManager.TryGetComponent<HandsComponent>(user, out var hands))
|
||||
@@ -45,39 +34,6 @@ namespace Content.Server.Hands.Systems
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void HandleBeforeInteract(
|
||||
EntityUid uid,
|
||||
HandVirtualItemComponent component,
|
||||
BeforeInteractEvent args)
|
||||
{
|
||||
// No interactions with a virtual item, please.
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
// If the virtual item gets removed from the hands for any reason, cancel the pull and delete it.
|
||||
private void HandleItemUnequipped(EntityUid uid, HandVirtualItemComponent component, UnequippedHandEvent args)
|
||||
{
|
||||
Delete(component, args.User);
|
||||
}
|
||||
|
||||
private void HandleItemDropped(EntityUid uid, HandVirtualItemComponent component, DroppedEvent args)
|
||||
{
|
||||
Delete(component, args.UserUid);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Queues a deletion for a virtual item and notifies the blocking entity and user.
|
||||
/// </summary>
|
||||
public void Delete(HandVirtualItemComponent comp, EntityUid user)
|
||||
{
|
||||
var userEv = new VirtualItemDeletedEvent(comp.BlockingEntity, user);
|
||||
RaiseLocalEvent(user, userEv, false);
|
||||
var targEv = new VirtualItemDeletedEvent(comp.BlockingEntity, user);
|
||||
RaiseLocalEvent(comp.BlockingEntity, targEv, false);
|
||||
|
||||
EntityManager.QueueDeleteEntity(comp.Owner);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes all virtual items in a user's hands with
|
||||
/// the specified blocked entity.
|
||||
|
||||
@@ -42,6 +42,7 @@ namespace Content.Server.Hands.Systems
|
||||
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
||||
[Dependency] private readonly AdminLogSystem _logSystem = default!;
|
||||
[Dependency] private readonly StrippableSystem _strippableSystem = default!;
|
||||
[Dependency] private readonly SharedHandVirtualItemSystem _virtualSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -115,6 +116,14 @@ namespace Content.Server.Hands.Systems
|
||||
|
||||
RaiseNetworkEvent(new PickupAnimationEvent(item, initialPosition, finalPosition), filter);
|
||||
}
|
||||
|
||||
protected override void HandleContainerRemoved(EntityUid uid, SharedHandsComponent component, ContainerModifiedMessage args)
|
||||
{
|
||||
if (!Deleted(args.Entity) && TryComp(args.Entity, out HandVirtualItemComponent? @virtual))
|
||||
_virtualSystem.Delete(@virtual, uid);
|
||||
|
||||
base.HandleContainerRemoved(uid, component, args);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region pulling
|
||||
|
||||
Reference in New Issue
Block a user