Files
crystall-punk-14/Content.Shared/Tools/Systems/ToolRefinableSystem.cs

56 lines
1.6 KiB
C#
Raw Permalink Normal View History

using Content.Shared.Construction;
2022-04-15 17:20:20 -04:00
using Content.Shared.Interaction;
using Content.Shared.Storage;
2024-06-02 22:28:53 -05:00
using Content.Shared.Tools.Components;
using Robust.Shared.Network;
using Robust.Shared.Random;
2022-04-15 17:20:20 -04:00
2024-06-02 22:28:53 -05:00
namespace Content.Shared.Tools.Systems;
2024-06-02 22:28:53 -05:00
public sealed class ToolRefinablSystem : EntitySystem
2022-04-15 17:20:20 -04:00
{
2024-06-02 22:28:53 -05:00
[Dependency] private readonly INetManager _net = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly SharedToolSystem _toolSystem = default!;
public override void Initialize()
2022-04-15 17:20:20 -04:00
{
base.Initialize();
2024-06-02 22:28:53 -05:00
SubscribeLocalEvent<ToolRefinableComponent, InteractUsingEvent>(OnInteractUsing);
SubscribeLocalEvent<ToolRefinableComponent, WelderRefineDoAfterEvent>(OnDoAfter);
}
2022-04-15 17:20:20 -04:00
2024-06-02 22:28:53 -05:00
private void OnInteractUsing(EntityUid uid, ToolRefinableComponent component, InteractUsingEvent args)
{
if (args.Handled)
return;
2022-04-15 17:20:20 -04:00
args.Handled = _toolSystem.UseTool(
args.Used,
args.User,
uid,
component.RefineTime,
component.QualityNeeded,
new WelderRefineDoAfterEvent(),
fuel: component.RefineFuel);
}
2024-06-02 22:28:53 -05:00
private void OnDoAfter(EntityUid uid, ToolRefinableComponent component, WelderRefineDoAfterEvent args)
{
if (args.Cancelled)
return;
2024-06-02 22:28:53 -05:00
if (_net.IsClient)
return;
var xform = Transform(uid);
var spawns = EntitySpawnCollection.GetSpawns(component.RefineResult, _random);
foreach (var spawn in spawns)
{
SpawnNextToOrDrop(spawn, uid, xform);
2022-04-15 17:20:20 -04:00
}
Del(uid);
2022-04-15 17:20:20 -04:00
}
}