2021-02-27 04:12:09 +01:00
|
|
|
using System;
|
2020-12-17 10:45:04 +03:00
|
|
|
using System.Threading.Tasks;
|
2020-07-06 14:27:03 -07:00
|
|
|
using JetBrains.Annotations;
|
2021-01-23 22:45:23 +01:00
|
|
|
using Robust.Shared.Analyzers;
|
2020-07-06 14:27:03 -07:00
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
using Robust.Shared.Map;
|
|
|
|
|
|
2021-01-11 09:36:21 +01:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Shared.Interaction
|
2020-07-06 14:27:03 -07:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
2020-12-13 14:28:20 -08:00
|
|
|
/// This interface gives components a behavior when their entity is in the active hand, when
|
|
|
|
|
/// clicking on another object and no interaction occurs, at any range. This includes
|
|
|
|
|
/// clicking on an object in the world as well as clicking on an object in inventory.
|
2020-07-06 14:27:03 -07:00
|
|
|
/// </summary>
|
2021-01-23 20:00:29 +01:00
|
|
|
[RequiresExplicitImplementation]
|
2020-07-06 14:27:03 -07:00
|
|
|
public interface IAfterInteract
|
|
|
|
|
{
|
2021-02-03 14:05:31 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// The interaction priority. Higher numbers get called first.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>Priority defaults to 0</value>
|
|
|
|
|
int Priority => 0;
|
|
|
|
|
|
2020-07-06 14:27:03 -07:00
|
|
|
/// <summary>
|
|
|
|
|
/// Called when we interact with nothing, or when we interact with an entity out of range that has no behavior
|
|
|
|
|
/// </summary>
|
2021-04-29 03:23:15 +10:00
|
|
|
[Obsolete("Use AfterInteractMessage instead")]
|
2021-02-03 14:05:31 +01:00
|
|
|
Task<bool> AfterInteract(AfterInteractEventArgs eventArgs);
|
2020-07-06 14:27:03 -07:00
|
|
|
}
|
|
|
|
|
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class AfterInteractEventArgs : EventArgs
|
2020-07-06 14:27:03 -07:00
|
|
|
{
|
2021-12-04 12:35:33 +01:00
|
|
|
public EntityUid User { get; }
|
2021-01-11 09:36:21 +01:00
|
|
|
public EntityCoordinates ClickLocation { get; }
|
2021-12-04 12:35:33 +01:00
|
|
|
public EntityUid? Target { get; }
|
2021-01-11 09:36:21 +01:00
|
|
|
public bool CanReach { get; }
|
|
|
|
|
|
2021-12-04 12:35:33 +01:00
|
|
|
public AfterInteractEventArgs(EntityUid user, EntityCoordinates clickLocation, EntityUid? target, bool canReach)
|
2021-01-11 09:36:21 +01:00
|
|
|
{
|
|
|
|
|
User = user;
|
|
|
|
|
ClickLocation = clickLocation;
|
|
|
|
|
Target = target;
|
|
|
|
|
CanReach = canReach;
|
|
|
|
|
}
|
2020-07-06 14:27:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[PublicAPI]
|
2022-02-05 15:39:01 +13:00
|
|
|
public abstract class InteractEvent : HandledEntityEventArgs
|
2020-07-06 14:27:03 -07:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
2021-05-22 21:06:40 -07:00
|
|
|
/// Entity that triggered the interaction.
|
2020-07-06 14:27:03 -07:00
|
|
|
/// </summary>
|
2021-12-04 12:35:33 +01:00
|
|
|
public EntityUid User { get; }
|
2020-07-06 14:27:03 -07:00
|
|
|
|
2021-11-09 15:00:59 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Entity that the user used to interact.
|
|
|
|
|
/// </summary>
|
2021-12-04 12:35:33 +01:00
|
|
|
public EntityUid Used { get; }
|
2020-07-06 14:27:03 -07:00
|
|
|
|
2021-11-09 15:00:59 +01:00
|
|
|
/// <summary>
|
2022-02-05 15:39:01 +13:00
|
|
|
/// Entity that was interacted on. This can be null if there was no target (e.g., clicking on tiles).
|
2021-11-09 15:00:59 +01:00
|
|
|
/// </summary>
|
2021-12-04 12:35:33 +01:00
|
|
|
public EntityUid? Target { get; }
|
2021-11-09 15:00:59 +01:00
|
|
|
|
2020-07-06 14:27:03 -07:00
|
|
|
/// <summary>
|
|
|
|
|
/// Location that the user clicked outside of their interaction range.
|
|
|
|
|
/// </summary>
|
2020-09-06 16:11:53 +02:00
|
|
|
public EntityCoordinates ClickLocation { get; }
|
2020-07-06 14:27:03 -07:00
|
|
|
|
2020-07-10 16:52:07 -07:00
|
|
|
/// <summary>
|
2022-02-05 15:39:01 +13:00
|
|
|
/// Is the click location in range without obstructions?
|
2020-07-10 16:52:07 -07:00
|
|
|
/// </summary>
|
|
|
|
|
public bool CanReach { get; }
|
|
|
|
|
|
2022-02-05 15:39:01 +13:00
|
|
|
public InteractEvent(EntityUid user, EntityUid used, EntityUid? target,
|
2021-01-11 09:36:21 +01:00
|
|
|
EntityCoordinates clickLocation, bool canReach)
|
2020-07-06 14:27:03 -07:00
|
|
|
{
|
|
|
|
|
User = user;
|
2021-05-22 21:06:40 -07:00
|
|
|
Used = used;
|
|
|
|
|
Target = target;
|
2020-07-06 14:27:03 -07:00
|
|
|
ClickLocation = clickLocation;
|
2020-07-10 16:52:07 -07:00
|
|
|
CanReach = canReach;
|
2020-07-06 14:27:03 -07:00
|
|
|
}
|
|
|
|
|
}
|
2022-02-05 15:39:01 +13:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Raised directed on the used object when clicking on another object and no standard interaction occurred.
|
|
|
|
|
/// Used for low-priority interactions facilitated by the used entity.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed class AfterInteractEvent : InteractEvent
|
|
|
|
|
{
|
|
|
|
|
public AfterInteractEvent(EntityUid user, EntityUid used, EntityUid? target,
|
|
|
|
|
EntityCoordinates clickLocation, bool canReach) : base(user, used, target, clickLocation, canReach)
|
|
|
|
|
{ }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Raised directed on the target when clicking on another object and no standard interaction occurred. Used for
|
|
|
|
|
/// low-priority interactions facilitated by the target entity.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed class AfterInteractUsingEvent : InteractEvent
|
|
|
|
|
{
|
|
|
|
|
public AfterInteractUsingEvent(EntityUid user, EntityUid used, EntityUid? target,
|
|
|
|
|
EntityCoordinates clickLocation, bool canReach) : base(user, used, target, clickLocation, canReach)
|
|
|
|
|
{ }
|
|
|
|
|
}
|
2020-07-06 14:27:03 -07:00
|
|
|
}
|