+using Content.Shared.Storage;
using Content.Shared.Tools;
using Robust.Shared.Prototypes;
/// Used for something that can be refined by welder.
/// For example, glass shard can be refined to glass sheet.
/// </summary>
-[RegisterComponent]
+[RegisterComponent, Access(typeof(RefiningSystem))]
public sealed partial class WelderRefinableComponent : Component
{
- [DataField]
- public HashSet<EntProtoId>? RefineResult = new();
+ /// <summary>
+ /// The items created when the item is refined.
+ /// </summary>
+ [DataField(required: true)]
+ public List<EntitySpawnEntry> RefineResult = new();
+ /// <summary>
+ /// The amount of time it takes to refine a given item.
+ /// </summary>
[DataField]
public float RefineTime = 2f;
+ /// <summary>
+ /// The amount of fuel it takes to refine a given item.
+ /// </summary>
[DataField]
public float RefineFuel;
+ /// <summary>
+ /// The tool type needed in order to refine this item.
+ /// </summary>
[DataField]
public ProtoId<ToolQualityPrototype> QualityNeeded = "Welding";
}
using Content.Server.Construction.Components;
-using Content.Server.Stack;
using Content.Shared.Construction;
using Content.Shared.Interaction;
-using Content.Shared.Stacks;
-using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
+using Content.Shared.Storage;
+using Content.Shared.Tools.Systems;
+using Robust.Shared.Random;
-namespace Content.Server.Construction
+namespace Content.Server.Construction;
+
+public sealed class RefiningSystem : EntitySystem
{
- public sealed class RefiningSystem : EntitySystem
+ [Dependency] private readonly IRobustRandom _random = default!;
+ [Dependency] private readonly SharedToolSystem _toolSystem = default!;
+
+ public override void Initialize()
{
- [Dependency] private readonly SharedToolSystem _toolSystem = default!;
- [Dependency] private readonly StackSystem _stackSystem = default!;
- public override void Initialize()
- {
- base.Initialize();
- SubscribeLocalEvent<WelderRefinableComponent, InteractUsingEvent>(OnInteractUsing);
- SubscribeLocalEvent<WelderRefinableComponent, WelderRefineDoAfterEvent>(OnDoAfter);
- }
+ base.Initialize();
+ SubscribeLocalEvent<WelderRefinableComponent, InteractUsingEvent>(OnInteractUsing);
+ SubscribeLocalEvent<WelderRefinableComponent, WelderRefineDoAfterEvent>(OnDoAfter);
+ }
- private void OnInteractUsing(EntityUid uid, WelderRefinableComponent component, InteractUsingEvent args)
- {
- if (args.Handled)
- return;
+ private void OnInteractUsing(EntityUid uid, WelderRefinableComponent component, InteractUsingEvent args)
+ {
+ if (args.Handled)
+ return;
- args.Handled = _toolSystem.UseTool(args.Used, args.User, uid, component.RefineTime, component.QualityNeeded, new WelderRefineDoAfterEvent(), fuel: component.RefineFuel);
- }
+ args.Handled = _toolSystem.UseTool(
+ args.Used,
+ args.User,
+ uid,
+ component.RefineTime,
+ component.QualityNeeded,
+ new WelderRefineDoAfterEvent(),
+ fuel: component.RefineFuel);
+ }
- private void OnDoAfter(EntityUid uid, WelderRefinableComponent component, WelderRefineDoAfterEvent args)
+ private void OnDoAfter(EntityUid uid, WelderRefinableComponent component, WelderRefineDoAfterEvent args)
+ {
+ if (args.Cancelled)
+ return;
+
+ var xform = Transform(uid);
+ var spawns = EntitySpawnCollection.GetSpawns(component.RefineResult, _random);
+ foreach (var spawn in spawns)
{
- if (args.Cancelled)
- return;
-
- // get last owner coordinates and delete it
- var resultPosition = Transform(uid).Coordinates;
- EntityManager.DeleteEntity(uid);
-
- // spawn each result after refine
- foreach (var result in component.RefineResult!)
- {
- var droppedEnt = Spawn(result, resultPosition);
-
- // TODO: If something has a stack... Just use a prototype with a single thing in the stack.
- // This is not a good way to do it.
- if (TryComp<StackComponent>(droppedEnt, out var stack))
- _stackSystem.SetCount(droppedEnt, 1, stack);
- }
+ SpawnNextToOrDrop(spawn, uid, xform);
}
+
+ Del(uid);
}
}