33 lines
1.1 KiB
C#
33 lines
1.1 KiB
C#
|
|
namespace DanieleMarotta.RiversongCodeShowcase
|
|
{
|
|
[GameSystemGroup(typeof(EconomySystemGroup))]
|
|
public class ProductionRequirementsGameSystem : GameSystem, IUpdatable
|
|
{
|
|
[InjectService]
|
|
private IEntityCache _entityCache;
|
|
|
|
public ProductionRequirementsGameSystem(IServiceLocator serviceLocator) : base(serviceLocator)
|
|
{
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
foreach (var producer in _entityCache.GetProducers())
|
|
{
|
|
ref var productionState = ref producer.GetProductionStateRW();
|
|
ref var recipe = ref productionState.Recipe;
|
|
ref var storage = ref producer.GetStorageRW();
|
|
|
|
productionState.MetRequirements = ProductionRequirements.All;
|
|
|
|
foreach (var (product, amount) in recipe.Inputs)
|
|
if (storage.AvailableNow(product) < amount)
|
|
{
|
|
productionState.MetRequirements &= ~ProductionRequirements.InputsAvailable;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |