Add support for printing reagents in lathes (#30476)

* Add support for reagents in lathes

* missing locale
This commit is contained in:
Nemanja
2024-08-01 00:15:05 -04:00
committed by GitHub
parent 4b7325098a
commit 2c26be606f
17 changed files with 239 additions and 139 deletions

View File

@@ -16,6 +16,7 @@ using Robust.Shared.Map.Components;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
using System.Linq;
using Content.Shared.Research.Prototypes;
namespace Content.Server.Cargo.Systems;
@@ -158,6 +159,26 @@ public sealed class PricingSystem : EntitySystem
return price;
}
public double GetLatheRecipePrice(LatheRecipePrototype recipe)
{
var price = 0.0;
if (recipe.Result is { } result)
{
price += GetEstimatedPrice(_prototypeManager.Index(result));
}
if (recipe.ResultReagents is { } resultReagents)
{
foreach (var (reagent, amount) in resultReagents)
{
price += (_prototypeManager.Index(reagent).PricePerUnit * amount).Double();
}
}
return price;
}
/// <summary>
/// Get a rough price for an entityprototype. Does not consider contained entities.
/// </summary>

View File

@@ -1,23 +1,29 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Content.Server.Administration.Logs;
using Content.Server.Atmos;
using Content.Server.Atmos.EntitySystems;
using Content.Server.Fluids.EntitySystems;
using Content.Server.Lathe.Components;
using Content.Server.Materials;
using Content.Server.Popups;
using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
using Content.Server.Stack;
using Content.Shared.Atmos;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.UserInterface;
using Content.Shared.Database;
using Content.Shared.Emag.Components;
using Content.Shared.Examine;
using Content.Shared.Lathe;
using Content.Shared.Materials;
using Content.Shared.ReagentSpeed;
using Content.Shared.Research.Components;
using Content.Shared.Research.Prototypes;
using JetBrains.Annotations;
using Robust.Server.Containers;
using Robust.Server.GameObjects;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Prototypes;
@@ -34,9 +40,13 @@ namespace Content.Server.Lathe
[Dependency] private readonly AtmosphereSystem _atmosphere = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly ContainerSystem _container = default!;
[Dependency] private readonly UserInterfaceSystem _uiSys = default!;
[Dependency] private readonly MaterialStorageSystem _materialStorage = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly PuddleSystem _puddle = default!;
[Dependency] private readonly ReagentSpeedSystem _reagentSpeed = default!;
[Dependency] private readonly SharedSolutionContainerSystem _solution = default!;
[Dependency] private readonly StackSystem _stack = default!;
[Dependency] private readonly TransformSystem _transform = default!;
@@ -63,7 +73,6 @@ namespace Content.Server.Lathe
SubscribeLocalEvent<EmagLatheRecipesComponent, LatheGetRecipesEvent>(GetEmagLatheRecipes);
SubscribeLocalEvent<LatheHeatProducingComponent, LatheStartPrintingEvent>(OnHeatStartPrinting);
}
public override void Update(float frameTime)
{
var query = EntityQueryEnumerator<LatheProducingComponent, LatheComponent>();
@@ -119,7 +128,7 @@ namespace Content.Server.Lathe
{
if (!_proto.TryIndex(id, out var proto))
continue;
foreach (var (mat, _) in proto.RequiredMaterials)
foreach (var (mat, _) in proto.Materials)
{
if (!materialWhitelist.Contains(mat))
{
@@ -165,7 +174,7 @@ namespace Content.Server.Lathe
if (!CanProduce(uid, recipe, 1, component))
return false;
foreach (var (mat, amount) in recipe.RequiredMaterials)
foreach (var (mat, amount) in recipe.Materials)
{
var adjustedAmount = recipe.ApplyMaterialDiscount
? (int) (-amount * component.MaterialUseMultiplier)
@@ -211,8 +220,31 @@ namespace Content.Server.Lathe
if (comp.CurrentRecipe != null)
{
var result = Spawn(comp.CurrentRecipe.Result, Transform(uid).Coordinates);
_stack.TryMergeToContacts(result);
if (comp.CurrentRecipe.Result is { } resultProto)
{
var result = Spawn(resultProto, Transform(uid).Coordinates);
_stack.TryMergeToContacts(result);
}
if (comp.CurrentRecipe.ResultReagents is { } resultReagents &&
comp.ReagentOutputSlotId is { } slotId)
{
var toAdd = new Solution(
resultReagents.Select(p => new ReagentQuantity(p.Key.Id, p.Value, null)));
// dispense it in the container if we have it and dump it if we don't
if (_container.TryGetContainer(uid, slotId, out var container) &&
container.ContainedEntities.Count == 1 &&
_solution.TryGetFitsInDispenser(container.ContainedEntities.First(), out var solution, out _))
{
_solution.AddSolution(solution.Value, toAdd);
}
else
{
_popup.PopupEntity(Loc.GetString("lathe-reagent-dispense-no-container", ("name", uid)), uid);
_puddle.TrySpillAt(uid, toAdd, out _);
}
}
}
comp.CurrentRecipe = null;
@@ -327,6 +359,7 @@ namespace Content.Server.Lathe
{
return GetAvailableRecipes(uid, component).Contains(recipe.ID);
}
#region UI Messages
private void OnLatheQueueRecipeMessage(EntityUid uid, LatheComponent component, LatheQueueRecipeMessage args)
@@ -343,8 +376,9 @@ namespace Content.Server.Lathe
}
if (count > 0)
{
_adminLogger.Add(LogType.Action, LogImpact.Low,
$"{ToPrettyString(args.Actor):player} queued {count} {recipe.Name} at {ToPrettyString(uid):lathe}");
_adminLogger.Add(LogType.Action,
LogImpact.Low,
$"{ToPrettyString(args.Actor):player} queued {count} {GetRecipeName(recipe)} at {ToPrettyString(uid):lathe}");
}
}
TryStartProducing(uid, component);

View File

@@ -7,7 +7,6 @@ using Content.Server.Item;
using Content.Server.Power.Components;
using Content.Shared.Administration;
using Content.Shared.Item;
using Content.Shared.Materials;
using Content.Shared.Research.Prototypes;
using Content.Shared.UserInterface;
using Content.Shared.Weapons.Melee;
@@ -224,13 +223,13 @@ public sealed class StatValuesCommand : IConsoleCommand
{
var cost = 0.0;
foreach (var (material, count) in proto.RequiredMaterials)
foreach (var (material, count) in proto.Materials)
{
var materialPrice = _proto.Index<MaterialPrototype>(material).Price;
var materialPrice = _proto.Index(material).Price;
cost += materialPrice * count;
}
var sell = priceSystem.GetEstimatedPrice(_proto.Index<EntityPrototype>(proto.Result));
var sell = priceSystem.GetLatheRecipePrice(proto);
values.Add(new[]
{