Files
tbd-station-14/Content.Server/Inventory/ServerInventorySystem.cs
SlamBamActionman a44baec417 Fix forensics not being applied to held items (#30609)
* Initial commit

* Fix merge changes

* sloth comment: bitmask

* fix MIA parameter

---------

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Co-authored-by: EmoGarbage404 <retron404@gmail.com>
2025-04-18 21:02:41 -04:00

40 lines
1.4 KiB
C#

using Content.Shared.Explosion;
using Content.Shared.Inventory;
namespace Content.Server.Inventory
{
public sealed class ServerInventorySystem : InventorySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<InventoryComponent, BeforeExplodeEvent>(OnExploded);
}
private void OnExploded(Entity<InventoryComponent> ent, ref BeforeExplodeEvent args)
{
// explode each item in their inventory too
var slots = new InventorySlotEnumerator(ent);
while (slots.MoveNext(out var slot))
{
if (slot.ContainedEntity != null)
args.Contents.Add(slot.ContainedEntity.Value);
}
}
public void TransferEntityInventories(Entity<InventoryComponent?> source, Entity<InventoryComponent?> target)
{
if (!Resolve(source.Owner, ref source.Comp) || !Resolve(target.Owner, ref target.Comp))
return;
var enumerator = new InventorySlotEnumerator(source.Comp);
while (enumerator.NextItem(out var item, out var slot))
{
if (TryUnequip(source, slot.Name, true, true, inventory: source.Comp, triggerHandContact: true))
TryEquip(target, item, slot.Name , true, true, inventory: target.Comp, triggerHandContact: true);
}
}
}
}