123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- 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);
- }
- }
- }
- }
|