riversong code showcase
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user