Recycler Overhaul (#30802)

* Recycler overhaul

* remove
This commit is contained in:
Nemanja
2024-08-18 23:39:00 -04:00
committed by GitHub
parent 1fa447f769
commit 476c7751c4
32 changed files with 207 additions and 253 deletions

View File

@@ -20,19 +20,24 @@ using Robust.Shared.Player;
using Robust.Shared.Utility;
using System.Linq;
using Content.Server.Administration.Logs;
using Content.Server.Repairable;
using Content.Shared.Database;
using Content.Shared.Destructible;
using Content.Shared.Emag.Components;
using Robust.Shared.Prototypes;
namespace Content.Server.Materials;
/// <inheritdoc/>
public sealed class MaterialReclaimerSystem : SharedMaterialReclaimerSystem
{
[Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] private readonly AppearanceSystem _appearance = default!;
[Dependency] private readonly GameTicker _ticker = default!;
[Dependency] private readonly MaterialStorageSystem _materialStorage = default!;
[Dependency] private readonly OpenableSystem _openable = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly SolutionContainerSystem _solutionContainer = default!;
[Dependency] private readonly SharedSolutionContainerSystem _solutionContainer = default!;
[Dependency] private readonly SharedBodySystem _body = default!; //bobby
[Dependency] private readonly PuddleSystem _puddle = default!;
[Dependency] private readonly StackSystem _stack = default!;
@@ -44,16 +49,14 @@ public sealed class MaterialReclaimerSystem : SharedMaterialReclaimerSystem
{
base.Initialize();
SubscribeLocalEvent<MaterialReclaimerComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<MaterialReclaimerComponent, PowerChangedEvent>(OnPowerChanged);
SubscribeLocalEvent<MaterialReclaimerComponent, InteractUsingEvent>(OnInteractUsing,
before: new []{typeof(WiresSystem), typeof(SolutionTransferSystem)});
before: [typeof(WiresSystem), typeof(SolutionTransferSystem)]);
SubscribeLocalEvent<MaterialReclaimerComponent, SuicideByEnvironmentEvent>(OnSuicideByEnvironment);
SubscribeLocalEvent<ActiveMaterialReclaimerComponent, PowerChangedEvent>(OnActivePowerChanged);
}
private void OnStartup(Entity<MaterialReclaimerComponent> entity, ref ComponentStartup args)
{
_solutionContainer.EnsureSolution(entity.Owner, entity.Comp.SolutionContainerId);
SubscribeLocalEvent<MaterialReclaimerComponent, BreakageEventArgs>(OnBreakage);
SubscribeLocalEvent<MaterialReclaimerComponent, RepairedEvent>(OnRepaired);
}
private void OnPowerChanged(Entity<MaterialReclaimerComponent> entity, ref PowerChangedEvent args)
@@ -119,6 +122,30 @@ public sealed class MaterialReclaimerSystem : SharedMaterialReclaimerSystem
TryFinishProcessItem(entity, null, entity.Comp);
}
private void OnBreakage(Entity<MaterialReclaimerComponent> ent, ref BreakageEventArgs args)
{
//un-emags itself when it breaks
RemComp<EmaggedComponent>(ent);
SetBroken(ent, true);
}
private void OnRepaired(Entity<MaterialReclaimerComponent> ent, ref RepairedEvent args)
{
SetBroken(ent, false);
}
public void SetBroken(Entity<MaterialReclaimerComponent> ent, bool val)
{
if (ent.Comp.Broken == val)
return;
_appearance.SetData(ent, RecyclerVisuals.Broken, val);
SetReclaimerEnabled(ent, false);
ent.Comp.Broken = val;
Dirty(ent);
}
/// <inheritdoc/>
public override bool TryFinishProcessItem(EntityUid uid, MaterialReclaimerComponent? component = null, ActiveMaterialReclaimerComponent? active = null)
{
@@ -136,7 +163,8 @@ public sealed class MaterialReclaimerSystem : SharedMaterialReclaimerSystem
// scales the output if the process was interrupted.
var completion = 1f - Math.Clamp((float) Math.Round((active.EndTime - Timing.CurTime) / active.Duration),
0f, 1f);
0f,
1f);
Reclaim(uid, item, completion, component);
return true;
@@ -193,7 +221,8 @@ public sealed class MaterialReclaimerSystem : SharedMaterialReclaimerSystem
foreach (var (storedMaterial, storedAmount) in storage.Storage)
{
var stacks = _materialStorage.SpawnMultipleFromMaterial(storedAmount, storedMaterial,
var stacks = _materialStorage.SpawnMultipleFromMaterial(storedAmount,
storedMaterial,
xform.Coordinates,
out var materialOverflow);
var amountConsumed = storedAmount - materialOverflow;
@@ -215,8 +244,6 @@ public sealed class MaterialReclaimerSystem : SharedMaterialReclaimerSystem
{
if (!Resolve(reclaimer, ref reclaimerComponent, ref xform))
return;
if (!_solutionContainer.TryGetSolution(reclaimer, reclaimerComponent.SolutionContainerId, out var outputSolution))
return;
efficiency *= reclaimerComponent.Efficiency;
@@ -232,20 +259,14 @@ public sealed class MaterialReclaimerSystem : SharedMaterialReclaimerSystem
}
// if the item we inserted has reagents, add it in.
if (TryComp<SolutionContainerManagerComponent>(item, out var solutionContainer))
if (_solutionContainer.TryGetDrainableSolution(item, out _, out var drainableSolution))
{
foreach (var (_, soln) in _solutionContainer.EnumerateSolutions((item, solutionContainer)))
{
var solution = soln.Comp.Solution;
foreach (var quantity in solution.Contents)
{
totalChemicals.AddReagent(quantity.Reagent.Prototype, quantity.Quantity * efficiency, false);
}
}
totalChemicals.AddSolution(drainableSolution, _prototype);
}
_solutionContainer.TryTransferSolution(outputSolution.Value, totalChemicals, totalChemicals.Volume);
if (totalChemicals.Volume > 0)
if (!_solutionContainer.TryGetSolution(reclaimer, reclaimerComponent.SolutionContainerId, out var outputSolution) ||
!_solutionContainer.TryTransferSolution(outputSolution.Value, totalChemicals, totalChemicals.Volume) ||
totalChemicals.Volume > 0)
{
_puddle.TrySpillAt(reclaimer, totalChemicals, out _, sound, transformComponent: xform);
}