HarvestData.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. openPanel(configID, plantID, call, node) {
  17. this.configID = configID;
  18. this.plantID = plantID;
  19. this.call = call;
  20. this.node_fly = node;
  21. this.config = gData.gameData.getProductMap(this.plantID);
  22. let isTeaching = mk.guide.isGuiding();
  23. let rand = Math.random();
  24. let rate = gData.adData.getPerByEcpm(RateConfig.RC_superDouble);
  25. if (!isTeaching && rand <= rate) {
  26. mk.ui.openPanel('game/prefab/uiPanel/HarvestPanel');
  27. } else {
  28. this.getNormalReward();
  29. }
  30. }
  31. setAdData(data) {
  32. mk.console.logSingle('HarvestData addata ', this.adData);
  33. super.setAdData(data);
  34. //奖励弹窗
  35. //gData.reward.adData = gData.harvestData.adData;
  36. gData.reward.data = gData.harvestData.adData.videoRedMoney.videoRewardList;
  37. gData.reward.callback = gData.harvestData.call;
  38. let world_Pos = this.node_fly.parent.convertToWorldSpaceAR(this.node_fly.getPosition());
  39. gData.reward.getReward(world_Pos);
  40. //mk.ui.openPanel('module/reward/reward');
  41. gData.harvestData.call = null;
  42. }
  43. async getNormalReward() {
  44. let data = { id: this.config.id };
  45. let response = await mk.http.sendData('redMoney/addRedMoneyByFarm', data);
  46. if (response && response.errcode != 0) {
  47. return;
  48. }
  49. //奖励弹窗
  50. if (response.data.redMoneyAddition <= 0) {
  51. console.log('返回奖励为0')
  52. }
  53. else {
  54. this.getType = 0;
  55. let rewardData = [{ rewardType: 1, rewardNum: response.data.redMoneyAddition }];
  56. gData.reward.data = rewardData;
  57. gData.reward.callback = this.call;
  58. let world_Pos = this.node_fly.parent.convertToWorldSpaceAR(this.node_fly.getPosition());
  59. gData.reward.getReward(world_Pos);
  60. //mk.ui.openPanel('module/reward/reward');
  61. }
  62. }
  63. }