diff --git a/Content.Server/Explosion/EntitySystems/TriggerSystem.Voice.cs b/Content.Server/Explosion/EntitySystems/TriggerSystem.Voice.cs index 9d11a9dad7..a96508e37c 100644 --- a/Content.Server/Explosion/EntitySystems/TriggerSystem.Voice.cs +++ b/Content.Server/Explosion/EntitySystems/TriggerSystem.Voice.cs @@ -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 /// /// The EntityUid of the entity sending the message /// The contents of the message +/// The message without the phrase that triggered it. [ByRefEvent] -public readonly record struct VoiceTriggeredEvent(EntityUid Source, string? Message); +public readonly record struct VoiceTriggeredEvent(EntityUid Source, string Message, string MessageWithoutPhrase); diff --git a/Content.Server/VoiceTrigger/StorageVoiceControlSystem.cs b/Content.Server/VoiceTrigger/StorageVoiceControlSystem.cs index 72e361bc58..c3fde14517 100644 --- a/Content.Server/VoiceTrigger/StorageVoiceControlSystem.cs +++ b/Content.Server/VoiceTrigger/StorageVoiceControlSystem.cs @@ -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(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; } } } + + /// + /// Extracts an item from storage and places it into the player's hands. + /// + /// The entity with the + /// The entity to be extracted from the attached storage + /// The entity wearing the item + /// The of the person wearing the item + private void ExtractItemFromStorage(Entity 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); + } }