]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
DetGadget hat fixes (#35658)
authorArtisticRoomba <145879011+ArtisticRoomba@users.noreply.github.com>
Sat, 19 Apr 2025 14:11:55 +0000 (07:11 -0700)
committerGitHub <noreply@github.com>
Sat, 19 Apr 2025 14:11:55 +0000 (16:11 +0200)
* """Refactors""" extraction code, fixes bug with labeled items

* second line of fixes

* Enhance label handling and add label retrieval method (its more preformant I swear)

* Cleanup

---------

Co-authored-by: beck-thompson <beck314159@hotmail.com>
Content.Server/Explosion/EntitySystems/TriggerSystem.Voice.cs
Content.Server/VoiceTrigger/StorageVoiceControlSystem.cs

index 9d11a9dad770ca23c4cae9c76eca575efa532e0b..a96508e37cbe4f26e852003a589f9c96e8f334b6 100644 (file)
@@ -48,13 +48,15 @@ namespace Content.Server.Explosion.EntitySystems
                 return;
             }
 
-            if (!string.IsNullOrWhiteSpace(component.KeyPhrase) && message.Contains(component.KeyPhrase, StringComparison.InvariantCultureIgnoreCase))
+            if (!string.IsNullOrWhiteSpace(component.KeyPhrase) && message.IndexOf(component.KeyPhrase, StringComparison.InvariantCultureIgnoreCase) is var index and >= 0 )
             {
                 _adminLogger.Add(LogType.Trigger, LogImpact.Medium,
                         $"A voice-trigger on {ToPrettyString(ent):entity} was triggered by {ToPrettyString(args.Source):speaker} speaking the key-phrase {component.KeyPhrase}.");
                 Trigger(ent, args.Source);
 
-                var voice = new VoiceTriggeredEvent(args.Source, message);
+                var messageWithoutPhrase = message.Remove(index, component.KeyPhrase.Length).Trim();
+
+                var voice = new VoiceTriggeredEvent(args.Source, message, messageWithoutPhrase);
                 RaiseLocalEvent(ent, ref voice);
             }
         }
@@ -147,5 +149,6 @@ namespace Content.Server.Explosion.EntitySystems
 /// </summary>
 /// <param name="Source"> The EntityUid of the entity sending the message</param>
 /// <param name="Message"> The contents of the message</param>
+/// <param name="MessageWithoutPhrase"> The message without the phrase that triggered it.</param>
 [ByRefEvent]
-public readonly record struct VoiceTriggeredEvent(EntityUid Source, string? Message);
+public readonly record struct VoiceTriggeredEvent(EntityUid Source, string Message, string MessageWithoutPhrase);
index 72e361bc58fbef0b125b95f3be90890f9cdee615..c3fde14517504110331b56bcb090ad07e2e3d708 100644 (file)
@@ -36,10 +36,6 @@ public sealed class StorageVoiceControlSystem : EntitySystem
             (itemSlot.SlotFlags & ent.Comp.AllowedSlots) == 0)
             return;
 
-        // Don't do anything if there is no message
-        if (args.Message == null)
-            return;
-
         // Get the storage component
         if (!TryComp<StorageComponent>(ent, out var storage))
             return;
@@ -79,20 +75,33 @@ public sealed class StorageVoiceControlSystem : EntitySystem
         // If otherwise, we're retrieving an item, so check all the items currently in the attached storage
         foreach (var item in storage.Container.ContainedEntities)
         {
-            // Get the item's name
-            var itemName = MetaData(item).EntityName;
-            // The message doesn't match the item name the requestor requested, skip and move on to the next item
-            if (!args.Message.Contains(itemName, StringComparison.InvariantCultureIgnoreCase))
-                continue;
-
-            // We found the item we want, so draw it from storage and place it into the player's hands
-            if (storage.Container.ContainedEntities.Count != 0)
+            // Check if the name contains the actual command.
+            // This will do comparisons against any length of string which is a little weird, but worth the tradeoff.
+            // E.g "go go s" would give you the screwdriver because "screwdriver" contains "s"
+            if (Name(item).Contains(args.MessageWithoutPhrase))
             {
-                _container.RemoveEntity(ent, item);
-                _adminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(args.Source)} retrieved {ToPrettyString(item)} from {ToPrettyString(ent)} via voice control");
-                _hands.TryPickup(args.Source, item, handsComp: hands);
+                ExtractItemFromStorage(ent, item, args.Source, hands);
                 break;
             }
         }
     }
+
+    /// <summary>
+    /// Extracts an item from storage and places it into the player's hands.
+    /// </summary>
+    /// <param name="ent">The entity with the <see cref="StorageVoiceControlComponent"/></param>
+    /// <param name="item">The entity to be extracted from the attached storage</param>
+    /// <param name="source">The entity wearing the item</param>
+    /// <param name="hands">The <see cref="HandsComponent"/> of the person wearing the item</param>
+    private void ExtractItemFromStorage(Entity<StorageVoiceControlComponent> ent,
+        EntityUid item,
+        EntityUid source,
+        HandsComponent hands)
+    {
+        _container.RemoveEntity(ent, item);
+        _adminLogger.Add(LogType.Action,
+            LogImpact.Low,
+            $"{ToPrettyString(source)} retrieved {ToPrettyString(item)} from {ToPrettyString(ent)} via voice control");
+        _hands.TryPickup(source, item, handsComp: hands);
+    }
 }