Ver código fonte

方块占用优化

181404010226 3 meses atrás
pai
commit
ceb44ab19d

+ 16 - 16
assets/assets/Prefabs/Blocks/BlockL2.prefab

@@ -47,8 +47,8 @@
       "__type__": "cc.Quat",
       "x": 0,
       "y": 0,
-      "z": 0.7071067811865475,
-      "w": 0.7071067811865476
+      "z": 0,
+      "w": 1
     },
     "_lscale": {
       "__type__": "cc.Vec3",
@@ -62,7 +62,7 @@
       "__type__": "cc.Vec3",
       "x": 0,
       "y": 0,
-      "z": 90
+      "z": 0
     },
     "_id": ""
   },
@@ -106,8 +106,8 @@
       "__type__": "cc.Quat",
       "x": 0,
       "y": 0,
-      "z": 0,
-      "w": 1
+      "z": 0.7071067811865475,
+      "w": 0.7071067811865476
     },
     "_lscale": {
       "__type__": "cc.Vec3",
@@ -121,7 +121,7 @@
       "__type__": "cc.Vec3",
       "x": 0,
       "y": 0,
-      "z": 0
+      "z": 90
     },
     "_id": ""
   },
@@ -458,16 +458,16 @@
     },
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": -12.257000000000062,
-      "y": 25.975000000000023,
+      "x": -24.866,
+      "y": -12.858,
       "z": 0
     },
     "_lrot": {
       "__type__": "cc.Quat",
       "x": 0,
       "y": 0,
-      "z": -0.7071067811865475,
-      "w": 0.7071067811865476
+      "z": 0,
+      "w": 1
     },
     "_lscale": {
       "__type__": "cc.Vec3",
@@ -481,7 +481,7 @@
       "__type__": "cc.Vec3",
       "x": 0,
       "y": 0,
-      "z": -90
+      "z": 0
     },
     "_id": ""
   },
@@ -571,7 +571,7 @@
     "_lpos": {
       "__type__": "cc.Vec3",
       "x": -27.181,
-      "y": 27.009,
+      "y": -26.991,
       "z": 0
     },
     "_lrot": {
@@ -617,8 +617,8 @@
     },
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": 54.363,
-      "y": -0.897,
+      "x": 0.475,
+      "y": 52.27,
       "z": 0
     },
     "_lrot": {
@@ -705,8 +705,8 @@
     },
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": 0.637,
-      "y": -54.138,
+      "x": 50.916,
+      "y": 1.529,
       "z": 0
     },
     "_lrot": {

+ 21 - 21
assets/assets/Prefabs/Blocks/BlockL3.prefab

@@ -47,8 +47,8 @@
       "__type__": "cc.Quat",
       "x": 0,
       "y": 0,
-      "z": 1,
-      "w": 6.123233995736766e-17
+      "z": 0,
+      "w": 1
     },
     "_lscale": {
       "__type__": "cc.Vec3",
@@ -62,7 +62,7 @@
       "__type__": "cc.Vec3",
       "x": 0,
       "y": 0,
-      "z": 180
+      "z": 0
     },
     "_id": ""
   },
@@ -106,8 +106,8 @@
       "__type__": "cc.Quat",
       "x": 0,
       "y": 0,
-      "z": 0,
-      "w": 1
+      "z": 1,
+      "w": 6.123233995736766e-17
     },
     "_lscale": {
       "__type__": "cc.Vec3",
@@ -121,7 +121,7 @@
       "__type__": "cc.Vec3",
       "x": 0,
       "y": 0,
-      "z": 0
+      "z": 180
     },
     "_id": ""
   },
@@ -458,16 +458,16 @@
     },
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": -26.248999999999967,
-      "y": 9.928999999999974,
+      "x": 26.501,
+      "y": -12.858,
       "z": 0
     },
     "_lrot": {
       "__type__": "cc.Quat",
       "x": 0,
       "y": 0,
-      "z": 1,
-      "w": 6.123233995736766e-17
+      "z": 0,
+      "w": 1
     },
     "_lscale": {
       "__type__": "cc.Vec3",
@@ -479,9 +479,9 @@
     "_layer": 1073741824,
     "_euler": {
       "__type__": "cc.Vec3",
-      "x": 180,
-      "y": 180,
-      "z": 7.016709298534876e-15
+      "x": 0,
+      "y": 0,
+      "z": 0
     },
     "_id": ""
   },
