2023-11-19 17:44:42 +00:00
|
|
|
using Content.Shared.Explosion;
|
2024-08-28 09:54:39 +03:00
|
|
|
using Content.Shared.Hands.EntitySystems;
|
2021-12-30 22:56:10 +01:00
|
|
|
using Content.Shared.Inventory;
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.Inventory
|
|
|
|
|
{
|
2022-04-28 06:11:15 -06:00
|
|
|
public sealed class ServerInventorySystem : InventorySystem
|
2021-12-30 22:56:10 +01:00
|
|
|
{
|
2024-08-28 09:54:39 +03:00
|
|
|
[Dependency] private readonly SharedHandsSystem _hands = default!; // WD
|
|
|
|
|
|
2021-12-30 22:56:10 +01:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
2023-11-19 17:44:42 +00:00
|
|
|
SubscribeLocalEvent<InventoryComponent, BeforeExplodeEvent>(OnExploded);
|
2021-12-30 22:56:10 +01:00
|
|
|
}
|
|
|
|
|
|
2023-11-19 17:44:42 +00:00
|
|
|
private void OnExploded(Entity<InventoryComponent> ent, ref BeforeExplodeEvent args)
|
|
|
|
|
{
|
|
|
|
|
// explode each item in their inventory too
|
2023-12-07 16:20:51 -05:00
|
|
|
var slots = new InventorySlotEnumerator(ent);
|
2023-11-19 17:44:42 +00:00
|
|
|
while (slots.MoveNext(out var slot))
|
|
|
|
|
{
|
|
|
|
|
if (slot.ContainedEntity != null)
|
|
|
|
|
args.Contents.Add(slot.ContainedEntity.Value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-07 16:20:51 -05:00
|
|
|
public void TransferEntityInventories(Entity<InventoryComponent?> source, Entity<InventoryComponent?> target)
|
2022-06-12 01:53:13 -04:00
|
|
|
{
|
2023-12-07 16:20:51 -05:00
|
|
|
if (!Resolve(source.Owner, ref source.Comp) || !Resolve(target.Owner, ref target.Comp))
|
2023-03-06 12:37:18 -05:00
|
|
|
return;
|
|
|
|
|
|
2023-12-07 16:20:51 -05:00
|
|
|
var enumerator = new InventorySlotEnumerator(source.Comp);
|
2024-03-21 04:54:07 +09:00
|
|
|
// WD EDIT START
|
|
|
|
|
List<(EntityUid, string)> items = new();
|
2023-12-07 16:20:51 -05:00
|
|
|
while (enumerator.NextItem(out var item, out var slot))
|
2023-03-06 12:37:18 -05:00
|
|
|
{
|
2024-03-21 04:54:07 +09:00
|
|
|
items.Add((item, slot.Name));
|
2022-06-12 01:53:13 -04:00
|
|
|
}
|
2024-03-21 04:54:07 +09:00
|
|
|
|
|
|
|
|
foreach (var (item, name) in items)
|
|
|
|
|
{
|
|
|
|
|
TryUnequip(source, name, true, true, inventory: source.Comp);
|
|
|
|
|
TryEquip(target, item, name, true, true, inventory: target.Comp);
|
|
|
|
|
}
|
|
|
|
|
// WD EDIT END
|
2022-06-12 01:53:13 -04:00
|
|
|
}
|
2024-08-28 09:54:39 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// WD edit start - new helper method for drop anything from inventory.
|
|
|
|
|
public void DropAnything(EntityUid uid)
|
|
|
|
|
{
|
|
|
|
|
if (TryGetContainerSlotEnumerator(uid, out var enumerator))
|
|
|
|
|
{
|
|
|
|
|
while (enumerator.MoveNext(out var slot))
|
|
|
|
|
{
|
|
|
|
|
TryUnequip(uid, slot.ID, true, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var held in _hands.EnumerateHeld(uid))
|
|
|
|
|
{
|
|
|
|
|
_hands.TryDrop(uid, held);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// WD edit end
|
2021-12-30 22:56:10 +01:00
|
|
|
}
|
|
|
|
|
}
|