2021-11-29 12:25:22 +13:00
|
|
|
using Content.Shared.ActionBlocker;
|
2021-11-23 23:00:16 +13:00
|
|
|
using Content.Shared.Hands.Components;
|
2021-11-29 12:25:22 +13:00
|
|
|
using Content.Shared.Interaction;
|
2024-01-14 06:18:47 -04:00
|
|
|
using Content.Shared.Inventory.VirtualItem;
|
2021-11-29 12:25:22 +13:00
|
|
|
using Robust.Shared.Containers;
|
2024-08-25 22:05:39 +10:00
|
|
|
using Robust.Shared.Map;
|
2020-08-29 20:46:42 +10:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Shared.Verbs
|
2020-08-29 20:46:42 +10:00
|
|
|
{
|
2021-11-23 23:00:16 +13:00
|
|
|
public abstract class SharedVerbSystem : EntitySystem
|
2020-08-29 20:46:42 +10:00
|
|
|
{
|
2021-11-29 12:25:22 +13:00
|
|
|
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
|
|
|
|
|
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
2022-01-31 20:08:53 +13:00
|
|
|
[Dependency] protected readonly SharedContainerSystem ContainerSystem = default!;
|
2021-11-23 23:00:16 +13:00
|
|
|
|
2021-12-16 23:42:02 +13:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
SubscribeAllEvent<ExecuteVerbEvent>(HandleExecuteVerb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HandleExecuteVerb(ExecuteVerbEvent args, EntitySessionEventArgs eventArgs)
|
|
|
|
|
{
|
|
|
|
|
var user = eventArgs.SenderSession.AttachedEntity;
|
|
|
|
|
if (user == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-11-05 02:58:26 +11:00
|
|
|
if (!TryGetEntity(args.Target, out var target))
|
|
|
|
|
return;
|
2023-09-11 09:42:41 +10:00
|
|
|
|
2022-07-07 15:35:01 +12:00
|
|
|
// It is possible that client-side prediction can cause this event to be raised after the target entity has
|
|
|
|
|
// been deleted. So we need to check that the entity still exists.
|
2023-11-05 02:58:26 +11:00
|
|
|
if (Deleted(user))
|
2022-07-07 15:35:01 +12:00
|
|
|
return;
|
|
|
|
|
|
2021-12-16 23:42:02 +13:00
|
|
|
// Get the list of verbs. This effectively also checks that the requested verb is in fact a valid verb that
|
|
|
|
|
// the user can perform.
|
2023-11-05 02:58:26 +11:00
|
|
|
var verbs = GetLocalVerbs(target.Value, user.Value, args.RequestedVerb.GetType());
|
2021-12-16 23:42:02 +13:00
|
|
|
|
|
|
|
|
// Note that GetLocalVerbs might waste time checking & preparing unrelated verbs even though we know
|
|
|
|
|
// precisely which one we want to run. However, MOST entities will only have 1 or 2 verbs of a given type.
|
|
|
|
|
// The one exception here is the "other" verb type, which has 3-4 verbs + all the debug verbs.
|
|
|
|
|
|
|
|
|
|
// Find the requested verb.
|
|
|
|
|
if (verbs.TryGetValue(args.RequestedVerb, out var verb))
|
2023-11-05 02:58:26 +11:00
|
|
|
ExecuteVerb(verb, user.Value, target.Value);
|
2021-12-16 23:42:02 +13:00
|
|
|
}
|
|
|
|
|
|
2021-10-05 14:29:03 +11:00
|
|
|
/// <summary>
|
2021-10-28 18:21:19 +13:00
|
|
|
/// Raises a number of events in order to get all verbs of the given type(s) defined in local systems. This
|
|
|
|
|
/// does not request verbs from the server.
|
2021-10-05 14:29:03 +11:00
|
|
|
/// </summary>
|
2022-02-24 23:48:53 +13:00
|
|
|
public SortedSet<Verb> GetLocalVerbs(EntityUid target, EntityUid user, Type type, bool force = false)
|
2021-10-05 14:29:03 +11:00
|
|
|
{
|
2022-02-24 23:48:53 +13:00
|
|
|
return GetLocalVerbs(target, user, new List<Type>() { type }, force);
|
2022-02-10 15:30:59 +13:00
|
|
|
}
|
|
|
|
|
|
2024-04-29 15:24:10 +12:00
|
|
|
/// <inheritdoc cref="GetLocalVerbs(Robust.Shared.GameObjects.EntityUid,Robust.Shared.GameObjects.EntityUid,System.Type,bool)"/>
|
|
|
|
|
public SortedSet<Verb> GetLocalVerbs(EntityUid target, EntityUid user, List<Type> types, bool force = false)
|
|
|
|
|
{
|
|
|
|
|
return GetLocalVerbs(target, user, types, out _, force);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-10 15:30:59 +13:00
|
|
|
/// <summary>
|
|
|
|
|
/// Raises a number of events in order to get all verbs of the given type(s) defined in local systems. This
|
|
|
|
|
/// does not request verbs from the server.
|
|
|
|
|
/// </summary>
|
2024-04-29 15:24:10 +12:00
|
|
|
public SortedSet<Verb> GetLocalVerbs(EntityUid target, EntityUid user, List<Type> types,
|
|
|
|
|
out List<VerbCategory> extraCategories, bool force = false)
|
2022-02-10 15:30:59 +13:00
|
|
|
{
|
|
|
|
|
SortedSet<Verb> verbs = new();
|
2024-04-29 15:24:10 +12:00
|
|
|
extraCategories = new();
|
2021-10-05 14:29:03 +11:00
|
|
|
|
2021-11-29 12:25:22 +13:00
|
|
|
// accessibility checks
|
2024-05-24 17:03:03 +12:00
|
|
|
var canAccess = force || _interactionSystem.InRangeAndAccessible(user, target);
|
2021-11-29 12:25:22 +13:00
|
|
|
|
|
|
|
|
// A large number of verbs need to check action blockers. Instead of repeatedly having each system individually
|
|
|
|
|
// call ActionBlocker checks, just cache it for the verb request.
|
2022-02-15 17:06:52 +13:00
|
|
|
var canInteract = force || _actionBlockerSystem.CanInteract(user, target);
|
2024-08-28 10:57:12 +10:00
|
|
|
var canComplexInteract = force || _actionBlockerSystem.CanComplexInteract(user);
|
2021-11-29 12:25:22 +13:00
|
|
|
|
2024-05-31 16:26:19 -04:00
|
|
|
_interactionSystem.TryGetUsedEntity(user, out var @using);
|
|
|
|
|
TryComp<HandsComponent>(user, out var hands);
|
2021-11-29 12:25:22 +13:00
|
|
|
|
2023-03-06 06:12:08 +13:00
|
|
|
// TODO: fix this garbage and use proper generics or reflection or something else, not this.
|
2022-02-10 15:30:59 +13:00
|
|
|
if (types.Contains(typeof(InteractionVerb)))
|
2020-08-30 11:37:06 +02:00
|
|
|
{
|
2024-08-28 10:57:12 +10:00
|
|
|
var verbEvent = new GetVerbsEvent<InteractionVerb>(user, target, @using, hands, canInteract: canInteract, canComplexInteract: canComplexInteract, canAccess: canAccess, extraCategories);
|
2022-06-22 09:53:41 +10:00
|
|
|
RaiseLocalEvent(target, verbEvent, true);
|
2022-02-10 15:30:59 +13:00
|
|
|
verbs.UnionWith(verbEvent.Verbs);
|
2020-08-30 11:37:06 +02:00
|
|
|
}
|
2020-08-29 20:46:42 +10:00
|
|
|
|
2022-02-24 23:48:53 +13:00
|
|
|
if (types.Contains(typeof(UtilityVerb))
|
|
|
|
|
&& @using != null
|
|
|
|
|
&& @using != target)
|
|
|
|
|
{
|
2024-08-28 10:57:12 +10:00
|
|
|
var verbEvent = new GetVerbsEvent<UtilityVerb>(user, target, @using, hands, canInteract: canInteract, canComplexInteract: canComplexInteract, canAccess: canAccess, extraCategories);
|
2022-06-22 09:53:41 +10:00
|
|
|
RaiseLocalEvent(@using.Value, verbEvent, true); // directed at used, not at target
|
2022-02-24 23:48:53 +13:00
|
|
|
verbs.UnionWith(verbEvent.Verbs);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-05 21:37:29 -04:00
|
|
|
if (types.Contains(typeof(InnateVerb)))
|
|
|
|
|
{
|
2024-08-28 10:57:12 +10:00
|
|
|
var verbEvent = new GetVerbsEvent<InnateVerb>(user, target, @using, hands, canInteract: canInteract, canComplexInteract: canComplexInteract, canAccess: canAccess, extraCategories);
|
2022-06-22 09:53:41 +10:00
|
|
|
RaiseLocalEvent(user, verbEvent, true);
|
2022-06-05 21:37:29 -04:00
|
|
|
verbs.UnionWith(verbEvent.Verbs);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-10 15:30:59 +13:00
|
|
|
if (types.Contains(typeof(AlternativeVerb)))
|
2021-10-05 14:29:03 +11:00
|
|
|
{
|
2024-08-28 10:57:12 +10:00
|
|
|
var verbEvent = new GetVerbsEvent<AlternativeVerb>(user, target, @using, hands, canInteract: canInteract, canComplexInteract: canComplexInteract, canAccess: canAccess, extraCategories);
|
2022-06-22 09:53:41 +10:00
|
|
|
RaiseLocalEvent(target, verbEvent, true);
|
2022-02-10 15:30:59 +13:00
|
|
|
verbs.UnionWith(verbEvent.Verbs);
|
2021-10-05 14:29:03 +11:00
|
|
|
}
|
2020-10-30 04:52:37 +01:00
|
|
|
|
2022-02-10 15:30:59 +13:00
|
|
|
if (types.Contains(typeof(ActivationVerb)))
|
2021-10-05 14:29:03 +11:00
|
|
|
{
|
2024-08-28 10:57:12 +10:00
|
|
|
var verbEvent = new GetVerbsEvent<ActivationVerb>(user, target, @using, hands, canInteract: canInteract, canComplexInteract: canComplexInteract, canAccess: canAccess, extraCategories);
|
2022-06-22 09:53:41 +10:00
|
|
|
RaiseLocalEvent(target, verbEvent, true);
|
2022-02-10 15:30:59 +13:00
|
|
|
verbs.UnionWith(verbEvent.Verbs);
|
2021-10-05 14:29:03 +11:00
|
|
|
}
|
2020-08-29 20:46:42 +10:00
|
|
|
|
2022-02-13 20:20:58 -07:00
|
|
|
if (types.Contains(typeof(ExamineVerb)))
|
|
|
|
|
{
|
2024-08-28 10:57:12 +10:00
|
|
|
var verbEvent = new GetVerbsEvent<ExamineVerb>(user, target, @using, hands, canInteract: canInteract, canComplexInteract: canComplexInteract, canAccess: canAccess, extraCategories);
|
2022-06-22 09:53:41 +10:00
|
|
|
RaiseLocalEvent(target, verbEvent, true);
|
2022-02-13 20:20:58 -07:00
|
|
|
verbs.UnionWith(verbEvent.Verbs);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-10 15:30:59 +13:00
|
|
|
// generic verbs
|
|
|
|
|
if (types.Contains(typeof(Verb)))
|
2020-08-29 20:46:42 +10:00
|
|
|
{
|
2024-08-28 10:57:12 +10:00
|
|
|
var verbEvent = new GetVerbsEvent<Verb>(user, target, @using, hands, canInteract: canInteract, canComplexInteract: canComplexInteract, canAccess: canAccess, extraCategories);
|
2022-06-22 09:53:41 +10:00
|
|
|
RaiseLocalEvent(target, verbEvent, true);
|
2022-02-10 15:30:59 +13:00
|
|
|
verbs.UnionWith(verbEvent.Verbs);
|
2020-08-29 20:46:42 +10:00
|
|
|
}
|
|
|
|
|
|
2023-03-06 06:12:08 +13:00
|
|
|
if (types.Contains(typeof(EquipmentVerb)))
|
|
|
|
|
{
|
|
|
|
|
var access = canAccess || _interactionSystem.CanAccessEquipment(user, target);
|
2024-08-28 10:57:12 +10:00
|
|
|
var verbEvent = new GetVerbsEvent<EquipmentVerb>(user, target, @using, hands, canInteract: canInteract, canComplexInteract: canComplexInteract, canAccess: canAccess, extraCategories);
|
2023-03-06 06:12:08 +13:00
|
|
|
RaiseLocalEvent(target, verbEvent);
|
|
|
|
|
verbs.UnionWith(verbEvent.Verbs);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-05 14:29:03 +11:00
|
|
|
return verbs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2021-10-28 18:21:19 +13:00
|
|
|
/// Execute the provided verb.
|
2021-10-05 14:29:03 +11:00
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
2021-10-28 18:21:19 +13:00
|
|
|
/// This will try to call the action delegates and raise the local events for the given verb.
|
2021-10-05 14:29:03 +11:00
|
|
|
/// </remarks>
|
2022-10-26 14:15:48 +13:00
|
|
|
public virtual void ExecuteVerb(Verb verb, EntityUid user, EntityUid target, bool forced = false)
|
|
|
|
|
{
|
|
|
|
|
// invoke any relevant actions
|
|
|
|
|
verb.Act?.Invoke();
|
|
|
|
|
|
|
|
|
|
// Maybe raise a local event
|
|
|
|
|
if (verb.ExecutionEventArgs != null)
|
|
|
|
|
{
|
|
|
|
|
if (verb.EventTarget.IsValid())
|
|
|
|
|
RaiseLocalEvent(verb.EventTarget, verb.ExecutionEventArgs);
|
|
|
|
|
else
|
|
|
|
|
RaiseLocalEvent(verb.ExecutionEventArgs);
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-15 19:34:47 +13:00
|
|
|
if (Deleted(user) || Deleted(target))
|
|
|
|
|
return;
|
|
|
|
|
|
2022-10-26 14:15:48 +13:00
|
|
|
// Perform any contact interactions
|
|
|
|
|
if (verb.DoContactInteraction ?? (verb.DefaultDoContactInteraction && _interactionSystem.InRangeUnobstructed(user, target)))
|
|
|
|
|
_interactionSystem.DoContactInteraction(user, target);
|
|
|
|
|
}
|
2020-08-29 20:46:42 +10:00
|
|
|
}
|
2024-08-25 22:05:39 +10:00
|
|
|
|
|
|
|
|
// Does nothing on server
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Raised directed when trying to get the entity menu visibility for entities.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ByRefEvent]
|
|
|
|
|
public record struct MenuVisibilityEvent
|
|
|
|
|
{
|
|
|
|
|
public MapCoordinates TargetPos;
|
|
|
|
|
public MenuVisibility Visibility;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Does nothing on server
|
|
|
|
|
[Flags]
|
|
|
|
|
public enum MenuVisibility
|
|
|
|
|
{
|
|
|
|
|
// What entities can a user see on the entity menu?
|
|
|
|
|
Default = 0, // They can only see entities in FoV.
|
|
|
|
|
NoFov = 1 << 0, // They ignore FoV restrictions
|
|
|
|
|
InContainer = 1 << 1, // They can see through containers.
|
|
|
|
|
Invisible = 1 << 2, // They can see entities without sprites and the "HideContextMenu" tag is ignored.
|
|
|
|
|
All = NoFov | InContainer | Invisible
|
|
|
|
|
}
|
2020-08-30 11:37:06 +02:00
|
|
|
}
|