| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- import { _decorator, Component } from 'cc';
- import { ConfigManager, EnemyConfig } from '../Core/ConfigManager';
- const { ccclass, property } = _decorator;
- /**
- * 敌人组件
- * 用于存储敌人的配置信息和基础属性
- */
- @ccclass('EnemyComponent')
- export class EnemyComponent extends Component {
- public enemyConfig: EnemyConfig = null;
- public spawner: any = null; // 对生成器的引用
- // 获取敌人生命值
- public getHealth(): number {
- return this.enemyConfig?.health || 100;
- }
- // 获取敌人速度
- public getSpeed(): number {
- return this.enemyConfig?.speed || 50;
- }
- // 获取敌人伤害
- public getDamage(): number {
- return this.enemyConfig?.attack || 20;
- }
- // 获取敌人攻击范围
- public getAttackRange(): number {
- return this.enemyConfig?.range || 30;
- }
- // 获取敌人攻击速度
- public getAttackSpeed(): number {
- return this.enemyConfig?.attackSpeed || 1.0;
- }
- // 获取敌人防御力
- public getDefense(): number {
- return this.enemyConfig?.defense || 0;
- }
- // 获取击杀奖励
- public getCoinReward(): number {
- return this.enemyConfig?.goldReward || 10;
- }
- // 获取移动类型
- public getMovementType(): string {
- return this.enemyConfig?.movement?.type || 'straight';
- }
- // 获取移动模式
- public getMovementPattern(): string {
- return this.enemyConfig?.movement?.pattern || 'walk_forward';
- }
- // 获取攻击类型
- public getAttackType(): string {
- return this.enemyConfig?.combat?.attackType || 'melee';
- }
- // 获取动画配置
- public getAnimations(): any {
- return this.enemyConfig?.visualConfig?.animations || {};
- }
- // 获取音频配置
- public getAudioConfig(): any {
- return this.enemyConfig?.audioConfig || {};
- }
- // 检查是否有特殊能力
- public hasSpecialAbility(abilityType: string): boolean {
- if (!this.enemyConfig || !this.enemyConfig.specialAbilities) return false;
- return this.enemyConfig.specialAbilities.indexOf(abilityType) !== -1;
- }
- // 获取特殊配置
- public getStealthConfig(): any {
- return this.enemyConfig?.stealthConfig || null;
- }
- public getArmorConfig(): any {
- return this.enemyConfig?.armorConfig || null;
- }
- public getExplosionConfig(): any {
- return this.enemyConfig?.explosionConfig || null;
- }
- public getBossConfig(): any {
- return this.enemyConfig?.bossConfig || null;
- }
- public getProjectileConfig(): any {
- return this.enemyConfig?.projectileConfig || null;
- }
- // 获取敌人信息文本
- public getEnemyInfo(): string {
- if (!this.enemyConfig) return '未知敌人';
-
- return `${this.enemyConfig.name}\n` +
- `类型: ${this.enemyConfig.type}\n` +
- `稀有度: ${this.enemyConfig.rarity}\n` +
- `生命值: ${this.enemyConfig.health}\n` +
- `速度: ${this.enemyConfig.speed}\n` +
- `伤害: ${this.enemyConfig.attack}\n` +
- `攻击范围: ${this.enemyConfig.range}`;
- }
- // 死亡时调用
- public onDeath() {
- if (this.spawner && this.spawner.onEnemyDeath) {
- this.spawner.onEnemyDeath(this.node);
- }
- }
- }
|