diff --git a/lib/src/features/game/game_play_screen.dart b/lib/src/features/game/game_play_screen.dart index cebc40b..4429437 100644 --- a/lib/src/features/game/game_play_screen.dart +++ b/lib/src/features/game/game_play_screen.dart @@ -255,6 +255,7 @@ class _GamePlayScreenState extends State /// TaskType 기반 BGM 전환 (애니메이션과 동기화) /// /// 애니메이션은 TaskType으로 결정되므로, BGM도 동일한 기준 사용 + /// 전환 감지 외에도 현재 BGM이 TaskType과 일치하는지 검증 void _updateBgmForTaskType(GameState state) { final audio = widget.audioService; if (audio == null) return; @@ -262,19 +263,20 @@ class _GamePlayScreenState extends State final taskType = state.progress.currentTask.type; final isInBattleTask = taskType == TaskType.kill; - if (isInBattleTask && !_wasInBattleTask) { - // 전투 태스크 시작: 보스 여부에 따라 BGM 선택 + // 전투 태스크 상태 결정 + if (isInBattleTask) { + // 전투 태스크: 보스 여부에 따라 BGM 선택 final monsterLevel = state.progress.currentTask.monsterLevel ?? 0; final playerLevel = state.traits.level; final isBoss = monsterLevel >= playerLevel + 5; + final expectedBgm = isBoss ? 'boss' : 'battle'; - if (isBoss) { - audio.playBgm('boss'); - } else { - audio.playBgm('battle'); + // 전환 시점이거나 현재 BGM이 일치하지 않으면 재생 + if (!_wasInBattleTask || audio.currentBgm != expectedBgm) { + audio.playBgm(expectedBgm); } - } else if (!isInBattleTask && _wasInBattleTask) { - // 전투 태스크 종료: 마을 BGM으로 복귀 + } else if (_wasInBattleTask || audio.currentBgm == 'battle' || audio.currentBgm == 'boss') { + // 전투 태스크 종료 또는 BGM 불일치: 마을 BGM으로 복귀 audio.playBgm('town'); } @@ -675,6 +677,7 @@ class _GamePlayScreenState extends State MaterialPageRoute( builder: (_) => GamePlayScreen( controller: widget.controller, + audioService: widget.audioService, currentThemeMode: widget.currentThemeMode, onThemeModeChange: widget.onThemeModeChange, ), @@ -784,6 +787,7 @@ class _GamePlayScreenState extends State MaterialPageRoute( builder: (_) => GamePlayScreen( controller: widget.controller, + audioService: widget.audioService, currentThemeMode: widget.currentThemeMode, onThemeModeChange: widget.onThemeModeChange, ),