Reduce action blocker uses and add target entity to CanInteract (#6655)

This commit is contained in:
Leon Friedrich
2022-02-15 17:06:52 +13:00
committed by GitHub
parent 334568dad2
commit ad9ddf1552
60 changed files with 286 additions and 402 deletions

View File

@@ -16,7 +16,7 @@ namespace Content.Shared.ActionBlocker
/// Utility methods to check if a specific entity is allowed to perform an action.
/// </summary>
[UsedImplicitly]
public class ActionBlockerSystem : EntitySystem
public sealed class ActionBlockerSystem : EntitySystem
{
public bool CanMove(EntityUid uid)
{
@@ -26,26 +26,54 @@ namespace Content.Shared.ActionBlocker
return !ev.Cancelled;
}
public bool CanInteract(EntityUid uid)
/// <summary>
/// Raises an event directed at both the user and the target entity to check whether a user is capable of
/// interacting with this entity.
/// </summary>
/// <remarks>
/// If this is a generic interaction without a target (e.g., stop-drop-and-roll when burning), the target
/// may be null. Note that this is checked by <see cref="SharedInteractionSystem"/>. In the majority of
/// cases, systems that provide interactions will not need to check this themselves, though they may need to
/// check other blockers like <see cref="CanPickup(EntityUid)"/>
/// </remarks>
/// <returns></returns>
public bool CanInteract(EntityUid user, EntityUid? target)
{
var ev = new InteractionAttemptEvent(uid);
RaiseLocalEvent(uid, ev);
var ev = new InteractionAttemptEvent(user, target);
RaiseLocalEvent(user, ev);
if (ev.Cancelled)
return false;
if (target == null)
return true;
var targetEv = new GettingInteractedWithAttemptEvent(user, target);
RaiseLocalEvent(target.Value, targetEv);
return !targetEv.Cancelled;
}
/// <summary>
/// Can a user utilize the entity that they are currently holding in their hands.
/// </summary>>
/// <remarks>
/// This event is automatically checked by <see cref="SharedInteractionSystem"/> for any interactions that
/// involve using a held entity. In the majority of cases, systems that provide interactions will not need
/// to check this themselves.
/// </remarks>
public bool CanUseHeldEntity(EntityUid user)
{
var ev = new UseAttemptEvent(user);
RaiseLocalEvent(user, ev);
return !ev.Cancelled;
}
public bool CanUse(EntityUid uid)
public bool CanThrow(EntityUid user)
{
var ev = new UseAttemptEvent(uid);
RaiseLocalEvent(uid, ev);
return !ev.Cancelled;
}
public bool CanThrow(EntityUid uid)
{
var ev = new ThrowAttemptEvent(uid);
RaiseLocalEvent(uid, ev);
var ev = new ThrowAttemptEvent(user);
RaiseLocalEvent(user, ev);
return !ev.Cancelled;
}