|
@@ -1,4 +1,4 @@
|
|
-import { BoxCollider, Component, ITriggerEvent, Node, Tween, Vec3, _decorator, randomRange } from 'cc';
|
|
|
|
|
|
+import { BoxCollider, Component, Game, ITriggerEvent, Node, Tween, Vec3, _decorator, randomRange } from 'cc';
|
|
import { PathfindingManager } from '../Manager/PathfindingManager';
|
|
import { PathfindingManager } from '../Manager/PathfindingManager';
|
|
import { PlayerStatus, TornadoComponent } from './TornadoComponent';
|
|
import { PlayerStatus, TornadoComponent } from './TornadoComponent';
|
|
import { GameUtil } from '../GameUtil';
|
|
import { GameUtil } from '../GameUtil';
|
|
@@ -119,8 +119,8 @@ export class TornadoAIComponent extends TornadoComponent {
|
|
}, this.moveDuration);
|
|
}, this.moveDuration);
|
|
}
|
|
}
|
|
|
|
|
|
- protected onTriggerEnter(event: ITriggerEvent): void {
|
|
|
|
- const otherCollider = event.otherCollider;
|
|
|
|
|
|
+ protected override onTriggerEnter(event: ITriggerEvent): void {
|
|
|
|
+
|
|
if (event.otherCollider.getGroup() === 1 << 2) {
|
|
if (event.otherCollider.getGroup() === 1 << 2) {
|
|
this.unscheduleAllCallbacks();
|
|
this.unscheduleAllCallbacks();
|
|
this.isChasing = false;
|
|
this.isChasing = false;
|
|
@@ -131,24 +131,30 @@ export class TornadoAIComponent extends TornadoComponent {
|
|
this.setPositionByObstacle(event, () => {
|
|
this.setPositionByObstacle(event, () => {
|
|
this.decideAction();
|
|
this.decideAction();
|
|
});
|
|
});
|
|
- } else if (event.otherCollider.getGroup() === 1 << 3) {
|
|
|
|
- if (otherCollider.getGroup() == 1 << 3) {
|
|
|
|
- const targetTornado = otherCollider.node.parent.getComponent(TornadoComponent);
|
|
|
|
- if (!targetTornado) return;
|
|
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected onTriggerStay(event: ITriggerEvent): void {
|
|
|
|
+ if (GameMgr.inst.getGameStatus() != GameStatus.Playing) return;
|
|
|
|
+ super.onTriggerStay(event);
|
|
|
|
|
|
- const isPlayer = targetTornado instanceof TornadoComponent;
|
|
|
|
- if (this.currentLv > targetTornado.currentLv && isPlayer) {
|
|
|
|
|
|
+ const otherCollider = event.otherCollider;
|
|
|
|
+ if (event.otherCollider.getGroup() === 1 << 3) {
|
|
|
|
+ const targetTornado = otherCollider.node.parent.getComponent(TornadoComponent);
|
|
|
|
+ if (!targetTornado) return;
|
|
|
|
+
|
|
|
|
+ const distance = Vec3.distance(this.node.worldPosition, otherCollider.node.worldPosition);
|
|
|
|
+ if (distance < 0.2) {
|
|
|
|
+ const isAI = targetTornado.ai;
|
|
|
|
+ if (this.currentLv > targetTornado.currentLv && !isAI) {
|
|
GameMgr.inst.isWin = false;
|
|
GameMgr.inst.isWin = false;
|
|
|
|
+ console.log(`AI 触发碰撞到:${targetTornado.name} isAI:${isAI}`);
|
|
GameMgr.inst.setGameStatus(GameStatus.Revive);
|
|
GameMgr.inst.setGameStatus(GameStatus.Revive);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- protected onTriggerStay(event: ITriggerEvent): void {
|
|
|
|
- super.onTriggerStay(event);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
protected addExpByKill() {
|
|
protected addExpByKill() {
|
|
super.addExpByKill(true);
|
|
super.addExpByKill(true);
|
|
// console.log(`AI 当前经验:${this.currentExp}`);
|
|
// console.log(`AI 当前经验:${this.currentExp}`);
|
|
@@ -156,7 +162,6 @@ export class TornadoAIComponent extends TornadoComponent {
|
|
|
|
|
|
/** 触发器检测(过程中遇到其他龙卷风) */
|
|
/** 触发器检测(过程中遇到其他龙卷风) */
|
|
protected onRadiusTriggerEnter(event: ITriggerEvent): void {
|
|
protected onRadiusTriggerEnter(event: ITriggerEvent): void {
|
|
- if (this.isChasing) return;
|
|
|
|
const otherCollider = event.otherCollider;
|
|
const otherCollider = event.otherCollider;
|
|
const otherNode = otherCollider.node;
|
|
const otherNode = otherCollider.node;
|
|
|
|
|
|
@@ -173,6 +178,7 @@ export class TornadoAIComponent extends TornadoComponent {
|
|
} else if (targetLv < this.currentLv) {
|
|
} else if (targetLv < this.currentLv) {
|
|
// 目标等级比自己低 → 先判断是否追击
|
|
// 目标等级比自己低 → 先判断是否追击
|
|
if (Math.random() * 100 < this.chaseAIProbability) {
|
|
if (Math.random() * 100 < this.chaseAIProbability) {
|
|
|
|
+ this.cancelAction();
|
|
if (isTargetAI) {
|
|
if (isTargetAI) {
|
|
// 目标是 AI,直接追击
|
|
// 目标是 AI,直接追击
|
|
this.chaseTarget(targetTornado.node);
|
|
this.chaseTarget(targetTornado.node);
|
|
@@ -204,24 +210,20 @@ export class TornadoAIComponent extends TornadoComponent {
|
|
/** 追击目标 */
|
|
/** 追击目标 */
|
|
private chaseTarget(target: Node) {
|
|
private chaseTarget(target: Node) {
|
|
if (this.isChasing) return;
|
|
if (this.isChasing) return;
|
|
- // console.log(`AI 追击目标->>>>>>>>>>>>>`);
|
|
|
|
|
|
+ console.log(`AI 追击目标-> ${target.name}}`);
|
|
|
|
|
|
this.isChasing = true;
|
|
this.isChasing = true;
|
|
this.targetNode = target;
|
|
this.targetNode = target;
|
|
|
|
|
|
PathfindingManager.getInstance().followTarget(this, target, this.speed, () => {
|
|
PathfindingManager.getInstance().followTarget(this, target, this.speed, () => {
|
|
// console.log(`AI 追击目标到达`);
|
|
// console.log(`AI 追击目标到达`);
|
|
- this.unscheduleAllCallbacks();
|
|
|
|
- this.isChasing = false;
|
|
|
|
- this.targetNode = null;
|
|
|
|
|
|
+ this.cancelAction();
|
|
this.decideAction();
|
|
this.decideAction();
|
|
});
|
|
});
|
|
|
|
|
|
// 追击时间结束后恢复行为
|
|
// 追击时间结束后恢复行为
|
|
this.scheduleOnce(() => {
|
|
this.scheduleOnce(() => {
|
|
- this.isChasing = false;
|
|
|
|
- this.targetNode = null;
|
|
|
|
- this.decideAction();
|
|
|
|
|
|
+ this.cancelAction();
|
|
}, this.chaseDuration);
|
|
}, this.chaseDuration);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -241,9 +243,17 @@ export class TornadoAIComponent extends TornadoComponent {
|
|
PathfindingManager.getInstance().moveTo(this.node, escapePosition, this.escapeDuration);
|
|
PathfindingManager.getInstance().moveTo(this.node, escapePosition, this.escapeDuration);
|
|
|
|
|
|
this.scheduleOnce(() => {
|
|
this.scheduleOnce(() => {
|
|
- this.isEscaping = false;
|
|
|
|
- this.decideAction();
|
|
|
|
|
|
+ this.cancelAction();
|
|
}, this.escapeDuration);
|
|
}, this.escapeDuration);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //取消AI行为
|
|
|
|
+ private cancelAction() {
|
|
|
|
+ this.unscheduleAllCallbacks();
|
|
|
|
+ this.isChasing = false;
|
|
|
|
+ this.isEscaping = false;
|
|
|
|
+ this.targetNode = null;
|
|
|
|
+ Tween.stopAllByTarget(this.node);
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|