|
@@ -1,4 +1,4 @@
|
|
|
-import { BoxCollider, Component, ITriggerEvent, Node, Vec3, _decorator, randomRange } from 'cc';
|
|
|
+import { BoxCollider, Component, ITriggerEvent, Node, Tween, Vec3, _decorator, randomRange } from 'cc';
|
|
|
import { PathfindingManager } from '../Manager/PathfindingManager';
|
|
|
import { PlayerStatus, TornadoComponent } from './TornadoComponent';
|
|
|
import { PropStatus } from './PropComponent';
|
|
@@ -48,8 +48,7 @@ export class TornadoAIComponent extends TornadoComponent {
|
|
|
//text:名称 range:检测半径 move_juge:移动概率 move_time:移动时间 escape_time:逃跑时间 pursuit_1:追击玩家概率 pursuit_2:追击AI概率 pursuit_time:追击时间
|
|
|
const { text, range, move_judge, move_time, escape_time, pursuit_1, pursuit_2, pursuit_time } = aiConfig.data;
|
|
|
this.playerInfo.nickName = text;
|
|
|
- this.playerInfo.level = 2;
|
|
|
- this.currentLv = this.playerInfo.level;
|
|
|
+ this.playerInfo.level = this.currentLv;
|
|
|
|
|
|
this.moveDuration = Math.floor(move_time[0] + Math.random() * (move_time[1] - move_time[0] + 1));
|
|
|
this.escapeDuration = Math.floor(escape_time[0] + Math.random() * (escape_time[1] - escape_time[0] + 1));
|
|
@@ -62,7 +61,7 @@ export class TornadoAIComponent extends TornadoComponent {
|
|
|
this.attack = this.attributeBonusMgr.getStormSunderAttack(this.currentLv, true);
|
|
|
this.speed = this.attributeBonusMgr.getStormSunderSpeed(this.currentLv, true);
|
|
|
|
|
|
- console.log(`AI 攻击力:${this.attack} 速度:${this.speed} 下一级经验:${this.nextExp}`)
|
|
|
+ // console.log(`AI 攻击力:${this.attack} 速度:${this.speed} 下一级经验:${this.nextExp}`);
|
|
|
}
|
|
|
|
|
|
/** 选择 AI 行为 */
|
|
@@ -101,7 +100,7 @@ export class TornadoAIComponent extends TornadoComponent {
|
|
|
const targetPosition = this.node.position.clone().add(randomDirection);
|
|
|
|
|
|
PathfindingManager.getInstance().moveTo(this.node, targetPosition, this.moveDuration);
|
|
|
- console.log(`AI 触发随机移动行为!`, targetPosition);
|
|
|
+ // console.log(`AI 触发随机移动行为!`, targetPosition);
|
|
|
|
|
|
this.scheduleOnce(() => {
|
|
|
if (!this.isChasing && !this.isEscaping) { // 再次检查状态,避免重复调用
|
|
@@ -111,13 +110,16 @@ export class TornadoAIComponent extends TornadoComponent {
|
|
|
}
|
|
|
|
|
|
protected onTriggerEnter(event: ITriggerEvent): void {
|
|
|
- // super.onTriggerEnter(event);
|
|
|
if (event.otherCollider.getGroup() === 1 << 2) {
|
|
|
this.unscheduleAllCallbacks();
|
|
|
this.isChasing = false;
|
|
|
this.isEscaping = false;
|
|
|
this.targetNode = null;
|
|
|
- this.decideAction();
|
|
|
+ Tween.stopAllByTarget(this.node);
|
|
|
+
|
|
|
+ this.setPositionByObstacle(event, () => {
|
|
|
+ this.decideAction();
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -138,7 +140,7 @@ export class TornadoAIComponent extends TornadoComponent {
|
|
|
|
|
|
protected addExpByKill() {
|
|
|
super.addExpByKill(true);
|
|
|
- console.log(`AI 当前经验:${this.currentExp}`);
|
|
|
+ // console.log(`AI 当前经验:${this.currentExp}`);
|
|
|
}
|
|
|
|
|
|
/** 触发器检测(过程中遇到其他龙卷风) */
|
|
@@ -220,7 +222,8 @@ export class TornadoAIComponent extends TornadoComponent {
|
|
|
const maxDistance = this.speed * this.escapeDuration;
|
|
|
|
|
|
// 计算逃离方向,指向目标的反方向
|
|
|
- const direction = this.node.position.clone().subtract(target.position).normalize().multiplyScalar(maxDistance);
|
|
|
+ const targetPos = new Vec3(target.position.x, 0, target.position.z);
|
|
|
+ const direction = this.node.position.clone().subtract(targetPos).normalize().multiplyScalar(maxDistance);
|
|
|
const escapePosition = this.node.position.clone().add(direction);
|
|
|
|
|
|
PathfindingManager.getInstance().moveTo(this.node, escapePosition, this.escapeDuration);
|