Эх сурвалжийг харах

Merge branch '金币配置'

181404010226 3 сар өмнө
parent
commit
4e4d4339bb

BIN
assets/resources/data/excel/关卡配置/关卡配置表.xlsx


+ 1 - 0
assets/resources/data/levels/Level1.json

@@ -12,6 +12,7 @@
   ],
   "coinReward": 300,
   "diamondReward": 20,
+  "initialCoins": 50,
   "timeLimit": 300,
   "difficulty": "normal",
   "healthMultiplier": 1.0,

+ 1 - 0
assets/resources/data/levels/Level2.json

@@ -12,6 +12,7 @@
   ],
   "coinReward": 500,
   "diamondReward": 30,
+  "initialCoins": 60,
   "timeLimit": 300,
   "difficulty": "normal",
   "healthMultiplier": 1.2,

+ 1 - 0
assets/resources/data/levels/Level3.json

@@ -12,6 +12,7 @@
   ],
   "coinReward": 800,
   "diamondReward": 50,
+  "initialCoins": 70,
   "timeLimit": 300,
   "difficulty": "normal",
   "healthMultiplier": 1.4,

+ 1 - 0
assets/resources/data/levels/Level4.json

@@ -16,6 +16,7 @@
   ],
   "coinReward": 1000,
   "diamondReward": 80,
+  "initialCoins": 80,
   "timeLimit": 300,
   "difficulty": "normal",
   "healthMultiplier": 1.6,

+ 1 - 0
assets/resources/data/levels/Level5.json

@@ -16,6 +16,7 @@
   ],
   "coinReward": 1300,
   "diamondReward": 100,
+  "initialCoins": 90,
   "timeLimit": 300,
   "difficulty": "normal",
   "healthMultiplier": 1.8,

+ 1 - 0
assets/resources/data/levels/Level6.json

@@ -16,6 +16,7 @@
   ],
   "coinReward": 1800,
   "diamondReward": 120,
+  "initialCoins": 100,
   "timeLimit": 300,
   "difficulty": "normal",
   "healthMultiplier": 2.0,

+ 1 - 0
assets/resources/data/levels/Level7.json

@@ -16,6 +16,7 @@
   ],
   "coinReward": 2200,
   "diamondReward": 150,
+  "initialCoins": 110,
   "timeLimit": 300,
   "difficulty": "normal",
   "healthMultiplier": 2.2,

+ 1 - 0
assets/resources/data/levels/Level8.json

@@ -16,6 +16,7 @@
   ],
   "coinReward": 2500,
   "diamondReward": 170,
+  "initialCoins": 120,
   "timeLimit": 300,
   "difficulty": "normal",
   "healthMultiplier": 2.4,

+ 1 - 0
assets/resources/data/levels/Level9.json

@@ -17,6 +17,7 @@
   ],
   "coinReward": 3000,
   "diamondReward": 200,
+  "initialCoins": 130,
   "timeLimit": 300,
   "difficulty": "normal",
   "healthMultiplier": 2.6,

+ 85 - 85
assets/scripts/CombatSystem/BlockSelection/GameBlockSelection.ts

@@ -122,7 +122,7 @@ export class GameBlockSelection extends Component {
             // 如果已经初始化,重新设置事件监听器(因为onDisable时会移除)
             this.setupEventListeners();
         }
-        this.initDebugDraw();
+        // this.initDebugDraw();
     }
 
     start() {
@@ -644,7 +644,7 @@ export class GameBlockSelection extends Component {
             );
             
             // 更新调试绘制
-            this.updateDebugDraw();
+            // this.updateDebugDraw();
         }, this);
         
         block.on(Node.EventType.TOUCH_END, async (event: EventTouch) => {
@@ -677,7 +677,7 @@ export class GameBlockSelection extends Component {
                 if (collider) collider.enabled = true;
                 
                 // 更新调试绘制
-                this.updateDebugDraw();
+                // this.updateDebugDraw();
             }
         }, this);
         
@@ -694,7 +694,7 @@ export class GameBlockSelection extends Component {
                 if (collider) collider.enabled = true;
                 
                 // 更新调试绘制
-                this.updateDebugDraw();
+                // this.updateDebugDraw();
             }
         }, this);
     }
