CatStation/Content.Shared/Hands/EntitySystems/ExtraHandsEquipmentSystem.cs
Pieter-Jan Briers 5168b5f3d4
IoC source gen compatibility (#43863)
* IoC source gen compatibility

Can be merged before or after https://github.com/space-wizards/RobustToolbox/pull/6549 doesn't really matter.

* Missed a spot
2026-05-09 03:29:58 +00:00

43 lines
1.6 KiB
C#

using Content.Shared.Hands.Components;
using Content.Shared.Inventory.Events;
namespace Content.Shared.Hands.EntitySystems;
public sealed partial class ExtraHandsEquipmentSystem : EntitySystem
{
[Dependency] private SharedHandsSystem _hands = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ExtraHandsEquipmentComponent, GotEquippedEvent>(OnEquipped);
SubscribeLocalEvent<ExtraHandsEquipmentComponent, GotUnequippedEvent>(OnUnequipped);
}
private void OnEquipped(Entity<ExtraHandsEquipmentComponent> ent, ref GotEquippedEvent args)
{
if (!TryComp<HandsComponent>(args.EquipTarget, out var handsComp))
return;
foreach (var (handName, hand) in ent.Comp.Hands)
{
// add the NetEntity id to the container name to prevent multiple items with this component from conflicting
var handId = $"{GetNetEntity(ent.Owner).Id}-{handName}";
_hands.AddHand((args.EquipTarget, handsComp), handId, hand.Location);
}
}
private void OnUnequipped(Entity<ExtraHandsEquipmentComponent> ent, ref GotUnequippedEvent args)
{
if (!TryComp<HandsComponent>(args.EquipTarget, out var handsComp))
return;
foreach (var handName in ent.Comp.Hands.Keys)
{
// add the NetEntity id to the container name to prevent multiple items with this component from conflicting
var handId = $"{GetNetEntity(ent.Owner).Id}-{handName}";
_hands.RemoveHand((args.EquipTarget, handsComp), handId);
}
}
}