48 lines
1.5 KiB
C#
48 lines
1.5 KiB
C#
|
|
namespace DanieleMarotta.RiversongCodeShowcase
|
|
{
|
|
[GameSystemGroup(typeof(DayOnlyAgentSpawnSystemsGroup))]
|
|
public class HouseAgentSystem : GameSystem, IUpdatable
|
|
{
|
|
[InjectService]
|
|
private GameConfig _config;
|
|
|
|
[InjectService]
|
|
private IEntityCache _entityCache;
|
|
|
|
[InjectService]
|
|
private IProductCatalog _productCatalog;
|
|
|
|
[InjectService]
|
|
private IAgentCommonLogic _agentCommonLogic;
|
|
|
|
public HouseAgentSystem(IServiceLocator serviceLocator) : base(serviceLocator)
|
|
{
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
var agentDefinition = (AgentDefinition)_config.Agents.GenericAgent.Asset;
|
|
|
|
foreach (var house in _entityCache.GetHouses())
|
|
{
|
|
ref var storage = ref house.GetStorageRW();
|
|
ref var needsState = ref house.GetNeedsStateRW();
|
|
|
|
for (var i = 0; i < needsState.Needs.Length; i++)
|
|
{
|
|
var need = needsState.Needs[i];
|
|
|
|
if (need.TierIndex > house.TierIndex) break;
|
|
if (need.Type != PopulationNeedType.Product || need.Current > need.FetchThreshold) continue;
|
|
|
|
storage.Get(need.ProductHandle, out var count, out var putReservations, out _);
|
|
if (count > 0 || putReservations > 0) continue;
|
|
|
|
if (_agentCommonLogic.TryFetchProductFromProvider(agentDefinition, house, need.ProductHandle, 1)) break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|