HarvestData.ts 7.5 KB

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