diff --git a/Assets/Scripts/Infrastructure/Unity/GameBootstrap.cs b/Assets/Scripts/Infrastructure/Unity/GameBootstrap.cs index 50a9a99..7df909e 100644 --- a/Assets/Scripts/Infrastructure/Unity/GameBootstrap.cs +++ b/Assets/Scripts/Infrastructure/Unity/GameBootstrap.cs @@ -213,9 +213,22 @@ namespace Infrastructure.Unity private void SpawnNpc() { - var spawnPos = new Vector3(levelGenerator.GridSizeX / 2f, 7f, levelGenerator.GridSizeY / 2f); + var validTiles = _allTiles.FindAll(t => t.Floor == 0 && t.CurrentState == TileState.Stable); - // 30% chance for Hunter if player available + if (validTiles.Count == 0) + { + validTiles = _allTiles.FindAll(t => t.CurrentState == TileState.Stable); + } + + if (validTiles.Count == 0) return; + + var randomTile = validTiles[Random.Range(0, validTiles.Count)]; + + if (!_tileViews.TryGetValue(randomTile.Id, out var tileView)) return; + if (!tileView) return; + + var spawnPos = tileView.transform.position + Vector3.up * 5f; + if (_playerInstance && hunterNpcPrefab && Random.value < 0.3f) { var hunter = Instantiate(hunterNpcPrefab, spawnPos, Quaternion.identity);