mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 18:31:17 +03:00
* IoC source gen compatibility Can be merged before or after https://github.com/space-wizards/RobustToolbox/pull/6549 doesn't really matter. * Missed a spot
47 lines
1.8 KiB
C#
47 lines
1.8 KiB
C#
using Content.Server.Chemistry.Components;
|
|
using Content.Shared.Chemistry.EntitySystems;
|
|
using Content.Shared.Chemistry.Reagent;
|
|
using Content.Shared.Random;
|
|
using Content.Shared.Random.Helpers;
|
|
using Content.Shared.Storage.Components;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Random;
|
|
|
|
namespace Content.Server.Chemistry.EntitySystems;
|
|
|
|
public sealed partial class SolutionRandomFillSystem : EntitySystem
|
|
{
|
|
[Dependency] private SharedSolutionContainerSystem _solutionsSystem = default!;
|
|
[Dependency] private IPrototypeManager _proto = default!;
|
|
[Dependency] private IRobustRandom _random = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<RandomFillSolutionComponent, MapInitEvent>(OnRandomSolutionFillMapInit);
|
|
}
|
|
|
|
private void OnRandomSolutionFillMapInit(Entity<RandomFillSolutionComponent> entity, ref MapInitEvent args)
|
|
{
|
|
if (entity.Comp.WeightedRandomId == null)
|
|
return;
|
|
|
|
var pick = _proto.Index<WeightedRandomFillSolutionPrototype>(entity.Comp.WeightedRandomId).Pick(_random);
|
|
|
|
var reagent = pick.reagent;
|
|
var quantity = pick.quantity;
|
|
|
|
if (!_proto.HasIndex<ReagentPrototype>(reagent))
|
|
{
|
|
Log.Error($"Tried to add invalid reagent Id {reagent} using SolutionRandomFill.");
|
|
return;
|
|
}
|
|
|
|
_solutionsSystem.EnsureSolution(entity.Owner, entity.Comp.Solution, out var target);
|
|
if (target.Comp.Solution.AvailableVolume < quantity)
|
|
Log.Error($"A random solution fill {entity.Comp.WeightedRandomId} tried to put {pick.quantity} of {pick.reagent} into {ToPrettyString(target)} but there was not enough space!");
|
|
|
|
_solutionsSystem.TryAddReagent(target, reagent, quantity);
|
|
}
|
|
}
|