import BankData from "../datas/BankData"; import { HTTP_TYPE } from "../datas/CommonData"; import Main from "../Main"; import AdM from "../manager/AdM"; import GameM, { AUDIO_TYPE } from "../manager/GameM"; import UiM, { PANEL_NAME } from "../manager/UiM"; import MoneySaveItem from "../prefabs/MoneySaveItem"; import LogUtil from "../utils/LogUtil"; import { Utils } from "../utils/Utils"; import EffectNode from "./EffectNode"; import RedCodeNode from "./RedCodeNode"; const { ccclass, property } = cc._decorator; @ccclass export default class SafeDepositBox extends cc.Component { @property(cc.Node) content: cc.Node = null @property(cc.Label) totalMoneyLabel: cc.Label = null @property(cc.Label) readyTixianLabel: cc.Label = null @property(cc.Button) readyTixianBtn: cc.Button = null @property(cc.Node) weitixianNode: cc.Node = null @property(cc.Node) tixianzhongNode: cc.Node = null @property(cc.Label) tixianzhongMoneyLabel: cc.Label = null @property(cc.Node) confirmTixianNode: cc.Node = null @property(cc.Node) saveNode: cc.Node = null @property(cc.Node) tixianTask: cc.Node = null @property(cc.RichText) loginProgress: cc.RichText = null @property(cc.RichText) playVideoProgress: cc.RichText = null @property(cc.Label) tipLogin: cc.Label = null @property(cc.Label) tipPlayVideo: cc.Label = null @property(cc.Node) safeBox: cc.Node = null @property(cc.Node) tipNode: cc.Node = null @property(cc.Node) completeNode: cc.Node = null @property(cc.Node) inCompleteNode: cc.Node = null @property(cc.Node) completeBtn: cc.Node = null @property(cc.Node) logDaysNode: cc.Node = null @property(cc.Node) videoTimesNode: cc.Node = null @property(cc.Node) saveSuccessNode: cc.Node = null @property(cc.Label) confirmMoneyLabel: cc.Label = null @property([cc.SpriteFrame]) boxSfLsit: cc.SpriteFrame[] = [] @property(cc.Sprite) boxSprite: cc.Sprite = null @property(cc.Node) ruleNode: cc.Node = null @property(cc.Node) boxNode: cc.Node = null @property(sp.Skeleton) openDraw: sp.Skeleton = null @property([cc.Node]) taskStartNodeList: cc.Node[] = [] @property(cc.Node) noPacketTip: cc.Node = null // 提现部分 @property(cc.Node) tixianNode: cc.Node = null @property(cc.Label) labRedMoneyF: cc.Label = null @property(cc.Label) labMoeny: cc.Label = null @property(cc.Node) cashPro: cc.Node = null @property(cc.Node) loadPart: cc.Node = null @property(cc.Animation) spot1: cc.Animation = null @property(cc.Button) startLingquBtn: cc.Button = null @property(cc.Label) rulelabel: cc.Label = null @property([cc.SpriteFrame]) spriteFrameList: cc.SpriteFrame[] = [] @property(cc.Node) labRedCode: cc.Node = null addNum = 0 addTotal = 0 itemP = null _n = 0 _dis = 5 animNode: cc.Node = null private totalMoney = 0 private startTixian: number = 0 private data: Array = null private test = false nodePos = [cc.v3(54, -63), cc.v3(313, 57), cc.v3(572, -67), cc.v3(862, -67)] private packet = [{ "amount": 30, "isSaveBank": 0, "partnerTradeNo": "a", "cashType": 1 }, { "amount": 500, "isSaveBank": 0, "partnerTradeNo": "a", "cashType": 1 }, { "amount": 600, "isSaveBank": 0, "partnerTradeNo": "a", "cashType": 1 }] // LIFE-CYCLE CALLBACKS: async onLoad() { this.itemP = await Utils.loadResPromise('prefabs/MoneySaveItem') } start() { // GameM.httpM.sendDatas(HTTP_TYPE.backIsOpenRichBank, {}) if (!this.test) { GameM.httpM.sendDatas(HTTP_TYPE.bankCashRecord, null, GameM.commonData.updateBankPacket.bind(GameM.commonData)) } // let isShowGuide = cc.sys.localStorage.getItem("bankGuideStep1") // if (isShowGuide == "true") { // UiM.Instance.guideNode.getComponent(Guide).bankGuideStep2() // } if (this.test) { // this.scheduleOnce(() => { // CommonData.Instance.updateBankPacket(this.packet) this.updateScrollView(this.packet) // }, 1) } BankData.Instance.getRichBankConfig(this.initView.bind(this)) // BankData.Instance.getCurrentCashTaskInfo(null) } clickClose() { GameM.audioM.playEffect(AUDIO_TYPE.button) let main = UiM.Instance.hallNode.getComponent(Main) let pos1 = main.bankBtn.node.position if (cc.winSize.height > 1500) { pos1.y = pos1.y + 45 } // pos1.y = pos1.y + 30 // let pos2 = main..position // let pos = cc.v2(pos1.x, pos1.y + pos2.y) let parNode = this.node.getChildByName("Par") cc.tween(parNode).to(0.2, { scale: 0, position: pos1 }).call(() => { UiM.Instance.offPanel(PANEL_NAME.SafeDepositBox) }).start(); // UiM.Instance.offPanel(PANEL_NAME.SafeDepositBox) } initView(showStep = false) { let money: number = GameM.commonData.richBankCashAmount if (money == null || undefined) { money = 0 } this.startTixian = GameM.commonData.currentRichBankCashTaskIndex if (this.startTixian > 0) { if (this.test) { this.weitixianNode.active = false this.tixianzhongNode.active = true let config = this.getBankTaskIndex() this.tixianzhongMoneyLabel.string = (config.money * 0.01).toFixed(2) + "元" this.readyTixianLabel.node.active = false this.tixianzhongNode.getChildByName("tixianLabel").active = true this.tixianTask.active = true this.labRedCode.active = false this.saveNode.active = true this.setTaskProgress() this.boxSprite.spriteFrame = this.boxSfLsit[1] if (showStep) { this.showInfoByStep() } this.noPacketTip.getChildByName("taskLabel").active = GameM.commonData.currentRichBankCashTaskIndex > 0 this.noPacketTip.getChildByName("noTaskLabel").active = !(GameM.commonData.currentRichBankCashTaskIndex > 0) } else { BankData.Instance.getCurrentCashTaskInfo(() => { this.weitixianNode.active = false this.tixianzhongNode.active = true let config = this.getBankTaskIndex() this.tixianzhongMoneyLabel.string = (config.money * 0.01).toFixed(2) + "元" this.readyTixianLabel.node.active = false this.tixianzhongNode.getChildByName("tixianLabel").active = true this.tixianTask.active = true this.labRedCode.active = false this.saveNode.active = true this.setTaskProgress() this.boxSprite.spriteFrame = this.boxSfLsit[1] if (showStep) { this.showInfoByStep() } this.noPacketTip.getChildByName("taskLabel").active = GameM.commonData.currentRichBankCashTaskIndex > 0 this.noPacketTip.getChildByName("noTaskLabel").active = !(GameM.commonData.currentRichBankCashTaskIndex > 0) }) } } else { this.tixianzhongNode.active = false this.weitixianNode.active = true this.readyTixianLabel.node.active = true this.totalMoneyLabel.string = (money * 0.01).toFixed(2) + "元" this.content.active = true this.tixianTask.active = false this.labRedCode.active = true this.saveNode.active = true this.completeBtn.active = false this.checkCurrentCanStartTask(money) this.boxSprite.spriteFrame = this.boxSfLsit[0] } } updateScrollView(data) { LogUtil.logV("updateScrollView", data) this.content.destroyAllChildren() if (data == null || data == undefined) { this.showNoPacket() return } if (!(data.length > 0)) { this.showNoPacket() return } this.noPacketTip.active = false this.noPacketTip.stopAllActions() this.noPacketTip.position = cc.v3(324, -10) // data.push(data[0]) // data.push(data[0]) // data.push(data[0]) // data.push(data[0]) let count = 0 let startTixian = GameM.commonData.currentRichBankCashTaskIndex let showFinger: boolean = startTixian > 0 for (let entry of data) { if (entry.isSaveBank != 0) { continue } count++ if (count > 5) { break } let info = entry if (info == null || info == undefined) { break } let item: cc.Node = cc.instantiate(this.itemP) let s = item.getComponent(MoneySaveItem) item.parent = this.content s.init(info, showFinger, this.clickItemEvent.bind(this), count) // item.y = - item.height * 0.5*1.5 // - this.disY * this.addNum } } //将提现金额放入保险箱 clickItemEvent(data, node) { GameM.audioM.playEffect(AUDIO_TYPE.button); if (GameM.commonData.currentRichBankCashTaskIndex > 0) { EffectNode.instance.PlayTip("提现后可存入") return } this.animNode = node // this.showAnim(node) if (this.test) { GameM.commonData.richBankCashAmount = GameM.commonData.richBankCashAmount + data.amount GameM.commonData.updateBankView({ "RichBankCashAmount": data.amount }) // this.saveMoneySuccess(CommonData.Instance.richBankCashAmount) } else { GameM.httpM.sendDatas(HTTP_TYPE.bankUpdateCashRecord, { "partnerTradeNo": data.partnerTradeNo }, GameM.commonData.updateBankView.bind(GameM.commonData)) } } saveMoneySuccess(money) { AdM.onSendEvent("Bank_01", "钱庄-点击存入", 'Bank') this.showAnim(this.animNode) this.totalMoneyLabel.string = ((money * 0.01).toFixed(2)) + "元" this.checkCurrentCanStartTask(money) } // checkItemEvent() //存入宝箱中的数据和动画处理 showAnim(itemNode: cc.Node) { itemNode.stopAllActions() let startWorldPos = itemNode.parent.convertToWorldSpaceAR(itemNode.position) let startPos = this.node.convertToNodeSpaceAR(startWorldPos) let worldEndPos = this.safeBox.parent.convertToWorldSpaceAR(this.safeBox.position) itemNode.parent = this.node itemNode.position = startPos let movePos = this.node.convertToNodeSpaceAR(worldEndPos) itemNode.runAction(cc.sequence(cc.spawn(cc.moveTo(1, cc.v2(movePos)), cc.scaleTo(1, 0.4), cc.fadeTo(1, 180)), cc.callFunc(() => { GameM.audioM.playEffect(AUDIO_TYPE.saveSuccess); this.openDraw.node.active = true this.openDraw.setAnimation(0, 'animation', false) this.saveSuccessNode.runAction(cc.sequence(cc.scaleTo(0.2, 1), cc.delayTime(0.5), cc.scaleTo(0.1, 0))) if (cc.isValid(itemNode)) { itemNode.destroy() } if (this.test) { this.updateScrollView(this.packet) } else { GameM.httpM.sendDatas(HTTP_TYPE.bankCashRecord, null, GameM.commonData.updateBankPacket.bind(GameM.commonData)) } }))) } //点提现按钮 readyTixian() { GameM.audioM.playEffect(AUDIO_TYPE.button) let configInfo = GameM.commonData.richBankConfig let richBankCashAmount = GameM.commonData.richBankCashAmount if (configInfo == null || configInfo == undefined) { return } let minConfig = this.getBankTaskIndex() let minMoney: number = minConfig.money // this.readyTixianBtn.interactable = money >= minMoney let showMoney = Math.floor(minMoney / 100) > 0 ? (minMoney / 100) + "" : (minMoney / 100).toFixed(2) if (richBankCashAmount < minMoney) { EffectNode.instance.PlayTip("存款达到" + showMoney + "元可提现哦") return } let currentConfig = this.getBankTaskIndex() // for (let entry of configInfo) { // if (entry.money <= richBankCashAmount) { // currentConfig = entry // } // } let totaldays = currentConfig.logintimes let totalVideoTimes = currentConfig.videotimes this.tipLogin.string = "1、连续登陆" + totaldays + "天" this.tipPlayVideo.string = "2、每天观看视频" + totalVideoTimes + "次" this.confirmMoneyLabel.string = Math.floor(currentConfig.money / 100) > 0 ? (currentConfig.money / 100) + "元" : (currentConfig.money / 100).toFixed(2) + "元" let y = this.boxNode.y let x = this.boxNode.x let delayTime = Math.random() this.scheduleOnce(() => { this.boxNode.runAction(cc.repeatForever(cc.sequence(cc.moveTo(1.5, cc.v2(x, y - 5)), cc.moveTo(1.2, cc.v2(x, this.node.y + 5))))) }, delayTime) this.confirmTixianNode.active = true this.saveNode.active = true this.content.active = false this.readyTixianLabel.node.active = false } //点开始任务 confirmStartTixian() { GameM.audioM.playEffect(AUDIO_TYPE.button) let config = this.getBankTaskIndex() if (!config) { LogUtil.logV("SafeDepositBox", "can not confirmStartTixian") return } this.confirmTixianNode.active = false this.boxNode.stopAllActions() this.boxNode.x = 161 this.boxNode.y = 0 this.content.active = true if (this.test) { GameM.commonData.updateBankTask(null, config.index) } else { GameM.httpM.sendDatas(HTTP_TYPE.bankOpenCashTask, { "index": config.index }, GameM.commonData.updateBankTask.bind(GameM.commonData)) } } startTixianTask() { this.startTixian = 1 this.totalMoneyLabel.string = (GameM.commonData.richBankCashAmount) + "元 提现中..." this.confirmTixianNode.active = false this.saveNode.active = true this.tixianTask.active = true this.labRedCode.active = false this.content.active = true this.readyTixianLabel.node.active = false } showCompleteNode() { cc.sys.localStorage.setItem("showBankTaskSuccess", Date.now() + "") this.tipNode.active = true this.tipNode.getChildByName("tipNode").active = true this.tipNode.getChildByName("tipNode").scale = 0; //1 // this.tipNode.getChildByName("tipNode").active = true this.completeNode.active = true this.inCompleteNode.active = false cc.tween(this.tipNode.getChildByName("tipNode")).to(0.3, { scale: 1 }, { easing: "backOut" }).start(); } showRestartTaskNode() { cc.sys.localStorage.setItem("showBankTaskRestart", Date.now() + "") this.tipNode.active = true this.tipNode.getChildByName("tipNode").active = true this.tipNode.getChildByName("tipNode").scale = 0; this.completeNode.active = false this.inCompleteNode.active = true cc.tween(this.tipNode.getChildByName("tipNode")).to(0.3, { scale: 1 }, { easing: "backOut" }).start(); AdM.onSendEvent("Bank_05", "钱庄-任务进度重置", 'Bank') } hideCompleteTipNode() { this.tipNode.active = false this.tipNode.getChildByName("tipNode").active = false } hideConfirmTixianNode() { GameM.audioM.playEffect(AUDIO_TYPE.button) this.confirmTixianNode.active = false this.saveNode.active = true this.content.active = true this.readyTixianLabel.node.active = true this.boxNode.stopAllActions() this.boxNode.x = 161 this.boxNode.y = 0 } //设置提现按钮状态 checkCurrentCanStartTask(money) { let configInfo = GameM.commonData.richBankConfig this.readyTixianLabel.string = "" if (configInfo == null || configInfo == undefined) { // this.readyTixianBtn.interactable = false this.readyTixianBtn.node.getComponent(cc.Sprite).spriteFrame = this.spriteFrameList[0] return } let outLine = this.readyTixianBtn.node.getChildByName("btnLabel").getComponent(cc.LabelOutline) let minConfig = this.getBankTaskIndex() let minMoney: number = minConfig.money // this.readyTixianBtn.interactable = money >= minMoney let showMoney = Math.floor(minMoney / 100) > 0 ? (minMoney / 100) + "" : (minMoney / 100).toFixed(2) if (money >= minMoney) { this.readyTixianBtn.node.getComponent(cc.Sprite).spriteFrame = this.spriteFrameList[0] this.readyTixianBtn.interactable = true outLine.color = cc.color(181, 140, 59) showMoney = Math.floor(minConfig.money / 100) > 0 ? (minConfig.money / 100) + "" : (minConfig.money / 100).toFixed(2) } else { this.readyTixianBtn.node.getComponent(cc.Sprite).spriteFrame = this.spriteFrameList[1] outLine.color = cc.Color.GRAY // this.readyTixianBtn.grayMaterial } this.readyTixianBtn.node.getChildByName("btnLabel").getComponent(cc.Label).string = "提现" + showMoney + "元" } /** * 检查在哪个段位 */ getBankTaskIndex(): any { LogUtil.logV("getBankTaskIndex addRichBankFinishIndex:", GameM.commonData.roleData.addRichBankFinishIndex) let configInfo = GameM.commonData.richBankConfig let richBankCashAmount = GameM.commonData.richBankCashAmount let currentConfig: any = null if (configInfo == null || configInfo == undefined) { return } let curIndex = GameM.commonData.roleData.addRichBankFinishIndex if (curIndex > configInfo.length) { return configInfo[configInfo.length - 1] } for (let entry of configInfo) { if (entry.index == curIndex) { return entry } } // for (let entry of configInfo) { // if (entry.money <= richBankCashAmount) { // currentConfig = entry // } // } // return currentConfig } clickLingqu() { GameM.audioM.playEffect(AUDIO_TYPE.button) let config = this.getBankTaskIndex() if (this.test) { GameM.commonData.updateBankCash({ "CashMode": 2, "withdrawalCode": "131231" }) } else { GameM.httpM.sendDatas(HTTP_TYPE.bankCash, { "index": config.index, 'appVersion': GameM.commonData.appVersion }, GameM.commonData.updateBankCash.bind(GameM.commonData), GameM.commonData.updateBankCashFail.bind(GameM.commonData)) this.loadPart.active = true this.spot1.play('load', 0) } } readyLingqu() { GameM.audioM.playEffect(AUDIO_TYPE.button) let config = this.getBankTaskIndex() // this.tixianNode.active = true UiM.Instance.openPanel(this.tixianNode) this.labRedMoneyF.string = "¥ " + (config.money * 0.01).toFixed(2) this.labMoeny.string = "¥" + (config.money * 0.01).toFixed(2) } tixianSuccess(showPro) { this.loadPart.active = false if (showPro) { this.cashPro.active = true UiM.Instance.openPanel(this.cashPro) } this.initView() this.startLingquBtn.interactable = false this.startLingquBtn.node.getComponent(cc.Animation).stop() this.startLingquBtn.node.getChildByName("labGet").getComponent(cc.Label).string = "已领取" } tixianFail() { this.loadPart.active = false this.cashPro.active = false // this.initView() // this.startLingquBtn.interactable = false // this.startLingquBtn.node.getComponent(cc.Animation).stop() // this.startLingquBtn.node.getChildByName("labGet").getComponent(cc.Label).string = "已领取" } hideTixianNode() { GameM.audioM.playEffect(AUDIO_TYPE.button) UiM.Instance.closePanelM() } closeTixianNode() { GameM.audioM.playEffect(AUDIO_TYPE.button) UiM.Instance.closePanelFromHome() UiM.Instance.closePanelFromHome() } setTaskProgress() { let richBankDailyVideoTimes = GameM.commonData.richBankDailyVideoTimes let richbank_logindays = GameM.commonData.richbank_logindays let totaldays = BankData.Instance.logintimes let progress = "(" + richbank_logindays + "/" + totaldays + ")" this.loginProgress.string = "1.连续登录" + totaldays + "天" + progress + "" if (richbank_logindays < totaldays) { this.logDaysNode.getChildByName("label").active = true this.logDaysNode.getChildByName("gou").active = false } else { this.logDaysNode.getChildByName("label").active = false this.logDaysNode.getChildByName("gou").active = true } let totalVideoTimes = BankData.Instance.videotimes let timeProgress = "(" + richBankDailyVideoTimes + "/" + totalVideoTimes + ")" this.playVideoProgress.string = "2.每天观看视频" + totalVideoTimes + "次" + timeProgress + "" if (richBankDailyVideoTimes < totalVideoTimes) {//没有完成视频次数 this.videoTimesNode.getChildByName("label").active = true this.videoTimesNode.getChildByName("label").getComponent(cc.Label).string = "进行中" this.videoTimesNode.getChildByName("label").color = cc.color(55, 139, 200) this.videoTimesNode.getChildByName("gou").active = false } else { if (richbank_logindays >= totaldays) { this.videoTimesNode.getChildByName("label").active = false this.videoTimesNode.getChildByName("gou").active = true } else { this.videoTimesNode.getChildByName("label").active = true this.videoTimesNode.getChildByName("label").getComponent(cc.Label).string = "今日已完成" this.videoTimesNode.getChildByName("label").color = cc.color(2, 224, 12) this.videoTimesNode.getChildByName("gou").active = false } } if (richbank_logindays >= totaldays && richBankDailyVideoTimes >= totalVideoTimes) { this.completeBtn.active = true this.tixianzhongNode.getChildByName("tixianLabel").active = false } else { this.completeBtn.active = false this.tixianzhongNode.getChildByName("tixianLabel").active = true } //提示完成任务 if (richBankDailyVideoTimes >= totalVideoTimes) { // totalVid let lastDateStr = cc.sys.localStorage.getItem("showBankTaskSuccess") if (lastDateStr != null && lastDateStr != undefined) { let lastDate = new Number(lastDateStr).valueOf() if (!this.checkSameDay(lastDate)) { this.scheduleOnce(() => { this.showCompleteNode() }, 0.3) } } else { this.scheduleOnce(() => { this.showCompleteNode() }, 0.3) } } //提示任务中断 if (richbank_logindays <= 1) { //任务中断的情况 let showBankTaskRestart = cc.sys.localStorage.getItem("showBankTaskRestart") let same = this.checkSameDay(new Number(showBankTaskRestart).valueOf()) let bankTaskStartTime = cc.sys.localStorage.getItem("bankTaskStartTime") let startTimeSame = this.checkSameDay(new Number(bankTaskStartTime).valueOf()) if (!same && !startTimeSame) { this.scheduleOnce(() => { this.showRestartTaskNode() }, 0.3) } } } clickRule() { GameM.audioM.playEffect(AUDIO_TYPE.button) // if (this.lock) { // return // } this.ruleNode.active = true let config = this.getBankTaskIndex() let money = config.money let showMoney = Math.floor(money / 100) > 0 ? (money / 100) + "" : (money / 100).toFixed(2) this.rulelabel.string = "2、存入金额达到" + showMoney + "元可开启提现" } clickCloseRule() { GameM.audioM.playEffect(AUDIO_TYPE.button) this.ruleNode.active = false } /** * 当前时间和目标时间是否是同一天 * @param targetTime 记录的时间戳 */ checkSameDay(targetTime: number): boolean { let currentDay = new Date().getDate() let lastData = new Date(targetTime).getDate() if (currentDay == lastData) { return true } return false } showInfoByStep() { let count = 0 for (let entry of this.taskStartNodeList) { // entry.opacity= 0 entry.scale = 0 } let array = new Array() for (let i = 0; i < this.taskStartNodeList.length; i++) { // array.push(this.taskStartNodeList[ i]) array.push(this.taskStartNodeList[this.taskStartNodeList.length - i - 1]) } this.schedule(() => { if (cc.isValid(array[count])) { // this.taskStartNodeList[count].runAction(cc.fadeIn(0.2)) if (array[count].name == "contentnode" || array[count].name == "emptyNode") { array[count].scale = 1 array[count].opacity = 0 array[count].runAction(cc.fadeIn(1)) } else { array[count].runAction(cc.sequence(cc.scaleTo(0.15, 1.2), cc.scaleTo(0.1, 1))) } } count++ }, 0.2, array.length) } clickBoxShowTip() { GameM.audioM.playEffect(AUDIO_TYPE.button); let config = this.getBankTaskIndex() let money = config.money let showMoney = Math.floor(money / 100) > 0 ? (money / 100) + "" : (money / 100).toFixed(2) let str = "存款达到" + showMoney + "元可提现哦" if (GameM.commonData.currentRichBankCashTaskIndex > 0) { str = "完成任务可提现,加油哦!" } EffectNode.instance.PlayTip(str) } showNoPacket() { this.noPacketTip.getChildByName("taskLabel").active = GameM.commonData.currentRichBankCashTaskIndex > 0 this.noPacketTip.getChildByName("noTaskLabel").active = !(GameM.commonData.currentRichBankCashTaskIndex > 0) this.noPacketTip.active = true let moveNode = this.noPacketTip let x = moveNode.x let y = moveNode.y moveNode.runAction(cc.repeatForever(cc.sequence(cc.moveTo(1.5, cc.v2(x, y - 5)), cc.moveTo(1.5, cc.v2(x - 5, y - 5)), cc.moveTo(1.2, cc.v2(x, y + 5))))) } clickRedCode() { GameM.audioM.playEffect(AUDIO_TYPE.button) UiM.Instance.onPanel(PANEL_NAME.RedCodeNode, false, () => { UiM.Instance.redCodeNode.getComponent(RedCodeNode).init(4) }) } }