|
|
@@ -6,6 +6,7 @@ import { HPBarAnimation } from '../Animations/HPBarAnimation';
|
|
|
import { EnemyComponent } from './EnemyComponent';
|
|
|
import { EnemyAudio } from '../AudioManager/EnemyAudios';
|
|
|
import { ScreenShakeManager } from './EnemyWeapon/ScreenShakeManager';
|
|
|
+
|
|
|
import EventBus, { GameEvents } from '../Core/EventBus';
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
@@ -81,6 +82,7 @@ export class EnemyInstance extends Component {
|
|
|
|
|
|
// 攻击属性
|
|
|
public attackInterval: number = 0; // 攻击间隔(秒),从配置文件读取
|
|
|
+ public attackRange: number = 0; // 攻击范围,从配置文件读取
|
|
|
private attackTimer: number = 0;
|
|
|
|
|
|
// 对控制器的引用
|
|
|
@@ -913,6 +915,11 @@ export class EnemyInstance extends Component {
|
|
|
|
|
|
// 重置攻击计时器
|
|
|
this.attackTimer = this.attackInterval;
|
|
|
+ } else {
|
|
|
+ // 攻击冷却期间播放待机动画(只有在不播放攻击动画时)
|
|
|
+ if (!this.isPlayingAttackAnimation) {
|
|
|
+ this.playIdleAnimationSafe();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -979,7 +986,10 @@ export class EnemyInstance extends Component {
|
|
|
|
|
|
// 在动画播放到90%时发射抛掷物,让抛掷物发射与动画同步
|
|
|
const projectileFireTime = animationDuration * 0.9;
|
|
|
+
|
|
|
+ // 在动画播放到90%时发射抛掷物
|
|
|
this.scheduleOnce(() => {
|
|
|
+ // 发射抛掷物
|
|
|
this.fireProjectile();
|
|
|
}, projectileFireTime);
|
|
|
|
|
|
@@ -1401,15 +1411,18 @@ export class EnemyInstance extends Component {
|
|
|
console.log(`[EnemyInstance] 敌人 ${this.getEnemyName()} 进入${attackTypeStr}范围,距离墙体 ${wallNode.name}: ${distance.toFixed(2)},攻击范围: ${attackRange}`);
|
|
|
|
|
|
if (isRangedAttack) {
|
|
|
- // 远程攻击:切换到攻击状态,继续移动并发射抛掷物
|
|
|
- this.state = EnemyState.ATTACKING;
|
|
|
+ // 远程攻击:切换到待机状态,停止移动并轮流播放攻击和待机动画
|
|
|
+ this.state = EnemyState.IDLE;
|
|
|
this.attackTimer = 0; // 立即开始攻击
|
|
|
this.collidedWall = wallNode; // 记录目标墙体
|
|
|
|
|
|
- // 远程攻击时继续播放walk动画,不停止移动
|
|
|
- this.playWalkAnimation();
|
|
|
+ // 停止移动
|
|
|
+ this.stopRigidBodyMovement();
|
|
|
+
|
|
|
+ // 切换到待机动画
|
|
|
+ this.playIdleAnimation();
|
|
|
|
|
|
- console.log(`[EnemyInstance] 远程敌人 ${this.getEnemyName()} 进入攻击状态,继续移动并播放walk动画`);
|
|
|
+ console.log(`[EnemyInstance] 远程敌人 ${this.getEnemyName()} 进入待机状态,停止移动并准备攻击`);
|
|
|
} else {
|
|
|
// 近战攻击:切换到待机状态,停止移动
|
|
|
this.state = EnemyState.IDLE;
|