GamePlay.ts 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274
  1. import CellItem from "./view/uiItem/CellItem";
  2. import { PROPTYPE } from "./data/Enum";
  3. import PoolMgr, { NODEPOOLPREFABTYPE } from "./mgr/PoolMgr";
  4. import GameConst from "./data/GameConst";
  5. import GameLogic from "./util/GameLogic";
  6. import BonusTip from "./view/effect/BonusTip";
  7. import DataMgr from "./mgr/DataMgr";
  8. import EffectMgr, { TIP_SPRITEITEM_TYPE } from "./mgr/EffectMgr";
  9. import { DataEventId, EVENT_TYPE, GameProp, VideoAdType } from "../game/data/GameData";
  10. import JsbSystem from "../mk/system/JsbSystem";
  11. const { ccclass, property } = cc._decorator;
  12. @ccclass
  13. export default class GamePlay extends cc.Component {
  14. /**单例模式 */
  15. public static Inst: GamePlay = null;
  16. /**背景 */
  17. @property(cc.Node)
  18. node_bg: cc.Node = null;
  19. /**标题 */
  20. @property(cc.Node)
  21. node_top: cc.Node = null;
  22. @property(cc.Label)
  23. label_level: cc.Label = null;
  24. @property(cc.Node)
  25. node_redPacketIcon: cc.Node = null;
  26. @property({ type: cc.Node, displayName: "气泡红包1" })
  27. btn_gameGetRed1: cc.Node = null;
  28. @property({ type: cc.Node, displayName: "气泡红包2" })
  29. btn_gameGetRed2: cc.Node = null;
  30. @property({ type: cc.Node, displayName: "气泡红包3" })
  31. btn_gameGetRed3: cc.Node = null;
  32. @property({ type: cc.Node, displayName: "气泡红包3" })
  33. btn_gameGetRed4: cc.Node = null;
  34. /**内容 */
  35. @property(cc.Node)
  36. node_content: cc.Node = null;
  37. /**cell背景块 */
  38. @property(cc.Node)
  39. node_cellBg: cc.Node = null;
  40. /**暂停按钮 */
  41. @property(cc.Node)
  42. node_pauseBtn: cc.Node = null;
  43. /**进度条UI */
  44. @property(cc.Node)
  45. node_progressUI: cc.Node = null;
  46. @property(cc.Sprite)
  47. spr_progress: cc.Sprite = null;
  48. /**重置按钮 */
  49. @property(cc.Node)
  50. node_resetBtn: cc.Node = null;
  51. @property(cc.Label)
  52. label_resetPropNum: cc.Label = null;
  53. /**锤子按钮 */
  54. @property(cc.Node)
  55. node_hammerBtn: cc.Node = null;
  56. @property(cc.Label)
  57. label_hammerPropNum: cc.Label = null;
  58. /**变色按钮 */
  59. @property(cc.Node)
  60. node_changeBtn: cc.Node = null;
  61. @property(cc.Label)
  62. label_changePropNum: cc.Label = null;
  63. /**更改CellItemUI */
  64. @property(cc.Node)
  65. node_changeCellItemUI: cc.Node = null;
  66. /**特效UI */
  67. @property(cc.Node)
  68. node_effectUI: cc.Node = null;
  69. /**关卡红包UI */
  70. @property(cc.Node)
  71. node_levelRedPacketUI: cc.Node = null;
  72. /**点击检测遮罩 */
  73. @property(cc.Node)
  74. node_touchListenMask: cc.Node = null;
  75. /**当前进度得分 */
  76. public curProgressScore: number = 0;
  77. /**当前得分 */
  78. public curGetScore: number = 0;
  79. /**目标分数 */
  80. public targetScore: number = 0;
  81. /**最终得分 */
  82. public finalGetScore: number = 0;
  83. /**增加得分速度 */
  84. public addScoreSpeed: number = 4;
  85. // /**道具类型 */
  86. // public curPropType: PROPTYPE = PROPTYPE.Null;
  87. /**消消的方块数组
  88. * @param:key index_x
  89. * @param: value 整个纵列数组
  90. */
  91. public cellItemDic: { [key: number]: CellItem[] } = {};
  92. public cellItemArr: CellItem[] = [];
  93. /**清理CellItem的Vec数组 */
  94. public cleanedVecArr: cc.Vec2[] = [];
  95. /**能够清理的vecArr组 */
  96. public couldCleanVecArr: cc.Vec2[] = [];
  97. /**清理纵列的x */
  98. public cleanXIndexArr: number[] = [];
  99. /**所有的清理 */
  100. public allCleanedXArr: number[] = [];
  101. /**剩余未移除的xIndex */
  102. public leftXIndexArr: number[] = [];
  103. /**当前选择的cellItem */
  104. public curSelectCellItem: CellItem = null;
  105. /**当前点击得cellItem */
  106. public curClickCellItem: CellItem = null;
  107. /**当前选择的道具按钮 */
  108. public curSelectPropBtn: cc.Node = null;
  109. /**是否可以点击 */
  110. public ifCouldClick: boolean = true;
  111. /**是否已经通关 */
  112. public ifPass: boolean = false;
  113. /**是否获取后台回调 */
  114. public ifGetPass: boolean = false;
  115. /**是否打开积分红包 */
  116. public ifOpenScoreRedPacket: boolean = false;
  117. /**当前的道具类型 */
  118. private _curPropType: PROPTYPE;
  119. public get curPropType(): PROPTYPE {
  120. return this._curPropType;
  121. }
  122. public set curPropType(v: PROPTYPE) {
  123. //LogUtil.log("this.curSelectPropBtn", this.curSelectPropBtn);
  124. let ani = null;
  125. if (this.curSelectPropBtn) {
  126. mk.console.log("this.curSelectPropBtn", this.curSelectPropBtn);
  127. ani = this.curSelectPropBtn.children[1].getComponent(cc.Animation);
  128. }
  129. if (v == PROPTYPE.Null) {
  130. if (ani) {
  131. ani.play("ani_normalBtn");
  132. }
  133. this.setPropBtnNormalTip(this.curSelectPropBtn)
  134. }
  135. else {
  136. if (ani) {
  137. ani.play("ani_selectBtn");
  138. }
  139. this.setPropBtnSelectTip(this.curSelectPropBtn)
  140. }
  141. this._curPropType = v;
  142. }
  143. //刷新计时
  144. private curTime = 0;
  145. private isAllShow = false;
  146. private isShowRedPacket = true;
  147. // LIFE-CYCLE CALLBACKS:
  148. onLoad() {
  149. GamePlay.Inst = this;
  150. mk.event.register("event_guide", this.clickGuide, this);
  151. }
  152. private clickGuide(data: string) {
  153. if (data == "1_3") {//点击即可消除哦!
  154. this.cellItemDic[0][0] && this.cellItemDic[0][0].onClick();
  155. }
  156. else if (data == "1_5") {//再点击一次增加大量进度哦
  157. this.cellItemDic[1][1] && this.cellItemDic[1][1].onClick();
  158. }
  159. }
  160. public start() {
  161. mk.data.sendDataEvent(DataEventId.level, "关卡开启");
  162. PoolMgr.Inst.initPoolPrefab();
  163. GameConst.loadConfig().then(() => {
  164. this.adapt();
  165. // AudioMgr.Inst.playMusic(AUDIO_CLIP_NAME.bg_game);
  166. mk.audio.playMusic("music_gameBg");
  167. //读取在线分数数据
  168. gData.gameData.setProp(GameProp.curTotalScore, 0);//杀掉进程,则清零积分
  169. let score = gData.gameData.getProp(GameProp.curTotalScore);
  170. this.curGetScore = score;
  171. this.curProgressScore = score;
  172. this.finalGetScore = score;
  173. console.log("score", score);
  174. this.initView();
  175. this.initEvent();
  176. this.intervalShowGuide();
  177. this.intervalShowInter();
  178. cc.tween(this.btn_gameGetRed1).delay(0.2).to(1, { y: 60 }, { easing: "" }).to(1, { y: 0 }, { easing: "" }).union().repeatForever().start();
  179. cc.tween(this.btn_gameGetRed2).delay(0.4).to(1, { y: 60 }, { easing: "" }).to(1, { y: 0 }, { easing: "" }).union().repeatForever().start();
  180. cc.tween(this.btn_gameGetRed3).delay(0.2).to(1, { y: 60 }, { easing: "" }).to(1, { y: 0 }, { easing: "" }).union().repeatForever().start();
  181. cc.tween(this.btn_gameGetRed4).delay(0.4).to(1, { y: 60 }, { easing: "" }).to(1, { y: 0 }, { easing: "" }).union().repeatForever().start();
  182. }).catch();
  183. this.qipaoShow();
  184. this.btn_gameGetRed1.active = false;
  185. this.btn_gameGetRed3.active = false;
  186. this.btn_gameGetRed4.active = false;
  187. this.isShowRedPacket = gData.gameData.funOpenData[7] == "1";
  188. if (this.isShowRedPacket) {
  189. mk.event.register("refreshGameUI", this.refreshRedPacketUI.bind(this), this);
  190. }
  191. }
  192. onEnable() {
  193. mk.console.log("PROPTYPE[PROPTYPE.Change]", PROPTYPE.Change);
  194. }
  195. onDisable() {
  196. //退出游戏归置下道具状态
  197. this.curPropType = PROPTYPE.Null;
  198. if (this.curSelectCellItem) {
  199. this.curSelectCellItem.normal();
  200. }
  201. if (this.node_changeCellItemUI.active = true) {
  202. this.node_changeCellItemUI.active = false;
  203. }
  204. }
  205. adapt() {
  206. mk.console.log("进行适配!!!!!!!!!!!!!!!!");
  207. //背景适配
  208. this.node_bg.setContentSize(new cc.Size(cc.winSize.width, cc.winSize.height));
  209. // this.node_top.y = (cc.winSize.height - this.node_top.height) * 0.5 + 5;
  210. const world_pos = gData.gameData.gameStyle.node_top_ui.parent.convertToWorldSpaceAR(gData.gameData.gameStyle.node_top_ui.getPosition());
  211. const node_pos = this.node_top.parent.convertToNodeSpaceAR(world_pos);
  212. this.node_top.y = node_pos.y - 40;
  213. }
  214. update(dt) {
  215. this.doBubbleRedPacketLogic(dt);
  216. if (this.curProgressScore >= this.curGetScore) {
  217. if (this.curProgressScore == 0) {
  218. this.spr_progress.fillRange = 0;
  219. }
  220. return;
  221. }
  222. else {
  223. if (this.curProgressScore >= this.targetScore) {
  224. this.curProgressScore = this.curGetScore;
  225. this.initScore();
  226. }
  227. else {
  228. let nextProgressScore: number = this.curProgressScore + this.addScoreSpeed;
  229. if (/**this.curProgressScore < GamePlay.Inst.targetScore && */nextProgressScore >= GamePlay.Inst.targetScore) {
  230. let node_getTargetScoreTip = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.GetTargetScoreTip);
  231. GamePlay.Inst.node_effectUI.addChild(node_getTargetScoreTip);
  232. //进度到达开始显示(挪到initScore判断)
  233. // gData.reward.subType = 2;
  234. // mk.ad.videoAdType = VideoAdType.LevelScoreRedBag;
  235. // mk.ui.openPanel("module/reward/rewardLuck");
  236. }
  237. this.curProgressScore = nextProgressScore;
  238. if (this.curProgressScore >= this.curGetScore) {
  239. this.curProgressScore = this.curGetScore;
  240. }
  241. this.initScore();
  242. }
  243. }
  244. }
  245. /**初始化视图 */
  246. initView() {
  247. this.initLevel();
  248. this.initTotalScore();
  249. this.initScore();
  250. this.initProgress();
  251. this.initHammerPropNum();
  252. this.setPropBtnNormalTip(this.node_hammerBtn);
  253. this.initResetPropNum();
  254. this.setPropBtnNormalTip(this.node_resetBtn);
  255. this.initChanegPropNum();
  256. this.setPropBtnNormalTip(this.node_changeBtn);
  257. this.initCellBg();
  258. this.initCell();
  259. }
  260. /**初始化事件 */
  261. initEvent() {
  262. this.node_pauseBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  263. this.node_resetBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  264. this.node_hammerBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  265. this.node_changeBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  266. this.node_redPacketIcon.on(cc.Node.EventType.TOUCH_END, this.onClickRedPacketIcon, this);
  267. mk.event.register(EVENT_TYPE.BACK_WxAuth, this.onWxAuthBack, this);
  268. }
  269. /**初始化关卡数目 */
  270. initLevel() {
  271. mk.console.log("[Game] levelNum", gData.gameData.getProp(GameProp.levelNum));
  272. let level = gData.gameData.getProp(GameProp.levelNum);
  273. this.label_level.string = `第${level + 1}关`
  274. }
  275. /**初始化总分数 */
  276. initTotalScore() {
  277. if (this.targetScore) {
  278. return;
  279. }
  280. let level = gData.gameData.getProp(GameProp.levelNum);
  281. //加入一些随机值,而不是都能获得过关红包
  282. this.targetScore = 450 + level * (5 + Math.floor(Math.random() * 15));
  283. // //测试切换
  284. // this.targetScore = 5000;
  285. this.addScoreSpeed = Math.floor(this.targetScore / 200) * 2 + 4;
  286. mk.console.log("this.addScoreSpeed", this.addScoreSpeed);
  287. }
  288. /**初始化得分 */
  289. initScore() {
  290. this.initProgress();
  291. }
  292. /**初始化进度 */
  293. initProgress() {
  294. let progress = this.curProgressScore / this.targetScore;
  295. progress = progress > 1 ? 1 : progress;
  296. this.spr_progress.fillRange = progress;
  297. if (progress >= 1) {
  298. //进度到达开始显示
  299. gData.reward.subType = 2;
  300. mk.ad.videoAdType = VideoAdType.LevelScoreRedBag;
  301. let node_rewardLuck = mk.ui.getCurOnPanel("rewardLuck");
  302. if (!node_rewardLuck && gData.gameData.funOpenData['6'] == '1') {
  303. mk.ui.openPanel("module/reward/rewardLuck");
  304. }
  305. }
  306. // if (progress >= 1) {
  307. // this.pass();
  308. // mk.ui.openPanel("module/reward/rewardMission");
  309. // }
  310. // LogUtil.log("progressprogressprogressprogressprogressprogress", progress);
  311. }
  312. /**初始化道具 */
  313. initPropNum() {
  314. this.initHammerPropNum();
  315. this.initResetPropNum();
  316. this.initChanegPropNum();
  317. }
  318. /**初始化锤子道具数目 */
  319. initHammerPropNum() {
  320. let hammerPropNum = gData.gameData.getProp(GameProp.hammerPropNum);
  321. if (hammerPropNum) {
  322. this.label_hammerPropNum.string = hammerPropNum.toString();
  323. }
  324. else {
  325. this.label_hammerPropNum.string = "+";
  326. }
  327. }
  328. /**初始化重置道具数目 */
  329. initResetPropNum() {
  330. let resetPropNum = gData.gameData.getProp(GameProp.resetPropNum);
  331. if (resetPropNum) {
  332. this.label_resetPropNum.string = resetPropNum.toString();
  333. }
  334. else {
  335. this.label_resetPropNum.string = "+";
  336. }
  337. }
  338. /**初始化替换道具数目 */
  339. initChanegPropNum() {
  340. let changePropNum = gData.gameData.getProp(GameProp.changePropNum);
  341. if (changePropNum) {
  342. this.label_changePropNum.string = changePropNum.toString();
  343. }
  344. else {
  345. this.label_changePropNum.string = "+";
  346. }
  347. }
  348. // update (dt) {}
  349. /**初始化cellBg */
  350. initCellBg() {
  351. for (var i = 0; i < GameConst.col_num; i++) {
  352. for (var j = 0; j < GameConst.row_num; j++) {
  353. let prefab_cellBg = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.CellBg);
  354. // LogUtil.log("prefab_cellBg", prefab_cellBg);
  355. let node_cellBg = cc.instantiate(prefab_cellBg);
  356. this.node_cellBg.addChild(node_cellBg);
  357. }
  358. }
  359. }
  360. /**初始化cell */
  361. public initCell() {
  362. this.addCellItemFuc = () => { this.addCellItem(); };
  363. this.schedule(this.addCellItemFuc, 0.05);
  364. }
  365. public addCellItemFuc: Function = null;
  366. public curXIndex: number = 0;
  367. public curYIndex: number = 7;
  368. /**添加CellItem */
  369. public addCellItem() {
  370. mk.console.log("addCellItem!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  371. this.addColCellItem();
  372. this.curXIndex++;
  373. if (this.curXIndex >= GameConst.col_num) {
  374. this.unschedule(this.addCellItemFuc);
  375. // this.getStartRedPacketCellItem();
  376. }
  377. }
  378. /**添加纵列的cellItem */
  379. public addColCellItem() {
  380. this.cellItemDic[this.curXIndex] = [];
  381. for (var i = GameConst.row_num - 1; i >= 0; i--) {
  382. let prefab_cellItem = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.CellItem);
  383. let node_prefab = cc.instantiate(prefab_cellItem);
  384. let cellItem = node_prefab.getComponent(CellItem);
  385. cellItem.init(this.curXIndex, i);
  386. this.cellItemDic[this.curXIndex][i] = cellItem;
  387. this.cellItemArr.push(cellItem);
  388. this.node_content.addChild(node_prefab);
  389. }
  390. }
  391. /**点击按钮 */
  392. onClickBtn(event: cc.Event.EventTouch) {
  393. this.intervalShowGuide();
  394. this.intervalShowInter();
  395. //是否已经通关
  396. if (this.ifPass) {
  397. EffectMgr.Inst.addTip("通关结算啦,请稍后操作哈")
  398. return;
  399. }
  400. // AudioMgr.Inst.playEffect(AUDIO_CLIP_NAME.buttonClick);
  401. mk.audio.playEffect("button");
  402. switch (event.currentTarget) {
  403. case this.node_pauseBtn:
  404. this.onClickPauseBtn();
  405. break;
  406. case this.node_hammerBtn:
  407. this.onClickHammerBtn();
  408. break;
  409. case this.node_changeBtn:
  410. this.onClickChangeBtn();
  411. break;
  412. case this.node_resetBtn:
  413. this.onClickResetBtn();
  414. break;
  415. }
  416. }
  417. /**点击暂停按钮 */
  418. onClickPauseBtn() {
  419. mk.ui.openPanel("game/prefab/uiPanel/PauseUI")
  420. }
  421. /**点击分享 */
  422. public onClickShare() {
  423. if (!gData.loginData.isAuth) {
  424. // mk.tip.pop("请先点击头像,在设置界面授权");
  425. JsbSystem.WxAuth();
  426. return;
  427. }
  428. JsbSystem.sharePic();
  429. }
  430. /**点击重置按钮 */
  431. onClickResetBtn() {
  432. //设置当前选择的道具按钮
  433. this.setCurSelectPropBtn(this.node_resetBtn);
  434. this.curPropType = PROPTYPE.Reset;
  435. let resetPropNum = gData.gameData.getProp(GameProp.resetPropNum);
  436. if (!resetPropNum || resetPropNum <= 0) {
  437. mk.ui.openPanel("game/prefab/uiPanel/GetPropUI");
  438. return;
  439. }
  440. // AudioMgr.Inst.playEffect(AUDIO_CLIP_NAME.refresh);
  441. mk.audio.playEffect("ef_refresh");
  442. let keys = Object.keys(this.cellItemDic);
  443. for (var i = 0; i < keys.length; i++) {
  444. let key = Number(keys[i]);
  445. let colCellItemArr = this.cellItemDic[key];
  446. for (var j = 0; j < colCellItemArr.length; j++) {
  447. let cellItem = colCellItemArr[j];
  448. if (cellItem) {
  449. cellItem.reset();
  450. }
  451. }
  452. }
  453. //暂时不扣
  454. DataMgr.Inst.updatePropNum(2, GamePlay.Inst.curPropType, -1);
  455. this.curPropType = PROPTYPE.Null;
  456. //this.recycleAllCellItem();
  457. }
  458. //点击锤子按钮
  459. onClickHammerBtn() {
  460. //设置当前选择的道具按钮
  461. this.setCurSelectPropBtn(this.node_hammerBtn);
  462. this.curPropType = PROPTYPE.Hammer;
  463. let hammerPropNum = gData.gameData.getProp(GameProp.hammerPropNum);
  464. if (!hammerPropNum || hammerPropNum <= 0) {
  465. mk.ui.openPanel("game/prefab/uiPanel/GetPropUI");
  466. return;
  467. }
  468. DataMgr.Inst.updatePropNum(2, GamePlay.Inst.curPropType, -1);
  469. }
  470. //点击更换按钮
  471. onClickChangeBtn() {
  472. //设置当前选择的道具按钮
  473. this.setCurSelectPropBtn(this.node_changeBtn);
  474. this.curPropType = PROPTYPE.Change;
  475. let changePropNum = gData.gameData.getProp(GameProp.changePropNum);
  476. if (!changePropNum || changePropNum <= 0) {
  477. mk.ui.openPanel("game/prefab/uiPanel/GetPropUI");
  478. return;
  479. }
  480. DataMgr.Inst.updatePropNum(2, GamePlay.Inst.curPropType, -1);
  481. }
  482. /** 点击关卡气泡红包 */
  483. onClickLevelQiPaoPacket(index) {
  484. mk.ad.videoAdType = VideoAdType.LevelQiPaoRedBag;
  485. gData.gameData.openIndex = parseInt(index);
  486. }
  487. /**更改cellItem类型
  488. * @param cellItemType
  489. */
  490. changeCellItemType(cellItemType: number) {
  491. let pos_x = this.curSelectCellItem.node.x + GamePlay.Inst.node_content.x;
  492. let pos_y = this.curSelectCellItem.node.y + GamePlay.Inst.node_content.y;
  493. let node_change = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.Change);
  494. node_change.setPosition(pos_x, pos_y);
  495. GamePlay.Inst.node_effectUI.addChild(node_change);
  496. this.curSelectCellItem.setType(cellItemType)
  497. // AudioMgr.Inst.playEffect(AUDIO_CLIP_NAME.change);
  498. mk.audio.playEffect("ef_change");
  499. this.curSelectCellItem = null;
  500. }
  501. /**设置当前 */
  502. setCurSelectPropBtn(propBtn: cc.Node) {
  503. if (this.curSelectPropBtn) {
  504. let node_ani = this.curSelectPropBtn.children[1];
  505. if (node_ani) {
  506. let ani = node_ani.getComponent(cc.Animation);
  507. if (ani) {
  508. ani.play("ani_normalBtn");
  509. }
  510. }
  511. this.setPropBtnNormalTip(this.curSelectPropBtn);
  512. }
  513. this.curSelectPropBtn = propBtn;
  514. }
  515. /**设置道具普通提示 */
  516. setPropBtnNormalTip(propBtn: cc.Node) {
  517. if (!propBtn) {
  518. return;
  519. }
  520. let node_tip = propBtn.children[2];
  521. if (node_tip) {
  522. let label = null;
  523. switch (propBtn) {
  524. case this.node_hammerBtn:
  525. label = this.label_hammerPropNum;
  526. break;
  527. case this.node_resetBtn:
  528. label = this.label_resetPropNum;
  529. break;
  530. case this.node_changeBtn:
  531. label = this.label_changePropNum;
  532. break;
  533. }
  534. let str = label.string;
  535. let num = Number(str);
  536. let label_tip = node_tip.getComponent(cc.Label);
  537. mk.console.log("propBtn.name", propBtn.name);
  538. mk.console.log("num", num);
  539. if (num && num >= 1) {
  540. label_tip.string = "";
  541. }
  542. else {
  543. label_tip.string = "点我领取";
  544. }
  545. }
  546. }
  547. /**设置道具使用提示 */
  548. setPropBtnSelectTip(propBtn: cc.Node) {
  549. if (!propBtn) {
  550. return;
  551. }
  552. let node_tip = propBtn.children[2];
  553. if (node_tip) {
  554. let label = node_tip.getComponent(cc.Label)
  555. label.string = "道具使用中";
  556. }
  557. }
  558. /**显示CellItemUI */
  559. showChangeCellItemUI() {
  560. let cruSelectCellItem = this.curSelectCellItem;
  561. GamePlay.Inst.node_changeCellItemUI.active = true;
  562. // let min_x = -this.node_content.width * 0.5 + this.node_changeCellItemUI.width * 0.5;
  563. // let max_x = this.node_content.width * 0.5 + this.node_changeCellItemUI.width * 0.5;
  564. GamePlay.Inst.node_changeCellItemUI.y = cruSelectCellItem.node.y + cruSelectCellItem.node.height * 0.5 + GamePlay.Inst.node_changeCellItemUI.height * 0.5 + 20;
  565. }
  566. //onClick
  567. onClickRedPacketIcon() {
  568. if (this.spr_progress.fillRange == 1) {
  569. EffectMgr.Inst.addTip("已达成目标啦,过关发放哦");
  570. }
  571. else {
  572. EffectMgr.Inst.addTip("达到目标分数,才能领取哦");
  573. }
  574. }
  575. //找到红包的那个水果
  576. /**
  577. * 获取红包cellItem
  578. */
  579. public getStartRedPacketCellItem() {
  580. let totalCellItemArr: CellItem[] = this.cellItemArr.concat();
  581. let largeCellItemVec: cc.Vec2[] = [];
  582. for (var i = 0; i < totalCellItemArr.length; i++) {
  583. let cellItem = totalCellItemArr[i];
  584. if (!!cellItem) {
  585. GameLogic.getCouldCleanVecList(cellItem.x, cellItem.y, cellItem.type, true);
  586. // console.log("this.couldCleanVecArr", this.couldCleanVecArr);
  587. console.log("largeCellItemVec.length", largeCellItemVec.length)
  588. if (largeCellItemVec.length < this.couldCleanVecArr.length) {
  589. largeCellItemVec = this.couldCleanVecArr;
  590. }
  591. this.couldCleanVecArr.forEach(element => {
  592. let index = GameConst.col_num * element.x + (GameConst.row_num - 1 - element.y);
  593. totalCellItemArr[index] = null;
  594. this.cellItemDic[element.x][element.y].ifRemoved = false;
  595. });
  596. this.couldCleanVecArr = [];
  597. }
  598. }
  599. console.log("FC------------------------------------------------------------");
  600. let random_index = mk.math.random(0, largeCellItemVec.length - 1);
  601. let vec = largeCellItemVec[random_index];
  602. let redPcaketCellItem: CellItem = this.cellItemDic[vec.x][vec.y];
  603. redPcaketCellItem.showRedPacket();
  604. return redPcaketCellItem;
  605. }
  606. //自定义事件---------------------------------------------------------------------
  607. /**微信授权返回 */
  608. onWxAuthBack() {
  609. if (this.node.active) {
  610. this.restart();
  611. //
  612. let node_redPacketUI = mk.ui.getCurOnPanel("RedPacketUI")
  613. if (node_redPacketUI) {
  614. mk.ui.closePanel("RedPacketUI");
  615. }
  616. }
  617. this.initLevel();
  618. this.initTotalScore();
  619. this.initPropNum();
  620. mk.event.remove(EVENT_TYPE.BACK_WxAuth, this.onWxAuthBack, this);
  621. }
  622. //其他显示或逻辑项-------------------------------------------------------------------
  623. /**根据vecList清除cellItem */
  624. public cleanCellItemByVecList() {
  625. //LogUtil.log("[Game] Game.Inst.cleanCellItemVecArr", Game.Inst.cleanCellItemVecArr);
  626. //没有可清清除
  627. if (GamePlay.Inst.cleanedVecArr.length <= 0) {
  628. //FC:+ 是否可以点击
  629. this.ifCouldClick = true;
  630. EffectMgr.Inst.addTip("点击两个或以上消除哦");
  631. return;
  632. }
  633. //区分消除音效
  634. if (GamePlay.Inst.cleanedVecArr.length >= 4) {
  635. // AudioMgr.Inst.playEffect(AUDIO_CLIP_NAME.eliminate_bonus);
  636. mk.audio.playEffect("ef_eliminate_bonus");
  637. }
  638. else {
  639. //AudioMgr.Inst.playEffect(AUDIO_CLIP_NAME.eliminate);
  640. mk.audio.playEffect("ef_eliminate");
  641. }
  642. // AudioMgr.Inst.playEffect(AUDIO_CLIP_NAME.fly);
  643. mk.audio.playEffect("ef_fly");
  644. //同时消除
  645. for (var i = 0; i < GamePlay.Inst.cleanedVecArr.length; i++) {
  646. let vec = GamePlay.Inst.cleanedVecArr[i];
  647. //最后一个判定
  648. if (i == GamePlay.Inst.cleanedVecArr.length - 1) {
  649. this.checkBonusNum(GamePlay.Inst.cleanedVecArr.length);
  650. GamePlay.Inst.cellItemDic[vec.x][vec.y].recycle(false, true);
  651. }
  652. else {
  653. GamePlay.Inst.cellItemDic[vec.x][vec.y].recycle();
  654. }
  655. //回收 注释 改成如上
  656. //Game.Inst.cellItemDic[vec.x][vec.y].recycle();
  657. //Game.Inst.cellItemDic[vec.x][vec.y] = null;
  658. if (this.cleanXIndexArr.indexOf(vec.x) == -1) {
  659. this.cleanXIndexArr.push(vec.x);
  660. }
  661. }
  662. this.cleanXIndexArr.sort();
  663. //计算下全部移除的
  664. this.allCleanedXArr = GameLogic.getAllCleanXIndex(this.cleanXIndexArr);
  665. //FC:移除完,检测下落
  666. this.scheduleOnce(() => {
  667. //检测下落
  668. this.checkMoveDownCellItem();
  669. }, 0.2)
  670. }
  671. /**检测向下移动的cellItem */
  672. checkMoveDownCellItem() {
  673. mk.console.log("this.cleanXIndexArr", this.cleanXIndexArr);
  674. for (var i = 0; i < this.cleanXIndexArr.length; i++) {
  675. let xIndex = this.cleanXIndexArr[i];
  676. this.moveYCellItem(xIndex);
  677. }
  678. }
  679. /**移动
  680. * @param xIndex 移除的纵列
  681. * @param removedYIndex 移除的横向index
  682. */
  683. public moveYCellItem(xIndex: number) {
  684. // LogUtil.log("moveYCellItem x", xIndex, this.allCleanedXArr);
  685. /**移动的次序(第几个移动的用来控制延迟移动的时间) */
  686. let movedIndex: number = 0;
  687. //移动位置间隔(比如前面两个空位就移动两格)
  688. let intervalNum: number = 0;
  689. /**是否是全部清理的x */
  690. let ifAllCleanedX: boolean = this.allCleanedXArr.indexOf(xIndex) != -1;
  691. /**是否是最后清理的x(全部清理完才开始左移) */
  692. let ifLastCleanX: boolean = (xIndex == this.cleanXIndexArr[this.cleanXIndexArr.length - 1]);
  693. let cellItemDic = GamePlay.Inst.cellItemDic[xIndex];
  694. //计算y方向移动的最后一位(这样只计算一次不用循环)
  695. let lastMoveCellItemY: number = null;
  696. let leftLastCellItemY: number = null;
  697. if (ifLastCleanX) {
  698. let lastCellItemArrSort = this.cleanedVecArr.filter((vec) => vec.x == xIndex).sort();
  699. lastMoveCellItemY = lastCellItemArrSort[0].y;
  700. // LogUtil.log("lastCellItemY", xIndex, lastMoveCellItemY, lastCellItemArrSort);
  701. for (var i = 0; i < GameConst.row_num; i++) {
  702. if (cellItemDic) {
  703. let cellItem = cellItemDic[i];
  704. if (cellItem) {
  705. leftLastCellItemY = cellItem.y;
  706. // LogUtil.log("leftLastCellItemY", leftLastCellItemY);
  707. break;
  708. }
  709. }
  710. }
  711. // let leftCellItemArrSort = this.cl
  712. }
  713. //如果最后一行 并且 是被全部清除的x
  714. if (ifLastCleanX && ifAllCleanedX) {
  715. // LogUtil.log("【checkMoveLeftCellItem】检测消除 全部消除的一列就是消除xIndex中最后一列");
  716. this.checkMoveLeftCellItem();
  717. return;
  718. }
  719. //y方向从下至上循环排查
  720. for (var i = GameConst.row_num - 1; i >= 0; i--) {
  721. if (cellItemDic) {
  722. let cellItem = cellItemDic[i];
  723. //该xIndex纵列没有全部移除
  724. if (cellItem) {
  725. if (ifLastCleanX && i == leftLastCellItemY) {
  726. // LogUtil.log("【checkMoveLeftCellItem】检测消除 移除了最后一个");
  727. cellItem.moveDown(xIndex, i + intervalNum, movedIndex, true);
  728. }
  729. else {
  730. cellItem.moveDown(xIndex, i + intervalNum, movedIndex);
  731. }
  732. movedIndex++;
  733. }
  734. else {
  735. intervalNum += 1;
  736. }
  737. }
  738. else {
  739. continue;
  740. }
  741. }
  742. }
  743. /**检测向左移动的cellItem */
  744. checkMoveLeftCellItem() {
  745. //计算消除的纵列中,有没有被全部移除
  746. //let allCleanedXArr = GameUtil.getAllCleanXIndex(this.cleanXIndexArr);
  747. // LogUtil.log("[Game] checkMoveLeftCellItem allCleanXArr ---------------------", this.allCleanedXArr);
  748. //如果没有全部移除得就return
  749. if (this.allCleanedXArr.length <= 0) {
  750. //LogUtil.log("【checkMoveLeftCellItem】检测是否能消除 没有全部移除的");
  751. GamePlay.Inst.ifCouldClick = true;
  752. GamePlay.Inst.checkIfEliminate();
  753. return;
  754. }
  755. //剩余一列未移除的xIndex
  756. let leftXIndexArr: number[] = GameLogic.getLeftXIndexArr();
  757. let leftMaxXIndex: number = leftXIndexArr[leftXIndexArr.length - 1];
  758. if (leftXIndexArr.length <= 0) {
  759. //检测是否移除
  760. this.checkIfEliminate();
  761. }
  762. else {
  763. mk.console.log("leftXIndexArr", leftXIndexArr);
  764. let intervalNum: number = 0;
  765. for (var i = 0; i < GameConst.col_num; i++) {
  766. let cellItemArr = GamePlay.Inst.cellItemDic[i];
  767. if (this.allCleanedXArr.indexOf(i) == -1) {
  768. //剩余存在的cellItem
  769. let leftCellItemArr = cellItemArr.filter((cellItem) => cellItem != null);
  770. if (intervalNum > 0) {
  771. for (var j = 0; j < cellItemArr.length; j++) {
  772. let cellItem = cellItemArr[j];
  773. if (cellItem) {
  774. if (i == leftMaxXIndex && j == (leftCellItemArr[0].y)) {
  775. mk.console.log("i,j,intervalNum", i, j, intervalNum);
  776. cellItem.moveLeft(i - intervalNum, j, true);
  777. }
  778. else {
  779. cellItem.moveLeft(i - intervalNum, j);
  780. }
  781. }
  782. }
  783. }
  784. else {
  785. //对应 1 2 3 列 中 3全部消除
  786. if (i == leftMaxXIndex) {
  787. GamePlay.Inst.ifCouldClick = true;
  788. GamePlay.Inst.checkIfEliminate();
  789. }
  790. }
  791. }
  792. else {
  793. intervalNum += 1;
  794. }
  795. }
  796. }
  797. }
  798. public timeout_pass: number = null;
  799. /**检测是否能移除 */
  800. checkIfEliminate() {
  801. mk.console.log("开始检测是否还能够消除!!!!!!!!!!!!!!!!!!!!!");
  802. //FC:替换
  803. GameLogic.getCouldCleanVec();
  804. if (this.couldCleanVecArr.length <= 0 && !this.ifPass) {
  805. EffectMgr.Inst.addSpriteTip(TIP_SPRITEITEM_TYPE.NormalPass);
  806. let timeOut = setTimeout(() => {
  807. this.pass();
  808. clearTimeout(timeOut);
  809. }, 1500);
  810. }
  811. //FC:正式使用
  812. // let timeOut = setTimeout(() => {
  813. // GameUtil.getCouldCleanVec();
  814. // if (this.couldCleanVecArr.length <= 0 && !this.ifPass) {
  815. // this.pass();
  816. // }
  817. // clearTimeout(timeOut);
  818. // }, 1500);
  819. }
  820. getCouldCleanCellItem() {
  821. for (var i = 0; this.cellItemArr.length; i++) {
  822. let cellItem = this.cellItemArr[i];
  823. let aroundSameType = GameLogic.getAroundSameType(cellItem.x, cellItem.y, cellItem.type, false);
  824. if (aroundSameType.length > 0) {
  825. return;
  826. }
  827. }
  828. //this.nextLevel();
  829. this.pass();
  830. //this.recycleAllCellItem();
  831. }
  832. /**restart
  833. * @param 是否扣除体力
  834. */
  835. restart() {
  836. mk.console.log("restart!!!!!!!!!!!!!!!")
  837. this.refreshGame();
  838. }
  839. /**下一关 */
  840. nextLevel() {
  841. mk.console.log("nextLevel!!!!!!!!!!!!!!!")
  842. this.targetScore = 0;//下一关才重置目标分数
  843. this.refreshGame();
  844. }
  845. /**刷新关卡 */
  846. refreshGame() {
  847. mk.data.sendDataEvent(DataEventId.level, "关卡开启");
  848. this.recycleAllCellItem();
  849. this.ifPass = false;
  850. this.ifGetPass = false;
  851. this.ifCouldClick = true;
  852. this.initLevel();
  853. this.initTotalScore();
  854. //FC:改成累分制而不是每关重置
  855. // this.curProgressScore = 0;
  856. // this.curGetScore = 0;
  857. // this.finalGetScore = 0;
  858. this.initScore();
  859. }
  860. /**回收所有的 */
  861. recycleAllCellItem() {
  862. for (var i = 0; i < GameConst.col_num; i++) {
  863. for (var j = 0; j < GameConst.row_num; j++) {
  864. let cellItem = this.cellItemDic[i][j];
  865. if (cellItem) {
  866. // mk.console.log("回收把>>>>>>>>>>>>>>>>>>>>>>");
  867. cellItem.recycle(true, false, false);
  868. }
  869. }
  870. }
  871. // while (this.cellItemList.length > 0) {
  872. // this.cellItemList.splice(0, 1);
  873. // this.cellItemList[0].recycle();
  874. // }
  875. this.cellItemArr = [];
  876. this.cellItemDic = {};
  877. this.curXIndex = 0;
  878. this.curYIndex = GameConst.row_num - 1;
  879. this.initCell();
  880. }
  881. /**通关 */
  882. pass() {
  883. //这边会多次进入
  884. if (GamePlay.Inst.node.active == false || this.ifPass) {
  885. return;
  886. }
  887. mk.data.sendDataEvent(DataEventId.level, "关卡通关");
  888. this.ifPass = true;
  889. GamePlay.Inst.ifGetPass = false;
  890. let levelNum = gData.gameData.getProp(GameProp.levelNum);
  891. if (levelNum == 0) {
  892. mk.data.sendXYEvent("firstlevel", "完成第一关");
  893. }
  894. mk.console.log("[Game]pass passLevelNum", levelNum);
  895. GamePlay.Inst.ifGetPass = true;
  896. gData.gameData.setProp(GameProp.levelNum, ++levelNum);
  897. if (gData.gameData.funOpenData['6'] == '1') {
  898. let node_rewardLuck = mk.ui.getCurOnPanel("rewardLuck");
  899. if (node_rewardLuck || this.finalGetScore >= this.targetScore) {
  900. return;
  901. }
  902. else {
  903. //游戏结算
  904. this.gameCount();
  905. console.log("gData.gameData.getProp(GameProp.levelNum)", gData.gameData.getProp(GameProp.levelNum));
  906. }
  907. }
  908. else {
  909. //游戏结算
  910. this.gameCount();
  911. console.log("gData.gameData.getProp(GameProp.levelNum)", gData.gameData.getProp(GameProp.levelNum));
  912. }
  913. }
  914. /**游戏结算 */
  915. gameCount() {
  916. let node_getPropUI = mk.ui.getCurOnPanel("GetPropUI");
  917. if (node_getPropUI) {
  918. mk.ui.closePanel("GetPropUI");
  919. }
  920. this.gameOver();
  921. }
  922. /**游戏结束 */
  923. gameOver() {
  924. mk.data.setTAEventUser(1, 'video_play_time', 1);
  925. mk.ui.openPanel("game/prefab/uiPanel/GameOverUI");
  926. }
  927. checkBonusNum(cleanCellItemNum: number) {
  928. if (cleanCellItemNum >= 4) {
  929. let node_bonusTip = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.BonusTip);
  930. let bonusTip = node_bonusTip.getComponent(BonusTip);
  931. //LogUtil.log("bonusTip",bonusTip);
  932. if (cleanCellItemNum == 4) {
  933. bonusTip.init(4);
  934. mk.audio.playEffect("ef_bonus4");
  935. }
  936. else if (cleanCellItemNum == 5) {
  937. bonusTip.init(5);
  938. mk.audio.playEffect("ef_bonus5");
  939. }
  940. else if (cleanCellItemNum == 6) {
  941. bonusTip.init(6);
  942. mk.audio.playEffect("ef_bonus6");
  943. }
  944. else if (cleanCellItemNum == 7) {
  945. bonusTip.init(7);
  946. mk.audio.playEffect("ef_bonus7");
  947. }
  948. else if (cleanCellItemNum == 8) {
  949. bonusTip.init(8);
  950. mk.audio.playEffect("ef_bonus8");
  951. }
  952. else {
  953. bonusTip.init(8);
  954. mk.audio.playEffect("ef_bonus8");
  955. }
  956. this.node_effectUI.addChild(node_bonusTip);
  957. }
  958. }
  959. checkAddLevelRedPacket(eliminateNum: number): boolean {
  960. let chance = (eliminateNum - 3) * 0.2;
  961. let random = Math.random();
  962. if (random < chance) {
  963. return true;
  964. }
  965. else {
  966. return false;
  967. }
  968. }
  969. public interval_ShowGuide: number = null;
  970. //间隔显示
  971. intervalShowGuide() {
  972. this.cancelShowCouldCleanCellItem();
  973. this.interval_ShowGuide = setInterval(() => {
  974. this.showCouldCleanCellItem();
  975. }, 10000);
  976. }
  977. /**显示 */
  978. showCouldCleanCellItem() {
  979. if (mk.ui.getCurOnPanel("RedPacketUI") || mk.ui.getCurOnPanel("GameOverUI") || !this.couldCleanVecArr || !this.cellItemDic) {
  980. return;
  981. }
  982. if (this.couldCleanVecArr.length <= 0) {
  983. GameLogic.getCouldCleanVec();
  984. }
  985. if (this.couldCleanVecArr.length > 0) {
  986. for (var i = 0; i < this.couldCleanVecArr.length; i++) {
  987. let vec = this.couldCleanVecArr[i];
  988. if (this.cellItemDic[vec.x]) {
  989. let cellItem = this.cellItemDic[vec.x][vec.y];
  990. if (cellItem) {
  991. cellItem.shake();
  992. }
  993. }
  994. else {
  995. }
  996. }
  997. }
  998. }
  999. /**取消显示 */
  1000. cancelShowCouldCleanCellItem() {
  1001. if (this.interval_ShowGuide) {
  1002. clearInterval(this.interval_ShowGuide);
  1003. this.interval_ShowGuide = null;
  1004. if (this.couldCleanVecArr.length > 0) {
  1005. for (var i = 0; i < this.couldCleanVecArr.length; i++) {
  1006. let vec = this.couldCleanVecArr[i];
  1007. let cellItem = this.cellItemDic[vec.x][vec.y];
  1008. if (cellItem) {
  1009. cellItem.normal();
  1010. }
  1011. }
  1012. }
  1013. this.couldCleanVecArr = [];
  1014. }
  1015. }
  1016. public interval_ShowInter: number = null;
  1017. //间隔显示
  1018. intervalShowInter() {
  1019. let time = gData.gameData.configs.ServerConfig.interOpenGapTime;
  1020. if (!time) {
  1021. time = 15000;
  1022. }
  1023. else {
  1024. time *= 1000;
  1025. }
  1026. this.cancelShowInter();
  1027. this.interval_ShowGuide = setInterval(() => {
  1028. mk.ad.showInterAd(0);
  1029. }, time);
  1030. }
  1031. cancelShowInter() {
  1032. if (this.interval_ShowGuide) {
  1033. clearInterval(this.interval_ShowGuide);
  1034. }
  1035. }
  1036. /**
  1037. * 气泡红包是否开启
  1038. */
  1039. private qipaoShow() {
  1040. for (let i = 0; i < 4; i++) {
  1041. this['btn_gameGetRed' + (i + 1)].active = gData.gameData.funBtns.btn8.active;
  1042. }
  1043. }
  1044. public doBubbleRedPacketLogic(dt) {
  1045. if (!this.isShowRedPacket) {
  1046. return;
  1047. }
  1048. if (this.isAllShow) {
  1049. return;
  1050. }
  1051. this.curTime += dt;
  1052. if (this.curTime >= gData.gameData.redPacketTime * 60) {
  1053. this.curTime = 0;
  1054. if (!this.btn_gameGetRed1.active) {
  1055. this.btn_gameGetRed1.active = true;
  1056. //cc.tween(this.btn_getRed1).to(1.2, { y: 100 }).to(1.2, { y: 50 }).union().repeatForever().start();
  1057. return;
  1058. } else if (!this.btn_gameGetRed2.active) {
  1059. this.btn_gameGetRed2.active = true;
  1060. //cc.tween(this.btn_getRed2).delay(0.2).to(1.5, { y: 125 }).to(1.5, { y: 50 }).union().repeatForever().start();
  1061. return;
  1062. } else if (!this.btn_gameGetRed3.active) {
  1063. this.btn_gameGetRed3.active = true;
  1064. //cc.tween(this.btn_getRed3).delay(0.4).to(1, { y: 10 }).to(1, { y: -50 }).union().repeatForever().start();
  1065. return;
  1066. } else if (!this.btn_gameGetRed4.active) {
  1067. this.btn_gameGetRed4.active = true;
  1068. }
  1069. this.isAllShow = true;
  1070. }
  1071. }
  1072. private refreshRedPacketUI(index) {
  1073. gData.gameData.openIndex = -1;
  1074. if (index == 4) {
  1075. this.btn_gameGetRed1.active = false;
  1076. if (this.isAllShow) {
  1077. this.isAllShow = false;
  1078. }
  1079. } else if (index == 5) {
  1080. this.btn_gameGetRed2.active = false;
  1081. if (this.isAllShow) {
  1082. this.isAllShow = false;
  1083. }
  1084. } else if (index == 6) {
  1085. this.btn_gameGetRed3.active = false;
  1086. if (this.isAllShow) {
  1087. this.isAllShow = false;
  1088. }
  1089. } else if (index == 7) {
  1090. this.btn_gameGetRed4.active = false;
  1091. if (this.isAllShow) {
  1092. this.isAllShow = false;
  1093. }
  1094. }
  1095. }
  1096. }