using Content.Server.Popups;
using Content.Shared.Atmos;
using Content.Shared.Atmos.Piping.Binary.Components;
+using Content.Shared.Containers.ItemSlots;
using Content.Shared.Database;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly UserInterfaceSystem _ui = default!;
[Dependency] private readonly NodeContainerSystem _nodeContainer = default!;
+ [Dependency] private readonly ItemSlotsSystem _slots = default!;
public override void Initialize()
{
SubscribeLocalEvent<GasCanisterComponent, AtmosDeviceUpdateEvent>(OnCanisterUpdated);
SubscribeLocalEvent<GasCanisterComponent, ActivateInWorldEvent>(OnCanisterActivate, after: new[] { typeof(LockSystem) });
SubscribeLocalEvent<GasCanisterComponent, InteractHandEvent>(OnCanisterInteractHand);
- SubscribeLocalEvent<GasCanisterComponent, InteractUsingEvent>(OnCanisterInteractUsing);
+ SubscribeLocalEvent<GasCanisterComponent, ItemSlotInsertAttemptEvent>(OnCanisterInsertAttempt);
SubscribeLocalEvent<GasCanisterComponent, EntInsertedIntoContainerMessage>(OnCanisterContainerInserted);
SubscribeLocalEvent<GasCanisterComponent, EntRemovedFromContainerMessage>(OnCanisterContainerRemoved);
SubscribeLocalEvent<GasCanisterComponent, PriceCalculationEvent>(CalculateCanisterPrice);
private void OnCanisterStartup(EntityUid uid, GasCanisterComponent comp, ComponentStartup args)
{
- // Ensure container manager.
- var containerManager = EnsureComp<ContainerManagerComponent>(uid);
-
- // Ensure container.
- _container.EnsureContainer<ContainerSlot>(uid, comp.ContainerName, containerManager);
+ // Ensure container
+ _slots.AddItemSlot(uid, comp.ContainerName, comp.GasTankSlot);
if (TryComp<LockComponent>(uid, out var lockComp))
{
}
private void DirtyUI(EntityUid uid,
- GasCanisterComponent? canister = null, NodeContainerComponent? nodeContainer = null,
- ContainerManagerComponent? containerManager = null)
+ GasCanisterComponent? canister = null, NodeContainerComponent? nodeContainer = null)
{
- if (!Resolve(uid, ref canister, ref nodeContainer, ref containerManager))
+ if (!Resolve(uid, ref canister, ref nodeContainer))
return;
var portStatus = false;
if (_nodeContainer.TryGetNode(nodeContainer, canister.PortName, out PipeNode? portNode) && portNode.NodeGroup?.Nodes.Count > 1)
portStatus = true;
- if (containerManager.TryGetContainer(canister.ContainerName, out var tankContainer)
- && tankContainer.ContainedEntities.Count > 0)
+ if (canister.GasTankSlot.Item != null)
{
- var tank = tankContainer.ContainedEntities[0];
+ var tank = canister.GasTankSlot.Item.Value;
var tankComponent = Comp<GasTankComponent>(tank);
tankLabel = Name(tank);
tankPressure = tankComponent.Air.Pressure;
private void OnHoldingTankEjectMessage(EntityUid uid, GasCanisterComponent canister, GasCanisterHoldingTankEjectMessage args)
{
- if (!TryComp<ContainerManagerComponent>(uid, out var containerManager)
- || !containerManager.TryGetContainer(canister.ContainerName, out var container))
- return;
-
- if (container.ContainedEntities.Count == 0)
+ if (canister.GasTankSlot.Item == null || args.Session.AttachedEntity == null)
return;
- _adminLogger.Add(LogType.CanisterTankEjected, LogImpact.Medium, $"Player {ToPrettyString(args.Session.AttachedEntity.GetValueOrDefault()):player} ejected tank {ToPrettyString(container.ContainedEntities[0]):tank} from {ToPrettyString(uid):canister}");
- container.Remove(container.ContainedEntities[0]);
+ var item = canister.GasTankSlot.Item;
+ _slots.TryEjectToHands(uid, canister.GasTankSlot, args.Session.AttachedEntity);
+ _adminLogger.Add(LogType.CanisterTankEjected, LogImpact.Medium, $"Player {ToPrettyString(args.Session.AttachedEntity.GetValueOrDefault()):player} ejected tank {ToPrettyString(item):tank} from {ToPrettyString(uid):canister}");
}
private void OnCanisterChangeReleasePressure(EntityUid uid, GasCanisterComponent canister, GasCanisterChangeReleasePressureMessage args)
private void OnCanisterChangeReleaseValve(EntityUid uid, GasCanisterComponent canister, GasCanisterChangeReleaseValveMessage args)
{
- var impact = LogImpact.High;
- if (TryComp<ContainerManagerComponent>(uid, out var containerManager)
- && containerManager.TryGetContainer(canister.ContainerName, out var container))
- {
- // filling a jetpack with plasma is less important than filling a room with it
- impact = container.ContainedEntities.Count != 0 ? LogImpact.Medium : LogImpact.High;
- }
+ var impact = LogImpact.High;
+ // filling a jetpack with plasma is less important than filling a room with it
+ impact = canister.GasTankSlot.HasItem ? LogImpact.Medium : LogImpact.High;
var containedGasDict = new Dictionary<Gas, float>();
var containedGasArray = Gas.GetValues(typeof(Gas));
{
MixContainerWithPipeNet(canister.Air, net.Air);
}
-
- ContainerManagerComponent? containerManager = null;
-
+
// Release valve is open, release gas.
if (canister.ReleaseValve)
{
- if (!TryComp(uid, out containerManager)
- || !containerManager.TryGetContainer(canister.ContainerName, out var container))
- return;
-
- if (container.ContainedEntities.Count > 0)
+ if (canister.GasTankSlot.Item != null)
{
- var gasTank = Comp<GasTankComponent>(container.ContainedEntities[0]);
+ var gasTank = Comp<GasTankComponent>(canister.GasTankSlot.Item.Value);
_atmos.ReleaseGasTo(canister.Air, gasTank.Air, canister.ReleasePressure);
}
else
if (MathHelper.CloseToPercent(canister.Air.Pressure, canister.LastPressure))
return;
- DirtyUI(uid, canister, nodeContainer, containerManager);
+ DirtyUI(uid, canister, nodeContainer);
canister.LastPressure = canister.Air.Pressure;
args.Handled = true;
}
- private void OnCanisterInteractUsing(EntityUid uid, GasCanisterComponent component, InteractUsingEvent args)
+ private void OnCanisterInsertAttempt(EntityUid uid, GasCanisterComponent component, ref ItemSlotInsertAttemptEvent args)
{
- var container = _container.EnsureContainer<ContainerSlot>(uid, component.ContainerName);
-
- // Container full.
- if (container.ContainedEntity != null)
+ if (args.Slot.ID != component.ContainerName || args.User == null)
return;
- // Check the used item is valid...
- if (!TryComp<GasTankComponent>(args.Used, out var gasTank) || gasTank.IsValveOpen)
+ if (!TryComp<GasTankComponent>(args.Item, out var gasTank) || gasTank.IsValveOpen)
+ {
+ args.Cancelled = true;
return;
+ }
// Preventing inserting a tank since if its locked you cant remove it.
- if (CheckLocked(uid, component, args.User))
+ if (!CheckLocked(uid, component, args.User.Value))
return;
-
- if (!_hands.TryDropIntoContainer(args.User, args.Used, container))
- return;
-
- _adminLogger.Add(LogType.CanisterTankInserted, LogImpact.Medium, $"Player {ToPrettyString(args.User):player} inserted tank {ToPrettyString(container.ContainedEntities[0]):tank} into {ToPrettyString(uid):canister}");
-
- args.Handled = true;
+
+ args.Cancelled = true;
}
private void OnCanisterContainerInserted(EntityUid uid, GasCanisterComponent component, EntInsertedIntoContainerMessage args)
if (TryComp<LockComponent>(uid, out var lockComp) && lockComp.Locked)
{
_popup.PopupEntity(Loc.GetString("gas-canister-popup-denied"), uid, user);
- if (comp.AccessDeniedSound != null)
- {
- _audio.PlayPvs(comp.AccessDeniedSound, uid);
- }
+ _audio.PlayPvs(comp.AccessDeniedSound, uid);
return true;
}