RedBagTask.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. import Util from "../../../before/util/Util";
  2. import JsbSystem from "../../../mk/system/JsbSystem";
  3. import SetGray from "../../component/SetGray";
  4. import { BannerAdType, DataEventId, GameProp } from "../../data/GameData";
  5. const { ccclass, property } = cc._decorator;
  6. @ccclass
  7. export default class RedBagTask extends cc.Component {
  8. @property({ displayName: '数字组', type: cc.Label })
  9. private lbl_value: cc.Label[] = [];
  10. @property({ displayName: '任务进度条', type: cc.Sprite })
  11. private sp_taskProgress: cc.Sprite = null;
  12. @property({ displayName: '任务进度文本', type: cc.Label })
  13. private lbl_taskProgress: cc.Label = null;
  14. @property({ displayName: '按钮动画', type: cc.Animation })
  15. private openBtn_ani: cc.Animation = null;
  16. @property(cc.Label)
  17. private lbl_reward_value: cc.Label = null;
  18. @property(cc.Sprite)
  19. private spr_cash_out: cc.Sprite = null;
  20. @property(cc.Label)
  21. private lbl_progress: cc.Label = null;
  22. @property(cc.Animation)
  23. private node_cash: cc.Animation = null;
  24. @property({ type: cc.Node, displayName: '显示金额节点' })
  25. private node_value: cc.Node = null;
  26. @property({ type: cc.Node, displayName: '任务节点' })
  27. private node_task: cc.Node = null;
  28. @property({ type: cc.Label, displayName: '动画显示文字' })
  29. private lbl_Ani: cc.Label = null;
  30. @property({ type: cc.Label, displayName: '任务数量' })
  31. private lbl_taskNum: cc.Label = null;
  32. @property(cc.Node)
  33. private node_videoIcon: cc.Node = null;
  34. @property(cc.Node)
  35. private node_hand: cc.Node = null;
  36. private isShowNewTask = false;
  37. private num = 0;
  38. private delayTime = 0;
  39. private times = 0;
  40. private maxNum = 14;
  41. private isCanCash = false;
  42. private isRefreshTask = false;
  43. private btnCD = 0;
  44. private startTimes = false;
  45. start() {
  46. mk.console.logSingle('redBagTask=>', gData.gameData.playerProp.userFarmTaskInfo);
  47. if (!gData.gameData.playerProp.userFarmTaskInfo) {
  48. return;
  49. }
  50. gData.gameData.init_redBagTask = false;
  51. this.maxNum = gData.gameData.playerProp.userFarmTaskInfo.taskCount;
  52. //this.isShowNewTask = gData.gameData.init_redBagTask;
  53. if (this.isShowNewTask) {
  54. this.showNewTaskUI();
  55. } else {
  56. //this.node_value.active = true;
  57. //this.node_task.active = true;
  58. //this.node_cash.node.active = true;
  59. this.initTaskProgressUI();
  60. this.showChangePart();
  61. }
  62. this.initCashOutStyle(gData.gameData.playerProp.redMoney);
  63. mk.event.register("refreshCoin", this.initCashOutStyle.bind(this), this);
  64. }
  65. private showNewTaskUI() {
  66. this.node_value.active = false;
  67. this.node_task.active = false;
  68. this.openBtn_ani.node.active = false;
  69. this.lbl_Ani.node.active = true;
  70. //gData.gameData.init_redBagTask = false;
  71. gData.gameData.init_task = true;
  72. this.node_hand.active = false;
  73. //gData.gameData.setProp(GameProp.redBagTaskRefresh, gData.gameData.init_redBagTask)
  74. }
  75. onEnable() {
  76. //mk.ad.showBanner(BannerAdType.banner_click_2);
  77. mk.ad.showNative();
  78. }
  79. onDisable() {
  80. mk.event.remove('refreshCoin', this);
  81. //mk.ad.destoryBanner();
  82. mk.ad.destroyNativeAd();
  83. }
  84. update(dt) {
  85. if (gData.reward.add_redbag_value) {
  86. this.initCashOutStyle(gData.gameData.playerProp.redMoney + gData.reward.add_redbag_value);
  87. }
  88. if (this.isShowNewTask) {
  89. if (this.delayTime <= 0.6) {
  90. this.delayTime += dt;
  91. } else {
  92. this.times += 1;
  93. if (this.times == 2) {
  94. this.times = 0;
  95. this.num += 1;
  96. let randNum = mk.math.random(1, this.maxNum);
  97. this.lbl_Ani.string = randNum.toString();
  98. if (this.num == 14) {
  99. this.lbl_Ani.string = this.maxNum.toString();
  100. this.isShowNewTask = false;
  101. this.lbl_Ani.node.color = new cc.Color(255, 218, 49);
  102. let clone = cc.instantiate(this.lbl_Ani.node);
  103. clone.parent = this.lbl_Ani.node.parent;
  104. cc.tween(clone).to(0.8, { scale: 4.0, opacity: 0 }).call(() => {
  105. clone.active = false;
  106. let worldPos = this.lbl_taskNum.node.parent.convertToWorldSpaceAR(this.lbl_taskNum.node.position);
  107. let pos = this.lbl_taskNum.node.parent.parent.convertToNodeSpaceAR(worldPos);
  108. cc.tween(this.lbl_Ani).to(0.6, { fontSize: 40 }).start();
  109. cc.tween(this.lbl_Ani.node).to(0.6, { position: pos }, cc.easeSineOut()).call(() => {
  110. this.lbl_Ani.node.active = false;
  111. this.node_task.active = true;
  112. cc.tween(this.node_task).by(0.16, { y: -6 }).by(0.1, { y: 6 }).start();
  113. }).start();
  114. this.node_value.active = true;
  115. this.node_value.scale = 0;
  116. cc.tween(this.node_value).to(0.5, { scale: 1.3 }, cc.easeSineOut()).to(0.1, { scale: 1 }).call(() => {
  117. this.openBtn_ani.node.active = true;
  118. // mk.guide.open(2);
  119. this.initTaskProgressUI();
  120. this.showChangePart();
  121. }).start();
  122. }).start();
  123. }
  124. }
  125. }
  126. }
  127. if (gData.gameData.init_redBagTask) {
  128. gData.gameData.init_redBagTask = false;
  129. gData.gameData.init_productTask = true;
  130. this.isRefreshTask = true;
  131. this.showNewTaskUI();
  132. this.isShowNewTask = true;
  133. }
  134. if(this.startTimes)
  135. {
  136. this.btnCD += dt;
  137. if(this.btnCD >= 2)
  138. {
  139. this.startTimes = false;
  140. this.btnCD = 0;
  141. }
  142. }
  143. }
  144. private initTaskProgressUI() {
  145. if (gData.gameData.playerProp.userFarmTaskInfo) {
  146. let com = gData.gameData.playerProp.userFarmTaskInfo.completeCount;
  147. let count = gData.gameData.playerProp.userFarmTaskInfo.taskCount;
  148. let per = com / count;
  149. if (!this.isRefreshTask) {
  150. cc.tween(this.sp_taskProgress).delay(0.2).to(0.2, { fillRange: per }, {
  151. onUpdate: () => {
  152. let num = Math.round(this.sp_taskProgress.fillRange * count);
  153. this.lbl_taskProgress.string = `${num}/${count}`;
  154. }
  155. }).call(() => {
  156. this.lbl_taskProgress.string = `${com}/${count}`;
  157. }).start();
  158. } else {
  159. this.sp_taskProgress.fillRange = per;
  160. this.lbl_taskProgress.string = `${com}/${count}`;
  161. }
  162. this.lbl_taskNum.string = count.toString();
  163. let gray = this.openBtn_ani.getComponent(SetGray);
  164. if (gray && com < count) {
  165. gray.setGray(true, true);
  166. //this.openBtn_ani.getComponent(cc.Button).interactable = true;
  167. }
  168. this.isCanCash = com >= count;
  169. this.node_hand.active = this.isCanCash;
  170. if (this.isCanCash && gData.adData.checkShowVideoIcon()) {
  171. this.node_videoIcon.active = true;
  172. } else {
  173. this.node_videoIcon.active = false;
  174. }
  175. }
  176. }
  177. showChangePart() {
  178. //this.changePart.active = true
  179. let len = this.lbl_value.length;
  180. this.schedule(() => {
  181. for (var i = 0; i < len; i++) {
  182. let ran = Util.rnd(0, 9);
  183. this.lbl_value[i].string = `${ran}`;
  184. }
  185. }, 0.1)
  186. }
  187. /**
  188. * 底部提现相关样式
  189. */
  190. private initCashOutStyle(redMoney: number = 0) {
  191. if (redMoney == 0) {
  192. redMoney = gData.gameData.playerProp.redMoney;
  193. }
  194. redMoney = redMoney / 100;
  195. const cash_bar = gData.redBagCash.cash_bar;
  196. let cash_data = gData.redBagCash.getItemDataByIndex(cash_bar);
  197. if (!cash_data) return;
  198. const newRedMoney = redMoney > cash_data.redMoney ? cash_data.redMoney : redMoney;
  199. this.lbl_reward_value.string = cash_data.money / 100 + '元';
  200. this.lbl_progress.string = newRedMoney + '/' + cash_data.redMoney / 100;
  201. const fillRange = newRedMoney / cash_data.redMoney >= 1 ? 1 : newRedMoney / (cash_data.redMoney / 100);
  202. // this.spr_cash_out.fillRange = fillRange;
  203. cc.tween(this.spr_cash_out).to(fillRange, { fillRange: fillRange }).start();
  204. if (redMoney >= cash_data.redMoney) {
  205. this.node_cash.play();
  206. } else {
  207. this.node_cash.stop();
  208. }
  209. }
  210. private clickVideoBtn() {
  211. }
  212. private clickGetRewardBtn() {
  213. //gData.receiptNotice.receip_rmb = gData.blessingBag.rbNum;
  214. //mk.ui.openPanel('module/newNotice/newNotice');
  215. if(!this.startTimes)
  216. {
  217. this.startTimes = true;
  218. this.btnCD = 0;
  219. }else{
  220. return;
  221. }
  222. mk.audio.playEffect("button");
  223. if (this.isCanCash) {
  224. if (cc.sys.isNative) {
  225. if (!gData.loginData.isAuth) {
  226. // JsbSystem.WxAuth();
  227. gData.gameData.authUIType = 0;
  228. mk.ui.openPanel('module/authUI/authUI');
  229. return;
  230. }
  231. }
  232. this.httpCashOut();
  233. } else {
  234. mk.tip.pop('完成任务即可提现');
  235. }
  236. }
  237. private async httpCashOut() {
  238. // gData.cashPro.openCashPro(0);
  239. let data = {};
  240. let response = await mk.http.sendData('farmTask/farmTaskCash', data);
  241. mk.console.logSingle('redBagTask=>', response);
  242. if (response.errcode != 0) {
  243. // gData.cashPro.init_fail = true;
  244. if(response.errcode == 405)
  245. {
  246. mk.tip.pop("今日提现额度已到上限,请明天再提现");
  247. mk.data.sendDataEvent(DataEventId.cashLimit, "提现触发上限");
  248. }
  249. return;
  250. }
  251. mk.console.logSingle('redBagTaskhttpCashOut=>', response.data.userFarmTaskInfo);
  252. gData.gameData.playerProp.userFarmTaskInfo = response.data.userFarmTaskInfo;
  253. gData.gameData.playerProp.completeFarmTaskTimes = response.data.completeFarmTaskTimes;
  254. mk.event.emit("refreshBubble");
  255. mk.data.setTAEventUser(0, 'Cumulative_task', gData.gameData.playerProp.completeFarmTaskTimes);
  256. //gData.gameData.init_redBagTask = true;
  257. gData.gameData.checkTaskFinishUnLock();
  258. gData.gameData.init_task = true;
  259. this.maxNum = gData.gameData.playerProp.userFarmTaskInfo.taskCount;
  260. this.num = 0;
  261. this.delayTime = 0;
  262. this.times = 0;
  263. //this.showNewTaskUI();
  264. //this.isShowNewTask = true;
  265. // gData.cashPro.cashPro_money = response.data.cashMoney;
  266. // gData.cashPro.init_success = true;
  267. gData.receiptNotice.receip_rmb = response.data.cashMoney;
  268. mk.ui.openPanel('module/newNotice/newNotice');
  269. mk.data.sendDataEvent(DataEventId.Sundry, '任务红包提现成功');
  270. let value = mk.storage.getStorage('guide_harvest');
  271. if (!value) {
  272. mk.storage.setStorage('guide_harvest', 1);
  273. mk.data.sendXYEvent('guide_harvest', '首次领取任务红包');
  274. }
  275. gData.gameData.doPointToXYLogic();
  276. //gData.gameData.addCashOutTimes();
  277. gData.adData.checkPopCashFull();
  278. //gData.safeDepositBoxData.updateQipao();
  279. gData.cashNormal.getRecord();
  280. }
  281. /**
  282. * 提现操作
  283. */
  284. private clickCashOut() {
  285. mk.audio.playEffect("button");
  286. gData.reward.addReward();
  287. //mk.ui.closePanel(this.node.name);
  288. let path = 'module/newCashUI/walletCashOut';
  289. mk.ui.openPanel(path);
  290. }
  291. private clickCloseBtn() {
  292. mk.audio.playEffect("button");
  293. }
  294. onDestroy(){
  295. //gData.adData.checkPopInter(InterAdType.interstitial1_click_5);
  296. gData.gameData.popTableScreenADLogic(4);
  297. }
  298. }