Migrate all mechs to PartAssembly and remove legacy MechAssemblySystem (#39027)

* Removed the old MechAssembly system and component.
Converted all mechs to use the unified PartAssembly system.
Removed dismantling mechs during assembly logic to simplify the code.

* Delete Chassis via migration
This commit is contained in:
AndrewFenriz
2025-08-31 15:54:45 +03:00
committed by GitHub
parent 487c280f1c
commit 0e23e4537f
9 changed files with 71 additions and 220 deletions

View File

@@ -1,50 +0,0 @@
using Content.Shared.Storage.Components;
using Content.Shared.Tag;
using Content.Shared.Tools;
using Robust.Shared.Containers;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
namespace Content.Server.Mech.Components;
/// <summary>
/// A component used to create a mech chassis
/// after the correct parts have been placed inside
/// of it.
/// </summary>
/// <remarks>
/// The actual visualization of the parts being inserted is
/// done via <see cref="ItemMapperComponent"/>
/// </remarks>
[RegisterComponent]
public sealed partial class MechAssemblyComponent : Component
{
/// <summary>
/// The parts needed to be placed within the assembly,
/// stored as a tag and a bool tracking whether or not
/// they're present.
/// </summary>
[DataField("requiredParts", required: true, customTypeSerializer: typeof(PrototypeIdDictionarySerializer<bool, TagPrototype>))]
public Dictionary<string, bool> RequiredParts = new();
/// <summary>
/// The prototype spawned when the assembly is finished
/// </summary>
[DataField("finishedPrototype", required: true, customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
public string FinishedPrototype = default!;
/// <summary>
/// The container that stores all of the parts when
/// they're being assembled.
/// </summary>
[ViewVariables]
public Container PartsContainer = default!;
/// <summary>
/// The quality of tool needed to remove all the parts
/// from the parts container.
/// </summary>
[DataField("qualityNeeded", customTypeSerializer: typeof(PrototypeIdSerializer<ToolQualityPrototype>))]
public string QualityNeeded = "Prying";
}

View File

@@ -1,67 +0,0 @@
using Content.Server.Mech.Components;
using Content.Shared.Interaction;
using Content.Shared.Tag;
using Content.Shared.Tools.Components;
using Content.Shared.Tools.Systems;
using Robust.Server.Containers;
using Robust.Shared.Containers;
namespace Content.Server.Mech.Systems;
/// <summary>
/// Handles <see cref="MechAssemblyComponent"/> and the insertion
/// and removal of parts from the assembly.
/// </summary>
public sealed class MechAssemblySystem : EntitySystem
{
[Dependency] private readonly ContainerSystem _container = default!;
[Dependency] private readonly TagSystem _tag = default!;
[Dependency] private readonly SharedToolSystem _toolSystem = default!;
/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<MechAssemblyComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<MechAssemblyComponent, InteractUsingEvent>(OnInteractUsing);
}
private void OnInit(EntityUid uid, MechAssemblyComponent component, ComponentInit args)
{
component.PartsContainer = _container.EnsureContainer<Container>(uid, "mech-assembly-container");
}
private void OnInteractUsing(EntityUid uid, MechAssemblyComponent component, InteractUsingEvent args)
{
if (_toolSystem.HasQuality(args.Used, component.QualityNeeded))
{
foreach (var tag in component.RequiredParts.Keys)
{
component.RequiredParts[tag] = false;
}
_container.EmptyContainer(component.PartsContainer);
return;
}
if (!TryComp<TagComponent>(args.Used, out var tagComp))
return;
foreach (var (tag, val) in component.RequiredParts)
{
if (!val && _tag.HasTag(tagComp, tag))
{
component.RequiredParts[tag] = true;
_container.Insert(args.Used, component.PartsContainer);
break;
}
}
//check to see if we have all the parts
foreach (var val in component.RequiredParts.Values)
{
if (!val)
return;
}
Spawn(component.FinishedPrototype, Transform(uid).Coordinates);
Del(uid);
}
}