woso_javan 2 місяців тому
батько
коміт
df80d842f5

+ 25 - 13
assets/module_storm_sunder/Script/Component/TornadoAIComponent.ts

@@ -3,6 +3,7 @@ import { PathfindingManager } from '../Manager/PathfindingManager';
 import { PlayerStatus, TornadoComponent } from './TornadoComponent';
 import { PropStatus } from './PropComponent';
 import { GameUtil } from '../GameUtil';
+import { PropMgr } from '../Manager/PropMgr';
 
 const { ccclass, property } = _decorator;
 
@@ -17,7 +18,7 @@ export class TornadoAIComponent extends TornadoComponent {
 
     moveDuration: number = 3; //移动行为持续时间(秒)
     escapeDuration: number = 5; //逃离行为持续时间(秒)
-    chaseDuration: number = 30; //追击行为持续时间(秒)
+    chaseDuration: number = 20; //追击行为持续时间(秒)
     chaseAIProbability: number = 1; //是否追击 AI 的概率 1是100%
     chasePlayerProbability: number = 1; //是否追击玩家的概率
 
@@ -31,7 +32,7 @@ export class TornadoAIComponent extends TornadoComponent {
         super.start();
         this.ai = true;
         this.playerInfo.nickName = '阿西吧 ai';
-        this.playerInfo.level = 2;
+        this.playerInfo.level = 4;
         this.currentLv = this.playerInfo.level;
 
         this.onPlayerInfoHandler();
@@ -50,9 +51,10 @@ export class TornadoAIComponent extends TornadoComponent {
         if (actionType === BehaviorType.Move) {
             this.randomMove();
         } else {
-            const closestItem = this.findClosestItem();
+            const closestItem = PropMgr.inst.getNearestProp(this.node);
             if (closestItem) {
-                this.moveToTarget(closestItem, this.moveDuration);
+                // this.moveToTarget(closestItem, this.moveDuration);
+                this.chaseTarget(closestItem);
             } else {
                 this.randomMove();
             }
@@ -84,6 +86,17 @@ export class TornadoAIComponent extends TornadoComponent {
         }, duration);
     }
 
+    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();
+        }
+    }
+
     /** 触发器检测(过程中遇到其他龙卷风) */
     protected onRadiusTriggerEnter(event: ITriggerEvent): void {
         const otherCollider = event.otherCollider;
@@ -92,7 +105,7 @@ export class TornadoAIComponent extends TornadoComponent {
         if (event.otherCollider.getGroup() == 1 << 3) {
             const targetTornado = otherNode.parent.getComponent(TornadoComponent);
             if (!targetTornado) return;
-            console.log(`AI 触发器检测到其他龙卷风!`)
+
             const isTargetAI = targetTornado instanceof TornadoAIComponent;
             const targetLv = targetTornado.currentLv;
 
@@ -139,7 +152,13 @@ export class TornadoAIComponent extends TornadoComponent {
         this.isChasing = true;
         this.targetNode = target;
 
-        PathfindingManager.getInstance().followTarget(this, target, 20);
+        PathfindingManager.getInstance().followTarget(this, target, 30, () => {
+            console.log(`AI 追击目标到达`);
+            this.unscheduleAllCallbacks();
+            this.isChasing = false;
+            this.targetNode = null;
+            this.decideAction();
+        });
 
         // 追击时间结束后恢复行为
         this.scheduleOnce(() => {
@@ -149,7 +168,6 @@ export class TornadoAIComponent extends TornadoComponent {
         }, this.chaseDuration);
     }
 
-
     /** 逃离目标 */
     private escapeFrom(target: Node) {
         this.isEscaping = true;
@@ -164,10 +182,4 @@ export class TornadoAIComponent extends TornadoComponent {
             this.decideAction();
         }, this.escapeDuration);
     }
-
-    /** 查找最近的道具 */
-    private findClosestItem(): Node | null {
-        // TODO: 实现查找最近的道具
-        return null;
-    }
 }

+ 7 - 3
assets/module_storm_sunder/Script/Manager/PathfindingManager.ts

@@ -23,12 +23,16 @@ export class PathfindingManager {
     }
 
     /** 让 AI 持续追踪目标 */
-    followTarget(aiComponent: Component, targetNode: Node, moveSpeed: number) {
-        if (!aiComponent || !targetNode) return;
+    followTarget(aiComponent: Component, targetNode: Node, moveSpeed: number, cb: Function) {
+        if (!targetNode) return;
 
         aiComponent.schedule(() => {
-            if (!targetNode.isValid) return; // 目标被销毁就停止追击
+            if (!targetNode.isValid) {
+                if (cb) cb();
+                return;
+            }
 
+            console.log('追击中...')
             const aiNode = aiComponent.node;
             const targetPos = targetNode.worldPosition;
             const myPos = aiNode.worldPosition;

Різницю між файлами не показано, бо вона завелика
+ 94 - 832
assets/module_storm_sunder/rooster_stormsunder.scene


Деякі файли не було показано, через те що забагато файлів було змінено