using Content.Server.Chemistry.Components; using Content.Server.Chemistry.Containers.EntitySystems; using Content.Shared.Chemistry.Reagent; using Content.Shared.Random; using Content.Shared.Random.Helpers; using Robust.Shared.Prototypes; using Robust.Shared.Random; namespace Content.Server.Chemistry.EntitySystems; public sealed class SolutionRandomFillSystem : EntitySystem { [Dependency] private readonly SolutionContainerSystem _solutionsSystem = default!; [Dependency] private readonly IPrototypeManager _proto = default!; [Dependency] private readonly IRobustRandom _random = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnRandomSolutionFillMapInit); } private void OnRandomSolutionFillMapInit(Entity entity, ref MapInitEvent args) { if (entity.Comp.WeightedRandomId == null) return; var pick = _proto.Index(entity.Comp.WeightedRandomId).Pick(_random); var reagent = pick.reagent; var quantity = pick.quantity; if (!_proto.HasIndex(reagent)) { Log.Error($"Tried to add invalid reagent Id {reagent} using SolutionRandomFill."); return; } var target = _solutionsSystem.EnsureSolutionEntity(entity.Owner, entity.Comp.Solution, pick.quantity, null, out _); _solutionsSystem.TryAddReagent(target, reagent, quantity, out _); } }