|
|
@@ -362,21 +362,31 @@ export class BlockManager extends Component {
|
|
|
for (let i = 0; i < 3; i++) {
|
|
|
let weaponConfig: WeaponConfig | null = null;
|
|
|
|
|
|
- // 如果关卡配置了武器列表,从中随机选择
|
|
|
+ // 优先使用关卡配置的武器,确保符合关卡设计
|
|
|
if (levelWeapons.length > 0) {
|
|
|
const randomWeaponName = levelWeapons[Math.floor(Math.random() * levelWeapons.length)];
|
|
|
weaponConfig = this.getWeaponConfigByName(randomWeaponName);
|
|
|
|
|
|
if (!weaponConfig) {
|
|
|
- console.warn(`关卡配置的武器 "${randomWeaponName}" 在武器配置文件中未找到,使用随机武器`);
|
|
|
- weaponConfig = this.configManager.getRandomWeapon();
|
|
|
+ console.warn(`关卡配置的武器 "${randomWeaponName}" 在武器配置文件中未找到`);
|
|
|
}
|
|
|
- } else {
|
|
|
- // 如果关卡没有配置武器列表,使用随机武器
|
|
|
- console.warn('关卡未配置武器列表,使用随机武器');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果关卡没有配置武器或获取失败,使用随机武器
|
|
|
+ if (!weaponConfig) {
|
|
|
weaponConfig = this.configManager.getRandomWeapon();
|
|
|
}
|
|
|
|
|
|
+ // 最后的兜底处理
|
|
|
+ if (!weaponConfig) {
|
|
|
+ console.warn('无法获取武器配置,使用默认武器');
|
|
|
+ // 尝试获取一个基础武器作为兜底
|
|
|
+ const allWeapons = this.configManager.getAllWeapons();
|
|
|
+ if (allWeapons.length > 0) {
|
|
|
+ weaponConfig = allWeapons[0];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if (!weaponConfig) {
|
|
|
console.error(`无法获取第 ${i + 1} 个武器配置`);
|
|
|
continue;
|
|
|
@@ -553,7 +563,7 @@ export class BlockManager extends Component {
|
|
|
);
|
|
|
}, this);
|
|
|
|
|
|
- block.on(Node.EventType.TOUCH_END, (event: EventTouch) => {
|
|
|
+ block.on(Node.EventType.TOUCH_END, async (event: EventTouch) => {
|
|
|
if (this.gameStarted && this.blockLocations.get(block) === 'grid') {
|
|
|
if (!this.canMoveBlock(block)) {
|
|
|
return;
|
|
|
@@ -561,7 +571,7 @@ export class BlockManager extends Component {
|
|
|
}
|
|
|
|
|
|
if (this.currentDragBlock) {
|
|
|
- this.handleBlockDrop(event);
|
|
|
+ await this.handleBlockDrop(event);
|
|
|
|
|
|
|
|
|
this.currentDragBlock = null;
|
|
|
@@ -583,7 +593,7 @@ export class BlockManager extends Component {
|
|
|
}
|
|
|
|
|
|
// 处理方块放下
|
|
|
- handleBlockDrop(event: EventTouch) {
|
|
|
+ async handleBlockDrop(event: EventTouch) {
|
|
|
const touchPos = event.getLocation();
|
|
|
const startLocation = this.currentDragBlock['startLocation'];
|
|
|
|
|
|
@@ -597,7 +607,7 @@ export class BlockManager extends Component {
|
|
|
this.returnBlockToOriginalPosition();
|
|
|
}
|
|
|
} else if (this.tryPlaceBlockToGrid(this.currentDragBlock)) {
|
|
|
- this.handleSuccessfulPlacement(startLocation);
|
|
|
+ await this.handleSuccessfulPlacement(startLocation);
|
|
|
} else {
|
|
|
console.log(`[BlockManager] 方块 ${this.currentDragBlock.name} 放置到网格失败`);
|
|
|
console.log(`[BlockManager] 方块标签状态:`, BlockTag.hasTag(this.currentDragBlock));
|
|
|
@@ -649,7 +659,7 @@ export class BlockManager extends Component {
|
|
|
}
|
|
|
|
|
|
// 处理成功放置
|
|
|
- handleSuccessfulPlacement(startLocation: string) {
|
|
|
+ async handleSuccessfulPlacement(startLocation: string) {
|
|
|
const price = this.getBlockPrice(this.currentDragBlock);
|
|
|
|
|
|
if (startLocation === 'grid') {
|
|
|
@@ -674,7 +684,7 @@ export class BlockManager extends Component {
|
|
|
}
|
|
|
|
|
|
// 检查并执行合成
|
|
|
- this.tryMergeBlock(this.currentDragBlock);
|
|
|
+ await this.tryMergeBlock(this.currentDragBlock);
|
|
|
} else {
|
|
|
if (this.deductPlayerCoins(price)) {
|
|
|
this.clearTempStoredOccupiedGrids(this.currentDragBlock);
|
|
|
@@ -700,7 +710,7 @@ export class BlockManager extends Component {
|
|
|
}
|
|
|
|
|
|
// 检查并执行合成
|
|
|
- this.tryMergeBlock(this.currentDragBlock);
|
|
|
+ await this.tryMergeBlock(this.currentDragBlock);
|
|
|
} else {
|
|
|
this.returnBlockToOriginalPosition();
|
|
|
}
|
|
|
@@ -1314,6 +1324,11 @@ export class BlockManager extends Component {
|
|
|
|
|
|
// 设置方块稀有度颜色
|
|
|
private setBlockRarityColor(block: Node, rarity: string) {
|
|
|
+ this.applyBlockRarityColor(block, rarity);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 公共方法:应用方块稀有度颜色(供外部调用)
|
|
|
+ public applyBlockRarityColor(block: Node, rarity: string) {
|
|
|
// Add null safety check for block
|
|
|
if (!block || !block.isValid) {
|
|
|
return;
|
|
|
@@ -1347,6 +1362,7 @@ export class BlockManager extends Component {
|
|
|
}
|
|
|
|
|
|
sprite.color = color;
|
|
|
+ console.log(`[BlockManager] 设置方块稀有度颜色: ${rarity}`, color);
|
|
|
}
|
|
|
|
|
|
// 加载武器图标
|
|
|
@@ -1770,7 +1786,7 @@ export class BlockManager extends Component {
|
|
|
private readonly rarityOrder: string[] = ['common','uncommon','rare','epic','legendary'];
|
|
|
|
|
|
/** 检查当前放置的方块能否与相同稀有度的方块合成 */
|
|
|
- private tryMergeBlock(block: Node) {
|
|
|
+ private async tryMergeBlock(block: Node) {
|
|
|
const rarity = this.getBlockRarity(block);
|
|
|
if (!rarity) return;
|
|
|
|
|
|
@@ -1787,13 +1803,13 @@ export class BlockManager extends Component {
|
|
|
const otherBB = this.getWorldAABB(other);
|
|
|
if (this.rectIntersects(blockBB, otherBB)) {
|
|
|
// 找到合成目标
|
|
|
- this.performMerge(block, other, rarity);
|
|
|
+ await this.performMerge(block, other, rarity);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private performMerge(target: Node, source: Node, rarity: string) {
|
|
|
+ private async performMerge(target: Node, source: Node, rarity: string) {
|
|
|
console.log(`[BlockManager] 开始合成方块: 目标=${target.name}, 源=${source.name}, 稀有度=${rarity}`);
|
|
|
|
|
|
// 隐藏价格标签并处理 db 关联
|
|
|
@@ -1808,13 +1824,39 @@ export class BlockManager extends Component {
|
|
|
const nextRarity = this.getNextRarity(rarity);
|
|
|
if (nextRarity) {
|
|
|
console.log(`[BlockManager] 合成成功,稀有度升级: ${rarity} -> ${nextRarity}`);
|
|
|
- this.setBlockRarityColor(target, nextRarity);
|
|
|
- // 如果有武器配置,也升级
|
|
|
- const cfg = this.blockWeaponConfigs.get(target);
|
|
|
- if (cfg) {
|
|
|
- cfg.rarity = nextRarity;
|
|
|
- this.blockWeaponConfigs.set(target, cfg);
|
|
|
+
|
|
|
+ // 获取当前武器配置
|
|
|
+ const currentConfig = this.blockWeaponConfigs.get(target);
|
|
|
+ if (currentConfig) {
|
|
|
+ // 保存原始武器名称用于日志输出
|
|
|
+ const originalWeaponName = currentConfig.name;
|
|
|
+
|
|
|
+ // 获取当前关卡允许的武器列表
|
|
|
+ const levelWeapons = await this.getCurrentLevelWeapons();
|
|
|
+
|
|
|
+ // 检查是否应该限制在关卡配置的武器范围内
|
|
|
+ if (levelWeapons.length > 0) {
|
|
|
+ // 如果当前武器不在关卡配置中,说明是通过合成获得的,应该保持原武器不变,只升级稀有度
|
|
|
+ if (!levelWeapons.some(weapon => weapon === originalWeaponName)) {
|
|
|
+ console.log(`[BlockManager] 武器 ${originalWeaponName} 不在关卡配置中,保持原武器,只升级稀有度`);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 无论如何,都只升级稀有度,不改变武器类型
|
|
|
+ const upgradedConfig = { ...currentConfig };
|
|
|
+ upgradedConfig.rarity = nextRarity;
|
|
|
+ this.blockWeaponConfigs.set(target, upgradedConfig);
|
|
|
+ console.log(`[BlockManager] 武器配置升级: ${originalWeaponName} 稀有度 ${rarity} -> ${nextRarity}`);
|
|
|
+ } else {
|
|
|
+ // 如果没有关卡配置限制,正常升级稀有度
|
|
|
+ const upgradedConfig = { ...currentConfig };
|
|
|
+ upgradedConfig.rarity = nextRarity;
|
|
|
+ this.blockWeaponConfigs.set(target, upgradedConfig);
|
|
|
+ console.log(`[BlockManager] 武器配置升级: ${originalWeaponName} 稀有度 ${rarity} -> ${nextRarity}`);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ // 更新方块颜色
|
|
|
+ this.setBlockRarityColor(target, nextRarity);
|
|
|
}
|
|
|
|
|
|
// 播放烟雾动画
|
|
|
@@ -1824,7 +1866,7 @@ export class BlockManager extends Component {
|
|
|
|
|
|
// 递归检查是否还能继续合成
|
|
|
if (nextRarity) {
|
|
|
- this.tryMergeBlock(target);
|
|
|
+ await this.tryMergeBlock(target);
|
|
|
}
|
|
|
}
|
|
|
|