Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Add IsQueuedForDeletion checks to interaction system (#32526)" #32872

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Content.Shared.Interaction.Events;
/// </remarks>
public sealed class ContactInteractionEvent : HandledEntityEventArgs
{
public EntityUid Other;
public readonly EntityUid Other;

public ContactInteractionEvent(EntityUid other)
{
Expand Down
2 changes: 0 additions & 2 deletions Content.Shared/Interaction/Events/InteractionFailureEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@ namespace Content.Shared.Interaction.Events;
/// <summary>
/// Raised on the target when failing to pet/hug something.
/// </summary>
// TODO INTERACTION
// Rename this, or move it to another namespace to make it clearer that this is specific to "petting/hugging" (InteractionPopupSystem)
[ByRefEvent]
public readonly record struct InteractionFailureEvent(EntityUid User);
2 changes: 0 additions & 2 deletions Content.Shared/Interaction/Events/InteractionSuccessEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@ namespace Content.Shared.Interaction.Events;
/// <summary>
/// Raised on the target when successfully petting/hugging something.
/// </summary>
// TODO INTERACTION
// Rename this, or move it to another namespace to make it clearer that this is specific to "petting/hugging" (InteractionPopupSystem)
[ByRefEvent]
public readonly record struct InteractionSuccessEvent(EntityUid User);
115 changes: 25 additions & 90 deletions Content.Shared/Interaction/SharedInteractionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -456,22 +456,8 @@ public void UserInteraction(
inRangeUnobstructed);
}

private bool IsDeleted(EntityUid uid)
{
return TerminatingOrDeleted(uid) || EntityManager.IsQueuedForDeletion(uid);
}

private bool IsDeleted(EntityUid? uid)
{
//optional / null entities can pass this validation check. I.e., is-deleted returns false for null uids
return uid != null && IsDeleted(uid.Value);
}

public void InteractHand(EntityUid user, EntityUid target)
{
if (IsDeleted(user) || IsDeleted(target))
return;

var complexInteractions = _actionBlockerSystem.CanComplexInteract(user);
if (!complexInteractions)
{
Expand All @@ -480,8 +466,7 @@ public void InteractHand(EntityUid user, EntityUid target)
checkCanInteract: false,
checkUseDelay: true,
checkAccess: false,
complexInteractions: complexInteractions,
checkDeletion: false);
complexInteractions: complexInteractions);
return;
}

Expand All @@ -494,7 +479,6 @@ public void InteractHand(EntityUid user, EntityUid target)
return;
}

DebugTools.Assert(!IsDeleted(user) && !IsDeleted(target));
// all interactions should only happen when in range / unobstructed, so no range check is needed
var message = new InteractHandEvent(user, target);
RaiseLocalEvent(target, message, true);
Expand All @@ -503,23 +487,18 @@ public void InteractHand(EntityUid user, EntityUid target)
if (message.Handled)
return;

DebugTools.Assert(!IsDeleted(user) && !IsDeleted(target));
// Else we run Activate.
InteractionActivate(user,
target,
checkCanInteract: false,
checkUseDelay: true,
checkAccess: false,
complexInteractions: complexInteractions,
checkDeletion: false);
complexInteractions: complexInteractions);
}

