| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- 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 = `<color=8A4312>再<color=ff0000>生产${count - com}次</color>,即可<color=ff0000>提现</color>,\n快领取次数吧!</color>`;
- 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);
- }
- }
|