FDialogNoneNPC.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import FqLogin from "../../../login/FqLogin";
  2. import { AudioMgr } from "../../../main/ViewManage";
  3. import BaseEvent from "./base/BaseEvent";
  4. /**
  5. * 闲聊脚本
  6. */
  7. const { ccclass, property } = cc._decorator;
  8. @ccclass
  9. export default class FDialogNoneNPC extends BaseEvent {
  10. @property(cc.Prefab)
  11. mMapDialog: cc.Prefab = null;
  12. @property({
  13. displayName: '对话内容',
  14. type: [cc.String]
  15. })
  16. text: Array<string> = [];
  17. @property({
  18. displayName: '靠近的提示',
  19. type: cc.Node
  20. })
  21. icon: cc.Node = null;
  22. @property({
  23. displayName: '提示图标',
  24. type: cc.SpriteFrame
  25. })
  26. mTipsIcon: cc.SpriteFrame = null;
  27. @property({
  28. displayName: 'NPC动画',
  29. type: sp.Skeleton
  30. })
  31. spine: sp.Skeleton = null;
  32. /**
  33. * 控制的栅栏
  34. */
  35. @property([cc.Node])
  36. mFenceTrigger: Array<cc.Node> = [];
  37. onLoad() {
  38. super.onLoad()
  39. if (this.icon) {
  40. this.icon.active = false;
  41. }
  42. }
  43. onBegin(tag: number) {
  44. if (tag == 1) {
  45. this.showOpt(this.mTipsIcon, () => {
  46. this.startDialog()
  47. })
  48. } else if (tag == 2) {
  49. if (this.icon) {
  50. this.icon.active = true;
  51. }
  52. }
  53. }
  54. onEnd(tag: number) {
  55. if (tag == 1) {
  56. this.closeOpt()
  57. } else if (tag == 2) {
  58. if (this.icon) {
  59. this.icon.active = false;
  60. }
  61. }
  62. }
  63. public startDialog() {
  64. if (this.icon) {
  65. this.icon.active = false;
  66. }
  67. this.dialog1();
  68. }
  69. public closeButton() {
  70. if (this.icon) {
  71. this.icon.active = false;
  72. }
  73. this.closeOpt()
  74. }
  75. private dialog1(index: number = 0) {
  76. if (index >= this.text.length) {
  77. this.npcFly(() => {
  78. this.openmFenceTrigger();
  79. this.spine.node.parent.active = false;
  80. this.closeOpt();
  81. });
  82. this.closeButton();
  83. this.resume();
  84. return;
  85. }
  86. let texts = this.text[index].split('|')
  87. let mid = parseInt(texts.shift());
  88. if (mid == -1) {//主角
  89. let my = this.ff.mainSprite.node;
  90. this.showDialog(my, texts, () => {
  91. index++;
  92. this.dialog1(index);
  93. });
  94. } else {
  95. this.showDialog(this.node, texts, () => {
  96. index++;
  97. this.dialog1(index);
  98. });
  99. }
  100. }
  101. npcFly(callBack: Function) {
  102. return
  103. //1.幽灵变身
  104. this.spine.setAnimation(0, 'escape', false);
  105. this.spine.setCompleteListener(() => {
  106. this.spine.setCompleteListener(null)
  107. this.spine.setAnimation(0, 'fly', true);
  108. let pos = cc.v2(-370, 460);
  109. cc.tween(this.spine.node).sequence(
  110. cc.moveTo(1, pos),
  111. cc.callFunc(() => {
  112. callBack && callBack();
  113. })
  114. ).start()
  115. })
  116. }
  117. public openmFenceTrigger() {
  118. if (this.mFenceTrigger.length <= 0) {
  119. return
  120. }
  121. this.pause()
  122. this.moveCamera(this.mFenceTrigger[0].getPosition(), 1, () => {
  123. cc.tween(this.node).sequence(
  124. cc.callFunc(() => {
  125. for (let i = 0; i < this.mFenceTrigger.length; i++) {
  126. const element = this.mFenceTrigger[i];
  127. this.showFence(element, 'close');
  128. }
  129. this.ff.main.playerEffectByPath(AudioMgr.openDoor);
  130. }),
  131. cc.delayTime(1),
  132. cc.callFunc(() => {
  133. this.resume()
  134. for (let i = 0; i < this.mFenceTrigger.length; i++) {
  135. const element = this.mFenceTrigger[i];
  136. element.active = false;
  137. }
  138. FqLogin.commitEvent(this.node.name, '', '');
  139. })
  140. ).start();
  141. })
  142. }
  143. private showFence(element, action) {
  144. let nodes = element.children;
  145. for (let i = 0; i < nodes.length; i++) {
  146. const element = nodes[i];
  147. let spine = element.getComponent(sp.Skeleton);
  148. if (spine) {
  149. spine.setAnimation(0, action, false);
  150. }
  151. }
  152. }
  153. }