Enable verbs for items in storage and prevent orphaned nested UIs (#5512)

This commit is contained in:
Leon Friedrich
2021-11-29 12:25:22 +13:00
committed by GitHub
parent 3601416f72
commit 22ee9f5e83
9 changed files with 190 additions and 86 deletions

View File

@@ -13,12 +13,14 @@ using Content.Shared.Throwing;
using Content.Shared.Timing;
using Content.Shared.Verbs;
using JetBrains.Annotations;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Players;
using Robust.Shared.Random;
using Robust.Shared.Serialization;
@@ -33,7 +35,6 @@ namespace Content.Shared.Interaction
public abstract class SharedInteractionSystem : EntitySystem
{
[Dependency] private readonly SharedPhysicsSystem _sharedBroadphaseSystem = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
[Dependency] private readonly SharedVerbSystem _verbSystem = default!;
[Dependency] private readonly SharedAdminLogSystem _adminLogSystem = default!;
@@ -454,6 +455,11 @@ namespace Content.Shared.Interaction
if (!InRangeUnobstructed(user, used, ignoreInsideBlocker: true, popup: true))
return;
// Check if interacted entity is in the same container, the direct child, or direct parent of the user.
// This is bypassed IF the interaction happened through an item slot (e.g., backpack UI)
if (!user.IsInSameOrParentContainer(used) && !CanAccessViaStorage(user.Uid, used.Uid))
return;
var activateMsg = new ActivateInWorldEvent(user, used);
RaiseLocalEvent(used.Uid, activateMsg);
if (activateMsg.Handled)
@@ -529,17 +535,9 @@ namespace Content.Shared.Interaction
public void AltInteract(IEntity user, IEntity target)
{
// Get list of alt-interact verbs
GetAlternativeVerbsEvent getVerbEvent = new(user, target);
RaiseLocalEvent(target.Uid, getVerbEvent);
foreach (var verb in getVerbEvent.Verbs)
{
if (verb.Disabled)
continue;
_verbSystem.ExecuteVerb(verb, user.Uid, target.Uid);
break;
}
var verbs = _verbSystem.GetLocalVerbs(target, user, VerbType.Alternative)[VerbType.Alternative];
if (verbs.Any())
_verbSystem.ExecuteVerb(verbs.First(), user.Uid, target.Uid);
}
#endregion
@@ -733,6 +731,13 @@ namespace Content.Shared.Interaction
}
}
#endregion
/// <summary>
/// If a target is in range, but not in the same container as the user, it may be inside of a backpack. This
/// checks if the user can access the item in these situations.
/// </summary>
public abstract bool CanAccessViaStorage(EntityUid user, EntityUid target);
#endregion
}