2023-11-11 07:42:59 +01:00
|
|
|
using Content.Shared.Construction;
|
2021-12-05 21:02:04 +01:00
|
|
|
using Content.Shared.Containers.ItemSlots;
|
2021-11-02 09:04:07 +00:00
|
|
|
using JetBrains.Annotations;
|
|
|
|
|
using Robust.Shared.Containers;
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.Containers
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Implements functionality of EmptyOnMachineDeconstructComponent.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[UsedImplicitly]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class EmptyOnMachineDeconstructSystem : EntitySystem
|
2021-11-02 09:04:07 +00:00
|
|
|
{
|
2023-10-11 02:18:49 -07:00
|
|
|
[Dependency] private readonly SharedContainerSystem _container = default!;
|
|
|
|
|
|
2021-11-02 09:04:07 +00:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<EmptyOnMachineDeconstructComponent, MachineDeconstructedEvent>(OnDeconstruct);
|
2021-11-24 20:03:07 +13:00
|
|
|
SubscribeLocalEvent<ItemSlotsComponent, MachineDeconstructedEvent>(OnSlotsDeconstruct);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// really this should be handled by ItemSlotsSystem, but for whatever reason MachineDeconstructedEvent is server-side? So eh.
|
|
|
|
|
private void OnSlotsDeconstruct(EntityUid uid, ItemSlotsComponent component, MachineDeconstructedEvent args)
|
|
|
|
|
{
|
|
|
|
|
foreach (var slot in component.Slots.Values)
|
|
|
|
|
{
|
2023-12-27 21:30:03 -08:00
|
|
|
if (slot.EjectOnDeconstruct && slot.Item != null && slot.ContainerSlot != null)
|
|
|
|
|
_container.Remove(slot.Item.Value, slot.ContainerSlot);
|
2021-11-24 20:03:07 +13:00
|
|
|
}
|
2021-11-02 09:04:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnDeconstruct(EntityUid uid, EmptyOnMachineDeconstructComponent component, MachineDeconstructedEvent ev)
|
|
|
|
|
{
|
2023-08-24 16:39:15 +10:00
|
|
|
if (!EntityManager.TryGetComponent<ContainerManagerComponent>(uid, out var mComp))
|
2021-11-02 09:04:07 +00:00
|
|
|
return;
|
2023-10-11 02:18:49 -07:00
|
|
|
var baseCoords = EntityManager.GetComponent<TransformComponent>(uid).Coordinates;
|
2021-11-02 09:04:07 +00:00
|
|
|
foreach (var v in component.Containers)
|
|
|
|
|
{
|
|
|
|
|
if (mComp.TryGetContainer(v, out var container))
|
|
|
|
|
{
|
2023-10-11 02:18:49 -07:00
|
|
|
_container.EmptyContainer(container, true, baseCoords);
|
2021-11-02 09:04:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|