riversong code showcase

This commit is contained in:
Daniele Marotta
2026-05-21 15:52:18 +02:00
commit 4c9eea1c02
462 changed files with 23406 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
using Cysharp.Threading.Tasks;
using Random = UnityEngine.Random;
namespace DanieleMarotta.RiversongCodeShowcase
{
public class HarvestFertileTileIntentExecutionLogic : IntentExecutionLogic
{
private IEntityCollection _entityCollection;
private IProductStackFactory _productStackFactory;
private World _world;
private ITileSpace _tileSpace;
public override UniTask InitializeAsync(IServiceLocator serviceLocator)
{
_entityCollection = serviceLocator.GetService<IEntityCollection>();
_productStackFactory = serviceLocator.GetService<IProductStackFactory>();
_world = serviceLocator.GetService<World>();
_tileSpace = serviceLocator.GetService<ITileSpace>();
return UniTask.CompletedTask;
}
public override IntentExecutionResult Execute(Agent agent, in AgentIntent intent)
{
if (!_entityCollection.TryGet<Building>(agent.HomeId, out var farm)) return IntentExecutionResult.Failure;
var tile = _tileSpace.WorldToTile(agent.Position);
ref var fertility = ref _world.Fertility.GetValueRW(tile);
fertility.CurrentFertility = 0;
var product = farm.Definition.FarmProduct;
var amount = Random.Range(farm.Definition.MinDroppedAmount, farm.Definition.MaxDroppedAmount + 1);
_productStackFactory.CreateOrMerge(tile, product, amount);
return IntentExecutionResult.Success;
}
}
}