FTreasureBox.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. import FqLogin from "../../../login/FqLogin";
  2. import { AudioMgr } from "../../../main/ViewManage";
  3. import FPanelIcon from "../object/FPanelIcon";
  4. import BaseEvent from "./base/BaseEvent";
  5. /**
  6. * 宝箱
  7. */
  8. const { ccclass, property } = cc._decorator;
  9. @ccclass
  10. export default class FTreasureBox extends BaseEvent {
  11. @property({
  12. displayName: '地图元素id'
  13. })
  14. boxId: string = '28';
  15. @property([cc.String])
  16. text: Array<string> = [];
  17. @property(sp.Skeleton)
  18. spine: sp.Skeleton = null;
  19. @property({
  20. displayName: '提示图标',
  21. type: cc.SpriteFrame
  22. })
  23. mTipsIcon: cc.SpriteFrame = null;
  24. @property(cc.Node)
  25. guides: Array<cc.Node> = [];//引导标识
  26. @property({
  27. displayName: '是否需要引导穿装备'
  28. })
  29. isGuide: boolean = false
  30. @property({
  31. displayName: '指引步骤'
  32. })
  33. guideStep: number = 0;
  34. /**
  35. * 控制的栅栏机关
  36. */
  37. @property({
  38. displayName: '控制的机关',
  39. type: [cc.Node],
  40. })
  41. mFenceTrigger: Array<cc.Node> = [];
  42. @property({
  43. displayName: '消失的提示',
  44. type: cc.Node
  45. })
  46. mCancelNode: cc.Node = null;
  47. private isOpen = false;
  48. onLoad() {
  49. super.onLoad()
  50. let stage = this.ff.main.player.stage;
  51. if (stage.element.indexOf(this.boxId) >= 0) {
  52. this.node.destroy();
  53. for (let i = 0; i < this.mFenceTrigger.length; i++) {
  54. const element = this.mFenceTrigger[i];
  55. element.destroy()
  56. }
  57. }
  58. }
  59. /**
  60. * 主角进入碰撞区域
  61. */
  62. public onBegin(tag: number) {
  63. if (this.isOpen) {
  64. return
  65. }
  66. if (tag == 1) {
  67. this.showOpt(this.mTipsIcon, () => {
  68. if (this.mCancelNode) {
  69. this.mCancelNode.destroy()
  70. }
  71. this.openBox();
  72. })
  73. }
  74. }
  75. /**
  76. * 主角离开碰撞区域
  77. */
  78. public onEnd(tag: number) {
  79. if (tag == 1) {
  80. this.closeOpt()
  81. }
  82. }
  83. private openBox() {
  84. this.closeOpt()
  85. this.isOpen = true;
  86. this.pause()
  87. for (let i = 0; i < this.guides.length; i++) {
  88. const element = this.guides[i];
  89. element.destroy();
  90. }
  91. this.guides = [];
  92. this.spine.setCompleteListener(() => {
  93. FqLogin.commitEvent(this.node.name, '', '');
  94. this.spine.setCompleteListener(null);
  95. //与服务器通讯
  96. this.getMapObject(this.boxId, () => {
  97. this.showDialog1()
  98. })
  99. });
  100. this.spine.setAnimation(0, 'open', false);
  101. this.ff.main.playerEffectByPath(AudioMgr.box);
  102. }
  103. private showDialog1() {
  104. if (this.text.length <= 0) {
  105. this.resume()
  106. return
  107. }
  108. this.showDialog(this.ff.mainSprite.node, this.text, () => {
  109. this.resume()
  110. if (this.isGuide) {
  111. if (this.guideStep == 0) {
  112. this.guide()
  113. } else if (this.guideStep == 1) {
  114. this.guide_1()
  115. }
  116. }
  117. })
  118. }
  119. /**
  120. * 开始引导穿装备
  121. */
  122. private guide() {
  123. for (let i = 0; i < this.mFenceTrigger.length; i++) {
  124. const element = this.mFenceTrigger[i];
  125. element.destroy()
  126. }
  127. let main = this.ff.main
  128. let guideMask = main.mGuideMask
  129. let res = this.ff.fres;
  130. let hudNode = res.mHudNode.children[0]
  131. guideMask.setTargetNode(hudNode)
  132. guideMask.show()
  133. let panelIcon = hudNode.getComponent(FPanelIcon)
  134. panelIcon.inGuide = true
  135. panelIcon.setGuideCallback(() => {
  136. panelIcon.setGuideCallback(null)
  137. guideMask.close();
  138. this.ff.firstGetSkillTips();
  139. })
  140. }
  141. /**
  142. * 开始引导强化装备
  143. */
  144. private guide_1() {
  145. for (let i = 0; i < this.mFenceTrigger.length; i++) {
  146. const element = this.mFenceTrigger[i];
  147. element.destroy()
  148. }
  149. let main = this.ff.main
  150. let guideMask = main.mGuideMask
  151. let res = this.ff.fres;
  152. let hudNode = res.mHudNode.children[0];
  153. guideMask.setTargetNode(hudNode);
  154. guideMask.show();
  155. let panelIcon = hudNode.getComponent(FPanelIcon);
  156. panelIcon.inGuide = true;
  157. panelIcon.guideStep = this.guideStep;
  158. panelIcon.setGuideCallback(() => {
  159. guideMask.close();
  160. })
  161. }
  162. }