Removed obsolete DroppableBorgModule Code (#4770)

Removed obsolete DroppableBorgModule since upstream merged in Borg hands
This commit is contained in:
Vanessa 2025-11-27 02:23:49 -06:00 committed by GitHub
parent 4dfada77c6
commit 1de9aa536c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 0 additions and 210 deletions

View File

@ -1,55 +0,0 @@
using Content.Shared.Whitelist;
using Robust.Shared.Containers;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
namespace Content.Shared._NF.Silicons.Borgs;
/// <summary>
/// Uses placeholder entities to give borgs "hands" that are whitelisted for a certain kind of item.
/// The items in it can be dropped and picked up if they match its whitelist.
/// </summary>
[RegisterComponent, NetworkedComponent, Access(typeof(DroppableBorgModuleSystem))]
public sealed partial class DroppableBorgModuleComponent : Component
{
/// <summary>
/// The items to spawn in borg hands.
/// </summary>
[DataField(required: true)]
public List<DroppableBorgItem> Items = new();
/// <summary>
/// The ID of the container to add that stores items when not in hands.
/// </summary>
[DataField]
public string ContainerId = "nf-droppable-items";
/// <summary>
/// The ID of the container to add that stores item placeholders when not in hands.
/// </summary>
[DataField]
public string PlaceholderContainerId = "nf-item-placeholders";
/// <summary>
/// The ID to check for module equivalence.
/// </summary>
[DataField(required: true)]
public string ModuleId = default!;
}
[DataDefinition]
public sealed partial class DroppableBorgItem
{
/// <summary>
/// The entity to spawn and use for the placeholder sprite.
/// </summary>
[DataField(required: true)]
public EntProtoId Id;
/// <summary>
/// A whitelist that items must match to be picked up by the placeholder.
/// Regardless of this whitelist entities must have <c>ItemComponent</c> to be picked up.
/// </summary>
[DataField(required: true)]
public EntityWhitelist Whitelist;
}

View File

@ -1,155 +0,0 @@
using Content.Shared._NF.Interaction.Systems;
using Content.Shared.Hands.Components;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction;
using Content.Shared.Popups;
using Content.Shared.Silicons.Borgs.Components;
using Robust.Shared.Containers;
using Robust.Shared.Map;
using Robust.Shared.Network;
using Robust.Shared.Utility;
namespace Content.Shared._NF.Silicons.Borgs;
public sealed class DroppableBorgModuleSystem : EntitySystem
{
[Dependency] private readonly HandPlaceholderSystem _placeholder = default!;
[Dependency] private readonly SharedContainerSystem _container = default!;
[Dependency] private readonly SharedHandsSystem _hands = default!;
[Dependency] private readonly SharedInteractionSystem _interaction = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<DroppableBorgModuleComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<DroppableBorgModuleComponent, BorgCanInsertModuleEvent>(OnCanInsertModule);
SubscribeLocalEvent<DroppableBorgModuleComponent, BorgModuleSelectedEvent>(OnModuleSelected);
SubscribeLocalEvent<DroppableBorgModuleComponent, BorgModuleUnselectedEvent>(OnModuleUnselected);
}
private void OnMapInit(Entity<DroppableBorgModuleComponent> ent, ref MapInitEvent args)
{
_container.EnsureContainer<Container>(ent, ent.Comp.ContainerId);
var placeholders = _container.EnsureContainer<Container>(ent, ent.Comp.PlaceholderContainerId);
foreach (var slot in ent.Comp.Items)
{
// only the server runs mapinit, this wont make clientside entities
var successful = TrySpawnInContainer(slot.Id, ent, ent.Comp.ContainerId, out var item);
// this would only fail if the current entity is being terminated, which is impossible for mapinit
DebugTools.Assert(successful, $"Somehow failed to insert {ToPrettyString(item)} into {ToPrettyString(ent)}");
_placeholder.SpawnPlaceholder(placeholders, item!.Value, slot.Id, slot.Whitelist);
}
Dirty(ent);
}
private void OnCanInsertModule(Entity<DroppableBorgModuleComponent> ent, ref BorgCanInsertModuleEvent args)
{
if (args.Cancelled)
return;
foreach (var module in args.Chassis.Comp.ModuleContainer.ContainedEntities)
{
if (!TryComp<DroppableBorgModuleComponent>(module, out var comp))
continue;
if (comp.ModuleId != ent.Comp.ModuleId)
continue;
if (args.User is { } user)
_popup.PopupEntity(Loc.GetString("borg-module-duplicate"), args.Chassis, user); // event is only raised by server so not using PopupClient
args.Cancelled = true;
return;
}
}
private void OnModuleSelected(Entity<DroppableBorgModuleComponent> ent, ref BorgModuleSelectedEvent args)
{
var chassis = args.Chassis;
if (!TryComp<HandsComponent>(chassis, out var hands))
return;
var container = _container.GetContainer(ent, ent.Comp.ContainerId);
var items = container.ContainedEntities;
for (int i = 0; i < ent.Comp.Items.Count; i++)
{
var item = items[0]; // the contained items will gradually go to 0
var handId = HandId(ent, i);
_hands.AddHand((chassis, hands), handId, HandLocation.Middle);
var hand = hands.Hands[handId];
_hands.DoPickup(chassis, handId, item, hands);
if (_hands.TryGetHeldItem((chassis, hands), handId, out var heldIdtem)
&& heldIdtem != item)
{
Log.Error($"Failed to pick up {ToPrettyString(item)} into hand {handId} of {ToPrettyString(chassis)}, it holds {ToPrettyString(heldIdtem)}");
// If we didn't pick up our expected item, delete the hand. No free hands!
_hands.RemoveHand((chassis, hands), handId);
}
else
{
_interaction.DoContactInteraction(chassis, item); // for potential forensics or other systems (why does hands system not do this)
_placeholder.SetEnabled(item, true);
}
}
}
private void OnModuleUnselected(Entity<DroppableBorgModuleComponent> ent, ref BorgModuleUnselectedEvent args)
{
var chassis = args.Chassis;
if (!TryComp<HandsComponent>(chassis, out var hands))
return;
if (TerminatingOrDeleted(ent))
{
for (int i = 0; i < ent.Comp.Items.Count; i++)
{
var handId = HandId(ent, i);
_hands.TryGetHand((chassis, hands), handId, out var hand);
if (_hands.TryGetHeldItem((chassis, hands), handId, out var item)
&& item != null)
QueueDel(item);
else if (!TerminatingOrDeleted(chassis) && Transform(chassis).MapID != MapId.Nullspace) // don't care if its empty if the server is shutting down
Log.Warning($"Borg {ToPrettyString(chassis)} terminated with empty hand {i} in {ToPrettyString(ent)}");
_hands.RemoveHand((chassis, hands), handId);
}
return;
}
var container = _container.GetContainer(ent, ent.Comp.ContainerId);
for (int i = 0; i < ent.Comp.Items.Count; i++)
{
var handId = HandId(ent, i);
_hands.TryGetHand((chassis, hands), handId, out var hand);
if (_hands.TryGetHeldItem((chassis, hands), handId, out var item)
&& item != null)
{
_placeholder.SetEnabled(item.Value, false);
_container.Insert(item.Value, container, force: true);
}
else
{
Log.Error($"Borg {ToPrettyString(chassis)} had an empty hand in the slot for {ent.Comp.Items[i].Id}");
}
_hands.RemoveHand((chassis, hands), handId);
}
}
/// <summary>
/// Format the hand ID for a given module and item number.
/// </summary>
private static string HandId(EntityUid uid, int i)
{
return $"nf-{uid}-item-{i}";
}
}
/// <summary>
/// Event raised on a module to check if it can be installed.
/// This should exist upstream but doesn't.
/// </summary>
[ByRefEvent]
public record struct BorgCanInsertModuleEvent(Entity<BorgChassisComponent> Chassis, EntityUid? User, bool Cancelled = false);