]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Space Ninjas auto-toggle internals after spawning (#25083)
authorErrant <35878406+Errant-4@users.noreply.github.com>
Fri, 3 May 2024 01:24:21 +0000 (03:24 +0200)
committerGitHub <noreply@github.com>
Fri, 3 May 2024 01:24:21 +0000 (11:24 +1000)
* fix engine version

* actually fix engine version

* Automatically activated breathing masks

* weh

* who needed that component anyway

* check if internals are already running

* Update Content.Server/Atmos/Components/BreathToolComponent.cs

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
* Update Content.Server/Body/Systems/InternalsSystem.cs

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
* prediction

* record struct event

* remove delayed activation, instead ensure that masks spawn last

* leftover

* engine version

* re-implement

---------

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
Content.Client/Station/StationSpawningSystem.cs
Content.Server/Atmos/Components/BreathToolComponent.cs
Content.Server/Body/Systems/InternalsSystem.cs
Content.Server/Station/Systems/StationSpawningSystem.cs
Content.Shared/Inventory/InventorySystem.Slots.cs
Content.Shared/Roles/StartingGearEquippedEvent.cs [new file with mode: 0644]
Content.Shared/Station/SharedStationSpawningSystem.cs

index 65da518d229b01a0010391c010dc261a5f2b98b8..71dce5a78f395bcfb91c7763f8a47decd48bb437 100644 (file)
@@ -2,7 +2,4 @@ using Content.Shared.Station;
 
 namespace Content.Client.Station;
 
-public sealed class StationSpawningSystem : SharedStationSpawningSystem
-{
-
-}
+public sealed class StationSpawningSystem : SharedStationSpawningSystem;
index f3688ef7ffc9732822cc433def3be397202e4426..ae17a5d872f51660de395c16f5628641be37b980 100644 (file)
@@ -12,9 +12,10 @@ namespace Content.Server.Atmos.Components
         /// <summary>
         /// Tool is functional only in allowed slots
         /// </summary>
-        [DataField("allowedSlots")]
+        [DataField]
         public SlotFlags AllowedSlots = SlotFlags.MASK | SlotFlags.HEAD;
         public bool IsFunctional;
+
         public EntityUid? ConnectedInternalsEntity;
     }
 }
index 972967fb15a4a0bcc076675aec1367c7c52265c9..8afd1c767f66008bdbbdce63e364751ace5e0f4e 100644 (file)
@@ -8,6 +8,7 @@ using Content.Shared.DoAfter;
 using Content.Shared.Hands.Components;
 using Content.Shared.Internals;
 using Content.Shared.Inventory;
+using Content.Shared.Roles;
 using Content.Shared.Verbs;
 using Robust.Shared.Containers;
 using Robust.Shared.Utility;
@@ -23,17 +24,29 @@ public sealed class InternalsSystem : EntitySystem
     [Dependency] private readonly InventorySystem _inventory = default!;
     [Dependency] private readonly PopupSystem _popupSystem = default!;
 