public void InteractUsingRanged(EntityUid user, EntityUid used, EntityUid? target,
EntityCoordinates clickLocation, bool inRangeUnobstructed)
{
if (IsDeleted(user) || IsDeleted(used) || IsDeleted(target))
return;

if (target != null)
{
_adminLogger.Add(
Expand All @@ -535,23 +514,22 @@ public void InteractUsingRanged(EntityUid user, EntityUid used, EntityUid? targe
$"{ToPrettyString(user):user} interacted with *nothing* using {ToPrettyString(used):used}");
}

if (RangedInteractDoBefore(user, used, target, clickLocation, inRangeUnobstructed, checkDeletion: false))
if (RangedInteractDoBefore(user, used, target, clickLocation, inRangeUnobstructed))
return;

DebugTools.Assert(!IsDeleted(user) && !IsDeleted(used) && !IsDeleted(target));
if (target != null)
{
var rangedMsg = new RangedInteractEvent(user, used, target.Value, clickLocation);
RaiseLocalEvent(target.Value, rangedMsg, true);

// We contact the USED entity, but not the target.
DoContactInteraction(user, used, rangedMsg);

if (rangedMsg.Handled)
return;
}

DebugTools.Assert(!IsDeleted(user) && !IsDeleted(used) && !IsDeleted(target));
InteractDoAfter(user, used, target, clickLocation, inRangeUnobstructed, checkDeletion: false);
InteractDoAfter(user, used, target, clickLocation, inRangeUnobstructed);
}

protected bool ValidateInteractAndFace(EntityUid user, EntityCoordinates coordinates)
Expand Down Expand Up @@ -955,18 +933,11 @@ public bool RangedInteractDoBefore(
EntityUid used,
EntityUid? target,
EntityCoordinates clickLocation,
bool canReach,
bool checkDeletion = true)
bool canReach)
{
if (checkDeletion && (IsDeleted(user) || IsDeleted(used) || IsDeleted(target)))
return false;

var ev = new BeforeRangedInteractEvent(user, used, target, clickLocation, canReach);
RaiseLocalEvent(used, ev);

if (!ev.Handled)
return false;

// We contact the USED entity, but not the target.
DoContactInteraction(user, used, ev);
return ev.Handled;
Expand Down Expand Up @@ -995,9 +966,6 @@ public bool InteractUsing(
bool checkCanInteract = true,
bool checkCanUse = true)
{
if (IsDeleted(user) || IsDeleted(used) || IsDeleted(target))
return false;

if (checkCanInteract && !_actionBlockerSystem.CanInteract(user, target))
return false;

Expand All @@ -1009,10 +977,9 @@ public bool InteractUsing(
LogImpact.Low,
$"{ToPrettyString(user):user} interacted with {ToPrettyString(target):target} using {ToPrettyString(used):used}");

if (RangedInteractDoBefore(user, used, target, clickLocation, canReach: true, checkDeletion: false))
if (RangedInteractDoBefore(user, used, target, clickLocation, true))
return true;

DebugTools.Assert(!IsDeleted(user) && !IsDeleted(used) && !IsDeleted(target));
// all interactions should only happen when in range / unobstructed, so no range check is needed
var interactUsingEvent = new InteractUsingEvent(user, used, target, clickLocation);
RaiseLocalEvent(target, interactUsingEvent, true);
Expand All @@ -1022,10 +989,8 @@ public bool InteractUsing(
if (interactUsingEvent.Handled)
return true;

if (InteractDoAfter(user, used, target, clickLocation, canReach: true, checkDeletion: false))
if (InteractDoAfter(user, used, target, clickLocation, canReach: true))
return true;

DebugTools.Assert(!IsDeleted(user) && !IsDeleted(used) && !IsDeleted(target));
return false;
}

Expand All @@ -1039,14 +1004,11 @@ public bool InteractUsing(
/// <param name="canReach">Whether the <paramref name="user"/> is in range of the <paramref name="target"/>.
/// </param>
/// <returns>True if the interaction was handled. Otherwise, false.</returns>
public bool InteractDoAfter(EntityUid user, EntityUid used, EntityUid? target, EntityCoordinates clickLocation, bool canReach, bool checkDeletion = true)
public bool InteractDoAfter(EntityUid user, EntityUid used, EntityUid? target, EntityCoordinates clickLocation, bool canReach)
{
if (target is { Valid: false })
target = null;

if (checkDeletion && (IsDeleted(user) || IsDeleted(used) || IsDeleted(target)))
return false;

var afterInteractEvent = new AfterInteractEvent(user, used, target, clickLocation, canReach);
RaiseLocalEvent(used, afterInteractEvent);
DoContactInteraction(user, used, afterInteractEvent);
Expand All @@ -1062,7 +1024,6 @@ public bool InteractDoAfter(EntityUid user, EntityUid used, EntityUid? target, E
if (target == null)
return false;

DebugTools.Assert(!IsDeleted(user) && !IsDeleted(used) && !IsDeleted(target));
var afterInteractUsingEvent = new AfterInteractUsingEvent(user, used, target, clickLocation, canReach);
RaiseLocalEvent(target.Value, afterInteractUsingEvent);

Expand All @@ -1073,7 +1034,9 @@ public bool InteractDoAfter(EntityUid user, EntityUid used, EntityUid? target, E
// Contact interactions are currently only used for forensics, so we don't raise used -> target
}

return afterInteractUsingEvent.Handled;
if (afterInteractUsingEvent.Handled)
return true;
return false;
}

#region ActivateItemInWorld
Expand Down Expand Up @@ -1105,13 +1068,8 @@ public bool InteractionActivate(
bool checkCanInteract = true,
bool checkUseDelay = true,
bool checkAccess = true,
bool? complexInteractions = null,
bool checkDeletion = true)
bool? complexInteractions = null)
{
if (checkDeletion && (IsDeleted(user) || IsDeleted(used)))
return false;

DebugTools.Assert(!IsDeleted(user) && !IsDeleted(used));
_delayQuery.TryComp(used, out var delayComponent);
if (checkUseDelay && delayComponent != null && _useDelay.IsDelayed((used, delayComponent)))
return false;
Expand All @@ -1127,32 +1085,21 @@ public bool InteractionActivate(
if (checkAccess && !IsAccessible(user, used))
return false;

complexInteractions ??= _actionBlockerSystem.CanComplexInteract(user);
complexInteractions ??= SupportsComplexInteractions(user);
var activateMsg = new ActivateInWorldEvent(user, used, complexInteractions.Value);
RaiseLocalEvent(used, activateMsg, true);
if (activateMsg.Handled)
{
DoContactInteraction(user, used);
if (!activateMsg.WasLogged)
_adminLogger.Add(LogType.InteractActivate, LogImpact.Low, $"{ToPrettyString(user):user} activated {ToPrettyString(used):used}");

if (delayComponent != null)
_useDelay.TryResetDelay(used, component: delayComponent);
return true;
}

DebugTools.Assert(!IsDeleted(user) && !IsDeleted(used));
var userEv = new UserActivateInWorldEvent(user, used, complexInteractions.Value);
RaiseLocalEvent(user, userEv, true);
if (!userEv.Handled)
if (!activateMsg.Handled && !userEv.Handled)
return false;

DoContactInteraction(user, used);
DoContactInteraction(user, used, activateMsg);
// Still need to call this even without checkUseDelay in case this gets relayed from Activate.
if (delayComponent != null)
_useDelay.TryResetDelay(used, component: delayComponent);

_adminLogger.Add(LogType.InteractActivate, LogImpact.Low, $"{ToPrettyString(user):user} activated {ToPrettyString(used):used}");
if (!activateMsg.WasLogged)
_adminLogger.Add(LogType.InteractActivate, LogImpact.Low, $"{ToPrettyString(user):user} activated {ToPrettyString(used):used}");
return true;
}
#endregion
Expand All @@ -1171,9 +1118,6 @@ public bool UseInHandInteraction(
bool checkCanInteract = true,
bool checkUseDelay = true)
{
if (IsDeleted(user) || IsDeleted(used))
return false;

_delayQuery.TryComp(used, out var delayComponent);
if (checkUseDelay && delayComponent != null && _useDelay.IsDelayed((used, delayComponent)))
return true; // if the item is on cooldown, we consider this handled.
Expand All @@ -1194,9 +1138,8 @@ public bool UseInHandInteraction(
return true;
}

DebugTools.Assert(!IsDeleted(user) && !IsDeleted(used));
// else, default to activating the item
return InteractionActivate(user, used, false, false, false, checkDeletion: false);
return InteractionActivate(user, used, false, false, false);
}

/// <summary>
Expand All @@ -1221,9 +1164,6 @@ public bool AltInteract(EntityUid user, EntityUid target)

public void DroppedInteraction(EntityUid user, EntityUid item)
{
if (IsDeleted(user) || IsDeleted(item))
return;

var dropMsg = new DroppedEvent(user);
RaiseLocalEvent(item, dropMsg, true);

Expand Down Expand Up @@ -1372,20 +1312,15 @@ public void DoContactInteraction(EntityUid uidA, EntityUid? uidB, HandledEntityE
if (uidB == null || args?.Handled == false)
return;

DebugTools.AssertNotEqual(uidA, uidB.Value);

if (!TryComp(uidA, out MetaDataComponent? metaA) || metaA.EntityPaused)
// Entities may no longer exist (banana was eaten, or human was exploded)?
if (!Exists(uidA) || !Exists(uidB))
return;

if (!TryComp(uidB, out MetaDataComponent? metaB) || metaB.EntityPaused)
return ;

// TODO Struct event
var ev = new ContactInteractionEvent(uidB.Value);
RaiseLocalEvent(uidA, ev);
if (Paused(uidA) || Paused(uidB.Value))
return;

ev.Other = uidA;
RaiseLocalEvent(uidB.Value, ev);
RaiseLocalEvent(uidA, new ContactInteractionEvent(uidB.Value));
RaiseLocalEvent(uidB.Value, new ContactInteractionEvent(uidA));
}


Expand Down
Loading