@@ -987,94 +987,94 @@ export class GameBlockSelection extends Component {
     
     // 初始化调试绘制
     private initDebugDraw() {
-        if (!this.debugDrawSnapRange) return;
-        
-        // 创建调试绘制节点
-        this.debugDrawNode = new Node('DebugDraw');
-        this.debugGraphics = this.debugDrawNode.addComponent(Graphics);
-        
-        // 将调试绘制节点添加到场景中
-        if (this.gridContainer && this.gridContainer.parent) {
-            this.gridContainer.parent.addChild(this.debugDrawNode);
-        }
-        
-        console.log('[GameBlockSelection] 调试绘制初始化完成');
+        // if (!this.debugDrawSnapRange) return;
+        // 
+        // // 创建调试绘制节点
+        // this.debugDrawNode = new Node('DebugDraw');
+        // this.debugGraphics = this.debugDrawNode.addComponent(Graphics);
+        // 
+        // // 将调试绘制节点添加到场景中
+        // if (this.gridContainer && this.gridContainer.parent) {
+        //     this.gridContainer.parent.addChild(this.debugDrawNode);
+        // }
+        // 
+        // console.log('[GameBlockSelection] 调试绘制初始化完成');
     }
     
     // 绘制网格吸附范围
     private drawGridSnapRanges() {
-        if (!this.debugDrawSnapRange || !this.debugGraphics || !this.blockManager) return;
-        
-        this.debugGraphics.strokeColor = Color.GREEN;
-        this.debugGraphics.lineWidth = 2;
-        
-        // 通过BlockManager获取网格信息来绘制吸附范围
-        const gridSpacing = this.blockManager.getGridSpacing(); // 动态获取网格间距
-        const snapRange = gridSpacing * 0.8; // 吸附范围
-        
-        // 遍历所有网格位置,绘制吸附范围
-        for (let row = 0; row < 6; row++) {
-            for (let col = 0; col < 11; col++) {
-                // 计算网格世界坐标
-                const gridWorldPos = this.blockManager.getGridWorldPosition(row, col);
-                if (!gridWorldPos) continue;
-                
-                // 转换为调试绘制节点的本地坐标
-                const localPos = new Vec3();
-                this.debugDrawNode.getComponent(UITransform).convertToNodeSpaceAR(gridWorldPos, localPos);
-                
-                // 绘制网格吸附范围圆圈
-                this.debugGraphics.circle(localPos.x, localPos.y, snapRange);
-                this.debugGraphics.stroke();
-            }
-        }
+        // if (!this.debugDrawSnapRange || !this.debugGraphics || !this.blockManager) return;
+        // 
+        // this.debugGraphics.strokeColor = Color.GREEN;
+        // this.debugGraphics.lineWidth = 2;
+        // 
+        // // 通过BlockManager获取网格信息来绘制吸附范围
+        // const gridSpacing = this.blockManager.getGridSpacing(); // 动态获取网格间距
+        // const snapRange = gridSpacing * 0.8; // 吸附范围
+        // 
+        // // 遍历所有网格位置,绘制吸附范围
+        // for (let row = 0; row < 6; row++) {
+        //     for (let col = 0; col < 11; col++) {
+        //         // 计算网格世界坐标
+        //         const gridWorldPos = this.blockManager.getGridWorldPosition(row, col);
+        //         if (!gridWorldPos) continue;
+        //         
+        //         // 转换为调试绘制节点的本地坐标
+        //         const localPos = new Vec3();
+        //         this.debugDrawNode.getComponent(UITransform).convertToNodeSpaceAR(gridWorldPos, localPos);
+        //         
+        //         // 绘制网格吸附范围圆圈
+        //         this.debugGraphics.circle(localPos.x, localPos.y, snapRange);
+        //         this.debugGraphics.stroke();
+        //     }
+        // }
     }
     
     // 绘制方块吸附范围
     private drawBlockSnapRange(block: Node) {
-        if (!this.debugDrawSnapRange || !this.debugGraphics || !block || !this.blockManager) return;
-        
-        // 绘制方块吸附点
-        this.debugGraphics.strokeColor = Color.RED;
-        this.debugGraphics.fillColor = Color.RED;
-        this.debugGraphics.lineWidth = 3;
-        
-        const blockParts = this.blockManager.getBlockParts(block);
-        const gridSpacing = this.blockManager.getGridSpacing(); // 动态获取网格间距
-        const snapRange = gridSpacing * 0.6; // 吸附范围
-        
-        blockParts.forEach(part => {
-            const worldPos = part.node.getWorldPosition();
-            const localPos = new Vec3();
-            this.debugDrawNode.getComponent(UITransform).convertToNodeSpaceAR(worldPos, localPos);
-            
-            // 绘制红色十字标记吸附点
-            const crossSize = 10;
-            this.debugGraphics.moveTo(localPos.x - crossSize, localPos.y);
-            this.debugGraphics.lineTo(localPos.x + crossSize, localPos.y);
-            this.debugGraphics.moveTo(localPos.x, localPos.y - crossSize);
-            this.debugGraphics.lineTo(localPos.x, localPos.y + crossSize);
-            this.debugGraphics.stroke();
-            
-            // 绘制吸附范围圆圈
-            this.debugGraphics.circle(localPos.x, localPos.y, snapRange);
-            this.debugGraphics.stroke();
-        });
+        // if (!this.debugDrawSnapRange || !this.debugGraphics || !block || !this.blockManager) return;
+        // 
+        // // 绘制方块吸附点
+        // this.debugGraphics.strokeColor = Color.RED;
+        // this.debugGraphics.fillColor = Color.RED;
+        // this.debugGraphics.lineWidth = 3;
+        // 
+        // const blockParts = this.blockManager.getBlockParts(block);
+        // const gridSpacing = this.blockManager.getGridSpacing(); // 动态获取网格间距
+        // const snapRange = gridSpacing * 0.6; // 吸附范围
+        // 
+        // blockParts.forEach(part => {
+        //     const worldPos = part.node.getWorldPosition();
+        //     const localPos = new Vec3();
+        //     this.debugDrawNode.getComponent(UITransform).convertToNodeSpaceAR(worldPos, localPos);
+        //     
+        //     // 绘制红色十字标记吸附点
+        //     const crossSize = 10;
+        //     this.debugGraphics.moveTo(localPos.x - crossSize, localPos.y);
+        //     this.debugGraphics.lineTo(localPos.x + crossSize, localPos.y);
+        //     this.debugGraphics.moveTo(localPos.x, localPos.y - crossSize);
+        //     this.debugGraphics.lineTo(localPos.x, localPos.y + crossSize);
+        //     this.debugGraphics.stroke();
+        //     
+        //     // 绘制吸附范围圆圈
+        //     this.debugGraphics.circle(localPos.x, localPos.y, snapRange);
+        //     this.debugGraphics.stroke();
+        // });
     }
     
     // 更新调试绘制
     private updateDebugDraw() {
-        if (!this.debugDrawSnapRange || !this.debugGraphics) return;
-        
-        this.debugGraphics.clear();
-        
-        // 绘制网格吸附范围
-        this.drawGridSnapRanges();
-        
-        // 如果有正在拖拽的方块,绘制其吸附范围
-        if (this.currentDragBlock) {
-            this.drawBlockSnapRange(this.currentDragBlock);
-        }
+        // if (!this.debugDrawSnapRange || !this.debugGraphics) return;
+        // 
+        // this.debugGraphics.clear();
+        // 
+        // // 绘制网格吸附范围
+        // this.drawGridSnapRanges();
+        // 
+        // // 如果有正在拖拽的方块,绘制其吸附范围
+        // if (this.currentDragBlock) {
+        //     this.drawBlockSnapRange(this.currentDragBlock);
+        // }
     }
     
     // 清理调试绘制
@@ -1090,11 +1090,11 @@ export class GameBlockSelection extends Component {
     public setDebugDrawSnapRange(enabled: boolean) {
         this.debugDrawSnapRange = enabled;
         
-        if (enabled) {
-            this.initDebugDraw();
-        } else {
-            this.cleanupDebugDraw();
-        }
+        // if (enabled) {
+        //     this.initDebugDraw();
+        // } else {
+        //     this.cleanupDebugDraw();
+        // }
         
         console.log(`[GameBlockSelection] 调试绘制已${enabled ? '开启' : '关闭'}`);
     }

+ 38 - 3
assets/scripts/Core/LevelSessionManager.ts

@@ -1,3 +1,5 @@
+import { resources, JsonAsset } from 'cc';
+
 export interface LevelRuntimeData {
   levelId: number;               // 本局关卡
   wallHealth: number;            // 当前墙血
@@ -17,7 +19,10 @@ export class LevelSessionManager {
   private data: LevelRuntimeData = null;
 
   /** 准备本关运行期数据 */
-  public initialize(levelId: number, wallHealth: number) {
+  public async initialize(levelId: number, wallHealth: number) {
+    // 从关卡配置读取初始金币
+    const initialCoins = await this.loadInitialCoins(levelId);
+    
     this.data = {
       levelId,
       wallHealth,
@@ -26,9 +31,39 @@ export class LevelSessionManager {
       currentWave: 1,
       //drops: [],
       startTime: Date.now(),
-      sessionCoins: 45
+      sessionCoins: initialCoins
     };
-    console.log(`[LevelSessionManager] 初始化完成,sessionCoins设置为: ${this.data.sessionCoins}`);
+    console.log(`[LevelSessionManager] 初始化完成,关卡${levelId}初始金币设置为: ${this.data.sessionCoins}`);
+  }
+
+  /** 从关卡配置文件加载初始金币数量 */
+  private async loadInitialCoins(levelId: number): Promise<number> {
+    try {
+      const jsonPath = `data/levels/Level${levelId}`;
+      console.log(`[LevelSessionManager] 尝试加载关卡配置: ${jsonPath}`);
+      
+      return new Promise<number>((resolve) => {
+        resources.load(jsonPath, JsonAsset, (err, asset) => {
+          if (err) {
+            console.warn(`[LevelSessionManager] 加载关卡${levelId}配置失败,使用默认初始金币45:`, err);
+            resolve(45); // 默认值
+            return;
+          }
+          
+          const levelConfig = asset.json;
+          if (levelConfig && typeof levelConfig.initialCoins === 'number') {
+            console.log(`[LevelSessionManager] 关卡${levelId}初始金币配置: ${levelConfig.initialCoins}`);
+            resolve(levelConfig.initialCoins);
+          } else {
+            console.warn(`[LevelSessionManager] 关卡${levelId}配置中未找到initialCoins字段,使用默认值45`);
+            resolve(45); // 默认值
+          }
+        });
+      });
+    } catch (error) {
+      console.error(`[LevelSessionManager] 加载关卡${levelId}初始金币配置时发生错误:`, error);
+      return 45; // 默认值
+    }
   }
 
   public get runtime() { return this.data; }

+ 2 - 2
assets/scripts/LevelSystem/GameManager.ts

@@ -165,7 +165,7 @@ export class GameManager extends Component {
         return isGameOver;
     }
 
-    start() {
+    async start() {
         // 初始化StartGame的静态事件监听器
         StartGame.initializeEventListeners();
         
@@ -177,7 +177,7 @@ export class GameManager extends Component {
         
         // 提前初始化本局数据,确保 BlockManager 在 start 时能拿到正确的局内金币
         if (!LevelSessionManager.inst.runtime) {
-            LevelSessionManager.inst.initialize(
+            await LevelSessionManager.inst.initialize(
                 this.saveDataManager?.getCurrentLevel() || 1,
                 this.getWallHealth()
             );

+ 3 - 3
assets/scripts/LevelSystem/StartGame.ts

@@ -137,8 +137,8 @@ export class StartGame extends Component {
         const saveDataManager = SaveDataManager.getInstance();
         await saveDataManager.initialize();
         
-        // 重新初始化LevelSessionManager,设置sessionCoins为45
-        LevelSessionManager.inst.initialize(
+        // 重新初始化LevelSessionManager,从关卡配置读取initialCoins
+        await LevelSessionManager.inst.initialize(
             saveDataManager.getCurrentLevel(),
             100 // 默认墙血量,可以根据需要调整
         );
@@ -146,7 +146,7 @@ export class StartGame extends Component {
         // 计算游戏区域边界
         StartGame.calculateGameBounds();
         
-        console.log('[StartGame] 游戏数据初始化完成,sessionCoins已设置为45');
+        console.log('[StartGame] 游戏数据初始化完成,sessionCoins已从关卡配置读取');
         
         // 重置游戏相关组件
         const eventBus = EventBus.getInstance();