Răsfoiți Sursa

关卡优化

181404010226 4 luni în urmă
părinte
comite
ace2bd133d

+ 3 - 3
assets/Scenes/GameLevel.scene

@@ -14462,7 +14462,7 @@
         "__id__": 441
       }
     ],
-    "_active": false,
+    "_active": true,
     "_components": [
       {
         "__id__": 449
@@ -14477,7 +14477,7 @@
     "_prefab": null,
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": 5.684341886080802e-14,
+      "x": 0,
       "y": 0,
       "z": 0
     },
@@ -19136,7 +19136,7 @@
         "__id__": 535
       }
     ],
-    "_active": true,
+    "_active": false,
     "_components": [
       {
         "__id__": 588

+ 19 - 7
assets/scripts/CombatSystem/Wall.ts

@@ -238,7 +238,18 @@ export class Wall extends Component {
         const actualNewHp = this.getWallHealthByLevel(newLvl); // 使用当前等级的基础血量
 
         // 更新内存中的数值为当前等级的基础血量
+        const previousHealth = this.currentHealth;
         this.currentHealth = actualNewHp;
+        
+        // 触发墙体血量变化事件,标记为升级事件
+        const eventBus = EventBus.getInstance();
+        eventBus.emit(GameEvents.WALL_HEALTH_CHANGED, {
+            previousHealth: previousHealth,
+            currentHealth: this.currentHealth,
+            maxHealth: this.getMaxHealth(),
+            isUpgrade: true
+        });
+        
         this.updateHealthDisplay();
 
         return {
@@ -319,13 +330,14 @@ export class Wall extends Component {
      * 处理墙体血量变化事件(用于升级后更新)
      */
     private onWallHealthChangedEvent(eventData?: any) {
-        console.log('[Wall] 接收到墙体血量变化事件,重新加载血量数据');
-        
-        // 重新从存档加载墙体血量(升级后血量会更新)
-        this.loadWallHealthFromSave();
-        
-        // 更新显示
-        this.updateHealthDisplay();
+        // 只有在特定情况下才重新加载存档数据,避免覆盖受伤后的血量
+        // 如果事件数据包含isUpgrade标志,说明是升级触发的,需要重新加载
+        if (eventData && eventData.isUpgrade) {
+            console.log('[Wall] 接收到墙体升级事件,重新加载血量数据');
+            this.loadWallHealthFromSave();
+            this.updateHealthDisplay();
+        }
+        // 其他情况(如受伤、治疗)不需要重新加载存档,血量已经在相应方法中更新
     }
     
     /**

+ 7 - 28
assets/scripts/FourUI/MainSystem/MainUIControlller.ts

@@ -203,7 +203,7 @@ export class MainUIController extends Component {
         if (this.rewardMoneyNode) {
           const coinLabel = this.rewardMoneyNode.getComponent(Label) || this.rewardMoneyNode.getComponentInChildren(Label);
           if (coinLabel) {
-            coinLabel.string = rewards.coins.toString();
+            coinLabel.string = rewards.money.toString();
           }
         }
         
@@ -297,9 +297,7 @@ export class MainUIController extends Component {
   public onReturnToMainUI(): void {
     console.log('MainUIController.onReturnToMainUI 开始执行');
     
-    // 设置应用状态为主菜单
-    const gm = this.gameManagerNode?.getComponent(GameManager);
-    gm?.setAppState(AppState.MAIN_MENU);
+    // 注意:应用状态已在GameManager中设置,这里不需要重复设置
     
     // 隐藏 TopArea (Canvas-001)
     if (this.topArea) {
@@ -366,30 +364,11 @@ export class MainUIController extends Component {
     const currentLevel = this.sdm.getCurrentLevel();
     
     try {
-      // 获取游戏管理器以判断游戏状态
-      const gameManager = this.gameManagerNode?.getComponent(GameManager);
-      const currentGameState = gameManager?.getCurrentGameState();
-      const isGameSuccess = currentGameState === GameState.SUCCESS; // 使用游戏内状态枚举进行比较
-      
-      let rewards;
-      if (isGameSuccess) {
-        // 游戏成功,获取完整奖励
-        console.log('游戏成功,获取完整奖励');
-        rewards = this.sdm.getLastRewards();
-      } else {
-        // 游戏失败,直接获取已经计算好的失败奖励
-        console.log('游戏失败,获取已计算的部分奖励');
-        rewards = this.sdm.getLastRewards();
-        
-        // 记录波数完成情况用于调试
-        const currentWave = gameManager?.getCurrentWave() || 0;
-        const inGameManager = gameManager?.getInGameManager();
-        const totalWaves = inGameManager?.levelWaves?.length || 1;
-        const completedWaves = Math.max(0, currentWave - 1);
-        
-        console.log(`波数完成情况: ${completedWaves}/${totalWaves} = ${(completedWaves / totalWaves * 100).toFixed(1)}%`);
-        console.log('计算出的失败奖励:', rewards);
-      }
+      // 直接获取SaveDataManager中已经计算好的奖励数据
+      // 注意:不再依赖当前游戏状态判断,因为游戏数据清理可能已经重置了状态
+      // SaveDataManager.getLastRewards()已经包含了正确的奖励信息(成功或失败奖励)
+      const rewards = this.sdm.getLastRewards();
+      console.log('获取已计算的奖励:', rewards);
       
       if (rewards && (rewards.money > 0 || rewards.diamonds > 0)) {
         // 使用MoneyAni播放奖励动画

+ 28 - 34
assets/scripts/LevelSystem/GameManager.ts

@@ -485,32 +485,8 @@ export class GameManager extends Component {
         this.saveDataManager.updateStatistic('totalEnemiesDefeated', this.totalEnemiesSpawned);
     }
     
-    /**
-     * 清除上一关的成功或失败记录
-     */
-    private clearPreviousGameRecord() {
-        console.log('[GameManager] 清除上一关的游戏记录');
-        
-        // 重置游戏时间记录
-        this.gameStartTime = 0;
-        this.gameEndTime = 0;
-        
-        // 重置敌人击杀统计
-        this.totalEnemiesSpawned = 0;
-        
-        // 通过InGameManager重置游戏状态记录
-        const inGameManager = this.getInGameManager();
-        if (inGameManager) {
-            // 重置InGameManager中的游戏状态
-            inGameManager.resetGameRecord();
-            console.log('[GameManager] InGameManager游戏记录已重置');
-        }
-        
-        console.log('[GameManager] 上一关游戏记录清除完成');
-        
-        // 兼容原有的LevelManager(已移除错误的currentLevel引用)
-        // 注意:LevelManager的相关逻辑已迁移到SaveDataManager
-    }
+    // clearPreviousGameRecord方法已被移除,其功能已整合到onMainMenuClick中
+    // 避免重复清理游戏数据
     
     // === 计算游戏时长 ===
     private getGameDuration(): number {
@@ -541,11 +517,17 @@ export class GameManager extends Component {
     private onMainMenuClick() {
         console.log('[GameManager] 返回主菜单');
         
-        // 1. 无论游戏状态如何,都进行清理(游戏结束时只是暂停,需要在此时清理)
+        // 1. 获取当前游戏状态,判断是否为获胜状态
         const inGameManager = this.getInGameManager();
         const currentGameState = inGameManager?.getCurrentState();
+        const isGameSuccess = currentGameState === GameState.SUCCESS;
         
         console.log(`[GameManager] 当前游戏状态:${currentGameState},开始清理游戏数据`);
+        console.log(`[GameManager] GameState.SUCCESS值:${GameState.SUCCESS}`);
+        console.log(`[GameManager] 状态比较结果 isGameSuccess:${isGameSuccess}`);
+        console.log(`[GameManager] 严格比较:${currentGameState} === ${GameState.SUCCESS} = ${currentGameState === GameState.SUCCESS}`);
+        
+        // 2. 统一进行游戏数据清理(只调用一次,避免重复清理)
         if (inGameManager) {
             console.log('[GameManager] 触发游戏数据清理');
             inGameManager.triggerGameDataCleanup();
@@ -553,20 +535,32 @@ export class GameManager extends Component {
             console.warn('[GameManager] 未找到InGameManager,跳过游戏数据清理');
         }
         
-        // 2. 发送重置UI状态事件,让UIStateManager统一关闭所有相关面板
+        // 3. 发送重置UI状态事件,让UIStateManager统一关闭所有相关面板
         const eventBus = EventBus.getInstance();
         eventBus.emit(GameEvents.RESET_UI_STATES);
         
-        // 3. 清除上一关的成功或失败记录
-        this.clearPreviousGameRecord();
+        // 4. 重置GameManager自身的记录(不调用InGameManager的重复清理)
+        this.gameStartTime = 0;
+        this.gameEndTime = 0;
+        this.totalEnemiesSpawned = 0;
+        console.log('[GameManager] GameManager记录已重置');
         
-        // 4. 重置关卡到第1关(解决能量条未重置和下次战斗变成下一关的问题)
+        // 5. 根据游戏结果决定关卡处理:获胜时进入下一关,失败时保持当前关
         if (this.saveDataManager) {
-            this.saveDataManager.setCurrentLevel(1);
-            console.log('[GameManager] 关卡已重置为第1关');
+            if (isGameSuccess) {
+                // 获胜后进入下一关
+                const currentLevel = this.saveDataManager.getCurrentLevel();
+                const nextLevel = currentLevel + 1;
+                this.saveDataManager.setCurrentLevel(nextLevel);
+                console.log(`[GameManager] 游戏获胜,从第${currentLevel}关进入第${nextLevel}关`);
+            } else {
+                // 失败时保持当前关卡,不重置
+                const currentLevel = this.saveDataManager.getCurrentLevel();
+                console.log(`[GameManager] 游戏失败,保持当前关卡: ${currentLevel}`);
+            }
         }
         
-        // 5. 重置应用状态为主菜单
+        // 6. 重置应用状态为主菜单
         this.currentAppState = AppState.MAIN_MENU;
         console.log('[GameManager] 应用状态已重置为MAIN_MENU');
         

+ 2 - 36
assets/scripts/LevelSystem/IN_game.ts

@@ -978,42 +978,8 @@ export class InGameManager extends Component {
         console.log('[InGameManager] 游戏状态重置完成');
     }
     
-    /**
-     * 重置游戏记录(供GameManager调用)
-     * 清除上一关的成功或失败记录
-     */
-    public resetGameRecord() {
-        console.log('[InGameManager] 重置游戏记录');
-        
-        // 重置游戏状态为初始状态
-        this.currentState = GameState.PLAYING;
-        
-        // 重置时间记录
-        this.gameStartTime = 0;
-        this.gameEndTime = 0;
-        
-        // 重置波次和敌人统计
-        this.currentWave = 1;
-        this.currentWaveEnemyCount = 0;
-        this.currentWaveTotalEnemies = 0;
-        this.enemiesKilled = 0;
-        this.totalEnemiesSpawned = 0;
-        this.levelTotalEnemies = 0;
-        
-        // 重置游戏标志
-        this.gameStarted = false;
-        this.enemySpawningStarted = false;
-        this.preparingNextWave = false;
-        this.pendingSkillSelection = false;
-        this.pendingBlockSelection = false;
-        this.shouldShowNextWavePrompt = false;
-        
-        // 重置能量系统
-        this.energyPoints = 0;
-        this.updateEnergyBar();
-        
-        console.log('[InGameManager] 游戏记录重置完成');
-    }
+    // resetGameRecord方法已被移除,避免与cleanupGameDataForMainMenu重复
+    // 所有清理逻辑已统一在cleanupGameDataForMainMenu中处理
 
     /**
      * 手动触发游戏数据清理(供外部调用)

+ 28 - 15
assets/scripts/LevelSystem/SaveDataManager.ts

@@ -905,7 +905,7 @@ export class SaveDataManager {
     /**
      * 从JSON配置文件获取关卡奖励数据
      */
-    public async getLevelRewardsFromConfig(levelId: number): Promise<{coins: number, diamonds: number} | null> {
+    public async getLevelRewardsFromConfig(levelId: number): Promise<{money: number, diamonds: number} | null> {
         try {
             // 由于不支持动态导入,改为直接导入
             const configManager = LevelConfigManager.getInstance();
@@ -919,7 +919,7 @@ export class SaveDataManager {
             if (levelConfig && levelConfig.levelSettings && (levelConfig.levelSettings as any).rewards) {
                 const rewards = (levelConfig.levelSettings as any).rewards;
                 return {
-                    coins: rewards.coins || 0,
+                    money: rewards.coins || 0,
                     diamonds: rewards.diamonds || 0
                 };
             }
@@ -937,7 +937,7 @@ export class SaveDataManager {
                      const jsonData = asset.json;
                      if (jsonData && jsonData.rewards) {
                          resolve({
-                             coins: jsonData.rewards.coins || 0,
+                             money: jsonData.rewards.coins || 0,
                              diamonds: jsonData.rewards.diamonds || 0
                          });
                      } else {
@@ -964,9 +964,9 @@ export class SaveDataManager {
         
         if (configRewards) {
             // 使用JSON配置中的奖励数据
-            if (configRewards.coins > 0) {
-                this.addMoney(configRewards.coins, `level_${levelId}_complete`);
-                actualCoins = configRewards.coins;
+            if (configRewards.money > 0) {
+                this.addMoney(configRewards.money, `level_${levelId}_complete`);
+                actualCoins = configRewards.money;
             }
             if (configRewards.diamonds > 0) {
                 this.addDiamonds(configRewards.diamonds, `level_${levelId}_complete`);
@@ -987,32 +987,41 @@ export class SaveDataManager {
      * 根据波数比例给予失败奖励
      */
     public async giveFailureRewards(levelId: number, completedWaves: number, totalWaves: number): Promise<void> {
-        if (completedWaves <= 0 || totalWaves <= 0) {
-            // 重置最近奖励为0
+        console.log(`[SaveDataManager] 计算失败奖励 - 关卡: ${levelId}, 完成波数: ${completedWaves}/${totalWaves}`);
+        
+        if (totalWaves <= 0) {
+            console.warn('[SaveDataManager] 总波数无效,重置奖励为0');
             this.lastRewards = {money: 0, diamonds: 0};
             return;
         }
         
+        // 即使completedWaves为0,也给予最低奖励(10%的基础奖励)
+        const minRewardRatio = 0.1; // 最低奖励比例
+        const actualCompletedWaves = Math.max(completedWaves, 0);
+        const waveRatio = Math.max(minRewardRatio, actualCompletedWaves / totalWaves);
+        
+        console.log(`[SaveDataManager] 波数完成情况: ${actualCompletedWaves}/${totalWaves} = ${(waveRatio * 100).toFixed(1)}%`);
+        
         // 获取完整奖励数据
         const configRewards = await this.getLevelRewardsFromConfig(levelId);
         
-        // 计算波数完成比例
-        const waveRatio = Math.min(completedWaves / totalWaves, 1.0);
-        
         let actualCoins = 0;
         let actualDiamonds = 0;
         
         if (configRewards) {
             // 基于JSON配置计算比例奖励(取整)
-            const partialCoins = Math.floor(configRewards.coins * waveRatio);
+            const partialCoins = Math.floor(configRewards.money * waveRatio);
             const partialDiamonds = Math.floor(configRewards.diamonds * waveRatio);
             
+            console.log(`[SaveDataManager] 基于配置计算奖励 - 原始金币: ${configRewards.money}, 原始钻石: ${configRewards.diamonds}`);
+            console.log(`[SaveDataManager] 计算出的失败奖励 - 金币: ${partialCoins}, 钻石: ${partialDiamonds}`);
+            
             if (partialCoins > 0) {
-                this.addMoney(partialCoins, `level_${levelId}_partial_${completedWaves}/${totalWaves}`);
+                this.addMoney(partialCoins, `level_${levelId}_partial_${actualCompletedWaves}/${totalWaves}`);
                 actualCoins = partialCoins;
             }
             if (partialDiamonds > 0) {
-                this.addDiamonds(partialDiamonds, `level_${levelId}_partial_${completedWaves}/${totalWaves}`);
+                this.addDiamonds(partialDiamonds, `level_${levelId}_partial_${actualCompletedWaves}/${totalWaves}`);
                 actualDiamonds = partialDiamonds;
             }
         } else {
@@ -1020,12 +1029,16 @@ export class SaveDataManager {
             const baseCoins = levelId * 50;
             const partialCoins = Math.floor(baseCoins * waveRatio);
             
+            console.log(`[SaveDataManager] 使用默认计算 - 基础金币: ${baseCoins}, 计算出的失败奖励: ${partialCoins}`);
+            
             if (partialCoins > 0) {
-                this.addMoney(partialCoins, `level_${levelId}_partial_${completedWaves}/${totalWaves}`);
+                this.addMoney(partialCoins, `level_${levelId}_partial_${actualCompletedWaves}/${totalWaves}`);
                 actualCoins = partialCoins;
             }
         }
         
+        console.log(`[SaveDataManager] 最终失败奖励 - 金币: ${actualCoins}, 钻石: ${actualDiamonds}`);
+        
         // 存储最近的奖励记录
         this.lastRewards = {money: actualCoins, diamonds: actualDiamonds};
     }