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