Przeglądaj źródła

fixed bug复活随机

woso_javan 2 miesięcy temu
rodzic
commit
927692754d

+ 6 - 3
assets/module_storm_sunder/Prefabs/UI/Revive/UI_BattleRevive_Impl.ts

@@ -4,6 +4,8 @@ import { UI_BattleRevive } from "../../../../scripts/UIDef";
 import { Layout_BattleRevive } from './Layout_BattleRevive';
 import { GameMgr, GameStatus } from '../../../Script/Manager/GameMgr';
 import { tgxModuleContext } from 'db://assets/core_tgx/tgx';
+import { EventDispatcher } from 'db://assets/core_tgx/easy_ui_framework/EventDispatcher';
+import { GameEvent } from '../../../Script/Enum/GameEvent';
 const { ccclass, property } = _decorator;
 
 @ccclass('UI_BattleRevive_Impl')
@@ -20,7 +22,8 @@ export class UI_BattleRevive_Impl extends UI_BattleRevive {
     protected onCreated(): void {
         let layout = this.layout as Layout_BattleRevive;
         this.onButtonEvent(layout.btn_revive, () => {
-            this.changeGameStatus(GameStatus.Playing);
+            EventDispatcher.instance.emit(GameEvent.EVENT_STORM_RESURRECT);
+            this.changeGameStatus(GameStatus.Continue);
         });
         this.onButtonEvent(layout.btn_back, () => {
             // this.changeGameStatus(GameStatus.None);
@@ -31,9 +34,9 @@ export class UI_BattleRevive_Impl extends UI_BattleRevive {
     }
 
     private changeGameStatus(status: GameStatus): void {
-        GameMgr.inst.setGameStatus(status);
         this.hide();
-        console.log("changeGameStatus", status);
+        GameMgr.inst.setGameStatus(status);
+        // console.log("changeGameStatus", status);
     }
 }
 

+ 38 - 8
assets/module_storm_sunder/Script/Component/TornadoAIComponent.ts

@@ -46,6 +46,7 @@ export class TornadoAIComponent extends TornadoComponent {
     protected registerEvent(): void {
         EventDispatcher.instance.on(GameEvent.EVENT_GAME_START, this.decideAction, this);
         EventDispatcher.instance.on(GameEvent.EVENT_GAME_START_EFFECT, this.decideAction, this);
+        EventDispatcher.instance.on(GameEvent.EVENT_STORM_RESURRECT, this.stormResurrect, this);
     }
 
     private initAIPlayer() {
@@ -146,13 +147,36 @@ export class TornadoAIComponent extends TornadoComponent {
             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;
-                    // console.log(`AI 触发碰撞到:${targetTornado.name} isAI:${isAI}`);
-                    GameMgr.inst.setGameStatus(GameStatus.Revive);
+            // 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;
+            //         // console.log(`AI 触发碰撞到:${targetTornado.name} isAI:${isAI}`);
+            //         GameMgr.inst.setGameStatus(GameStatus.Revive);
+            //     }
+            // }
+
+            if (event.selfCollider.node.name == 'RigibodyStorm') {
+                if (event.otherCollider.node.name == 'RigibodyStorm') {
+                    const distance = Vec3.distance(event.selfCollider.node.worldPosition, otherCollider.node.worldPosition);
+
+                    // 增加碰撞检测的容差范围
+                    const collisionThreshold = 3;  // 增加检测范围
+                    if (distance <= collisionThreshold) {
+                        // 添加额外的速度检查,确保不会因为速度太快而错过碰撞
+                        const relativeSpeed = Math.abs(this.speed - targetTornado.speed);
+                        const minSpeedThreshold = 5;  // 最小速度阈值
+
+                        if (relativeSpeed >= minSpeedThreshold || distance <= 1.5) {  // 如果速度差够大或距离非常近
+                            const isAI = targetTornado.ai;
+                            if (this.currentLv > targetTornado.currentLv && !isAI) {
+                                console.log(`AI 击杀玩家!!!`);
+                                GameMgr.inst.isWin = false;
+                                GameMgr.inst.setGameStatus(GameStatus.Revive);
+                            }
+                        }
+                    }
                 }
             }
         }
@@ -213,7 +237,7 @@ export class TornadoAIComponent extends TornadoComponent {
     /** 追击目标 */
     private chaseTarget(target: Node) {
         if (this.isChasing) return;
-        // console.log(`AI 追击目标-> ${target.name}}`);
+        console.log(`AI 追击目标-> ${target.name}}`);
 
         this.isChasing = true;
         this.targetNode = target;
@@ -252,6 +276,12 @@ export class TornadoAIComponent extends TornadoComponent {
         }, this.escapeDuration);
     }
 
+    private stormResurrect() {
+        // console.log(`玩家复活 AI取消行为 重新选择行为!`);
+        this.cancelAction();
+        this.decideAction();
+    }
+
     //取消AI行为
     private cancelAction() {
         this.unscheduleAllCallbacks();

+ 2 - 1
assets/module_storm_sunder/Script/Component/TornadoComponent.ts

@@ -249,7 +249,7 @@ export class TornadoComponent extends Component {
         const targetTornado = targetNode.getComponent(TornadoComponent);
         if (targetTornado && !targetTornado.ai) {
             // 如果是玩家被击杀,只隐藏节点
-            targetNode.active = false;
+            // targetNode.active = false;
         } else {
             // 如果是AI被击杀,移除并销毁节点
             targetNode.removeFromParent();
@@ -341,6 +341,7 @@ export class TornadoComponent extends Component {
         this.particleSystem.startSizeX.constantMax = 1;
         this.particleSystem.startLifetime.constantMax = 0.6;
     }
+
     //变大体积
     private grow() {
         //体积=基础体积×(1+等级×百分比)

+ 3 - 0
assets/module_storm_sunder/Script/Enum/GameEvent.ts

@@ -6,6 +6,9 @@ export class GameEvent {
     /**龙卷风重置*/
     static readonly EVENT_STORM_RESET = 'EVENT_STORM_RESET';
 
+    /** 龙卷风复活*/
+    static readonly EVENT_STORM_RESURRECT = 'EVENT_STORM_RESURRECT';
+
     /** 开局特效*/
     static readonly EVENT_GAME_START_EFFECT = 'EVENT_GAME_START_EFFECT';
 

+ 1 - 1
assets/module_storm_sunder/Script/HomeUI.ts

@@ -42,7 +42,7 @@ export class HomeUI extends Component {
         const idMax: number = 20;
         this.lbUserName.string = PlayerMgr.inst.generateUniqueName(idMax);
         AttributeBonusMgr.inst.userModel.nickName = this.lbUserName.string;
-        console.log('onClickRandom', AttributeBonusMgr.inst.userModel.nickName);
+        // console.log('onClickRandom', AttributeBonusMgr.inst.userModel.nickName);
     }
 
 }

+ 9 - 0
assets/module_storm_sunder/Script/Manager/GameMgr.ts

@@ -10,6 +10,7 @@ import { assetManager, instantiate, Prefab } from "cc";
 import { resLoader } from "db://assets/core_tgx/base/ResLoader";
 import { Effect2DUIMgr } from "./Effect2DUIMgr";
 import { MapMgr } from "./MapMgr";
+import { GameUtil } from "../GameUtil";
 
 export class GameMgr {
     private static _instance: GameMgr;
@@ -74,6 +75,7 @@ export class GameMgr {
                 }
                 break;
             case GameStatus.Playing:
+
                 break;
             case GameStatus.Revive:
                 const revive = tgxUIMgr.inst.isShowing(UI_BattleRevive);
@@ -82,6 +84,11 @@ export class GameMgr {
                     // console.log("GameMgr.ts updateGameStatusUI() GameStatus.Revive");
                 }
                 break;
+            case GameStatus.Continue:
+                await PlayerMgr.inst.revivePlayer();
+                await GameUtil.delay(0.2);
+                this.setGameStatus(GameStatus.Playing);
+                break;
             case GameStatus.End:
                 tgxUIMgr.inst.showUI(UI_BattleResult);
                 break;
@@ -111,6 +118,8 @@ export enum GameStatus {
     Gambit,
     /** 复活中*/
     Revive,
+    /** 继续游戏*/
+    Continue,
     /** 游戏结束 */
     End,
 }

+ 8 - 2
assets/module_storm_sunder/Script/Manager/PlayerMgr.ts

@@ -255,10 +255,16 @@ export class PlayerMgr {
         return ""; // 若无有效名称,返回空字符串
     }
 
+    //复活玩家 随机位置
+    async revivePlayer() {
+        const player = await this.getTornadoNode();
+        const aiPoints = StormSunderGlobalInstance.instance.aiPoints;
+        let randomIndex = Math.floor(Math.random() * aiPoints.children.length);
+        player.setPosition(aiPoints.children[randomIndex].getWorldPosition());
+    }
+
     async reset() {
         this.destroyOtherAI();
-        let tornado = await this.getTornadoNode();
-        // tornado.scale = new Vec3(1, 1, 1);
         const sence = director.getScene();
         sence.emit(EasyControllerEvent.CAMERA_ZOOM, 30);
         EventDispatcher.instance.emit(GameEvent.EVENT_STORM_RESET);

+ 2 - 2
assets/module_storm_sunder/rooster_stormsunder.scene

@@ -6262,8 +6262,8 @@
     },
     "_lscale": {
       "__type__": "cc.Vec3",
-      "x": 1,
-      "y": 1,
+      "x": 0.7,
+      "y": 0.7,
       "z": 1
     },
     "_mobility": 0,