Raise an attempt-event when receiving client BUI messages. (#6113)

This commit is contained in:
Leon Friedrich
2022-01-31 04:26:07 +13:00
committed by GitHub
parent 2208a51a1e
commit 83d29ce38d
4 changed files with 47 additions and 41 deletions

View File

@@ -50,6 +50,7 @@ namespace Content.Shared.Interaction
public override void Initialize()
{
SubscribeLocalEvent<BoundUserInterfaceMessageAttempt>(OnBoundInterfaceInteractAttempt);
SubscribeAllEvent<InteractInventorySlotEvent>(HandleInteractInventorySlotEvent);
CommandBinds.Builder
@@ -64,6 +65,30 @@ namespace Content.Shared.Interaction
base.Shutdown();
}
/// <summary>
/// Check that the user that is interacting with the BUI is capable of interacting and can access the entity.
/// </summary>
private void OnBoundInterfaceInteractAttempt(BoundUserInterfaceMessageAttempt ev)
{
if (ev.Sender.AttachedEntity is not EntityUid user || !_actionBlockerSystem.CanInteract(user))
{
ev.Cancel();
return;
}
if (!user.IsInSameOrParentContainer(ev.Target) && !CanAccessViaStorage(user, ev.Target))
{
ev.Cancel();
return;
}
if (!user.InRangeUnobstructed(ev.Target))
{
ev.Cancel();
return;
}
}
/// <summary>
/// Handles the event were a client uses an item in their inventory or in their hands, either by
/// alt-clicking it or pressing 'E' while hovering over it.