riversong code showcase
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
|
||||
namespace DanieleMarotta.RiversongCodeShowcase
|
||||
{
|
||||
[GameSystemGroup(typeof(DayOnlyAgentSpawnSystemsGroup))]
|
||||
public class ProducerDeliveryAgentSystem : GameSystem, IUpdatable
|
||||
{
|
||||
[InjectService]
|
||||
private GameConfig _config;
|
||||
|
||||
[InjectService]
|
||||
private IEntityCache _entityCache;
|
||||
|
||||
[InjectService]
|
||||
private IAgentCommonLogic _agentCommonLogic;
|
||||
|
||||
public ProducerDeliveryAgentSystem(IServiceLocator serviceLocator) : base(serviceLocator)
|
||||
{
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
var agentDefinition = (AgentDefinition)_config.Agents.GenericAgent.Asset;
|
||||
|
||||
foreach (var producer in _entityCache.GetProducers())
|
||||
{
|
||||
if (!producer.Definition.DeliversOutput) continue;
|
||||
|
||||
ref var productionState = ref producer.GetProductionStateRW();
|
||||
ref var recipe = ref productionState.Recipe;
|
||||
|
||||
foreach (var (productHandle, amount) in recipe.Inputs)
|
||||
if (_agentCommonLogic.TryFetchProductFromStorage(agentDefinition, producer, productHandle, amount))
|
||||
return;
|
||||
|
||||
_agentCommonLogic.TryDeliverProduct(agentDefinition, producer, recipe.OutputProductHandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user