riversong code showcase
This commit is contained in:
40
Source/Riversong/Game/World/Agents/FarmingAgentSystem.cs
Normal file
40
Source/Riversong/Game/World/Agents/FarmingAgentSystem.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user