Files
tbd-station-14/Content.Shared/Lathe/SharedLatheSystem.cs
Nemanja 2e7dcb1ed8 Lathe Refactor and ECS (#11201)
* lathe and material storage refactor

* materialStorage ECS

it kinda sus tho

* beginning the lathe shitcode dive

* couple lathe visuals and lathe system

* lathe changes and such

* dynamic lathe databases

* rewrote internal logic

on to ui

* da newI

* material display clientside

* misc ui changes

* component state handling and various other things

* moar

* Update Content.Shared/Lathe/LatheComponent.cs

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>

* first volley of sloth review

* more fixes

* losin' my mind

* all da changes

* test fix and other review

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
2022-09-16 18:49:05 -05:00

39 lines
1.3 KiB
C#

using Content.Shared.Materials;
using Content.Shared.Research.Prototypes;
using JetBrains.Annotations;
using Robust.Shared.Prototypes;
namespace Content.Shared.Lathe;
/// <summary>
/// This handles...
/// </summary>
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<LatheRecipePrototype>(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);
}