WeaponComponent.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { _decorator, Component } from 'cc';
  2. import { WeaponConfig } from '../Core/ConfigManager';
  3. const { ccclass } = _decorator;
  4. /**
  5. * 武器组件
  6. * 用于存储方块的武器配置信息
  7. */
  8. @ccclass('WeaponComponent')
  9. export class WeaponComponent extends Component {
  10. public weaponConfig: WeaponConfig = null;
  11. // 获取武器伤害
  12. public getDamage(): number {
  13. return this.weaponConfig?.stats?.damage || 0;
  14. }
  15. // 获取武器射速
  16. public getFireRate(): number {
  17. return this.weaponConfig?.stats?.fireRate || 1.0;
  18. }
  19. // 获取武器射程
  20. public getRange(): number {
  21. return this.weaponConfig?.stats?.range || 100;
  22. }
  23. // 获取子弹速度
  24. public getBulletSpeed(): number {
  25. return this.weaponConfig?.stats?.bulletSpeed || 100;
  26. }
  27. // 获取穿透数量
  28. public getPenetration(): number {
  29. return this.weaponConfig?.stats?.penetration || 1;
  30. }
  31. // 获取精准度
  32. public getAccuracy(): number {
  33. return this.weaponConfig?.stats?.accuracy || 1.0;
  34. }
  35. // 获取子弹预制体路径
  36. public getBulletPrefab(): string {
  37. return this.weaponConfig?.bulletConfig?.bulletPrefab || '';
  38. }
  39. // 获取攻击模式
  40. public getAttackPattern(): any {
  41. return this.weaponConfig?.attackPattern || null;
  42. }
  43. // 检查是否有特殊能力
  44. public hasSpecialAbility(abilityType: string): boolean {
  45. if (!this.weaponConfig) return false;
  46. switch (abilityType) {
  47. case 'explosive':
  48. return this.weaponConfig.type === 'explosive';
  49. case 'piercing':
  50. return this.weaponConfig.type === 'piercing';
  51. case 'ricochet':
  52. return this.weaponConfig.type === 'ricochet_piercing';
  53. case 'homing':
  54. return this.weaponConfig.type === 'homing_missile';
  55. case 'area_burn':
  56. return this.weaponConfig.type === 'area_burn';
  57. default:
  58. return false;
  59. }
  60. }
  61. // 获取武器信息文本
  62. public getWeaponInfo(): string {
  63. if (!this.weaponConfig) return '未知武器';
  64. return `${this.weaponConfig.name}\n` +
  65. `类型: ${this.weaponConfig.type}\n` +
  66. `稀有度: ${this.weaponConfig.rarity}\n` +
  67. `伤害: ${this.weaponConfig.stats.damage}\n` +
  68. `射速: ${this.weaponConfig.stats.fireRate}\n` +
  69. `射程: ${this.weaponConfig.stats.range}`;
  70. }
  71. }