2020-07-06 14:27:03 -07:00
|
|
|
using System;
|
2020-08-18 14:39:08 +02: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;
|
2022-02-23 17:58:06 +13:00
|
|
|
using Robust.Shared.Utility;
|
2020-07-06 14:27:03 -07: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 behavior when their entity is clicked on by a user with an object in their hand
|
|
|
|
|
/// who is in range and has unobstructed reach of the target entity (allows inside blockers). 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 IInteractUsing
|
|
|
|
|
{
|
2020-08-12 23:01:30 +02:00
|
|
|
/// <summary>
|
2020-08-13 09:54:27 +02:00
|
|
|
/// The interaction priority. Higher numbers get called first.
|
2020-08-12 23:01:30 +02:00
|
|
|
/// </summary>
|
2020-08-13 09:54:27 +02:00
|
|
|
/// <value>Priority defaults to 0</value>
|
2020-08-16 17:45:15 +02:00
|
|
|
int Priority => 0;
|
2020-08-12 23:01:30 +02:00
|
|
|
|
2020-07-06 14:27:03 -07:00
|
|
|
/// <summary>
|
|
|
|
|
/// Called when using one object on another when user is in range of the target entity.
|
|
|
|
|
/// </summary>
|
2021-04-29 03:23:15 +10:00
|
|
|
[Obsolete("Use InteractUsingMessage instead")]
|
2020-08-18 14:39:08 +02:00
|
|
|
Task<bool> InteractUsing(InteractUsingEventArgs eventArgs);
|
2020-07-06 14:27:03 -07:00
|
|
|
}
|
|
|
|
|
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class InteractUsingEventArgs : EventArgs, ITargetedInteractEventArgs
|
2020-07-06 14:27:03 -07:00
|
|
|
{
|
2021-12-04 12:35:33 +01:00
|
|
|
public InteractUsingEventArgs(EntityUid user, EntityCoordinates clickLocation, EntityUid @using, EntityUid target)
|
2021-03-15 21:55:49 +01:00
|
|
|
{
|
|
|
|
|
User = user;
|
|
|
|
|
ClickLocation = clickLocation;
|
|
|
|
|
Using = @using;
|
|
|
|
|
Target = target;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-04 12:35:33 +01:00
|
|
|
public EntityUid User { get; }
|
2021-03-15 21:55:49 +01:00
|
|
|
public EntityCoordinates ClickLocation { get; }
|
2021-12-04 12:35:33 +01:00
|
|
|
public EntityUid Using { get; }
|
|
|
|
|
public EntityUid Target { get; }
|
2020-07-06 14:27:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2021-05-22 21:06:40 -07:00
|
|
|
/// Raised when a target entity is interacted with by a user while holding an object in their hand.
|
2020-07-06 14:27:03 -07:00
|
|
|
/// </summary>
|
|
|
|
|
[PublicAPI]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class InteractUsingEvent : 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>
|
|
|
|
|
/// Entity that was interacted on.
|
|
|
|
|
/// </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>
|
|
|
|
|
/// The original location that was clicked by the user.
|
|
|
|
|
/// </summary>
|
2020-09-06 16:11:53 +02:00
|
|
|
public EntityCoordinates ClickLocation { get; }
|
2020-07-06 14:27:03 -07:00
|
|
|
|
2022-01-30 13:50:10 +13:00
|
|
|
/// <summary>
|
|
|
|
|
/// If true, this prediction is also being predicted client-side. So care has to be taken to avoid audio
|
|
|
|
|
/// duplication.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool Predicted { get; }
|
|
|
|
|
|
|
|
|
|
public InteractUsingEvent(EntityUid user, EntityUid used, EntityUid target, EntityCoordinates clickLocation, bool predicted = false)
|
2020-07-06 14:27:03 -07:00
|
|
|
{
|
2022-02-23 17:58:06 +13:00
|
|
|
// Interact using should not have the same used and target.
|
|
|
|
|
// That should be a use-in-hand event instead.
|
|
|
|
|
// If this is not the case, can lead to bugs (e.g., attempting to merge a item stack into itself).
|
|
|
|
|
DebugTools.Assert(used != target);
|
|
|
|
|
|
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;
|
2022-01-30 13:50:10 +13:00
|
|
|
Predicted = predicted;
|
2020-07-06 14:27:03 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|