Files
2026-05-21 16:04:49 +02:00

46 lines
1.5 KiB
C#

namespace DanieleMarotta.RiversongCodeShowcase
{
[GameSystemGroup(typeof(DayOnlyAgentSpawnSystemsGroup))]
public class HunterSpawnSystem : GameSystem, IUpdatable
{
[InjectService]
private GameConfig _config;
[InjectService]
private IEntityCache _entityCache;
[InjectService]
private ITileSpace _tileSpace;
[InjectService]
private IAgentFactory _agentFactory;
public HunterSpawnSystem(IServiceLocator serviceLocator) : base(serviceLocator)
{
}
public void Update()
{
var agentDefinition = (AgentDefinition)_config.Agents.HunterAgent.Asset;
foreach (var hunterBuilding in _entityCache.GetHunterBuildings()) SpawnHunterAgent(hunterBuilding, agentDefinition);
}
private void SpawnHunterAgent(Building hunterBuilding, AgentDefinition agentDefinition)
{
if (!_agentFactory.CanSpawnAgent(hunterBuilding, 1, AgentJob.Hunter)) return;
var position = _tileSpace.TileToWorld(hunterBuilding.Rect.Center);
var critterId = hunterBuilding.Definition.TargetCritter.RuntimeId;
var agent = _agentFactory.CreateVillager(agentDefinition, hunterBuilding, position, AgentJob.Hunter);
ref var jobState = ref agent.GetJobStateRW();
jobState.StateMachineStep = AgentStateMachineStep.Hunter_SeekingPrey;
IntentQueue.SeekPrey(ref agent.GetIntentQueueRW(), critterId, hunterBuilding.Definition.Range);
}
}
}