123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- 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<string> = [];
- @property({
- displayName: '完成后的对话',
- type: [cc.String]
- })
- finish: Array<string> = [];//完成后的对话
- @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<cc.Node> = [];
- 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;
- }
- });
- }
- }
|