@@ -511,7 +511,7 @@
   },
   {
     "__type__": "cc.CompPrefabInfo",
-    "fileId": "71vZ1XpbdHc4vUl0h4X3rh"
+    "fileId": "56SDA95upKHr5yPMWV0tYc"
   },
   {
     "__type__": "cc.PrefabInfo",
@@ -521,14 +521,14 @@
     "asset": {
       "__id__": 0
     },
-    "fileId": "06DWBEyCRA47TjwtuZmkm8",
+    "fileId": "9c7Ubhn0RM96gqrQtgSLfg",
     "instance": null,
     "targetOverrides": null,
     "nestedPrefabInstanceRoots": null
   },
   {
     "__type__": "cc.CompPrefabInfo",
-    "fileId": "8eef+IKt9Mi7Cb/4CCRxJ2"
+    "fileId": "fe6ih0GxBBr6cRar+jUZ69"
   },
   {
     "__type__": "cc.PrefabInfo",
@@ -570,8 +570,8 @@
     },
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": -27.181,
-      "y": 27.009,
+      "x": 26.518,
+      "y": -26.808,
       "z": 0
     },
     "_lrot": {
@@ -617,8 +617,8 @@
     },
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": 54.363,
-      "y": -0.897,
+      "x": -48.257,
+      "y": -0.172,
       "z": 0
     },
     "_lrot": {
@@ -706,7 +706,7 @@
     "_lpos": {
       "__type__": "cc.Vec3",
       "x": 0.637,
-      "y": -54.138,
+      "y": 52.409,
       "z": 0
     },
     "_lrot": {

+ 7 - 7
assets/assets/Prefabs/Blocks/BlockL4.prefab

@@ -578,8 +578,8 @@
       "__type__": "cc.Quat",
       "x": 0,
       "y": 0,
-      "z": -0.7071067811865475,
-      "w": 0.7071067811865476
+      "z": 0,
+      "w": 1
     },
     "_lscale": {
       "__type__": "cc.Vec3",
@@ -593,7 +593,7 @@
       "__type__": "cc.Vec3",
       "x": 0,
       "y": 0,
-      "z": -90
+      "z": 0
     },
     "_id": ""
   },
@@ -617,8 +617,8 @@
     },
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": 54.363,
-      "y": -0.897,
+      "x": 0.957,
+      "y": -49.318,
       "z": 0
     },
     "_lrot": {
@@ -705,8 +705,8 @@
     },
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": 0.637,
-      "y": -54.138,
+      "x": -51.785,
+      "y": 2.156,
       "z": 0
     },
     "_lrot": {

+ 23 - 23
assets/assets/Prefabs/Blocks/BlockT.prefab

@@ -47,8 +47,8 @@
       "__type__": "cc.Quat",
       "x": 0,
       "y": 0,
-      "z": 1,
-      "w": 6.123233995736766e-17
+      "z": 0,
+      "w": 1
     },
     "_lscale": {
       "__type__": "cc.Vec3",
@@ -62,7 +62,7 @@
       "__type__": "cc.Vec3",
       "x": 0,
       "y": 0,
-      "z": 180
+      "z": 0
     },
     "_id": ""
   },
@@ -106,8 +106,8 @@
       "__type__": "cc.Quat",
       "x": 0,
       "y": 0,
-      "z": 0,
-      "w": 1
+      "z": 1,
+      "w": 6.123233995736766e-17
     },
     "_lscale": {
       "__type__": "cc.Vec3",
@@ -121,7 +121,7 @@
       "__type__": "cc.Vec3",
       "x": 0,
       "y": 0,
-      "z": 0
+      "z": 180
     },
     "_id": ""
   },
@@ -473,16 +473,16 @@
     },
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": 0.7819999999999823,
-      "y": -9.769999999999982,
+      "x": -0.07699999999999818,
+      "y": -3.8099999999999454,
       "z": 0
     },
     "_lrot": {
       "__type__": "cc.Quat",
       "x": 0,
       "y": 0,
-      "z": 1,
-      "w": 6.123233995736766e-17
+      "z": 0,
+      "w": 1
     },
     "_lscale": {
       "__type__": "cc.Vec3",
@@ -494,9 +494,9 @@
     "_layer": 1073741824,
     "_euler": {
       "__type__": "cc.Vec3",
-      "x": 180,
-      "y": 180,
-      "z": 7.016709298534876e-15
+      "x": 0,
+      "y": 0,
+      "z": 0
     },
     "_id": ""
   },
