GamePlay.ts 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909
  1. import CellItem from "./view/uiItem/CellItem";
  2. import PoolMgr, { NODEPOOLPREFABTYPE } from "./mgr/PoolMgr";
  3. import GameConst from "./data/GameConst";
  4. import GameLogic from "./util/GameLogic";
  5. import BonusTip from "./view/effect/BonusTip";
  6. import EffectMgr, { TIP_SPRITEITEM_TYPE } from "./mgr/EffectMgr";
  7. import { DataEventId, EVENT_TYPE, GameProp, VideoAdType } from "../game/data/GameData";
  8. import JsbSystem from "../mk/system/JsbSystem";
  9. import Util from "./util/Util";
  10. import { RedPoinNode } from "../game/game/Game";
  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. @property({ type: cc.Sprite, displayName: "头像" })
  20. img_head: cc.Sprite = null;
  21. @property({ type: cc.Label, displayName: "红包币" })
  22. lbl_redMoney: cc.Label = null;
  23. @property({ type: cc.Sprite, displayName: "红包提现" })
  24. btn_cashOutNormal: cc.Sprite = null;
  25. @property(cc.Label)
  26. label_level: cc.Label = null;
  27. /**内容 */
  28. @property(cc.Node)
  29. node_content: cc.Node = null;
  30. /**cell背景块 */
  31. @property(cc.Node)
  32. node_cellBg: cc.Node = null;
  33. /**进度条UI */
  34. @property(cc.Node)
  35. node_progressUI: cc.Node = null;
  36. @property(cc.Sprite)
  37. spr_progress: cc.Sprite = null;
  38. /**特效UI */
  39. @property(cc.Node)
  40. node_effectUI: cc.Node = null;
  41. /**关卡红包UI */
  42. @property(cc.Node)
  43. node_levelRedPacketUI: cc.Node = null;
  44. @property({ type: cc.Node, displayName: "签到红点" })
  45. node_signRed: cc.Node = null;
  46. /** 是否开启关卡红包 */
  47. public ifOpenLevelRedBag: boolean = false;
  48. /**当前进度得分 */
  49. public curProgressScore: number = 0;
  50. /**当前得分 */
  51. public curGetScore: number = 0;
  52. /**目标分数 */
  53. public targetScore: number = 0;
  54. /**最终得分 */
  55. public finalGetScore: number = 0;
  56. /**增加得分速度 */
  57. public addScoreSpeed: number = 4;
  58. /**消消的方块数组
  59. * @param:key index_x
  60. * @param: value 整个纵列数组
  61. */
  62. public cellItemDic: { [key: number]: CellItem[] } = {};
  63. public cellItemArr: CellItem[] = [];
  64. /**清理CellItem的Vec数组 */
  65. public cleanedVecArr: cc.Vec2[] = [];
  66. /**能够清理的vecArr组 */
  67. public couldCleanVecArr: cc.Vec2[] = [];
  68. /**清理纵列的x */
  69. public cleanXIndexArr: number[] = [];
  70. /**所有的清理 */
  71. public allCleanedXArr: number[] = [];
  72. /**剩余未移除的xIndex */
  73. public leftXIndexArr: number[] = [];
  74. /**当前选择的cellItem */
  75. public curSelectCellItem: CellItem = null;
  76. /**当前点击得cellItem */
  77. public curClickCellItem: CellItem = null;
  78. /**当前选择的道具按钮 */
  79. public curSelectPropBtn: cc.Node = null;
  80. /**是否可以点击 */
  81. public ifCouldClick: boolean = true;
  82. /**是否已经通关 */
  83. public ifPass: boolean = false;
  84. /**是否获取后台回调 */
  85. public ifGetPass: boolean = false;
  86. /**是否打开积分红包 */
  87. public ifOpenScoreRedPacket: boolean = false;
  88. @property({ type: RedPoinNode, displayName: "红点组" })
  89. nodeRedPoint: RedPoinNode = null;
  90. onLoad() {
  91. GamePlay.Inst = this;
  92. mk.event.register("event_guide", this.clickGuide, this);
  93. this.checkLevelRedBagSwitch();
  94. }
  95. private async initHead() {
  96. let result = await mk.loader.loadRemote(gData.wechatData.avatar + "?aaa=aa.jpg", null);
  97. this.img_head.spriteFrame = new cc.SpriteFrame(result);
  98. }
  99. private initInfo() {
  100. this.lbl_redMoney.string = (gData.gameData.gameData.redMoney * 0.0001).toFixed(2) + '元';
  101. gData.gameData.init_coin = false;
  102. }
  103. private changeInfo() {
  104. this.lbl_redMoney.node.getComponent(mk.component.numberAnim).setValue(gData.gameData.gameData.redMoney * 0.0001, 2) + '元';
  105. gData.gameData.init_coin = false;
  106. }
  107. private clickGuide(data: string) {
  108. if (data == "1_3") {//点击即可消除哦!
  109. this.cellItemDic[0][0] && this.cellItemDic[0][0].onClick();
  110. }
  111. else if (data == "1_5") {//再点击一次增加大量进度哦
  112. this.cellItemDic[1][1] && this.cellItemDic[1][1].onClick();
  113. }
  114. }
  115. public start() {
  116. mk.data.sendDataEvent(DataEventId.level, "关卡开启");
  117. PoolMgr.Inst.initPoolPrefab();
  118. GameConst.loadConfig().then(() => {
  119. mk.audio.playMusic("music_gameBg");
  120. //读取在线分数数据
  121. gData.gameData.setProp(GameProp.curTotalScore, 0);//杀掉进程,则清零积分
  122. let score = gData.gameData.getProp(GameProp.curTotalScore);
  123. this.curGetScore = score;
  124. this.curProgressScore = score;
  125. this.finalGetScore = score;
  126. console.log("score", score);
  127. this.initView();
  128. this.initEvent();
  129. this.intervalShowGuide();
  130. }).catch();
  131. this.initInfo();
  132. let level = gData.gameData.getProp(GameProp.levelNum);
  133. mk.data.setTAEventUser(0, 'level', level + 1);
  134. this.schedule(this.firstShowBanner, 2)
  135. }
  136. firstShowBanner() {
  137. if (mk.ad.hasBannerReady()) {
  138. mk.ad.showBanner();
  139. this.unschedule(this.firstShowBanner)
  140. }
  141. }
  142. onDisable() {
  143. //退出游戏归置下道具状态
  144. if (this.curSelectCellItem) {
  145. this.curSelectCellItem.normal();
  146. }
  147. }
  148. /** [FC][V2.0.1]检测关卡红包开关 */
  149. checkLevelRedBagSwitch() {
  150. let levelRedBagSwitch = gData.gameData.configs.GlobalCfg.levelRedBagSwitch;
  151. if (levelRedBagSwitch) {
  152. this.ifOpenLevelRedBag = levelRedBagSwitch == 0 ? false : true;
  153. }
  154. else {
  155. this.ifOpenLevelRedBag = false;
  156. }
  157. }
  158. update(dt) {
  159. if (gData.gameData.init_coin) {
  160. this.changeInfo();
  161. }
  162. if (gData.gameData.init_head) {
  163. this.initHead();
  164. }
  165. if (gData.gameData.init_red_point) {
  166. this.initRedPoint();
  167. }
  168. if (this.curProgressScore >= this.curGetScore) {
  169. if (this.curProgressScore == 0) {
  170. this.spr_progress.fillRange = 0;
  171. }
  172. return;
  173. }
  174. else {
  175. if (this.curProgressScore >= this.targetScore) {
  176. this.curProgressScore = this.curGetScore;
  177. this.initScore();
  178. }
  179. else {
  180. let nextProgressScore: number = this.curProgressScore + this.addScoreSpeed;
  181. if (/**this.curProgressScore < GamePlay.Inst.targetScore && */nextProgressScore >= GamePlay.Inst.targetScore) {
  182. let node_getTargetScoreTip = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.GetTargetScoreTip);
  183. GamePlay.Inst.node_effectUI.addChild(node_getTargetScoreTip);
  184. //进度到达开始显示(挪到initScore判断)
  185. // gData.reward.subType = 2;
  186. // mk.ad.videoAdType = VideoAdType.LevelScoreRedBag;
  187. // mk.ui.openPanel("module/reward/rewardLuck");
  188. }
  189. this.curProgressScore = nextProgressScore;
  190. if (this.curProgressScore >= this.curGetScore) {
  191. this.curProgressScore = this.curGetScore;
  192. }
  193. this.initScore();
  194. }
  195. }
  196. }
  197. lateUpdate() {
  198. gData.gameData.init_head = false;
  199. }
  200. /**初始化视图 */
  201. initView() {
  202. this.initLevel();
  203. this.initTotalScore();
  204. this.initScore();
  205. this.initProgress();
  206. this.initCellBg();
  207. this.initCell();
  208. }
  209. /**初始化事件 */
  210. initEvent() {
  211. mk.event.register(EVENT_TYPE.BACK_WxAuth, this.onWxAuthBack, this);
  212. }
  213. /**初始化关卡数目 */
  214. initLevel() {
  215. mk.console.log("[Game] levelNum", gData.gameData.getProp(GameProp.levelNum));
  216. let level = gData.gameData.getProp(GameProp.levelNum);
  217. this.label_level.string = `第${level + 1}关`
  218. }
  219. /**初始化总分数 */
  220. initTotalScore() {
  221. if (this.targetScore) {
  222. return;
  223. }
  224. let level = gData.gameData.getProp(GameProp.levelNum);
  225. //加入一些随机值,而不是都能获得过关红包
  226. this.targetScore = 450 + level * (5 + Math.floor(Math.random() * 15));
  227. // //测试切换
  228. // this.targetScore = 5000;
  229. this.addScoreSpeed = Math.floor(this.targetScore / 200) * 2 + 4;
  230. mk.console.log("this.addScoreSpeed", this.addScoreSpeed);
  231. }
  232. /**初始化得分 */
  233. initScore() {
  234. this.initProgress();
  235. }
  236. /**初始化进度 */
  237. initProgress() {
  238. let progress = this.curProgressScore / this.targetScore;
  239. progress = progress > 1 ? 1 : progress;
  240. this.spr_progress.fillRange = progress;
  241. // if (progress >= 1) {
  242. // let level = gData.gameData.getProp(GameProp.levelNum);
  243. // //如果未开启关卡红包
  244. // if (level <= 0 || !this.ifOpenLevelRedBag) {
  245. // //进度到达开始显示
  246. // gData.reward.subType = 2;
  247. // mk.ad.videoAdType = VideoAdType.LevelScoreRedBag;
  248. // let node_rewardLuck = mk.ui.getCurOnPanel("rewardLuck");
  249. // if (!node_rewardLuck && gData.gameData.funOpenData['6'] == '1') {
  250. // mk.ui.openPanel("module/reward/rewardLuck");
  251. // }
  252. // }
  253. // }
  254. }
  255. /**初始化cellBg */
  256. initCellBg() {
  257. for (var i = 0; i < GameConst.col_num; i++) {
  258. for (var j = 0; j < GameConst.row_num; j++) {
  259. let prefab_cellBg = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.CellBg);
  260. // LogUtil.log("prefab_cellBg", prefab_cellBg);
  261. let node_cellBg = cc.instantiate(prefab_cellBg);
  262. this.node_cellBg.addChild(node_cellBg);
  263. }
  264. }
  265. }
  266. /**初始化cell */
  267. public initCell() {
  268. //关卡配置从100关开始随机关卡50-99
  269. let level = gData.gameData.getProp(GameProp.levelNum);
  270. let levelIndex = 0;
  271. if (level <= GameConst.configCount - 1) {
  272. levelIndex = level;
  273. }
  274. else {
  275. levelIndex = Util.rnd(50, GameConst.configCount - 1);
  276. }
  277. GameConst.curLevelCfg = GameConst.config_level[levelIndex];
  278. this.addCellItemFuc = () => { this.addCellItem(); };
  279. this.schedule(this.addCellItemFuc, 0.05);
  280. }
  281. public addCellItemFuc: Function = null;
  282. public curXIndex: number = 0;
  283. public curYIndex: number = 7;
  284. /**添加CellItem */
  285. public addCellItem() {
  286. mk.console.log("addCellItem!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  287. this.addColCellItem();
  288. this.curXIndex++;
  289. if (this.curXIndex >= GameConst.col_num) {
  290. this.unschedule(this.addCellItemFuc);
  291. // this.getStartRedPacketCellItem();
  292. }
  293. }
  294. /**添加纵列的cellItem */
  295. public addColCellItem() {
  296. this.cellItemDic[this.curXIndex] = [];
  297. for (var i = GameConst.row_num - 1; i >= 0; i--) {
  298. let prefab_cellItem = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.CellItem);
  299. let node_prefab = cc.instantiate(prefab_cellItem);
  300. let cellItem = node_prefab.getComponent(CellItem);
  301. cellItem.init(this.curXIndex, i);
  302. this.cellItemDic[this.curXIndex][i] = cellItem;
  303. this.cellItemArr.push(cellItem);
  304. this.node_content.addChild(node_prefab);
  305. }
  306. }
  307. /**点击分享 */
  308. public onClickShare() {
  309. if (!gData.loginData.isAuth) {
  310. // mk.tip.pop("请先点击头像,在设置界面授权");
  311. JsbSystem.WxAuth();
  312. return;
  313. }
  314. JsbSystem.sharePic();
  315. }
  316. // /** 点击关卡气泡红包 */
  317. // onClickLevelQiPaoPacket() {
  318. // mk.ad.videoAdType = VideoAdType.LevelQiPaoRedBag;
  319. // }
  320. // /**更改cellItem类型
  321. // * @param cellItemType
  322. // */
  323. // changeCellItemType(cellItemType: number) {
  324. // let pos_x = this.curSelectCellItem.node.x + GamePlay.Inst.node_content.x;
  325. // let pos_y = this.curSelectCellItem.node.y + GamePlay.Inst.node_content.y;
  326. // let node_change = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.Change);
  327. // node_change.setPosition(pos_x, pos_y);
  328. // GamePlay.Inst.node_effectUI.addChild(node_change);
  329. // this.curSelectCellItem.setType(cellItemType)
  330. // mk.audio.playEffect("ef_change");
  331. // this.curSelectCellItem = null;
  332. // }
  333. //找到红包的那个水果
  334. /**
  335. * 获取红包cellItem
  336. */
  337. public getStartRedPacketCellItem() {
  338. let totalCellItemArr: CellItem[] = this.cellItemArr.concat();
  339. let largeCellItemVec: cc.Vec2[] = [];
  340. for (var i = 0; i < totalCellItemArr.length; i++) {
  341. let cellItem = totalCellItemArr[i];
  342. if (!!cellItem) {
  343. GameLogic.getCouldCleanVecList(cellItem.x, cellItem.y, cellItem.type, true);
  344. // console.log("this.couldCleanVecArr", this.couldCleanVecArr);
  345. console.log("largeCellItemVec.length", largeCellItemVec.length)
  346. if (largeCellItemVec.length < this.couldCleanVecArr.length) {
  347. largeCellItemVec = this.couldCleanVecArr;
  348. }
  349. this.couldCleanVecArr.forEach(element => {
  350. let index = GameConst.col_num * element.x + (GameConst.row_num - 1 - element.y);
  351. totalCellItemArr[index] = null;
  352. this.cellItemDic[element.x][element.y].ifRemoved = false;
  353. });
  354. this.couldCleanVecArr = [];
  355. }
  356. }
  357. console.log("FC------------------------------------------------------------");
  358. let random_index = mk.math.random(0, largeCellItemVec.length - 1);
  359. let vec = largeCellItemVec[random_index];
  360. let redPcaketCellItem: CellItem = this.cellItemDic[vec.x][vec.y];
  361. redPcaketCellItem.showRedPacket();
  362. return redPcaketCellItem;
  363. }
  364. //自定义事件---------------------------------------------------------------------
  365. /**微信授权返回 */
  366. onWxAuthBack() {
  367. if (this.node.active) {
  368. this.restart();
  369. //
  370. let node_redPacketUI = mk.ui.getCurOnPanel("RedPacketUI")
  371. if (node_redPacketUI) {
  372. mk.ui.closePanel("RedPacketUI");
  373. }
  374. }
  375. this.initLevel();
  376. this.initTotalScore();
  377. // this.initPropNum();
  378. mk.event.remove(EVENT_TYPE.BACK_WxAuth, this.onWxAuthBack, this);
  379. }
  380. //其他显示或逻辑项-------------------------------------------------------------------
  381. /**根据vecList清除cellItem */
  382. public cleanCellItemByVecList() {
  383. //没有可清清除
  384. if (GamePlay.Inst.cleanedVecArr.length <= 0) {
  385. //FC:+ 是否可以点击
  386. this.ifCouldClick = true;
  387. EffectMgr.Inst.addTip("点击两个或以上消除哦");
  388. return;
  389. }
  390. //区分消除音效
  391. if (GamePlay.Inst.cleanedVecArr.length >= 4) {
  392. mk.audio.playEffect("ef_eliminate_bonus");
  393. }
  394. else {
  395. mk.audio.playEffect("ef_eliminate");
  396. }
  397. mk.audio.playEffect("ef_fly");
  398. //同时消除
  399. for (var i = 0; i < GamePlay.Inst.cleanedVecArr.length; i++) {
  400. let vec = GamePlay.Inst.cleanedVecArr[i];
  401. //最后一个判定
  402. if (i == GamePlay.Inst.cleanedVecArr.length - 1) {
  403. this.checkBonusNum(GamePlay.Inst.cleanedVecArr.length);
  404. GamePlay.Inst.cellItemDic[vec.x][vec.y].recycle(false, true);
  405. }
  406. else {
  407. GamePlay.Inst.cellItemDic[vec.x][vec.y].recycle();
  408. }
  409. if (this.cleanXIndexArr.indexOf(vec.x) == -1) {
  410. this.cleanXIndexArr.push(vec.x);
  411. }
  412. }
  413. this.cleanXIndexArr.sort();
  414. //计算下全部移除的
  415. this.allCleanedXArr = GameLogic.getAllCleanXIndex(this.cleanXIndexArr);
  416. //FC:移除完,检测下落
  417. this.scheduleOnce(() => {
  418. //检测下落
  419. this.checkMoveDownCellItem();
  420. }, 0.2)
  421. }
  422. /**检测向下移动的cellItem */
  423. checkMoveDownCellItem() {
  424. mk.console.log("this.cleanXIndexArr", this.cleanXIndexArr);
  425. for (var i = 0; i < this.cleanXIndexArr.length; i++) {
  426. let xIndex = this.cleanXIndexArr[i];
  427. this.moveYCellItem(xIndex);
  428. }
  429. }
  430. /**移动
  431. * @param xIndex 移除的纵列
  432. * @param removedYIndex 移除的横向index
  433. */
  434. public moveYCellItem(xIndex: number) {
  435. /**移动的次序(第几个移动的用来控制延迟移动的时间) */
  436. let movedIndex: number = 0;
  437. //移动位置间隔(比如前面两个空位就移动两格)
  438. let intervalNum: number = 0;
  439. /**是否是全部清理的x */
  440. let ifAllCleanedX: boolean = this.allCleanedXArr.indexOf(xIndex) != -1;
  441. /**是否是最后清理的x(全部清理完才开始左移) */
  442. let ifLastCleanX: boolean = (xIndex == this.cleanXIndexArr[this.cleanXIndexArr.length - 1]);
  443. let cellItemDic = GamePlay.Inst.cellItemDic[xIndex];
  444. //计算y方向移动的最后一位(这样只计算一次不用循环)
  445. let lastMoveCellItemY: number = null;
  446. let leftLastCellItemY: number = null;
  447. if (ifLastCleanX) {
  448. let lastCellItemArrSort = this.cleanedVecArr.filter((vec) => vec.x == xIndex).sort();
  449. lastMoveCellItemY = lastCellItemArrSort[0].y;
  450. // LogUtil.log("lastCellItemY", xIndex, lastMoveCellItemY, lastCellItemArrSort);
  451. for (var i = 0; i < GameConst.row_num; i++) {
  452. if (cellItemDic) {
  453. let cellItem = cellItemDic[i];
  454. if (cellItem) {
  455. leftLastCellItemY = cellItem.y;
  456. // LogUtil.log("leftLastCellItemY", leftLastCellItemY);
  457. break;
  458. }
  459. }
  460. }
  461. // let leftCellItemArrSort = this.cl
  462. }
  463. //如果最后一行 并且 是被全部清除的x
  464. if (ifLastCleanX && ifAllCleanedX) {
  465. // LogUtil.log("【checkMoveLeftCellItem】检测消除 全部消除的一列就是消除xIndex中最后一列");
  466. this.checkMoveLeftCellItem();
  467. return;
  468. }
  469. //y方向从下至上循环排查
  470. for (var i = GameConst.row_num - 1; i >= 0; i--) {
  471. if (cellItemDic) {
  472. let cellItem = cellItemDic[i];
  473. //该xIndex纵列没有全部移除
  474. if (cellItem) {
  475. if (ifLastCleanX && i == leftLastCellItemY) {
  476. // LogUtil.log("【checkMoveLeftCellItem】检测消除 移除了最后一个");
  477. cellItem.moveDown(xIndex, i + intervalNum, movedIndex, true);
  478. }
  479. else {
  480. cellItem.moveDown(xIndex, i + intervalNum, movedIndex);
  481. }
  482. movedIndex++;
  483. }
  484. else {
  485. intervalNum += 1;
  486. }
  487. }
  488. else {
  489. continue;
  490. }
  491. }
  492. }
  493. /**检测向左移动的cellItem */
  494. checkMoveLeftCellItem() {
  495. //计算消除的纵列中,有没有被全部移除
  496. //let allCleanedXArr = GameUtil.getAllCleanXIndex(this.cleanXIndexArr);
  497. // LogUtil.log("[Game] checkMoveLeftCellItem allCleanXArr ---------------------", this.allCleanedXArr);
  498. //如果没有全部移除得就return
  499. if (this.allCleanedXArr.length <= 0) {
  500. //LogUtil.log("【checkMoveLeftCellItem】检测是否能消除 没有全部移除的");
  501. GamePlay.Inst.ifCouldClick = true;
  502. GamePlay.Inst.checkIfEliminate();
  503. return;
  504. }
  505. //剩余一列未移除的xIndex
  506. let leftXIndexArr: number[] = GameLogic.getLeftXIndexArr();
  507. let leftMaxXIndex: number = leftXIndexArr[leftXIndexArr.length - 1];
  508. if (leftXIndexArr.length <= 0) {
  509. //检测是否移除
  510. this.checkIfEliminate();
  511. }
  512. else {
  513. mk.console.log("leftXIndexArr", leftXIndexArr);
  514. let intervalNum: number = 0;
  515. for (var i = 0; i < GameConst.col_num; i++) {
  516. let cellItemArr = GamePlay.Inst.cellItemDic[i];
  517. if (this.allCleanedXArr.indexOf(i) == -1) {
  518. //剩余存在的cellItem
  519. let leftCellItemArr = cellItemArr.filter((cellItem) => cellItem != null);
  520. if (intervalNum > 0) {
  521. for (var j = 0; j < cellItemArr.length; j++) {
  522. let cellItem = cellItemArr[j];
  523. if (cellItem) {
  524. if (i == leftMaxXIndex && j == (leftCellItemArr[0].y)) {
  525. mk.console.log("i,j,intervalNum", i, j, intervalNum);
  526. cellItem.moveLeft(i - intervalNum, j, true);
  527. }
  528. else {
  529. cellItem.moveLeft(i - intervalNum, j);
  530. }
  531. }
  532. }
  533. }
  534. else {
  535. //对应 1 2 3 列 中 3全部消除
  536. if (i == leftMaxXIndex) {
  537. GamePlay.Inst.ifCouldClick = true;
  538. GamePlay.Inst.checkIfEliminate();
  539. }
  540. }
  541. }
  542. else {
  543. intervalNum += 1;
  544. }
  545. }
  546. }
  547. }
  548. public timeout_pass: number = null;
  549. /**检测是否能移除 */
  550. checkIfEliminate() {
  551. mk.console.log("开始检测是否还能够消除!!!!!!!!!!!!!!!!!!!!!");
  552. //FC:替换
  553. GameLogic.getCouldCleanVec();
  554. if (this.couldCleanVecArr.length <= 0 && !this.ifPass) {
  555. EffectMgr.Inst.addSpriteTip(TIP_SPRITEITEM_TYPE.NormalPass);
  556. let timeOut = setTimeout(() => {
  557. this.pass();
  558. clearTimeout(timeOut);
  559. }, 1500);
  560. }
  561. }
  562. getCouldCleanCellItem() {
  563. for (var i = 0; this.cellItemArr.length; i++) {
  564. let cellItem = this.cellItemArr[i];
  565. let aroundSameType = GameLogic.getAroundSameType(cellItem.x, cellItem.y, cellItem.type, false);
  566. if (aroundSameType.length > 0) {
  567. return;
  568. }
  569. }
  570. //this.nextLevel();
  571. this.pass();
  572. //this.recycleAllCellItem();
  573. }
  574. /**restart
  575. * @param 是否扣除体力
  576. */
  577. restart() {
  578. mk.console.log("restart!!!!!!!!!!!!!!!")
  579. this.refreshGame();
  580. }
  581. /**下一关 */
  582. nextLevel() {
  583. mk.console.log("nextLevel!!!!!!!!!!!!!!!")
  584. this.targetScore = 0;//下一关才重置目标分数
  585. this.refreshGame();
  586. let level = gData.gameData.getProp(GameProp.levelNum);
  587. if (level % 5 == 0) {
  588. mk.ad.showInterAd(1);
  589. }
  590. }
  591. /**刷新关卡 */
  592. refreshGame() {
  593. mk.data.sendDataEvent(DataEventId.level, "关卡开启");
  594. this.recycleAllCellItem();
  595. this.ifPass = false;
  596. this.ifGetPass = false;
  597. this.ifCouldClick = true;
  598. this.initLevel();
  599. this.initTotalScore();
  600. //FC:改成累分制而不是每关重置
  601. // this.curProgressScore = 0;
  602. // this.curGetScore = 0;
  603. // this.finalGetScore = 0;
  604. this.initScore();
  605. this.freshBanner();
  606. let level = gData.gameData.getProp(GameProp.levelNum);
  607. mk.data.setTAEventUser(0, 'level', level + 1);
  608. }
  609. /**回收所有的 */
  610. recycleAllCellItem() {
  611. for (var i = 0; i < GameConst.col_num; i++) {
  612. for (var j = 0; j < GameConst.row_num; j++) {
  613. let cellItem = this.cellItemDic[i][j];
  614. if (cellItem) {
  615. // mk.console.log("回收把>>>>>>>>>>>>>>>>>>>>>>");
  616. cellItem.recycle(true, false, false);
  617. }
  618. }
  619. }
  620. this.cellItemArr = [];
  621. this.cellItemDic = {};
  622. this.curXIndex = 0;
  623. this.curYIndex = GameConst.row_num - 1;
  624. this.initCell();
  625. }
  626. /**通关 */
  627. pass() {
  628. //这边会多次进入
  629. if (GamePlay.Inst.node.active == false || this.ifPass) {
  630. return;
  631. }
  632. mk.data.sendDataEvent(DataEventId.level, "关卡通关");
  633. this.ifPass = true;
  634. GamePlay.Inst.ifGetPass = false;
  635. let levelNum = gData.gameData.getProp(GameProp.levelNum);
  636. if (levelNum == 0) {
  637. mk.data.sendXYEvent("firstlevel", "完成第一关");
  638. }
  639. mk.console.log("[Game]pass passLevelNum", levelNum);
  640. GamePlay.Inst.ifGetPass = true;
  641. gData.gameData.setProp(GameProp.levelNum, ++levelNum);
  642. //游戏结算
  643. this.gameCount();
  644. // if (!this.ifOpenLevelRedBag) {
  645. // if (gData.gameData.funOpenData['6'] == '1') {
  646. // let node_rewardLuck = mk.ui.getCurOnPanel("rewardLuck");
  647. // if (node_rewardLuck || this.finalGetScore >= this.targetScore) {
  648. // return;
  649. // }
  650. // else {
  651. // //游戏结算
  652. // this.gameCount();
  653. // console.log("gData.gameData.getProp(GameProp.levelNum)", gData.gameData.getProp(GameProp.levelNum));
  654. // }
  655. // }
  656. // else {
  657. // //游戏结算
  658. // this.gameCount();
  659. // console.log("gData.gameData.getProp(GameProp.levelNum)", gData.gameData.getProp(GameProp.levelNum));
  660. // }
  661. // }
  662. // else {
  663. // //游戏结算
  664. // this.gameCount();
  665. // }
  666. }
  667. /**游戏结算 */
  668. gameCount() {
  669. this.gameOver();
  670. }
  671. /**游戏结束 */
  672. gameOver() {
  673. mk.data.setTAEventUser(1, 'video_play_time', 1);
  674. gData.reward.subType = 2;
  675. mk.ad.videoAdType = VideoAdType.LevelScoreRedBag;
  676. mk.ui.openPanel("module/reward/rewardMission");
  677. }
  678. checkBonusNum(cleanCellItemNum: number) {
  679. if (cleanCellItemNum >= 4) {
  680. let node_bonusTip = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.BonusTip);
  681. let bonusTip = node_bonusTip.getComponent(BonusTip);
  682. //LogUtil.log("bonusTip",bonusTip);
  683. if (cleanCellItemNum == 4) {
  684. bonusTip.init(4);
  685. mk.audio.playEffect("ef_bonus4");
  686. }
  687. else if (cleanCellItemNum == 5) {
  688. bonusTip.init(5);
  689. mk.audio.playEffect("ef_bonus5");
  690. }
  691. else if (cleanCellItemNum == 6) {
  692. bonusTip.init(6);
  693. mk.audio.playEffect("ef_bonus6");
  694. }
  695. else if (cleanCellItemNum == 7) {
  696. bonusTip.init(7);
  697. mk.audio.playEffect("ef_bonus7");
  698. }
  699. else if (cleanCellItemNum == 8) {
  700. bonusTip.init(8);
  701. mk.audio.playEffect("ef_bonus8");
  702. }
  703. else {
  704. bonusTip.init(8);
  705. mk.audio.playEffect("ef_bonus8");
  706. }
  707. this.node_effectUI.addChild(node_bonusTip);
  708. }
  709. }
  710. public interval_ShowGuide: number = null;
  711. //间隔显示
  712. intervalShowGuide() {
  713. this.cancelShowCouldCleanCellItem();
  714. this.interval_ShowGuide = setInterval(() => {
  715. this.showCouldCleanCellItem();
  716. }, 10000);
  717. }
  718. /**显示 */
  719. showCouldCleanCellItem() {
  720. if (mk.ui.getCurOnPanel("RedPacketUI") || mk.ui.getCurOnPanel("GameOverUI") || !this.couldCleanVecArr || !this.cellItemDic) {
  721. return;
  722. }
  723. if (this.couldCleanVecArr.length <= 0) {
  724. GameLogic.getCouldCleanVec();
  725. }
  726. if (this.couldCleanVecArr.length > 0) {
  727. for (var i = 0; i < this.couldCleanVecArr.length; i++) {
  728. let vec = this.couldCleanVecArr[i];
  729. if (this.cellItemDic[vec.x]) {
  730. let cellItem = this.cellItemDic[vec.x][vec.y];
  731. if (cellItem) {
  732. cellItem.shake();
  733. }
  734. }
  735. else {
  736. }
  737. }
  738. }
  739. }
  740. /**取消显示 */
  741. cancelShowCouldCleanCellItem() {
  742. if (this.interval_ShowGuide) {
  743. clearInterval(this.interval_ShowGuide);
  744. this.interval_ShowGuide = null;
  745. if (this.couldCleanVecArr.length > 0) {
  746. for (var i = 0; i < this.couldCleanVecArr.length; i++) {
  747. let vec = this.couldCleanVecArr[i];
  748. let cellItem = this.cellItemDic[vec.x][vec.y];
  749. if (cellItem) {
  750. cellItem.normal();
  751. }
  752. }
  753. }
  754. this.couldCleanVecArr = [];
  755. }
  756. }
  757. //刷新banner
  758. freshBanner() {
  759. mk.ad.destoryBanner();
  760. this.scheduleOnce(() => {
  761. mk.ad.showBanner();
  762. }, 1)
  763. }
  764. /**
  765. * 初始化红点
  766. */
  767. private initRedPoint() {
  768. this.nodeRedPoint.node_sign.active = gData.sign.redPoint();
  769. this.nodeRedPoint.node_redbagCash.active = gData.redBagCash.redPoint();
  770. gData.gameData.init_red_point = false;
  771. }
  772. }