ProductReward.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. onEnable() {
  24. let isGuide = false;
  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. if (gData.gameData.playerProp.userFarmTaskInfo) {
  29. let com = gData.gameData.playerProp.userFarmTaskInfo.completeCount;
  30. let count = gData.gameData.playerProp.userFarmTaskInfo.taskCount;
  31. if ((count - com) <= 10) {
  32. if (count > com) {
  33. this.lbl_taskTimes.string = (count - com).toString();
  34. this.node_Uncomplete.active = true;
  35. this.node_complete.active = false;
  36. isGuide = true;
  37. this.scheduleOnce(() => {
  38. let curDes = `<color=8A4312>再<color=ff0000>生产${count - com}次</color>,即可<color=ff0000>提现</color>,\n快领取次数吧!</color>`;
  39. mk.guide.open(2, curDes);
  40. }, 0.5)
  41. } else {
  42. this.node_Uncomplete.active = false;
  43. this.node_complete.active = true;
  44. }
  45. let per = com / count;
  46. cc.tween(this.sp_taskProgress).delay(0.2).to(0.3, { fillRange: per }, {
  47. onUpdate: () => {
  48. let num = Math.round(this.sp_taskProgress.fillRange * count);
  49. this.lbl_progress.string = `${num}/${count}`;
  50. }
  51. }).call(() => {
  52. this.lbl_progress.string = `${com}/${count}`;
  53. }).start();
  54. } else {
  55. this.node_1.active = false;
  56. this.node_2.active = true;
  57. }
  58. }
  59. if (isGuide) {
  60. let id = gData.gameData.getProp(GameProp.guideID);
  61. if (id >= 2) {
  62. mk.ad.showNative();
  63. }
  64. } else {
  65. mk.ad.showNative();
  66. }
  67. }
  68. update(dt) {
  69. if (gData.gameData.init_productTask) {
  70. if (gData.gameData.playerProp.userFarmTaskInfo) {
  71. let com = gData.gameData.playerProp.userFarmTaskInfo.completeCount;
  72. let count = gData.gameData.playerProp.userFarmTaskInfo.taskCount;
  73. if (count <= 10) {
  74. if (count > com) {
  75. this.lbl_taskTimes.string = (count - com).toString();
  76. this.node_Uncomplete.active = true;
  77. this.node_complete.active = false;
  78. } else {
  79. this.node_Uncomplete.active = false;
  80. this.node_complete.active = true;
  81. }
  82. this.lbl_progress.string = `${com}/${count}`;
  83. this.sp_taskProgress.fillRange = com / count;
  84. } else {
  85. this.node_1.active = false;
  86. this.node_2.active = true;
  87. }
  88. }
  89. gData.gameData.init_productTask = false;
  90. }
  91. }
  92. private clickVideoBtn() {
  93. mk.audio.playEffect("button");
  94. mk.ui.closePanel(this.node.name);
  95. mk.ad.videoAdType = VideoAdType.video_init_16;
  96. mk.ad.watchAd((success: boolean) => {
  97. if (success) {
  98. gData.adData.watchVideo(null);
  99. let rewardData = [{ rewardType: 4, rewardNum: parseInt(gData.gameData.configs.ServerConfig.ProductionAd) }];
  100. gData.reward.data = rewardData;
  101. gData.reward.callback = this.addTimes;
  102. mk.ui.openPanel('module/reward/reward');
  103. let value = mk.storage.getStorage('guide_production');
  104. if (!value) {
  105. mk.storage.setStorage('guide_production', 1);
  106. mk.data.sendXYEvent('guide_production', '首次领取生产次数');
  107. }
  108. }
  109. })
  110. }
  111. addTimes() {
  112. let add = parseInt(gData.gameData.configs.ServerConfig.ProductionAd);
  113. gData.gameData.changeLeftTimes(add);
  114. gData.gameData.gameStyle.playAdd(add, 2);
  115. }
  116. onDisable() {
  117. mk.ad.destroyNativeAd();
  118. }
  119. private clickCloseBtn() {
  120. mk.audio.playEffect("button");
  121. mk.ui.closePanel(this.node.name);
  122. }
  123. }