Pulled item interaction fix (#34587)
This commit is contained in:
@@ -188,11 +188,13 @@ public abstract partial class SharedHandsSystem : EntitySystem
|
|||||||
if (args.Handled)
|
if (args.Handled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// TODO: this pattern is super uncommon, but it might be worth changing GetUsedEntityEvent to be recursive.
|
if (component.ActiveHandEntity.HasValue)
|
||||||
if (TryComp<VirtualItemComponent>(component.ActiveHandEntity, out var virtualItem))
|
{
|
||||||
args.Used = virtualItem.BlockingEntity;
|
// allow for the item to return a different entity, e.g. virtual items
|
||||||
else
|
RaiseLocalEvent(component.ActiveHandEntity.Value, ref args);
|
||||||
args.Used = component.ActiveHandEntity;
|
}
|
||||||
|
|
||||||
|
args.Used ??= component.ActiveHandEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Actually shows all items/clothing/etc.
|
//TODO: Actually shows all items/clothing/etc.
|
||||||
|
|||||||
@@ -1413,7 +1413,7 @@ namespace Content.Shared.Interaction
|
|||||||
/// <returns>If there is an entity being used.</returns>
|
/// <returns>If there is an entity being used.</returns>
|
||||||
public bool TryGetUsedEntity(EntityUid user, [NotNullWhen(true)] out EntityUid? used, bool checkCanUse = true)
|
public bool TryGetUsedEntity(EntityUid user, [NotNullWhen(true)] out EntityUid? used, bool checkCanUse = true)
|
||||||
{
|
{
|
||||||
var ev = new GetUsedEntityEvent();
|
var ev = new GetUsedEntityEvent(user);
|
||||||
RaiseLocalEvent(user, ref ev);
|
RaiseLocalEvent(user, ref ev);
|
||||||
|
|
||||||
used = ev.Used;
|
used = ev.Used;
|
||||||
@@ -1464,8 +1464,9 @@ namespace Content.Shared.Interaction
|
|||||||
/// Raised directed by-ref on an entity to determine what item will be used in interactions.
|
/// Raised directed by-ref on an entity to determine what item will be used in interactions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ByRefEvent]
|
[ByRefEvent]
|
||||||
public record struct GetUsedEntityEvent()
|
public record struct GetUsedEntityEvent(EntityUid User)
|
||||||
{
|
{
|
||||||
|
public EntityUid User = User;
|
||||||
public EntityUid? Used = null;
|
public EntityUid? Used = null;
|
||||||
|
|
||||||
public bool Handled => Used != null;
|
public bool Handled => Used != null;
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ public abstract class SharedVirtualItemSystem : EntitySystem
|
|||||||
|
|
||||||
SubscribeLocalEvent<VirtualItemComponent, BeforeRangedInteractEvent>(OnBeforeRangedInteract);
|
SubscribeLocalEvent<VirtualItemComponent, BeforeRangedInteractEvent>(OnBeforeRangedInteract);
|
||||||
SubscribeLocalEvent<VirtualItemComponent, GettingInteractedWithAttemptEvent>(OnGettingInteractedWithAttemptEvent);
|
SubscribeLocalEvent<VirtualItemComponent, GettingInteractedWithAttemptEvent>(OnGettingInteractedWithAttemptEvent);
|
||||||
|
|
||||||
|
SubscribeLocalEvent<VirtualItemComponent, GetUsedEntityEvent>(OnGetUsedEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -81,6 +83,23 @@ public abstract class SharedVirtualItemSystem : EntitySystem
|
|||||||
args.Cancelled = true;
|
args.Cancelled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnGetUsedEntity(Entity<VirtualItemComponent> ent, ref GetUsedEntityEvent args)
|
||||||
|
{
|
||||||
|
if (args.Handled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// if the user is holding the real item the virtual item points to,
|
||||||
|
// we allow them to use it in the interaction
|
||||||
|
foreach (var hand in _handsSystem.EnumerateHands(args.User))
|
||||||
|
{
|
||||||
|
if (hand.HeldEntity == ent.Comp.BlockingEntity)
|
||||||
|
{
|
||||||
|
args.Used = ent.Comp.BlockingEntity;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#region Hands
|
#region Hands
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user