GamePlay.ts 42 KB

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