40 lines
1.4 KiB
C#
40 lines
1.4 KiB
C#
using UnityEngine;
|
|
|
|
namespace DanieleMarotta.RiversongCodeShowcase
|
|
{
|
|
[GameSystemGroup(typeof(EarlyAgentsSystemGroup))]
|
|
[UpdateBefore(typeof(AgentsSpawnTickSystem))]
|
|
public class AgentSpawnCooldownSystem : GameSystem, IUpdatable
|
|
{
|
|
[InjectService]
|
|
private IEntityCollection _entityCollection;
|
|
|
|
[InjectService]
|
|
private World _world;
|
|
|
|
public AgentSpawnCooldownSystem(IServiceLocator serviceLocator) : base(serviceLocator)
|
|
{
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
var laborEfficiencyModifier = _world.ProductionState.LaborEfficiencyModifier;
|
|
|
|
foreach (Building building in _entityCollection.GetInternalEntityList(typeof(Building)))
|
|
{
|
|
ref var agentSourceState = ref building.GetAgentSourceStateRW();
|
|
ref var sleepState = ref building.GetSleepStateRW();
|
|
|
|
for (var jobIndex = 1; jobIndex < (int)AgentJob.Count; jobIndex++)
|
|
{
|
|
var cooldown = agentSourceState.SpawnCooldown[jobIndex];
|
|
if (cooldown <= 0) continue;
|
|
|
|
var efficiencyMultiplier = Mathf.Max(0, 1 + sleepState.EfficiencyModifier + laborEfficiencyModifier);
|
|
var dt = Time.deltaTime * efficiencyMultiplier;
|
|
agentSourceState.SpawnCooldown[jobIndex] = Mathf.MoveTowards(cooldown, 0, dt);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |