FDialogNoneXJ.ts 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. import FqLogin from "../../../login/FqLogin";
  2. import { AudioMgr } from "../../../main/ViewManage";
  3. import { HttpStateType, ReveData } from "../../../util/CHttp";
  4. import BaseEvent from "./base/BaseEvent";
  5. import WOneByone from "./map1/WOneByone";
  6. /**
  7. * 闲聊脚本
  8. */
  9. const { ccclass, property } = cc._decorator;
  10. @ccclass
  11. export default class FDialogNoneXJ extends BaseEvent {
  12. @property({
  13. displayName: '地图元素编号'
  14. })
  15. public mapGoodId: string = '23';
  16. @property({
  17. displayName: "拾取物品ID"
  18. })
  19. public goodId: number = 2002;
  20. @property(cc.Prefab)
  21. mMapDialog: cc.Prefab = null;
  22. @property({
  23. displayName: '对话内容',
  24. type: [cc.String]
  25. })
  26. text: Array<string> = [];
  27. @property({
  28. displayName: '完成后的对话',
  29. type: [cc.String]
  30. })
  31. finish: Array<string> = [];//完成后的对话
  32. @property({
  33. displayName: '靠近的提示',
  34. type: cc.Node
  35. })
  36. icon: cc.Node = null;
  37. @property({
  38. displayName: "拾取列表",
  39. type: [cc.Node]
  40. })
  41. goodList: cc.Node[] = [];
  42. @property({
  43. displayName: '提示图标',
  44. type: cc.SpriteFrame
  45. })
  46. mTipsIcon: cc.SpriteFrame = null;
  47. @property({
  48. displayName: 'NPC动画',
  49. type: sp.Skeleton
  50. })
  51. spine: sp.Skeleton = null;
  52. /**
  53. * 控制的栅栏
  54. */
  55. @property([cc.Node])
  56. mFenceTrigger: Array<cc.Node> = [];
  57. private showParticle = false;
  58. onLoad() {
  59. super.onLoad()
  60. if (this.icon) {
  61. this.icon.active = false;
  62. }
  63. let stage = this.ff.main.player.stage;
  64. if (stage.element.indexOf(this.mapGoodId) > -1) {
  65. for (let i = 0; i < this.mFenceTrigger.length; i++) {
  66. const element = this.mFenceTrigger[i];
  67. element.active = false;
  68. }
  69. for (let i = 0; i < this.goodList.length; i++) {
  70. const element = this.goodList[i];
  71. element.active = false;
  72. }
  73. this.node.active = false;
  74. }
  75. }
  76. onBegin(tag: number) {
  77. if (tag == 1) {
  78. this.showOpt(this.mTipsIcon, () => {
  79. this.startDialog()
  80. })
  81. } else if (tag == 2) {
  82. if (this.icon) {
  83. this.icon.active = true;
  84. }
  85. }
  86. }
  87. onEnd(tag: number) {
  88. if (tag == 1) {
  89. this.closeOpt()
  90. } else if (tag == 2) {
  91. if (this.icon) {
  92. this.icon.active = false;
  93. }
  94. }
  95. }
  96. public startDialog() {
  97. if (this.icon) {
  98. this.icon.active = false;
  99. }
  100. let head = this.ff.mFFheader;
  101. let count = head.getTmpCount(this.goodId);
  102. this.pause()
  103. if (count >= this.goodList.length) {
  104. head.removeTmpGood(this.goodId, count);
  105. if (this.mapGoodId != "") {
  106. this.getMapObject(this.mapGoodId, null);
  107. }
  108. this.dialog2();
  109. } else {
  110. this.dialog1();
  111. }
  112. }
  113. public closeButton() {
  114. if (this.icon) {
  115. this.icon.active = false;
  116. }
  117. this.closeOpt()
  118. }
  119. private dialog1(index: number = 0) {
  120. if (index >= this.text.length) {
  121. this.closeButton();
  122. this.resume();
  123. this.activateGood();
  124. return;
  125. }
  126. let texts = this.text[index].split('|')
  127. let mid = parseInt(texts.shift());
  128. if (mid == -1) {//主角
  129. let my = this.ff.mainSprite.node;
  130. this.showDialog(my, texts, () => {
  131. index++;
  132. this.dialog1(index);
  133. });
  134. } else {
  135. this.showDialog(this.node, texts, () => {
  136. index++;
  137. this.dialog1(index);
  138. });
  139. }
  140. }
  141. private dialog2(index: number = 0) {
  142. if (index >= this.finish.length) {
  143. this.closeButton();
  144. if (this.spine) {
  145. this.npcFly(() => {
  146. this.spine.node.parent.active = false;
  147. this.openmFenceTrigger();
  148. })
  149. } else {
  150. this.openmFenceTrigger();
  151. }
  152. FqLogin.commitEvent(this.node.name, '', '');
  153. return;
  154. }
  155. let texts = this.finish[index].split('|')
  156. let mid = parseInt(texts.shift());
  157. if (mid == -1) {//主角
  158. let my = this.ff.mainSprite.node;
  159. this.showDialog(my, texts, () => {
  160. index++;
  161. this.dialog2(index);
  162. });
  163. } else {
  164. this.showDialog(this.node, texts, () => {
  165. index++;
  166. this.dialog2(index);
  167. });
  168. }
  169. }
  170. npcFly(callBack: Function) {
  171. //1.幽灵变身
  172. this.spine.setAnimation(0, 'escape', false);
  173. this.spine.setCompleteListener(() => {
  174. this.spine.setCompleteListener(null)
  175. this.spine.setAnimation(0, 'fly', true);
  176. let pos = cc.v2(-370, 460);
  177. cc.tween(this.spine.node).sequence(
  178. cc.moveTo(1, pos),
  179. cc.callFunc(() => {
  180. callBack && callBack();
  181. })
  182. ).start()
  183. })
  184. }
  185. public openmFenceTrigger() {
  186. if (this.mFenceTrigger.length <= 0) {
  187. return
  188. }
  189. this.pause()
  190. this.moveCamera(this.mFenceTrigger[0].getPosition(), 1, () => {
  191. cc.tween(this.node).sequence(
  192. cc.callFunc(() => {
  193. for (let i = 0; i < this.mFenceTrigger.length; i++) {
  194. const element = this.mFenceTrigger[i];
  195. this.showFence(element, 'close');
  196. }
  197. this.ff.main.playerEffectByPath(AudioMgr.openDoor);
  198. }),
  199. cc.delayTime(1),
  200. cc.callFunc(() => {
  201. this.resume()
  202. for (let i = 0; i < this.mFenceTrigger.length; i++) {
  203. const element = this.mFenceTrigger[i];
  204. element.active = false;
  205. }
  206. })
  207. ).start();
  208. })
  209. }
  210. private showFence(element, action) {
  211. let nodes = element.children;
  212. for (let i = 0; i < nodes.length; i++) {
  213. const element = nodes[i];
  214. let spine = element.getComponent(sp.Skeleton);
  215. if (spine) {
  216. spine.setAnimation(0, action, false);
  217. }
  218. }
  219. }
  220. public activateGood() {
  221. if (this.showParticle) return
  222. this.showParticle = true;
  223. this.goodList.forEach(element => {
  224. if (element.name) {
  225. element.getChildByName("lizi_gs").active = true;
  226. }
  227. });
  228. }
  229. }