Add a component that inserts the held item when no interaction happens on the stored item (#29823)

* Insert when held item has no interaction with stored item

* Decouple inserting on failure

* Add component that stores the used entity when no interaction happened

* Add prediction
This commit is contained in:
ShadowCommander
2024-08-10 19:29:44 -07:00
committed by GitHub
parent d7c3ba8409
commit 2f77d0d4f3
5 changed files with 93 additions and 25 deletions

View File

@@ -918,11 +918,21 @@ namespace Content.Shared.Interaction
}
/// <summary>
/// Uses a item/object on an entity
/// Uses an item/object on an entity
/// Finds components with the InteractUsing interface and calls their function
/// NOTE: Does not have an InRangeUnobstructed check
/// </summary>
public void InteractUsing(
/// <param name="user">User doing the interaction.</param>
/// <param name="used">Item being used on the <paramref name="target"/>.</param>
/// <param name="target">Entity getting interacted with by the <paramref name="user"/> using the
/// <paramref name="used"/> entity.</param>
/// <param name="clickLocation">The location that the <paramref name="user"/> clicked.</param>
/// <param name="checkCanInteract">Whether to check that the <paramref name="user"/> can interact with the
/// <paramref name="target"/>.</param>
/// <param name="checkCanUse">Whether to check that the <paramref name="user"/> can use the
/// <paramref name="used"/> entity.</param>
/// <returns>True if the interaction was handled. Otherwise, false.</returns>
public bool InteractUsing(
EntityUid user,
EntityUid used,
EntityUid target,
@@ -931,10 +941,10 @@ namespace Content.Shared.Interaction
bool checkCanUse = true)
{
if (checkCanInteract && !_actionBlockerSystem.CanInteract(user, target))
return;
return false;
if (checkCanUse && !_actionBlockerSystem.CanUseHeldEntity(user, used))
return;
return false;
_adminLogger.Add(
LogType.InteractUsing,
@@ -942,7 +952,7 @@ namespace Content.Shared.Interaction
$"{ToPrettyString(user):user} interacted with {ToPrettyString(target):target} using {ToPrettyString(used):used}");
if (RangedInteractDoBefore(user, used, target, clickLocation, true))
return;
return true;
// all interactions should only happen when in range / unobstructed, so no range check is needed
var interactUsingEvent = new InteractUsingEvent(user, used, target, clickLocation);
@@ -951,15 +961,24 @@ namespace Content.Shared.Interaction
DoContactInteraction(user, target, interactUsingEvent);
// Contact interactions are currently only used for forensics, so we don't raise used -> target
if (interactUsingEvent.Handled)
return;
return true;
InteractDoAfter(user, used, target, clickLocation, canReach: true);
if (InteractDoAfter(user, used, target, clickLocation, canReach: true))
return true;
return false;
}
/// <summary>
/// Used when clicking on an entity resulted in no other interaction. Used for low-priority interactions.
/// </summary>
public void InteractDoAfter(EntityUid user, EntityUid used, EntityUid? target, EntityCoordinates clickLocation, bool canReach)
/// <param name="user"><inheritdoc cref="InteractUsing"/></param>
/// <param name="used"><inheritdoc cref="InteractUsing"/></param>
/// <param name="target"><inheritdoc cref="InteractUsing"/></param>
/// <param name="clickLocation"><inheritdoc cref="InteractUsing"/></param>
/// <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)
{
if (target is { Valid: false })
target = null;
@@ -974,10 +993,10 @@ namespace Content.Shared.Interaction
}
if (afterInteractEvent.Handled)
return;
return true;
if (target == null)
return;
return false;
var afterInteractUsingEvent = new AfterInteractUsingEvent(user, used, target, clickLocation, canReach);
RaiseLocalEvent(target.Value, afterInteractUsingEvent);
@@ -988,6 +1007,10 @@ namespace Content.Shared.Interaction
DoContactInteraction(user, target, afterInteractUsingEvent);
// Contact interactions are currently only used for forensics, so we don't raise used -> target
}
if (afterInteractUsingEvent.Handled)
return true;
return false;
}
#region ActivateItemInWorld