DetGadget hat fixes (#35658)

* """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>
This commit is contained in:
ArtisticRoomba
2025-04-19 07:11:55 -07:00
committed by GitHub
parent aa5d344a57
commit d9e9afed1e
2 changed files with 30 additions and 18 deletions

View File

@@ -48,13 +48,15 @@ namespace Content.Server.Explosion.EntitySystems
return; 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, _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}."); $"A voice-trigger on {ToPrettyString(ent):entity} was triggered by {ToPrettyString(args.Source):speaker} speaking the key-phrase {component.KeyPhrase}.");
Trigger(ent, args.Source); 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); RaiseLocalEvent(ent, ref voice);
} }
} }
@@ -147,5 +149,6 @@ namespace Content.Server.Explosion.EntitySystems
/// </summary> /// </summary>
/// <param name="Source"> The EntityUid of the entity sending the message</param> /// <param name="Source"> The EntityUid of the entity sending the message</param>
/// <param name="Message"> The contents of 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] [ByRefEvent]
public readonly record struct VoiceTriggeredEvent(EntityUid Source, string? Message); public readonly record struct VoiceTriggeredEvent(EntityUid Source, string Message, string MessageWithoutPhrase);

View File

@@ -36,10 +36,6 @@ public sealed class StorageVoiceControlSystem : EntitySystem
(itemSlot.SlotFlags & ent.Comp.AllowedSlots) == 0) (itemSlot.SlotFlags & ent.Comp.AllowedSlots) == 0)
return; return;
// Don't do anything if there is no message
if (args.Message == null)
return;
// Get the storage component // Get the storage component
if (!TryComp<StorageComponent>(ent, out var storage)) if (!TryComp<StorageComponent>(ent, out var storage))
return; 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 // If otherwise, we're retrieving an item, so check all the items currently in the attached storage
foreach (var item in storage.Container.ContainedEntities) foreach (var item in storage.Container.ContainedEntities)
{ {
// Get the item's name // Check if the name contains the actual command.
var itemName = MetaData(item).EntityName; // This will do comparisons against any length of string which is a little weird, but worth the tradeoff.
// The message doesn't match the item name the requestor requested, skip and move on to the next item // E.g "go go s" would give you the screwdriver because "screwdriver" contains "s"
if (!args.Message.Contains(itemName, StringComparison.InvariantCultureIgnoreCase)) if (Name(item).Contains(args.MessageWithoutPhrase))
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)
{ {
_container.RemoveEntity(ent, item); ExtractItemFromStorage(ent, item, args.Source, hands);
_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);
break; 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);
}
} }