32 lines
975 B
C#
32 lines
975 B
C#
using Cysharp.Threading.Tasks;
|
|
|
|
namespace DanieleMarotta.RiversongCodeShowcase
|
|
{
|
|
public class HarvestResourceIntentExecutionLogic : IntentExecutionLogic
|
|
{
|
|
private World _world;
|
|
|
|
private ISignalBus _signalBus;
|
|
|
|
public override UniTask InitializeAsync(IServiceLocator serviceLocator)
|
|
{
|
|
_world = serviceLocator.GetService<World>();
|
|
_signalBus = serviceLocator.GetService<ISignalBus>();
|
|
|
|
return UniTask.CompletedTask;
|
|
}
|
|
|
|
public override IntentExecutionResult Execute(Agent agent, in AgentIntent intent)
|
|
{
|
|
ref var jobState = ref agent.GetJobStateRW();
|
|
var resourceNodeId = jobState.Harvester.ResourceNodeId;
|
|
|
|
if (!_world.RawResources.Exists(resourceNodeId)) return IntentExecutionResult.Failure;
|
|
|
|
_signalBus.Raise(new RawResourceHarvestedSignal(resourceNodeId));
|
|
|
|
return IntentExecutionResult.Success;
|
|
}
|
|
}
|
|
}
|