Browse Source

技能缓存解决

181404010226 3 tháng trước cách đây
mục cha
commit
941a02b2b4

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 317 - 362
assets/Scenes/GameLevel.scene


+ 2 - 2
assets/resources/data/weapons.json

@@ -454,7 +454,7 @@
       "stats": {
         "damage": 10,
         "fireRate": 10.0,
-        "range": 300,
+        "range": 500,
         "bulletSpeed": 20
       },
       "bulletConfig": {
@@ -486,7 +486,7 @@
           "penetration": 999,
           "ricochetCount": 0,
           "returnToOrigin": true,
-          "returnDelay": 1.0
+          "returnDelay": 2.0
         },
         "visual": {
           "bulletImages": "images/PlantsSprite/004",

+ 27 - 7
assets/scripts/CombatSystem/BulletEffects/BulletLifecycle.ts

@@ -168,11 +168,13 @@ export class BulletLifecycle extends Component {
      */
     private handleReturnTrip(): boolean {
         if (this.state.phase === 'active') {
-            // 首次命中立即开始返程,不再依据pierceLeft
+            // 首次命中敌人立即开始返程
+            console.log(`[BulletLifecycle] 回旋镖命中敌人,开始返回`);
             this.startReturn();
             return false; // 不销毁
         } else if (this.state.phase === 'returning') {
             // 返回途中命中,仅造成伤害不销毁
+            console.log(`[BulletLifecycle] 回旋镖返回途中命中目标`);
             return false;
         }
         return false;
@@ -263,6 +265,7 @@ export class BulletLifecycle extends Component {
             } else if (this.config.type === 'return_trip') {
                 // 回旋镖:首次超距时开始返回;返回途中不再因射程销毁
                 if (this.state.phase === 'active') {
+                    console.log(`[BulletLifecycle] 回旋镖达到最大射程 ${this.config.maxRange},开始返回`);
                     this.startReturn();
                 }
             }
@@ -297,15 +300,20 @@ export class BulletLifecycle extends Component {
      * 更新回旋镖逻辑
      */
     private updateReturnTrip(dt: number) {
-        if (this.state.phase === 'active' && this.state.returnTimer > 0) {
-            this.state.returnTimer -= dt;
-            if (this.state.returnTimer <= 0) {
-                this.startReturn();
+        if (this.state.phase === 'active') {
+            // 检查返回计时器(如果配置了延迟返回)
+            if (this.state.returnTimer > 0) {
+                this.state.returnTimer -= dt;
+                if (this.state.returnTimer <= 0) {
+                    console.log(`[BulletLifecycle] 回旋镖延迟时间到,开始返回`);
+                    this.startReturn();
+                }
             }
         } else if (this.state.phase === 'returning') {
             // 检查是否返回到原点
             const distanceToOrigin = Vec3.distance(this.node.worldPosition, this.state.startPosition);
-            if (distanceToOrigin <= 50) { // 50单位的容差
+            if (distanceToOrigin <= 80) { // 增加容差到80单位,确保能够回收
+                console.log(`[BulletLifecycle] 回旋镖返回到原点,销毁`);
                 this.state.shouldDestroy = true;
             }
         }
@@ -315,12 +323,24 @@ export class BulletLifecycle extends Component {
      * 开始返回
      */
     private startReturn() {
+        if (this.state.phase === 'returning') {
+            return; // 避免重复调用
+        }
+        
         this.state.phase = 'returning';
+        console.log(`[BulletLifecycle] 回旋镖进入返回阶段`);
         
         const trajectory = this.getComponent(BulletTrajectory);
         if (trajectory) {
+            // 设置返回目标为起始位置
             trajectory.setTargetPosition(this.state.startPosition);
-            trajectory.reverseDirection();
+            
+            // 对于弧线弹道,不需要反转方向,让它自然转向回家
+            // 只有非弧线弹道才需要反转方向
+            const config = (trajectory as any).config;
+            if (config && config.type !== 'arc') {
+                trajectory.reverseDirection();
+            }
         }
     }
     

+ 52 - 16
assets/scripts/CombatSystem/BulletEffects/BulletTrajectory.ts

@@ -306,8 +306,11 @@ export class BulletTrajectory extends Component {
             this.findTarget();
         }
 
-        // 检查是否到达目标位置(用于西瓜炸弹等爆炸武器)
-        if (this.state.targetPosition) {
+        // 检查是否到达目标位置(仅用于西瓜炸弹等爆炸武器,回旋镖不适用)
+        const lifecycle = this.getComponent('BulletLifecycle') as any;
+        const isBoomerang = lifecycle && lifecycle.getState && lifecycle.getState().phase !== undefined;
+        
+        if (this.state.targetPosition && !isBoomerang) {
             const currentPos = this.node.worldPosition;
             const distanceToTarget = Vec3.distance(currentPos, this.state.targetPosition);
             
@@ -326,7 +329,6 @@ export class BulletTrajectory extends Component {
                 }
                 
                 // 然后通知生命周期组件触发爆炸
-                const lifecycle = this.getComponent('BulletLifecycle') as any;
                 if (lifecycle && typeof lifecycle.onHit === 'function') {
                     lifecycle.onHit(this.node); // 触发爆炸逻辑
                 }
@@ -334,23 +336,57 @@ export class BulletTrajectory extends Component {
             }
         }
 
-        // 每帧计算目标方向,使得弹道持续朝向敌人
-        if (this.targetNode && this.targetNode.isValid) {
-            const pos = this.node.worldPosition;
-            const dirToTarget = this.targetNode.worldPosition.clone().subtract(pos).normalize();
-            this.arcTargetDir.set(dirToTarget);
-            
-            // 更新目标位置为当前敌人位置
-            this.state.targetPosition = this.targetNode.worldPosition.clone();
-        } else if (!this.state.targetPosition) {
-            // 如果没有目标且没有记录的目标位置,设置一个默认的前方位置
-            const defaultTarget = this.node.worldPosition.clone().add(this.arcDir.clone().multiplyScalar(200));
-            this.state.targetPosition = defaultTarget;
+        // 根据回旋镖状态决定目标方向
+        if (isBoomerang && lifecycle.getState().phase === 'returning') {
+            // 返回阶段:朝向起始位置
+             const pos = this.node.worldPosition;
+             const startPos = this.state.startPosition || pos; // 防止空指针
+             const dirToHome = startPos.clone().subtract(pos).normalize();
+             this.arcTargetDir.set(dirToHome);
+             
+             // 更新目标位置为起始位置
+             this.state.targetPosition = startPos.clone();
+        } else {
+            // 主动追踪阶段:朝向敌人
+            if (this.targetNode && this.targetNode.isValid) {
+                const pos = this.node.worldPosition;
+                const dirToTarget = this.targetNode.worldPosition.clone().subtract(pos).normalize();
+                this.arcTargetDir.set(dirToTarget);
+                
+                // 对于回旋镖,检查是否足够接近敌人来触发命中
+                if (isBoomerang) {
+                    const distanceToEnemy = Vec3.distance(pos, this.targetNode.worldPosition);
+                    if (distanceToEnemy <= 30) { // 30像素内算命中
+                        // 触发命中效果
+                        const hitEffect = this.getComponent('BulletHitEffect') as any;
+                        if (hitEffect && typeof hitEffect.processHit === 'function') {
+                            hitEffect.processHit(this.targetNode, pos);
+                        }
+                        
+                        // 通知生命周期组件处理命中
+                        if (lifecycle && typeof lifecycle.onHit === 'function') {
+                            lifecycle.onHit(this.targetNode);
+                        }
+                    }
+                }
+                
+                // 更新目标位置为当前敌人位置
+                this.state.targetPosition = this.targetNode.worldPosition.clone();
+            } else if (!this.state.targetPosition) {
+                // 如果没有目标且没有记录的目标位置,设置一个默认的前方位置
+                const defaultTarget = this.node.worldPosition.clone().add(this.arcDir.clone().multiplyScalar(200));
+                this.state.targetPosition = defaultTarget;
+            }
         }
 
         // 根据与目标距离动态调整转向速率:越近转得越快,避免打圈
         let rotateFactor = (this.config.rotateSpeed ?? 0.5) * dt;
-        if (this.targetNode && this.targetNode.isValid) {
+        
+        if (isBoomerang && lifecycle.getState().phase === 'returning') {
+            // 回旋镖返回阶段:使用固定的转向速率,确保平滑返回
+            rotateFactor *= 1.5; // 返回时适中的转向速率
+        } else if (this.targetNode && this.targetNode.isValid) {
+            // 主动追踪阶段:根据距离调整转向速率
             const distance = Vec3.distance(this.node.worldPosition, this.targetNode.worldPosition);
             rotateFactor *= (2000 / Math.max(distance, 50));
         }

+ 8 - 1
assets/scripts/CombatSystem/EnemyController.ts

@@ -9,6 +9,7 @@ import { LevelConfigManager } from '../LevelSystem/LevelConfigManager';
 import EventBus, { GameEvents } from '../Core/EventBus';
 import { Wall } from './Wall';
 import { BurnEffect } from './BulletEffects/BurnEffect';
+import { Audio } from '../AudioManager/AudioManager';
 const { ccclass, property } = _decorator;
 
 
@@ -508,7 +509,13 @@ export class EnemyController extends BaseSingleton {
         // 确保先取消之前的定时器,避免重复调度
         this.unschedule(this.spawnEnemy);
         
-        // 开始生成敌人
+        // 播放游戏开始音效
+        Audio.playUISound('data/弹球音效/start zombie');
+        
+        // 立即生成第一个敌人,与音效同步
+        this.spawnEnemy();
+        
+        // 然后按间隔生成后续敌人
         this.schedule(this.spawnEnemy, this.spawnInterval);
         
         // 触发敌人生成开始事件

+ 8 - 1
assets/scripts/CombatSystem/WeaponBullet.ts

@@ -317,7 +317,14 @@ export class WeaponBullet extends Component {
         
         // 初始化生命周期组件
         this.bulletLifecycle = this.getComponent(BulletLifecycle) || this.addComponent(BulletLifecycle);
-        this.bulletLifecycle.init(config.lifecycle, initData.firePosition);
+        
+        // 为回旋镖类型的武器设置maxRange,如果配置中没有设置的话
+        const lifecycleConfig = { ...config.lifecycle };
+        if (lifecycleConfig.type === 'return_trip' && !lifecycleConfig.maxRange && this.weaponConfig.stats.range) {
+            lifecycleConfig.maxRange = this.weaponConfig.stats.range;
+        }
+        
+        this.bulletLifecycle.init(lifecycleConfig, initData.firePosition);
         
         // 设置碰撞监听
         this.setupCollisionListener();

+ 0 - 3
assets/scripts/FourUI/MainSystem/MainUIControlller.ts

@@ -156,9 +156,6 @@ export class MainUIController extends Component {
   }
 
   private onBattle () {
-    // 播放游戏开始音效
-    Audio.playUISound('data/弹球音效/start zombie');
-    console.log('[MainUIController] 播放游戏开始音效');
     // 停止主界面背景音乐,避免与游戏内音效冲突
     Audio.stopMusic();
     // 播放战斗背景音乐,音量较小

+ 7 - 7
assets/scripts/FourUI/SkillSystem/SkillNodeGenerator.ts

@@ -26,7 +26,6 @@ interface SkillNodeData {
  */
 @ccclass('SkillNodeGenerator')
 export class SkillNodeGenerator extends Component {
-    
     @property(Prefab)
     skillNode1Prefab: Prefab = null!; // Damage
     
@@ -101,11 +100,6 @@ export class SkillNodeGenerator extends Component {
         // 更新进度条
         this.updateProgressBar();
         
-        // 延迟一帧后滚动到最新解锁的技能节点,确保所有节点都已正确布局
-        this.scheduleOnce(() => {
-            this.scrollToLatestUnlockedSkill();
-        }, 0.1);
-        
         // 更新钻石UI显示
         this.updateDiamondUI();
         
@@ -247,6 +241,12 @@ export class SkillNodeGenerator extends Component {
      * 技能节点点击事件处理
      */
     private onSkillNodeClick(skillNodeData: SkillNodeData) {
+        
+        // 延迟一帧后滚动到最新解锁的技能节点,确保所有节点都已正确布局
+        this.scheduleOnce(() => {
+            this.scrollToLatestUnlockedSkill();
+        }, 1);
+        
         // 计算当前节点的索引
         const nodeIndex = (skillNodeData.group - 1) * 3 + skillNodeData.skillIndex;
         
@@ -587,7 +587,7 @@ export class SkillNodeGenerator extends Component {
                 } else {
                     // 如果没有解锁技能,滚动到顶部
                     this.scrollView.scrollToPercentVertical(0, 0.3, true);
-                    console.log('滚动到部');
+                    console.log('滚动到部');
                 }
             } else {
                 console.warn('ScrollView not assigned in inspector');

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác