ProductReward.ts 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. import { GameProp, VideoAdType } from "../../data/GameData";
  2. const { ccclass, property } = cc._decorator;
  3. @ccclass
  4. export default class ProductReward extends cc.Component {
  5. @property({ type: cc.Label, displayName: "文本" })
  6. lbl_times: cc.Label = null;
  7. @property({ type: cc.Label, displayName: "文本2" })
  8. lbl_times2: cc.Label = null;
  9. @property({ type: cc.Label, displayName: '任务次数' })
  10. lbl_taskTimes: cc.Label = null;
  11. @property({ type: cc.Label, displayName: '进度文本' })
  12. lbl_progress: cc.Label = null;
  13. @property({ type: cc.Sprite, displayName: '进度条' })
  14. sp_taskProgress: cc.Sprite = null;
  15. @property({ type: cc.Node, displayName: '完成节点' })
  16. node_complete: cc.Node = null;
  17. @property({ type: cc.Node, displayName: '未完成节点' })
  18. node_Uncomplete: cc.Node = null;
  19. @property({ type: cc.Node, displayName: '节点1' })
  20. node_1: cc.Node = null;
  21. @property({ type: cc.Node, displayName: '节点2' })
  22. node_2: cc.Node = null;
  23. private btnCanClick = true;
  24. onEnable() {
  25. this.lbl_times.string = `生产次数+${gData.gameData.configs.ServerConfig.ProductionAd}`;
  26. this.lbl_times2.string = `生产次数+${gData.gameData.configs.ServerConfig.ProductionAd}`;
  27. gData.gameData.init_productTask = false;
  28. let id = gData.gameData.getProp(GameProp.guideID);
  29. if (gData.gameData.playerProp.userFarmTaskInfo && id >= 11) {
  30. let com = gData.gameData.playerProp.userFarmTaskInfo.completeCount;
  31. let count = gData.gameData.playerProp.userFarmTaskInfo.taskCount;
  32. if ((count - com) <= 10) {
  33. if (count > com) {
  34. this.lbl_taskTimes.string = (count - com).toString();
  35. this.node_Uncomplete.active = true;
  36. this.node_complete.active = false;
  37. } else {
  38. this.node_Uncomplete.active = false;
  39. this.node_complete.active = true;
  40. }
  41. let per = com / count;
  42. cc.tween(this.sp_taskProgress).delay(0.2).to(0.3, { fillRange: per }, {
  43. onUpdate: () => {
  44. let num = Math.round(this.sp_taskProgress.fillRange * count);
  45. this.lbl_progress.string = `${num}/${count}`;
  46. }
  47. }).call(() => {
  48. this.lbl_progress.string = `${com}/${count}`;
  49. }).start();
  50. } else {
  51. this.node_1.active = false;
  52. this.node_2.active = true;
  53. }
  54. }
  55. //if (id >= 11)
  56. {
  57. mk.ad.showNative();
  58. }
  59. // else {
  60. // this.btnCanClick = false;
  61. // this.lbl_taskTimes.string = "1";
  62. // this.node_Uncomplete.active = true;
  63. // this.node_complete.active = false;
  64. // this.sp_taskProgress.fillRange = 0.99;
  65. // this.lbl_progress.string = "99%";
  66. // this.scheduleOnce(() => {
  67. // this.btnCanClick = true;
  68. // let data = gData.gameData.playerProp.orderData;
  69. // let orderData = data.orderTaskList;
  70. // let copyData = gData.gameData.playerProp.copyOrderData;
  71. // if (data && orderData && copyData) {
  72. // let num = 0;
  73. // for (let i = 0; i != orderData.length; ++i) {
  74. // num += (orderData[i].taskCount - copyData[i])
  75. // }
  76. // if (gData.gameData.funOpenData[11] == "1") {
  77. // let curDes = `<color=8A4312>再生产${num}次,就可以收获\n啦,完成订单立即<color=ff0000>提现</color>!</color>`;
  78. // mk.guide.open(11, curDes);
  79. // }
  80. // }
  81. // }, 0.2)
  82. // }
  83. }
  84. update(dt) {
  85. if (gData.gameData.init_productTask) {
  86. if (gData.gameData.playerProp.userFarmTaskInfo) {
  87. let com = gData.gameData.playerProp.userFarmTaskInfo.completeCount;
  88. let count = gData.gameData.playerProp.userFarmTaskInfo.taskCount;
  89. if (count <= 10) {
  90. if (count > com) {
  91. this.lbl_taskTimes.string = (count - com).toString();
  92. this.node_Uncomplete.active = true;
  93. this.node_complete.active = false;
  94. } else {
  95. this.node_Uncomplete.active = false;
  96. this.node_complete.active = true;
  97. }
  98. this.lbl_progress.string = `${com}/${count}`;
  99. this.sp_taskProgress.fillRange = com / count;
  100. } else {
  101. this.node_1.active = false;
  102. this.node_2.active = true;
  103. }
  104. }
  105. gData.gameData.init_productTask = false;
  106. }
  107. }
  108. private clickVideoBtn() {
  109. mk.audio.playEffect("button");
  110. if(!this.btnCanClick)
  111. {
  112. return;
  113. }
  114. mk.ui.closePanel(this.node.name);
  115. mk.ad.videoAdType = VideoAdType.video_init_16;
  116. mk.ad.watchAd((success: boolean) => {
  117. if (success) {
  118. gData.adData.watchVideo(null);
  119. let rewardData = [{ rewardType: 4, rewardNum: parseInt(gData.gameData.configs.ServerConfig.ProductionAd) }];
  120. gData.reward.data = rewardData;
  121. gData.reward.callback = this.addTimes;
  122. mk.ui.openPanel('module/reward/reward');
  123. let value = mk.storage.getStorage('guide_production');
  124. if (!value) {
  125. mk.storage.setStorage('guide_production', 1);
  126. mk.data.sendXYEvent('guide_production', '首次领取生产次数');
  127. }
  128. }
  129. })
  130. }
  131. addTimes() {
  132. let add = parseInt(gData.gameData.configs.ServerConfig.ProductionAd);
  133. gData.gameData.changeLeftTimes(add);
  134. gData.gameData.gameStyle.playAdd(add, 2);
  135. }
  136. onDisable() {
  137. mk.ad.destroyNativeAd();
  138. }
  139. private clickCloseBtn() {
  140. mk.audio.playEffect("button");
  141. mk.ui.closePanel(this.node.name);
  142. }
  143. }