TaskActive.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { _decorator, Component, Node, ProgressBar, EventTouch, UIOpacity, Sprite, SpriteFrame } from 'cc';
  2. import { Http } from '../../core/net/Http';
  3. import { ResourcesUtils } from '../../core/resourceManager/ResourcesUtils';
  4. import { OpenWindow } from '../../core/ui/window/OpenWindow';
  5. import { WindowManager } from '../../core/ui/window/WindowManager';
  6. import { WindowOpenMode } from '../../core/ui/window/WindowOpenMode';
  7. import { Utils } from '../../core/utils/Utils';
  8. import { g } from '../../Data/g';
  9. import { HttpErrorCode } from '../../Data/HttpErrorCode';
  10. import { platform } from '../../Data/platform';
  11. import { GetType } from '../GetWindow/GetType';
  12. const { ccclass, property } = _decorator;
  13. @ccclass('TaskActive')
  14. export class TaskActive extends Component {
  15. @property({ type: ProgressBar, tooltip: "活跃度进度条" }) activeProgress: ProgressBar;
  16. @property({ type: [Node], tooltip: "宝箱节点集合" }) cubeNodes: Array<Node> = [];
  17. // @property({ type: [Node], tooltip: "星星节点集合" }) starNodes: Array<Node> = [];
  18. @property({ tooltip: "网络请求对象", type: Http }) http: Http;
  19. private data: any;
  20. public async setData(active: any) {
  21. this.data = active;
  22. this.activeProgress.progress = this.data.value / 100;
  23. let starCount = Math.floor(this.data.value / 20);
  24. for (let i = 0; i < starCount; i++) {
  25. // this.starNodes[i].active = true;
  26. (this.cubeNodes[i] && this.cubeNodes[i].getComponent(UIOpacity)) && (this.cubeNodes[i].getComponent(UIOpacity).opacity = 255);
  27. }
  28. for (let i = 0; i < 4; i++) {
  29. if (this.data["box" + i]) {
  30. this.cubeNodes[i].getComponent(Sprite).spriteFrame = await ResourcesUtils.load("Images/TaskWindow/task_cube_open/spriteFrame", SpriteFrame, this.node);
  31. this.cubeNodes[i].getComponent(UIOpacity).opacity = 150;
  32. }
  33. }
  34. }
  35. public async onCubeClick(e: EventTouch, num: string) {
  36. let touchNum = parseInt(num)
  37. if (!this.data["box" + num] && touchNum < Math.floor(this.data.value / 20)) {
  38. if (touchNum < 4) {
  39. let result = await this.http.send("/api/task/activeBoxReceive", { index: num, adData: g.adData });
  40. if (result.code == 0) {
  41. this.cubeNodes[num].getComponent(Sprite).spriteFrame = await ResourcesUtils.load("Images/TaskWindow/task_cube_open/spriteFrame", SpriteFrame, this.node);
  42. this.cubeNodes[num].getComponent(UIOpacity).opacity = 150;
  43. if (result.data.diamond > 0) {
  44. platform.reportThinking("diamond_increase", JSON.stringify({ previous_number: g.userData.diamond, increase_number: result.data.diamond, current_number: g.userData.diamond + result.data.diamond, reasons: "activeBoxReceive" }));
  45. WindowManager.open("Prefabs/GetWindow", WindowOpenMode.NotCloseAndAdd, [{ count: result.data.diamond, type: GetType.Diamond, needBezierEffect: true }], this.node.parent.parent);
  46. } else {
  47. platform.reportThinking("envelope_increase", JSON.stringify({ previous_number: g.userData.bonus, increase_number: result.data.bonus, current_number: g.userData.bonus + result.data.bonus, reasons: "activeBoxReceive" }));
  48. WindowManager.open("Prefabs/GetWindow", WindowOpenMode.NotCloseAndAdd, [{ count: result.data.bonus, type: GetType.RedBag, needBezierEffect: true }], this.node.parent.parent);
  49. }
  50. } else if (result.code == HttpErrorCode.VideoADCD) {
  51. WindowManager.showTips("请求频繁,请稍后再试");
  52. }
  53. } else {
  54. let result = await this.http.send("/api/ad/watchVideoAD");
  55. if (result.code == 0) {
  56. //播放视频
  57. platform.reportThinking("ad_init", JSON.stringify({ ad_id: "task_active", ad_time: Utils.formatDate(new Date()), id: g.userData.id, role_name: g.userData.nickName, level: g.userData.getLevel() }));
  58. //播放视频
  59. let adData = await g.showRewardVideo();
  60. if (adData) {
  61. this.onVideoOver();
  62. } else {
  63. //视频观看失败
  64. WindowManager.showTips("视频观看时间不足");
  65. }
  66. } else if (result.code == 106) {
  67. WindowManager.showTips("今日视频次数已用完,请明日再继续");
  68. } else if (result.code == HttpErrorCode.VideoADCD) {
  69. WindowManager.showTips("请求频繁,请稍后再试");
  70. } else {
  71. WindowManager.showTips("视频准备中,请稍后再试");
  72. }
  73. }
  74. }
  75. }
  76. public async onVideoOver() {
  77. let result = await this.http.send("/api/task/activeBoxReceive", { index: 4, adData: g.adData });
  78. if (result.code == 0) {
  79. platform.reportThinking("ad_end", JSON.stringify({ ad_id: "task_active", ad_time: Utils.formatDate(new Date()), id: g.userData.id, role_name: g.userData.nickName, level: g.userData.getLevel(), award: result.data.bonus }));
  80. platform.reportThinking("envelope_increase", JSON.stringify({ previous_number: g.userData.bonus, increase_number: result.data.bonus, current_number: g.userData.bonus + result.data.bonus, reasons: "activeBoxReceive" }));
  81. WindowManager.open("Prefabs/GetWindow", WindowOpenMode.NotCloseAndAdd, [{ count: result.data.bonus, type: GetType.RedBag, needBezierEffect: true }], this.node.parent.parent);
  82. } else if (result.code == HttpErrorCode.VideoADCD) {
  83. WindowManager.showTips("请求频繁,请稍后再试");
  84. }
  85. }
  86. }