CatStation/Content.Server/Animals/Systems/SolutionProducerSystem.cs
AndrewFenriz 6dc1aae3f2
Refactor animal reagent/entity production (#45019)
* port 35190

* HungerProduction

* SolutionProducer

* update

* move to server

* small tweak for Shearable

* fix

* ProductionAttemptEvent

* EntityProducer

* update EggLayer

* EntityTable

* no more actions on EggLayer

* move popups to comp

* kill EggLayer

* new locale

* rename field

* upd

* SatiationType

* rename to SatiationProduction and lil docs

* EntityQuery

* more docs for god of docs

* small fix

* more queries
2026-08-16 19:15:52 +00:00

34 lines
1.1 KiB
C#

using Content.Server.Animals.Components;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.FixedPoint;
namespace Content.Server.Animals.Systems;
/// <inheritdoc cref="SolutionProducerComponent"/>
public sealed partial class SolutionProducerSystem : EntitySystem
{
[Dependency] private SharedSolutionContainerSystem _solutionContainer = default!;
[Dependency] private EntityQuery<SolutionComponent> _solutionQuery;
[SubscribeLocalEvent]
private void OnProduce(Entity<SolutionProducerComponent> ent, ref ProductionAttemptEvent args)
{
if (!_solutionQuery.TryComp(ent, out var solution))
return;
var amount = FixedPoint2.Min(solution.Solution.AvailableVolume, ent.Comp.Generated.Volume);
if (amount <= FixedPoint2.Zero)
return;
var generated = amount == ent.Comp.Generated.Volume
? ent.Comp.Generated
: ent.Comp.Generated.Clone().SplitSolution(amount);
if (!_solutionContainer.TryAddSolution((ent.Owner, solution), generated))
return;
args.Produced = true;
}
}