41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
|
|
namespace DanieleMarotta.RiversongCodeShowcase
|
|
{
|
|
[GameSystemGroup(typeof(DayOnlyAgentSpawnSystemsGroup))]
|
|
public class FarmingAgentSystem : GameSystem, IUpdatable
|
|
{
|
|
private const int MaxAgentCount = 1;
|
|
|
|
[InjectService]
|
|
private GameConfig _config;
|
|
|
|
[InjectService]
|
|
private IEntityCache _entityCache;
|
|
|
|
[InjectService]
|
|
private ITileSpace _tileSpace;
|
|
|
|
[InjectService]
|
|
private IAgentFactory _agentFactory;
|
|
|
|
public FarmingAgentSystem(IServiceLocator serviceLocator) : base(serviceLocator)
|
|
{
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
var agentDefinition = (AgentDefinition)_config.Agents.FarmerAgent.Asset;
|
|
|
|
foreach (var farm in _entityCache.GetFarmBuildings())
|
|
{
|
|
if (!_agentFactory.CanSpawnAgent(farm, MaxAgentCount, AgentJob.Farmer)) continue;
|
|
|
|
var position = _tileSpace.TileToWorld(farm.Rect.Center);
|
|
var agent = _agentFactory.CreateVillager(agentDefinition, farm, position, AgentJob.Farmer);
|
|
|
|
IntentQueue.WorkFertileTile(ref agent.GetIntentQueueRW(), farm.Rect, farm.Id, agent.Id, farm.Definition.Range);
|
|
}
|
|
}
|
|
}
|
|
}
|