public void TryMoveToBiome(TileProperties tileToGo) { if (tileToGo.Coordinates.Distance(entity.Tile.Coordinates) <= range) { return; } List <TileProperties> inRange = tileToGo.InRange(range); inRange.Shuffle(); foreach (TileProperties tile in inRange) { if ((!goOnTile && tile == tileToGo) || !tile.Tile || !tile.IsWalkable() || tile.asLake || tile.windOrigin) { continue; } entity.MoveTo(tile, null); break; } }
public override void Act(StateController controller) { MovingEntity entity = controller.entity as MovingEntity; var nearestEntity = entity.Tile.NearestEntity(entity.movingEntitySO.foods.ToArray(), -1); if (nearestEntity) { bool targetIsStatic = !nearestEntity.movingEntity || nearestEntity.movingEntity == entity; Entity target; int distanceOfHarvest; if (targetIsStatic) { distanceOfHarvest = 0; target = nearestEntity.staticEntity; } else { distanceOfHarvest = 1; target = nearestEntity.movingEntity; } int distance = target.Tile.Coordinates.Distance(entity.Tile.Coordinates); bool rightDistance = distance <= distanceOfHarvest; if (!entity.hasFled && !rightDistance) { entity.MoveTo(nearestEntity, () => TryHarvest(entity, target, distanceOfHarvest)); } else if (rightDistance) { entity.isHungry = false; TryHarvest(entity, target, distanceOfHarvest); } } else { DecreasePop(entity); } }