import DataMgr from "../data/DataMgr"; import { AwardType, GameMode, PlaceBallType, POWER_TIME, Prop, RESET_GAME, RESTART_GAME } from "../data/Define"; import UIBase from "../fgui/core/UIBase"; import ui_UIGameEnd from "../fgui/res/game/ui_UIGameEnd"; import PlatMgr from "../game/PlatMgr"; import Common from "../utils/Common"; import { xGame } from "../xGame"; import MoneyNode from "./item/MoneyNode"; import UIAddCoin from "./UIAddCoin"; import UIAddProp from "./UIAddProp"; import { UIGame } from "./UIGame"; import UIInvitation from "./UIInvitation"; import UIMain from "./UIMain"; import UIPower from "./UIPower"; import UIMsg from "./UIMsg"; import GlobalManager from "../utils/GlobalManager"; import JSBridgeUtils from "../utils/JSBridgeUtils"; export default class UIGameEnd extends UIBase { public ui: ui_UIGameEnd; public success: boolean = false; public moneyNode: MoneyNode; // public awardCoinNum = 1000; public awardDiamondNum = 10; public constructor() { super(); } protected onConstructor(): void { this.ui = ui_UIGameEnd.createInstance(); this.contentPane = this.ui; // this.addUIClick(this.ui.leftBtn, this.clickLeftBtn); this.addUIClick(this.ui.closeNode.closeBtn, this.returnHome); this.addUIClick(this.ui.rightBtn, this.clickRightBtn); this.moneyNode = new MoneyNode(this.ui.moneyNode); this.ui.talkNode.visible = false; if (Moyu.isKs) this.ui.closeNode.closeBtn.x += 100; } updateType() { switch (xGame.common.gameMode) { case GameMode.classic: this.ui.c1.selectedIndex = this.success ? 0 : 1; this.ui.coinNode.visible = this.success; if (!this.success) { Laya.timer.once(500, this, () => { xGame.uiMgr.Show(UIAddCoin); }) } this.ui.isGetAward.visible = false; this.ui.leftBtn.c1.selectedIndex = 3; this.ui.rightBtn.c1.selectedIndex = 0; // this.moneyNode.ui.c1.selectedIndex = 1; break; case GameMode.bigMove: this.ui.c1.selectedIndex = this.success ? 0 : 1; this.ui.coinNode.visible = this.success; //设置大招版本的连胜数据 if (xGame.common.gameMode == GameMode.bigMove) { if (this.success) { DataMgr.setSkillSuccessTimes(1, true); DataMgr.setSkillAccTimes(1); } else { DataMgr.setSkillSuccessTimes(0, false); } } // if (!this.success) { Laya.timer.once(500, this, () => { xGame.uiMgr.Show(UIAddCoin); }) } this.ui.isGetAward.visible = false; this.ui.leftBtn.c1.selectedIndex = 3; this.ui.rightBtn.c1.selectedIndex = 0; // this.moneyNode.ui.c1.selectedIndex = 1; break; case GameMode.placeBall: this.ui.coinNode.visible = false; if (this.success) { if (xGame.common.placeBallStarNum == 3) { this.ui.c1.selectedIndex = 2; } else { this.ui.c1.selectedIndex = 3; } } else { this.ui.c1.selectedIndex = 4; } let cfg = cfgTable.placeballData[xGame.common.placeBallCurLevel]; if (cfg.type == PlaceBallType.challenge) { //挑战关卡 this.ui.c1.selectedIndex = 2; } this.ui.conditionNode.conditionTxt.text = cfg.type == 0 ? `Clear the table` : `Pocket ${cfg.ball} balls `;//打进颗球 Clear the table this.updatePlaceBallBtn(); this.updatePlaceBallStarNum(); this.updatePlaceBallAwardState(); this.moneyNode.ui.c1.selectedIndex = 2; this.moneyNode.checkPowerTime(); this.moneyNode.powerChange(); // DataMgr.upRankData(); // break; default: break; } } updatePlaceBallBtn() { this.ui.leftBtn.c1.selectedIndex = 5; if (this.success) { //挑战下一关要花费金币 this.ui.rightBtn.c1.selectedIndex = 14; } else { if (xGame.common.placeBallStarNum == 3) { //挑战下一关要花费金币 this.ui.rightBtn.c1.selectedIndex = 14; } else { //看视频跳过 this.ui.rightBtn.c1.selectedIndex = 1; } } } updatePlaceBallStarNum() { let starNum = xGame.common.placeBallStarNum; if (starNum == 0) this.ui.starNumNode.c1.selectedIndex = 3; else { this.ui.starNumNode.c1.selectedIndex = starNum - 1; } } updatePlaceBallAwardState() { let level = xGame.common.placeBallCurLevel; let starNum = xGame.common.placeBallStarNum; //是否获得奖励 let getAward = DataMgr.getPlaceBallLevel(level).getAward; let data = cfgTable.placeballData[level].award; let cfg = cfgTable.placeballData[level]; this.awardDiamondNum = data[1]; this.awardCoinNum = data[0]; if (cfg.type == PlaceBallType.challenge) { this.awardDiamondNum = 0; this.awardCoinNum = xGame.common.gameMgr.finishBalls * 100; } this.ui.awardNode.diamondNode.visible = this.awardDiamondNum > 0; this.ui.awardNode.coinNode.visible = this.awardCoinNum > 0; if (cfg.type == PlaceBallType.challenge) { this.ui.awardNode.coinNode.visible = true; } // if (this.awardCoinNum > 0 && this.awardDiamondNum > 0) { this.ui.awardNode.diamondNode.x = 265; this.ui.awardNode.coinNode.x = 354; } else { this.ui.awardNode.diamondNode.x = 291; this.ui.awardNode.coinNode.x = 291; } this.ui.awardNode.diamondNode.numTxt.text = this.awardDiamondNum + ""; this.ui.awardNode.coinNode.numTxt.text = this.awardCoinNum + ""; if (this.awardCoinNum == 0) { this.ui.awardNode.coinNode.numTxt.text = ""; } if (getAward) { this.ui.isGetAward.visible = true; this.ui.awardNode.diamondNode.c1.selectedIndex = 2; this.ui.awardNode.coinNode.c1.selectedIndex = 2; } else { this.ui.isGetAward.visible = false; if (starNum == 3 && cfg.type == PlaceBallType.challenge) { this.ui.awardNode.diamondNode.c1.selectedIndex = 0; this.ui.awardNode.coinNode.c1.selectedIndex = 0; } else { this.ui.awardNode.diamondNode.c1.selectedIndex = 1; this.ui.awardNode.coinNode.c1.selectedIndex = 1; } } } public show(success): void { super.show(); //重置游戏 xGame.eventMgr.event(RESET_GAME); this.success = success; Laya.timer.clearAll(this); this.playSecretaryAni(); Moyu.sendDataEvent("GameEnd", { id: xGame.common.gameMode, res: this.success ? 1 : 2 }); // let offsetTime = new Date().getTime() - xGame.common.gameStartTime; offsetTime = Math.floor(offsetTime / 1000); Moyu.sendDataEvent("gameOver", { isWin: this.success ? 1 : 0, timeConsuming: offsetTime, gameType: xGame.common.gameMode }); // this.updateType(); // Laya.timer.once(200, this, () => { this.addAward(() => { // this.updateType(); // Laya.timer.once(500, this, () => { this.showChallengeLevel(); }) }); }) // if (this.success) { JSBridgeUtils.instance.showInternAd('gameend_success'); //成功 console.log('zh:game end 成功'); xGame.soundMgr.playSound('slots_roll01'); xGame.soundMgr.playSound("s_win"); xGame.common.showGirlTalkPop(8, this.ui.talkNode, this.ui.talkNode.womanTxt); this.diyGameDataUtilForGameWin(); } else { JSBridgeUtils.instance.showInternAd('gameend_faill'); //失败 console.log('zh:game end失败'); xGame.soundMgr.playSound('matchwin01'); xGame.soundMgr.playSound("s_lose"); xGame.common.showGirlTalkPop(9, this.ui.talkNode, this.ui.talkNode.womanTxt); } //if (!Moyu.isLegal) PlatMgr.showBanner(true); ////// let challengeNum = DataMgr.getChallengeTimes(); if (xGame.common.gameMode == GameMode.classic && challengeNum >= 1 && challengeNum <= 3) { DataMgr.setChallengeTimes(1); } //增加经典模式胜利场次 if (this.success && xGame.common.gameMode == GameMode.classic) { DataMgr.setClassicTimes(); } } diyGameDataUtilForGameWin(){ console.log('zh: DiyGameDataUtilForGameWin diy '); switch (xGame.common.gameMode) { case GameMode.classic: console.log('zh:DiyGameDataUtilForGameWin 111'); case GameMode.bigMove: console.log('zh:DiyGameDataUtilForGameWin 222'); this.restartGame(); break; case GameMode.placeBall: console.log('zh:DiyGameDataUtilForGameWin 333'); var level = xGame.common.placeBallCurLevel; console.log('zh:练习模式 联系了多少LEV=' + level); let db_over_lev = DataMgr.getChallengeMode_overLev(); if (level > db_over_lev) { DataMgr.setChallengeMode_overLev(level); } break; default: console.log('zh:DiyGameDataUtilForGameWin 444'); break; } } //展示经典模式挑战关卡 showChallengeLevel() { //todo if (DataMgr.getChallengeTimes() != 0) return; let skill = DataMgr.getSkillAccTimes(); let put = DataMgr.getPlaceBallLevelList().length; if (skill >= 3 || put >= 5) { xGame.uiMgr.Show(UIInvitation); this.hide(); } } //添加奖励 addAward(callback) { if (!this.success) { callback && callback(); return; } switch (xGame.common.gameMode) { case GameMode.classic: this.awardCoinNum = xGame.common.passAwardCoin; this.awardDiamondNum = 0; xGame.common.playObjFlyAnim(this.awardCoinNum, Prop.coin); break; case GameMode.bigMove: this.awardCoinNum = xGame.common.passAwardCoin; this.awardDiamondNum = 0; xGame.common.playObjFlyAnim(this.awardCoinNum, Prop.coin); callback && callback(); break; case GameMode.placeBall: let level = xGame.common.placeBallCurLevel; Moyu.sendDataEvent("PlaceBall", { id: level, res: this.success ? 1 : 2 }); if (xGame.common.placeBallStarNum != 3) { //未获得三星 callback && callback(); return; } else { let getAward = DataMgr.getPlaceBallLevel(level).getAward; if (getAward) { //已经获得了该奖励 callback && callback(); return; } } let cfg = cfgTable.placeballData[level]; let data = cfgTable.placeballData[level].award; this.awardCoinNum = data[0]; this.awardDiamondNum = data[1]; // if (cfg.type == PlaceBallType.challenge) { this.awardDiamondNum = 0; this.awardCoinNum = xGame.common.gameMgr.finishBalls * 100; } // let coinAward = new AwardType(Prop.coin, this.awardCoinNum); let diamondAward; if (this.awardDiamondNum > 0) { //钻石和金币 diamondAward = new AwardType(Prop.diamond, this.awardDiamondNum); xGame.common.getAward([diamondAward, coinAward], callback); } else { //只有金币 xGame.common.getAward([coinAward], callback); } if (cfg.type == PlaceBallType.normal) { DataMgr.setPlaceBallAward(level); } break; default: break; } } playSecretaryAni_old() { let parent = this.ui.secretary.displayObject; parent.destroyChildren(); let xx = this.ui.secretary.width / 2 let yy = this.ui.secretary.height; let scale = xGame.common.getSecretaryScale(); let data = { x: xx, y: yy, scaleX: scale, scaleY: scale }; if (this.success) { let rand = Math.random() <= 0.5 ? 2 : 3; xGame.common.secretary.play(data, rand, false, parent, () => { xGame.common.secretary.play(data, 1, true, parent); }); } else { //失败特效 xGame.common.secretary.play(data, 0, true, parent); } } playSecretaryAni() { let parent = this.ui.secretary.displayObject; parent.destroyChildren(); let xx = this.ui.secretary.width / 2 let yy = this.ui.secretary.height; let scale = xGame.common.getSecretaryScale(); let data = { x: xx, y: yy, scaleX: scale, scaleY: scale }; if (this.success) { //let rand = Math.random() <= 0.5 ? 2 : 3; let rand = 0;//只有一个动画 xGame.common.secretary.play(data, 0, true, parent); } else { //失败特效 xGame.common.secretary.play(data, 0, true, parent); } } restartGame() { switch (xGame.common.gameMode) { case GameMode.classic: xGame.eventMgr.event(RESTART_GAME); Moyu.sendDataEvent("GameAgain", { mode: xGame.common.gameMode }); break; case GameMode.bigMove: this.hide(); xGame.eventMgr.event(RESTART_GAME); Moyu.sendDataEvent("GameAgain", { mode: xGame.common.gameMode }); break; default: break; } } hide() { super.hide(); xGame.common.stopGirlPop(this.ui.talkNode) PlatMgr.showBanner(false); } returnHome() { this.hide(); let showFailWords = !this.success; xGame.uiMgr.Show(UIMain, showFailWords); } clickLeftBtn() { switch (xGame.common.gameMode) { case GameMode.classic: case GameMode.bigMove: this.returnHome(); break; case GameMode.placeBall: //重新挑战 let level = xGame.common.placeBallCurLevel; this.powerStartPlaceBallLevel(level, this.ui.leftBtn); Moyu.sendDataEvent("GameAgain", { mode: xGame.common.gameMode }); break; default: break; } } powerStartPlaceBallLevel(level, btn) { if (DataMgr.powerEnough()) { btn.touchable = false; btn.powerEft.t0.play(Laya.Handler.create(this, () => { // btn.touchable = true; DataMgr.setPower(-1); xGame.eventMgr.event(POWER_TIME); this.startPlaceBallLevel(level); // })) } else { xGame.uiMgr.Show(UIPower, 0); } } clickRightBtn() { switch (xGame.common.gameMode) { case GameMode.classic: console.log('zh:clickRightBtn 111'); case GameMode.bigMove: console.log('zh:clickRightBtn 222'); this.restartGame(); break; case GameMode.placeBall: console.log('zh:clickRightBtn 333'); //直接进入下一关,若当前关卡没有通关则当前关卡按照1星通关 let level = xGame.common.placeBallCurLevel; let data = DataMgr.getPlaceBallLevel(level); //当前关卡是否通关 let curPss = data.play && !data.isCur; if (curPss) { console.log('zh:clickRightBtn 333-111'); console.log('zh:当前LV=' + level) if (level == 60) { xGame.uiMgr.Show(UIMsg, "Congratulations on passing all levels.") // this.ui.rightBtn.visible = false; Laya.timer.once(3000, this, () => { this.returnHome(); }); } else { this.powerStartPlaceBallLevel(level + 1, this.ui.rightBtn); } } else { console.log('zh:clickRightBtn 333-000'); //当前关卡未通关 Moyu.sendDataEvent("placeBallNextLevel"); console.log('zh:qjff_AD_for_uiGameEnd') // GlobalManager.instance.registerMethod('xxxxx',this.xxxxx); // JSBridgeUtils.instance.showRewardAd('xxxxx'); //需要传递参数 Laya.LocalStorage.setItem('temp_qjff_AD_for_uiGameEnd_level', level + ''); if (JSBridgeUtils.instance.showRewardAd('qjff_AD_for_uiGameEnd')) { } else { console.log('zh:AD 失败,直接发放奖励') this.qjff_AD_for_uiGameEnd(level); } // Moyu.showVideoAd(() => { // //一星通关当前关卡,不领取当前关卡奖励 // DataMgr.setPlaceBallLevel(level, 1); // //进入下一关 // this.startPlaceBallLevel(level + 1); // // // }, xGame.define.EAdType.placeBallNextLevel); } break; default: console.log('zh:clickRightBtn 444'); break; } } public qjff_AD_for_uiGameEnd(level) { //一星通关当前关卡,不领取当前关卡奖励 DataMgr.setPlaceBallLevel(level, 1); //进入下一关 this.startPlaceBallLevel(level + 1); } startPlaceBallLevel(level) { xGame.common.gameMode = GameMode.placeBall; xGame.common.placeBallCurLevel = level; xGame.uiMgr.Show(UIGame); this.hide(); } } UIGameEnd.uiName = "UIGameEnd";