|
|
@@ -10,57 +10,221 @@ const { ccclass, property } = _decorator;
|
|
|
export class EnemyComponent extends Component {
|
|
|
public enemyConfig: EnemyConfig = null;
|
|
|
public spawner: any = null; // 对生成器的引用
|
|
|
+ private rageActive: boolean = false;
|
|
|
+ private rageStartTime: number = 0;
|
|
|
|
|
|
// 获取敌人生命值
|
|
|
public getHealth(): number {
|
|
|
- return this.enemyConfig?.health || 100;
|
|
|
+ return this.enemyConfig?.stats?.health || 100;
|
|
|
}
|
|
|
|
|
|
// 获取敌人速度
|
|
|
public getSpeed(): number {
|
|
|
- return this.enemyConfig?.speed || 50;
|
|
|
+ return this.enemyConfig?.stats?.speed || 50;
|
|
|
}
|
|
|
|
|
|
// 获取敌人伤害
|
|
|
public getDamage(): number {
|
|
|
- return this.enemyConfig?.attack || 20;
|
|
|
+ return this.enemyConfig?.combat?.attackDamage || 20;
|
|
|
}
|
|
|
|
|
|
// 获取敌人攻击范围
|
|
|
public getAttackRange(): number {
|
|
|
- return this.enemyConfig?.range || 30;
|
|
|
+ return this.enemyConfig?.combat?.attackRange || 30;
|
|
|
}
|
|
|
|
|
|
// 获取敌人攻击速度
|
|
|
public getAttackSpeed(): number {
|
|
|
- return this.enemyConfig?.attackSpeed || 1.0;
|
|
|
+ return this.enemyConfig?.combat?.attackSpeed || 1.0;
|
|
|
}
|
|
|
|
|
|
// 获取敌人防御力
|
|
|
public getDefense(): number {
|
|
|
- return this.enemyConfig?.defense || 0;
|
|
|
+ return this.enemyConfig?.stats?.defense || 0;
|
|
|
}
|
|
|
|
|
|
// 获取击杀奖励
|
|
|
public getCoinReward(): number {
|
|
|
- return this.enemyConfig?.goldReward || 10;
|
|
|
+ return this.enemyConfig?.stats?.dropEnergy || 1;
|
|
|
}
|
|
|
|
|
|
+ // === 移动相关配置 ===
|
|
|
// 获取移动类型
|
|
|
public getMovementType(): string {
|
|
|
- return this.enemyConfig?.movement?.type || 'straight';
|
|
|
+ return this.enemyConfig?.movement?.moveType || 'straight';
|
|
|
}
|
|
|
|
|
|
// 获取移动模式
|
|
|
public getMovementPattern(): string {
|
|
|
- return this.enemyConfig?.movement?.pattern || 'walk_forward';
|
|
|
+ return this.enemyConfig?.movement?.pattern || 'direct';
|
|
|
}
|
|
|
|
|
|
+ // 获取摆动幅度
|
|
|
+ public getSwingAmplitude(): number {
|
|
|
+ return this.enemyConfig?.movement?.swingAmplitude || 0.0;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取摆动频率
|
|
|
+ public getSwingFrequency(): number {
|
|
|
+ return this.enemyConfig?.movement?.swingFrequency || 0.0;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取速度变化
|
|
|
+ public getSpeedVariation(): number {
|
|
|
+ return this.enemyConfig?.movement?.speedVariation || 0.1;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取旋转速度
|
|
|
+ public getRotationSpeed(): number {
|
|
|
+ return this.enemyConfig?.movement?.rotationSpeed || 180.0;
|
|
|
+ }
|
|
|
+
|
|
|
+ // === 战斗相关配置 ===
|
|
|
// 获取攻击类型
|
|
|
public getAttackType(): string {
|
|
|
return this.enemyConfig?.combat?.attackType || 'melee';
|
|
|
}
|
|
|
|
|
|
+ // 获取攻击冷却时间
|
|
|
+ public getAttackCooldown(): number {
|
|
|
+ return this.enemyConfig?.combat?.attackCooldown || 2.0;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取攻击延迟
|
|
|
+ public getAttackDelay(): number {
|
|
|
+ return this.enemyConfig?.combat?.attackDelay || 1.0;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取武器类型
|
|
|
+ public getWeaponType(): string {
|
|
|
+ return this.enemyConfig?.combat?.weaponType || 'none';
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取投掷物类型
|
|
|
+ public getProjectileType(): string {
|
|
|
+ return this.enemyConfig?.combat?.projectileType || 'none';
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取投掷物速度
|
|
|
+ public getProjectileSpeed(): number {
|
|
|
+ return this.enemyConfig?.combat?.projectileSpeed || 100.0;
|
|
|
+ }
|
|
|
+
|
|
|
+ // === 格挡系统 ===
|
|
|
+ // 是否可以格挡
|
|
|
+ public canBlock(): boolean {
|
|
|
+ return this.enemyConfig?.combat?.canBlock || false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取格挡几率
|
|
|
+ public getBlockChance(): number {
|
|
|
+ return this.enemyConfig?.combat?.blockChance || 0.0;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取格挡伤害减免
|
|
|
+ public getBlockDamageReduction(): number {
|
|
|
+ return this.enemyConfig?.combat?.blockDamageReduction || 0.5;
|
|
|
+ }
|
|
|
+
|
|
|
+ // === 狂暴系统 ===
|
|
|
+ // 是否有狂暴能力
|
|
|
+ public hasRage(): boolean {
|
|
|
+ return this.enemyConfig?.boss?.rage_threshold > 0 || false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取狂暴触发血量阈值
|
|
|
+ public getRageThreshold(): number {
|
|
|
+ return this.enemyConfig?.boss?.rage_threshold || 0.3;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取狂暴触发血量阈值(别名方法)
|
|
|
+ public getRageTriggerThreshold(): number {
|
|
|
+ return this.getRageThreshold();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取狂暴伤害倍率
|
|
|
+ public getRageDamageMultiplier(): number {
|
|
|
+ return this.enemyConfig?.boss?.rage_damage_multiplier || 1.5;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取狂暴速度倍率
|
|
|
+ public getRageSpeedMultiplier(): number {
|
|
|
+ return this.enemyConfig?.boss?.rage_speed_multiplier || 1.3;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取狂暴持续时间
|
|
|
+ public getRageDuration(): number {
|
|
|
+ return 10.0; // 固定持续时间
|
|
|
+ }
|
|
|
+
|
|
|
+ // === 特殊能力 ===
|
|
|
+ // 获取特殊能力类型
|
|
|
+ public getSpecialAbility(): string {
|
|
|
+ if (this.enemyConfig?.special_abilities && this.enemyConfig.special_abilities.length > 0) {
|
|
|
+ return this.enemyConfig.special_abilities[0].type || 'none';
|
|
|
+ }
|
|
|
+ return 'none';
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取特殊能力冷却时间
|
|
|
+ public getSpecialAbilityCooldown(): number {
|
|
|
+ if (this.enemyConfig?.special_abilities && this.enemyConfig.special_abilities.length > 0) {
|
|
|
+ return this.enemyConfig.special_abilities[0].cooldown || 5.0;
|
|
|
+ }
|
|
|
+ return 5.0;
|
|
|
+ }
|
|
|
+
|
|
|
+ // === 狂暴状态管理 ===
|
|
|
+ // 检查是否处于狂暴状态
|
|
|
+ public isInRage(): boolean {
|
|
|
+ if (!this.rageActive) return false;
|
|
|
+
|
|
|
+ // 检查狂暴是否过期
|
|
|
+ const currentTime = Date.now();
|
|
|
+ const rageDuration = this.getRageDuration() * 1000; // 转换为毫秒
|
|
|
+
|
|
|
+ if (currentTime - this.rageStartTime > rageDuration) {
|
|
|
+ this.endRage();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 触发狂暴状态
|
|
|
+ public triggerRage(): void {
|
|
|
+ if (!this.hasRage()) return;
|
|
|
+
|
|
|
+ this.rageActive = true;
|
|
|
+ this.rageStartTime = Date.now();
|
|
|
+ console.log(`[EnemyComponent] 狂暴状态激活,持续时间: ${this.getRageDuration()}秒`);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 结束狂暴状态
|
|
|
+ public endRage(): void {
|
|
|
+ this.rageActive = false;
|
|
|
+ this.rageStartTime = 0;
|
|
|
+ console.log(`[EnemyComponent] 狂暴状态结束`);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取当前攻击力(考虑狂暴加成)
|
|
|
+ public getCurrentAttackPower(): number {
|
|
|
+ const baseDamage = this.getDamage();
|
|
|
+ if (this.isInRage()) {
|
|
|
+ return baseDamage * this.getRageDamageMultiplier();
|
|
|
+ }
|
|
|
+ return baseDamage;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取当前移动速度(考虑狂暴加成)
|
|
|
+ public getCurrentSpeed(): number {
|
|
|
+ const baseSpeed = this.getSpeed();
|
|
|
+ if (this.isInRage()) {
|
|
|
+ return baseSpeed * this.getRageSpeedMultiplier();
|
|
|
+ }
|
|
|
+ return baseSpeed;
|
|
|
+ }
|
|
|
+
|
|
|
// 获取动画配置
|
|
|
public getAnimations(): any {
|
|
|
return this.enemyConfig?.visualConfig?.animations || {};
|
|
|
@@ -73,29 +237,13 @@ export class EnemyComponent extends Component {
|
|
|
|
|
|
// 检查是否有特殊能力
|
|
|
public hasSpecialAbility(abilityType: string): boolean {
|
|
|
- if (!this.enemyConfig || !this.enemyConfig.specialAbilities) return false;
|
|
|
- return this.enemyConfig.specialAbilities.indexOf(abilityType) !== -1;
|
|
|
+ if (!this.enemyConfig || !this.enemyConfig.special_abilities) return false;
|
|
|
+ return this.enemyConfig.special_abilities.some(ability => ability.type === abilityType);
|
|
|
}
|
|
|
|
|
|
// 获取特殊配置
|
|
|
- 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;
|
|
|
+ return this.enemyConfig?.boss || null;
|
|
|
}
|
|
|
|
|
|
// 获取敌人信息文本
|
|
|
@@ -104,11 +252,10 @@ export class EnemyComponent extends Component {
|
|
|
|
|
|
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}`;
|
|
|
+ `生命值: ${this.enemyConfig.stats?.health || 0}\n` +
|
|
|
+ `速度: ${this.enemyConfig.stats?.speed || 0}\n` +
|
|
|
+ `伤害: ${this.enemyConfig.combat?.attackDamage || 0}\n` +
|
|
|
+ `攻击范围: ${this.enemyConfig.combat?.attackRange || 0}`;
|
|
|
}
|
|
|
|
|
|
// 死亡时调用
|