import { GameProp, VideoAdType } from "../../data/GameData"; const { ccclass, property } = cc._decorator; @ccclass export default class ProductReward extends cc.Component { @property({ type: cc.Label, displayName: "文本" }) lbl_times: cc.Label = null; @property({ type: cc.Label, displayName: "文本2" }) lbl_times2: cc.Label = null; @property({ type: cc.Label, displayName: '任务次数' }) lbl_taskTimes: cc.Label = null; @property({ type: cc.Label, displayName: '进度文本' }) lbl_progress: cc.Label = null; @property({ type: cc.Sprite, displayName: '进度条' }) sp_taskProgress: cc.Sprite = null; @property({ type: cc.Node, displayName: '完成节点' }) node_complete: cc.Node = null; @property({ type: cc.Node, displayName: '未完成节点' }) node_Uncomplete: cc.Node = null; @property({ type: cc.Node, displayName: '节点1' }) node_1: cc.Node = null; @property({ type: cc.Node, displayName: '节点2' }) node_2: cc.Node = null; onEnable() { let isGuide = false; this.lbl_times.string = `生产次数+${gData.gameData.configs.ServerConfig.ProductionAd}`; this.lbl_times2.string = `生产次数+${gData.gameData.configs.ServerConfig.ProductionAd}`; gData.gameData.init_productTask = false; if (gData.gameData.playerProp.userFarmTaskInfo) { let com = gData.gameData.playerProp.userFarmTaskInfo.completeCount; let count = gData.gameData.playerProp.userFarmTaskInfo.taskCount; if ((count - com) <= 10) { if (count > com) { this.lbl_taskTimes.string = (count - com).toString(); this.node_Uncomplete.active = true; this.node_complete.active = false; isGuide = true; this.scheduleOnce(() => { let curDes = `生产${count - com}次,即可提现,\n快领取次数吧!`; mk.guide.open(2, curDes); }, 0.5) } else { this.node_Uncomplete.active = false; this.node_complete.active = true; } let per = com / count; cc.tween(this.sp_taskProgress).delay(0.2).to(0.3, { fillRange: per }, { onUpdate: () => { let num = Math.round(this.sp_taskProgress.fillRange * count); this.lbl_progress.string = `${num}/${count}`; } }).call(() => { this.lbl_progress.string = `${com}/${count}`; }).start(); } else { this.node_1.active = false; this.node_2.active = true; } } if (isGuide) { let id = gData.gameData.getProp(GameProp.guideID); if (id >= 2) { mk.ad.showNative(); } } else { mk.ad.showNative(); } } update(dt) { if (gData.gameData.init_productTask) { if (gData.gameData.playerProp.userFarmTaskInfo) { let com = gData.gameData.playerProp.userFarmTaskInfo.completeCount; let count = gData.gameData.playerProp.userFarmTaskInfo.taskCount; if (count <= 10) { if (count > com) { this.lbl_taskTimes.string = (count - com).toString(); this.node_Uncomplete.active = true; this.node_complete.active = false; } else { this.node_Uncomplete.active = false; this.node_complete.active = true; } this.lbl_progress.string = `${com}/${count}`; this.sp_taskProgress.fillRange = com / count; } else { this.node_1.active = false; this.node_2.active = true; } } gData.gameData.init_productTask = false; } } private clickVideoBtn() { mk.audio.playEffect("button"); mk.ui.closePanel(this.node.name); mk.ad.videoAdType = VideoAdType.video_init_16; mk.ad.watchAd((success: boolean) => { if (success) { gData.adData.watchVideo(null); let rewardData = [{ rewardType: 4, rewardNum: parseInt(gData.gameData.configs.ServerConfig.ProductionAd) }]; gData.reward.data = rewardData; gData.reward.callback = this.addTimes; mk.ui.openPanel('module/reward/reward'); let value = mk.storage.getStorage('guide_production'); if (!value) { mk.storage.setStorage('guide_production', 1); mk.data.sendXYEvent('guide_production', '首次领取生产次数'); } } }) } addTimes() { let add = parseInt(gData.gameData.configs.ServerConfig.ProductionAd); gData.gameData.changeLeftTimes(add); gData.gameData.gameStyle.playAdd(add, 2); } onDisable() { mk.ad.destroyNativeAd(); } private clickCloseBtn() { mk.audio.playEffect("button"); mk.ui.closePanel(this.node.name); } }