From 3956a6ffab630e7ec75d0cdb3de674b87011358e Mon Sep 17 00:00:00 2001 From: Jesus Castro Date: Thu, 18 Dec 2025 14:38:57 +0800 Subject: [PATCH] Update BombService.cs - Matched bombs now explode one at a time --- Assets/Scripts/Services/BombService.cs | 86 ++++++++++---------------- 1 file changed, 33 insertions(+), 53 deletions(-) diff --git a/Assets/Scripts/Services/BombService.cs b/Assets/Scripts/Services/BombService.cs index 89a5af0..502a479 100644 --- a/Assets/Scripts/Services/BombService.cs +++ b/Assets/Scripts/Services/BombService.cs @@ -118,75 +118,55 @@ namespace Services while (waveQueue.Count > 0) { - // current wave (per bomb) - List waveBombs = new List(); - while (waveQueue.Count > 0) - { - Vector2Int b = waveQueue.Dequeue(); - if (processedBombs.Contains(b)) - continue; + Vector2Int bombPos = waveQueue.Dequeue(); - if (!GemUtils.IsInBounds(b, gameBoard)) - continue; - - Gem g = gameBoard.GetGemAt(b); - if (g is not { Type: GemType.Bomb }) - continue; - - processedBombs.Add(b); - waveBombs.Add(b); - } - - if (waveBombs.Count == 0) + if (processedBombs.Contains(bombPos)) continue; - // delay once per wave - if (waveDelayMs > 0) - await UniTask.Delay(waveDelayMs); + if (!GemUtils.IsInBounds(bombPos, gameBoard)) + continue; - HashSet nextWaveBombs = new HashSet(); + Gem g = gameBoard.GetGemAt(bombPos); + if (g is not { Type: GemType.Bomb }) + continue; + + processedBombs.Add(bombPos); + + // delay once per bomb + await UniTask.Delay(waveDelayMs); HashSet toDestroyNow = new HashSet(); - for (int i = 0; i < waveBombs.Count; i++) + // destroy self when it detonates + toDestroyNow.Add(bombPos); + + foreach (Vector2Int position in DiamondAreaInclusive(bombPos, this.gameVariables.bombRadius)) { - Vector2Int bombPos = waveBombs[i]; + if (!GemUtils.IsInBounds(position, gameBoard)) + continue; - // destroy self when it detonates - toDestroyNow.Add(bombPos); + if (position == bombPos) + continue; - foreach (Vector2Int p in DiamondAreaInclusive(bombPos, this.gameVariables.bombRadius)) + Gem cellGem = gameBoard.GetGemAt(position); + if (cellGem == null) + continue; + + if (cellGem.Type == GemType.Bomb) { - if (!GemUtils.IsInBounds(p, gameBoard)) - continue; + // bombs in range are NOT destroyed now. triggered to explode in a later "step". + if (!processedBombs.Contains(position)) + waveQueue.Enqueue(position); - if (p == bombPos) - continue; - - Gem cellGem = gameBoard.GetGemAt(p); - if (cellGem == null) - continue; - - if (cellGem.Type == GemType.Bomb) - { - // bombs in range are NOT destroyed now. triggered to explode in a later wave. - if (!processedBombs.Contains(p)) - nextWaveBombs.Add(p); - - continue; - } - - // Non-bomb gem gets destroyed by this bomb - toDestroyNow.Add(p); + continue; } + + // Non-bomb gem gets destroyed by this bomb + toDestroyNow.Add(position); } - // Destroy everything for this wave (non-bombs in range and the detonating bombs themselves) + // Destroy everything for this specific bomb detonation foreach (Vector2Int p in toDestroyNow) await destroyAtAsync(p); - - // Schedule the next wave (triggered bombs) - foreach (Vector2Int b in nextWaveBombs) - waveQueue.Enqueue(b); } }