2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.ActionBlocker;
|
|
|
|
|
using Content.Shared.Interaction;
|
2022-09-29 15:51:59 +10:00
|
|
|
using Content.Shared.Storage;
|
2019-05-16 15:51:26 +02:00
|
|
|
using JetBrains.Annotations;
|
2020-06-18 22:52:44 +10:00
|
|
|
using Robust.Server.GameObjects;
|
2020-07-07 01:00:29 +02:00
|
|
|
using Robust.Shared.Containers;
|
2023-10-29 04:21:02 +11:00
|
|
|
using Robust.Shared.Player;
|
2018-02-05 13:57:26 -06:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Interaction
|
2018-02-05 13:57:26 -06:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Governs interactions during clicking on entities
|
|
|
|
|
/// </summary>
|
2019-05-16 15:51:26 +02:00
|
|
|
[UsedImplicitly]
|
2022-09-13 23:52:36 +10:00
|
|
|
public sealed partial class InteractionSystem : SharedInteractionSystem
|
2018-02-05 13:57:26 -06:00
|
|
|
{
|
2021-07-26 12:58:17 +02:00
|
|
|
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
2022-09-29 15:51:59 +10:00
|
|
|
[Dependency] private readonly SharedContainerSystem _container = default!;
|
2022-04-28 06:11:15 -06:00
|
|
|
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
|
2019-04-20 16:20:18 -07:00
|
|
|
|
2018-08-16 15:57:11 -07:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
2021-12-16 23:42:02 +13:00
|
|
|
base.Initialize();
|
|
|
|
|
|
2023-08-27 10:27:43 +02:00
|
|
|
SubscribeLocalEvent<BoundUserInterfaceCheckRangeEvent>(HandleUserInterfaceRangeCheck);
|
2020-05-31 14:32:05 -07:00
|
|
|
}
|
2020-02-28 17:52:18 +01:00
|
|
|
|
2021-11-29 12:25:22 +13:00
|
|
|
public override bool CanAccessViaStorage(EntityUid user, EntityUid target)
|
|
|
|
|
{
|
2021-12-14 06:17:18 +01:00
|
|
|
if (Deleted(target))
|
2021-11-29 12:25:22 +13:00
|
|
|
return false;
|
|
|
|
|
|
2022-09-29 15:51:59 +10:00
|
|
|
if (!_container.TryGetContainingContainer(target, out var container))
|
2021-11-29 12:25:22 +13:00
|
|
|
return false;
|
|
|
|
|
|
2023-09-11 21:20:46 +10:00
|
|
|
if (!TryComp(container.Owner, out StorageComponent? storage))
|
2021-11-29 12:25:22 +13:00
|
|
|
return false;
|
|
|
|
|
|
2023-09-11 21:20:46 +10:00
|
|
|
if (storage.Container?.ID != container.ID)
|
2021-11-29 12:25:22 +13:00
|
|
|
return false;
|
|
|
|
|
|
2021-12-14 06:17:18 +01:00
|
|
|
if (!TryComp(user, out ActorComponent? actor))
|
2021-11-29 12:25:22 +13:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// we don't check if the user can access the storage entity itself. This should be handed by the UI system.
|
2023-09-11 21:20:46 +10:00
|
|
|
return _uiSystem.SessionHasOpenUi(container.Owner, StorageComponent.StorageUiKey.Key, actor.PlayerSession);
|
2021-11-29 12:25:22 +13:00
|
|
|
}
|
2021-08-22 03:20:18 +10:00
|
|
|
|
2023-08-27 10:27:43 +02:00
|
|
|
private void HandleUserInterfaceRangeCheck(ref BoundUserInterfaceCheckRangeEvent ev)
|
|
|
|
|
{
|
2024-01-06 12:19:45 +03:00
|
|
|
if (ev.Player.AttachedEntity is not { } user || ev.Result == BoundUserInterfaceRangeResult.Fail)
|
2023-08-27 10:27:43 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (InRangeUnobstructed(user, ev.Target, ev.UserInterface.InteractionRange))
|
|
|
|
|
{
|
|
|
|
|
ev.Result = BoundUserInterfaceRangeResult.Pass;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ev.Result = BoundUserInterfaceRangeResult.Fail;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-05 13:57:26 -06:00
|
|
|
}
|
|
|
|
|
}
|