Elimate most IInteractUsing (#7481)

This commit is contained in:
Rane
2022-04-15 17:20:20 -04:00
committed by GitHub
parent 569085ab5c
commit 70a26bf0c2
13 changed files with 431 additions and 485 deletions

View 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);
}
}
}
}