49 lines
1.5 KiB
C#
49 lines
1.5 KiB
C#
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;
|
|
|
|
if (args.Container.ID != component.CellSlotId)
|
|
return;
|
|
|
|
if (!HasComp<PowerCellComponent>(args.EntityUid))
|
|
{
|
|
args.Cancel();
|
|
}
|
|
}
|
|
|
|
private void OnCellInserted(EntityUid uid, PowerCellSlotComponent component, EntInsertedIntoContainerMessage args)
|
|
{
|
|
if (!component.Initialized)
|
|
return;
|
|
|
|
if (args.Container.ID != component.CellSlotId)
|
|
return;
|
|
|
|
RaiseLocalEvent(uid, new PowerCellChangedEvent(false), false);
|
|
}
|
|
|
|
private void OnCellRemoved(EntityUid uid, PowerCellSlotComponent component, EntRemovedFromContainerMessage args)
|
|
{
|
|
if (args.Container.ID != component.CellSlotId)
|
|
return;
|
|
|
|
RaiseLocalEvent(uid, new PowerCellChangedEvent(true), false);
|
|
}
|
|
}
|