New science unlock: the H.A.R.M.P.A.C.K (#38824)

This commit is contained in:
slarticodefast
2025-07-07 23:43:33 +02:00
committed by GitHub
parent 366b623cd0
commit 46ec3b402a
13 changed files with 136 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
using Robust.Shared.GameStates;
using Content.Shared.Hands.EntitySystems;
namespace Content.Shared.Hands.Components;
/// <summary>
/// An entity with this component will give you extra hands when you equip it in your inventory.
/// </summary>
[RegisterComponent, NetworkedComponent]
[Access(typeof(ExtraHandsEquipmentSystem))]
public sealed partial class ExtraHandsEquipmentComponent : Component
{
/// <summary>
/// Dictionary relating a unique hand ID corresponding to a container slot on the attached entity to a struct containing information about the Hand itself.
/// </summary>
[DataField]
public Dictionary<string, Hand> Hands = new();
}

View File

@@ -0,0 +1,43 @@
using Content.Shared.Hands.Components;
using Content.Shared.Inventory.Events;
namespace Content.Shared.Hands.EntitySystems;
public sealed class ExtraHandsEquipmentSystem : EntitySystem
{
[Dependency] private readonly 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.Equipee, 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.Equipee, handsComp), handId, hand.Location);
}
}
private void OnUnequipped(Entity<ExtraHandsEquipmentComponent> ent, ref GotUnequippedEvent args)
{
if (!TryComp<HandsComponent>(args.Equipee, 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.Equipee, handsComp), handId);
}
}
}