Files
space-station-14/Content.Server/Administration/Commands/AddReagent.cs
T
Princess Cheeseballs ef3a0ecc2a Solutions Refactor Part 1 - Solution Prototypes (#43412)
* Everything except the YAML slop...

* She solution on my manager till I sajfslkahfsjakfhaskjfshajksafhfsakhfasjfas

* another 1000 lines

* fix chem dispenser size

* go my shnelf

* Implicit ass

* rider is being mean for some reason

* dasdas

* borger

* better formatting go!

* clothes/bloodstream

* Cartons

* cups and bottles

* mmm soder

* bar drinks

* Spray bottles and some size tweaks with hindsight

* 99 bottles of beer on the wall I hate YAML

* push that shit

* mmm burger

* Sneed

* sheets

* condiments

* mmm yummy

* fridge yummyfood

* meat...

* sub 300

* burger...

* bready

* let them eat cake

* does she know how to make a grilled cheese?

* pizza pie!

* misc shit

* soup or salad

* Food and drinks, vanquished

* the cubes!!!

* Almost free from YAML...

* fix test fails and some yaml issues

* fix prediction, almost done

* fix all test fails

* remove master merge artifacts and undo autonetworking

* review and compatibility

* graaah

* unfuck master merge I hate github

* merg conflicts

* sfsa

* ehoop

* sadas

* afsafsaasf

* merge conflicts

* fucked up the merge conflicts

* merge conflict is fucked I might need to completely redo this branch

* test fail

* no calcium????

---------

Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
2026-04-25 02:00:34 +00:00

74 lines
2.8 KiB
C#

using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Administration;
using Content.Shared.Chemistry.Components.SolutionManager;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Robust.Shared.Console;
using Robust.Shared.Prototypes;
using System.Linq;
namespace Content.Server.Administration.Commands
{
/// <summary>
/// Command that allows you to edit an existing solution by adding (or removing) reagents.
/// </summary>
[AdminCommand(AdminFlags.Admin)]
public sealed class AddReagent : IConsoleCommand
{
[Dependency] private readonly IEntityManager _entManager = default!;
[Dependency] private readonly IPrototypeManager _protomanager = default!;
public string Command => "addreagent";
public string Description => "Add (or remove) some amount of reagent from some solution.";
public string Help => $"Usage: {Command} <target> <solution> <reagent> <quantity>";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length < 4)
{
shell.WriteLine($"Not enough arguments.\n{Help}");
return;
}
if (!NetEntity.TryParse(args[0], out var uidNet) || !_entManager.TryGetEntity(uidNet, out var uid))
{
shell.WriteLine($"Invalid entity id.");
return;
}
var solutionContainerSystem = _entManager.System<SharedSolutionContainerSystem>();
if (!solutionContainerSystem.TryGetSolution(uid.Value, args[1], out var solution))
{
var solutions = solutionContainerSystem.EnumerateSolutions(uid.Value).ToArray();
if (!solutions.Any())
{
shell.WriteLine("Entity does not have any solutions!");
return;
}
var validSolutions = string.Join(", ", solutions.Select(s => s.Name));
shell.WriteLine($"Entity does not have a \"{args[1]}\" solution. Valid solutions are:\n{validSolutions}");
return;
}
if (!_protomanager.HasIndex<ReagentPrototype>(args[2]))
{
shell.WriteLine($"Unknown reagent prototype");
return;
}
if (!float.TryParse(args[3], out var quantityFloat))
{
shell.WriteLine($"Failed to parse quantity");
return;
}
var quantity = FixedPoint2.New(MathF.Abs(quantityFloat));
if (quantityFloat > 0)
solutionContainerSystem.TryAddReagent(solution.Value, args[2], quantity, out _);
else
solutionContainerSystem.RemoveReagent(solution.Value, args[2], quantity);
}
}
}