import FqLogin from "../../../login/FqLogin"; import { AudioMgr } from "../../../main/ViewManage"; import { HttpStateType, ReveData } from "../../../util/CHttp"; import BaseEvent from "./base/BaseEvent"; import WOneByone from "./map1/WOneByone"; /** * 闲聊脚本 */ const { ccclass, property } = cc._decorator; @ccclass export default class FDialogNoneXJ extends BaseEvent { @property({ displayName: '地图元素编号' }) public mapGoodId: string = '23'; @property({ displayName: "拾取物品ID" }) public goodId: number = 2002; @property(cc.Prefab) mMapDialog: cc.Prefab = null; @property({ displayName: '对话内容', type: [cc.String] }) text: Array = []; @property({ displayName: '完成后的对话', type: [cc.String] }) finish: Array = [];//完成后的对话 @property({ displayName: '靠近的提示', type: cc.Node }) icon: cc.Node = null; @property({ displayName: "拾取列表", type: [cc.Node] }) goodList: cc.Node[] = []; @property({ displayName: '提示图标', type: cc.SpriteFrame }) mTipsIcon: cc.SpriteFrame = null; @property({ displayName: 'NPC动画', type: sp.Skeleton }) spine: sp.Skeleton = null; /** * 控制的栅栏 */ @property([cc.Node]) mFenceTrigger: Array = []; private showParticle = false; onLoad() { super.onLoad() if (this.icon) { this.icon.active = false; } let stage = this.ff.main.player.stage; if (stage.element.indexOf(this.mapGoodId) > -1) { for (let i = 0; i < this.mFenceTrigger.length; i++) { const element = this.mFenceTrigger[i]; element.active = false; } for (let i = 0; i < this.goodList.length; i++) { const element = this.goodList[i]; element.active = false; } this.node.active = false; } } onBegin(tag: number) { if (tag == 1) { this.showOpt(this.mTipsIcon, () => { this.startDialog() }) } else if (tag == 2) { if (this.icon) { this.icon.active = true; } } } onEnd(tag: number) { if (tag == 1) { this.closeOpt() } else if (tag == 2) { if (this.icon) { this.icon.active = false; } } } public startDialog() { if (this.icon) { this.icon.active = false; } let head = this.ff.mFFheader; let count = head.getTmpCount(this.goodId); this.pause() if (count >= this.goodList.length) { head.removeTmpGood(this.goodId, count); if (this.mapGoodId != "") { this.getMapObject(this.mapGoodId, null); } this.dialog2(); } else { this.dialog1(); } } public closeButton() { if (this.icon) { this.icon.active = false; } this.closeOpt() } private dialog1(index: number = 0) { if (index >= this.text.length) { this.closeButton(); this.resume(); this.activateGood(); return; } let texts = this.text[index].split('|') let mid = parseInt(texts.shift()); if (mid == -1) {//主角 let my = this.ff.mainSprite.node; this.showDialog(my, texts, () => { index++; this.dialog1(index); }); } else { this.showDialog(this.node, texts, () => { index++; this.dialog1(index); }); } } private dialog2(index: number = 0) { if (index >= this.finish.length) { this.closeButton(); if (this.spine) { this.npcFly(() => { this.spine.node.parent.active = false; this.openmFenceTrigger(); }) } else { this.openmFenceTrigger(); } FqLogin.commitEvent(this.node.name, '', ''); return; } let texts = this.finish[index].split('|') let mid = parseInt(texts.shift()); if (mid == -1) {//主角 let my = this.ff.mainSprite.node; this.showDialog(my, texts, () => { index++; this.dialog2(index); }); } else { this.showDialog(this.node, texts, () => { index++; this.dialog2(index); }); } } npcFly(callBack: Function) { //1.幽灵变身 this.spine.setAnimation(0, 'escape', false); this.spine.setCompleteListener(() => { this.spine.setCompleteListener(null) this.spine.setAnimation(0, 'fly', true); let pos = cc.v2(-370, 460); cc.tween(this.spine.node).sequence( cc.moveTo(1, pos), cc.callFunc(() => { callBack && callBack(); }) ).start() }) } public openmFenceTrigger() { if (this.mFenceTrigger.length <= 0) { return } 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, 'close'); } 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); } } } public activateGood() { if (this.showParticle) return this.showParticle = true; this.goodList.forEach(element => { if (element.name) { element.getChildByName("lizi_gs").active = true; } }); } }