Переглянути джерело

优化修改激活怪物脚本

chelios 3 роки тому
батько
коміт
4f2d437ccb
1 змінених файлів з 32 додано та 82 видалено
  1. 32 82
      assets/Script/game/fight/evnet/FFenceTrigger.ts

+ 32 - 82
assets/Script/game/fight/evnet/FFenceTrigger.ts

@@ -1,10 +1,8 @@
 import FqLogin from "../../../login/FqLogin";
 import CMath from "../../../util/CMath";
-import FF from "../FF";
 import { GroupType } from "../object/FObject";
 import FSprite, { SpriteActionType } from "../object/FSprite";
-import FDialogMonster from "./FDialogMonster";
-import WOneByone from "./map1/WOneByone";
+import BaseEvent from "./base/BaseEvent";
 
 /**
  * 激活怪物
@@ -13,7 +11,7 @@ import WOneByone from "./map1/WOneByone";
 const { ccclass, property } = cc._decorator;
 
 @ccclass
-export default class FFenceTrigger extends cc.Component {
+export default class FFenceTrigger extends BaseEvent {
     /**
      * 伙伴初始化区域
      */
@@ -102,7 +100,6 @@ export default class FFenceTrigger extends cc.Component {
     })
     countDown = -1;
 
-    public ff: FF;
     private isOver = false;
 
     private mIndex = 0
@@ -114,6 +111,7 @@ export default class FFenceTrigger extends cc.Component {
     private mMonster: Array<FSprite> = null
 
     onLoad() {
+        super.onLoad()
         this.groupMonster.push(this.mMonster1)
         if (this.mMonster2.length > 0) {
             this.groupMonster.push(this.mMonster2)
@@ -142,35 +140,41 @@ export default class FFenceTrigger extends cc.Component {
         }
         this.mMonster = this.groupMonster[0]
     }
+    /**
+     * 主角进入碰撞区域
+     *  @param tag 碰撞组件编号
+     */
+    public onBegin(tag: number) {
+        this.node.removeComponent(cc.PhysicsBoxCollider);
+        this.node.removeComponent(cc.PhysicsBoxCollider);
 
-    onBeginContact(contact: cc.PhysicsContact, selfCollider: cc.PhysicsCollider, otherCollider: cc.PhysicsCollider) {
-        if (this.isOver) {
-            return;
-        }
-        if (otherCollider.node.group == 'A') {//主角踩到机关
-            let obj = otherCollider.node.getComponent(FSprite);
-            this.ff = obj.ff;
-            if (obj == this.ff.mainSprite) {
-                this.node.removeComponent(cc.PhysicsBoxCollider);
-                this.node.removeComponent(cc.PhysicsBoxCollider);
-                this.ff = obj.ff;
-
-                this.ff.regRemoveCallback((f: FSprite) => {
-                    this.removeCallback(f);
-                });
-                this.isOver = true;
-                this.startFight();
+        this.ff.regRemoveCallback((f: FSprite) => {
+            this.removeCallback(f);
+        });
+        this.isOver = true;
+        this.startFight();
 
-                FqLogin.commitEvent(this.node.name, '', '')
-            }
-        }
+        FqLogin.commitEvent(this.node.name, '', '')
     }
     /**
      * 开始战斗
      */
     private startFight() {
         this.ff.pauseSprite(true);
-        this.moveCamera(this.node, () => {
+        for (let i = 0; i < this.mFenceTrigger.length; i++) {
+            const element = this.mFenceTrigger[i];
+            element.active = true;
+
+            let nodes = element.children;
+            nodes.forEach(tmp => {
+                let spine = tmp.getComponent(sp.Skeleton);
+                if (spine) {
+                    spine.setAnimation(0, 'close', false);
+                }
+            });
+        }
+
+        this.moveCamera(this.node.getPosition(),1, () => {
             this.dialog(0);
         })
     }
@@ -197,29 +201,6 @@ export default class FFenceTrigger extends cc.Component {
         }
 
     }
-    private showDialog(my: cc.Node, dialogs, fCallback: () => void) {
-        this.ff.mBlockInputEvents.active = true;
-        let node = cc.instantiate(this.mMapDialog);
-        node.group = 'map'
-        node.zIndex = 9999;
-        node.x = my.x;
-        node.y = my.y + my.height;
-        node.parent = this.ff.mMap.mSprites;
-        let obo = node.getComponent(WOneByone);
-
-        obo.dialogs = dialogs;
-        obo.setCallback(() => {
-            node.destroy();
-            this.ff.setBlockInputCallback(null);
-
-            fCallback();
-        });
-        this.ff.setBlockInputCallback(() => {
-            obo.jump();
-        });
-        obo._start();
-    }
-
     private startFight1() {
         this.addMark();
         // this.moveTo();
@@ -241,18 +222,7 @@ export default class FFenceTrigger extends cc.Component {
                 this.ff.pauseSprite(false);
                 this.ff.mBlockInputEvents.active = false;
 
-                for (let i = 0; i < this.mFenceTrigger.length; i++) {
-                    const element = this.mFenceTrigger[i];
-                    element.active = true;
-
-                    let nodes = element.children;
-                    nodes.forEach(tmp => {
-                        let spine = tmp.getComponent(sp.Skeleton);
-                        if (spine) {
-                            spine.setAnimation(0, 'close', false);
-                        }
-                    });
-                }
+               
                 for (let i = 0; i < this.mMonster.length; i++) {
                     const element = this.mMonster[i];
                     element.isActive = true;
@@ -288,26 +258,6 @@ export default class FFenceTrigger extends cc.Component {
             cc.destroySelf(),
         ).start();
     }
-
-    private moveCamera(node: cc.Node, finishCallback: () => void) {
-        if (!this.mCameraPos) {
-            finishCallback();
-            return;
-        }
-        let map = this.ff.mMap;
-        let camera = map.mCamera;
-
-        let pos = cc.v2();
-        let winsize = cc.winSize;
-        pos.x = node.x + this.mCameraPos.x - winsize.width / 2;
-        pos.y = node.y + this.mCameraPos.y - winsize.height / 2;
-        cc.tween(camera.node).sequence(
-            cc.moveTo(1, pos),
-            cc.callFunc(() => {
-                finishCallback();
-            })
-        ).start()
-    }
     /**
      * 移动伙伴
      * @param sprite 
@@ -474,7 +424,7 @@ export default class FFenceTrigger extends cc.Component {
         //检查其它开关是否打开
         if (!this.mFenceTrigger2.length) return
         this.ff.pauseSprite(true);
-        this.moveCamera(this.mFenceTrigger2[0], () => {
+        this.moveCamera(this.mFenceTrigger2[0].getPosition(),1, () => {
             cc.tween(this.node).sequence(
                 cc.callFunc(() => {
                     for (let i = 0; i < this.mFenceTrigger2.length; i++) {