Fix misc virtual item issues (#5980)

This commit is contained in:
Leon Friedrich
2022-01-10 17:22:56 +13:00
committed by GitHub
parent 5ceb2372bf
commit 19b1c003e0
7 changed files with 54 additions and 53 deletions

View File

@@ -193,9 +193,12 @@ namespace Content.Client.Hands
hands.Gui.Update(new HandsGuiState(states, hands.ActiveHand)); 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) if (uid == _playerManager.LocalPlayer?.ControlledEntity)
UpdateGui(); UpdateGui();

View File

@@ -1,7 +1,6 @@
using Content.Server.Hands.Components; using Content.Server.Hands.Components;
using Content.Shared.Hands; using Content.Shared.Hands;
using Content.Shared.Hands.Components; using Content.Shared.Hands.Components;
using Content.Shared.Interaction;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
@@ -13,16 +12,6 @@ namespace Content.Server.Hands.Systems
{ {
[Dependency] private readonly SharedHandsSystem _handsSystem = default!; [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) public bool TrySpawnVirtualItemInHand(EntityUid blockingEnt, EntityUid user)
{ {
if (EntityManager.TryGetComponent<HandsComponent>(user, out var hands)) if (EntityManager.TryGetComponent<HandsComponent>(user, out var hands))
@@ -45,39 +34,6 @@ namespace Content.Server.Hands.Systems
return false; 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> /// <summary>
/// Deletes all virtual items in a user's hands with /// Deletes all virtual items in a user's hands with
/// the specified blocked entity. /// the specified blocked entity.

View File

@@ -42,6 +42,7 @@ namespace Content.Server.Hands.Systems
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!; [Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
[Dependency] private readonly AdminLogSystem _logSystem = default!; [Dependency] private readonly AdminLogSystem _logSystem = default!;
[Dependency] private readonly StrippableSystem _strippableSystem = default!; [Dependency] private readonly StrippableSystem _strippableSystem = default!;
[Dependency] private readonly SharedHandVirtualItemSystem _virtualSystem = default!;
public override void Initialize() public override void Initialize()
{ {
@@ -115,6 +116,14 @@ namespace Content.Server.Hands.Systems
RaiseNetworkEvent(new PickupAnimationEvent(item, initialPosition, finalPosition), filter); 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 #endregion
#region pulling #region pulling

View File

@@ -1,4 +1,5 @@
using System; using System;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.GameStates; using Robust.Shared.GameStates;
using Robust.Shared.Players; using Robust.Shared.Players;
@@ -37,6 +38,10 @@ namespace Content.Shared.Hands.Components
return; return;
_blockingEntity = pullState.BlockingEntity; _blockingEntity = pullState.BlockingEntity;
// update hands GUI with new entity.
if (Owner.TryGetContainer(out var containter))
EntitySystem.Get<SharedHandsSystem>().UpdateHandVisuals(containter.Owner);
} }
[Serializable, NetSerializable] [Serializable, NetSerializable]

View File

@@ -1,4 +1,5 @@
using Content.Shared.Hands.Components; using Content.Shared.Hands.Components;
using Content.Shared.Interaction;
using Content.Shared.Inventory.Events; using Content.Shared.Inventory.Events;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
@@ -11,10 +12,33 @@ public abstract class SharedHandVirtualItemSystem : EntitySystem
base.Initialize(); base.Initialize();
SubscribeLocalEvent<HandVirtualItemComponent, BeingEquippedAttemptEvent>(OnBeingEquippedAttempt); SubscribeLocalEvent<HandVirtualItemComponent, BeingEquippedAttemptEvent>(OnBeingEquippedAttempt);
SubscribeLocalEvent<HandVirtualItemComponent, BeforeInteractEvent>(HandleBeforeInteract);
} }
private void OnBeingEquippedAttempt(EntityUid uid, HandVirtualItemComponent component, BeingEquippedAttemptEvent args) private void OnBeingEquippedAttempt(EntityUid uid, HandVirtualItemComponent component, BeingEquippedAttemptEvent args)
{ {
args.Cancel(); args.Cancel();
} }
private static void HandleBeforeInteract(
EntityUid uid,
HandVirtualItemComponent component,
BeforeInteractEvent args)
{
// No interactions with a virtual item, please.
args.Handled = true;
}
/// <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);
}
} }

View File

@@ -24,8 +24,7 @@ namespace Content.Shared.Hands
base.Initialize(); base.Initialize();
SubscribeAllEvent<RequestSetHandEvent>(HandleSetHand); SubscribeAllEvent<RequestSetHandEvent>(HandleSetHand);
SubscribeLocalEvent<SharedHandsComponent, EntRemovedFromContainerMessage>(HandleContainerRemoved);
SubscribeLocalEvent<SharedHandsComponent, EntRemovedFromContainerMessage>(HandleContainerModified);
SubscribeLocalEvent<SharedHandsComponent, EntInsertedIntoContainerMessage>(HandleContainerModified); SubscribeLocalEvent<SharedHandsComponent, EntInsertedIntoContainerMessage>(HandleContainerModified);
CommandBinds.Builder CommandBinds.Builder
@@ -127,18 +126,23 @@ namespace Content.Shared.Hands
public abstract void PickupAnimation(EntityUid item, EntityCoordinates initialPosition, Vector2 finalPosition, public abstract void PickupAnimation(EntityUid item, EntityCoordinates initialPosition, Vector2 finalPosition,
EntityUid? exclude); EntityUid? exclude);
protected virtual void HandleContainerRemoved(EntityUid uid, SharedHandsComponent component, ContainerModifiedMessage args)
{
HandleContainerModified(uid, component, args);
}
#endregion #endregion
#region visuals #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);
} }
/// <summary> /// <summary>
/// Update the In-Hand sprites /// Update the In-Hand sprites
/// </summary> /// </summary>
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)) if (!Resolve(uid, ref handComp, ref appearance, false))
return; return;

View File

@@ -121,7 +121,7 @@ namespace Content.Shared.Item
private void OnEquippedPrefixChange() private void OnEquippedPrefixChange()
{ {
if (Owner.TryGetContainer(out var container)) if (Owner.TryGetContainer(out var container))
EntitySystem.Get<SharedHandsSystem>().UpdateHandVisualizer(container.Owner); EntitySystem.Get<SharedHandsSystem>().UpdateHandVisuals(container.Owner);
} }
public void RemovedFromSlot() public void RemovedFromSlot()