| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- /**收获界面数据类 */
- import { RateConfig } from "../../../game/data/AdData";
- import Guide from "../../../game/module/guide/Guide";
- import { Data } from "../../../mk/data/Data";
- const { ccclass } = cc._decorator;
- @ccclass
- export default class HarvestData extends Data {
- configID = null;
- plantID = null;
- config = null;
- call = null;
- //领取类型 0 普通领取 1 超级加倍
- getType = 0;
- init_reward = false;
- node_fly: cc.Node = null;
- isMatchOrder = false;
- //是否是点击一键生产按钮
- isTouchBtn = false;
- isCdOver = true;
- openPanel(configID, plantID, call, node, isTouchBtn =false, isTeach = false) {
- if(!this.isCdOver)
- {
- console.log("=========isCdOver");
- return;
- }
- this.configID = configID;
- this.plantID = plantID;
- this.call = call;
- this.node_fly = node;
- this.isTouchBtn = isTouchBtn;
- this.config = gData.gameData.getProductMap(this.plantID);
- this.judgeIsMatchOrder();
- if(!isTeach)
- {
- let isTeaching = mk.guide.isGuiding();
- let rand = Math.random();
- let rate = gData.adData.getPerByEcpm(RateConfig.RC_superDouble);
- if (!isTeaching && rand <= rate) {
- if(gData.gameData.playerProp.orderData && gData.gameData.playerProp.orderData.overTimes >0)
- {
- this.isTouchBtn = false;
- mk.ui.openPanel('game/prefab/uiPanel/HarvestPanel');
- }else{
- this.isCdOver = false;
- console.log("=========isCdOver == false");
- this.getNormalReward();
- }
-
- } else {
- this.isCdOver = false;
- this.getNormalReward();
- }
- }else{
- this.isCdOver = false;
- console.log("=========isCdOver == false");
- this.getNormalReward();
- }
-
- }
- setAdData(data) {
- mk.console.logSingle('HarvestData addata ', this.adData);
- super.setAdData(data);
- //奖励弹窗
- //gData.reward.adData = gData.harvestData.adData;
- gData.reward.data = gData.harvestData.adData.videoRedMoney.videoRewardList;
- gData.reward.callback = gData.harvestData.call;
- let world_Pos = this.node_fly.parent.convertToWorldSpaceAR(this.node_fly.getPosition());
- gData.reward.getReward(world_Pos, this.isMatchOrder);
- //mk.ui.openPanel('module/reward/reward');
- gData.harvestData.call = null;
- }
- async getNormalReward() {
- if(this.isTouchBtn)
- {
- await mk.time.WaitForSeconds(0.5);
- }
- let data = { id: this.config.id };
- let response = await mk.http.sendData('redMoney/addRedMoneyByFarm', data);
- if (response && response.errcode != 0) {
- return;
- }
- //奖励弹窗
- if (response.data.redMoneyAddition <= 0) {
- this.isCdOver = true;
- console.log("=========isCdOver == true");
- console.log('返回奖励为0')
- }
- else {
- if(this.isTouchBtn)
- {
- let world_Pos = this.node_fly.parent.convertToWorldSpaceAR(this.node_fly.getPosition());
- let pos = mk.fly.node.convertToNodeSpaceAR(world_Pos);
- let prefab = await mk.loader.load("module/guide/hand", cc.Prefab);
- let hand = cc.instantiate(prefab);
- hand.scale = 0.8;
- let ani = hand.getComponent(cc.Animation);
- let state = ani.getAnimationState("guideA");
- state.speed = 2;
- hand.parent = mk.fly.node;
- hand.setPosition(pos);
- cc.tween(hand).delay(0.4).call(()=>{
- this.isCdOver = true;
- console.log("=========isCdOver == true");
- this.getType = 0;
- let rewardData = [{ rewardType: 1, rewardNum: response.data.redMoneyAddition }];
- gData.reward.data = rewardData;
- gData.reward.callback = this.call;
-
-
- //let world_Pos = this.node_fly.parent.convertToWorldSpaceAR(this.node_fly.getPosition());
- gData.reward.getReward(world_Pos, this.isMatchOrder);
- }).removeSelf().start();
- }else{
- this.isCdOver = true;
- console.log("=========isCdOver == true");
- this.getType = 0;
- let rewardData = [{ rewardType: 1, rewardNum: response.data.redMoneyAddition }];
- gData.reward.data = rewardData;
- gData.reward.callback = this.call;
-
-
- let world_Pos = this.node_fly.parent.convertToWorldSpaceAR(this.node_fly.getPosition());
- gData.reward.getReward(world_Pos, this.isMatchOrder);
- //mk.ui.openPanel('module/reward/reward');
- }
-
- }
- }
- public judgeIsMatchOrder()
- {
- let data = gData.gameData.playerProp.orderData;
- if (data && data.orderTaskList) {
- let productJson = gData.gameData.configs.Product;
- let orderData = data.orderTaskList;
- let len = orderData.length;
- for (let i = 0; i != len; ++i) {
- let dataE = orderData[i];
- if (dataE.Id <= productJson.length) {
- let productData = productJson[dataE.Id - 1];
- if (productData.picture == this.plantID) {
- this.isMatchOrder = true;
- return;
- }
- }
- }
- }
-
- this.isMatchOrder = false;
- }
- }
|