123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- import FqLogin from "../../../login/FqLogin";
- import { AudioMgr } from "../../../main/ViewManage";
- import EventListener from "../../../util/EventListener";
- import BaseEvent from "./base/BaseEvent";
- /**
- * 闲聊脚本
- */
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class FDialogNoneNPC extends BaseEvent {
- @property(cc.Prefab)
- mMapDialog: cc.Prefab = null;
- @property({
- displayName: '对话内容1',
- type: [cc.String]
- })
- text1: Array<string> = [];
- @property({
- displayName: '对话内容2',
- type: [cc.String]
- })
- text2: Array<string> = [];
- @property({
- displayName: '靠近的提示',
- type: cc.Node
- })
- icon: cc.Node = null;
- @property({
- displayName: '提示图标',
- type: cc.SpriteFrame
- })
- mTipsIcon: cc.SpriteFrame = null;
- @property({
- displayName: 'NPC动画',
- type: sp.Skeleton
- })
- spine: sp.Skeleton = null;
- /**
- * 控制的栅栏
- */
- @property([cc.Node])
- mFenceTrigger: Array<cc.Node> = [];
- onLoad() {
- super.onLoad()
- if (this.icon) {
- this.icon.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;
- }
- this.pause()
- this.dialog1();
- }
- public closeButton() {
- if (this.icon) {
- this.icon.active = false;
- }
- this.closeOpt()
- }
- public dialog1(index: number = 0) {
- if (index >= this.text1.length) {
- this.npcFly(() => {
- this.openmFenceTrigger();
- this.spine.node.parent.active = false;
- this.closeOpt();
- });
- this.closeButton();
- this.resume();
- return;
- }
- let texts = this.text1[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);
- });
- }
- }
- public dialog2(index: number = 0) {
- if (index >= this.text2.length) {
- this.npcFly(() => {
- this.openmFenceTrigger();
- this.spine.node.parent.active = false;
- this.closeOpt();
- });
- this.closeButton();
- this.resume();
- return;
- }
- let texts = this.text2[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) {
- return
- //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;
- }
- FqLogin.commitEvent(this.node.name, '', '');
- })
- ).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);
- }
- }
- }
- }
|