| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405 |
- /** 投资Item */
- import { HTTP_TYPE, MONEY_TYPE } from "../datas/CommonData";
- import GameM, { VIDEO_TYPE, AUDIO_TYPE } from "../manager/GameM";
- import { Utils } from "../utils/Utils";
- import UiM from "../manager/UiM";
- import EffectNode from "../ui/EffectNode";
- import RedPointM, { RedPointType } from "../manager/RedPointM";
- import Sciencen_M from "../utils/Sciencen_M";
- import Guide from "../ui/Guide";
- import AdM from "../manager/AdM";
- import Invest from "../ui/Invest";
- import RoleManageData from "../datas/RoleManageData";
- import LogUtil from "../utils/LogUtil";
- import InvestData from "../datas/InvestData";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class InvestItem extends cc.Component {
- @property(cc.Label)
- labName: cc.Label = null;
- @property(cc.Label)
- labAward: cc.Label = null;
- @property(cc.Node)
- timeNode: cc.Node = null;
- @property(cc.Label)
- labTimeLeft: cc.Label = null;
- @property(cc.Sprite)
- icon: cc.Sprite = null;
- @property(cc.Sprite)
- moneyIcon: cc.Sprite = null;
- @property(cc.Node)
- videoIcon: cc.Node = null;
- @property(cc.Node)
- btnInvest: cc.Node = null;
- @property(cc.Node)
- btnGet: cc.Node = null;
- @property(cc.Node)
- btnSpeed: cc.Node = null;
- @property(cc.Node)
- cardInfo: cc.Node = null;
- @property(cc.Label)
- labCardTime: cc.Label = null;
- @property(cc.Node)
- videoInfo: cc.Node = null;
- @property(cc.Label)
- labVideoTime: cc.Label = null;
- @property(cc.Label)
- completeLabel: cc.Label = null;
- @property(sp.Skeleton)
- clockSk: sp.Skeleton = null
- /** 服务器数据 */
- data = null
- awardNum = 0
- /** 倒计时时间 */
- leftTime = 0
- realTime = 0
- interValNum = 0
- start() {
- }
- init(data) {
- this.data = data
- var self = this
- cc.loader.loadRes('gift/money_picture_' + this.data.index, cc.SpriteFrame, (err, assets) => {
- if (err) {
- cc.error(err);
- return;
- }
- self.icon.spriteFrame = assets;
- })
- this.freshVideoState()
- if (this.data.rewadr == MONEY_TYPE.gold) {
- let time = GameM.commonData.buyTimeTotal
- if (time == 0) {
- time = 1
- }
- this.awardNum = Math.floor(GameM.commonData.buyNumCfg[time.toString()].gold * this.data.rewardNum)
- cc.loader.loadRes('gift/goldIcon1', cc.SpriteFrame, (err, assets) => {
- if (err) {
- cc.error(err);
- return;
- }
- self.moneyIcon.spriteFrame = assets;
- })
- }
- else {
- this.awardNum = this.data.rewardNum
- cc.loader.loadRes('gift/redMoneyIcon1', cc.SpriteFrame, (err, assets) => {
- if (err) {
- cc.error(err);
- return;
- }
- self.moneyIcon.spriteFrame = assets;
- })
- }
- this.labAward.string = Sciencen_M.instance.format(this.awardNum.toString());// this.awardNum.toString()
- this.labCardTime.string = "-" + InvestData.Instance.investCardTime + "分钟"
- this.labVideoTime.string = "-" + Math.floor(InvestData.Instance.investVideoTime * 100) + "%时间"
- if (this.data.state == 0) {
- this.btnGet.active = false
- // this.timeNode.x = 1000
- this.leftTime = 0
- this.labTimeLeft.string = ""
- this.completeLabel.string = ""
- this.btnInvest.active = true
- this.btnSpeed.active = false
- }
- else if (this.data.state == 1) {
- if (this.leftTime <= 0) { //判断是否是刷新时间
- this.leftTime = this.data.investTime - GameM.commonData.gameTime * 0.001
- this.schedule(this.freshTime, 1)
- } else {
- this.realTime = this.data.investTime - GameM.commonData.gameTime * 0.001 - 1
- this.interValNum = Math.floor((this.leftTime - this.realTime) / 60)
- if (this.interValNum <= 0) {
- this.schedule(this.freshTime, 1)
- } else {
- this.unschedule(this.freshTime)
- this.clockSk.node.active = true
- this.clockSk.setAnimation(0, 'animation', false)
- this.schedule(this.fastScrollTime, 1 / 60)
- }
- }
- this.btnGet.active = false
- // this.timeNode.x = 180
- this.btnInvest.active = false
- this.btnSpeed.active = true
- }
- else if (this.data.state == 2) {
- this.leftTime = 0
- this.btnGet.active = true
- // this.timeNode.x = 1000
- this.btnInvest.active = false
- this.btnSpeed.active = false
- this.labTimeLeft.string = ""
- this.completeLabel.string = "已完成"
- }
- this.freshSpeedType()
- }
- freshVideoState() {
- if (InvestData.Instance.checkHasInvest()) {
- this.videoIcon.active = true
- }
- else {
- this.videoIcon.active = false
- }
- }
- freshSpeedType() {
- this.cardInfo.active = GameM.commonData.roleData.speedCard > 0
- this.videoInfo.active = GameM.commonData.roleData.speedCard <= 0
- }
- fastScrollTime() {
- LogUtil.logV('leftTime ', this.leftTime)
- this.leftTime -= this.interValNum
- if (this.leftTime <= this.realTime) {
- this.leftTime = this.realTime
- this.schedule(this.freshTime, 1)
- this.unschedule(this.fastScrollTime)
- this.clockSk.node.active = false
- // this.data.state = 2
- } else {
- // this.clockSk.node.active = false
- this.completeLabel.string = ""
- this.labTimeLeft.string = Utils.ParseTime2Format(this.leftTime)
- }
- }
- freshTime() {
- LogUtil.logV('leftTime ', this.leftTime)
- this.leftTime--
- if (this.leftTime <= 0) {
- this.leftTime = 0
- this.labTimeLeft.string = ""
- this.completeLabel.string = "已完成"
- this.unschedule(this.freshTime)
- this.btnGet.active = true
- // this.timeNode.x = 1000
- this.btnInvest.active = false
- this.btnSpeed.active = false
- InvestData.Instance.updateInvestProject(this.data.index, 2)
- // this.data.state = 2
- }
- this.completeLabel.string = ""
- this.labTimeLeft.string = Utils.ParseTime2Format(this.leftTime)
- }
- onDisable() {
- this.unschedule(this.freshTime)
- this.unschedule(this.fastScrollTime)
- }
- coolTime = false
- clickInvest() {
- GameM.audioM.playEffect(AUDIO_TYPE.button)
- if (GameM.commonData.roleData.investGuide == 1) {
- GameM.commonData.roleData.investGuide = 2
- GameM.commonData.updateRoleData()
- // UiM.Instance.guideNode.getComponent(Guide).nextInvest()
- }
- if (this.coolTime) {
- return
- }
- this.coolTime = true
- setTimeout(() => {
- this.coolTime = false
- }, 1000);
- if (InvestData.Instance.SurplusTimes <= 0) {
- EffectNode.instance.PlayTip("每日次数不足")
- return
- }
- else if (this.videoIcon.active) {
- InvestData.Instance.investItem = this.node
- GameM.adM.watchVideo(VIDEO_TYPE.invest)
- }
- else {
- this.btnInvest.active = false
- this.btnSpeed.active = true
- // this.timeNode.x = 198
- // this.data.investTime = this.data.time
- // this.data.state = 1
- // InvestData.Instance.updateInvestData()
- // UiM.Instance.InvestNode.getComponent(Invest).freshInvestItem()
- GameM.commonData.addDailyFinishTimesDataByType(4)
- // GameM.commonData.updateRoleData()
- InvestData.Instance.updateInvestProject(this.data.index, 1)
- RedPointM.instance.ActiveRedPoint(RedPointType.Invest, false)
- }
- }
- //播放视频成功
- onInvestVideoEnd() {
- this.btnInvest.active = false
- this.btnSpeed.active = true
- this.btnGet.active = false
- // this.timeNode.x = 198
- // this.data.investTime = this.data.time
- // this.data.state = 1
- // InvestData.Instance.updateInvestData()
- // UiM.Instance.InvestNode.getComponent(Invest).freshInvestItem()
- GameM.commonData.addDailyFinishTimesDataByType(4)
- // GameM.commonData.updateRoleData()
- InvestData.Instance.updateInvestProject(this.data.index, 1)
- RedPointM.instance.ActiveRedPoint(RedPointType.Invest, false)
- }
- // /** 投资返回 */
- // investBack() {
- // UiM.Instance.InvestNode.getComponent(Invest).updateTimes()
- // this.schedule(this.freshTime, 1)
- // }
- //播放加速成功
- onInvestVideoSpeedEnd() {
- InvestData.Instance.reduceTimeInvestProject(this.data.index, 2)
- let reduceTime = Math.floor(this.leftTime * InvestData.Instance.investVideoTime)
- this.leftTime = Math.floor(this.leftTime - reduceTime)
- if (this.leftTime < 0) {
- this.leftTime = 0
- }
- // InvestData.Instance.updateInvestData()
- let min = Math.floor(reduceTime / 60)
- let sec = reduceTime % 60
- let str = ""
- if (min <= 0) {
- str = sec + "秒"
- } else {
- if (min > 60 || sec < 10) {
- str = min + "分钟"
- } else {
- str = (reduceTime / 60).toFixed(1) + "分钟"
- }
- }
- EffectNode.instance.PlayTip(`视频加速成功,减少${str}`)
- // UiM.Instance.InvestNode.getComponent(Invest).freshInvestItem()
- if (this.leftTime <= 0) {
- // this.data.state = 2
- // UiM.Instance.InvestNode.getComponent(Invest).freshInvestItem()
- // GameM.httpM.sendDatas(HTTP_TYPE.updateInvestData, { 'investData': InvestData.Instance.investData })
- InvestData.Instance.updateInvestProject(this.data.index, 2)
- }
- }
- clickGet() {
- GameM.audioM.playEffect(AUDIO_TYPE.button)
- if (this.coolTime) {
- return
- }
- this.coolTime = true
- setTimeout(() => {
- this.coolTime = false
- }, 1000);
- this.btnInvest.active = true
- this.btnGet.active = false
- // this.data.state = 0
- // InvestData.Instance.updateInvestData()
- InvestData.Instance.updateInvestProject(this.data.index, 0)
- }
- getGold() {
- GameM.audioM.playEffect(AUDIO_TYPE.getGold, false)
- EffectNode.instance.PlayCoinAnim(0, 20, cc.v2(0, -300));
- let numStr = Sciencen_M.instance.format(String(this.awardNum))
- GameM.commonData.updateGold(String(this.awardNum))
- EffectNode.instance.PlayTip(`获得金币:${numStr}`)
- }
- speedClick() {
- GameM.audioM.playEffect(AUDIO_TYPE.button)
- if (this.coolTime) {
- return
- }
- this.coolTime = true
- setTimeout(() => {
- this.coolTime = false
- }, 1000);
- if (GameM.commonData.roleData.speedCard <= 0) {
- InvestData.Instance.investItem = this.node
- if (GameM.commonData.isVideoTest) {
- //测试
- InvestData.Instance.investItem.getComponent(InvestItem).onInvestVideoSpeedEnd()
- } else {
- GameM.adM.watchVideo(VIDEO_TYPE.investSpeed)
- }
- LogUtil.logV("speedClick", "没有加速卡")
- return
- }
- // 加速卡加速
- RoleManageData.Instance.updateInvestCard()
- EffectNode.instance.PlayTip(`加速卡使用成功,探索时间-10分钟`)
- InvestData.Instance.reduceTimeInvestProject(this.data.index, 1)
- AdM.onSendEvent(`item_${MONEY_TYPE.speedCard}`, `使用道具${MONEY_TYPE.speedCard}`, 'item')
- // this.leftTime = Math.floor(this.leftTime - InvestData.Instance.investCardTime * 60)
- // if (this.leftTime < 0) {
- // this.leftTime = 0
- // }
- // // InvestData.Instance.updateInvestData()
- // EffectNode.instance.PlayTip(`加速成功,减少${InvestData.Instance.investCardTime}分钟`)
- // AdM.onSendEvent("Investcakduse", "投资加速券使用")
- // // UiM.Instance.InvestNode.getComponent(Invest).freshInvestItem()
- // // UiM.Instance.InvestNode.getComponent(Invest).updateTimes()
- // if (this.leftTime <= 0) {
- // // this.data.state = 2
- // // UiM.Instance.InvestNode.getComponent(Invest).freshInvestItem()
- // // GameM.httpM.sendDatas(HTTP_TYPE.updateInvestData, { 'investData': InvestData.Instance.investData })
- // InvestData.Instance.updateInvestProject(this.data.index, 2)
- // }
- }
- }
|