Remove InteractedWithEvent and friends. (#11939)

This commit is contained in:
Leon Friedrich
2022-10-26 14:15:48 +13:00
committed by GitHub
parent b03f17bda2
commit c0b657ca18
21 changed files with 133 additions and 101 deletions

View File

@@ -261,7 +261,8 @@ namespace Content.Shared.Interaction
if (target != null)
{
var ev = new InteractNoHandEvent(user, target.Value);
RaiseLocalEvent(user, ev, true);
RaiseLocalEvent(user, ev);
DoContactInteraction(user, target.Value, ev);
}
return;
}
@@ -316,6 +317,7 @@ namespace Content.Shared.Interaction
var message = new InteractHandEvent(user, target);
RaiseLocalEvent(target, message, true);
_adminLogger.Add(LogType.InteractHand, LogImpact.Low, $"{ToPrettyString(user):user} interacted with {ToPrettyString(target):target}");
DoContactInteraction(user, target, message);
if (message.Handled)
return;
@@ -337,6 +339,9 @@ namespace Content.Shared.Interaction
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;
}
@@ -722,6 +727,9 @@ namespace Content.Shared.Interaction
{
var ev = new BeforeRangedInteractEvent(user, used, target, clickLocation, canReach);
RaiseLocalEvent(used, ev);
// We contact the USED entity, but not the target.
DoContactInteraction(user, used, ev);
return ev.Handled;
}
@@ -750,6 +758,9 @@ namespace Content.Shared.Interaction
// 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);
DoContactInteraction(user, used, interactUsingEvent);
DoContactInteraction(user, target, interactUsingEvent);
DoContactInteraction(used, target, interactUsingEvent);
if (interactUsingEvent.Handled)
return;
@@ -765,7 +776,14 @@ namespace Content.Shared.Interaction
target = null;
var afterInteractEvent = new AfterInteractEvent(user, used, target, clickLocation, canReach);
RaiseLocalEvent(used, afterInteractEvent, false);
RaiseLocalEvent(used, afterInteractEvent);
DoContactInteraction(user, used, afterInteractEvent);
if (canReach)
{
DoContactInteraction(user, target, afterInteractEvent);
DoContactInteraction(used, target, afterInteractEvent);
}
if (afterInteractEvent.Handled)
return;
@@ -774,6 +792,13 @@ namespace Content.Shared.Interaction
var afterInteractUsingEvent = new AfterInteractUsingEvent(user, used, target, clickLocation, canReach);
RaiseLocalEvent(target.Value, afterInteractUsingEvent);
DoContactInteraction(user, used, afterInteractUsingEvent);
if (canReach)
{
DoContactInteraction(user, target, afterInteractUsingEvent);
DoContactInteraction(used, target, afterInteractUsingEvent);
}
}
#region ActivateItemInWorld
@@ -832,6 +857,7 @@ namespace Content.Shared.Interaction
if (!activateMsg.Handled)
return false;
DoContactInteraction(user, used, activateMsg);
_useDelay.BeginDelay(used, delayComponent);
_adminLogger.Add(LogType.InteractActivate, LogImpact.Low, $"{ToPrettyString(user):user} activated {ToPrettyString(used):used}");
return true;
@@ -869,6 +895,7 @@ namespace Content.Shared.Interaction
RaiseLocalEvent(used, useMsg, true);
if (useMsg.Handled)
{
DoContactInteraction(user, used, useMsg);
_useDelay.BeginDelay(used, delayComponent);
return true;
}
@@ -977,6 +1004,18 @@ namespace Content.Shared.Interaction
return true;
}
/// <summary>
/// Simple convenience function to raise contact events (disease, forensics, etc).
/// </summary>
public void DoContactInteraction(EntityUid uidA, EntityUid? uidB, HandledEntityEventArgs? args = null)
{
if (uidB == null || args?.Handled == false)
return;
RaiseLocalEvent(uidA, new ContactInteractionEvent(uidB.Value));
RaiseLocalEvent(uidB.Value, new ContactInteractionEvent(uidA));
}
}
/// <summary>