-    public const SlotFlags InventorySlots = SlotFlags.POCKET | SlotFlags.BELT;
+    private EntityQuery<InternalsComponent> _internalsQuery;
 
     public override void Initialize()
     {
         base.Initialize();
 
+        _internalsQuery = GetEntityQuery<InternalsComponent>();
+
         SubscribeLocalEvent<InternalsComponent, InhaleLocationEvent>(OnInhaleLocation);
         SubscribeLocalEvent<InternalsComponent, ComponentStartup>(OnInternalsStartup);
         SubscribeLocalEvent<InternalsComponent, ComponentShutdown>(OnInternalsShutdown);
         SubscribeLocalEvent<InternalsComponent, GetVerbsEvent<InteractionVerb>>(OnGetInteractionVerbs);
         SubscribeLocalEvent<InternalsComponent, InternalsDoAfterEvent>(OnDoAfter);
+
+        SubscribeLocalEvent<StartingGearEquippedEvent>(OnStartingGear);
+    }
+
+    private void OnStartingGear(ref StartingGearEquippedEvent ev)
+    {
+        if (!_internalsQuery.TryComp(ev.Entity, out var internals) || internals.BreathToolEntity == null)
+            return;
+
+        ToggleInternals(ev.Entity, ev.Entity, force: false, internals);
     }
 
     private void OnGetInteractionVerbs(
@@ -217,7 +230,7 @@ public sealed class InternalsSystem : EntitySystem
         if (component.BreathToolEntity is null || !AreInternalsWorking(component))
             return 2;
 
-        // If pressure in the tank is below low pressure threshhold, flash warning on internals UI
+        // If pressure in the tank is below low pressure threshold, flash warning on internals UI
         if (TryComp<GasTankComponent>(component.GasTankEntity, out var gasTank)
             && gasTank.IsLowPressure)
         {
index f8bd2979052c66e397ab12b27eb09e5221c5ec1f..6826dedf83117ed951e14abad4c6de578735b645 100644 (file)
@@ -59,6 +59,7 @@ public sealed class StationSpawningSystem : SharedStationSpawningSystem
     /// <inheritdoc/>
     public override void Initialize()
     {
+        base.Initialize();
         Subs.CVar(_configurationManager, CCVars.ICRandomCharacters, e => _randomizeCharacters = e, true);
 
         _spawnerCallbacks = new Dictionary<SpawnPriorityPreference, Action<PlayerSpawningEvent>>()
@@ -181,7 +182,7 @@ public sealed class StationSpawningSystem : SharedStationSpawningSystem
         if (prototype?.StartingGear != null)
         {
             var startingGear = _prototypeManager.Index<StartingGearPrototype>(prototype.StartingGear);
-            EquipStartingGear(entity.Value, startingGear);
+            EquipStartingGear(entity.Value, startingGear, raiseEvent: false);
         }
 
         // Run loadouts after so stuff like storage loadouts can get
@@ -217,11 +218,14 @@ public sealed class StationSpawningSystem : SharedStationSpawningSystem
                     }
 
                     // Handle any extra data here.
-                    EquipStartingGear(entity.Value, startingGear);
+                    EquipStartingGear(entity.Value, startingGear, raiseEvent: false);
                 }
             }
         }
 
+        var gearEquippedEv = new StartingGearEquippedEvent(entity.Value);
+        RaiseLocalEvent(entity.Value, ref gearEquippedEv, true);
+
         if (profile != null)
         {
             if (prototype != null)
index 1da44155b9566656de711a94b55921bb8454aa23..e0f2a695576b7d167e6aa6bf3a734780f8466a38 100644 (file)
@@ -151,7 +151,6 @@ public partial class InventorySystem : EntitySystem
             slotDefinitions = null;
             return false;
         }
-
         slotDefinitions = inv.Slots;
         return true;
     }
diff --git a/Content.Shared/Roles/StartingGearEquippedEvent.cs b/Content.Shared/Roles/StartingGearEquippedEvent.cs
new file mode 100644 (file)
index 0000000..41b6cac
--- /dev/null
@@ -0,0 +1,10 @@
+namespace Content.Shared.Roles;
+
+/// <summary>
+/// Raised directed on an entity when a new starting gear prototype has been equipped.
+/// </summary>
+[ByRefEvent]
+public record struct StartingGearEquippedEvent(EntityUid Entity)
+{
+    public readonly EntityUid Entity = Entity;
+}
index 363fb3f91e6e851c7427c124e9e14f1041acb284..8a063938ee3fd947a7c87e6e541f9cb556e66e98 100644 (file)
@@ -17,12 +17,24 @@ public abstract class SharedStationSpawningSystem : EntitySystem
     [Dependency] private   readonly SharedStorageSystem _storage = default!;
     [Dependency] private   readonly SharedTransformSystem _xformSystem = default!;
 
+    private EntityQuery<HandsComponent> _handsQuery;
+    private EntityQuery<InventoryComponent> _inventoryQuery;
+    private EntityQuery<StorageComponent> _storageQuery;
+    private EntityQuery<TransformComponent> _xformQuery;
+
+    public override void Initialize()
+    {
+        base.Initialize();
+        _handsQuery = GetEntityQuery<HandsComponent>();
+        _inventoryQuery = GetEntityQuery<InventoryComponent>();
+        _storageQuery = GetEntityQuery<StorageComponent>();
+        _xformQuery = GetEntityQuery<TransformComponent>();
+    }
+
     /// <summary>
