From 19b1c003e076808c7ea19d68f9f24d29c776c9e3 Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Mon, 10 Jan 2022 17:22:56 +1300 Subject: [PATCH] Fix misc virtual item issues (#5980) --- Content.Client/Hands/Systems/HandsSystem.cs | 7 ++- .../Hands/Systems/HandVirtualItemSystem.cs | 44 ------------------- Content.Server/Hands/Systems/HandsSystem.cs | 9 ++++ .../Components/HandVirtualItemComponent.cs | 5 +++ .../Hands/SharedHandVirtualItemSystem.cs | 26 ++++++++++- Content.Shared/Hands/SharedHandsSystem.cs | 14 +++--- Content.Shared/Item/SharedItemComponent.cs | 2 +- 7 files changed, 54 insertions(+), 53 deletions(-) diff --git a/Content.Client/Hands/Systems/HandsSystem.cs b/Content.Client/Hands/Systems/HandsSystem.cs index 6b1b2adfa5..3ae0356649 100644 --- a/Content.Client/Hands/Systems/HandsSystem.cs +++ b/Content.Client/Hands/Systems/HandsSystem.cs @@ -193,9 +193,12 @@ namespace Content.Client.Hands hands.Gui.Update(new HandsGuiState(states, hands.ActiveHand)); } - protected override void HandleContainerModified(EntityUid uid, SharedHandsComponent component, ContainerModifiedMessage args) + public override void UpdateHandVisuals(EntityUid uid, SharedHandsComponent? handComp = null, AppearanceComponent? appearance = null) { - base.HandleContainerModified(uid, component, args); + if (!Resolve(uid, ref handComp, ref appearance, false)) + return; + + base.UpdateHandVisuals(uid, handComp, appearance); if (uid == _playerManager.LocalPlayer?.ControlledEntity) UpdateGui(); diff --git a/Content.Server/Hands/Systems/HandVirtualItemSystem.cs b/Content.Server/Hands/Systems/HandVirtualItemSystem.cs index 0eb368e075..3de0a99d5a 100644 --- a/Content.Server/Hands/Systems/HandVirtualItemSystem.cs +++ b/Content.Server/Hands/Systems/HandVirtualItemSystem.cs @@ -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(HandleItemDropped); - SubscribeLocalEvent(HandleItemUnequipped); - - SubscribeLocalEvent(HandleBeforeInteract); - } - public bool TrySpawnVirtualItemInHand(EntityUid blockingEnt, EntityUid user) { if (EntityManager.TryGetComponent(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); - } - - /// - /// Queues a deletion for a virtual item and notifies the blocking entity and user. - /// - 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); - } - /// /// Deletes all virtual items in a user's hands with /// the specified blocked entity. diff --git a/Content.Server/Hands/Systems/HandsSystem.cs b/Content.Server/Hands/Systems/HandsSystem.cs index fd2f3fff2b..0a0d784aa5 100644 --- a/Content.Server/Hands/Systems/HandsSystem.cs +++ b/Content.Server/Hands/Systems/HandsSystem.cs @@ -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 diff --git a/Content.Shared/Hands/Components/HandVirtualItemComponent.cs b/Content.Shared/Hands/Components/HandVirtualItemComponent.cs index db42caede4..8c7ea64ce4 100644 --- a/Content.Shared/Hands/Components/HandVirtualItemComponent.cs +++ b/Content.Shared/Hands/Components/HandVirtualItemComponent.cs @@ -1,4 +1,5 @@ using System; +using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.GameStates; using Robust.Shared.Players; @@ -37,6 +38,10 @@ namespace Content.Shared.Hands.Components return; _blockingEntity = pullState.BlockingEntity; + + // update hands GUI with new entity. + if (Owner.TryGetContainer(out var containter)) + EntitySystem.Get().UpdateHandVisuals(containter.Owner); } [Serializable, NetSerializable] diff --git a/Content.Shared/Hands/SharedHandVirtualItemSystem.cs b/Content.Shared/Hands/SharedHandVirtualItemSystem.cs index ac3db9d714..57345608e5 100644 --- a/Content.Shared/Hands/SharedHandVirtualItemSystem.cs +++ b/Content.Shared/Hands/SharedHandVirtualItemSystem.cs @@ -1,4 +1,5 @@ -using Content.Shared.Hands.Components; +using Content.Shared.Hands.Components; +using Content.Shared.Interaction; using Content.Shared.Inventory.Events; using Robust.Shared.GameObjects; @@ -11,10 +12,33 @@ public abstract class SharedHandVirtualItemSystem : EntitySystem base.Initialize(); SubscribeLocalEvent(OnBeingEquippedAttempt); + SubscribeLocalEvent(HandleBeforeInteract); } private void OnBeingEquippedAttempt(EntityUid uid, HandVirtualItemComponent component, BeingEquippedAttemptEvent args) { args.Cancel(); } + + private static void HandleBeforeInteract( + EntityUid uid, + HandVirtualItemComponent component, + BeforeInteractEvent args) + { + // No interactions with a virtual item, please. + args.Handled = true; + } + + /// + /// Queues a deletion for a virtual item and notifies the blocking entity and user. + /// + 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); + } } diff --git a/Content.Shared/Hands/SharedHandsSystem.cs b/Content.Shared/Hands/SharedHandsSystem.cs index 67bf3bfc91..81d5f36424 100644 --- a/Content.Shared/Hands/SharedHandsSystem.cs +++ b/Content.Shared/Hands/SharedHandsSystem.cs @@ -24,8 +24,7 @@ namespace Content.Shared.Hands base.Initialize(); SubscribeAllEvent(HandleSetHand); - - SubscribeLocalEvent(HandleContainerModified); + SubscribeLocalEvent(HandleContainerRemoved); SubscribeLocalEvent(HandleContainerModified); CommandBinds.Builder @@ -127,18 +126,23 @@ namespace Content.Shared.Hands public abstract void PickupAnimation(EntityUid item, EntityCoordinates initialPosition, Vector2 finalPosition, EntityUid? exclude); + + protected virtual void HandleContainerRemoved(EntityUid uid, SharedHandsComponent component, ContainerModifiedMessage args) + { + HandleContainerModified(uid, component, args); + } #endregion #region visuals - protected virtual void HandleContainerModified(EntityUid uid, SharedHandsComponent hands, ContainerModifiedMessage args) + private void HandleContainerModified(EntityUid uid, SharedHandsComponent hands, ContainerModifiedMessage args) { - UpdateHandVisualizer(uid, hands); + UpdateHandVisuals(uid, hands); } /// /// Update the In-Hand sprites /// - public void UpdateHandVisualizer(EntityUid uid, SharedHandsComponent? handComp = null, AppearanceComponent? appearance = null) + public virtual void UpdateHandVisuals(EntityUid uid, SharedHandsComponent? handComp = null, AppearanceComponent? appearance = null) { if (!Resolve(uid, ref handComp, ref appearance, false)) return; diff --git a/Content.Shared/Item/SharedItemComponent.cs b/Content.Shared/Item/SharedItemComponent.cs index 34e454b13e..bab87b15b6 100644 --- a/Content.Shared/Item/SharedItemComponent.cs +++ b/Content.Shared/Item/SharedItemComponent.cs @@ -121,7 +121,7 @@ namespace Content.Shared.Item private void OnEquippedPrefixChange() { if (Owner.TryGetContainer(out var container)) - EntitySystem.Get().UpdateHandVisualizer(container.Owner); + EntitySystem.Get().UpdateHandVisuals(container.Owner); } public void RemovedFromSlot()