import { _decorator, Component } from 'cc'; import { WeaponConfig } from '../Core/ConfigManager'; const { ccclass } = _decorator; /** * 武器组件 * 用于存储方块的武器配置信息 */ @ccclass('WeaponComponent') export class WeaponComponent extends Component { public weaponConfig: WeaponConfig = null; // 获取武器伤害 public getDamage(): number { return this.weaponConfig?.stats?.damage || 0; } // 获取武器射速 public getFireRate(): number { return this.weaponConfig?.stats?.fireRate || 1.0; } // 获取武器射程 public getRange(): number { return this.weaponConfig?.stats?.range || 100; } // 获取子弹速度 public getBulletSpeed(): number { return this.weaponConfig?.stats?.bulletSpeed || 50; } // 获取穿透数量 public getPenetration(): number { return this.weaponConfig?.stats?.penetration || 1; } // 获取精准度 public getAccuracy(): number { return this.weaponConfig?.stats?.accuracy || 1.0; } // 获取子弹预制体路径 public getBulletPrefab(): string { return this.weaponConfig?.bulletConfig?.bulletPrefab || ''; } // 获取攻击模式 public getAttackPattern(): any { return this.weaponConfig?.attackPattern || null; } // 检查是否有特殊能力 public hasSpecialAbility(abilityType: string): boolean { if (!this.weaponConfig) return false; switch (abilityType) { case 'explosive': return this.weaponConfig.type === 'explosive'; case 'piercing': return this.weaponConfig.type === 'piercing'; case 'ricochet': return this.weaponConfig.type === 'ricochet_piercing'; case 'homing': return this.weaponConfig.type === 'homing_missile'; case 'area_burn': return this.weaponConfig.type === 'area_burn'; default: return false; } } // 获取武器信息文本 public getWeaponInfo(): string { if (!this.weaponConfig) return '未知武器'; return `${this.weaponConfig.name}\n` + `类型: ${this.weaponConfig.type}\n` + `稀有度: ${this.weaponConfig.rarity}\n` + `伤害: ${this.weaponConfig.stats.damage}\n` + `射速: ${this.weaponConfig.stats.fireRate}\n` + `射程: ${this.weaponConfig.stats.range}`; } }