//********************* // create by 流云 // time: Thu Sep 25 2025 // desc: //********************* import { _decorator, Component, Node, find, instantiate, Label, sp } from 'cc'; import { Auto_BattleFail } from './Auto_BattleFail'; import { ChapterDataManager, BattleType, ChapterDifficulty } from '../../manager/ChapterDataManager'; import { OtherDataType, StatisticsType } from '../../game/GameData'; import MTools from 'db://assets/mx/tools/MTools'; import { ItemData } from '../../game/ConfigProjectData'; import { itemPic } from '../../com/itemPic'; import { ConstEnum, ConstManager } from '../../manager/ConstManager'; import { UIID } from '../../game/ConfigRes'; import { LangSpine } from 'db://assets/mx/module/lang/LangSpine'; import { WeaponType } from '../../manager/WeaponDataManager'; const { ccclass, property } = _decorator; @ccclass('UIBattleFail') export class UIBattleFail extends Auto_BattleFail { curCoinNum: number = 0 curDiamondNum: number = 0 //游戏进度 curGameProgress: number = 0 addNum = 1 dataList = null onLoad(): void { super.onLoad(); let curDeadMonsterNum = gg.game.CurentBattle.MonsterDeadNum; let totalMonsterNum = gg.game.CurentBattle.TotalMonsterNum; /**无限模式下,怪物总数量翻倍 */ if (gg.game.CurentBattle.BattleType == BattleType.InfiniteMode) { curDeadMonsterNum = gg.game.CurentBattle.InfiniteModeMonsterDeadNum; totalMonsterNum = totalMonsterNum * 2; } this.curGameProgress = curDeadMonsterNum / totalMonsterNum; if (gg.game.CurentBattle.BattleType == BattleType.Level) { gg.data.project.setChapterStatusByProgress(gg.game.CurentBattle.ChapterId, gg.game.CurentBattle.Difficulty, this.curGameProgress); } } onEnable(): void { super.onEnable(); } onDisable(): void { // 关闭界面后仍可能有 scheduleOnce 在跑,需全部取消避免回调访问已销毁节点 this.unscheduleAllCallbacks(); super.onDisable(); } onInit(): void { gg.audio.playEffect({ name: "复活失败音效" }); gg.game.thirdChapterFailRoleUpgrade = false gg.game.thirdChapterFailWeaponUpgrade = false this.showOpenMaskEff(2); // let spine = this.ui_center.find("失败结算").getComponent(sp.Skeleton); // spine.getComponent(LangSpine).animation = 'play'; // spine.getComponent(LangSpine).updateLang(); // this.scheduleOnce(()=>{ // spine.setAnimation(0, 'idle', true); // },1.5) // console.log('失败——---当前存档章节:' + gg.data.doc.chapter, "当前章节:" + gg.game.CurentSelectChapterId,"当前模式:"+ gg.game.CurentSelectBattleType) // let n1=gg.data.getStatistics(StatisticsType.FailContinuousCount); // let n2=gg.data.getStatistics(StatisticsType.FailContinuousCountReset); // let n3=gg.data.getStatistics(StatisticsType.SuccessContinuousCount); // console.log('失败次数:'+n1,'失败重置次数:'+n2,'成功次数:'+n3); if (gg.game.CurentBattle.ChapterId == gg.data.doc.chapter && gg.game.CurentBattle.BattleType == BattleType.Level && gg.game.CurentBattle.Difficulty == ChapterDifficulty.Normal) { gg.data.setStatistics(StatisticsType.SuccessContinuousCount, 0) } gg.game.CurentBattle.tryAddEarlyChapterChallengeCount(); //获取关卡次数统计(打点用) let value = gg.data.getkeyKeyValue(OtherDataType.FailReportData, gg.game.CurentBattle.getReportDYChapterId()); let times = 1; if (value != '' && value != '0') { times = Number(value) + 1 } gg.data.setkeyKeyValue(OtherDataType.FailReportData, gg.game.CurentBattle.getReportDYChapterId(), times); let curWaveNum = gg.game.CurentBattle.CurentWaveNum; gg.sdk.reportDY("inLevel", `章节${gg.game.CurentBattle.getReportDYChapterId()}_${curWaveNum}-过关失败${times}`) //玩家等级打点 let playerLevel = gg.data.getPlayerLevel(); console.log('玩家等级',playerLevel); gg.sdk.reportDY("inLevel", `章节${gg.game.CurentBattle.getReportDYChapterId()}_${curWaveNum}-玩家等级`+playerLevel) let length = gg.game.CurentBattle.curMap?.getTetriNodeCount?.() ?? 0; gg.sdk.reportDY("inLevel", `章节${gg.game.CurentBattle.getReportDYChapterId()}_${curWaveNum}-失败摆放方块数量`+length) if (gg.data.doc.chapter >= 3) { let curData = gg.data.getStringData(OtherDataType.UserLevelupData) let array = curData.split('&') let level1 = Number(array[4]) let level2 = Number(array[5]) let level3 = Number(array[6]) if (level1 > 0 || level2 > 0 || level3 > 0) { console.log('不需要引导升级属性') } else { this.ui_upUser.active = false } } else { this.ui_upUser.active = false } let caihongLevel = gg.data.project.getWeaponLevel(WeaponType.DanGong); //彩虹飞弹等级 if (caihongLevel >= 2) { console.log('不需要引导武器') } else { this.ui_upWeapon.active = false } if (!this.ui_upUser.active && gg.data.doc.chapter == 3) { gg.game.thirdChapterFailRoleUpgrade = true } if (!this.ui_upWeapon.active && gg.data.doc.chapter == 2) { //武器升级引导 if (caihongLevel >= 2) { //角色升级引导 gg.game.thirdChapterFailRoleUpgrade = true } else { gg.game.thirdChapterFailWeaponUpgrade = true } } else { if (this.ui_upWeapon.active) { if (caihongLevel >= 2) { //角色升级引导 gg.game.thirdChapterFailRoleUpgrade = true } else { gg.game.thirdChapterFailWeaponUpgrade = true } } } this.showReward() if (!gg.game.CurentBattle.IsWatchAd && gg.game.CurentSelectChapterId >= 3) { gg.sdk.showInterstitialAd(() => { }, () => { }, true) } gg.PRR.addRecordData(); gg.PRR.upToServer(1, gg.game.CurentBattle.BattleTime, () => { console.log("玩家记录上报-失败数据上传成功"); }, () => { console.log("玩家记录上报-失败数据上传失败"); }); } showReward() { let reward = gg.game.CurentBattle.CurentChapterRewardStr.split('|'); //奖励倍数 let mt = 1; let addRatio = 1; if (gg.game.CurentSelectBattleType == BattleType.Level) { addRatio += gg.data.getFightRewardRatio(); addRatio += gg.purchase.getMainLineRewardAdd(); } let itemsArray = [] for (let i = 0; i < reward.length; i++) { let value = reward[i].split(',') let goodId = Number(value[0]) let itemNum = Number(value[1]) if (goodId == 104 || goodId == 105 || goodId == 106 || goodId == 107) { let rewardNum = Math.floor(itemNum * this.curGameProgress * addRatio * mt) if (rewardNum > 0) { let boxRewardArray = gg.data.getFragmentNumArray(goodId + ',' + rewardNum) let statsArray = MTools.mergeToStatsArray(boxRewardArray) for (let i = 0; i < statsArray.length; i++) { let array = statsArray[i].split('|') let id = Number(array[0]); let num = Number(array[1]); let item = new ItemData(id, num) itemsArray.push(item) } } } else { let num = Math.floor(itemNum * this.curGameProgress * addRatio); if (goodId != 4) { num = num * mt; } let item = new ItemData(goodId, num) itemsArray.push(item) } } // this.dataList = itemsArray for (let i = 0; i < itemsArray.length; i++) { //隔振处理 this.scheduleOnce(() => { if (!this.node?.isValid || !this.ui_content?.isValid || !this.ui_singleItem?.isValid) return; let value = itemsArray[i] let item = instantiate(this.ui_singleItem) if (!item?.isValid) return; item.active = true item.parent = this.ui_content item.setPosition(0, 0) this.initItem(item, value) }, 0.01 * i) } } /**初始化单个物品 */ initItem(item, value) { let goodId = value.id let num = value.num item.getComponent(itemPic).setGoodId(goodId) let numLabel = item.getChildByName('numStr').getComponent(Label) numLabel.string = num.toString() } click_btnGet() { gg.audio.playEffect({ name: "点击音效" }); let curWaveNum = gg.game.CurentBattle.CurentWaveNum gg.sdk.reportDY("inLevel", `章节${gg.game.CurentBattle.getReportDYChapterId()}_${curWaveNum}-失败领取奖励`) this.getAward() this.unscheduleAllCallbacks(); //因为失败界面有广告 gg.game.CurentBattle.addFailWeight(false); let id = UIID.Home; if (gg.game.CurentSelectBattleType != BattleType.Level) id = UIID.Replica; gg.game.enterMain(id); } getAward() { // gg.game.IsPlayedGame = true gg.game.playerGameFail = true if(gg.data.doc.chapter == 2){ gg.data.setStatistics(StatisticsType.homeGuideIndex, 0) } for (let i = 0; i < this.dataList.length; i++) { let value = this.dataList[i]; let goodId = Number(value.id) let num = Number(value.num) gg.data.addItemNum(goodId, num * this.addNum); } } click_btnADGet() { gg.audio.playEffect({ name: "点击音效" }); gg.sdk.showVideoAd((res) => { if (res) { let curWaveNum = gg.game.CurentBattle.CurentWaveNum gg.sdk.reportDY("inLevel", `章节${gg.game.CurentBattle.getReportDYChapterId()}_${curWaveNum}-AD-失败双倍领取奖励`) // for(let i = 0;i < this.dataList.length;i++){ // let value = this.dataList[i]; // let goodId = Number(value.id) // let num = Number(value.num) // gg.data.addItemNum(goodId, num * 3); // } // this.close(2) // GEvent.Ins.emit(GEvent.EnterHome) this.addNum = 2 this.btnADGet.active = false //刷新界面数字 for (let i = 0; i < this.ui_content.children.length; i++) { let item = this.ui_content.children[i] let numLabel = item.getChildByName('numStr').getComponent(Label) numLabel.string = (Number(numLabel.string) * this.addNum).toString() } gg.game.CurentBattle.IsWatchAd = true } else { gg.ui.showToast('观看视频失败'); } }) } click_btnUpWeapon() { gg.audio.playEffect({ name: "点击音效" }); let curWaveNum = gg.game.CurentBattle.CurentWaveNum gg.sdk.reportDY("inLevel", `章节${gg.game.CurentBattle.getReportDYChapterId()}_${curWaveNum}-失败跳武器升级`) this.getAward() gg.game.enterMain(UIID.Weapon); } click_btnUpUser() { gg.audio.playEffect({ name: "点击音效" }); let curWaveNum = gg.game.CurentBattle.CurentWaveNum gg.sdk.reportDY("inLevel", `章节${gg.game.CurentBattle.getReportDYChapterId()}_${curWaveNum}-失败跳角色升级`) this.getAward() gg.game.enterMain(UIID.Role); } }