|
@@ -0,0 +1,203 @@
|
|
|
+import FqLogin from "../../../../login/FqLogin";
|
|
|
+import { AudioMgr } from "../../../../main/ViewManage";
|
|
|
+import FFCalAttr from "../../../data/FFCalAttr";
|
|
|
+import AIPet from "../../object/AI/AIPet";
|
|
|
+import { GroupType } from "../../object/FObject";
|
|
|
+import { SpriteActionType } from "../../object/FSprite";
|
|
|
+import PSprite from "../../object/PSprite";
|
|
|
+import BaseEvent from "../base/BaseEvent";
|
|
|
+
|
|
|
+const { ccclass, property } = cc._decorator;
|
|
|
+/**
|
|
|
+ * 第一个宠物牢笼
|
|
|
+ */
|
|
|
+@ccclass
|
|
|
+export default class FCagePet1 extends BaseEvent {
|
|
|
+
|
|
|
+ @property({
|
|
|
+ displayName: '解救的伙伴id',
|
|
|
+ })
|
|
|
+ mPetId: number = 1;
|
|
|
+
|
|
|
+ @property({
|
|
|
+ displayName: '没有钥匙的对话',
|
|
|
+ type: [cc.String]
|
|
|
+ })
|
|
|
+ dialog1: Array<string> = [];
|
|
|
+
|
|
|
+ @property({
|
|
|
+ displayName: '牢笼动画',
|
|
|
+ tooltip: '显示牢笼的动画',
|
|
|
+ type: sp.Skeleton
|
|
|
+ })
|
|
|
+ spine: sp.Skeleton = null;//牢笼
|
|
|
+
|
|
|
+ @property({
|
|
|
+ displayName: '按钮图标',
|
|
|
+ type: cc.SpriteFrame
|
|
|
+ })
|
|
|
+ mTipsIcon: cc.SpriteFrame = null;
|
|
|
+
|
|
|
+ @property({
|
|
|
+ displayName: '靠近的提示',
|
|
|
+ type: cc.Sprite
|
|
|
+ })
|
|
|
+ mIcon: cc.Sprite = null;//靠近后的提示
|
|
|
+
|
|
|
+ @property({
|
|
|
+ type: [cc.SpriteFrame],
|
|
|
+ displayName: '不同状态的图标'
|
|
|
+ })
|
|
|
+ mIconFrame: Array<cc.SpriteFrame> = [];
|
|
|
+
|
|
|
+ @property({
|
|
|
+ displayName: '牢笼中的伙伴',
|
|
|
+ type: cc.Node
|
|
|
+ })
|
|
|
+ mPet: cc.Node = null;//伙伴
|
|
|
+ @property({
|
|
|
+ displayName: '解救出来的对话',
|
|
|
+ type: [cc.String]
|
|
|
+ })
|
|
|
+ dialog2: Array<string> = [];
|
|
|
+
|
|
|
+ @property({
|
|
|
+ displayName: '宠物预制体',
|
|
|
+ type: cc.Prefab
|
|
|
+ })
|
|
|
+ mPetPrefab: cc.Prefab = null;
|
|
|
+
|
|
|
+ @property({
|
|
|
+ type: [cc.Node],
|
|
|
+ displayName: '需要打开的门'
|
|
|
+ })
|
|
|
+ mFenceTrigger: Array<cc.Node> = [];
|
|
|
+
|
|
|
+ @property({
|
|
|
+ displayName: 'npc',
|
|
|
+ type: cc.Node
|
|
|
+ })
|
|
|
+ mNPC2: cc.Node = null;
|
|
|
+
|
|
|
+ private isOver = false;
|
|
|
+
|
|
|
+ onBegin(tag: number) {
|
|
|
+ if (this.isOver) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (tag == 1) {
|
|
|
+ this.iconTips(true);
|
|
|
+ this.showOpt(this.mTipsIcon, () => {
|
|
|
+ this.iconTips(false);
|
|
|
+ this.closeOpt()
|
|
|
+ this.openCage()
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ onEnd(tag: number) {
|
|
|
+ if (tag == 1) {
|
|
|
+ this.iconTips(false);
|
|
|
+ this.closeOpt()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param show 是否显示提示
|
|
|
+ */
|
|
|
+ private iconTips(show) {
|
|
|
+ if (this.mIcon) {
|
|
|
+ if (show) {
|
|
|
+ this.mIcon.node.active = true;
|
|
|
+ let head = this.ff.mFFheader;
|
|
|
+ let count = head.getTmpCount(2001);
|
|
|
+ if (count > 0) {
|
|
|
+ this.mIcon.spriteFrame = this.mIconFrame[0]
|
|
|
+ } else {
|
|
|
+ this.mIcon.spriteFrame = this.mIconFrame[1]
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.mIcon.node.active = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //打开牢笼
|
|
|
+ private openCage() {
|
|
|
+ let head = this.ff.mFFheader;
|
|
|
+ let count = head.getTmpCount(2001);
|
|
|
+ if (count > 0) {
|
|
|
+ head.removeTmpGood(2001, 1);
|
|
|
+ this.isOver = true;
|
|
|
+
|
|
|
+ this.spine.setCompleteListener(() => {
|
|
|
+ this.spine.setCompleteListener(null);
|
|
|
+ this.showDialog(this.node,this.dialog2,()=>{
|
|
|
+ this.movePet()
|
|
|
+ })
|
|
|
+ });
|
|
|
+ if (this.spine.findAnimation("open3")) {
|
|
|
+ this.spine.setAnimation(0, 'open3', false);
|
|
|
+ } else {
|
|
|
+ this.spine.setAnimation(0, 'open', false);
|
|
|
+ }
|
|
|
+ FqLogin.commitEvent(this.node.name, '', '');
|
|
|
+ } else {
|
|
|
+ // this.ff.main.showTips('需要一把牢笼钥匙');
|
|
|
+ this.showDialog(this.node,this.dialog1,()=>{
|
|
|
+
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private movePet() {
|
|
|
+ let anim = this.mPet.getComponent(cc.Animation);
|
|
|
+ let spine = this.mPet.getComponent(sp.Skeleton);
|
|
|
+
|
|
|
+ spine.setAnimation(0, SpriteActionType.run, true);
|
|
|
+ anim.on('finished', this.onFinished, this);
|
|
|
+ anim.play('cage_pet_move');
|
|
|
+ }
|
|
|
+ private onFinished(num, string) {
|
|
|
+ let anim = this.mPet.getComponent(cc.Animation);
|
|
|
+ let spine = this.mPet.getComponent(sp.Skeleton);
|
|
|
+ anim.off('finished', this.onFinished, this);
|
|
|
+ spine.setAnimation(0, SpriteActionType.stand, true);
|
|
|
+ this.mPet.destroy()
|
|
|
+ this.openDoor()
|
|
|
+ }
|
|
|
+
|
|
|
+ public openDoor(){
|
|
|
+ this.pause()
|
|
|
+ this.moveCamera(this.mFenceTrigger[0].getPosition(), 1, () => {
|
|
|
+ cc.tween(this.node).sequence(
|
|
|
+ cc.callFunc(() => {
|
|
|
+ for (let i = 0; i < this.mFenceTrigger.length; i++) {
|
|
|
+ const element = this.mFenceTrigger[i];
|
|
|
+ this.showFence(element, 'open');
|
|
|
+ }
|
|
|
+ this.ff.main.playerEffectByPath(AudioMgr.openDoor);
|
|
|
+ }),
|
|
|
+ cc.delayTime(1),
|
|
|
+ cc.callFunc(() => {
|
|
|
+ this.resume()
|
|
|
+ for (let i = 0; i < this.mFenceTrigger.length; i++) {
|
|
|
+ const element = this.mFenceTrigger[i];
|
|
|
+ element.active = false;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ ).start();
|
|
|
+
|
|
|
+ })
|
|
|
+ }
|
|
|
+ private showFence(element, action) {
|
|
|
+ let nodes = element.children;
|
|
|
+ for (let i = 0; i < nodes.length; i++) {
|
|
|
+ const element = nodes[i];
|
|
|
+ let spine = element.getComponent(sp.Skeleton);
|
|
|
+ if (spine) {
|
|
|
+ spine.setAnimation(0, action, false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|