2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Research.Prototypes;
|
2021-07-12 01:32:10 -07:00
|
|
|
using Robust.Shared.GameStates;
|
2019-04-26 15:51:05 +02:00
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Shared.Lathe
|
2019-04-26 15:51:05 +02:00
|
|
|
{
|
2021-07-12 01:32:10 -07:00
|
|
|
[NetworkedComponent()]
|
2022-02-16 00:23:23 -07:00
|
|
|
[Virtual]
|
2019-04-26 15:51:05 +02:00
|
|
|
public class SharedLatheComponent : Component
|
|
|
|
|
{
|
2021-12-08 17:32:32 +01:00
|
|
|
[Dependency] private readonly IEntityManager _entMan = default!;
|
2020-08-24 14:10:28 +02:00
|
|
|
[Dependency] protected readonly IPrototypeManager PrototypeManager = default!;
|
2019-04-26 15:51:05 +02:00
|
|
|
public bool CanProduce(LatheRecipePrototype recipe, int quantity = 1)
|
|
|
|
|
{
|
2021-12-08 17:32:32 +01:00
|
|
|
if (!_entMan.TryGetComponent(Owner, out SharedMaterialStorageComponent? storage)
|
|
|
|
|
|| !_entMan.TryGetComponent(Owner, out SharedLatheDatabaseComponent? database)) return false;
|
2019-04-26 15:51:05 +02:00
|
|
|
|
|
|
|
|
if (!database.Contains(recipe)) return false;
|
|
|
|
|
|
|
|
|
|
foreach (var (material, amount) in recipe.RequiredMaterials)
|
|
|
|
|
{
|
2022-04-17 03:34:14 -04:00
|
|
|
if (storage[material] < (amount * quantity)) return false;
|
2019-04-26 15:51:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-09 20:10:36 -08:00
|
|
|
public bool CanProduce(string id, int quantity = 1)
|
2019-04-26 15:51:05 +02:00
|
|
|
{
|
2022-01-09 20:10:36 -08:00
|
|
|
return PrototypeManager.TryIndex(id, out LatheRecipePrototype? recipe) && CanProduce(recipe, quantity);
|
2019-04-26 15:51:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|