HandsSystem Refactor (#38438)
* checkpoint * pt 2 * pt... i forgot * pt 4 * patch * More test fixes * optimization!!! * the REAL hand system * fix RetractableItemActionSystem.cs oversight * the review * test * remove test usage of body prototype * Update Content.IntegrationTests/Tests/Interaction/InteractionTest.cs Co-authored-by: Tayrtahn <tayrtahn@gmail.com> * hellcode * hellcode 2 * Minor cleanup * test * Chasing the last of the bugs * changes --------- Co-authored-by: Tayrtahn <tayrtahn@gmail.com>
This commit is contained in:
@@ -2,7 +2,6 @@ using Content.Server.Hands.Systems;
|
||||
using Content.Server.Storage.EntitySystems;
|
||||
using Content.Shared.Administration.Logs;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Inventory;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Storage;
|
||||
@@ -40,24 +39,20 @@ public sealed class StorageVoiceControlSystem : EntitySystem
|
||||
if (!TryComp<StorageComponent>(ent, out var storage))
|
||||
return;
|
||||
|
||||
// Get the hands component
|
||||
if (!TryComp<HandsComponent>(args.Source, out var hands))
|
||||
return;
|
||||
|
||||
// If the player has something in their hands, try to insert it into the storage
|
||||
if (hands.ActiveHand != null && hands.ActiveHand.HeldEntity.HasValue)
|
||||
if (_hands.TryGetActiveItem(ent.Owner, out var activeItem))
|
||||
{
|
||||
// Disallow insertion and provide a reason why if the person decides to insert the item into itself
|
||||
if (ent.Owner.Equals(hands.ActiveHand.HeldEntity.Value))
|
||||
if (ent.Owner.Equals(activeItem.Value))
|
||||
{
|
||||
_popup.PopupEntity(Loc.GetString("comp-storagevoicecontrol-self-insert", ("entity", hands.ActiveHand.HeldEntity.Value)), ent, args.Source);
|
||||
_popup.PopupEntity(Loc.GetString("comp-storagevoicecontrol-self-insert", ("entity", activeItem.Value)), ent, args.Source);
|
||||
return;
|
||||
}
|
||||
if (_storage.CanInsert(ent, hands.ActiveHand.HeldEntity.Value, out var failedReason))
|
||||
if (_storage.CanInsert(ent, activeItem.Value, out var failedReason))
|
||||
{
|
||||
// We adminlog before insertion, otherwise the logger will attempt to pull info on an entity that no longer is present and throw an exception
|
||||
_adminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(args.Source)} inserted {ToPrettyString(hands.ActiveHand.HeldEntity.Value)} into {ToPrettyString(ent)} via voice control");
|
||||
_storage.Insert(ent, hands.ActiveHand.HeldEntity.Value, out _);
|
||||
_adminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(args.Source)} inserted {ToPrettyString(activeItem.Value)} into {ToPrettyString(ent)} via voice control");
|
||||
_storage.Insert(ent, activeItem.Value, out _);
|
||||
return;
|
||||
}
|
||||
{
|
||||
@@ -67,7 +62,7 @@ public sealed class StorageVoiceControlSystem : EntitySystem
|
||||
_popup.PopupEntity(Loc.GetString(failedReason), ent, args.Source);
|
||||
_adminLogger.Add(LogType.Action,
|
||||
LogImpact.Low,
|
||||
$"{ToPrettyString(args.Source)} failed to insert {ToPrettyString(hands.ActiveHand.HeldEntity.Value)} into {ToPrettyString(ent)} via voice control");
|
||||
$"{ToPrettyString(args.Source)} failed to insert {ToPrettyString(activeItem.Value)} into {ToPrettyString(ent)} via voice control");
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -80,7 +75,7 @@ public sealed class StorageVoiceControlSystem : EntitySystem
|
||||
// E.g "go go s" would give you the screwdriver because "screwdriver" contains "s"
|
||||
if (Name(item).Contains(args.MessageWithoutPhrase))
|
||||
{
|
||||
ExtractItemFromStorage(ent, item, args.Source, hands);
|
||||
ExtractItemFromStorage(ent, item, args.Source);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -92,16 +87,14 @@ public sealed class StorageVoiceControlSystem : EntitySystem
|
||||
/// <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)
|
||||
EntityUid source)
|
||||
{
|
||||
_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);
|
||||
_hands.TryPickup(source, item);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user