Change gas canisters to use ItemSlots (#22561)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Content.Shared.Atmos;
|
||||
using Content.Shared.Containers.ItemSlots;
|
||||
using Robust.Shared.Audio;
|
||||
|
||||
namespace Content.Server.Atmos.Piping.Unary.Components
|
||||
@@ -15,7 +16,11 @@ namespace Content.Server.Atmos.Piping.Unary.Components
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("container")]
|
||||
public string ContainerName { get; set; } = "GasCanisterTankHolder";
|
||||
public string ContainerName { get; set; } = "tank_slot";
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField]
|
||||
public ItemSlot GasTankSlot = new();
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("gasMixture")]
|
||||
|
||||
@@ -11,6 +11,7 @@ using Content.Server.NodeContainer.Nodes;
|
||||
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;
|
||||
@@ -34,6 +35,7 @@ public sealed class GasCanisterSystem : EntitySystem
|
||||
[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()
|
||||
{
|
||||
@@ -43,7 +45,7 @@ public sealed class GasCanisterSystem : EntitySystem
|
||||
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);
|
||||
@@ -74,11 +76,8 @@ public sealed class GasCanisterSystem : EntitySystem
|
||||
|
||||
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))
|
||||
{
|
||||
@@ -87,10 +86,9 @@ public sealed class GasCanisterSystem : EntitySystem
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -100,10 +98,9 @@ public sealed class GasCanisterSystem : EntitySystem
|
||||
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;
|
||||
@@ -117,15 +114,12 @@ public sealed class GasCanisterSystem : EntitySystem
|
||||
|
||||
private void OnHoldingTankEjectMessage(EntityUid uid, GasCanisterComponent canister, GasCanisterHoldingTankEjectMessage args)
|
||||
{
|
||||
if (!TryComp<ContainerManagerComponent>(uid, out var containerManager)
|
||||
|| !containerManager.TryGetContainer(canister.ContainerName, out var container))
|
||||
if (canister.GasTankSlot.Item == null || args.Session.AttachedEntity == null)
|
||||
return;
|
||||
|
||||
if (container.ContainedEntities.Count == 0)
|
||||
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)
|
||||
@@ -140,13 +134,9 @@ public sealed class GasCanisterSystem : EntitySystem
|
||||
|
||||
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));
|
||||
@@ -177,19 +167,13 @@ public sealed class GasCanisterSystem : EntitySystem
|
||||
{
|
||||
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
|
||||
@@ -203,7 +187,7 @@ public sealed class GasCanisterSystem : EntitySystem
|
||||
if (MathHelper.CloseToPercent(canister.Air.Pressure, canister.LastPressure))
|
||||
return;
|
||||
|
||||
DirtyUI(uid, canister, nodeContainer, containerManager);
|
||||
DirtyUI(uid, canister, nodeContainer);
|
||||
|
||||
canister.LastPressure = canister.Air.Pressure;
|
||||
|
||||
@@ -254,28 +238,22 @@ public sealed class GasCanisterSystem : EntitySystem
|
||||
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)
|
||||
@@ -347,10 +325,7 @@ public sealed class GasCanisterSystem : EntitySystem
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@
|
||||
joinSystem: true
|
||||
- type: ContainerContainer
|
||||
containers:
|
||||
GasCanisterTankHolder: !type:ContainerSlot {}
|
||||
tank_slot: !type:ContainerSlot {}
|
||||
- type: NodeContainer
|
||||
nodes:
|
||||
port:
|
||||
@@ -88,8 +88,14 @@
|
||||
nodeGroupID: Pipe
|
||||
rotationsEnabled: false
|
||||
volume: 1
|
||||
- type: ItemSlots
|
||||
- type: GasPortable
|
||||
- type: GasCanister
|
||||
tank_slot:
|
||||
name: Gas Tank
|
||||
whitelist:
|
||||
component:
|
||||
- GasTank
|
||||
- type: StaticPrice
|
||||
price: 1000
|
||||
- type: AccessReader
|
||||
|
||||
Reference in New Issue
Block a user