48 lines
1.5 KiB
C#
48 lines
1.5 KiB
C#
|
|
namespace DanieleMarotta.RiversongCodeShowcase
|
|
{
|
|
[GameSystemGroup(typeof(DayOnlyAgentSpawnSystemsGroup))]
|
|
public class HarvesterAgentSystem : GameSystem, IUpdatable
|
|
{
|
|
[InjectService]
|
|
private IEntityCollection _entityCollection;
|
|
|
|
[InjectService]
|
|
private IEntityCache _entityCache;
|
|
|
|
[InjectService]
|
|
private ITileSpace _tileSpace;
|
|
|
|
[InjectService]
|
|
private IAgentFactory _agentFactory;
|
|
|
|
[InjectService]
|
|
private IProductCatalog _productCatalog;
|
|
|
|
[InjectService]
|
|
private IBuildingSpatialQuery _buildingSpatialQuery;
|
|
|
|
[InjectService]
|
|
private IAgentCommonLogic _agentCommonLogic;
|
|
|
|
public HarvesterAgentSystem(IServiceLocator serviceLocator) : base(serviceLocator)
|
|
{
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
foreach (var harvester in _entityCache.GetHarvesterBuildings())
|
|
{
|
|
if (!_agentFactory.CanSpawnAgent(harvester, 1, AgentJob.Harvester)) continue;
|
|
|
|
var resourceDefinition = harvester.Definition.HarvestedResource;
|
|
var position = _tileSpace.TileToWorld(harvester.Rect.Center);
|
|
var agent = _agentFactory.CreateVillager(resourceDefinition.HarvesterAgent, harvester, position, AgentJob.Harvester);
|
|
|
|
var range = harvester.Definition.Range;
|
|
IntentQueue.Harvest(ref agent.GetIntentQueueRW(), harvester.Rect, harvester.Id, resourceDefinition, range);
|
|
}
|
|
}
|
|
}
|
|
}
|