// Learn TypeScript: // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html // Learn Attribute: // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html import { MONEY_TYPE } from "../datas/CommonData"; import TreasureData from "../datas/TreasureData"; import AdM from "../manager/AdM"; import GameM, { AUDIO_TYPE, VIDEO_TYPE } from "../manager/GameM"; import GuideMng from "../manager/GuideMng"; import UiM, { PANEL_NAME } from "../manager/UiM"; import TreaRecordItem from "../prefabs/TreaRecordItem"; import TreasureItem from "../prefabs/TreasureItem"; import { PlayerPrefs } from "../tools/MyExtends"; import LogUtil from "../utils/LogUtil"; import Sciencen_M from "../utils/Sciencen_M"; import { Utils } from "../utils/Utils"; import EffectNode from "./EffectNode"; import Gift from "./Gift"; import Guide from "./Guide"; import RedCodeNode from "./RedCodeNode"; const { ccclass, property } = cc._decorator; @ccclass export default class Treasure extends cc.Component { @property(cc.Label) labGetGold: cc.Label = null; @property(cc.Label) labTicket: cc.Label = null; @property(cc.Label) labLeftTimes: cc.Label = null; @property(cc.Node) scNode: cc.Node = null; @property(cc.Node) viewNode: cc.Node = null; @property(cc.Node) content: cc.Node = null; //--弹窗 @property(cc.Node) resultPart: cc.Node = null; @property(cc.Label) labIssue: cc.Label = null; @property(cc.Label) labAwardMoney: cc.Label = null; @property(cc.Label) labNickName: cc.Label = null; @property(cc.Node) btnState: cc.Node = null; @property(cc.Label) labState: cc.Label = null; @property(cc.Sprite) spHead: cc.Sprite = null; @property(cc.Node) spFail: cc.Node = null; @property(cc.Node) spSuccess: cc.Node = null; //提现成功 @property(cc.Node) loadPart: cc.Node = null; @property(cc.Animation) loadAni: cc.Animation = null; @property(cc.Node) cashPro: cc.Node = null; @property(cc.Label) labMoney1: cc.Label = null; //--记录 @property(cc.Label) labRTitle: cc.Label = null; @property(cc.Node) recordPart: cc.Node = null; @property(cc.Node) recordContent: cc.Node = null; //--帮助 @property(cc.Node) helpPart: cc.Node = null; @property(cc.Label) labTimes: cc.Label = null; @property(cc.RichText) LabScroll: cc.RichText = null @property(cc.Node) qipaoOne: cc.Node = null @property(cc.Node) qipaoSec: cc.Node = null @property(cc.Node) rewardBgNode: cc.Node = null @property(cc.Node) guideRect1: cc.Node = null; //当前弹窗状态 0 参加下一期 1 提现 2 过期 curResultState = 0 roledata = null cfg = null //分帧加载 addNum = 0 addTotal = 0 //刷新现金夺宝间隔 treasureDis = 0 _n = 0 _dis = 5 itemP = null //看视频获得金币数量 private getGoldNum: string = '' //开奖记录 recordList = [] private reAddNum = 0 private reAddTotal = 0 _ren = 0 _redis = 5 reItemP = null curLotteryResult = null private addY = 0 private lastTicket = 0 //获奖信息滚动播出,每次进夺宝,随机取一个档位的获奖记录显示 private recordScroll: Array = null //滚动信息下标 count = 0 //滚动信息的获奖金额 scrollAmount = 0 // LIFE-CYCLE CALLBACKS: async onLoad() { this.node.height = cc.winSize.height this.addY = cc.winSize.height - 1334 this.itemP = await Utils.loadResPromise('prefabs/TreasureItem') this.reItemP = await Utils.loadResPromise('prefabs/TreaRecordItem') this.roledata = GameM.commonData.roleData this.schedule(this.updateOpenTime, 3) if (!TreasureData.Instance.treasureData) { TreasureData.Instance.getTreasureData() } else { this.onGetTreasureData() } this.getPopResult() this.scNode.height += this.addY this.viewNode.height += this.addY LogUtil.logV("TreasureData.Instance.treasureDailyTimes zero", TreasureData.Instance.treasureDailyTimes) this.freshLimitLab() TreasureData.Instance.getDailyLimit() this.rewardBgNode.y += this.addY / 2 } onDisable() { this.unschedule(this.updateOpenTime) } /** */ onEnable() { // let guide = UiM.Instance.guideNode.getComponent(Guide); // if (guide.treasureStep1.active) { // guide.hideTreasureStep1(); // } //西游 夺宝引导 第一次进入夺宝界面 this.scheduleOnce(() => { GuideMng.Ins.CheckTreasureGuide13(); this.guideRect1.active = GuideMng.Ins.CurGuideId == 13; }, 0.1); } updateOpenTime() { TreasureData.Instance.treasureOpenTime += 3 } /** 获取服务器数据返回 * 数据 name 开奖名字 * phase 开奖期数 * joinManInfoQueue 参加者队列 * limitMan 个人参加次数 * joinTimes 个人参加次数 * joinTotal 参加总人数 */ onGetTreasureData() { this.cfg = TreasureData.Instance.treasureCfg this.addTotal = TreasureData.Instance.treasureData.length this.addNum = 0 this.lastTicket = GameM.commonData.roleData.ticket this.refreshLabs() // this.checkTreasureTimer() this.getShowScrollReward() } /** 单条数据 */ freshTreasureDataOne(hasOpen, data) { let item = this.content.getChildByName(data.drawid) item.getComponent(TreasureItem).onFreshServerData(hasOpen, data) } start() { LogUtil.logV("Treasure", " start ") } update() { if (this.addNum < this.addTotal) { if (this._n <= this._dis) { this._n++ } else { this._n = 0 let item: cc.Node = cc.instantiate(this.itemP) let curCfg = this.cfg[this.addNum] item.name = (curCfg.drawid).toString() let s = item.getComponent(TreasureItem) s.init(curCfg) this.content.addChild(item) // this.content.height = this.addTotal * (item.height + 10) this.addNum++ } } if (this.recordPart.active) { if (this.reAddNum < this.reAddTotal) { if (this._ren <= this._redis) { this._ren++ } else { this._ren = 0 let item: cc.Node = cc.instantiate(this.reItemP) let s = item.getComponent(TreaRecordItem) s.init(this.recordList[this.reAddNum]) this.recordContent.addChild(item) // this.content.height = this.addTotal * (item.height + 10) this.reAddNum++ } } } } refreshLabs() { this.labTimes.string = `5、每人每天最多只能参加${GameM.commonData.globalCfg.treasureDailylimit}次现金夺宝` this.labTicket.string = this.roledata.ticket.toString() let videoPrice = GameM.commonData.buyNumCfg[(GameM.commonData.buyTimeTotal + 1).toString()].gold; let percent = 0.1 this.getGoldNum = Sciencen_M.instance.accMul(videoPrice, percent.toString()) let str = Sciencen_M.instance.format(this.getGoldNum) this.labGetGold.string = str //`观看视频必得${str}金币奖励,并额外赠送夺宝券` } // /** 刷新为index的item */ // refreshItem(index) { // let item = this.content.getChildByName(index.toString()) // if (item) { // let s = item.getComponent(TreasureItem) // s.refresh() // } // } // /** 检查是否更新现金夺宝消息 */ // checkTreasureTimer() { // if (GameM.commonData.roleData.treasureDayNum != [] || UiM.Instance.treasureNode) { // this.treasureDis = 0 // this.startTreasureTimer() // } // else { // this.unschedule(this.freshTreasure) // } // } // /** 刷新夺宝时间 */ // startTreasureTimer() { // this.schedule(this.freshTreasure, 10) // } // freshTreasure() { // this.treasureDis++ // if (GameM.commonData.roleData.treasureDayNum != []) { // } // if (UiM.Instance.treasureNode) { // //刷新界面 // } // } clickGetTicket() { GameM.audioM.playEffect(AUDIO_TYPE.button) this.showVideoTip() // this.showVideoTip() // if (GameM.commonData.isVideoTest) { // this.onGetTicketAdEnd() // } // else { // GameM.adM.watchVideo(VIDEO_TYPE.getTicket) // } } showVideoTip() { // this.videoTip.active= true // if (GameM.commonData.isVideoTest) { // this.onGetTicketAdEnd() // } // else { // GameM.adM.watchVideo(VIDEO_TYPE.getTicket) UiM.Instance.giftNode.active = true let gift = UiM.Instance.giftNode.getComponent(Gift) gift.init(MONEY_TYPE.treasureTicket, this.getGoldNum) // } } watchVideo() { if (GameM.commonData.isVideoTest) { this.onGetTicketAdEnd() } else { GameM.adM.watchVideo(VIDEO_TYPE.getTicket) } } freshVideo() { this.content.children.forEach(element => { let s = element.getComponent(TreasureItem) s.freshVideo() }); } onGetTicketAdEnd() { LogUtil.logV(" onGetTicketAdEndt", "start") // this.roledata.ticket++ GameM.commonData.updateRoleData() if (this.lastTicket == 0) { this.freshVideo() } this.lastTicket = this.roledata.ticket // GameM.audioM.playEffect(AUDIO_TYPE.getGold, false) // EffectNode.instance.PlayCoinAnim(0, 20, cc.v2(0, -300)) let str = Sciencen_M.instance.format(this.getGoldNum) this.refreshLabs() } clickClose() { GameM.audioM.playEffect(AUDIO_TYPE.button) this.content.destroyAllChildren() UiM.Instance.offPanel(PANEL_NAME.TreasureNode, false, () => { AdM.createInter(17) }) } freshLimitLab() { let leftTimes = GameM.commonData.globalCfg.treasureDailylimit - TreasureData.Instance.treasureDailyTimes if (leftTimes < 0) { leftTimes = 0 } this.labLeftTimes.string = `今日剩余夺宝次数:${leftTimes}` } //-----resultPart /** 界面打开获取弹出数组 */ getPopResult() { TreasureData.Instance.getLotteryresults() } /** 显示开奖结果界面 */ showResult() { this.curLotteryResult = TreasureData.Instance.getCurLotteryresult() if (this.curLotteryResult) { this.resultPart.active = true cc.loader.load(this.curLotteryResult.headimgurl + "?aaa=aa.jpg", (err, res) => { if (err) { console.log('err:', err); return; } let tex: cc.Texture2D = res as cc.Texture2D; this.spHead.spriteFrame = new cc.SpriteFrame(tex); }) this.labIssue.string = `现金夺宝第${this.curLotteryResult.phase}期` let money = this.curLotteryResult.amount / 100 this.labAwardMoney.string = `¥${money.toFixed(2)}` this.labNickName.string = `${this.curLotteryResult.nikeName}` if (!this.curLotteryResult.isWin) { this.labState.string = '参加下一期' this.btnState.active = true this.curResultState = 0 this.spFail.active = false this.spSuccess.active = false //发送消息弹过窗了 this.curLotteryResult.isNotice = true TreasureData.Instance.updateLottery(this.curLotteryResult.recordId) } else { if (GameM.commonData.gameTime * 0.001 < this.curLotteryResult.outTime) { this.labState.string = '提现' this.btnState.active = true this.curResultState = 1 this.spFail.active = false this.spSuccess.active = true } else { this.spFail.active = true this.spSuccess.active = false this.btnState.active = false this.curResultState = 2 //发送消息弹过窗了 this.curLotteryResult.isNotice = true TreasureData.Instance.updateLottery(this.curLotteryResult.recordId) } } } } /** 下一个开奖结果 */ nextResult() { this.resultPart.active = false this.scheduleOnce(() => { //检查是否有下一个数据 this.showResult() }, 1) } clickCloseResult() { GameM.audioM.playEffect(AUDIO_TYPE.button) this.resultPart.active = false this.nextResult() } clickBtnState() { GameM.audioM.playEffect(AUDIO_TYPE.button) if (this.curResultState == 0) { this.nextResult() } else if (this.curResultState == 1) { //调用提现接口 let money = this.curLotteryResult.amount / 100 TreasureData.Instance.luckycash(this.curLotteryResult.recordId, money) this.loadPart.active = true this.loadAni.play('load', 0) } } resultLuckycash(showPro) { //发送消息弹过窗了 this.curLotteryResult.isNotice = true TreasureData.Instance.updateLottery(this.curLotteryResult.recordId) this.scheduleOnce(() => { this.loadPart.active = false this.showCashPro(showPro) }, 1.5) } tixianFail() { this.scheduleOnce(() => { this.loadPart.active = false this.nextResult() }, 1.5) } showCashPro(showPro) { if (showPro) { UiM.Instance.openPanel(this.cashPro) } let money = this.curLotteryResult.amount / 100 this.labMoney1.string = `¥${money.toFixed(2)}` } clickClosePro() { GameM.audioM.playEffect(AUDIO_TYPE.button) UiM.Instance.closePanelM() this.nextResult() } //------recordPart showRecord(id, amount) { TreasureData.Instance.getLuckyLottery(id) this.labRTitle.string = `${(amount / 100).toFixed(2)}元开奖记录` } onShowRecord(data) { this.recordPart.active = true this.recordList = data this.reAddTotal = this.recordList.length this.reAddNum = 0 } getShowScrollReward() { LogUtil.logV("getShowScrollReward", "start") // let tempArr = new Array() // for (let i = 0; i < this.cfg.length; i++) { // if (this.cfg[i].amount >= 50) { // tempArr.push(this.cfg[i]) // } // } // LogUtil.logV("getShowScrollReward", "one") // tempArr = tempArr.sort((a, b) => { // return Math.random() - 0.5 // }) // LogUtil.logV("getShowScrollReward", "two") // let tempInfo = tempArr[0] // this.scrollAmount = tempInfo.amount // LogUtil.logV("getShowScrollReward", tempInfo.drawid) TreasureData.Instance.getRandomLottery() } showScrollInfo(data) { LogUtil.logV("showScrollInfo", "one") this.recordScroll = data this.startScrollInfo() } startScrollInfo() { LogUtil.logV("startScrollInfo", "one") if (this.recordScroll == null || this.recordScroll == undefined || this.recordScroll.length == 0) { LogUtil.logV("startScrollInfo", "null") return } LogUtil.logV("startScrollInfo", this.recordScroll.length + "two") if (this.count == this.recordScroll.length - 1) { this.count = 0 } else { this.count++ } let info = this.recordScroll[this.count] let name = info.nickname let money = info.amount / 100 let str = `恭喜 “${name}” 获得 “${money.toFixed(2)}” 元` this.LabScroll.string = str this.LabScroll.node.position = cc.v3(0, -55) this.LabScroll.node.runAction(cc.sequence(cc.moveTo(0.3, cc.v2(0, 0)), cc.delayTime(2), cc.moveTo(0.3, cc.v2(0, 55)), cc.callFunc(() => { this.startScrollInfo() }))) } clickCloseRecord() { GameM.audioM.playEffect(AUDIO_TYPE.button) this.recordPart.active = false this.recordContent.removeAllChildren() } //------helpPart clickOpenHelp() { GameM.audioM.playEffect(AUDIO_TYPE.button) this.helpPart.active = true } clickCloseHelp() { GameM.audioM.playEffect(AUDIO_TYPE.button) this.helpPart.active = false } clickIconShowTipOne() { this.qipaoOne.active = true this.scheduleOnce(() => { if (cc.isValid(this.qipaoOne)) { this.qipaoOne.active = false } }, 2) } clickIconShowTipSec() { this.qipaoSec.active = true this.scheduleOnce(() => { if (cc.isValid(this.qipaoSec)) { this.qipaoSec.active = false } }, 2) } clickRedCode() { GameM.audioM.playEffect(AUDIO_TYPE.button) UiM.Instance.onPanel(PANEL_NAME.RedCodeNode, false, () => { UiM.Instance.redCodeNode.getComponent(RedCodeNode).init(3) }) } //西游 隐藏guideRect按钮 Click_GuideRectBtn() { this.guideRect1.active = false; } }