//********************* // create by 流云 // time: Mon Nov 03 2025 // desc: //********************* import { _decorator, Component, Node, find, Label, Button, Sprite, ProgressBar, tween, v3, sp, ScrollView, Prefab, instantiate, Asset } from 'cc'; import { Auto_pageShop } from './Auto_pageShop'; import { ItemNumType, OtherDataType, StatisticsType, TaskType } from '../../game/GameData'; import MTools from 'db://assets/mx/tools/MTools'; import { ItemData } from '../../game/ConfigProjectData'; import { GBundle, GPath, UIID } from '../../game/ConfigRes'; import { itemPic } from '../../com/itemPic'; import { IShopItemData, TableNames } from '../../game/ConfigTableData'; import { GEvent } from 'db://assets/mx/module/event/GEvent'; import { sdkConfig } from '../../sdk/sdkConfig'; import { TargetTaskType } from '../../manager/TargetTaskManager'; const { ccclass, property } = _decorator; @ccclass('UIpageShop') export class UIpageShop extends Auto_pageShop { getResPkg() { let pkg = { name: "商店页", isReleaseable: true, ress: [ ] } if (sdkConfig.isIAPVersion) { pkg.ress.push({ name: 'chapterGift', bundle: GBundle.ChapterGiftBg, path: GPath.Prefab, type: Prefab }) pkg.ress.push({ name: 'diamondShop', bundle: GBundle.DiamondShop, path: GPath.Prefab, type: Prefab }) } return pkg; } gaojiBoxSpendNum = 30//高级宝箱花费30钻石 xiyouBoxSpendNum = 200//普通宝箱花费100钻石 // //一堆金币花费 // heapGoldSpendNum = 1500//10亿 // //一袋金币花费 // bagGoldSpendNum = 500//1亿 spendNumArray = [0, 500, 1500] goldNumArray = [500, 2500, 10000] changePosi = 0 //免费获取的钻石 freeDiamondNum = 100//100钻石 // //一堆金币 // freeGoldNum = 500//1亿 // //一堆金币数量 // heapGoldNum = 10000//10亿 // //一袋金币数量 // bagGoldNum = 2500//1亿 onLoad(): void { super.onLoad(); //checkShopItem GEvent.Ins.on(GEvent.checkShopItem, this.checkShopItem, this); } setChangePosi(changePosi) { this.changePosi = changePosi //console.log('this.changePosi=66666=',this.changePosi) //进行滚动 this.scheduleOnce(() => { if (changePosi == 0) { } else if (changePosi == 1) { this.ui_scrollView.getComponent(ScrollView).scrollToTop(0.3) } else if (changePosi == 2) { this.ui_scrollView.getComponent(ScrollView).scrollToPercentVertical(0.35, 0.3) } else if (changePosi == 3) { this.ui_scrollView.getComponent(ScrollView).scrollToBottom(0.3) } }, 0.3) } onEnable(): void { super.onEnable(); let chepdate = gg.data.table.getTableData(TableNames.Chapter, gg.data.doc.chapter); if (chepdate) { let num = chepdate.shop_coin; this.goldNumArray = [num, num * 5, num * 20]; } } updateShopTime() { //更新商店时间,同步到当前的时间 let autoTime2 = find("shopNodes/autoTime2", this.ui_content)?.getComponent(Label); const now = new Date(); // 获取明天的日期(用于计算到午夜的时间) const tomorrow = new Date(now); tomorrow.setDate(tomorrow.getDate() + 1); tomorrow.setHours(0, 0, 0, 0); // 计算时间差(毫秒) const timeDiff = tomorrow.getTime() - now.getTime(); autoTime2.string = MTools.formatTimeString(timeDiff / 1000, "hh:mm:ss"); } onDisable(): void { super.onDisable(); } onInit(): void { this.unscheduleAllCallbacks(); this.schedule(() => { this.updateShopTime(); }, 1); let showInde = 0; let bosFreeBtn = this.ui_content.find("BoxNodes/稀有宝箱框/freeBtnAd"); let buyBtn = this.ui_content.find("BoxNodes/稀有宝箱框/buyBtn"); let dotNode = this.ui_content.find("BoxNodes/稀有宝箱框/dot"); if (sdkConfig.isIAPVersion) { bosFreeBtn.active = false; this.gaojiBoxSpendNum = 300; this.xiyouBoxSpendNum = 3000; buyBtn.x = 0; dotNode.x = 68; if (gg.purchase.getCanShowChapterGiftList().length > 0) { this.showChapterBox() showInde++; } this.scheduleOnce(() => { this.showDiamondShop(); }, 0.05 * showInde++) } else { this.gaojiBoxSpendNum = 30; this.xiyouBoxSpendNum = 200; buyBtn.x = 65; dotNode.x = 128; bosFreeBtn.active = true } this.scheduleOnce(() => { this.showShopItem() }, 0.05 * showInde++) this.scheduleOnce(() => { this.showBoxNode() }, 0.05 * showInde++) this.scheduleOnce(() => { this.showGoldNode() }, 0.05 * showInde++) this.updateShopTime() // this.showBoxNode() // this.showGoldNode() // this.updateShopTime() // console.log('this.changePosi=5555=',this.changePosi) } onDestroy() { GEvent.Ins.off(GEvent.checkShopItem, this.checkShopItem, this); } checkShopItem(index) { let shopNodes = find("shopNodes", this.ui_content); let itemNodes = find("itemNodes", shopNodes); let itemNode: Node = itemNodes.children[index]; let mask = find("mask", itemNode); let lay = find("lay", itemNode); mask.active = true lay.active = false } refreshFirstShopitem() { //第一个商品特殊处理 let shopNodes = find("shopNodes", this.ui_content); //shopNodes.active = true //console.log('显示商店物品'); //商店固定物品第一个是免费钻石,其他五个需要随机 let itemNodes = find("itemNodes", shopNodes); let buyZSNode = itemNodes.children[0]; //动画 let name = find("name", buyZSNode)?.getComponent(Label); name.string = gg.lang.get('钻石')//'免费钻石' let count = gg.data.getStatistics(StatisticsType.ShopBuyItemAdCount) let shareCount = gg.data.getStatistics(StatisticsType.ShopDiamondShareCount) let mask = find("mask", buyZSNode); let freeLabNode = find("freeLab", buyZSNode) let lay2 = find("lay2", buyZSNode); let buyLab = find("buyLab", lay2)?.getComponent(Label); let jinka = find("商城金卡", buyZSNode) let layShare = find("layShare", buyZSNode); if (count == 0) { //不可以购买 mask.active = true freeLabNode.active = false lay2.active = false layShare.active = false jinka.active = false } else { if (count == 6) { //每日免费购买 mask.active = false freeLabNode.active = true lay2.active = false layShare.active = false } else if (shareCount == 0) { mask.active = false freeLabNode.active = false lay2.active = false layShare.active = true } else { //广告购买 mask.active = false freeLabNode.active = false lay2.active = true layShare.active = false //免费(4) buyLab.string = gg.lang.get('免费') + `(${count})` } } } /**显示章节礼包 */ showChapterBox() { void this._showChapterBoxAsync(); } private async _showChapterBoxAsync(): Promise { if (!this.ui_content?.isValid) return; let chapterGiftNode = find('chapterGift', this.ui_content); if (!chapterGiftNode?.isValid) { chapterGiftNode = await gg.res.getNodeAsync(GPath.UIPrefab, 'chapterGift', GBundle.ChapterGiftBg); if (!chapterGiftNode?.isValid || !this.ui_content?.isValid) { console.warn('[UIpageShop] chapterGift 加载失败'); return; } // 异步期间可能已挂上同名节点,避免重复 const existed = find('chapterGift', this.ui_content); if (existed?.isValid) { gg.res.putNode(chapterGiftNode); chapterGiftNode = existed; } else { this.ui_content.addChild(chapterGiftNode); chapterGiftNode.setSiblingIndex(1); } } chapterGiftNode.active = true; } showDiamondShop() { void this._showDiamondShopAsync(); } private async _showDiamondShopAsync(): Promise { if (!this.ui_content?.isValid) return; let diamondShopNode = find('diamondShop', this.ui_content); if (!diamondShopNode?.isValid) { diamondShopNode = await gg.res.getNodeAsync(GPath.UIPrefab, 'diamondShop', GBundle.DiamondShop); if (!diamondShopNode?.isValid || !this.ui_content?.isValid) { console.warn('[UIpageShop] diamondShop 加载失败'); return; } const existed = find('diamondShop', this.ui_content); if (existed?.isValid) { gg.res.putNode(diamondShopNode); diamondShopNode = existed; } else { this.ui_content.addChild(diamondShopNode); const boxNodes = find('BoxNodes', this.ui_content); if (boxNodes) { diamondShopNode.setSiblingIndex(boxNodes.getSiblingIndex() + 1); } } } diamondShopNode.active = true; } showShopItem() { //1 显示商店物品 let shopNodes = find("shopNodes", this.ui_content); shopNodes.active = true //console.log('显示商店物品'); //商店固定物品第一个是免费钻石,其他五个需要随机 //动画 let itemNodes = find("itemNodes", shopNodes); for (let i = 0; i < itemNodes.children.length; i++) { let itemNode = itemNodes.children[i]; itemNode.scale = v3(0.1, 0.1, 0.1) tween(itemNode) .to(0.5, { scale: v3(1, 1, 1) }, { easing: 'elasticOut' }) .start() } //获取商店的商品列表 let localStr = gg.data.getStringData(OtherDataType.ShopBuyListData) let shopItemList = [] if (localStr == null || localStr == '' || gg.game.isShopFirstLoginRefresh) { //第一次打开商店 gg.game.isShopFirstLoginRefresh = false; console.log('第一次打开商店, 或者刷新商店') shopItemList = gg.data.getShopItemList() } else { shopItemList = localStr.split('&') } this.refreshFirstShopitem() //刷新其他商品 名字,底板,icon, 金币或者钻石,折扣 for (let i = 1; i < itemNodes.children.length; i++) { if (shopItemList[i] == null || shopItemList[i] == '') { continue } let itemNode: Node = itemNodes.children[i]; let pinjikuang = find("品级框", itemNode); let icon = find("icon", itemNode); let zhekouPic = find("折扣", itemNode); let nameLab = find("name", itemNode)?.getComponent(Label); let numLab = find("numLab", itemNode)?.getComponent(Label); let zhekouLab = find("zhekouLab", itemNode)?.getComponent(Label); let mask = find("mask", itemNode); let lay = find("lay", itemNode); let jinbiIcon = find("金币", lay); let zuanshiIcon = find("钻石", lay); let buyLab = find("buyLab", lay)?.getComponent(Label); let dataArray = shopItemList[i].split('|'); let suipianId = Number(dataArray[0]); let zhekouNum = Number(dataArray[1]); let isGet = Number(dataArray[2]); if (isGet == 1) { //已购买 mask.active = true lay.active = false } else { //未购买 mask.active = false lay.active = true } let suiPianShopList = gg.data.table.getTableList(TableNames.Shop) let shopItemData = suiPianShopList.find((item) => item.id == suipianId) let goodId = shopItemData.frag itemNode.getComponent(itemPic).setGoodId(goodId) nameLab.string = gg.lang.get(shopItemData.name)//shopItemData.name //设置信息 numLab.string = 'x' + shopItemData.quantity + '' if (zhekouNum == 10) { zhekouLab.node.active = false zhekouPic.active = false } else { zhekouLab.node.active = true zhekouPic.active = true zhekouLab.string = zhekouNum + gg.lang.get('折')//zhekouNum + '折' } if (shopItemData.type == 1) { jinbiIcon.active = true zuanshiIcon.active = false buyLab.string = Math.floor(shopItemData.price * zhekouNum / 10) + '' } else { jinbiIcon.active = false zuanshiIcon.active = true buyLab.string = Math.floor(shopItemData.price * zhekouNum / 10) + '' } let shopData = { itemIndex: i, suipianId: suipianId, goodId: goodId, zhekouNum: zhekouNum, buyType: shopItemData.type, buyPrice: Math.floor(shopItemData.price * zhekouNum / 10), buyNum: shopItemData.quantity } //把属性增加到itemNode上 itemNode.attr(shopData) } } showBoxNode() { //2 显示宝箱节点 钻石花费 //console.log('显示宝箱节点'); let BoxNodes = find("BoxNodes", this.ui_content); BoxNodes.active = true let gaojiLab = find("高级宝箱框/buyBtn/lay/buyLab", BoxNodes)?.getComponent(Label); let xiyouLab = find("稀有宝箱框/buyBtn/lay/buyLab", BoxNodes)?.getComponent(Label); let freeBtnAd1 = find("高级宝箱框/freeBtnAd", BoxNodes); let freeBtnAd2 = find("稀有宝箱框/freeBtnAd", BoxNodes); gaojiLab.string = this.gaojiBoxSpendNum.toString(); xiyouLab.string = this.xiyouBoxSpendNum.toString(); //高级宝箱免费次数 let freeBoxCount = gg.data.getStatistics(StatisticsType.FreeBoxCount); //console.log('高级宝箱免费次数',freeBoxCount); //0,1,2,3 if (freeBoxCount == 0) { //都可以看广告免费 freeBtnAd1.getComponent(Button).interactable = true freeBtnAd1.getComponent(Sprite).grayscale = false freeBtnAd2.getComponent(Button).interactable = true freeBtnAd2.getComponent(Sprite).grayscale = false } else if (freeBoxCount == 1) { //高级免费使用完 freeBtnAd1.getComponent(Button).interactable = false freeBtnAd1.getComponent(Sprite).grayscale = true freeBtnAd2.getComponent(Button).interactable = true freeBtnAd2.getComponent(Sprite).grayscale = false } else if (freeBoxCount == 2) { //稀有免费使用完 freeBtnAd2.getComponent(Button).interactable = false freeBtnAd2.getComponent(Sprite).grayscale = true freeBtnAd1.getComponent(Button).interactable = true freeBtnAd1.getComponent(Sprite).grayscale = false } else if (freeBoxCount == 3) { //都使用完 freeBtnAd1.getComponent(Button).interactable = false freeBtnAd1.getComponent(Sprite).grayscale = true freeBtnAd2.getComponent(Button).interactable = false freeBtnAd2.getComponent(Sprite).grayscale = true } //经验条修改 let progress = find("ProgressBar", BoxNodes)?.getComponent(ProgressBar); //进度 let levelLab = find("ProgressBar/levelLab", BoxNodes)?.getComponent(Label); //等级 let proLab = find("ProgressBar/proLab", BoxNodes)?.getComponent(Label); //经验值 let curBoxLevel = gg.data.getCurBoxLevel(); //console.log('当前宝箱等级',curBoxLevel); let curExp = gg.data.getCurBoxExp(); //console.log('当前宝箱经验',curExp); levelLab.string = '' + curBoxLevel.toString(); proLab.string = '' + curExp[0].toString() + '/' + curExp[1].toString(); progress.progress = curExp[0] / curExp[1]; } showGoldNode() { //3 显示金币节点 //console.log('显示金币节点'); let GoldNodes = find("GoldNodes", this.ui_content); GoldNodes.active = true for (let i = 0; i < GoldNodes.children.length; i++) { let node = GoldNodes.children[i]; let goldNum = find("numLab", node)?.getComponent(Label); let spendNum = find("layZuanshi/buyLab", node)?.getComponent(Label); goldNum.string = 'x' + this.goldNumArray[i].toString(); if (spendNum) { spendNum.string = this.spendNumArray[i].toString(); } } // let freeNode = GoldNodes.children[0]; let mask = find("mask", freeNode); let layFree = find("layFree", freeNode); let freeLab = find("freeLab", freeNode); let layShare = find("layShare", freeNode); //一次免费,5次广告,次日请空 let freeSpendNum = gg.data.getStatistics(StatisticsType.ShopBuyGoldAdCount) //console.log('免费购买次数',freeSpendNum); let buyGoldShareCount = gg.data.getStatistics(StatisticsType.BuyGoldShareCount) if (freeSpendNum == 0) { //显示已经卖完了 mask.active = true layFree.active = false freeLab.active = false layShare.active = false } else { if (freeSpendNum == 6) { //免费购买 layFree.active = false freeLab.active = true mask.active = false } else if (buyGoldShareCount == 0) { //分享购买 layFree.active = false freeLab.active = false mask.active = false layShare.active = true } else { //看视频免费购买 mask.active = false layFree.active = true freeLab.active = false let lab = find("buyLab2", layFree)?.getComponent(Label); //(3/5) lab.string = '(' + (freeSpendNum).toString() + '/5)'; layShare.active = false } } } //购买物品 //购买物品 buyFreeItemClick(event, data) { gg.audio.playEffect({ name: "点击音效" }); //4 购买物品 //console.log('购买物品',data); let count = gg.data.getStatistics(StatisticsType.ShopBuyItemAdCount) let shareCount = gg.data.getStatistics(StatisticsType.ShopDiamondShareCount) if (count == 0) { //不可以购买 gg.ui.showToast('购买次数已用完') } else { if (count == 6) { gg.sdk.reportDY("inLevel", `商店-免费获取钻石`) gg.data.setStatistics(StatisticsType.ShopBuyItemAdCount, count - 1) //gg.data.addItemNum(ItemNumType.diamond, this.freeDiamondNum); let itemsArray = [] let id = 3//钻石 let item = new ItemData(id, this.freeDiamondNum) item.num = this.freeDiamondNum item.id = id itemsArray.push(item) gg.ui.openPanel(UIID.GetReward, { data: itemsArray }); gg.data.addDayTaskProgressData(TaskType.shopBuyZuanshi, 1) this.refreshFirstShopitem() } else if (shareCount == 0) { gg.sdk.share(2, (res) => { if (res) { // 视频播放成功 // 执行购买物品的逻辑 gg.sdk.reportDY("inLevel", `商店-分享购买钻石`); gg.data.setStatistics(StatisticsType.ShopDiamondShareCount, 1) //gg.data.addItemNum(ItemNumType.diamond, this.freeDiamondNum); let itemsArray = [] let id = 3//钻石 let item = new ItemData(id, this.freeDiamondNum) item.num = this.freeDiamondNum item.id = id itemsArray.push(item) gg.ui.openPanel(UIID.GetReward, { data: itemsArray }); this.refreshFirstShopitem() gg.data.addDayTaskProgressData(TaskType.gameShare, 1) gg.data.addDayTaskProgressData(TaskType.shopBuyZuanshi, 1) } else { // 视频播放失败 gg.ui.showToast('购买失败') } }) } else { gg.sdk.showVideoAd((res) => { if (res) { // 视频播放成功 // 执行购买物品的逻辑 gg.sdk.reportDY("inLevel", `商店-AD-购买钻石`); gg.data.setStatistics(StatisticsType.ShopBuyItemAdCount, count - 1) //gg.data.addItemNum(ItemNumType.diamond, this.freeDiamondNum); let itemsArray = [] let id = 3//钻石 let item = new ItemData(id, this.freeDiamondNum) item.num = this.freeDiamondNum item.id = id itemsArray.push(item) gg.data.addDayTaskProgressData(TaskType.shopBuyZuanshi, 1) gg.ui.openPanel(UIID.GetReward, { data: itemsArray }); this.refreshFirstShopitem() } else { // 视频播放失败 gg.ui.showToast('购买失败') } }) } } } buyItemClick(event, data) { gg.audio.playEffect({ name: "点击音效" }); //4 购买物品 // let shopData = { // itemIndex:i, // suipianId:suipianId, // goodId:goodId, // zhekouNum:zhekouNum, // buyType:shopItemData.type, // buyPrice:Math.floor(shopItemData.price*zhekouNum/10), // buyNum:shopItemData.quantity // } let target = event.target gg.ui.openPanel(UIID.buyItemBox, { data: [ target.itemIndex, target.suipianId, target.goodId, target.zhekouNum, target.buyType, target.buyPrice, target.buyNum ] }) } buyBoxFreeAdClick(event, data) { gg.audio.playEffect({ name: "点击音效" }); //1 高级宝箱和2稀有宝箱 免费购买金币 //console.log('免费购买金币',data); gg.sdk.showVideoAd((res) => { if (res) { gg.targetTaskManager.statisticalData(TargetTaskType.openBox, 1); gg.sdk.reportDY("inLevel", `商店-AD-购买宝箱` + data); let freeSpendNum = gg.data.getStatistics(StatisticsType.FreeBoxCount) let exp = gg.data.getStatistics(StatisticsType.FreeBoxExp) if (data == '高级') { //高级宝箱 gg.data.setStatistics(StatisticsType.FreeBoxCount, freeSpendNum + 1) gg.data.setStatistics(StatisticsType.FreeBoxExp, exp + this.gaojiBoxSpendNum) let boxLevelData = gg.data.getCurBoxLevelData(1); //console.log('高级宝箱等级数据',boxLevelData); let boxRewardArray = gg.data.getBoxRewardArray(boxLevelData) let statsArray = MTools.mergeToStatsArray(boxRewardArray) this.openBox(statsArray, boxLevelData.amount, 'blue') gg.data.addDayTaskProgressData(TaskType.boxOpenGaoji, 1) } else if (data == '稀有') { //稀有宝箱 gg.data.setStatistics(StatisticsType.FreeBoxCount, freeSpendNum + 2) gg.data.setStatistics(StatisticsType.FreeBoxExp, exp + this.xiyouBoxSpendNum) let boxLevelData = gg.data.getCurBoxLevelData(2); //4,50:5,16 let boxRewardArray = gg.data.getBoxRewardArray(boxLevelData) let statsArray = MTools.mergeToStatsArray(boxRewardArray) this.openBox(statsArray, boxLevelData.amount, 'red') gg.data.addDayTaskProgressData(TaskType.boxOpenCommon, 1) //console.log('稀有宝箱等级数据',boxLevelData); } this.showBoxNode() //打开宝箱 fix me //console.log('打开宝箱',data); } else { // 视频播放失败 // 提示用户 gg.ui.showToast("观看视频失败"); } }); } //花钻石购买宝箱 buyBoxDiamondClick(event, data) { gg.audio.playEffect({ name: "点击音效" }); //3 普通宝箱 花钻石购买 //console.log('花钻石购买宝箱',data); let myDiamondNum = gg.data.getDiamond(); let spendNum = 0 if (data == '高级') { spendNum = this.gaojiBoxSpendNum } else if (data == '稀有') { spendNum = this.xiyouBoxSpendNum } if (myDiamondNum < spendNum) { //钻石不足 gg.ui.showToast("钻石不足"); //console.log('钻石不足'); return; } //gg.data.setItemNum(ItemNumType.diamond, 100) //购买成功, 扣除钻石 gg.data.subDiamond(spendNum); //打开宝箱 gg.targetTaskManager.statisticalData(TargetTaskType.openBox, 1); let exp = gg.data.getStatistics(StatisticsType.FreeBoxExp) if (data == '高级') { gg.sdk.reportDY("inLevel", `商店-购买高级宝箱`) gg.data.setStatistics(StatisticsType.FreeBoxExp, exp + this.gaojiBoxSpendNum) let boxLevelData = gg.data.getCurBoxLevelData(1); //console.log('高级宝箱等级数据',boxLevelData); let boxRewardArray = gg.data.getBoxRewardArray(boxLevelData) let statsArray = MTools.mergeToStatsArray(boxRewardArray) this.openBox(statsArray, boxLevelData.amount, 'blue') gg.data.addDayTaskProgressData(TaskType.boxOpenGaoji, 1) //开始 } else if (data == '稀有') { gg.sdk.reportDY("inLevel", `商店-购买稀有宝箱`) gg.data.setStatistics(StatisticsType.FreeBoxExp, exp + this.xiyouBoxSpendNum) let boxLevelData = gg.data.getCurBoxLevelData(2); //console.log('稀有宝箱等级数据',boxLevelData); let boxRewardArray = gg.data.getBoxRewardArray(boxLevelData) let statsArray = MTools.mergeToStatsArray(boxRewardArray) this.openBox(statsArray, boxLevelData.amount, 'red') gg.data.addDayTaskProgressData(TaskType.boxOpenCommon, 1) } this.showBoxNode() //console.log('打开宝箱',data); } //打开宝箱 openBox(statsArray, amount, skin) { gg.audio.playEffect({ name: "开宝箱" }); let mengban = this.node.getChildByName("箱子蒙版") let xiangzi = this.node.getChildByName("箱子") mengban.active = true xiangzi.active = true xiangzi.getComponent(sp.Skeleton).setSkin(skin) xiangzi.getComponent(sp.Skeleton).setAnimation(0, 'play', false) this.scheduleOnce(() => { xiangzi.getComponent(sp.Skeleton).setAnimation(0, 'idle2', true) }, 1.0) this.scheduleOnce(() => { mengban.active = false xiangzi.active = false let itemsArray = [] // for (let i = 0; i < statsArray.length; i++) { let array = statsArray[i].split('|') let item = new ItemData(Number(array[0]), Number(array[1])) item.num = Number(array[1]) item.id = Number(array[0]) itemsArray.push(item) } let id = 1//钱 let item = new ItemData(id, amount) item.num = amount item.id = id itemsArray.push(item) gg.ui.openPanel(UIID.GetReward, { data: itemsArray, onClose: () => { } }); }, 1.1) //固定金币奖励amount //console.log('打开宝箱',statsArray); //预加载GetReward //箱子蒙版 } //免费购买金币 freeBuyGoldBtnClick(event, data) { gg.audio.playEffect({ name: "点击音效" }); //免费购金币 看视频购买金币 let dataNum = Number(data) //console.log('免费购金币或者看视频购买金币'); let goldNum = this.goldNumArray[dataNum]; let spendNum = this.spendNumArray[dataNum]; let myDiamondNum = gg.data.getDiamond(); if (dataNum == 0) { //免费购金币 let freeSpendNum = gg.data.getStatistics(StatisticsType.ShopBuyGoldAdCount) let buyGoldShareCount = gg.data.getStatistics(StatisticsType.BuyGoldShareCount) if (freeSpendNum == 6) { gg.sdk.reportDY("inLevel", `商店-免费获取金币`) //免费 //免费购买金币 //gg.data.addItemNum(ItemNumType.money, goldNum); this.showGoldView(goldNum) //更新免费购买次数 gg.data.setStatistics(StatisticsType.ShopBuyGoldAdCount, freeSpendNum - 1); //更新显示 gg.data.addDayTaskProgressData(TaskType.shopBuyGold, 1) this.showGoldNode(); } else if (buyGoldShareCount == 0) { //分享购买 gg.sdk.reportDY("inLevel", `商店-分享购买金币`) //分享购买金币 gg.sdk.share(2, (res) => { if (res) { gg.sdk.reportDY("inLevel", `商店-AD-看视频购买金币`); this.showGoldView(goldNum) //更新免费购买次数 gg.data.setStatistics(StatisticsType.BuyGoldShareCount, 1) //更新显示 this.showGoldNode(); gg.data.addDayTaskProgressData(TaskType.gameShare, 1) gg.data.addDayTaskProgressData(TaskType.shopBuyGold, 1) } else { gg.ui.showToast("观看视频失败"); } }) } else { //看视频购买 gg.sdk.showVideoAd((res) => { if (res) { gg.sdk.reportDY("inLevel", `商店-AD-看视频购买金币`); this.showGoldView(goldNum) //更新免费购买次数 gg.data.setStatistics(StatisticsType.ShopBuyGoldAdCount, freeSpendNum - 1); //更新显示 this.showGoldNode(); gg.data.addDayTaskProgressData(TaskType.shopBuyGold, 1) } else { gg.ui.showToast("观看视频失败"); } }); } } else if (dataNum == 1) { //一袋金币 if (myDiamondNum < spendNum) { //钻石不足 gg.ui.showToast("钻石不足"); //console.log('钻石不足'); return; } //gg.data.setItemNum(ItemNumType.diamond, 100) //购买成功, 扣除钻石 gg.data.subDiamond(spendNum); //购买成功, 增加金币 //gg.data.addItemNum(ItemNumType.money, goldNum); this.showGoldView(goldNum) //更新显示 //this.showGoldNode(); gg.data.addDayTaskProgressData(TaskType.shopBuyGold, 1) gg.sdk.reportDY("inLevel", `商店-500钻购买金币`) } else if (dataNum == 2) { //一堆金币 if (myDiamondNum < spendNum) { //钻石不足 gg.ui.showToast("钻石不足"); //console.log('钻石不足'); return; } //gg.data.setItemNum(ItemNumType.diamond, 100) //购买成功, 扣除钻石 gg.data.subDiamond(spendNum); //购买成功, 增加金币 //gg.data.addItemNum(ItemNumType.money, goldNum); this.showGoldView(goldNum) //更新显示 gg.data.addDayTaskProgressData(TaskType.shopBuyGold, 1) //this.showGoldNode(); gg.sdk.reportDY("inLevel", `商店-1500钻购买金币`) } } showGoldView(goldNum) { let itemsArray = [] let id = 1//jinbi let item = new ItemData(id, goldNum) item.num = goldNum item.id = id itemsArray.push(item) gg.ui.openPanel(UIID.GetReward, { data: itemsArray }); } scorllViewEvent() { //超出范围的隐藏不然就显示 } refreshItemBtnClick() { gg.audio.playEffect({ name: "点击音效" }); //刷新物品框 gg.sdk.showVideoAd((res) => { if (res) { gg.sdk.reportDY("inLevel", `商店-AD-刷新物品框`); //刷新物品框 let shopItemList = gg.data.getShopItemList() this.showShopItem() } else { gg.ui.showToast("观看视频失败"); } }) } opneLevelUpBoxDetail() { //打开升级宝箱详情 gg.ui.openPanel(UIID.boxLevelupDetail); } }