ProductReward.ts 6.7 KB

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