Separate Bomb Logic
This commit is contained in:
@@ -181,7 +181,6 @@ namespace Services {
|
||||
}
|
||||
|
||||
private async UniTask DestroyMatchesAsync(List<Vector2Int> protectedPositions) {
|
||||
// Collect match positions, excluding protected (bomb creation slots).
|
||||
List<Vector2Int> matchPositions = new List<Vector2Int>(this.matchService.CurrentMatches.Count);
|
||||
for (int i = 0; i < this.matchService.CurrentMatches.Count; i++) {
|
||||
var m = this.matchService.CurrentMatches[i];
|
||||
@@ -194,13 +193,12 @@ namespace Services {
|
||||
matchPositions.Add(pos);
|
||||
}
|
||||
|
||||
// Bombs are handled by BombService so they can respect delays + chaining.
|
||||
foreach (Vector2Int pos in matchPositions.Distinct().ToList()) {
|
||||
var g = GetGem(pos);
|
||||
if (g == null) continue;
|
||||
if (g.Type == GemType.Bomb) continue;
|
||||
Gem gem = GetGem(pos);
|
||||
if (gem == null) continue;
|
||||
if (gem.Type == GemType.Bomb) continue;
|
||||
|
||||
this.scoreService.ScoreCheck(g.ScoreValue);
|
||||
this.scoreService.ScoreCheck(gem.ScoreValue);
|
||||
DestroyMatchedGems(pos);
|
||||
}
|
||||
|
||||
@@ -209,22 +207,17 @@ namespace Services {
|
||||
List<Vector2Int> initialBombs = new List<Vector2Int>();
|
||||
foreach (Vector2Int p in bombCandidates) {
|
||||
if (!InBounds(p)) continue;
|
||||
var g = GetGem(p);
|
||||
if (g is { Type: GemType.Bomb })
|
||||
|
||||
if (protectedPositions != null && protectedPositions.Contains(p))
|
||||
continue;
|
||||
|
||||
Gem gem = GetGem(p);
|
||||
if (gem is { Type: GemType.Bomb })
|
||||
initialBombs.Add(p);
|
||||
}
|
||||
initialBombs = initialBombs.Distinct().ToList();
|
||||
|
||||
await this.bombService.DetonateChainAsync(
|
||||
initialBombs,
|
||||
InBounds,
|
||||
GetGem,
|
||||
DestroyAtAsync,
|
||||
this.gameVariables.bombRadius,
|
||||
this.gameVariables.bombDelay,
|
||||
this.gameVariables.bombSelfDelay
|
||||
);
|
||||
|
||||
await this.bombService.DetonateChainAsync(initialBombs, InBounds, GetGem, DestroyAtAsync, this.gameVariables.bombRadius, this.gameVariables.bombDelay, this.gameVariables.bombSelfDelay);
|
||||
await MoveGemsDown();
|
||||
}
|
||||
|
||||
@@ -238,16 +231,6 @@ namespace Services {
|
||||
return UniTask.CompletedTask;
|
||||
}
|
||||
|
||||
private static IEnumerable<Vector2Int> CrossNeighbors(Vector2Int center, int radius) {
|
||||
// center excluded for "neighbors first"
|
||||
for (int i = 1; i <= radius; i++) {
|
||||
yield return center + Vector2Int.left * i;
|
||||
yield return center + Vector2Int.right * i;
|
||||
yield return center + Vector2Int.up * i;
|
||||
yield return center + Vector2Int.down * i;
|
||||
}
|
||||
}
|
||||
|
||||
private async UniTask MoveGemsDown() {
|
||||
await UniTask.Delay(50);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user