woso_javan 2 meses atrás
pai
commit
578f6e1cdc

+ 1 - 1
assets/module_storm_sunder/Script/Component/PropComponent.ts

@@ -14,7 +14,7 @@ export class PropComponent extends Component {
     hp: number = 1;
 
     @property({ type: CCFloat })
-    exp: number = 10;
+    currentExp: number = 10;
 
     @property({ type: CCBoolean, displayName: "是否可移动" })
     isMove: boolean = false;

+ 17 - 1
assets/module_storm_sunder/Script/Component/TornadoAIComponent.ts

@@ -4,6 +4,7 @@ import { PlayerStatus, TornadoComponent } from './TornadoComponent';
 import { PropStatus } from './PropComponent';
 import { GameUtil } from '../GameUtil';
 import { PropMgr } from '../Manager/PropMgr';
+import { GameMgr, GameStatus } from '../Manager/GameMgr';
 
 const { ccclass, property } = _decorator;
 
@@ -30,9 +31,10 @@ export class TornadoAIComponent extends TornadoComponent {
 
     protected async start() {
         super.start();
+
         this.ai = true;
         this.playerInfo.nickName = '阿西吧 ai';
-        this.playerInfo.level = 4;
+        this.playerInfo.level = 1;
         this.currentLv = this.playerInfo.level;
 
         this.onPlayerInfoHandler();
@@ -97,6 +99,20 @@ export class TornadoAIComponent extends TornadoComponent {
         }
     }
 
+    protected onTriggerStay(event: ITriggerEvent): void {
+        const otherCollider = event.otherCollider;
+
+        if (otherCollider.getGroup() == 1 << 3) {
+            const targetTornado = otherCollider.node.parent.getComponent(TornadoComponent);
+            if (!targetTornado) return;
+
+            if (this.currentLv > targetTornado.currentLv) {
+                console.log('AI 撒日朗++++++++');
+                GameMgr.inst.setGameStatus(GameStatus.End);
+            }
+        }
+    }
+
     /** 触发器检测(过程中遇到其他龙卷风) */
     protected onRadiusTriggerEnter(event: ITriggerEvent): void {
         const otherCollider = event.otherCollider;

+ 45 - 21
assets/module_storm_sunder/Script/Component/TornadoComponent.ts

@@ -25,6 +25,7 @@ export class TornadoComponent extends Component {
     tigger: Collider = null!; //龙卷风触发器
     radiusTigger: Collider = null!;     //龙卷风半径检测触发器
 
+    ai: boolean = false;
     attack: number = 20;
     speed: number = 50;
     currentExp: number = 0;
@@ -34,15 +35,8 @@ export class TornadoComponent extends Component {
     playerStatus: PlayerStatus = PlayerStatus.LIFE;
     playerInfo: PlayerInfo = null;
     isColliding: boolean = false;
-    //当前攻击的道具
-    currentAttackProp: Node = null;
-    private _ai: boolean = false;
-    public get ai(): boolean {
-        return this._ai;
-    }
-    public set ai(value: boolean) {
-        this._ai = value;
-    }
+    //当前攻击的道具或玩家
+    curHitObj: Node = null;
 
     _attackInterval: number = 0.5; // 攻击间隔
     _lastAttackTime: Map<string, number> = new Map(); // 记录上次攻击时间
@@ -91,6 +85,8 @@ export class TornadoComponent extends Component {
     }
 
     protected onTriggerEnter(event: ITriggerEvent): void {
+        if (GameMgr.inst.gameStatus !== GameStatus.Playing) return;
+
         let _originalPosition = this.node.position.clone();
         if (event.otherCollider.getGroup() === 1 << 2) {
             if (this.isColliding) return; // 防止重复触发
@@ -128,12 +124,15 @@ export class TornadoComponent extends Component {
     }
 
     protected onTriggerStay(event: ITriggerEvent): void {
-        if (event.otherCollider.getGroup() == 1 << 4) {
-            const otherCollider = event.otherCollider;
-            this.currentAttackProp = otherCollider.node;
+        if (GameMgr.inst.gameStatus !== GameStatus.Playing) return;
+
+        const otherCollider = event.otherCollider;
+
+        if (otherCollider.getGroup() == 1 << 4) {
+            this.curHitObj = otherCollider.node;
 
-            if (!this.currentAttackProp.getComponent(PropComponent)) return;
-            const propComponent = this.currentAttackProp.getComponent(PropComponent);
+            if (!this.curHitObj.getComponent(PropComponent)) return;
+            const propComponent = this.curHitObj.getComponent(PropComponent);
 
             const currentTime = game.totalTime;
             const nodeId = otherCollider.node.uuid;
@@ -155,16 +154,34 @@ export class TornadoComponent extends Component {
                         otherCollider.node.parent = randomPoint;
                         otherCollider.node.setPosition(Vec3.ZERO);
                         propComponent.swallow();
-                        this.addExpByProp();
+                        this.addExpByKill();
                     }
                 }
             }
+        } else if (otherCollider.getGroup() == 1 << 3) {
+            const targetTornado = otherCollider.node.parent.getComponent(TornadoComponent);
+            if (!targetTornado) return;
+
+            if (this.currentLv > targetTornado.currentLv) {
+                console.log('撒日朗++++++++');
+                this.curHitObj = targetTornado.node;
+                this.addExpByKill();
+                this.killed(targetTornado.node);
+
+                targetTornado.node.removeFromParent();
+                targetTornado.node.destroy();
+            }
         }
     }
 
+    //被击杀
+    killed(targetNode: Node) {
+        Effect2DUIMgr.inst.removePlayerInfo(targetNode);
+    }
+
     onTriggerExit(event: ITriggerEvent) {
         if (event.otherCollider.getGroup() == 1 << 4) {
-            this.currentAttackProp = null;
+            this.curHitObj = null;
         }
     }
 
@@ -194,12 +211,19 @@ export class TornadoComponent extends Component {
         this.node.setPosition(this.node.position.x + playerX, 0, this.node.position.z - playerZ);
     }
 
-    protected addExpByProp() {
-        if (!this.currentAttackProp) return;
+    protected addExpByKill() {
+        if (!this.curHitObj) return;
+
+        const propComp = this.curHitObj.getComponent(PropComponent);
+        let objExp = 0;
+        if (this.curHitObj.getComponent(PropComponent)) {
+            objExp = propComp.currentExp;
+        } else {
+            //TODO 计算经验
+            objExp = this.currentLv * 10;
+        }
 
-        const propComp = this.currentAttackProp.getComponent(PropComponent);
-        const propExp = propComp.exp;
-        this.currentExp += propExp;
+        this.currentExp += objExp;
         if (this.currentExp >= this.nextExp) {
             this.stormLevelUp();
             this.currentLv++;