Remove IUse (#7074)
This commit is contained in:
@@ -2,6 +2,7 @@ using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Acts;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Sound;
|
||||
using Content.Shared.Verbs;
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
|
||||
20
Content.Shared/Interaction/Events/UseInHandEvent.cs
Normal file
20
Content.Shared/Interaction/Events/UseInHandEvent.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Helpers;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Inventory.Events;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Movement.EntitySystems;
|
||||
@@ -10,9 +9,6 @@ using Content.Shared.Popups;
|
||||
using Content.Shared.Strip.Components;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Timing;
|
||||
@@ -33,9 +29,47 @@ public abstract partial class InventorySystem
|
||||
SubscribeLocalEvent<InventoryComponent, EntInsertedIntoContainerMessage>(OnEntInserted);
|
||||
SubscribeLocalEvent<InventoryComponent, EntRemovedFromContainerMessage>(OnEntRemoved);
|
||||
|
||||
SubscribeLocalEvent<SharedItemComponent, UseInHandEvent>(OnUseInHand);
|
||||
|
||||
SubscribeAllEvent<UseSlotNetworkMessage>(OnUseSlot);
|
||||
}
|
||||
|
||||
private void OnUseInHand(EntityUid uid, SharedItemComponent component, UseInHandEvent args)
|
||||
{
|
||||
if (args.Handled || !component.QuickEquip)
|
||||
return;
|
||||
|
||||
if (!TryComp(args.User, out InventoryComponent? inv)
|
||||
|| !TryComp(args.User, out SharedHandsComponent? hands)
|
||||
|| !_prototypeManager.TryIndex<InventoryTemplatePrototype>(inv.TemplateId, out var prototype))
|
||||
return;
|
||||
|
||||
foreach (var slotDef in prototype.Slots)
|
||||
{
|
||||
if (!CanEquip(args.User, uid, slotDef.Name, out _, slotDef, inv))
|
||||
continue;
|
||||
|
||||
if (TryGetSlotEntity(args.User, slotDef.Name, out var slotEntity, inv))
|
||||
{
|
||||
if (!TryUnequip(args.User, slotDef.Name, true, inventory: inv))
|
||||
continue;
|
||||
|
||||
if (!TryEquip(args.User, uid, slotDef.Name, true, inventory: inv))
|
||||
continue;
|
||||
|
||||
hands.PutInHandOrDrop(slotEntity.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!TryEquip(args.User, uid, slotDef.Name, true, inventory: inv))
|
||||
continue;
|
||||
}
|
||||
|
||||
args.Handled = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEntRemoved(EntityUid uid, InventoryComponent component, EntRemovedFromContainerMessage args)
|
||||
{
|
||||
if(!TryGetSlot(uid, args.Container.ID, out var slotDef, inventory: component))
|
||||
|
||||
@@ -1,17 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Helpers;
|
||||
using Content.Shared.Inventory;
|
||||
using Content.Shared.Sound;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using static Robust.Shared.GameObjects.SharedSpriteComponent;
|
||||
|
||||
namespace Content.Shared.Item
|
||||
@@ -24,6 +15,9 @@ namespace Content.Shared.Item
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entMan = default!;
|
||||
|
||||
[DataField("quickEquip")]
|
||||
public bool QuickEquip = true;
|
||||
|
||||
/// <summary>
|
||||
/// How much big this item is.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user