Files
riversong-code-showcase/Source/Riversong/Game/World/Agents/Critters/CritterHerdMoveCenterSystem.cs
2026-05-21 16:04:49 +02:00

37 lines
1.1 KiB
C#

using Random = UnityEngine.Random;
namespace DanieleMarotta.RiversongCodeShowcase
{
[GameSystemGroup(typeof(DefaultAgentsSystemGroup))]
public class CritterHerdMoveCenterSystem : GameSystem, IUpdatable
{
[InjectService]
private IEntityCollection _entityCollection;
[InjectService]
private World _world;
[InjectService]
private ISignalBus _signalBus;
public CritterHerdMoveCenterSystem(IServiceLocator serviceLocator) : base(serviceLocator)
{
}
public void Update()
{
foreach (CritterHerd herd in _entityCollection.GetInternalEntityList(typeof(CritterHerd)))
{
if (!_world.BlockMap.IsBlocked(herd.Center, BlockReason.BlocksAgents)) continue;
var oldCenter = herd.Center;
var moveDirection = ((Directions)Random.Range(0, 8)).ToVector();
var center = oldCenter + 4 * moveDirection;
if (!_world.Contains(center) || _world.BlockMap.IsBlocked(center, BlockReason.BlocksAgents)) continue;
herd.Center = center;
}
}
}
}