2022-01-05 17:20:25 +13:00
|
|
|
using Content.Shared.PowerCell.Components;
|
|
|
|
|
using Robust.Shared.Containers;
|
|
|
|
|
|
|
|
|
|
namespace Content.Shared.PowerCell;
|
|
|
|
|
|
|
|
|
|
public abstract class SharedPowerCellSystem : EntitySystem
|
|
|
|
|
{
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
SubscribeLocalEvent<PowerCellSlotComponent, EntInsertedIntoContainerMessage>(OnCellInserted);
|
|
|
|
|
SubscribeLocalEvent<PowerCellSlotComponent, EntRemovedFromContainerMessage>(OnCellRemoved);
|
|
|
|
|
SubscribeLocalEvent<PowerCellSlotComponent, ContainerIsInsertingAttemptEvent>(OnCellInsertAttempt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnCellInsertAttempt(EntityUid uid, PowerCellSlotComponent component, ContainerIsInsertingAttemptEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (!component.Initialized)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-10-15 13:15:39 -07:00
|
|
|
if (args.Container.ID != component.CellSlotId)
|
2022-01-05 17:20:25 +13:00
|
|
|
return;
|
|
|
|
|
|
2022-06-16 18:37:07 +10:00
|
|
|
if (!HasComp<PowerCellComponent>(args.EntityUid))
|
2022-01-05 17:20:25 +13:00
|
|
|
{
|
|
|
|
|
args.Cancel();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnCellInserted(EntityUid uid, PowerCellSlotComponent component, EntInsertedIntoContainerMessage args)
|
|
|
|
|
{
|
|
|
|
|
if (!component.Initialized)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-10-15 13:15:39 -07:00
|
|
|
if (args.Container.ID != component.CellSlotId)
|
2022-01-05 17:20:25 +13:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
RaiseLocalEvent(uid, new PowerCellChangedEvent(false), false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnCellRemoved(EntityUid uid, PowerCellSlotComponent component, EntRemovedFromContainerMessage args)
|
|
|
|
|
{
|
2022-10-15 13:15:39 -07:00
|
|
|
if (args.Container.ID != component.CellSlotId)
|
2022-01-05 17:20:25 +13:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
RaiseLocalEvent(uid, new PowerCellChangedEvent(true), false);
|
|
|
|
|
}
|
|
|
|
|
}
|