| 123456789101112131415161718192021222324252627282930313233343536373839 |
- 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);
- }
- }
- }
- }
|