UIGameEnd.ts 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. import DataMgr from "../data/DataMgr";
  2. import { AwardType, GameMode, PlaceBallType, POWER_TIME, Prop, RESET_GAME, RESTART_GAME } from "../data/Define";
  3. import UIBase from "../fgui/core/UIBase";
  4. import ui_UIGameEnd from "../fgui/res/game/ui_UIGameEnd";
  5. import PlatMgr from "../game/PlatMgr";
  6. import Common from "../utils/Common";
  7. import { xGame } from "../xGame";
  8. import MoneyNode from "./item/MoneyNode";
  9. import UIAddCoin from "./UIAddCoin";
  10. import UIAddProp from "./UIAddProp";
  11. import { UIGame } from "./UIGame";
  12. import UIInvitation from "./UIInvitation";
  13. import UIMain from "./UIMain";
  14. import UIPower from "./UIPower";
  15. import UIMsg from "./UIMsg";
  16. import GlobalManager from "../utils/GlobalManager";
  17. import JSBridgeUtils from "../utils/JSBridgeUtils";
  18. export default class UIGameEnd extends UIBase {
  19. public ui: ui_UIGameEnd;
  20. public success: boolean = false;
  21. public moneyNode: MoneyNode;
  22. //
  23. public awardCoinNum = 1000;
  24. public awardDiamondNum = 10;
  25. public constructor() {
  26. super();
  27. }
  28. protected onConstructor(): void {
  29. this.ui = ui_UIGameEnd.createInstance();
  30. this.contentPane = this.ui;
  31. //
  32. this.addUIClick(this.ui.leftBtn, this.clickLeftBtn);
  33. this.addUIClick(this.ui.closeNode.closeBtn, this.returnHome);
  34. this.addUIClick(this.ui.rightBtn, this.clickRightBtn);
  35. this.moneyNode = new MoneyNode(this.ui.moneyNode);
  36. this.ui.talkNode.visible = false;
  37. if (Moyu.isKs)
  38. this.ui.closeNode.closeBtn.x += 100;
  39. }
  40. updateType() {
  41. switch (xGame.common.gameMode) {
  42. case GameMode.classic:
  43. this.ui.c1.selectedIndex = this.success ? 0 : 1;
  44. this.ui.coinNode.visible = this.success;
  45. if (!this.success) {
  46. Laya.timer.once(500, this, () => {
  47. xGame.uiMgr.Show(UIAddCoin);
  48. })
  49. }
  50. this.ui.isGetAward.visible = false;
  51. this.ui.leftBtn.c1.selectedIndex = 3;
  52. this.ui.rightBtn.c1.selectedIndex = 0;
  53. //
  54. this.moneyNode.ui.c1.selectedIndex = 1;
  55. break;
  56. case GameMode.bigMove:
  57. this.ui.c1.selectedIndex = this.success ? 0 : 1;
  58. this.ui.coinNode.visible = this.success;
  59. //设置大招版本的连胜数据
  60. if (xGame.common.gameMode == GameMode.bigMove) {
  61. if (this.success) {
  62. DataMgr.setSkillSuccessTimes(1, true);
  63. DataMgr.setSkillAccTimes(1);
  64. }
  65. else {
  66. DataMgr.setSkillSuccessTimes(0, false);
  67. }
  68. }
  69. //
  70. if (!this.success) {
  71. Laya.timer.once(500, this, () => {
  72. xGame.uiMgr.Show(UIAddCoin);
  73. })
  74. }
  75. this.ui.isGetAward.visible = false;
  76. this.ui.leftBtn.c1.selectedIndex = 3;
  77. this.ui.rightBtn.c1.selectedIndex = 0;
  78. //
  79. this.moneyNode.ui.c1.selectedIndex = 1;
  80. break;
  81. case GameMode.placeBall:
  82. this.ui.coinNode.visible = false;
  83. if (this.success) {
  84. if (xGame.common.placeBallStarNum == 3) {
  85. this.ui.c1.selectedIndex = 2;
  86. }
  87. else {
  88. this.ui.c1.selectedIndex = 3;
  89. }
  90. }
  91. else {
  92. this.ui.c1.selectedIndex = 4;
  93. }
  94. let cfg = cfgTable.placeballData[xGame.common.placeBallCurLevel];
  95. if (cfg.type == PlaceBallType.challenge) {
  96. //挑战关卡
  97. this.ui.c1.selectedIndex = 2;
  98. }
  99. this.ui.conditionNode.conditionTxt.text = cfg.type == 0 ? `Clear the table` : `Pocket ${cfg.ball} balls `;//打进颗球 Clear the table
  100. this.updatePlaceBallBtn();
  101. this.updatePlaceBallStarNum();
  102. this.updatePlaceBallAwardState();
  103. this.moneyNode.ui.c1.selectedIndex = 2;
  104. this.moneyNode.checkPowerTime();
  105. this.moneyNode.powerChange();
  106. //
  107. DataMgr.upRankData();
  108. //
  109. break;
  110. default:
  111. break;
  112. }
  113. }
  114. updatePlaceBallBtn() {
  115. this.ui.leftBtn.c1.selectedIndex = 5;
  116. if (this.success) {
  117. //挑战下一关要花费金币
  118. this.ui.rightBtn.c1.selectedIndex = 14;
  119. }
  120. else {
  121. if (xGame.common.placeBallStarNum == 3) {
  122. //挑战下一关要花费金币
  123. this.ui.rightBtn.c1.selectedIndex = 14;
  124. }
  125. else {
  126. //看视频跳过
  127. this.ui.rightBtn.c1.selectedIndex = 1;
  128. }
  129. }
  130. }
  131. updatePlaceBallStarNum() {
  132. let starNum = xGame.common.placeBallStarNum;
  133. if (starNum == 0) this.ui.starNumNode.c1.selectedIndex = 3;
  134. else {
  135. this.ui.starNumNode.c1.selectedIndex = starNum - 1;
  136. }
  137. }
  138. updatePlaceBallAwardState() {
  139. let level = xGame.common.placeBallCurLevel;
  140. let starNum = xGame.common.placeBallStarNum;
  141. //是否获得奖励
  142. let getAward = DataMgr.getPlaceBallLevel(level).getAward;
  143. let data = cfgTable.placeballData[level].award;
  144. let cfg = cfgTable.placeballData[level];
  145. this.awardDiamondNum = data[1];
  146. this.awardCoinNum = data[0];
  147. if (cfg.type == PlaceBallType.challenge) {
  148. this.awardDiamondNum = 0;
  149. this.awardCoinNum = xGame.common.gameMgr.finishBalls * 100;
  150. }
  151. this.ui.awardNode.diamondNode.visible = this.awardDiamondNum > 0;
  152. this.ui.awardNode.coinNode.visible = this.awardCoinNum > 0;
  153. if (cfg.type == PlaceBallType.challenge) {
  154. this.ui.awardNode.coinNode.visible = true;
  155. }
  156. //
  157. if (this.awardCoinNum > 0 && this.awardDiamondNum > 0) {
  158. this.ui.awardNode.diamondNode.x = 265;
  159. this.ui.awardNode.coinNode.x = 354;
  160. }
  161. else {
  162. this.ui.awardNode.diamondNode.x = 291;
  163. this.ui.awardNode.coinNode.x = 291;
  164. }
  165. this.ui.awardNode.diamondNode.numTxt.text = this.awardDiamondNum + "";
  166. this.ui.awardNode.coinNode.numTxt.text = this.awardCoinNum + "";
  167. if (this.awardCoinNum == 0) {
  168. this.ui.awardNode.coinNode.numTxt.text = "";
  169. }
  170. if (getAward) {
  171. this.ui.isGetAward.visible = true;
  172. this.ui.awardNode.diamondNode.c1.selectedIndex = 2;
  173. this.ui.awardNode.coinNode.c1.selectedIndex = 2;
  174. }
  175. else {
  176. this.ui.isGetAward.visible = false;
  177. if (starNum == 3 && cfg.type == PlaceBallType.challenge) {
  178. this.ui.awardNode.diamondNode.c1.selectedIndex = 0;
  179. this.ui.awardNode.coinNode.c1.selectedIndex = 0;
  180. }
  181. else {
  182. this.ui.awardNode.diamondNode.c1.selectedIndex = 1;
  183. this.ui.awardNode.coinNode.c1.selectedIndex = 1;
  184. }
  185. }
  186. }
  187. public show(success): void {
  188. super.show();
  189. //重置游戏
  190. xGame.eventMgr.event(RESET_GAME);
  191. this.success = success;
  192. Laya.timer.clearAll(this);
  193. this.playSecretaryAni();
  194. Moyu.sendDataEvent("GameEnd", { id: xGame.common.gameMode, res: this.success ? 1 : 2 });
  195. //
  196. let offsetTime = new Date().getTime() - xGame.common.gameStartTime;
  197. offsetTime = Math.floor(offsetTime / 1000);
  198. Moyu.sendDataEvent("gameOver", { isWin: this.success ? 1 : 0, timeConsuming: offsetTime, gameType: xGame.common.gameMode });
  199. //
  200. this.updateType();
  201. //
  202. Laya.timer.once(200, this, () => {
  203. this.addAward(() => {
  204. //
  205. this.updateType();
  206. //
  207. Laya.timer.once(500, this, () => {
  208. this.showChallengeLevel();
  209. })
  210. });
  211. })
  212. //
  213. if (this.success) {
  214. JSBridgeUtils.instance.showInternAd('gameend_success');
  215. //成功
  216. console.log('zh:game end 成功');
  217. xGame.soundMgr.playSound('slots_roll01');
  218. xGame.soundMgr.playSound("s_win");
  219. xGame.common.showGirlTalkPop(8, this.ui.talkNode, this.ui.talkNode.womanTxt);
  220. this.diyGameDataUtilForGameWin();
  221. }
  222. else {
  223. JSBridgeUtils.instance.showInternAd('gameend_faill');
  224. //失败
  225. console.log('zh:game end失败');
  226. xGame.soundMgr.playSound('matchwin01');
  227. xGame.soundMgr.playSound("s_lose");
  228. xGame.common.showGirlTalkPop(9, this.ui.talkNode, this.ui.talkNode.womanTxt);
  229. }
  230. //if (!Moyu.isLegal) PlatMgr.showBanner(true);
  231. //////
  232. let challengeNum = DataMgr.getChallengeTimes();
  233. if (xGame.common.gameMode == GameMode.classic && challengeNum >= 1 && challengeNum <= 3) {
  234. DataMgr.setChallengeTimes(1);
  235. }
  236. //增加经典模式胜利场次
  237. if (this.success && xGame.common.gameMode == GameMode.classic) {
  238. DataMgr.setClassicTimes();
  239. }
  240. }
  241. diyGameDataUtilForGameWin(){
  242. console.log('zh: DiyGameDataUtilForGameWin diy ');
  243. switch (xGame.common.gameMode) {
  244. case GameMode.classic:
  245. console.log('zh:DiyGameDataUtilForGameWin 111');
  246. case GameMode.bigMove:
  247. console.log('zh:DiyGameDataUtilForGameWin 222');
  248. this.restartGame();
  249. break;
  250. case GameMode.placeBall:
  251. console.log('zh:DiyGameDataUtilForGameWin 333');
  252. var level = xGame.common.placeBallCurLevel;
  253. console.log('zh:练习模式 联系了多少LEV=' + level);
  254. let db_over_lev = DataMgr.getChallengeMode_overLev();
  255. if (level > db_over_lev) {
  256. DataMgr.setChallengeMode_overLev(level);
  257. }
  258. break;
  259. default:
  260. console.log('zh:DiyGameDataUtilForGameWin 444');
  261. break;
  262. }
  263. }
  264. //展示经典模式挑战关卡
  265. showChallengeLevel() {
  266. //todo
  267. if (DataMgr.getChallengeTimes() != 0) return;
  268. let skill = DataMgr.getSkillAccTimes();
  269. let put = DataMgr.getPlaceBallLevelList().length;
  270. if (skill >= 3 || put >= 5) {
  271. xGame.uiMgr.Show(UIInvitation);
  272. this.hide();
  273. }
  274. }
  275. //添加奖励
  276. addAward(callback) {
  277. if (!this.success) {
  278. callback && callback();
  279. return;
  280. }
  281. switch (xGame.common.gameMode) {
  282. case GameMode.classic:
  283. this.awardCoinNum = xGame.common.passAwardCoin;
  284. this.awardDiamondNum = 0;
  285. xGame.common.playObjFlyAnim(this.awardCoinNum, Prop.coin);
  286. break;
  287. case GameMode.bigMove:
  288. this.awardCoinNum = xGame.common.passAwardCoin;
  289. this.awardDiamondNum = 0;
  290. xGame.common.playObjFlyAnim(this.awardCoinNum, Prop.coin);
  291. callback && callback();
  292. break;
  293. case GameMode.placeBall:
  294. let level = xGame.common.placeBallCurLevel;
  295. Moyu.sendDataEvent("PlaceBall", { id: level, res: this.success ? 1 : 2 });
  296. if (xGame.common.placeBallStarNum != 3) {
  297. //未获得三星
  298. callback && callback();
  299. return;
  300. }
  301. else {
  302. let getAward = DataMgr.getPlaceBallLevel(level).getAward;
  303. if (getAward) {
  304. //已经获得了该奖励
  305. callback && callback();
  306. return;
  307. }
  308. }
  309. let cfg = cfgTable.placeballData[level];
  310. let data = cfgTable.placeballData[level].award;
  311. this.awardCoinNum = data[0];
  312. this.awardDiamondNum = data[1];
  313. //
  314. if (cfg.type == PlaceBallType.challenge) {
  315. this.awardDiamondNum = 0;
  316. this.awardCoinNum = xGame.common.gameMgr.finishBalls * 100;
  317. }
  318. //
  319. let coinAward = new AwardType(Prop.coin, this.awardCoinNum);
  320. let diamondAward;
  321. if (this.awardDiamondNum > 0) {
  322. //钻石和金币
  323. diamondAward = new AwardType(Prop.diamond, this.awardDiamondNum);
  324. xGame.common.getAward([diamondAward, coinAward], callback);
  325. }
  326. else {
  327. //只有金币
  328. xGame.common.getAward([coinAward], callback);
  329. }
  330. if (cfg.type == PlaceBallType.normal) {
  331. DataMgr.setPlaceBallAward(level);
  332. }
  333. break;
  334. default:
  335. break;
  336. }
  337. }
  338. playSecretaryAni_old() {
  339. let parent = this.ui.secretary.displayObject;
  340. parent.destroyChildren();
  341. let xx = this.ui.secretary.width / 2
  342. let yy = this.ui.secretary.height;
  343. let scale = xGame.common.getSecretaryScale();
  344. let data = { x: xx, y: yy, scaleX: scale, scaleY: scale };
  345. if (this.success) {
  346. let rand = Math.random() <= 0.5 ? 2 : 3;
  347. xGame.common.secretary.play(data, rand, false, parent, () => {
  348. xGame.common.secretary.play(data, 1, true, parent);
  349. });
  350. }
  351. else {
  352. //失败特效
  353. xGame.common.secretary.play(data, 0, true, parent);
  354. }
  355. }
  356. playSecretaryAni() {
  357. let parent = this.ui.secretary.displayObject;
  358. parent.destroyChildren();
  359. let xx = this.ui.secretary.width / 2
  360. let yy = this.ui.secretary.height;
  361. let scale = xGame.common.getSecretaryScale();
  362. let data = { x: xx, y: yy, scaleX: scale, scaleY: scale };
  363. if (this.success) {
  364. //let rand = Math.random() <= 0.5 ? 2 : 3;
  365. let rand = 0;//只有一个动画
  366. xGame.common.secretary.play(data, 0, true, parent);
  367. }
  368. else {
  369. //失败特效
  370. xGame.common.secretary.play(data, 0, true, parent);
  371. }
  372. }
  373. restartGame() {
  374. switch (xGame.common.gameMode) {
  375. case GameMode.classic:
  376. xGame.eventMgr.event(RESTART_GAME);
  377. Moyu.sendDataEvent("GameAgain", { mode: xGame.common.gameMode });
  378. break;
  379. case GameMode.bigMove:
  380. this.hide();
  381. xGame.eventMgr.event(RESTART_GAME);
  382. Moyu.sendDataEvent("GameAgain", { mode: xGame.common.gameMode });
  383. break;
  384. default:
  385. break;
  386. }
  387. }
  388. hide() {
  389. super.hide();
  390. xGame.common.stopGirlPop(this.ui.talkNode)
  391. PlatMgr.showBanner(false);
  392. }
  393. returnHome() {
  394. this.hide();
  395. let showFailWords = !this.success;
  396. xGame.uiMgr.Show(UIMain, showFailWords);
  397. }
  398. clickLeftBtn() {
  399. switch (xGame.common.gameMode) {
  400. case GameMode.classic:
  401. case GameMode.bigMove:
  402. this.returnHome();
  403. break;
  404. case GameMode.placeBall:
  405. //重新挑战
  406. let level = xGame.common.placeBallCurLevel;
  407. this.powerStartPlaceBallLevel(level, this.ui.leftBtn);
  408. Moyu.sendDataEvent("GameAgain", { mode: xGame.common.gameMode });
  409. break;
  410. default:
  411. break;
  412. }
  413. }
  414. powerStartPlaceBallLevel(level, btn) {
  415. if (DataMgr.powerEnough()) {
  416. btn.touchable = false;
  417. btn.powerEft.t0.play(Laya.Handler.create(this, () => {
  418. //
  419. btn.touchable = true;
  420. DataMgr.setPower(-1);
  421. xGame.eventMgr.event(POWER_TIME);
  422. this.startPlaceBallLevel(level);
  423. //
  424. }))
  425. }
  426. else {
  427. xGame.uiMgr.Show(UIPower, 0);
  428. }
  429. }
  430. clickRightBtn() {
  431. switch (xGame.common.gameMode) {
  432. case GameMode.classic:
  433. console.log('zh:clickRightBtn 111');
  434. case GameMode.bigMove:
  435. console.log('zh:clickRightBtn 222');
  436. this.restartGame();
  437. break;
  438. case GameMode.placeBall:
  439. console.log('zh:clickRightBtn 333');
  440. //直接进入下一关,若当前关卡没有通关则当前关卡按照1星通关
  441. let level = xGame.common.placeBallCurLevel;
  442. let data = DataMgr.getPlaceBallLevel(level);
  443. //当前关卡是否通关
  444. let curPss = data.play && !data.isCur;
  445. if (curPss) {
  446. console.log('zh:clickRightBtn 333-111');
  447. console.log('zh:当前LV=' + level)
  448. if (level == 60) {
  449. xGame.uiMgr.Show(UIMsg, "Congratulations on passing all levels.")
  450. // this.ui.rightBtn.visible = false;
  451. Laya.timer.once(3000, this, () => {
  452. this.returnHome();
  453. });
  454. } else {
  455. this.powerStartPlaceBallLevel(level + 1, this.ui.rightBtn);
  456. }
  457. }
  458. else {
  459. console.log('zh:clickRightBtn 333-000');
  460. //当前关卡未通关
  461. Moyu.sendDataEvent("placeBallNextLevel");
  462. console.log('zh:qjff_AD_for_uiGameEnd')
  463. // GlobalManager.instance.registerMethod('xxxxx',this.xxxxx);
  464. // JSBridgeUtils.instance.showRewardAd('xxxxx');
  465. //需要传递参数
  466. Laya.LocalStorage.setItem('temp_qjff_AD_for_uiGameEnd_level', level + '');
  467. if (JSBridgeUtils.instance.showRewardAd('qjff_AD_for_uiGameEnd')) {
  468. } else {
  469. console.log('zh:AD 失败,直接发放奖励')
  470. this.qjff_AD_for_uiGameEnd(level);
  471. }
  472. // Moyu.showVideoAd(() => {
  473. // //一星通关当前关卡,不领取当前关卡奖励
  474. // DataMgr.setPlaceBallLevel(level, 1);
  475. // //进入下一关
  476. // this.startPlaceBallLevel(level + 1);
  477. // //
  478. // }, xGame.define.EAdType.placeBallNextLevel);
  479. }
  480. break;
  481. default:
  482. console.log('zh:clickRightBtn 444');
  483. break;
  484. }
  485. }
  486. public qjff_AD_for_uiGameEnd(level) {
  487. //一星通关当前关卡,不领取当前关卡奖励
  488. DataMgr.setPlaceBallLevel(level, 1);
  489. //进入下一关
  490. this.startPlaceBallLevel(level + 1);
  491. }
  492. startPlaceBallLevel(level) {
  493. xGame.common.gameMode = GameMode.placeBall;
  494. xGame.common.placeBallCurLevel = level;
  495. xGame.uiMgr.Show(UIGame);
  496. this.hide();
  497. }
  498. }
  499. UIGameEnd.uiName = "UIGameEnd";