Fix misc virtual item issues (#5980)
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<SharedHandsSystem>().UpdateHandVisuals(containter.Owner);
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
|
||||
@@ -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<HandVirtualItemComponent, BeingEquippedAttemptEvent>(OnBeingEquippedAttempt);
|
||||
SubscribeLocalEvent<HandVirtualItemComponent, BeforeInteractEvent>(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;
|
||||
}
|
||||
|
||||
/// <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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,8 +24,7 @@ namespace Content.Shared.Hands
|
||||
base.Initialize();
|
||||
|
||||
SubscribeAllEvent<RequestSetHandEvent>(HandleSetHand);
|
||||
|
||||
SubscribeLocalEvent<SharedHandsComponent, EntRemovedFromContainerMessage>(HandleContainerModified);
|
||||
SubscribeLocalEvent<SharedHandsComponent, EntRemovedFromContainerMessage>(HandleContainerRemoved);
|
||||
SubscribeLocalEvent<SharedHandsComponent, EntInsertedIntoContainerMessage>(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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the In-Hand sprites
|
||||
/// </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))
|
||||
return;
|
||||
|
||||
@@ -121,7 +121,7 @@ namespace Content.Shared.Item
|
||||
private void OnEquippedPrefixChange()
|
||||
{
|
||||
if (Owner.TryGetContainer(out var container))
|
||||
EntitySystem.Get<SharedHandsSystem>().UpdateHandVisualizer(container.Owner);
|
||||
EntitySystem.Get<SharedHandsSystem>().UpdateHandVisuals(container.Owner);
|
||||
}
|
||||
|
||||
public void RemovedFromSlot()
|
||||
|
||||
Reference in New Issue
Block a user