Procházet zdrojové kódy

解决波次问题

181404010226 před 4 měsíci
rodič
revize
70819452ff
1 změnil soubory, kde provedl 44 přidání a 21 odebrání
  1. 44 21
      assets/scripts/LevelSystem/IN_game.ts

+ 44 - 21
assets/scripts/LevelSystem/IN_game.ts

@@ -352,28 +352,33 @@ export class InGameManager extends Component {
         let hasActiveEnemies = false;
         EventBus.getInstance().emit(GameEvents.ENEMY_CHECK_ACTIVE, (active: boolean) => {
             hasActiveEnemies = active;
-        });
-        
-        const isWaveEnd = remaining <= 0 && !hasActiveEnemies;
-        
-        const energyBeforeIncrement = this.energyPoints;
-        this.incrementEnergy();
-        
-        const energyWillBeFull = energyBeforeIncrement + 1 >= this.energyMax;
-        
-        if (isWaveEnd) {
-            if (energyWillBeFull) {
-                this.pendingBlockSelection = true;
-                this.preparingNextWave = true;
-                this.currentState = GameState.BLOCK_SELECTION;
-            } else {
-                if (this.currentWave < (this.levelWaves?.length || 1)) {
-                    this.showNextWavePrompt();
+            
+            // 在回调中检查波次是否结束
+            const isWaveEnd = remaining <= 0 && !hasActiveEnemies;
+            
+            if (isWaveEnd) {
+                console.log(`[InGameManager] 波次结束检测: remaining=${remaining}, hasActiveEnemies=${hasActiveEnemies}`);
+                
+                const energyBeforeIncrement = this.energyPoints;
+                this.incrementEnergy();
+                
+                const energyWillBeFull = energyBeforeIncrement + 1 >= this.energyMax;
+                
+                if (energyWillBeFull) {
+                    this.pendingBlockSelection = true;
+                    this.preparingNextWave = true;
+                    this.currentState = GameState.BLOCK_SELECTION;
                 } else {
-                    this.triggerGameSuccess();
+                    if (this.currentWave < (this.levelWaves?.length || 1)) {
+                        this.showNextWavePrompt();
+                    } else {
+                        this.triggerGameSuccess();
+                    }
                 }
             }
-        }
+        });
+        
+        // 能量增加逻辑移到了回调函数中,这里不再需要重复处理
     }
 
     /**
@@ -396,6 +401,13 @@ export class InGameManager extends Component {
      * 显示下一波提示
      */
     private showNextWavePrompt() {
+        // 设置准备下一波的状态
+        this.preparingNextWave = true;
+        this.pendingBlockSelection = true;
+        this.currentState = GameState.BLOCK_SELECTION;
+        
+        console.log('[InGameManager] 设置准备下一波状态,准备显示方块选择UI');
+        
         // 如果当前没有技能选择UI显示,立即显示方块选择UI
         if (!this.selectSkillUI || !this.selectSkillUI.active) {
             this.showBlockSelectionForNextWave();
@@ -736,6 +748,17 @@ export class InGameManager extends Component {
     public handleConfirmAction() {
         console.log('[InGameManager] 处理方块选择确认操作');
         
+        // 如果是在准备下一波的状态,需要先切换到下一波
+        if (this.preparingNextWave) {
+            console.log('[InGameManager] 检测到准备下一波状态,切换到下一波');
+            this.nextWave();
+            
+            // 重置状态
+            this.preparingNextWave = false;
+            this.pendingBlockSelection = false;
+            this.currentState = GameState.PLAYING;
+        }
+        
         // 发送游戏开始事件,确保GamePause正确设置状态
         EventBus.getInstance().emit(GameEvents.GAME_START);
         console.log('[InGameManager] 发送GAME_START事件');
@@ -744,10 +767,10 @@ export class InGameManager extends Component {
         EventBus.getInstance().emit(GameEvents.BALL_START);
         console.log('[InGameManager] 发送BALL_START事件,球已启动');
         
-        // 通过事件系统开始当前波次的敌人生成(不更新波次)
+        // 通过事件系统开始当前波次的敌人生成
         EventBus.getInstance().emit(GameEvents.ENEMY_START_GAME);
         EventBus.getInstance().emit(GameEvents.ENEMY_SHOW_START_WAVE_PROMPT);
-        console.log('[InGameManager] 当前波次敌人生成已启动');
+        console.log(`[InGameManager] 波次 ${this.currentWave} 敌人生成已启动`);
     }
     
     /**