import { AdFun } from "../../data/AdData";
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;
@property({ type: cc.Label, displayName: '订单提现金额' })
lbl_orderValue: cc.Label = null;
@property({ type: cc.Label, displayName: '奖励类型描述' })
lbl_rewardDes: cc.Label = null;
private btnCanClick = true;
start(){
//gData.adData.checkPopInter(InterAdType.interstitial1_click_7);
gData.gameData.popTableScreenADLogic(6);
}
onEnable() {
this.lbl_times.string = `生产次数+${gData.gameData.configs.ServerConfig.ProductionAd}`;
this.lbl_times2.string = `生产次数+${gData.gameData.configs.ServerConfig.ProductionAd}`;
//this.initUIByTaskData();
gData.gameData.init_order = false;
this.initUIByOrderData();
}
initUIByTaskData() {
gData.gameData.init_productTask = false;
let id = gData.gameData.getProp(GameProp.guideID);
if (gData.gameData.playerProp.userFarmTaskInfo && id >= 11) {
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;
} 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 (id >= 11) {
mk.ad.showNative();
} else {
this.btnCanClick = false;
this.lbl_taskTimes.string = "1";
this.node_Uncomplete.active = true;
this.node_complete.active = false;
this.sp_taskProgress.fillRange = 0.99;
this.lbl_progress.string = "99%";
this.scheduleOnce(() => {
this.btnCanClick = true;
let data = gData.gameData.playerProp.orderData;
let orderData = data.orderTaskList;
//let copyData = gData.gameData.playerProp.copyOrderData;
if (data && orderData) {
let num = 0;
for (let i = 0; i != orderData.length; ++i) {
num += (orderData[i].taskCount - orderData[i].completeCount)
}
if (gData.gameData.funOpenData[11] == "1") {
let curDes = `再生产${num}次,就可以收获\n啦,完成订单立即提现!`;
mk.guide.open(11, curDes);
}
}
}, 0.2)
}
}
initUIByOrderData(isRefresh = false) {
if (gData.gameData.funOpenData[11] == "1") {
let data = gData.gameData.playerProp.orderData;
if (data) {
let count = 0;
let allCount = 0;
let orderData = data.orderTaskList;
for (let i = 0; i != orderData.length; ++i) {
allCount += orderData[i].taskCount;
count += (orderData[i].taskCount - orderData[i].completeCount)
}
if (count > 0) {
this.node_Uncomplete.active = true;
this.node_complete.active = false;
let com = allCount - count;
let per = com / allCount;
this.lbl_taskTimes.string = count.toString();
cc.tween(this.sp_taskProgress).delay(0.2).to(0.3, { fillRange: per }, {
onUpdate: () => {
let num = Math.round(this.sp_taskProgress.fillRange * allCount);
this.lbl_progress.string = `${num}/${allCount}`;
}
}).call(() => {
this.lbl_progress.string = `${com}/${allCount}`;
}).start();
let id = gData.gameData.getProp(GameProp.guideID);
if (id >= 11) {
if(!isRefresh)
{
mk.ad.showNative();
}
} else {
this.btnCanClick = false;
this.scheduleOnce(() => {
this.btnCanClick = true;
let curDes = `再生产${count}次,就可以完成\n订单立即提现!`;
mk.guide.open(11, curDes);
}, 0.2)
}
if(gData.gameData.orderRewardType == 1){
this.lbl_rewardDes.string = `领取${data.redMoneyAddition/100}红包币`;
}
} else {
// if(gData.gameData.orderRewardType == 1){
// let v = gData.gameData.playerProp.orderData.redMoneyAddition;
// this.lbl_orderValue.string = "订单已完成,可领取" + (v/100) + "红包币";
// }else{
// let v = gData.gameData.playerProp.orderData.cashMoney;
// this.lbl_orderValue.string = "订单已完成,可提现" + (v/100).toFixed(2) + "元";
// }
this.sp_taskProgress.fillRange = 1;
this.lbl_progress.string = `${allCount}/${allCount}`;
this.node_Uncomplete.active = false;
this.node_complete.active = true;
if(!isRefresh)
{
mk.ad.showNative();
}
}
}
} else {
this.node_1.active = false;
this.node_2.active = true;
if(!isRefresh)
{
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;
// }
if(gData.gameData.init_order)
{
this.initUIByOrderData(true);
gData.gameData.init_order = false;
}
}
private clickVideoBtn() {
mk.audio.playEffect("button");
if (!this.btnCanClick) {
return;
}
mk.ui.closePanel(this.node.name);
mk.ad.videoAdType = VideoAdType.video_init_16;
mk.ad.watchAd((success: boolean) => {
if (success) {
let str = gData.gameData.prohibitProductionAd[gData.loginData.userChannel].split(",");
if (str[1 - gData.loginData.isMatched] == "1") {
gData.adData.watchVideo(AdFun.addProductTimes, this.refreshMaxAdTimes);
} else {
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', '首次领取生产次数');
}
}
})
}
refreshMaxAdTimes(value) {
gData.gameData.playerProp.curProductionAdTimes = value;
}
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);
}
private clickGetOrderRewardBtn()
{
gData.gameData.gameStyle.getOrderReward(false);
}
}