FDialogNoneNPC.ts 5.4 KB

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