Remove IUse (#7074)

This commit is contained in:
Leon Friedrich
2022-03-13 01:33:23 +13:00
committed by GitHub
parent c908a843ab
commit b1e719c70d
42 changed files with 109 additions and 158 deletions

View File

@@ -1,14 +1,13 @@
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects;
namespace Content.Shared.Interaction.Events
namespace Content.Shared.Interaction.Events;
public sealed class ChangeDirectionAttemptEvent : CancellableEntityEventArgs
{
public sealed class ChangeDirectionAttemptEvent : CancellableEntityEventArgs
public ChangeDirectionAttemptEvent(EntityUid uid)
{
public ChangeDirectionAttemptEvent(EntityUid uid)
{
Uid = uid;
}
public EntityUid Uid { get; }
Uid = uid;
}
public EntityUid Uid { get; }
}

View File

@@ -0,0 +1,20 @@
using JetBrains.Annotations;
namespace Content.Shared.Interaction.Events;
/// <summary>
/// Raised when using the entity in your hands.
/// </summary>
[PublicAPI]
public sealed class UseInHandEvent : HandledEntityEventArgs
{
/// <summary>
/// Entity holding the item in their hand.
/// </summary>
public EntityUid User { get; }
public UseInHandEvent(EntityUid user)
{
User = user;
}
}

View File

@@ -1,55 +0,0 @@
using System;
using JetBrains.Annotations;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
namespace Content.Shared.Interaction
{
/// <summary>
/// This interface gives components behavior when using the entity in your active hand
/// (done by clicking the entity in the active hand or pressing the keybind that defaults to Z).
/// </summary>
[RequiresExplicitImplementation]
public interface IUse
{
/// <summary>
/// Called when we activate an object we are holding to use it
/// </summary>
/// <returns></returns>
[Obsolete("Use UseInHandMessage instead")]
bool UseEntity(UseEntityEventArgs eventArgs);
}
public sealed class UseEntityEventArgs : EventArgs
{
public UseEntityEventArgs(EntityUid user)
{
User = user;
}
public EntityUid User { get; }
}
/// <summary>
/// Raised when using the entity in your hands.
/// </summary>
[PublicAPI]
public sealed class UseInHandEvent : HandledEntityEventArgs
{
/// <summary>
/// Entity holding the item in their hand.
/// </summary>
public EntityUid User { get; }
/// <summary>
/// Item that was used.
/// </summary>
public EntityUid Used { get; }
public UseInHandEvent(EntityUid user, EntityUid used)
{
User = user;
Used = used;
}
}
}

View File

@@ -1,7 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading.Tasks;
using Content.Shared.ActionBlocker;
using Content.Shared.Administration.Logs;
using Content.Shared.CombatMode;
@@ -26,6 +24,7 @@ using Content.Shared.Item;
using Robust.Shared.Player;
using Robust.Shared.Input;
using Robust.Shared.Timing;
using Content.Shared.Interaction.Events;
#pragma warning disable 618
@@ -786,7 +785,7 @@ namespace Content.Shared.Interaction
if (checkCanUse && !_actionBlockerSystem.CanUseHeldEntity(user))
return false;
var useMsg = new UseInHandEvent(user, used);
var useMsg = new UseInHandEvent(user);
RaiseLocalEvent(used, useMsg);
if (useMsg.Handled)
{
@@ -794,19 +793,6 @@ namespace Content.Shared.Interaction
return true;
}
var uses = AllComps<IUse>(used).ToList();
// Try to use item on any components which have the interface
foreach (var use in uses)
{
// If a Use returns a status completion we finish our interaction
if (use.UseEntity(new UseEntityEventArgs(user)))
{
_useDelay.BeginDelay(used, delayComponent);
return true;
}
}
// else, default to activating the item
return InteractionActivate(user, used, false, false, false);
}