ProductReward.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. @property({ type: cc.Label, displayName: '订单提现金额' })
  25. lbl_orderValue: cc.Label = null;
  26. private btnCanClick = true;
  27. onEnable() {
  28. this.lbl_times.string = `生产次数+${gData.gameData.configs.ServerConfig.ProductionAd}`;
  29. this.lbl_times2.string = `生产次数+${gData.gameData.configs.ServerConfig.ProductionAd}`;
  30. //this.initUIByTaskData();
  31. gData.gameData.init_order = false;
  32. this.initUIByOrderData();
  33. }
  34. initUIByTaskData() {
  35. gData.gameData.init_productTask = false;
  36. let id = gData.gameData.getProp(GameProp.guideID);
  37. if (gData.gameData.playerProp.userFarmTaskInfo && id >= 11) {
  38. let com = gData.gameData.playerProp.userFarmTaskInfo.completeCount;
  39. let count = gData.gameData.playerProp.userFarmTaskInfo.taskCount;
  40. if ((count - com) <= 10) {
  41. if (count > com) {
  42. this.lbl_taskTimes.string = (count - com).toString();
  43. this.node_Uncomplete.active = true;
  44. this.node_complete.active = false;
  45. } else {
  46. this.node_Uncomplete.active = false;
  47. this.node_complete.active = true;
  48. }
  49. let per = com / count;
  50. cc.tween(this.sp_taskProgress).delay(0.2).to(0.3, { fillRange: per }, {
  51. onUpdate: () => {
  52. let num = Math.round(this.sp_taskProgress.fillRange * count);
  53. this.lbl_progress.string = `${num}/${count}`;
  54. }
  55. }).call(() => {
  56. this.lbl_progress.string = `${com}/${count}`;
  57. }).start();
  58. } else {
  59. this.node_1.active = false;
  60. this.node_2.active = true;
  61. }
  62. }
  63. if (id >= 11) {
  64. mk.ad.showNative();
  65. } else {
  66. this.btnCanClick = false;
  67. this.lbl_taskTimes.string = "1";
  68. this.node_Uncomplete.active = true;
  69. this.node_complete.active = false;
  70. this.sp_taskProgress.fillRange = 0.99;
  71. this.lbl_progress.string = "99%";
  72. this.scheduleOnce(() => {
  73. this.btnCanClick = true;
  74. let data = gData.gameData.playerProp.orderData;
  75. let orderData = data.orderTaskList;
  76. //let copyData = gData.gameData.playerProp.copyOrderData;
  77. if (data && orderData) {
  78. let num = 0;
  79. for (let i = 0; i != orderData.length; ++i) {
  80. num += (orderData[i].taskCount - orderData[i].completeCount)
  81. }
  82. if (gData.gameData.funOpenData[11] == "1") {
  83. let curDes = `<color=8A4312>再生产${num}次,就可以收获\n啦,完成订单立即<color=ff0000>提现</color>!</color>`;
  84. mk.guide.open(11, curDes);
  85. }
  86. }
  87. }, 0.2)
  88. }
  89. }
  90. initUIByOrderData(isRefresh = false) {
  91. if (gData.gameData.funOpenData[11] == "1") {
  92. let data = gData.gameData.playerProp.orderData;
  93. if (data) {
  94. let count = 0;
  95. let allCount = 0;
  96. let orderData = data.orderTaskList;
  97. for (let i = 0; i != orderData.length; ++i) {
  98. allCount += orderData[i].taskCount;
  99. count += (orderData[i].taskCount - orderData[i].completeCount)
  100. }
  101. if (count > 0) {
  102. this.node_Uncomplete.active = true;
  103. this.node_complete.active = false;
  104. let com = allCount - count;
  105. let per = com / allCount;
  106. this.lbl_taskTimes.string = count.toString();
  107. cc.tween(this.sp_taskProgress).delay(0.2).to(0.3, { fillRange: per }, {
  108. onUpdate: () => {
  109. let num = Math.round(this.sp_taskProgress.fillRange * allCount);
  110. this.lbl_progress.string = `${num}/${allCount}`;
  111. }
  112. }).call(() => {
  113. this.lbl_progress.string = `${com}/${allCount}`;
  114. }).start();
  115. let id = gData.gameData.getProp(GameProp.guideID);
  116. if (id >= 11) {
  117. if(!isRefresh)
  118. {
  119. mk.ad.showNative();
  120. }
  121. } else {
  122. this.btnCanClick = false;
  123. this.scheduleOnce(() => {
  124. this.btnCanClick = true;
  125. let curDes = `<color=8A4312>再生产<color=ff0000>${count}</color>次,就可以完成\n订单立即<color=ff0000>提现</color>!</color>`;
  126. mk.guide.open(11, curDes);
  127. }, 0.2)
  128. }
  129. } else {
  130. let v = gData.gameData.playerProp.orderData.cashMoney;
  131. this.lbl_orderValue.string = "订单已完成,可提现" + (v/100).toFixed(2) + "元";
  132. this.sp_taskProgress.fillRange = 1;
  133. this.lbl_progress.string = `${allCount}/${allCount}`;
  134. this.node_Uncomplete.active = false;
  135. this.node_complete.active = true;
  136. if(!isRefresh)
  137. {
  138. mk.ad.showNative();
  139. }
  140. }
  141. }
  142. } else {
  143. this.node_1.active = false;
  144. this.node_2.active = true;
  145. if(!isRefresh)
  146. {
  147. mk.ad.showNative();
  148. }
  149. }
  150. }
  151. update(dt) {
  152. // if (gData.gameData.init_productTask) {
  153. // if (gData.gameData.playerProp.userFarmTaskInfo) {
  154. // let com = gData.gameData.playerProp.userFarmTaskInfo.completeCount;
  155. // let count = gData.gameData.playerProp.userFarmTaskInfo.taskCount;
  156. // if (count <= 10) {
  157. // if (count > com) {
  158. // this.lbl_taskTimes.string = (count - com).toString();
  159. // this.node_Uncomplete.active = true;
  160. // this.node_complete.active = false;
  161. // } else {
  162. // this.node_Uncomplete.active = false;
  163. // this.node_complete.active = true;
  164. // }
  165. // this.lbl_progress.string = `${com}/${count}`;
  166. // this.sp_taskProgress.fillRange = com / count;
  167. // } else {
  168. // this.node_1.active = false;
  169. // this.node_2.active = true;
  170. // }
  171. // }
  172. // gData.gameData.init_productTask = false;
  173. // }
  174. if(gData.gameData.init_order)
  175. {
  176. this.initUIByOrderData(true);
  177. gData.gameData.init_order = false;
  178. }
  179. }
  180. private clickVideoBtn() {
  181. mk.audio.playEffect("button");
  182. if (!this.btnCanClick) {
  183. return;
  184. }
  185. mk.ui.closePanel(this.node.name);
  186. mk.ad.videoAdType = VideoAdType.video_init_16;
  187. mk.ad.watchAd((success: boolean) => {
  188. if (success) {
  189. let str = gData.gameData.prohibitProductionAd[gData.loginData.userChannel].split(",");
  190. if (str[1 - gData.loginData.isMatched] == "1") {
  191. gData.adData.watchVideo(AdFun.addProductTimes, this.refreshMaxAdTimes);
  192. } else {
  193. gData.adData.watchVideo(null);
  194. }
  195. let rewardData = [{ rewardType: 4, rewardNum: parseInt(gData.gameData.configs.ServerConfig.ProductionAd) }];
  196. gData.reward.data = rewardData;
  197. gData.reward.callback = this.addTimes;
  198. mk.ui.openPanel('module/reward/reward');
  199. let value = mk.storage.getStorage('guide_production');
  200. if (!value) {
  201. mk.storage.setStorage('guide_production', 1);
  202. mk.data.sendXYEvent('guide_production', '首次领取生产次数');
  203. }
  204. }
  205. })
  206. }
  207. refreshMaxAdTimes(value) {
  208. gData.gameData.playerProp.curProductionAdTimes = value;
  209. }
  210. addTimes() {
  211. let add = parseInt(gData.gameData.configs.ServerConfig.ProductionAd);
  212. gData.gameData.changeLeftTimes(add);
  213. gData.gameData.gameStyle.playAdd(add, 2);
  214. }
  215. onDisable() {
  216. mk.ad.destroyNativeAd();
  217. }
  218. private clickCloseBtn() {
  219. mk.audio.playEffect("button");
  220. mk.ui.closePanel(this.node.name);
  221. }
  222. private clickGetOrderRewardBtn()
  223. {
  224. gData.gameData.gameStyle.getOrderReward();
  225. }
  226. }