ProductReward.ts 11 KB

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