|
|
@@ -514,8 +514,26 @@ export class BlockManager extends Component {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- // 基于武器配置选择合适的预制体
|
|
|
- const prefab = this.selectPrefabForWeapon(weaponConfig);
|
|
|
+ // 从武器配置的形状成本中随机选择一个形状ID
|
|
|
+ let targetShapeId: string | null = null;
|
|
|
+ try {
|
|
|
+ const shapeCosts = weaponConfig.inGameCostConfig?.shapeCosts;
|
|
|
+ if (shapeCosts && Object.keys(shapeCosts).length > 0) {
|
|
|
+ const availableShapes = Object.keys(shapeCosts);
|
|
|
+ targetShapeId = availableShapes[Math.floor(Math.random() * availableShapes.length)];
|
|
|
+ console.log(`[BlockManager] 为武器 ${weaponConfig.name} 选择形状: ${targetShapeId}`);
|
|
|
+ console.log(`[BlockManager] 可用形状列表: ${availableShapes.join(', ')}`);
|
|
|
+ } else {
|
|
|
+ console.warn(`[BlockManager] 武器 ${weaponConfig.name} 没有配置shapeCosts或为空`);
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.warn(`[BlockManager] 无法从武器配置获取形状信息: ${error}`);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 基于武器配置和目标形状选择合适的预制体
|
|
|
+ console.log(`[BlockManager] 开始为武器 ${weaponConfig.name} 选择预制体,目标形状: ${targetShapeId || '未指定'}`);
|
|
|
+ const prefab = this.selectPrefabForWeapon(weaponConfig, targetShapeId);
|
|
|
+ console.log(`[BlockManager] 预制体选择结果: ${prefab ? '成功' : '失败'}`);
|
|
|
if (!prefab) {
|
|
|
console.error(`无法为武器 ${weaponConfig.name} 选择合适的预制体`);
|
|
|
continue;
|
|
|
@@ -1167,13 +1185,21 @@ export class BlockManager extends Component {
|
|
|
}
|
|
|
|
|
|
// 根据武器配置选择合适的预制体
|
|
|
- private selectPrefabForWeapon(weaponConfig: WeaponConfig): Prefab | null {
|
|
|
+ private selectPrefabForWeapon(weaponConfig: WeaponConfig, targetShapeId?: string): Prefab | null {
|
|
|
if (this.blockPrefabs.length === 0) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- // 简化逻辑:直接使用随机预制体,避免复杂的形状匹配
|
|
|
- // 这样可以避免形状匹配失败导致的问题,同时保持游戏的随机性
|
|
|
+ // 如果指定了目标形状ID,尝试找到匹配的预制体
|
|
|
+ if (targetShapeId) {
|
|
|
+ const matchingPrefab = this.findPrefabByShape(targetShapeId);
|
|
|
+ if (matchingPrefab) {
|
|
|
+ console.log(`[BlockManager] 为武器 ${weaponConfig.name} 找到匹配形状 ${targetShapeId} 的预制体`);
|
|
|
+ return matchingPrefab;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果没有指定形状或没有找到匹配的预制体,使用随机选择
|
|
|
const randomIndex = Math.floor(Math.random() * this.blockPrefabs.length);
|
|
|
const selectedPrefab = this.blockPrefabs[randomIndex];
|
|
|
|
|
|
@@ -1182,6 +1208,30 @@ export class BlockManager extends Component {
|
|
|
return selectedPrefab;
|
|
|
}
|
|
|
|
|
|
+ // 根据形状ID查找匹配的预制体(按照Block+形状ID的命名规则)
|
|
|
+ private findPrefabByShape(targetShapeId: string): Prefab | null {
|
|
|
+ // 构建预期的预制体名称:Block + 形状ID
|
|
|
+ const expectedPrefabName = `Block${targetShapeId}`;
|
|
|
+
|
|
|
+ console.log(`[BlockManager] 寻找形状 ${targetShapeId} 的预制体,期望名称: ${expectedPrefabName}`);
|
|
|
+ console.log(`[BlockManager] 当前可用预制体数量: ${this.blockPrefabs.length}`);
|
|
|
+
|
|
|
+ // 输出所有可用预制体的详细信息
|
|
|
+ this.blockPrefabs.forEach((prefab, index) => {
|
|
|
+ console.log(`[BlockManager] 预制体[${index}]: ${prefab.name} (匹配: ${prefab.name === expectedPrefabName})`);
|
|
|
+ });
|
|
|
+
|
|
|
+ for (const prefab of this.blockPrefabs) {
|
|
|
+ if (prefab.name === expectedPrefabName) {
|
|
|
+ console.log(`[BlockManager] ✓ 找到匹配形状 ${targetShapeId} 的预制体: ${prefab.name}`);
|
|
|
+ return prefab;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log(`[BlockManager] ✗ 未找到匹配形状 ${targetShapeId} 的预制体 (期望名称: ${expectedPrefabName})`);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
// 根据稀有度设置方块价格
|
|
|
private setBlockPriceByRarity(priceNode: Node, rarity: string) {
|
|
|
const label = priceNode.getComponent(Label);
|
|
|
@@ -1644,20 +1694,14 @@ export class BlockManager extends Component {
|
|
|
|
|
|
// 从方块结构推断形状
|
|
|
private inferBlockShapeFromStructure(block: Node): string {
|
|
|
- // 简化逻辑:直接返回随机形状,避免复杂的形状匹配
|
|
|
- // 这样可以避免形状匹配失败导致的警告,同时保持游戏的多样性
|
|
|
- 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];
|
|
|
-
|
|
|
- console.log(`[BlockManager] 为方块分配随机形状: ${selectedShape}`);
|
|
|
+ // 直接从B1节点结构读取形状矩阵
|
|
|
+ const actualShape = this.extractShapeFromBlock(block);
|
|
|
|
|
|
- return selectedShape;
|
|
|
+ // 返回默认形状ID,实际形状矩阵已通过extractShapeFromBlock获取
|
|
|
+ return 'I';
|
|
|
}
|
|
|
|
|
|
- // 寻找与目标形状匹配的预制体
|
|
|
- // 注意:findMatchingPrefab 和 doesPrefabMatchShape 方法已被移除
|
|
|
- // 因为我们简化了形状匹配逻辑,直接使用随机预制体选择
|
|
|
+
|
|
|
|
|
|
// 从方块实例中提取形状矩阵
|
|
|
private extractShapeFromBlock(block: Node): number[][] {
|
|
|
@@ -1687,10 +1731,6 @@ export class BlockManager extends Component {
|
|
|
}
|
|
|
|
|
|
// 移除矩阵翻转操作,保持原始坐标系
|
|
|
- // 注释掉翻转逻辑,确保提取的矩阵与配置文件中的标准矩阵一致
|
|
|
- // const temp = matrix[0];
|
|
|
- // matrix[0] = matrix[1];
|
|
|
- // matrix[1] = temp;
|
|
|
|
|
|
return matrix;
|
|
|
}
|