Files
OldThink/Content.Server/Interaction/InteractionSystem.cs

65 lines
2.2 KiB
C#
Raw Normal View History

2021-06-09 22:19:39 +02:00
using Content.Shared.ActionBlocker;
using Content.Shared.Interaction;
using Content.Shared.Storage;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Shared.Containers;
2023-10-29 04:21:02 +11:00
using Robust.Shared.Player;
2021-06-09 22:19:39 +02:00
namespace Content.Server.Interaction
{
/// <summary>
/// Governs interactions during clicking on entities
/// </summary>
[UsedImplicitly]
2022-09-13 23:52:36 +10:00
public sealed partial class InteractionSystem : SharedInteractionSystem
{
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
[Dependency] private readonly SharedContainerSystem _container = default!;
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
public override void Initialize()
{
2021-12-16 23:42:02 +13:00
base.Initialize();
SubscribeLocalEvent<BoundUserInterfaceCheckRangeEvent>(HandleUserInterfaceRangeCheck);
}
public override bool CanAccessViaStorage(EntityUid user, EntityUid target)
{
if (Deleted(target))
return false;
if (!_container.TryGetContainingContainer(target, out var container))
return false;
2023-09-11 21:20:46 +10:00
if (!TryComp(container.Owner, out StorageComponent? storage))
return false;
2023-09-11 21:20:46 +10:00
if (storage.Container?.ID != container.ID)
return false;
if (!TryComp(user, out ActorComponent? actor))
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);
}
private void HandleUserInterfaceRangeCheck(ref BoundUserInterfaceCheckRangeEvent ev)
{
if (ev.Player.AttachedEntity is not { } user || ev.Result == BoundUserInterfaceRangeResult.Fail)
return;
if (InRangeUnobstructed(user, ev.Target, ev.UserInterface.InteractionRange))
{
ev.Result = BoundUserInterfaceRangeResult.Pass;
}
else
{
ev.Result = BoundUserInterfaceRangeResult.Fail;
}
}
}
}