@@ -526,7 +526,7 @@
   },
   {
     "__type__": "cc.CompPrefabInfo",
-    "fileId": "207cpmoKZN+IaAT5tDgbME"
+    "fileId": "e9JLYRFyNL6JPLgwEHpgt/"
   },
   {
     "__type__": "cc.PrefabInfo",
@@ -536,14 +536,14 @@
     "asset": {
       "__id__": 0
     },
-    "fileId": "84iKe614FJXKPNlVw3Ul3Y",
+    "fileId": "86+CZ/NdxG3bIME+X0l9dd",
     "instance": null,
     "targetOverrides": null,
     "nestedPrefabInstanceRoots": null
   },
   {
     "__type__": "cc.CompPrefabInfo",
-    "fileId": "2537TbpGRNhapre/4Mxk9S"
+    "fileId": "7evy51BiJHtbT6yDEe8wHZ"
   },
   {
     "__type__": "cc.PrefabInfo",
@@ -617,7 +617,7 @@
   },
   {
     "__type__": "cc.Node",
-    "_name": "(0,-1)",
+    "_name": "(0,1)",
     "_objFlags": 0,
     "__editorExtras__": {},
     "_parent": {
@@ -705,7 +705,7 @@
   },
   {
     "__type__": "cc.Node",
-    "_name": "(1,0)",
+    "_name": "(-1,1)",
     "_objFlags": 0,
     "__editorExtras__": {},
     "_parent": {
@@ -723,8 +723,8 @@
     },
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": -49.78899999999999,
-      "y": -0.5,
+      "x": -49.789,
+      "y": 52.654,
       "z": 0
     },
     "_lrot": {
@@ -793,7 +793,7 @@
   },
   {
     "__type__": "cc.Node",
-    "_name": "(-1,0)",
+    "_name": "(1,1)",
     "_objFlags": 0,
     "__editorExtras__": {},
     "_parent": {
@@ -811,8 +811,8 @@
     },
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": 49.90900000000005,
-      "y": -0.5,
+      "x": 49.909,
+      "y": 53.124,
       "z": 0
     },
     "_lrot": {

+ 19 - 0
assets/scripts/CombatSystem/BlockManager.ts

@@ -863,6 +863,25 @@ export class BlockManager extends Component {
         this.tempRemovedOccupiedGrids.splice(index, 1);
     }
     
+    // 清除特定方块的占用状态
+    public clearOccupiedPositions(block: Node) {
+        if (!this.gridInitialized) return;
+        
+        const occupiedGrids = block['occupiedGrids'];
+        if (!occupiedGrids || occupiedGrids.length === 0) return;
+        
+        // 清除网格占用状态
+        for (const grid of occupiedGrids) {
+            if (grid.row >= 0 && grid.row < this.GRID_ROWS && 
+                grid.col >= 0 && grid.col < this.GRID_COLS) {
+                this.gridOccupationMap[grid.row][grid.col] = 0;
+            }
+        }
+        
+        // 清除方块的占用记录
+        block['occupiedGrids'] = [];
+    }
+    
     // 尝试将方块放置到网格中
     tryPlaceBlockToGrid(block: Node): boolean {
         console.log(`[BlockManager] 尝试放置方块 ${block.name} 到网格`);

+ 30 - 0
assets/scripts/CombatSystem/BlockSelection/GameBlockSelection.ts

@@ -576,6 +576,13 @@ export class GameBlockSelection extends Component {
             this.blockStartPos.set(block.position);
             this.currentDragBlock['startLocation'] = blockLocation;
             
+            // 如果方块在grid区域,拿起时清除其占用状态
+            if (blockLocation === 'grid') {
+                this.blockManager.clearOccupiedPositions(block);
+                // 输出更新后的占用情况
+                this.blockManager.printGridOccupationMatrix();
+            }
+            
             // 设置拖动状态,隐藏价格标签
             block['isDragging'] = true;
             
@@ -983,6 +990,8 @@ export class GameBlockSelection extends Component {
     // 返回方块到原位置
     private returnBlockToOriginalPosition() {
         const currentLocation = this.blockManager.blockLocations.get(this.currentDragBlock);
+        const startLocation = this.currentDragBlock['startLocation'];
+        
         if (currentLocation === 'kuang') {
             const originalPos = this.blockManager.originalPositions.get(this.currentDragBlock);
             if (originalPos) {
@@ -990,6 +999,27 @@ export class GameBlockSelection extends Component {
             }
         } else {
             this.currentDragBlock.position = this.blockStartPos.clone();
+            
+            // 如果方块原本在grid区域,返回原位置后需要重新标记占用状态
+            if (startLocation === 'grid') {
+                // 获取方块当前位置对应的网格节点
+                let b1Node = this.currentDragBlock;
+                if (this.currentDragBlock.name !== 'B1') {
+                    b1Node = this.currentDragBlock.getChildByName('B1');
+                }
+                
+                if (b1Node) {
+                    const b1WorldPos = b1Node.parent.getComponent(UITransform).convertToWorldSpaceAR(b1Node.position);
+                    const gridPos = this.blockManager.gridContainer.getComponent(UITransform).convertToNodeSpaceAR(b1WorldPos);
+                    const gridNode = this.blockManager.findNearestGridNode(gridPos);
+                    
+                    if (gridNode) {
+                        this.blockManager.markOccupiedPositions(this.currentDragBlock, gridNode);
+                        // 输出更新后的占用情况
+                        this.blockManager.printGridOccupationMatrix();
+                    }
+                }
+            }
         }
         
         // 清除拖动状态,恢复db节点显示