HarvestData.ts 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. this.isTouchBtn = false;
  42. mk.ui.openPanel('game/prefab/uiPanel/HarvestPanel');
  43. }else{
  44. this.isCdOver = false;
  45. console.log("=========isCdOver == false");
  46. this.getNormalReward();
  47. }
  48. } else {
  49. this.isCdOver = false;
  50. this.getNormalReward();
  51. }
  52. }else{
  53. this.isCdOver = false;
  54. console.log("=========isCdOver == false");
  55. this.getNormalReward();
  56. }
  57. }
  58. setAdData(data) {
  59. mk.console.logSingle('HarvestData addata ', this.adData);
  60. super.setAdData(data);
  61. //奖励弹窗
  62. //gData.reward.adData = gData.harvestData.adData;
  63. gData.reward.data = gData.harvestData.adData.videoRedMoney.videoRewardList;
  64. gData.reward.callback = gData.harvestData.call;
  65. let world_Pos = this.node_fly.parent.convertToWorldSpaceAR(this.node_fly.getPosition());
  66. gData.reward.getReward(world_Pos, this.isMatchOrder);
  67. //mk.ui.openPanel('module/reward/reward');
  68. gData.harvestData.call = null;
  69. }
  70. async getNormalReward() {
  71. if(this.isTouchBtn)
  72. {
  73. await mk.time.WaitForSeconds(0.5);
  74. }
  75. let data = { id: this.config.id };
  76. let response = await mk.http.sendData('redMoney/addRedMoneyByFarm', data);
  77. if (response && response.errcode != 0) {
  78. return;
  79. }
  80. //奖励弹窗
  81. if (response.data.redMoneyAddition <= 0) {
  82. this.isCdOver = true;
  83. console.log("=========isCdOver == true");
  84. console.log('返回奖励为0')
  85. }
  86. else {
  87. if(this.isTouchBtn)
  88. {
  89. let world_Pos = this.node_fly.parent.convertToWorldSpaceAR(this.node_fly.getPosition());
  90. let pos = mk.fly.node.convertToNodeSpaceAR(world_Pos);
  91. let prefab = await mk.loader.load("module/guide/hand", cc.Prefab);
  92. let hand = cc.instantiate(prefab);
  93. hand.scale = 0.8;
  94. let ani = hand.getComponent(cc.Animation);
  95. let state = ani.getAnimationState("guideA");
  96. state.speed = 2;
  97. hand.parent = mk.fly.node;
  98. hand.setPosition(pos);
  99. cc.tween(hand).delay(0.4).call(()=>{
  100. this.isCdOver = true;
  101. console.log("=========isCdOver == true");
  102. this.getType = 0;
  103. let rewardData = [{ rewardType: 1, rewardNum: response.data.redMoneyAddition }];
  104. gData.reward.data = rewardData;
  105. gData.reward.callback = this.call;
  106. //let world_Pos = this.node_fly.parent.convertToWorldSpaceAR(this.node_fly.getPosition());
  107. gData.reward.getReward(world_Pos, this.isMatchOrder);
  108. }).removeSelf().start();
  109. }else{
  110. this.isCdOver = true;
  111. console.log("=========isCdOver == true");
  112. this.getType = 0;
  113. let rewardData = [{ rewardType: 1, rewardNum: response.data.redMoneyAddition }];
  114. gData.reward.data = rewardData;
  115. gData.reward.callback = this.call;
  116. let world_Pos = this.node_fly.parent.convertToWorldSpaceAR(this.node_fly.getPosition());
  117. gData.reward.getReward(world_Pos, this.isMatchOrder);
  118. //mk.ui.openPanel('module/reward/reward');
  119. }
  120. }
  121. }
  122. public judgeIsMatchOrder()
  123. {
  124. let data = gData.gameData.playerProp.orderData;
  125. if (data && data.orderTaskList) {
  126. let productJson = gData.gameData.configs.Product;
  127. let orderData = data.orderTaskList;
  128. let len = orderData.length;
  129. for (let i = 0; i != len; ++i) {
  130. let dataE = orderData[i];
  131. if (dataE.Id <= productJson.length) {
  132. let productData = productJson[dataE.Id - 1];
  133. if (productData.picture == this.plantID) {
  134. this.isMatchOrder = true;
  135. return;
  136. }
  137. }
  138. }
  139. }
  140. this.isMatchOrder = false;
  141. }
  142. }