HarvestData.ts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /**收获界面数据类 */
  2. import { RateConfig } from "../../../game/data/AdData";
  3. import Guide from "../../../game/module/guide/Guide";
  4. import { Data } from "../../../mk/data/Data";
  5. const { ccclass } = cc._decorator;
  6. @ccclass
  7. export default class HarvestData extends Data {
  8. configID = null;
  9. plantID = null;
  10. config = null;
  11. call = null;
  12. //领取类型 0 普通领取 1 超级加倍
  13. getType = 0;
  14. init_reward = false;
  15. node_fly: cc.Node = null;
  16. isMatchOrder = false;
  17. //是否是点击一键生产按钮
  18. isTouchBtn = false;
  19. isCdOver = true;
  20. openPanel(configID, plantID, call, node, isTouchBtn =false, isTeach = false) {
  21. if(!this.isCdOver)
  22. {
  23. console.log("=========isCdOver");
  24. return;
  25. }
  26. this.configID = configID;
  27. this.plantID = plantID;
  28. this.call = call;
  29. this.node_fly = node;
  30. this.isTouchBtn = isTouchBtn;
  31. this.config = gData.gameData.getProductMap(this.plantID);
  32. this.judgeIsMatchOrder();
  33. if(!isTeach)
  34. {
  35. let isTeaching = mk.guide.isGuiding();
  36. let rand = Math.random();
  37. let rate = gData.adData.getPerByEcpm(RateConfig.RC_superDouble);
  38. if (!isTeaching && rand <= rate) {
  39. if(gData.gameData.playerProp.orderData && gData.gameData.playerProp.orderData.overTimes >0)
  40. {
  41. let str = gData.gameData.prohibiJBAd[gData.loginData.userChannel].split(",");
  42. if (str[1- gData.loginData.isMatched] == "1") {
  43. this.isTouchBtn = false;
  44. this.isCdOver = true;
  45. mk.ui.openPanel('game/prefab/uiPanel/HarvestPanel');
  46. } else {
  47. this.isCdOver = false;
  48. console.log("=========isCdOver == false");
  49. this.getNormalReward();
  50. }
  51. }else{
  52. this.isCdOver = false;
  53. console.log("=========isCdOver == false");
  54. this.getNormalReward();
  55. }
  56. } else {
  57. this.isCdOver = false;
  58. this.getNormalReward();
  59. }
  60. }else{
  61. this.isCdOver = false;
  62. console.log("=========isCdOver == false");
  63. this.getNormalReward();
  64. }
  65. }
  66. setAdData(data) {
  67. mk.console.logSingle('HarvestData addata ', this.adData);
  68. super.setAdData(data);
  69. //奖励弹窗
  70. //gData.reward.adData = gData.harvestData.adData;
  71. gData.reward.data = gData.harvestData.adData.videoRedMoney.videoRewardList;
  72. gData.reward.callback = gData.harvestData.call;
  73. let world_Pos = this.node_fly.parent.convertToWorldSpaceAR(this.node_fly.getPosition());
  74. gData.reward.getReward(world_Pos, this.isMatchOrder);
  75. //mk.ui.openPanel('module/reward/reward');
  76. gData.harvestData.call = null;
  77. }
  78. async getNormalReward() {
  79. if(this.isTouchBtn)
  80. {
  81. await mk.time.WaitForSeconds(0.5);
  82. }
  83. let data = { id: this.config.id };
  84. let response = await mk.http.sendData('redMoney/addRedMoneyByFarm', data);
  85. if (response && response.errcode != 0) {
  86. this.isCdOver = true;
  87. return;
  88. }
  89. //奖励弹窗
  90. if (response.data.redMoneyAddition <= 0) {
  91. this.isCdOver = true;
  92. console.log("=========isCdOver == true");
  93. console.log('返回奖励为0')
  94. }
  95. else {
  96. if(this.isTouchBtn)
  97. {
  98. let world_Pos = this.node_fly.parent.convertToWorldSpaceAR(this.node_fly.getPosition());
  99. let pos = mk.fly.node.convertToNodeSpaceAR(world_Pos);
  100. let prefab = await mk.loader.load("module/guide/hand", cc.Prefab);
  101. let hand = cc.instantiate(prefab);
  102. hand.scale = 0.8;
  103. let ani = hand.getComponent(cc.Animation);
  104. let state = ani.getAnimationState("guideA");
  105. state.speed = 2;
  106. hand.parent = mk.fly.node;
  107. hand.setPosition(pos);
  108. cc.tween(hand).delay(0.4).call(()=>{
  109. this.isCdOver = true;
  110. console.log("=========isCdOver == true");
  111. this.getType = 0;
  112. let rewardData = [{ rewardType: 1, rewardNum: response.data.redMoneyAddition }];
  113. gData.reward.data = rewardData;
  114. gData.reward.callback = this.call;
  115. //let world_Pos = this.node_fly.parent.convertToWorldSpaceAR(this.node_fly.getPosition());
  116. gData.reward.getReward(world_Pos, this.isMatchOrder);
  117. }).removeSelf().start();
  118. }else{
  119. this.isCdOver = true;
  120. console.log("=========isCdOver == true");
  121. this.getType = 0;
  122. let rewardData = [{ rewardType: 1, rewardNum: response.data.redMoneyAddition }];
  123. gData.reward.data = rewardData;
  124. gData.reward.callback = this.call;
  125. let world_Pos = this.node_fly.parent.convertToWorldSpaceAR(this.node_fly.getPosition());
  126. gData.reward.getReward(world_Pos, this.isMatchOrder);
  127. //mk.ui.openPanel('module/reward/reward');
  128. }
  129. }
  130. }
  131. public judgeIsMatchOrder()
  132. {
  133. let data = gData.gameData.playerProp.orderData;
  134. if (data && data.orderTaskList) {
  135. let productJson = gData.gameData.configs.Product;
  136. let orderData = data.orderTaskList;
  137. let len = orderData.length;
  138. for (let i = 0; i != len; ++i) {
  139. let dataE = orderData[i];
  140. if (dataE.Id <= productJson.length) {
  141. let productData = productJson[dataE.Id - 1];
  142. if (productData.picture == this.plantID) {
  143. this.isMatchOrder = true;
  144. return;
  145. }
  146. }
  147. }
  148. }
  149. this.isMatchOrder = false;
  150. }
  151. }