From 20c9100e75b5a052abc83ab1cb9e021264371578 Mon Sep 17 00:00:00 2001
From: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
Date: Fri, 18 Oct 2024 00:54:40 +0200
Subject: [PATCH] Revert "Add `IsQueuedForDeletion` checks to interaction
system (#32526)"
This reverts commit 97f6097dad149d819bc4db918759d71cb6de9b04.
---
.../Events/ContactInteractionEvent.cs | 2 +-
.../Events/InteractionFailureEvent.cs | 2 -
.../Events/InteractionSuccessEvent.cs | 2 -
.../Interaction/SharedInteractionSystem.cs | 115 ++++--------------
4 files changed, 26 insertions(+), 95 deletions(-)
diff --git a/Content.Shared/Interaction/Events/ContactInteractionEvent.cs b/Content.Shared/Interaction/Events/ContactInteractionEvent.cs
index 7be1c01c4ad7d7..c9d5fba2ed0b59 100644
--- a/Content.Shared/Interaction/Events/ContactInteractionEvent.cs
+++ b/Content.Shared/Interaction/Events/ContactInteractionEvent.cs
@@ -8,7 +8,7 @@ namespace Content.Shared.Interaction.Events;
///
public sealed class ContactInteractionEvent : HandledEntityEventArgs
{
- public EntityUid Other;
+ public readonly EntityUid Other;
public ContactInteractionEvent(EntityUid other)
{
diff --git a/Content.Shared/Interaction/Events/InteractionFailureEvent.cs b/Content.Shared/Interaction/Events/InteractionFailureEvent.cs
index 8670164293951b..a820048104d0f5 100644
--- a/Content.Shared/Interaction/Events/InteractionFailureEvent.cs
+++ b/Content.Shared/Interaction/Events/InteractionFailureEvent.cs
@@ -3,7 +3,5 @@ namespace Content.Shared.Interaction.Events;
///
/// Raised on the target when failing to pet/hug something.
///
-// 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);
diff --git a/Content.Shared/Interaction/Events/InteractionSuccessEvent.cs b/Content.Shared/Interaction/Events/InteractionSuccessEvent.cs
index 9395ddc910c9c5..da4f9e43d7d263 100644
--- a/Content.Shared/Interaction/Events/InteractionSuccessEvent.cs
+++ b/Content.Shared/Interaction/Events/InteractionSuccessEvent.cs
@@ -3,7 +3,5 @@ namespace Content.Shared.Interaction.Events;
///
/// Raised on the target when successfully petting/hugging something.
///
-// 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);
diff --git a/Content.Shared/Interaction/SharedInteractionSystem.cs b/Content.Shared/Interaction/SharedInteractionSystem.cs
index 6f44d3089d1524..ddbf3ee57294ee 100644
--- a/Content.Shared/Interaction/SharedInteractionSystem.cs
+++ b/Content.Shared/Interaction/SharedInteractionSystem.cs
@@ -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)
{
@@ -480,8 +466,7 @@ public void InteractHand(EntityUid user, EntityUid target)
checkCanInteract: false,
checkUseDelay: true,
checkAccess: false,
- complexInteractions: complexInteractions,
- checkDeletion: false);
+ complexInteractions: complexInteractions);
return;
}
@@ -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);
@@ -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(
@@ -535,10 +514,9 @@ 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);
@@ -546,12 +524,12 @@ public void InteractUsingRanged(EntityUid user, EntityUid used, EntityUid? targe
// 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)
@@ -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;
@@ -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;
@@ -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);
@@ -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;
}
@@ -1039,14 +1004,11 @@ public bool InteractUsing(
/// Whether the is in range of the .
///
/// True if the interaction was handled. Otherwise, false.
- 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);
@@ -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);
@@ -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
@@ -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;
@@ -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
@@ -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.
@@ -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);
}
///
@@ -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);
@@ -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));
}