GamePlay.ts 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232
  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. let level = gData.gameData.getProp(GameProp.levelNum);
  300. //如果未开启关卡红包
  301. if (level <= 0 || !this.ifOpenLevelRedBag) {
  302. //进度到达开始显示
  303. gData.reward.subType = 2;
  304. mk.ad.videoAdType = VideoAdType.LevelScoreRedBag;
  305. let node_rewardLuck = mk.ui.getCurOnPanel("rewardLuck");
  306. if (!node_rewardLuck && gData.gameData.funOpenData['6'] == '1') {
  307. mk.ui.openPanel("module/reward/rewardLuck");
  308. }
  309. }
  310. }
  311. // if (progress >= 1) {
  312. // this.pass();
  313. // mk.ui.openPanel("module/reward/rewardMission");
  314. // }
  315. // LogUtil.log("progressprogressprogressprogressprogressprogress", progress);
  316. }
  317. /**初始化道具 */
  318. initPropNum() {
  319. this.initHammerPropNum();
  320. this.initResetPropNum();
  321. this.initChanegPropNum();
  322. }
  323. /**初始化锤子道具数目 */
  324. initHammerPropNum() {
  325. let hammerPropNum = gData.gameData.getProp(GameProp.hammerPropNum);
  326. if (hammerPropNum) {
  327. this.label_hammerPropNum.string = hammerPropNum.toString();
  328. }
  329. else {
  330. this.label_hammerPropNum.string = "+";
  331. }
  332. }
  333. /**初始化重置道具数目 */
  334. initResetPropNum() {
  335. let resetPropNum = gData.gameData.getProp(GameProp.resetPropNum);
  336. if (resetPropNum) {
  337. this.label_resetPropNum.string = resetPropNum.toString();
  338. }
  339. else {
  340. this.label_resetPropNum.string = "+";
  341. }
  342. }
  343. /**初始化替换道具数目 */
  344. initChanegPropNum() {
  345. let changePropNum = gData.gameData.getProp(GameProp.changePropNum);
  346. if (changePropNum) {
  347. this.label_changePropNum.string = changePropNum.toString();
  348. }
  349. else {
  350. this.label_changePropNum.string = "+";
  351. }
  352. }
  353. // update (dt) {}
  354. /**初始化cellBg */
  355. initCellBg() {
  356. for (var i = 0; i < GameConst.col_num; i++) {
  357. for (var j = 0; j < GameConst.row_num; j++) {
  358. let prefab_cellBg = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.CellBg);
  359. // LogUtil.log("prefab_cellBg", prefab_cellBg);
  360. let node_cellBg = cc.instantiate(prefab_cellBg);
  361. this.node_cellBg.addChild(node_cellBg);
  362. }
  363. }
  364. }
  365. /**初始化cell */
  366. public initCell() {
  367. this.addCellItemFuc = () => { this.addCellItem(); };
  368. this.schedule(this.addCellItemFuc, 0.05);
  369. }
  370. public addCellItemFuc: Function = null;
  371. public curXIndex: number = 0;
  372. public curYIndex: number = 7;
  373. /**添加CellItem */
  374. public addCellItem() {
  375. mk.console.log("addCellItem!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  376. this.addColCellItem();
  377. this.curXIndex++;
  378. if (this.curXIndex >= GameConst.col_num) {
  379. this.unschedule(this.addCellItemFuc);
  380. // this.getStartRedPacketCellItem();
  381. }
  382. }
  383. /**添加纵列的cellItem */
  384. public addColCellItem() {
  385. this.cellItemDic[this.curXIndex] = [];
  386. for (var i = GameConst.row_num - 1; i >= 0; i--) {
  387. let prefab_cellItem = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.CellItem);
  388. let node_prefab = cc.instantiate(prefab_cellItem);
  389. let cellItem = node_prefab.getComponent(CellItem);
  390. cellItem.init(this.curXIndex, i);
  391. this.cellItemDic[this.curXIndex][i] = cellItem;
  392. this.cellItemArr.push(cellItem);
  393. this.node_content.addChild(node_prefab);
  394. }
  395. }
  396. /**点击按钮 */
  397. onClickBtn(event: cc.Event.EventTouch) {
  398. this.intervalShowGuide();
  399. this.intervalShowInter();
  400. //是否已经通关
  401. if (this.ifPass) {
  402. EffectMgr.Inst.addTip("通关结算啦,请稍后操作哈")
  403. return;
  404. }
  405. // AudioMgr.Inst.playEffect(AUDIO_CLIP_NAME.buttonClick);
  406. mk.audio.playEffect("button");
  407. switch (event.currentTarget) {
  408. case this.node_pauseBtn:
  409. this.onClickPauseBtn();
  410. break;
  411. case this.node_hammerBtn:
  412. this.onClickHammerBtn();
  413. break;
  414. case this.node_changeBtn:
  415. this.onClickChangeBtn();
  416. break;
  417. case this.node_resetBtn:
  418. this.onClickResetBtn();
  419. break;
  420. }
  421. }
  422. /**点击暂停按钮 */
  423. onClickPauseBtn() {
  424. mk.ui.openPanel("game/prefab/uiPanel/PauseUI")
  425. }
  426. /**点击分享 */
  427. public onClickShare() {
  428. if (!gData.loginData.isAuth) {
  429. // mk.tip.pop("请先点击头像,在设置界面授权");
  430. JsbSystem.WxAuth();
  431. return;
  432. }
  433. JsbSystem.sharePic();
  434. }
  435. /**点击重置按钮 */
  436. onClickResetBtn() {
  437. //设置当前选择的道具按钮
  438. this.setCurSelectPropBtn(this.node_resetBtn);
  439. this.curPropType = PROPTYPE.Reset;
  440. let resetPropNum = gData.gameData.getProp(GameProp.resetPropNum);
  441. if (!resetPropNum || resetPropNum <= 0) {
  442. mk.ui.openPanel("game/prefab/uiPanel/GetPropUI");
  443. return;
  444. }
  445. // AudioMgr.Inst.playEffect(AUDIO_CLIP_NAME.refresh);
  446. mk.audio.playEffect("ef_refresh");
  447. let keys = Object.keys(this.cellItemDic);
  448. for (var i = 0; i < keys.length; i++) {
  449. let key = Number(keys[i]);
  450. let colCellItemArr = this.cellItemDic[key];
  451. for (var j = 0; j < colCellItemArr.length; j++) {
  452. let cellItem = colCellItemArr[j];
  453. if (cellItem) {
  454. cellItem.reset();
  455. }
  456. }
  457. }
  458. //暂时不扣
  459. DataMgr.Inst.updatePropNum(2, GamePlay.Inst.curPropType, -1);
  460. this.curPropType = PROPTYPE.Null;
  461. //this.recycleAllCellItem();
  462. }
  463. //点击锤子按钮
  464. onClickHammerBtn() {
  465. //设置当前选择的道具按钮
  466. this.setCurSelectPropBtn(this.node_hammerBtn);
  467. this.curPropType = PROPTYPE.Hammer;
  468. let hammerPropNum = gData.gameData.getProp(GameProp.hammerPropNum);
  469. if (!hammerPropNum || hammerPropNum <= 0) {
  470. mk.ui.openPanel("game/prefab/uiPanel/GetPropUI");
  471. return;
  472. }
  473. DataMgr.Inst.updatePropNum(2, GamePlay.Inst.curPropType, -1);
  474. }
  475. //点击更换按钮
  476. onClickChangeBtn() {
  477. //设置当前选择的道具按钮
  478. this.setCurSelectPropBtn(this.node_changeBtn);
  479. this.curPropType = PROPTYPE.Change;
  480. let changePropNum = gData.gameData.getProp(GameProp.changePropNum);
  481. if (!changePropNum || changePropNum <= 0) {
  482. mk.ui.openPanel("game/prefab/uiPanel/GetPropUI");
  483. return;
  484. }
  485. DataMgr.Inst.updatePropNum(2, GamePlay.Inst.curPropType, -1);
  486. }
  487. /** 点击关卡气泡红包 */
  488. onClickLevelQiPaoPacket() {
  489. mk.ad.videoAdType = VideoAdType.LevelQiPaoRedBag;
  490. }
  491. /**更改cellItem类型
  492. * @param cellItemType
  493. */
  494. changeCellItemType(cellItemType: number) {
  495. let pos_x = this.curSelectCellItem.node.x + GamePlay.Inst.node_content.x;
  496. let pos_y = this.curSelectCellItem.node.y + GamePlay.Inst.node_content.y;
  497. let node_change = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.Change);
  498. node_change.setPosition(pos_x, pos_y);
  499. GamePlay.Inst.node_effectUI.addChild(node_change);
  500. this.curSelectCellItem.setType(cellItemType)
  501. // AudioMgr.Inst.playEffect(AUDIO_CLIP_NAME.change);
  502. mk.audio.playEffect("ef_change");
  503. this.curSelectCellItem = null;
  504. }
  505. /**设置当前 */
  506. setCurSelectPropBtn(propBtn: cc.Node) {
  507. if (this.curSelectPropBtn) {
  508. let node_ani = this.curSelectPropBtn.children[1];
  509. if (node_ani) {
  510. let ani = node_ani.getComponent(cc.Animation);
  511. if (ani) {
  512. ani.play("ani_normalBtn");
  513. }
  514. }
  515. this.setPropBtnNormalTip(this.curSelectPropBtn);
  516. }
  517. this.curSelectPropBtn = propBtn;
  518. }
  519. /**设置道具普通提示 */
  520. setPropBtnNormalTip(propBtn: cc.Node) {
  521. if (!propBtn) {
  522. return;
  523. }
  524. let node_tip = propBtn.children[2];
  525. if (node_tip) {
  526. let label = null;
  527. switch (propBtn) {
  528. case this.node_hammerBtn:
  529. label = this.label_hammerPropNum;
  530. break;
  531. case this.node_resetBtn:
  532. label = this.label_resetPropNum;
  533. break;
  534. case this.node_changeBtn:
  535. label = this.label_changePropNum;
  536. break;
  537. }
  538. let str = label.string;
  539. let num = Number(str);
  540. let label_tip = node_tip.getComponent(cc.Label);
  541. mk.console.log("propBtn.name", propBtn.name);
  542. mk.console.log("num", num);
  543. if (num && num >= 1) {
  544. label_tip.string = "";
  545. }
  546. else {
  547. label_tip.string = "点我领取";
  548. }
  549. }
  550. }
  551. /**设置道具使用提示 */
  552. setPropBtnSelectTip(propBtn: cc.Node) {
  553. if (!propBtn) {
  554. return;
  555. }
  556. let node_tip = propBtn.children[2];
  557. if (node_tip) {
  558. let label = node_tip.getComponent(cc.Label)
  559. label.string = "道具使用中";
  560. }
  561. }
  562. /**显示CellItemUI */
  563. showChangeCellItemUI() {
  564. let cruSelectCellItem = this.curSelectCellItem;
  565. GamePlay.Inst.node_changeCellItemUI.active = true;
  566. // let min_x = -this.node_content.width * 0.5 + this.node_changeCellItemUI.width * 0.5;
  567. // let max_x = this.node_content.width * 0.5 + this.node_changeCellItemUI.width * 0.5;
  568. GamePlay.Inst.node_changeCellItemUI.y = cruSelectCellItem.node.y + cruSelectCellItem.node.height * 0.5 + GamePlay.Inst.node_changeCellItemUI.height * 0.5 + 20;
  569. }
  570. //onClick
  571. onClickRedPacketIcon() {
  572. if (this.spr_progress.fillRange == 1) {
  573. EffectMgr.Inst.addTip("已达成目标啦,过关发放哦");
  574. }
  575. else {
  576. EffectMgr.Inst.addTip("达到目标分数,才能领取哦");
  577. }
  578. }
  579. //找到红包的那个水果
  580. /**
  581. * 获取红包cellItem
  582. */
  583. public getStartRedPacketCellItem() {
  584. let totalCellItemArr: CellItem[] = this.cellItemArr.concat();
  585. let largeCellItemVec: cc.Vec2[] = [];
  586. for (var i = 0; i < totalCellItemArr.length; i++) {
  587. let cellItem = totalCellItemArr[i];
  588. if (!!cellItem) {
  589. GameLogic.getCouldCleanVecList(cellItem.x, cellItem.y, cellItem.type, true);
  590. // console.log("this.couldCleanVecArr", this.couldCleanVecArr);
  591. console.log("largeCellItemVec.length", largeCellItemVec.length)
  592. if (largeCellItemVec.length < this.couldCleanVecArr.length) {
  593. largeCellItemVec = this.couldCleanVecArr;
  594. }
  595. this.couldCleanVecArr.forEach(element => {
  596. let index = GameConst.col_num * element.x + (GameConst.row_num - 1 - element.y);
  597. totalCellItemArr[index] = null;
  598. this.cellItemDic[element.x][element.y].ifRemoved = false;
  599. });
  600. this.couldCleanVecArr = [];
  601. }
  602. }
  603. console.log("FC------------------------------------------------------------");
  604. let random_index = mk.math.random(0, largeCellItemVec.length - 1);
  605. let vec = largeCellItemVec[random_index];
  606. let redPcaketCellItem: CellItem = this.cellItemDic[vec.x][vec.y];
  607. redPcaketCellItem.showRedPacket();
  608. return redPcaketCellItem;
  609. }
  610. //自定义事件---------------------------------------------------------------------
  611. /**微信授权返回 */
  612. onWxAuthBack() {
  613. if (this.node.active) {
  614. this.restart();
  615. //
  616. let node_redPacketUI = mk.ui.getCurOnPanel("RedPacketUI")
  617. if (node_redPacketUI) {
  618. mk.ui.closePanel("RedPacketUI");
  619. }
  620. }
  621. this.initLevel();
  622. this.initTotalScore();
  623. this.initPropNum();
  624. mk.event.remove(EVENT_TYPE.BACK_WxAuth, this.onWxAuthBack, this);
  625. }
  626. //其他显示或逻辑项-------------------------------------------------------------------
  627. /**根据vecList清除cellItem */
  628. public cleanCellItemByVecList() {
  629. //LogUtil.log("[Game] Game.Inst.cleanCellItemVecArr", Game.Inst.cleanCellItemVecArr);
  630. //没有可清清除
  631. if (GamePlay.Inst.cleanedVecArr.length <= 0) {
  632. //FC:+ 是否可以点击
  633. this.ifCouldClick = true;
  634. EffectMgr.Inst.addTip("点击两个或以上消除哦");
  635. return;
  636. }
  637. //区分消除音效
  638. if (GamePlay.Inst.cleanedVecArr.length >= 4) {
  639. // AudioMgr.Inst.playEffect(AUDIO_CLIP_NAME.eliminate_bonus);
  640. mk.audio.playEffect("ef_eliminate_bonus");
  641. }
  642. else {
  643. //AudioMgr.Inst.playEffect(AUDIO_CLIP_NAME.eliminate);
  644. mk.audio.playEffect("ef_eliminate");
  645. }
  646. // AudioMgr.Inst.playEffect(AUDIO_CLIP_NAME.fly);
  647. mk.audio.playEffect("ef_fly");
  648. //同时消除
  649. for (var i = 0; i < GamePlay.Inst.cleanedVecArr.length; i++) {
  650. let vec = GamePlay.Inst.cleanedVecArr[i];
  651. //最后一个判定
  652. if (i == GamePlay.Inst.cleanedVecArr.length - 1) {
  653. this.checkBonusNum(GamePlay.Inst.cleanedVecArr.length);
  654. GamePlay.Inst.cellItemDic[vec.x][vec.y].recycle(false, true);
  655. }
  656. else {
  657. GamePlay.Inst.cellItemDic[vec.x][vec.y].recycle();
  658. }
  659. //回收 注释 改成如上
  660. //Game.Inst.cellItemDic[vec.x][vec.y].recycle();
  661. //Game.Inst.cellItemDic[vec.x][vec.y] = null;
  662. if (this.cleanXIndexArr.indexOf(vec.x) == -1) {
  663. this.cleanXIndexArr.push(vec.x);
  664. }
  665. }
  666. this.cleanXIndexArr.sort();
  667. //计算下全部移除的
  668. this.allCleanedXArr = GameLogic.getAllCleanXIndex(this.cleanXIndexArr);
  669. //FC:移除完,检测下落
  670. this.scheduleOnce(() => {
  671. //检测下落
  672. this.checkMoveDownCellItem();
  673. }, 0.2)
  674. }
  675. /**检测向下移动的cellItem */
  676. checkMoveDownCellItem() {
  677. mk.console.log("this.cleanXIndexArr", this.cleanXIndexArr);
  678. for (var i = 0; i < this.cleanXIndexArr.length; i++) {
  679. let xIndex = this.cleanXIndexArr[i];
  680. this.moveYCellItem(xIndex);
  681. }
  682. }
  683. /**移动
  684. * @param xIndex 移除的纵列
  685. * @param removedYIndex 移除的横向index
  686. */
  687. public moveYCellItem(xIndex: number) {
  688. // LogUtil.log("moveYCellItem x", xIndex, this.allCleanedXArr);
  689. /**移动的次序(第几个移动的用来控制延迟移动的时间) */
  690. let movedIndex: number = 0;
  691. //移动位置间隔(比如前面两个空位就移动两格)
  692. let intervalNum: number = 0;
  693. /**是否是全部清理的x */
  694. let ifAllCleanedX: boolean = this.allCleanedXArr.indexOf(xIndex) != -1;
  695. /**是否是最后清理的x(全部清理完才开始左移) */
  696. let ifLastCleanX: boolean = (xIndex == this.cleanXIndexArr[this.cleanXIndexArr.length - 1]);
  697. let cellItemDic = GamePlay.Inst.cellItemDic[xIndex];
  698. //计算y方向移动的最后一位(这样只计算一次不用循环)
  699. let lastMoveCellItemY: number = null;
  700. let leftLastCellItemY: number = null;
  701. if (ifLastCleanX) {
  702. let lastCellItemArrSort = this.cleanedVecArr.filter((vec) => vec.x == xIndex).sort();
  703. lastMoveCellItemY = lastCellItemArrSort[0].y;
  704. // LogUtil.log("lastCellItemY", xIndex, lastMoveCellItemY, lastCellItemArrSort);
  705. for (var i = 0; i < GameConst.row_num; i++) {
  706. if (cellItemDic) {
  707. let cellItem = cellItemDic[i];
  708. if (cellItem) {
  709. leftLastCellItemY = cellItem.y;
  710. // LogUtil.log("leftLastCellItemY", leftLastCellItemY);
  711. break;
  712. }
  713. }
  714. }
  715. // let leftCellItemArrSort = this.cl
  716. }
  717. //如果最后一行 并且 是被全部清除的x
  718. if (ifLastCleanX && ifAllCleanedX) {
  719. // LogUtil.log("【checkMoveLeftCellItem】检测消除 全部消除的一列就是消除xIndex中最后一列");
  720. this.checkMoveLeftCellItem();
  721. return;
  722. }
  723. //y方向从下至上循环排查
  724. for (var i = GameConst.row_num - 1; i >= 0; i--) {
  725. if (cellItemDic) {
  726. let cellItem = cellItemDic[i];
  727. //该xIndex纵列没有全部移除
  728. if (cellItem) {
  729. if (ifLastCleanX && i == leftLastCellItemY) {
  730. // LogUtil.log("【checkMoveLeftCellItem】检测消除 移除了最后一个");
  731. cellItem.moveDown(xIndex, i + intervalNum, movedIndex, true);
  732. }
  733. else {
  734. cellItem.moveDown(xIndex, i + intervalNum, movedIndex);
  735. }
  736. movedIndex++;
  737. }
  738. else {
  739. intervalNum += 1;
  740. }
  741. }
  742. else {
  743. continue;
  744. }
  745. }
  746. }
  747. /**检测向左移动的cellItem */
  748. checkMoveLeftCellItem() {
  749. //计算消除的纵列中,有没有被全部移除
  750. //let allCleanedXArr = GameUtil.getAllCleanXIndex(this.cleanXIndexArr);
  751. // LogUtil.log("[Game] checkMoveLeftCellItem allCleanXArr ---------------------", this.allCleanedXArr);
  752. //如果没有全部移除得就return
  753. if (this.allCleanedXArr.length <= 0) {
  754. //LogUtil.log("【checkMoveLeftCellItem】检测是否能消除 没有全部移除的");
  755. GamePlay.Inst.ifCouldClick = true;
  756. GamePlay.Inst.checkIfEliminate();
  757. return;
  758. }
  759. //剩余一列未移除的xIndex
  760. let leftXIndexArr: number[] = GameLogic.getLeftXIndexArr();
  761. let leftMaxXIndex: number = leftXIndexArr[leftXIndexArr.length - 1];
  762. if (leftXIndexArr.length <= 0) {
  763. //检测是否移除
  764. this.checkIfEliminate();
  765. }
  766. else {
  767. mk.console.log("leftXIndexArr", leftXIndexArr);
  768. let intervalNum: number = 0;
  769. for (var i = 0; i < GameConst.col_num; i++) {
  770. let cellItemArr = GamePlay.Inst.cellItemDic[i];
  771. if (this.allCleanedXArr.indexOf(i) == -1) {
  772. //剩余存在的cellItem
  773. let leftCellItemArr = cellItemArr.filter((cellItem) => cellItem != null);
  774. if (intervalNum > 0) {
  775. for (var j = 0; j < cellItemArr.length; j++) {
  776. let cellItem = cellItemArr[j];
  777. if (cellItem) {
  778. if (i == leftMaxXIndex && j == (leftCellItemArr[0].y)) {
  779. mk.console.log("i,j,intervalNum", i, j, intervalNum);
  780. cellItem.moveLeft(i - intervalNum, j, true);
  781. }
  782. else {
  783. cellItem.moveLeft(i - intervalNum, j);
  784. }
  785. }
  786. }
  787. }
  788. else {
  789. //对应 1 2 3 列 中 3全部消除
  790. if (i == leftMaxXIndex) {
  791. GamePlay.Inst.ifCouldClick = true;
  792. GamePlay.Inst.checkIfEliminate();
  793. }
  794. }
  795. }
  796. else {
  797. intervalNum += 1;
  798. }
  799. }
  800. }
  801. }
  802. public timeout_pass: number = null;
  803. /**检测是否能移除 */
  804. checkIfEliminate() {
  805. mk.console.log("开始检测是否还能够消除!!!!!!!!!!!!!!!!!!!!!");
  806. //FC:替换
  807. GameLogic.getCouldCleanVec();
  808. if (this.couldCleanVecArr.length <= 0 && !this.ifPass) {
  809. EffectMgr.Inst.addSpriteTip(TIP_SPRITEITEM_TYPE.NormalPass);
  810. let timeOut = setTimeout(() => {
  811. this.pass();
  812. clearTimeout(timeOut);
  813. }, 1500);
  814. }
  815. //FC:正式使用
  816. // let timeOut = setTimeout(() => {
  817. // GameUtil.getCouldCleanVec();
  818. // if (this.couldCleanVecArr.length <= 0 && !this.ifPass) {
  819. // this.pass();
  820. // }
  821. // clearTimeout(timeOut);
  822. // }, 1500);
  823. }
  824. getCouldCleanCellItem() {
  825. for (var i = 0; this.cellItemArr.length; i++) {
  826. let cellItem = this.cellItemArr[i];
  827. let aroundSameType = GameLogic.getAroundSameType(cellItem.x, cellItem.y, cellItem.type, false);
  828. if (aroundSameType.length > 0) {
  829. return;
  830. }
  831. }
  832. //this.nextLevel();
  833. this.pass();
  834. //this.recycleAllCellItem();
  835. }
  836. /**restart
  837. * @param 是否扣除体力
  838. */
  839. restart() {
  840. mk.console.log("restart!!!!!!!!!!!!!!!")
  841. this.refreshGame();
  842. }
  843. /**下一关 */
  844. nextLevel() {
  845. mk.console.log("nextLevel!!!!!!!!!!!!!!!")
  846. this.targetScore = 0;//下一关才重置目标分数
  847. this.refreshGame();
  848. }
  849. /**刷新关卡 */
  850. refreshGame() {
  851. mk.data.sendDataEvent(DataEventId.level, "关卡开启");
  852. this.recycleAllCellItem();
  853. this.ifPass = false;
  854. this.ifGetPass = false;
  855. this.ifCouldClick = true;
  856. this.initLevel();
  857. this.initTotalScore();
  858. //FC:改成累分制而不是每关重置
  859. // this.curProgressScore = 0;
  860. // this.curGetScore = 0;
  861. // this.finalGetScore = 0;
  862. this.initScore();
  863. }
  864. /**回收所有的 */
  865. recycleAllCellItem() {
  866. for (var i = 0; i < GameConst.col_num; i++) {
  867. for (var j = 0; j < GameConst.row_num; j++) {
  868. let cellItem = this.cellItemDic[i][j];
  869. if (cellItem) {
  870. // mk.console.log("回收把>>>>>>>>>>>>>>>>>>>>>>");
  871. cellItem.recycle(true, false, false);
  872. }
  873. }
  874. }
  875. // while (this.cellItemList.length > 0) {
  876. // this.cellItemList.splice(0, 1);
  877. // this.cellItemList[0].recycle();
  878. // }
  879. this.cellItemArr = [];
  880. this.cellItemDic = {};
  881. this.curXIndex = 0;
  882. this.curYIndex = GameConst.row_num - 1;
  883. this.initCell();
  884. }
  885. /**通关 */
  886. pass() {
  887. //这边会多次进入
  888. if (GamePlay.Inst.node.active == false || this.ifPass) {
  889. return;
  890. }
  891. mk.data.sendDataEvent(DataEventId.level, "关卡通关");
  892. this.ifPass = true;
  893. GamePlay.Inst.ifGetPass = false;
  894. let levelNum = gData.gameData.getProp(GameProp.levelNum);
  895. if (levelNum == 0) {
  896. mk.data.sendXYEvent("firstlevel", "完成第一关");
  897. }
  898. mk.console.log("[Game]pass passLevelNum", levelNum);
  899. GamePlay.Inst.ifGetPass = true;
  900. gData.gameData.setProp(GameProp.levelNum, ++levelNum);
  901. if (!this.ifOpenLevelRedBag) {
  902. if (gData.gameData.funOpenData['6'] == '1') {
  903. let node_rewardLuck = mk.ui.getCurOnPanel("rewardLuck");
  904. if (node_rewardLuck || this.finalGetScore >= this.targetScore) {
  905. return;
  906. }
  907. else {
  908. //游戏结算
  909. this.gameCount();
  910. console.log("gData.gameData.getProp(GameProp.levelNum)", gData.gameData.getProp(GameProp.levelNum));
  911. }
  912. }
  913. else {
  914. //游戏结算
  915. this.gameCount();
  916. console.log("gData.gameData.getProp(GameProp.levelNum)", gData.gameData.getProp(GameProp.levelNum));
  917. }
  918. }
  919. else {
  920. //游戏结算
  921. this.gameCount();
  922. }
  923. }
  924. /**游戏结算 */
  925. gameCount() {
  926. let node_getPropUI = mk.ui.getCurOnPanel("GetPropUI");
  927. if (node_getPropUI) {
  928. mk.ui.closePanel("GetPropUI");
  929. }
  930. this.gameOver();
  931. }
  932. /**游戏结束 */
  933. gameOver() {
  934. mk.data.setTAEventUser(1, 'video_play_time', 1);
  935. if (!this.ifOpenLevelRedBag) {
  936. mk.ui.openPanel("game/prefab/uiPanel/GameOverUI");
  937. }
  938. else {
  939. gData.reward.subType = 2;
  940. mk.ad.videoAdType = VideoAdType.LevelScoreRedBag;
  941. mk.ui.openPanel("module/reward/rewardMission");
  942. }
  943. }
  944. checkBonusNum(cleanCellItemNum: number) {
  945. if (cleanCellItemNum >= 4) {
  946. let node_bonusTip = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.BonusTip);
  947. let bonusTip = node_bonusTip.getComponent(BonusTip);
  948. //LogUtil.log("bonusTip",bonusTip);
  949. if (cleanCellItemNum == 4) {
  950. bonusTip.init(4);
  951. mk.audio.playEffect("ef_bonus4");
  952. }
  953. else if (cleanCellItemNum == 5) {
  954. bonusTip.init(5);
  955. mk.audio.playEffect("ef_bonus5");
  956. }
  957. else if (cleanCellItemNum == 6) {
  958. bonusTip.init(6);
  959. mk.audio.playEffect("ef_bonus6");
  960. }
  961. else if (cleanCellItemNum == 7) {
  962. bonusTip.init(7);
  963. mk.audio.playEffect("ef_bonus7");
  964. }
  965. else if (cleanCellItemNum == 8) {
  966. bonusTip.init(8);
  967. mk.audio.playEffect("ef_bonus8");
  968. }
  969. else {
  970. bonusTip.init(8);
  971. mk.audio.playEffect("ef_bonus8");
  972. }
  973. this.node_effectUI.addChild(node_bonusTip);
  974. }
  975. }
  976. checkAddLevelRedPacket(eliminateNum: number): boolean {
  977. let chance = (eliminateNum - 3) * 0.2;
  978. let random = Math.random();
  979. if (random < chance) {
  980. return true;
  981. }
  982. else {
  983. return false;
  984. }
  985. }
  986. public interval_ShowGuide: number = null;
  987. //间隔显示
  988. intervalShowGuide() {
  989. this.cancelShowCouldCleanCellItem();
  990. this.interval_ShowGuide = setInterval(() => {
  991. this.showCouldCleanCellItem();
  992. }, 10000);
  993. }
  994. /**显示 */
  995. showCouldCleanCellItem() {
  996. if (mk.ui.getCurOnPanel("RedPacketUI") || mk.ui.getCurOnPanel("GameOverUI") || !this.couldCleanVecArr || !this.cellItemDic) {
  997. return;
  998. }
  999. if (this.couldCleanVecArr.length <= 0) {
  1000. GameLogic.getCouldCleanVec();
  1001. }
  1002. if (this.couldCleanVecArr.length > 0) {
  1003. for (var i = 0; i < this.couldCleanVecArr.length; i++) {
  1004. let vec = this.couldCleanVecArr[i];
  1005. if (this.cellItemDic[vec.x]) {
  1006. let cellItem = this.cellItemDic[vec.x][vec.y];
  1007. if (cellItem) {
  1008. cellItem.shake();
  1009. }
  1010. }
  1011. else {
  1012. }
  1013. }
  1014. }
  1015. }
  1016. /**取消显示 */
  1017. cancelShowCouldCleanCellItem() {
  1018. if (this.interval_ShowGuide) {
  1019. clearInterval(this.interval_ShowGuide);
  1020. this.interval_ShowGuide = null;
  1021. if (this.couldCleanVecArr.length > 0) {
  1022. for (var i = 0; i < this.couldCleanVecArr.length; i++) {
  1023. let vec = this.couldCleanVecArr[i];
  1024. let cellItem = this.cellItemDic[vec.x][vec.y];
  1025. if (cellItem) {
  1026. cellItem.normal();
  1027. }
  1028. }
  1029. }
  1030. this.couldCleanVecArr = [];
  1031. }
  1032. }
  1033. public interval_ShowInter: number = null;
  1034. //间隔显示
  1035. intervalShowInter() {
  1036. let time = gData.gameData.configs.ServerConfig.interOpenGapTime;
  1037. if (!time) {
  1038. time = 15000;
  1039. }
  1040. else {
  1041. time *= 1000;
  1042. }
  1043. this.cancelShowInter();
  1044. this.interval_ShowGuide = setInterval(() => {
  1045. mk.ad.showInterAd(0);
  1046. }, time);
  1047. }
  1048. cancelShowInter() {
  1049. if (this.interval_ShowGuide) {
  1050. clearInterval(this.interval_ShowGuide);
  1051. }
  1052. }
  1053. /**
  1054. * 气泡红包是否开启
  1055. */
  1056. private qipaoShow() {
  1057. for (let i = 0; i < 4; i++) {
  1058. this['btn_gameGetRed' + (i + 1)].active = gData.gameData.funBtns.btn8.active;
  1059. }
  1060. }
  1061. }