-    /// Equips starting gear onto the given entity.
+    /// <see cref="EquipStartingGear(Robust.Shared.GameObjects.EntityUid,System.Nullable{Robust.Shared.Prototypes.ProtoId{Content.Shared.Roles.StartingGearPrototype}},bool)"/>
     /// </summary>
-    /// <param name="entity">Entity to load out.</param>
-    /// <param name="startingGear">Starting gear to use.</param>
-    public void EquipStartingGear(EntityUid entity, ProtoId<StartingGearPrototype>? startingGear)
+    public void EquipStartingGear(EntityUid entity, ProtoId<StartingGearPrototype>? startingGear, bool raiseEvent = true)
     {
         PrototypeManager.TryIndex(startingGear, out var gearProto);
         EquipStartingGear(entity, gearProto);
@@ -33,11 +45,14 @@ public abstract class SharedStationSpawningSystem : EntitySystem
     /// </summary>
     /// <param name="entity">Entity to load out.</param>
     /// <param name="startingGear">Starting gear to use.</param>
-    public void EquipStartingGear(EntityUid entity, StartingGearPrototype? startingGear)
+    /// <param name="raiseEvent">Should we raise the event for equipped. Set to false if you will call this manually</param>
+    public void EquipStartingGear(EntityUid entity, StartingGearPrototype? startingGear, bool raiseEvent = true)
     {
         if (startingGear == null)
             return;
 
+        var xform = _xformQuery.GetComponent(entity);
+
         if (InventorySystem.TryGetSlots(entity, out var slotDefinitions))
         {
             foreach (var slot in slotDefinitions)
@@ -45,16 +60,16 @@ public abstract class SharedStationSpawningSystem : EntitySystem
                 var equipmentStr = startingGear.GetGear(slot.Name);
                 if (!string.IsNullOrEmpty(equipmentStr))
                 {
-                    var equipmentEntity = EntityManager.SpawnEntity(equipmentStr, EntityManager.GetComponent<TransformComponent>(entity).Coordinates);
+                    var equipmentEntity = EntityManager.SpawnEntity(equipmentStr, xform.Coordinates);
                     InventorySystem.TryEquip(entity, equipmentEntity, slot.Name, silent: true, force:true);
                 }
             }
         }
 
-        if (TryComp(entity, out HandsComponent? handsComponent))
+        if (_handsQuery.TryComp(entity, out var handsComponent))
         {
             var inhand = startingGear.Inhand;
-            var coords = EntityManager.GetComponent<TransformComponent>(entity).Coordinates;
+            var coords = xform.Coordinates;
             foreach (var prototype in inhand)
             {
                 var inhandEntity = EntityManager.SpawnEntity(prototype, coords);
@@ -70,7 +85,7 @@ public abstract class SharedStationSpawningSystem : EntitySystem
         {
             var coords = _xformSystem.GetMapCoordinates(entity);
             var ents = new ValueList<EntityUid>();
-            TryComp(entity, out InventoryComponent? inventoryComp);
+            _inventoryQuery.TryComp(entity, out var inventoryComp);
 
             foreach (var (slot, entProtos) in startingGear.Storage)
             {
@@ -84,7 +99,7 @@ public abstract class SharedStationSpawningSystem : EntitySystem
 
                 if (inventoryComp != null &&
                     InventorySystem.TryGetSlotEntity(entity, slot, out var slotEnt, inventoryComponent: inventoryComp) &&
-                    TryComp(slotEnt, out StorageComponent? storage))
+                    _storageQuery.TryComp(slotEnt, out var storage))
                 {
                     foreach (var ent in ents)
                     {
@@ -93,5 +108,11 @@ public abstract class SharedStationSpawningSystem : EntitySystem
                 }
             }
         }
+
+        if (raiseEvent)
+        {
+            var ev = new StartingGearEquippedEvent(entity);
+            RaiseLocalEvent(entity, ref ev, true);
+        }
     }
 }