Przeglądaj źródła

解决子弹发射问题(距离问题)

181404010226 4 miesięcy temu
rodzic
commit
0abf10389b

+ 77 - 20
assets/scripts/CombatSystem/BallController.ts

@@ -6,6 +6,7 @@ import EventBus, { GameEvents } from '../Core/EventBus';
 import { PersistentSkillManager } from '../FourUI/SkillSystem/PersistentSkillManager';
 import { BallAni } from '../Animations/BallAni';
 import { BallControllerConfig } from '../Core/ConfigManager';
+import { WeaponInfo } from './BlockSelection/WeaponInfo';
 const { ccclass, property } = _decorator;
 
 @ccclass('BallController')
@@ -313,8 +314,7 @@ export class BallController extends Component {
         }
         
         // 如果游戏未暂停,则继续执行子弹发射逻辑
-        const weaponConfig: WeaponConfig | null = (blockNode as any)['weaponConfig'] || null;
-        this.createAndFireBullet(fireWorldPos, weaponConfig);
+        this.fireBulletAt(blockNode, fireWorldPos);
     }
 
     // 计算游戏边界(使用GameArea节点)
@@ -905,6 +905,7 @@ export class BallController extends Component {
             eventBus.emit(GameEvents.BALL_FIRE_BULLET, { canFire: (value: boolean) => { canFire = value; } });
             
             if (canFire) {
+                
                 const now = performance.now();
                 const lastTime = this.blockFireCooldown.get(otherNode.uuid) || 0;
                 if (now - lastTime > this.FIRE_COOLDOWN * 1000) {
@@ -1144,40 +1145,69 @@ export class BallController extends Component {
     /**
      * 创建并发射子弹 - 使用新的WeaponBullet系统
      * @param firePosition 发射位置(世界坐标)
-     * @param weaponConfig 武器配置
+     * @param weaponNode 武器节点(包含WeaponInfo组件)
      */
-    private createAndFireBullet(firePosition: Vec3, weaponConfig: WeaponConfig | null) {
+    private createAndFireBullet(firePosition: Vec3, weaponNode: Node | null) {
         
         // 确保武器配置加载
         WeaponBullet.loadWeaponsData().then(() => {
-            // 默认使用毛豆射手配置,后续可以根据方块类型动态选择
-            const defaultWeaponId = 'pea_shooter';
-            const finalConfig = weaponConfig || WeaponBullet.getWeaponConfig(defaultWeaponId);
+            let finalConfig: WeaponConfig | null = null;
+            
+            // 优先从武器节点的WeaponInfo组件获取配置
+            if (weaponNode && weaponNode.isValid) {
+                const weaponInfo = weaponNode.getComponent(WeaponInfo);
+                if (weaponInfo) {
+                    finalConfig = weaponInfo.getWeaponConfig();
+                    console.log(`[BallController] 从武器节点获取武器配置: ${finalConfig?.name || '未知'}`);
+                    
+                    // 检查武器是否可以开火
+                    if (!weaponInfo.canFire()) {
+                        console.log(`[BallController] 武器 ${finalConfig?.name || '未知'} 冷却中,无法开火`);
+                        return;
+                    }
+                    
+                    // 记录开火时间
+                    weaponInfo.recordFireTime();
+                }
+            }
+            
+            // 如果没有从武器节点获取到配置,使用默认配置
+            if (!finalConfig) {
+                const defaultWeaponId = 'pea_shooter';
+                finalConfig = WeaponBullet.getWeaponConfig(defaultWeaponId);
+                console.log(`[BallController] 使用默认武器配置: ${defaultWeaponId}`);
+            }
             
             if (!finalConfig) {
+                console.warn(`[BallController] 无法获取武器配置,取消发射`);
                 return;
             }
             
+            // 获取WeaponInfo组件(如果有的话)
+            let weaponInfoComponent: WeaponInfo | null = null;
+            if (weaponNode && weaponNode.isValid) {
+                weaponInfoComponent = weaponNode.getComponent(WeaponInfo);
+            }
+            
             // 创建子弹初始化数据
             const initData: BulletInitData = {
                 weaponId: finalConfig.id,
                 firePosition: firePosition,
                 autoTarget: true,
-                weaponConfig: finalConfig
+                weaponConfig: finalConfig,
+                weaponInfo: weaponInfoComponent
             };
             
             // 验证初始化数据
             if (!WeaponBullet.validateInitData(initData)) {
+                console.warn(`[BallController] 子弹初始化数据验证失败`);
                 return;
             }
             
-            // 判断是否为多发子弹(散射/连发等)
-            const countCfg = finalConfig.bulletConfig.count;
-            // const isMultiShot = countCfg && countCfg.type !== 'single' && countCfg.amount > 1;
-
             // 查找GameArea(子弹统一添加到此节点)
             const gameArea = find('Canvas/GameLevelUI/GameArea');
             if (!gameArea) {
+                console.warn(`[BallController] 未找到GameArea节点,无法发射子弹`);
                 return;
             }
 
@@ -1189,24 +1219,39 @@ export class BallController extends Component {
             const needsContainerPrefab = Boolean(trailEffect) || isSharpCarrot;
             const prefabToUse: Prefab = (needsContainerPrefab && this.bulletContainerPrefab) ? this.bulletContainerPrefab : this.bulletPrefab;
             if (!prefabToUse) {
-                return; // 如果没有可用的预制体则直接退出
+                console.warn(`[BallController] 没有可用的子弹预制体`);
+                return;
             }
 
             // 使用批量创建逻辑
+            console.log(`[BallController] 开始创建子弹 - 武器: ${finalConfig.name}, 预制体: ${prefabToUse ? prefabToUse.name : 'null'}`);
             const bullets = WeaponBullet.createBullets(initData, prefabToUse as any);
-            bullets.forEach(b => {
-                gameArea.addChild(b);
+            console.log(`[BallController] WeaponBullet.createBullets 返回了 ${bullets.length} 个子弹`);
+            
+            bullets.forEach((b, index) => {
+                console.log(`[BallController] 添加第 ${index + 1} 个子弹到场景 - 子弹节点: ${b ? b.name : 'null'}, 是否有效: ${b ? b.isValid : 'false'}`);
+                if (b && b.isValid) {
+                    gameArea.addChild(b);
+                    console.log(`[BallController] 子弹 ${index + 1} 成功添加到场景,世界坐标: ${b.worldPosition}`);
+                } else {
+                    console.error(`[BallController] 子弹 ${index + 1} 无效,无法添加到场景`);
+                }
             });
             
+            console.log(`[BallController] 成功发射 ${bullets.length} 发子弹,武器: ${finalConfig.name}`);
             
         }).catch(error => {
-            // 武器配置加载失败
+            console.error(`[BallController] 武器配置加载失败:`, error);
         });
     }
     
     // 递归查找Weapon节点
     private findWeaponNode(node: Node): Node | null {
-        // logs removed
+        // 检查节点是否有效
+        if (!node || !node.isValid) {
+            console.warn('[BallController] findWeaponNode: 传入的节点无效');
+            return null;
+        }
         
         // 先检查当前节点是否有Weapon子节点
         const weaponNode = node.getChildByName('Weapon');
@@ -1484,15 +1529,27 @@ export class BallController extends Component {
      * 从给定世界坐标发射子弹
      */
     private fireBulletAt(blockNode: Node, fireWorldPos: Vec3) {
+        // 检查方块节点是否有效
+        if (!blockNode || !blockNode.isValid) {
+            console.warn('[BallController] fireBulletAt: 方块节点无效,无法发射子弹');
+            return;
+        }
         
         // 检查子弹预制体是否存在
         if (!this.bulletPrefab) {
+            console.warn(`[BallController] 子弹预制体未设置,无法发射`);
             return;
         }        
         
-        // 直接使用碰撞世界坐标作为发射点
-        const weaponConfig: WeaponConfig | null = (blockNode as any)['weaponConfig'] || null;
-        this.createAndFireBullet(fireWorldPos, weaponConfig);
+        // 查找方块中的武器节点
+        const weaponNode = this.findWeaponNode(blockNode);
+        if (!weaponNode) {
+            const blockName = blockNode && blockNode.isValid ? blockNode.name : 'unknown';
+            console.warn(`[BallController] 方块 ${blockName} 中未找到武器节点`);
+        }
+        
+        // 传递武器节点给createAndFireBullet方法
+        this.createAndFireBullet(fireWorldPos, weaponNode);
     }
 
     /**

+ 48 - 1
assets/scripts/CombatSystem/BlockSelection/WeaponInfo.ts

@@ -37,6 +37,9 @@ export class WeaponInfo extends Component {
     @property({ displayName: "击杀数", readonly: true })
     public killCount: number = 0;
     
+    @property({ displayName: "剩余冷却时间(秒)", readonly: true })
+    public remainingCooldown: number = 0;
+    
     // 武器配置数据
     private _weaponConfig: WeaponConfig | null = null;
     
@@ -80,6 +83,7 @@ export class WeaponInfo extends Component {
         this.activeStatus = this._isActive;
         this.totalDamage = this._totalDamageDealt;
         this.killCount = this._killCount;
+        this.remainingCooldown = 0;
         
         // 如果武器配置中有弹药限制,设置初始弹药数
         if (config.bulletConfig && config.bulletConfig.count) {
@@ -198,14 +202,19 @@ export class WeaponInfo extends Component {
      */
     public canFire(): boolean {
         if (!this._isActive || !this._weaponConfig) {
+            this.remainingCooldown = 0;
             return false;
         }
         
         const currentTime = Date.now() / 1000; // 转换为秒
         const fireRate = this._weaponConfig.stats.fireRate || 1.0;
         const cooldown = 1.0 / fireRate; // 计算冷却时间
+        const timeSinceLastFire = currentTime - this._lastFireTime;
+        
+        // 更新剩余冷却时间
+        this.remainingCooldown = Math.max(0, cooldown - timeSinceLastFire);
         
-        return (currentTime - this._lastFireTime) >= cooldown;
+        return timeSinceLastFire >= cooldown;
     }
     
     /**
@@ -213,6 +222,12 @@ export class WeaponInfo extends Component {
      */
     public recordFireTime(): void {
         this._lastFireTime = Date.now() / 1000;
+        
+        // 开火后立即设置冷却时间
+        if (this._weaponConfig) {
+            const fireRate = this._weaponConfig.stats.fireRate || 1.0;
+            this.remainingCooldown = 1.0 / fireRate;
+        }
     }
     
     /**
@@ -266,6 +281,26 @@ export class WeaponInfo extends Component {
         return this._weaponConfig?.stats.accuracy || 1.0;
     }
     
+    /**
+     * 获取当前剩余冷却时间
+     * @returns 剩余冷却时间(秒)
+     */
+    public getRemainingCooldown(): number {
+        if (!this._isActive || !this._weaponConfig) {
+            return 0;
+        }
+        
+        const currentTime = Date.now() / 1000;
+        const fireRate = this._weaponConfig.stats.fireRate || 1.0;
+        const cooldown = 1.0 / fireRate;
+        const timeSinceLastFire = currentTime - this._lastFireTime;
+        
+        const remaining = Math.max(0, cooldown - timeSinceLastFire);
+        this.remainingCooldown = remaining; // 同时更新编辑器属性
+        
+        return remaining;
+    }
+    
     /**
      * 添加伤害统计
      * @param damage 造成的伤害
@@ -318,6 +353,7 @@ export class WeaponInfo extends Component {
         // 更新编辑器面板可见属性
         this.totalDamage = this._totalDamageDealt;
         this.killCount = this._killCount;
+        this.remainingCooldown = 0;
         
         console.log(`[WeaponInfo] 武器统计数据已重置`);
     }
@@ -387,6 +423,17 @@ export class WeaponInfo extends Component {
         this.activeStatus = this._isActive;
         this.totalDamage = this._totalDamageDealt;
         this.killCount = this._killCount;
+        
+        // 更新剩余冷却时间
+        if (this._weaponConfig && this._isActive) {
+            const currentTime = Date.now() / 1000;
+            const fireRate = this._weaponConfig.stats.fireRate || 1.0;
+            const cooldown = 1.0 / fireRate;
+            const timeSinceLastFire = currentTime - this._lastFireTime;
+            this.remainingCooldown = Math.max(0, cooldown - timeSinceLastFire);
+        } else {
+            this.remainingCooldown = 0;
+        }
     }
     
     /**

+ 38 - 9
assets/scripts/CombatSystem/BulletEffects/BulletLifecycle.ts

@@ -30,6 +30,8 @@ export class BulletLifecycle extends Component {
      * 初始化生命周期
      */
     public init(config: BulletLifecycleConfig, startPos: Vec3) {
+        console.log(`[BulletLifecycle] 初始化子弹生命周期 - 节点: ${this.node.name}, 配置类型: ${config.type}, 最大生命: ${config.maxLifetime}, 最大射程: ${config.maxRange}`);
+        
         this.config = { ...config };
         
         this.state = {
@@ -44,7 +46,8 @@ export class BulletLifecycle extends Component {
             returnTimer: config.returnDelay || 0
         };
         
-        this.lastPosition = this.node.worldPosition.clone();
+        this.lastPosition = startPos.clone();
+        console.log(`[BulletLifecycle] 子弹生命周期初始化完成 - 节点: ${this.node.name}, 起始位置: (${startPos.x}, ${startPos.y}), 当前位置: (${this.node.worldPosition.x}, ${this.node.worldPosition.y}), lastPosition: (${this.lastPosition.x}, ${this.lastPosition.y})`);
     }
     
     /**
@@ -216,7 +219,10 @@ export class BulletLifecycle extends Component {
     }
     
     update(dt: number) {
-        if (!this.config || !this.state) return;
+        if (!this.config || !this.state) {
+            console.log(`[BulletLifecycle] update跳过 - 节点: ${this.node.name}, config存在: ${!!this.config}, state存在: ${!!this.state}`);
+            return;
+        }
         
         this.state.elapsedTime += dt;
         
@@ -231,6 +237,7 @@ export class BulletLifecycle extends Component {
         
         // 如果需要销毁,执行销毁
         if (this.state.shouldDestroy) {
+            console.log(`[BulletLifecycle] 准备销毁子弹 - 节点: ${this.node.name}, 存活时间: ${this.state.elapsedTime}`);
             this.destroyBullet();
         }
     }
@@ -241,6 +248,7 @@ export class BulletLifecycle extends Component {
     private updateTravelDistance() {
         const currentPos = this.node.worldPosition;
         const distance = Vec3.distance(this.lastPosition, currentPos);
+        console.log(`[BulletLifecycle] 更新飞行距离 - 节点: ${this.node.name}, 上次位置: (${this.lastPosition.x}, ${this.lastPosition.y}), 当前位置: (${currentPos.x}, ${currentPos.y}), 本次距离: ${distance}, 总距离: ${this.state.travelDistance} -> ${this.state.travelDistance + distance}`);
         this.state.travelDistance += distance;
         this.lastPosition.set(currentPos);
     }
@@ -249,19 +257,25 @@ export class BulletLifecycle extends Component {
      * 检查销毁条件
      */
     private checkDestroyConditions() {
+        console.log(`[BulletLifecycle] 检查销毁条件 - 节点: ${this.node.name}, 存活时间: ${this.state.elapsedTime}, 最大生命: ${this.config.maxLifetime}, 飞行距离: ${this.state.travelDistance}, 最大射程: ${this.config.maxRange}`);
+        
         // 检查时间限制
         if (this.state.elapsedTime >= this.config.maxLifetime) {
+            console.log(`[BulletLifecycle] 子弹因超时被销毁 - 节点: ${this.node.name}, 存活时间: ${this.state.elapsedTime} >= 最大生命: ${this.config.maxLifetime}`);
             this.state.shouldDestroy = true;
             return;
         }
         
         // === 射程限制逻辑优化 ===
         if (this.config.maxRange && this.state.travelDistance >= this.config.maxRange) {
+            console.log(`[BulletLifecycle] 子弹达到最大射程 - 节点: ${this.node.name}, 飞行距离: ${this.state.travelDistance} >= 最大射程: ${this.config.maxRange}, 类型: ${this.config.type}`);
             if (this.config.type === 'range_limit') {
+                console.log(`[BulletLifecycle] 子弹因射程限制被销毁 - 节点: ${this.node.name}`);
                 this.state.shouldDestroy = true;
             } else if (this.config.type === 'return_trip') {
                 // 回旋镖:首次超距时开始返回;返回途中不再因射程销毁
                 if (this.state.phase === 'active') {
+                    console.log(`[BulletLifecycle] 回旋镖开始返回 - 节点: ${this.node.name}`);
                     this.startReturn();
                 }
             }
@@ -270,10 +284,14 @@ export class BulletLifecycle extends Component {
         }
         
         // 检查越界
-        if (this.checkOutOfBounds()) {
+        const outOfBounds = this.checkOutOfBounds();
+        console.log(`[BulletLifecycle] 越界检查结果 - 节点: ${this.node.name}, 是否越界: ${outOfBounds}, 位置: (${this.node.worldPosition.x}, ${this.node.worldPosition.y})`);
+        if (outOfBounds) {
             if (this.config.type === 'return_trip' && this.state.phase === 'active') {
+                console.log(`[BulletLifecycle] 回旋镖因越界开始返回 - 节点: ${this.node.name}`);
                 this.startReturn();
             } else {
+                console.log(`[BulletLifecycle] 子弹因越界被销毁 - 节点: ${this.node.name}, 位置: (${this.node.worldPosition.x}, ${this.node.worldPosition.y})`);
                 this.state.shouldDestroy = true;
             }
             return;
@@ -333,6 +351,7 @@ export class BulletLifecycle extends Component {
             const tr = gameArea.getComponent(UITransform);
             if (tr) {
                 bounding = tr.getBoundingBoxToWorld();
+                console.log(`[BulletLifecycle] 使用GameArea边界 - 节点: ${this.node.name}, 边界: (${bounding.xMin}, ${bounding.yMin}) 到 (${bounding.xMax}, ${bounding.yMax})`);
             }
         }
 
@@ -343,28 +362,38 @@ export class BulletLifecycle extends Component {
                 const tr = canvas.getComponent(UITransform);
                 if (tr) {
                     bounding = tr.getBoundingBoxToWorld();
+                    console.log(`[BulletLifecycle] 使用Canvas边界 - 节点: ${this.node.name}, 边界: (${bounding.xMin}, ${bounding.yMin}) 到 (${bounding.xMax}, ${bounding.yMax})`);
                 }
             }
         }
 
         // 若无法获取区域,则不做越界销毁
-        if (!bounding) return false;
+        if (!bounding) {
+            console.log(`[BulletLifecycle] 无法获取边界信息 - 节点: ${this.node.name}, 不进行越界检查`);
+            return false;
+        }
 
         // 允许一定的 margin
         const margin = 300; // 扩大容差,防止大速度时瞬移出界
         const pos = this.node.worldPosition;
-
-        return pos.x < bounding.xMin - margin ||
-               pos.x > bounding.xMax + margin ||
-               pos.y < bounding.yMin - margin ||
-               pos.y > bounding.yMax + margin;
+        
+        const outOfBounds = pos.x < bounding.xMin - margin ||
+                           pos.x > bounding.xMax + margin ||
+                           pos.y < bounding.yMin - margin ||
+                           pos.y > bounding.yMax + margin;
+        
+        console.log(`[BulletLifecycle] 越界详细检查 - 节点: ${this.node.name}, 位置: (${pos.x}, ${pos.y}), 边界(含margin): (${bounding.xMin - margin}, ${bounding.yMin - margin}) 到 (${bounding.xMax + margin}, ${bounding.yMax + margin}), 结果: ${outOfBounds}`);
+        
+        return outOfBounds;
     }
     
     /**
      * 销毁子弹
      */
     private destroyBullet() {
+        console.log(`[BulletLifecycle] 执行销毁子弹 - 节点: ${this.node.name}, 存活时间: ${this.state.elapsedTime}, 飞行距离: ${this.state.travelDistance}`);
         this.node.destroy();
+        console.log(`[BulletLifecycle] 子弹已销毁 - 节点: ${this.node.name}`);
     }
     
     /**

+ 51 - 13
assets/scripts/CombatSystem/WeaponBullet.ts

@@ -8,6 +8,7 @@ import { ConfigManager, WeaponConfig, BulletCountConfig, BulletTrajectoryConfig,
 import  EventBus,{ GameEvents } from '../Core/EventBus';
 import { PersistentSkillManager } from '../FourUI/SkillSystem/PersistentSkillManager';
 import { SaveDataManager } from '../LevelSystem/SaveDataManager';
+import { WeaponInfo } from './BlockSelection/WeaponInfo';
 
 const { ccclass, property } = _decorator;
 
@@ -29,6 +30,7 @@ export interface BulletInitData {
     direction?: Vec3;           // 发射方向(可选)
     autoTarget?: boolean;       // 是否自动瞄准
     weaponConfig?: WeaponConfig; // 直接传入的武器配置(优先级更高)
+    weaponInfo?: WeaponInfo;    // WeaponInfo组件实例(用于冷却管理等)
 }
 
 @ccclass('WeaponBullet')
@@ -48,6 +50,7 @@ export class WeaponBullet extends Component {
     // 武器配置和状态
     private weaponConfig: WeaponConfig = null;
     private weaponId: string = null; // 存储武器ID用于获取升级数据
+    private weaponInfo: WeaponInfo = null; // WeaponInfo组件实例
     private isInitialized: boolean = false;
     
     // === 静态武器配置缓存 ===
@@ -159,20 +162,31 @@ export class WeaponBullet extends Component {
         const bullets: Node[] = [];
         
         // 为每个子弹创建实例
+        console.log(`[WeaponBullet] 准备创建 ${spawnInfos.length} 个子弹,预制体: ${bulletPrefab ? bulletPrefab.name : 'null'}`);
         for (const spawnInfo of spawnInfos) {
             const createBullet = () => {
-                const bullet = instantiate(bulletPrefab);
-                const weaponBullet = bullet.getComponent(WeaponBullet) || bullet.addComponent(WeaponBullet);
-                
-                // 初始化子弹
-                weaponBullet.init({
-                    ...initData,
-                    firePosition: spawnInfo.position,
-                    direction: spawnInfo.direction,
-                    weaponConfig: config
-                });
-                
-                bullets.push(bullet);
+                console.log(`[WeaponBullet] 开始实例化子弹预制体: ${bulletPrefab ? bulletPrefab.name : 'null'}`);
+                try {
+                    const bullet = instantiate(bulletPrefab);
+                    console.log(`[WeaponBullet] 子弹实例化成功 - 节点: ${bullet ? bullet.name : 'null'}, 是否有效: ${bullet ? bullet.isValid : 'false'}`);
+                    
+                    const weaponBullet = bullet.getComponent(WeaponBullet) || bullet.addComponent(WeaponBullet);
+                    console.log(`[WeaponBullet] WeaponBullet组件获取/添加成功: ${weaponBullet ? 'true' : 'false'}`);
+                    
+                    // 初始化子弹
+                    weaponBullet.init({
+                        ...initData,
+                        firePosition: spawnInfo.position,
+                        direction: spawnInfo.direction,
+                        weaponConfig: config
+                    });
+                    console.log(`[WeaponBullet] 子弹初始化完成,位置: ${spawnInfo.position}`);
+                    
+                    bullets.push(bullet);
+                    console.log(`[WeaponBullet] 子弹已添加到数组,当前数组长度: ${bullets.length}`);
+                } catch (error) {
+                    console.error(`[WeaponBullet] 子弹创建失败:`, error);
+                }
             };
             
             // 处理延迟发射
@@ -191,11 +205,14 @@ export class WeaponBullet extends Component {
      * 初始化子弹
      */
     public init(initData: BulletInitData) {
+        console.log(`[WeaponBullet] 开始初始化子弹 - 武器ID: ${initData.weaponId}, 节点: ${this.node ? this.node.name : 'null'}`);
+        
         // 通过事件系统检查游戏是否暂停,暂停时不初始化子弹
         let bulletFireEnabled = true;
         EventBus.getInstance().emit(GameEvents.BALL_FIRE_BULLET, { canFire: (result: boolean) => { bulletFireEnabled = result; } });
         
         if (!bulletFireEnabled) {
+            console.log(`[WeaponBullet] 子弹发射被禁用,销毁节点`);
             // 立即销毁自己
             this.node.destroy();
             return;
@@ -208,8 +225,10 @@ export class WeaponBullet extends Component {
             return;
         }
         
-        // 存储武器ID
+        // 存储武器ID和WeaponInfo
         this.weaponId = initData.weaponId;
+        this.weaponInfo = initData.weaponInfo || null;
+        console.log(`[WeaponBullet] 武器ID和WeaponInfo已存储 - 武器ID: ${this.weaponId}`);
         
         // 获取武器配置
         this.weaponConfig = initData.weaponConfig || WeaponBullet.getWeaponConfig(initData.weaponId);
@@ -218,26 +237,38 @@ export class WeaponBullet extends Component {
             this.node.destroy();
             return;
         }
+        console.log(`[WeaponBullet] 武器配置获取成功 - 武器名称: ${this.weaponConfig.name}`);
         
         // 应用技能加成计算运行时数值
         this.calculateRuntimeStats();
+        console.log(`[WeaponBullet] 运行时数值计算完成`);
         
         // 使用世界坐标设置位置
         this.setPositionInGameArea(initData.firePosition);
+        console.log(`[WeaponBullet] 位置设置完成 - 世界坐标: ${initData.firePosition}, 节点位置: ${this.node.position}`);
         
         // 初始化各个组件
+        console.log(`[WeaponBullet] 开始初始化组件`);
         this.initializeComponents(initData);
+        console.log(`[WeaponBullet] 组件初始化完成`);
         
         // 设置子弹外观
+        console.log(`[WeaponBullet] 开始设置子弹外观`);
         this.setupBulletSprite();
+        console.log(`[WeaponBullet] 子弹外观设置完成`);
         
         // 设置子弹效果节点激活状态
+        console.log(`[WeaponBullet] 开始设置子弹效果节点`);
         this.setupBulletEffectNodes();
+        console.log(`[WeaponBullet] 子弹效果节点设置完成`);
         
         // 设置碰撞监听
+        console.log(`[WeaponBullet] 开始设置碰撞监听`);
         this.setupCollisionListener();
+        console.log(`[WeaponBullet] 碰撞监听设置完成`);
         
         this.isInitialized = true;
+        console.log(`[WeaponBullet] 子弹初始化完全完成 - 节点: ${this.node.name}, 位置: ${this.node.position}`);
     }
     
     /**
@@ -461,6 +492,13 @@ export class WeaponBullet extends Component {
         return this.weaponConfig;
     }
     
+    /**
+     * 获取WeaponInfo组件实例
+     */
+    public getWeaponInfo(): WeaponInfo | null {
+        return this.weaponInfo;
+    }
+    
     /**
      * 获取子弹状态信息
      */