Elimate most IInteractUsing (#7481)
This commit is contained in:
54
Content.Server/Construction/RefiningSystem.cs
Normal file
54
Content.Server/Construction/RefiningSystem.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using Content.Server.Construction.Components;
|
||||
using Content.Server.Tools;
|
||||
using Content.Server.Stack;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Tools.Components;
|
||||
|
||||
namespace Content.Server.Construction
|
||||
{
|
||||
public sealed class RefiningSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly ToolSystem _toolSystem = default!;
|
||||
[Dependency] private readonly StackSystem _stackSystem = default!;
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<WelderRefinableComponent, InteractUsingEvent>(OnInteractUsing);
|
||||
}
|
||||
|
||||
private async void OnInteractUsing(EntityUid uid, WelderRefinableComponent component, InteractUsingEvent args)
|
||||
{
|
||||
// check if object is welder
|
||||
if (!TryComp(args.Used, out ToolComponent? tool))
|
||||
return;
|
||||
|
||||
// check if someone is already welding object
|
||||
if (component.BeingWelded)
|
||||
return;
|
||||
|
||||
component.BeingWelded = true;
|
||||
|
||||
if (!await _toolSystem.UseTool(args.Used, args.User, uid, component.RefineFuel, component.RefineTime, component.QualityNeeded))
|
||||
{
|
||||
// failed to veld - abort refine
|
||||
component.BeingWelded = false;
|
||||
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 = EntityManager.SpawnEntity(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user