]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Change gas canisters to use ItemSlots (#22561)
authorKara <lunarautomaton6@gmail.com>
Sat, 16 Dec 2023 08:28:27 +0000 (01:28 -0700)
committerGitHub <noreply@github.com>
Sat, 16 Dec 2023 08:28:27 +0000 (01:28 -0700)
Content.Server/Atmos/Piping/Unary/Components/GasCanisterComponent.cs
Content.Server/Atmos/Piping/Unary/EntitySystems/GasCanisterSystem.cs
Resources/Prototypes/Entities/Structures/Storage/Canisters/gas_canisters.yml

index 178e169888bef76a228a4506f99e57a950375a61..1daa42d7c40d86c3917868f93852240037ae1bf2 100644 (file)
@@ -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")]
index 1ec1bdb1c17733e1ab9404b2d306928db3cdf4b2..8ac91ce0efce5e07d0f5f9b2846bf041a4233cb8 100644 (file)
@@ -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))
-            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)
@@ -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;
         }
index ee726083b67712e1b6ebec7f71148e4094494418..458f7178eaff1d4eca68a0f5d3bb32508a753573 100644 (file)
@@ -80,7 +80,7 @@
       joinSystem: true
     - type: ContainerContainer
       containers:
-        GasCanisterTankHolder: !type:ContainerSlot {}
+        tank_slot: !type:ContainerSlot {}
     - type: NodeContainer
       nodes:
         port:
           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