FopenDoorOrder.ts 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. import FqLogin from "../../../../login/FqLogin";
  2. import { AudioMgr, GameViewType } from "../../../../main/ViewManage";
  3. import ViewObject from "../../../../main/ViewObject";
  4. import FqPay, { UM_EVENT_ID } from "../../../../pay/FqPay";
  5. import BaseEvent from "../base/BaseEvent";
  6. import FTipsEvent from "../tips/FTipsEvent";
  7. /**
  8. * 按照顺序打开机关
  9. *
  10. * 踩的顺序记录在第一个节点上
  11. */
  12. const { ccclass, property } = cc._decorator;
  13. @ccclass
  14. export default class FopenDoorOrder extends BaseEvent {
  15. @property({
  16. displayName: '顺序编号',
  17. type: cc.Integer
  18. })
  19. mNumber: number = 1;
  20. @property({
  21. displayName: '替换的图片',
  22. type: cc.Sprite,
  23. })
  24. mIcon: cc.Sprite = null;
  25. @property({
  26. displayName: '未踩上图片',
  27. type: cc.SpriteFrame,
  28. })
  29. mIcon0: cc.SpriteFrame = null;
  30. @property({
  31. displayName: '踩上后的图片',
  32. type: cc.SpriteFrame,
  33. })
  34. mIcon1: cc.SpriteFrame = null;
  35. @property({
  36. displayName: '踩上后点亮的火把',
  37. type: cc.Node,
  38. })
  39. mFireNode: cc.Node = null;
  40. @property({
  41. displayName: '失败后传送的位置',
  42. type: cc.Node,
  43. })
  44. mSiteNode: cc.Node = null;
  45. /**
  46. * 控制的栅栏机关
  47. */
  48. @property({
  49. displayName: '其它开关',
  50. type: [cc.Node],
  51. })
  52. mButtons: Array<cc.Node> = [];
  53. /**
  54. * 控制的栅栏机关
  55. */
  56. @property({
  57. displayName: '控制的机关',
  58. type: [cc.Node],
  59. })
  60. mFenceTrigger: Array<cc.Node> = [];
  61. @property({
  62. displayName: '提示文字',
  63. })
  64. mTipsWord = '';
  65. /**
  66. * 记录踩的顺序
  67. */
  68. private checkOrder = []
  69. private isHand = false
  70. /**
  71. * 玩家选择错误次数
  72. */
  73. private errorCount = 0;
  74. onLoad() {
  75. super.onLoad()
  76. this.mFireNode.active = false
  77. }
  78. onBegin(tag: number) {
  79. if (this.isHand) {
  80. return
  81. }
  82. this.isHand = true
  83. this.mIcon.spriteFrame = this.mIcon1
  84. this.mFireNode.active = true;
  85. this.checkOpen()
  86. }
  87. public checkOpen() {
  88. let firstNode = this.mButtons[0].getComponent(FopenDoorOrder)
  89. firstNode.checkOrder.push(this.mNumber)
  90. if (firstNode.checkOrder.length >= this.mButtons.length) {
  91. if (this.check(firstNode.checkOrder)) {
  92. this.openDoor()
  93. } else {
  94. this.resumeButton()
  95. firstNode.errorCount++
  96. if (firstNode.errorCount >= 3) {
  97. firstNode.errorCount = 0
  98. this.openEventTips()
  99. }
  100. }
  101. }
  102. }
  103. /**
  104. * 显示提示的提示
  105. */
  106. private openEventTips() {
  107. this.ff.main.viewManage.loadFunc(GameViewType.fight_map_event_tips, (viewObject: ViewObject) => {
  108. let tipsEvent: FTipsEvent = viewObject as FTipsEvent
  109. tipsEvent.init('查看提示', '点击查看提示,可偷窥答案')
  110. tipsEvent.setCallback(() => {
  111. viewObject.exitDistroy()
  112. let fqPay: FqPay = new FqPay(this.ff.main)
  113. if (this.node.name == 'event12') {
  114. fqPay.adVideo((result: number) => {
  115. if (result == 1) {
  116. this.openTips()
  117. }else if (result == -1) {
  118. this.ff.main.showTips('广告还未加载好,请稍后在试')
  119. }
  120. }, UM_EVENT_ID.ad_color_2_0, UM_EVENT_ID.ad_color_2_1)
  121. } else {
  122. fqPay.adVideo((result: number) => {
  123. if (result == 1) {
  124. this.openTips()
  125. }else if (result == -1) {
  126. this.ff.main.showTips('广告还未加载好,请稍后在试')
  127. }
  128. }, UM_EVENT_ID.ad_color_5_0, UM_EVENT_ID.ad_color_5_1)
  129. }
  130. })
  131. viewObject.show();
  132. });
  133. }
  134. /**
  135. * 显示提示的提示
  136. */
  137. private openTips() {
  138. let firstNode = this.mButtons[0].getComponent(FopenDoorOrder)
  139. this.ff.main.viewManage.loadFunc(GameViewType.fight_map_event_tips, (viewObject: ViewObject) => {
  140. let tipsEvent: FTipsEvent = viewObject as FTipsEvent
  141. tipsEvent.init('确定', firstNode.mTipsWord)
  142. tipsEvent.setCallback(() => {
  143. viewObject.exitDistroy()
  144. })
  145. viewObject.show();
  146. });
  147. }
  148. /**
  149. * 检查顺序是否正确
  150. * @param array
  151. * @returns
  152. */
  153. private check(array: Array<number>): boolean {
  154. for (let i = 0; i < array.length; i++) {
  155. const element = array[i];
  156. if (element != i + 1) {
  157. return false
  158. }
  159. }
  160. return true
  161. }
  162. /**
  163. * 恢复所有按钮
  164. */
  165. private resumeButton() {
  166. for (let i = 0; i < this.mButtons.length; i++) {
  167. const element = this.mButtons[i];
  168. let fdo = element.getComponent(FopenDoorOrder)
  169. fdo.mIcon.spriteFrame = fdo.mIcon0
  170. fdo.mFireNode.active = false;
  171. fdo.isHand = false
  172. fdo.checkOrder = []
  173. }
  174. let firstNode = this.mButtons[0].getComponent(FopenDoorOrder)
  175. cc.tween(this).sequence(
  176. cc.delayTime(0.1),
  177. cc.callFunc(() => {
  178. this.ff.mainSprite.node.setPosition(firstNode.mSiteNode.getPosition())
  179. })
  180. ).start()
  181. }
  182. private openDoor() {
  183. this.pause()
  184. this.moveCamera(this.mFenceTrigger[0].getPosition(), 1, () => {
  185. cc.tween(this.node).sequence(
  186. cc.callFunc(() => {
  187. for (let i = 0; i < this.mFenceTrigger.length; i++) {
  188. const element = this.mFenceTrigger[i];
  189. this.showFence(element, 'close');
  190. }
  191. this.ff.main.playerEffectByPath(AudioMgr.openDoor);
  192. }),
  193. cc.delayTime(1),
  194. cc.callFunc(() => {
  195. this.resume()
  196. FqLogin.commitEvent(this.node.name, '', '');
  197. for (let i = 0; i < this.mFenceTrigger.length; i++) {
  198. const element = this.mFenceTrigger[i];
  199. element.active = false;
  200. }
  201. })
  202. ).start();
  203. })
  204. }
  205. private showFence(element, action) {
  206. let nodes = element.children;
  207. for (let i = 0; i < nodes.length; i++) {
  208. const element = nodes[i];
  209. let spine = element.getComponent(sp.Skeleton);
  210. if (spine) {
  211. spine.setAnimation(0, action, false);
  212. }
  213. }
  214. }
  215. }