]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix inventory relay by-ref events (#20816)
authorLeon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Wed, 11 Oct 2023 16:31:10 +0000 (03:31 +1100)
committerGitHub <noreply@github.com>
Wed, 11 Oct 2023 16:31:10 +0000 (19:31 +0300)
* Fix inventory relay ref events

* this works too (avoid duplication)

---------

Co-authored-by: Slava0135 <super.novalskiy_0135@inbox.ru>
Content.Server/Explosion/EntitySystems/ExplosionSystem.cs
Content.Shared/Inventory/InventorySystem.Relay.cs
Content.Shared/Verbs/Verb.cs

index aa007c61c05566bbb117194bab7554cb207db685..5e5af03c17b3d37c93f17db8b8dd549fea953eba 100644 (file)
@@ -116,8 +116,7 @@ public sealed partial class ExplosionSystem : EntitySystem
     private void RelayedResistance(EntityUid uid, ExplosionResistanceComponent component,
         InventoryRelayedEvent<GetExplosionResistanceEvent> args)
     {
-        var a = args.Args;
-        OnGetResistance(uid, component, ref a);
+        OnGetResistance(uid, component, ref args.Args);
     }
 
     private void OnGetResistance(EntityUid uid, ExplosionResistanceComponent component, ref GetExplosionResistanceEvent args)
index 83b47542e2929ca9adff1085074678ebff8af27a..fbe744911fd40ae8ac42adf730a5cb2d7fe1a5be 100644 (file)
@@ -24,12 +24,14 @@ public partial class InventorySystem
         SubscribeLocalEvent<InventoryComponent, ElectrocutionAttemptEvent>(RelayInventoryEvent);
         SubscribeLocalEvent<InventoryComponent, SlipAttemptEvent>(RelayInventoryEvent);
         SubscribeLocalEvent<InventoryComponent, RefreshMovementSpeedModifiersEvent>(RelayInventoryEvent);
-        SubscribeLocalEvent<InventoryComponent, GetExplosionResistanceEvent>(RefRelayInventoryEvent);
         SubscribeLocalEvent<InventoryComponent, BeforeStripEvent>(RelayInventoryEvent);
         SubscribeLocalEvent<InventoryComponent, SeeIdentityAttemptEvent>(RelayInventoryEvent);
         SubscribeLocalEvent<InventoryComponent, ModifyChangedTemperatureEvent>(RelayInventoryEvent);
         SubscribeLocalEvent<InventoryComponent, GetDefaultRadioChannelEvent>(RelayInventoryEvent);
 
+        // by-ref events
+        SubscribeLocalEvent<InventoryComponent, GetExplosionResistanceEvent>(RefRelayInventoryEvent);
+
         // Eye/vision events
         SubscribeLocalEvent<InventoryComponent, CanSeeAttemptEvent>(RelayInventoryEvent);
         SubscribeLocalEvent<InventoryComponent, GetEyeProtectionEvent>(RelayInventoryEvent);
@@ -41,22 +43,24 @@ public partial class InventorySystem
         SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowHungerIconsComponent>>(RelayInventoryEvent);
         SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowThirstIconsComponent>>(RelayInventoryEvent);
 
-        SubscribeLocalEvent<InventoryComponent, GetVerbsEvent<EquipmentVerb>>(OnGetStrippingVerbs);
+        SubscribeLocalEvent<InventoryComponent, GetVerbsEvent<EquipmentVerb>>(OnGetEquipmentVerbs);
     }
 
     protected void RefRelayInventoryEvent<T>(EntityUid uid, InventoryComponent component, ref T args) where T : IInventoryRelayEvent
     {
-        // Just so I don't have to update 20 morbillion events at once.
-        if (args.TargetSlots == SlotFlags.NONE)
-            return;
-
         var containerEnumerator = new ContainerSlotEnumerator(uid, component.TemplateId, _prototypeManager, this, args.TargetSlots);
+
+        // this copies the by-ref event
         var ev = new InventoryRelayedEvent<T>(args);
+
         while (containerEnumerator.MoveNext(out var container))
         {
             if (!container.ContainedEntity.HasValue) continue;
-            RaiseLocalEvent(container.ContainedEntity.Value, ev, broadcast: false);
+            RaiseLocalEvent(container.ContainedEntity.Value, ev);
         }
+
+        // and now we copy it back
+        args = ev.Args;
     }
 
     protected void RelayInventoryEvent<T>(EntityUid uid, InventoryComponent component, T args) where T : IInventoryRelayEvent
@@ -69,11 +73,11 @@ public partial class InventorySystem
         while (containerEnumerator.MoveNext(out var container))
         {
             if (!container.ContainedEntity.HasValue) continue;
-            RaiseLocalEvent(container.ContainedEntity.Value, ev, broadcast: false);
+            RaiseLocalEvent(container.ContainedEntity.Value, ev);
         }
     }
 
-    private void OnGetStrippingVerbs(EntityUid uid, InventoryComponent component, GetVerbsEvent<EquipmentVerb> args)
+    private void OnGetEquipmentVerbs(EntityUid uid, InventoryComponent component, GetVerbsEvent<EquipmentVerb> args)
     {
         // Automatically relay stripping related verbs to all equipped clothing.
 
@@ -112,7 +116,7 @@ public partial class InventorySystem
 /// </remarks>
 public sealed class InventoryRelayedEvent<TEvent> : EntityEventArgs
 {
-    public readonly TEvent Args;
+    public TEvent Args;
 
     public InventoryRelayedEvent(TEvent args)
     {
index 76ed20730753e75bd671d416814ac141406553e1..660a3bdf948d156cf1bb15804afabaf9f63bcef2 100644 (file)
@@ -1,5 +1,6 @@
 using Content.Shared.Database;
 using Content.Shared.Interaction.Events;
+using Content.Shared.Inventory;
 using Robust.Shared.Serialization;
 using Robust.Shared.Utility;
 
@@ -349,9 +350,10 @@ namespace Content.Shared.Verbs
     }
 
     /// <summary>
-    ///     Verbs specifically for interactions that occur with equipped entities. These verbs should be accessible via
-    ///     the stripping UI, and may optionally also be accessible via a verb on the equipee if the via inventory relay
-    ///     events.get-verbs event.
+    ///     Verbs specifically for interactions that occur with equipped entities. These verbs are unique in that they
+    ///     can be used via the stripping UI. Additionally, when getting verbs on an entity with an inventory it will
+    ///     these automatically relay the <see cref="GetVerbsEvent{EquipmentVerb}"/> event to all equipped items via a
+    ///     <see cref="InventoryRelayedEvent{T}"/>.
     /// </summary>
     [Serializable, NetSerializable]
     public sealed class EquipmentVerb : Verb