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,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))