riversong code showcase
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using Cysharp.Threading.Tasks;
|
||||
|
||||
namespace DanieleMarotta.RiversongCodeShowcase
|
||||
{
|
||||
[GameSystemGroup(typeof(DefaultAgentsSystemGroup))]
|
||||
public class DeSpawnAgentsAtNightSystem : GameSystem, IInitializable, IDisposable
|
||||
{
|
||||
[InjectService]
|
||||
private ISignalBus _signalBus;
|
||||
|
||||
[InjectService]
|
||||
private IEntityCollection _entityCollection;
|
||||
|
||||
[InjectService]
|
||||
private IIntentLogicExecutor _intentLogicExecutor;
|
||||
|
||||
public DeSpawnAgentsAtNightSystem(IServiceLocator serviceLocator) : base(serviceLocator)
|
||||
{
|
||||
}
|
||||
|
||||
public UniTask InitializeAsync()
|
||||
{
|
||||
_signalBus.Subscribe<NightStartedSignal>(OnNightStarted);
|
||||
|
||||
return UniTask.CompletedTask;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_signalBus.Unsubscribe<NightStartedSignal>(OnNightStarted);
|
||||
}
|
||||
|
||||
private void OnNightStarted(NightStartedSignal signal)
|
||||
{
|
||||
foreach (Agent agent in _entityCollection.GetInternalEntityList(typeof(Agent)))
|
||||
{
|
||||
if (agent.LifecycleState == AgentLifecycleState.DeSpawning) continue;
|
||||
|
||||
if (agent.CarriedProductHandle != IProductCatalog.InvalidHandle) continue;
|
||||
|
||||
ref var jobState = ref agent.GetJobStateRW();
|
||||
if (jobState.Job == AgentJob.StorageRequestHauler) continue;
|
||||
|
||||
ref var critterState = ref agent.GetCritterStateRW();
|
||||
if (critterState.IsCritter) continue;
|
||||
|
||||
_intentLogicExecutor.CancelRemainingIntents(agent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user