using Content.Shared.Materials; using Content.Shared.Research.Prototypes; using JetBrains.Annotations; using Robust.Shared.Prototypes; namespace Content.Shared.Lathe; /// /// This handles... /// public abstract class SharedLatheSystem : EntitySystem { [Dependency] private readonly IPrototypeManager _proto = default!; [Dependency] private readonly SharedMaterialStorageSystem _materialStorage = default!; [PublicAPI] public bool CanProduce(EntityUid uid, string recipe, int amount = 1, LatheComponent? component = null) { return _proto.TryIndex(recipe, out var proto) && CanProduce(uid, proto, amount, component); } public bool CanProduce(EntityUid uid, LatheRecipePrototype recipe, int amount = 1, LatheComponent? component = null) { if (!Resolve(uid, ref component)) return false; if (!HasRecipe(uid, recipe, component)) return false; foreach (var (material, needed) in recipe.RequiredMaterials) { if (_materialStorage.GetMaterialAmount(component.Owner, material) < (amount * needed)) return false; } return true; } protected abstract bool HasRecipe(EntityUid uid, LatheRecipePrototype recipe, LatheComponent component); }