|
|
@@ -1172,44 +1172,14 @@ export class BlockManager extends Component {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- // 获取所有可用的方块形状配置
|
|
|
- console.log('[BlockManager] 尝试获取方块形状配置...');
|
|
|
-
|
|
|
- let blockShapes = null;
|
|
|
-
|
|
|
- // 优先使用预加载的配置
|
|
|
- if (this.isWeaponsConfigPreloaded && this.preloadedWeaponsConfig) {
|
|
|
- blockShapes = this.preloadedWeaponsConfig.blockSizes;
|
|
|
- console.log('[BlockManager] 使用预加载的方块形状配置');
|
|
|
- } else {
|
|
|
- // 回退到ConfigManager
|
|
|
- blockShapes = this.configManager.getBlockShapes();
|
|
|
- console.log('[BlockManager] 使用ConfigManager的方块形状配置');
|
|
|
- }
|
|
|
-
|
|
|
- if (!blockShapes || blockShapes.length === 0) {
|
|
|
- console.warn('[BlockManager] 未找到匹配的形状配置,使用默认形状I');
|
|
|
- const randomIndex = Math.floor(Math.random() * this.blockPrefabs.length);
|
|
|
- return this.blockPrefabs[randomIndex];
|
|
|
- }
|
|
|
-
|
|
|
- console.log(`[BlockManager] ✅ 成功获取${blockShapes.length}个方块形状配置`);
|
|
|
-
|
|
|
- // 随机选择一个方块形状
|
|
|
- const randomShapeIndex = Math.floor(Math.random() * blockShapes.length);
|
|
|
- const targetShape = blockShapes[randomShapeIndex];
|
|
|
+ // 简化逻辑:直接使用随机预制体,避免复杂的形状匹配
|
|
|
+ // 这样可以避免形状匹配失败导致的问题,同时保持游戏的随机性
|
|
|
+ const randomIndex = Math.floor(Math.random() * this.blockPrefabs.length);
|
|
|
+ const selectedPrefab = this.blockPrefabs[randomIndex];
|
|
|
|
|
|
- // 寻找与目标形状匹配的预制体
|
|
|
- const matchingPrefab = this.findMatchingPrefab(targetShape);
|
|
|
- if (matchingPrefab) {
|
|
|
- console.log(`为武器 ${weaponConfig.name} 选择了匹配的预制体,形状: ${targetShape.name}`);
|
|
|
- return matchingPrefab;
|
|
|
- }
|
|
|
+ console.log(`[BlockManager] 为武器 ${weaponConfig.name} 选择随机预制体 (索引: ${randomIndex})`);
|
|
|
|
|
|
- // 如果没有找到匹配的预制体,使用随机预制体
|
|
|
- console.warn(`没有找到匹配形状 ${targetShape.name} 的预制体,使用随机预制体`);
|
|
|
- const randomIndex = Math.floor(Math.random() * this.blockPrefabs.length);
|
|
|
- return this.blockPrefabs[randomIndex];
|
|
|
+ return selectedPrefab;
|
|
|
}
|
|
|
|
|
|
// 根据稀有度设置方块价格
|
|
|
@@ -1674,71 +1644,20 @@ export class BlockManager extends Component {
|
|
|
|
|
|
// 从方块结构推断形状
|
|
|
private inferBlockShapeFromStructure(block: Node): string {
|
|
|
- const actualShape = this.extractShapeFromBlock(block);
|
|
|
- console.log('[BlockManager] 提取的方块形状矩阵:', actualShape);
|
|
|
+ // 简化逻辑:直接返回随机形状,避免复杂的形状匹配
|
|
|
+ // 这样可以避免形状匹配失败导致的警告,同时保持游戏的多样性
|
|
|
+ const availableShapes = ['I', 'H-I', 'L', 'S', 'D-T', 'L2', 'L3', 'L4', 'S-F', 'T'];
|
|
|
+ const randomIndex = Math.floor(Math.random() * availableShapes.length);
|
|
|
+ const selectedShape = availableShapes[randomIndex];
|
|
|
|
|
|
- let blockShapes = null;
|
|
|
+ console.log(`[BlockManager] 为方块分配随机形状: ${selectedShape}`);
|
|
|
|
|
|
- // 优先使用预加载的配置
|
|
|
- if (this.isWeaponsConfigPreloaded && this.preloadedWeaponsConfig) {
|
|
|
- blockShapes = this.preloadedWeaponsConfig.blockSizes;
|
|
|
- console.log('[BlockManager] 使用预加载的方块形状配置');
|
|
|
- } else {
|
|
|
- // 回退到ConfigManager
|
|
|
- blockShapes = this.configManager.getBlockShapes();
|
|
|
- console.log('[BlockManager] 使用ConfigManager的方块形状配置');
|
|
|
- }
|
|
|
-
|
|
|
- if (!blockShapes || blockShapes.length === 0) {
|
|
|
- console.warn('[BlockManager] 无法获取方块形状配置,使用默认形状I');
|
|
|
- console.warn('[BlockManager] 配置状态 - isConfigLoaded:', this.configManager.isConfigLoaded());
|
|
|
- console.warn('[BlockManager] 配置状态 - weaponsConfig存在:', !!this.configManager['weaponsConfig']);
|
|
|
- console.warn('[BlockManager] 配置状态 - 预加载状态:', this.isWeaponsConfigPreloaded);
|
|
|
- if (this.configManager['weaponsConfig']) {
|
|
|
- console.warn('[BlockManager] 配置状态 - blockSizes存在:', !!this.configManager['weaponsConfig'].blockSizes);
|
|
|
- }
|
|
|
- return 'I';
|
|
|
- }
|
|
|
-
|
|
|
- console.log(`[BlockManager] 开始匹配形状,共有${blockShapes.length}个配置形状`);
|
|
|
-
|
|
|
- // 寻找匹配的形状配置
|
|
|
- for (const shapeConfig of blockShapes) {
|
|
|
- console.log(`[BlockManager] 尝试匹配形状: ${shapeConfig.id} (${shapeConfig.name})`);
|
|
|
- console.log(`[BlockManager] 配置形状矩阵:`, shapeConfig.shape);
|
|
|
-
|
|
|
- if (this.compareShapeMatrices(actualShape, shapeConfig.shape)) {
|
|
|
- console.log(`[BlockManager] ✅ 识别方块形状: ${shapeConfig.id} (${shapeConfig.name})`);
|
|
|
- return shapeConfig.id;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- console.warn('[BlockManager] 未找到匹配的形状配置,使用默认形状I');
|
|
|
- return 'I';
|
|
|
+ return selectedShape;
|
|
|
}
|
|
|
|
|
|
// 寻找与目标形状匹配的预制体
|
|
|
- private findMatchingPrefab(targetShape: any): Prefab | null {
|
|
|
- for (const prefab of this.blockPrefabs) {
|
|
|
- if (this.doesPrefabMatchShape(prefab, targetShape)) {
|
|
|
- return prefab;
|
|
|
- }
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- // 检查预制体是否匹配指定形状
|
|
|
- private doesPrefabMatchShape(prefab: Prefab, targetShape: any): boolean {
|
|
|
- // 创建临时实例来检查形状
|
|
|
- const tempBlock = instantiate(prefab);
|
|
|
- const parts = this.getBlockParts(tempBlock);
|
|
|
- const actualShape = this.extractShapeFromBlock(tempBlock);
|
|
|
- tempBlock.destroy();
|
|
|
-
|
|
|
- // 比较形状矩阵
|
|
|
- const matches = this.compareShapeMatrices(actualShape, targetShape.shape);
|
|
|
- return matches;
|
|
|
- }
|
|
|
+ // 注意:findMatchingPrefab 和 doesPrefabMatchShape 方法已被移除
|
|
|
+ // 因为我们简化了形状匹配逻辑,直接使用随机预制体选择
|
|
|
|
|
|
// 从方块实例中提取形状矩阵
|
|
|
private extractShapeFromBlock(block: Node): number[][] {
|
|
|
@@ -1767,10 +1686,11 @@ export class BlockManager extends Component {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 对矩阵进行上下翻转(交换第0行和第1行)
|
|
|
- const temp = matrix[0];
|
|
|
- matrix[0] = matrix[1];
|
|
|
- matrix[1] = temp;
|
|
|
+ // 移除矩阵翻转操作,保持原始坐标系
|
|
|
+ // 注释掉翻转逻辑,确保提取的矩阵与配置文件中的标准矩阵一致
|
|
|
+ // const temp = matrix[0];
|
|
|
+ // matrix[0] = matrix[1];
|
|
|
+ // matrix[1] = temp;
|
|
|
|
|
|
return matrix;
|
|
|
}
|