2022-09-29 15:51:59 +10:00
|
|
|
|
|
|
|
|
|
2021-11-24 16:52:31 -06:00
|
|
|
using Content.Server.Administration.Logs;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Pulling;
|
|
|
|
|
using Content.Shared.ActionBlocker;
|
|
|
|
|
using Content.Shared.DragDrop;
|
2018-08-16 15:57:11 -07:00
|
|
|
using Content.Shared.Input;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Interaction;
|
2021-10-05 14:29:03 +11:00
|
|
|
using Content.Shared.Pulling.Components;
|
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;
|
2020-05-31 14:32:05 -07:00
|
|
|
using Robust.Shared.Input.Binding;
|
2019-05-16 15:51:26 +02:00
|
|
|
using Robust.Shared.Map;
|
2019-04-15 21:11:38 -06:00
|
|
|
using Robust.Shared.Players;
|
2022-09-13 23:52:36 +10:00
|
|
|
using Robust.Shared.Random;
|
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();
|
|
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
SubscribeNetworkEvent<DragDropRequestEvent>(HandleDragDropRequestEvent);
|
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
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
#region Drag drop
|
2023-02-14 00:29:34 +11:00
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
private void HandleDragDropRequestEvent(DragDropRequestEvent msg, EntitySessionEventArgs args)
|
|
|
|
|
{
|
2023-09-11 09:42:41 +10:00
|
|
|
var dragged = GetEntity(msg.Dragged);
|
|
|
|
|
var target = GetEntity(msg.Target);
|
|
|
|
|
|
|
|
|
|
if (Deleted(dragged) || Deleted(target))
|
2021-06-07 05:49:43 -07:00
|
|
|
return;
|
|
|
|
|
|
2023-02-14 00:29:34 +11:00
|
|
|
var user = args.SenderSession.AttachedEntity;
|
2021-11-07 01:05:51 +01:00
|
|
|
|
2023-09-11 09:42:41 +10:00
|
|
|
if (user == null || !_actionBlockerSystem.CanInteract(user.Value, target))
|
2021-06-07 05:49:43 -07:00
|
|
|
return;
|
2020-07-06 14:27:03 -07:00
|
|
|
|
|
|
|
|
// must be in range of both the target and the object they are drag / dropping
|
2021-01-11 22:14:01 +11:00
|
|
|
// Client also does this check but ya know we gotta validate it.
|
2023-09-11 09:42:41 +10:00
|
|
|
if (!InRangeUnobstructed(user.Value, dragged, popup: true)
|
|
|
|
|
|| !InRangeUnobstructed(user.Value, target, popup: true))
|
2023-02-14 00:29:34 +11:00
|
|
|
{
|
2021-06-07 05:49:43 -07:00
|
|
|
return;
|
2023-02-14 00:29:34 +11:00
|
|
|
}
|
|
|
|
|
|
2023-09-11 09:42:41 +10:00
|
|
|
var dragArgs = new DragDropDraggedEvent(user.Value, target);
|
2020-07-06 14:27:03 -07:00
|
|
|
|
|
|
|
|
// trigger dragdrops on the dropped entity
|
2023-09-11 09:42:41 +10:00
|
|
|
RaiseLocalEvent(dragged, ref dragArgs);
|
2021-12-26 05:32:01 +03:00
|
|
|
|
2023-02-14 00:29:34 +11:00
|
|
|
if (dragArgs.Handled)
|
2021-12-26 05:32:01 +03:00
|
|
|
return;
|
|
|
|
|
|
2023-09-11 09:42:41 +10:00
|
|
|
var dropArgs = new DragDropTargetEvent(user.Value, dragged);
|
2021-12-26 05:32:01 +03:00
|
|
|
|
2023-09-04 14:53:13 +02:00
|
|
|
// trigger dragdrops on the target entity (what you are dropping onto)
|
2023-09-11 09:42:41 +10:00
|
|
|
RaiseLocalEvent(GetEntity(msg.Target), ref dropArgs);
|
2020-07-06 14:27:03 -07:00
|
|
|
}
|
2023-02-14 00:29:34 +11:00
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
#endregion
|
2023-08-27 10:27:43 +02:00
|
|
|
|
|
|
|
|
private void HandleUserInterfaceRangeCheck(ref BoundUserInterfaceCheckRangeEvent ev)
|
|
|
|
|
{
|
|
|
|
|
if (ev.Player.AttachedEntity is not { } user)
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|