FDialogNoneNPC.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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.pause()
  74. this.dialog1();
  75. }
  76. public closeButton() {
  77. if (this.icon) {
  78. this.icon.active = false;
  79. }
  80. this.closeOpt()
  81. }
  82. public dialog1(index: number = 0) {
  83. if (index >= this.text1.length) {
  84. this.npcFly(() => {
  85. this.openmFenceTrigger();
  86. this.spine.node.parent.active = false;
  87. this.closeOpt();
  88. });
  89. this.closeButton();
  90. this.resume();
  91. return;
  92. }
  93. let texts = this.text1[index].split('|')
  94. let mid = parseInt(texts.shift());
  95. if (mid == -1) {//主角
  96. let my = this.ff.mainSprite.node;
  97. this.showDialog(my, texts, () => {
  98. index++;
  99. this.dialog1(index);
  100. });
  101. } else {
  102. this.showDialog(this.node, texts, () => {
  103. index++;
  104. this.dialog1(index);
  105. });
  106. }
  107. }
  108. public dialog2(index: number = 0) {
  109. if (index >= this.text2.length) {
  110. this.npcFly(() => {
  111. this.openmFenceTrigger();
  112. this.spine.node.parent.active = false;
  113. this.closeOpt();
  114. });
  115. this.closeButton();
  116. this.resume();
  117. return;
  118. }
  119. let texts = this.text2[index].split('|')
  120. let mid = parseInt(texts.shift());
  121. if (mid == -1) {//主角
  122. let my = this.ff.mainSprite.node;
  123. this.showDialog(my, texts, () => {
  124. index++;
  125. this.dialog2(index);
  126. });
  127. } else {
  128. this.showDialog(this.node, texts, () => {
  129. index++;
  130. this.dialog2(index);
  131. });
  132. }
  133. }
  134. npcFly(callBack: Function) {
  135. return
  136. //1.幽灵变身
  137. this.spine.setAnimation(0, 'escape', false);
  138. this.spine.setCompleteListener(() => {
  139. this.spine.setCompleteListener(null)
  140. this.spine.setAnimation(0, 'fly', true);
  141. let pos = cc.v2(-370, 460);
  142. cc.tween(this.spine.node).sequence(
  143. cc.moveTo(1, pos),
  144. cc.callFunc(() => {
  145. callBack && callBack();
  146. })
  147. ).start()
  148. })
  149. }
  150. public openmFenceTrigger() {
  151. if (this.mFenceTrigger.length <= 0) {
  152. return
  153. }
  154. this.pause()
  155. this.moveCamera(this.mFenceTrigger[0].getPosition(), 1, () => {
  156. cc.tween(this.node).sequence(
  157. cc.callFunc(() => {
  158. for (let i = 0; i < this.mFenceTrigger.length; i++) {
  159. const element = this.mFenceTrigger[i];
  160. this.showFence(element, 'close');
  161. }
  162. this.ff.main.playerEffectByPath(AudioMgr.openDoor);
  163. }),
  164. cc.delayTime(1),
  165. cc.callFunc(() => {
  166. this.resume()
  167. for (let i = 0; i < this.mFenceTrigger.length; i++) {
  168. const element = this.mFenceTrigger[i];
  169. element.active = false;
  170. }
  171. FqLogin.commitEvent(this.node.name, '', '');
  172. })
  173. ).start();
  174. })
  175. }
  176. private showFence(element, action) {
  177. let nodes = element.children;
  178. for (let i = 0; i < nodes.length; i++) {
  179. const element = nodes[i];
  180. let spine = element.getComponent(sp.Skeleton);
  181. if (spine) {
  182. spine.setAnimation(0, action, false);
  183. }
  184. }
  185. }
  186. }