40 lines
1.4 KiB
C#
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))
|
|
TryEquip(target, item, slot.Name , true, true, inventory: target.Comp);
|
|
}
|
|
}
|
|
}
|
|
}
|