FDialogNoneNPC.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. //1.幽灵变身
  103. this.spine.setAnimation(0, 'escape', false);
  104. this.spine.setCompleteListener(() => {
  105. this.spine.setCompleteListener(null)
  106. this.spine.setAnimation(0, 'fly', true);
  107. let pos = cc.v2(-370, 460);
  108. cc.tween(this.spine.node).sequence(
  109. cc.moveTo(1, pos),
  110. cc.callFunc(() => {
  111. callBack && callBack();
  112. })
  113. ).start()
  114. })
  115. }
  116. public openmFenceTrigger() {
  117. if (this.mFenceTrigger.length <= 0) {
  118. return
  119. }
  120. this.pause()
  121. this.moveCamera(this.mFenceTrigger[0].getPosition(), 1, () => {
  122. cc.tween(this.node).sequence(
  123. cc.callFunc(() => {
  124. for (let i = 0; i < this.mFenceTrigger.length; i++) {
  125. const element = this.mFenceTrigger[i];
  126. this.showFence(element, 'close');
  127. }
  128. this.ff.main.playerEffectByPath(AudioMgr.openDoor);
  129. }),
  130. cc.delayTime(1),
  131. cc.callFunc(() => {
  132. this.resume()
  133. for (let i = 0; i < this.mFenceTrigger.length; i++) {
  134. const element = this.mFenceTrigger[i];
  135. element.active = false;
  136. }
  137. FqLogin.commitEvent(this.node.name, '', '');
  138. })
  139. ).start();
  140. })
  141. }
  142. private showFence(element, action) {
  143. let nodes = element.children;
  144. for (let i = 0; i < nodes.length; i++) {
  145. const element = nodes[i];
  146. let spine = element.getComponent(sp.Skeleton);
  147. if (spine) {
  148. spine.setAnimation(0, action, false);
  149. }
  150. }
  151. }
  152. }