Browse Source

方块特效优化

181404010226 4 months ago
parent
commit
79c452df94

+ 8 - 40
assets/scripts/Animations/BallAni.ts

@@ -1,4 +1,4 @@
-import { _decorator, Component, Node, Vec3, tween, Color, Sprite, resources, sp, find } from 'cc';
+import { _decorator, Component, Node, Vec3, tween, Color,find, Sprite, resources, sp } from 'cc';
 import EventBus, { GameEvents } from '../Core/EventBus';
 const { ccclass, property } = _decorator;
 
@@ -55,29 +55,17 @@ export class BallAni extends Component {
         
         const sprite = blockNode.getComponent(Sprite);
         const originalScale = blockNode.scale.clone();
-        const originalColor = sprite ? sprite.color.clone() : Color.WHITE.clone();
         
-        console.log('[BallAni] 原始缩放:', originalScale, '原始颜色:', originalColor);
+        console.log('[BallAni] 原始缩放:', originalScale);
         
         if (hasActiveEnemies) {
-            // 有敌人时播放完整动画:收缩到0.5倍 -> 变白发亮 -> 恢复正常
+            // 有敌人时播放缩放动画
             const shrinkScale = originalScale.clone().multiplyScalar(0.5);
             const animationTween = tween(blockNode)
                 .to(0.2, { scale: shrinkScale })
-                .call(() => {
-                    console.log('[BallAni] 方块收缩完成,开始变白');
-                    // 变白发光效果
-                    if (sprite) {
-                        sprite.color = Color.WHITE;
-                    }
-                })
                 .to(0.2, { scale: originalScale })
                 .call(() => {
                     console.log('[BallAni] 方块动画完成,恢复原状');
-                    // 恢复原始颜色
-                    if (sprite) {
-                        sprite.color = originalColor;
-                    }
                     // 动画完成,从活动列表中移除
                     this.activeBlockAnimations.delete(blockNode);
                 })
@@ -86,22 +74,11 @@ export class BallAni extends Component {
             // 添加到活动动画列表
             this.activeBlockAnimations.set(blockNode, animationTween);
         } else {
-            // 没有敌人时只播放白光效果,不缩放
+            // 没有敌人时直接结束动画
             const animationTween = tween({})
+                .delay(0.2)
                 .call(() => {
-                    console.log('[BallAni] 无敌人,仅播放白光效果');
-                    // 变白发光效果
-                    if (sprite) {
-                        sprite.color = Color.WHITE;
-                    }
-                })
-                .delay(0.2) // 保持白光一段时间
-                .call(() => {
-                    console.log('[BallAni] 白光效果完成,恢复原状');
-                    // 恢复原始颜色
-                    if (sprite) {
-                        sprite.color = originalColor;
-                    }
+                    console.log('[BallAni] 无敌人,直接恢复原状');
                     // 动画完成,从活动列表中移除
                     this.activeBlockAnimations.delete(blockNode);
                 })
@@ -198,6 +175,8 @@ export class BallAni extends Component {
         }
     }
     
+
+    
     /**
      * 停止指定方块的动画
      * @param blockNode 方块节点
@@ -207,12 +186,6 @@ export class BallAni extends Component {
         if (animation) {
             animation.stop();
             this.activeBlockAnimations.delete(blockNode);
-            
-            // 恢复原始状态
-            const sprite = blockNode.getComponent(Sprite);
-            if (sprite) {
-                sprite.color = Color.WHITE;
-            }
         }
     }
     
@@ -237,11 +210,6 @@ export class BallAni extends Component {
             if (animation) {
                 animation.stop();
             }
-            // 恢复方块状态
-            const sprite = blockNode.getComponent(Sprite);
-            if (sprite) {
-                sprite.color = Color.WHITE;
-            }
         }
         this.activeBlockAnimations.clear();
     }

+ 65 - 23
assets/scripts/CombatSystem/BlockManager.ts

@@ -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);
         }
     }
 

+ 42 - 4
assets/scripts/Core/ConfigManager.ts

@@ -281,11 +281,49 @@ export class ConfigManager extends BaseSingleton {
             return filteredWeapons[randomIndex];
         }
 
-        // 从权重列表中随机选择
-        const randomIndex = Math.floor(Math.random() * this.weaponWeightedList.length);
-        return this.weaponWeightedList[randomIndex];
-    }
+        // 使用稀有度权重系统进行随机选择
+        const rarityWeights = this.weaponsConfig.rarityWeights;
+        if (!rarityWeights) {
+            console.warn('稀有度权重配置未找到,使用武器权重列表');
+            const randomIndex = Math.floor(Math.random() * this.weaponWeightedList.length);
+            return this.weaponWeightedList[randomIndex];
+        }
 
+        // 计算总权重
+        // 计算总权重(兼容ES5)
+        const totalWeight = Object.keys(rarityWeights).reduce((sum: number, key: string) => sum + (rarityWeights[key] as number), 0);
+        const randomValue = Math.random() * totalWeight;
+        
+        // 根据权重选择稀有度
+        let currentWeight = 0;
+        let selectedRarity = 'common';
+        
+        // 兼容ES5的写法遍历对象
+        for (let rarity in rarityWeights) {
+            if (rarityWeights.hasOwnProperty(rarity)) {
+                const weight = rarityWeights[rarity];
+            currentWeight += weight as number;
+            if (randomValue <= currentWeight) {
+                selectedRarity = rarity;
+                break;
+            }
+        }
+        
+        // 从选中的稀有度中随机选择武器
+        const weaponsOfRarity = this.weaponsConfig.weapons.filter(weapon => weapon.rarity === selectedRarity);
+        if (weaponsOfRarity.length === 0) {
+            console.warn(`稀有度 ${selectedRarity} 没有可用武器,使用武器权重列表`);
+            const randomIndex = Math.floor(Math.random() * this.weaponWeightedList.length);
+            return this.weaponWeightedList[randomIndex];
+        }
+        
+        const randomIndex = Math.floor(Math.random() * weaponsOfRarity.length);
+        const selectedWeapon = weaponsOfRarity[randomIndex];
+        
+        console.log(`随机选择武器: ${selectedWeapon.name} (${selectedRarity})`);
+        return selectedWeapon;
+        }
+    }
     // 随机获取敌人配置
     public getRandomEnemy(rarity?: string): EnemyConfig | null {
         if (!this.enemiesConfig || this.enemyWeightedList.length === 0) {

+ 0 - 6
assets/scripts/Core/EventBus.ts

@@ -102,10 +102,4 @@ export default class EventBus extends EventTarget {
         return this._instance;
     }
 
-    // 重写emit方法,添加黄色字体的日志输出
-    emit(type: string, ...args: any[]): void {
-        console.log(`%c[EventBus] 发送事件: ${type}`, 'color: #FFD700; font-weight: bold;', args.length > 0 ? args : '');
-        super.emit(type, ...args);
-    }
-
 }

+ 4 - 4
assets/scripts/FourUI/MainSystem/MainUIControlller.ts

@@ -391,22 +391,22 @@ export class MainUIController extends Component {
         console.log('计算出的失败奖励:', rewards);
       }
       
-      if (rewards && (rewards.coins > 0 || rewards.diamonds > 0)) {
+      if (rewards && (rewards.money > 0 || rewards.diamonds > 0)) {
         // 使用MoneyAni播放奖励动画
         if (this.moneyAniNode) {
           const moneyAni = this.moneyAniNode.getComponent(MoneyAni);
           if (moneyAni) {
-            moneyAni.playRewardAnimation(rewards.coins, rewards.diamonds, () => {
+            moneyAni.playRewardAnimation(rewards.money, rewards.diamonds, () => {
               console.log('奖励动画播放完成');
             });
           } else {
             console.error('MoneyAni组件未找到');
             // 使用静态方法作为备选
-            MoneyAni.playReward(rewards.coins, rewards.diamonds);
+            MoneyAni.playReward(rewards.money, rewards.diamonds);
           }
         } else {
           console.warn('MoneyAni节点未设置,使用静态方法播放动画');
-          MoneyAni.playReward(rewards.coins, rewards.diamonds);
+          MoneyAni.playReward(rewards.money, rewards.diamonds);
         }
       } else {
         console.log('当前关卡没有奖励或奖励为0');