ActivityGift.ts 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import { _decorator, Component, Node, Label, Sprite, SpriteFrame, Skeleton, sp } from 'cc';
  2. import { RewardVideoSystem } from '../ad/RewardVideoSystem';
  3. import { DataSystem } from '../core/data/DataSystem';
  4. import { Http, HttpResponseCode } from '../core/net/Http';
  5. import { HttpSystem } from '../core/net/HttpSystem';
  6. import { ResourceLoader } from '../core/resourceManager/ResourceLoader';
  7. import { Window } from '../core/ui/window/Window';
  8. import { WindowOpenMode } from '../core/ui/window/WindowOpenMode';
  9. import { WindowSystem } from '../core/ui/window/WindowSystem';
  10. import { ConfigData } from '../data/ConfigData';
  11. import { platform } from '../data/jsb/platform';
  12. import { UserData } from '../data/UserData';
  13. import { ReportThinking } from '../ReportThinking';
  14. import { ActivityInfoData } from './ActivityInfoData';
  15. import { TaskData } from './TaskData';
  16. const { ccclass, property, requireComponent } = _decorator;
  17. /***
  18. * 宝箱奖励领取
  19. */
  20. @ccclass('ActivityGift')
  21. @requireComponent(Http)
  22. export class ActivityGift extends Component {
  23. @property({ type: Node, tooltip: "双倍领取" }) doubleNode: Node;
  24. @property({ type: Node, tooltip: "普通领取" }) singleNode: Node;
  25. @property({ type: Node, tooltip: "普通领取按钮节点" }) getBtnNode: Node;
  26. @property({ type: Label, tooltip: "普通领取" }) numLabel: Label;
  27. @property({ type: Label, tooltip: "视频领取按钮文本" }) btnLabel: Label;
  28. @property({ type: Sprite, tooltip: "普通领取" }) iconSprite: Sprite;
  29. @property({ type: sp.Skeleton, tooltip: "宝箱特效" }) boxSkeleton: sp.Skeleton;
  30. @property({ type: Node, tooltip: "奖励节点" }) giftNode: Node;
  31. private id: number;
  32. private data: any;
  33. private activitys = [];
  34. private async onOpenHandler(data: { id: number }) {
  35. this.id = data.id;
  36. this.data = DataSystem.getData(ConfigData).get('taskActive')[this.id];
  37. // this.boxSkeleton.animation = 'animantion';
  38. let openBox = this.boxSkeleton.addAnimation(0, "animation", false);
  39. openBox && this.boxSkeleton.setTrackCompleteListener(openBox, (e) => {
  40. this.giftNode.active = true;
  41. }
  42. );
  43. let result = await this.getComponent(Http).send('/api/task/OpenTaskActive', { id: this.id });
  44. if (result && result.code == HttpResponseCode.Success) {
  45. this.numLabel.string = result.data.rewardNum + '';
  46. if (result.data.rewardType == 'bonus') {
  47. this.iconSprite.spriteFrame = await this.getComponent(ResourceLoader).load<SpriteFrame>('image/icons/icon1/spriteFrame', SpriteFrame);
  48. } else {
  49. this.iconSprite.spriteFrame = await this.getComponent(ResourceLoader).load<SpriteFrame>('image/icons/icon4/spriteFrame', SpriteFrame);
  50. }
  51. this.activitys = DataSystem.getData(TaskData).activitys;
  52. let d: ActivityInfoData;
  53. for (let i = 0; i < this.activitys.length; i++) {
  54. if (this.activitys[i].id == this.id) {
  55. d = this.activitys[i];
  56. break;
  57. }
  58. }
  59. if (this.data.isdouble) {
  60. if (d.isReceiveSingle) {
  61. this.scheduleOnce(() => {
  62. this.doubleNode.active = true;
  63. }, 2);
  64. } else {
  65. this.scheduleOnce(() => {
  66. this.btnLabel.string = '三倍领取';
  67. this.doubleNode.active = true;
  68. }, 2);
  69. this.scheduleOnce(() => {
  70. this.singleNode.active = true;
  71. }, 5);
  72. }
  73. } else {
  74. this.scheduleOnce(() => {
  75. this.getBtnNode.active = true;
  76. }, 2);
  77. }
  78. }
  79. }
  80. private async onDouble() {
  81. let result = await this.getComponent(Http).send("/api/ad/watchVideoAD");
  82. if (result && result.code == 0) {
  83. ReportThinking.ad_init('activeBox_get');
  84. let adData = await RewardVideoSystem.show();
  85. if (adData) {//观看视频成功
  86. this.onGetGift(true, adData.obj);
  87. } else {//TODO 观看视频失败
  88. }
  89. }
  90. }
  91. private onSingle() {
  92. this.onGetGift();
  93. }
  94. private async onGetGift(isDouble: boolean = false, adData?: any) {
  95. let data;
  96. if (adData) {
  97. data = { id: this.id, isDouble: isDouble, adData: adData };
  98. } else {
  99. data = { id: this.id, isDouble: isDouble };
  100. }
  101. let result = await this.getComponent(Http).send('/api/task/ReceiveTaskActive', data);
  102. if (result && result.code == HttpResponseCode.Success) {
  103. adData && ReportThinking.ad_end('activeBox_get', result.data.rewardType == 'bonus' ? result.data.rewardNum : 0);
  104. // rewardType string 奖励类型(bonus是红包币,money是粮草)
  105. // rewardNum number 奖励数量/
  106. let type: number = 0;
  107. if (result.data.rewardType == 'bonus') {
  108. type = 3;
  109. } else {
  110. type = 1;
  111. }
  112. for (let i = 0; i < this.activitys.length; i++) {
  113. if (this.activitys[i].id == this.id) {
  114. !isDouble && (this.activitys[i].isReceiveSingle = true);
  115. isDouble && (this.activitys[i].isReceiveDouble = true);
  116. }
  117. }
  118. ReportThinking.activity(this.id, result.data.rewardNum);
  119. let userData = DataSystem.getData(UserData);
  120. ReportThinking.currency_increase(result.data.rewardType, userData[result.data.rewardType], result.data.rewardNum, userData[result.data.rewardType] + result.data.rewardNum, 'activebox_get');
  121. DataSystem.getData(TaskData).getActiveBoxGiftNum++;
  122. this.getComponent(Window).close();
  123. WindowSystem.open("prefabs/ui/turntable/prizeFly", WindowOpenMode.NotCloseAndAdd, [{ type: type, num: result.data.rewardNum }]);
  124. }
  125. else if (result && result.code == 104) {
  126. WindowSystem.showTips('活跃度不足');
  127. }
  128. else {
  129. this.getComponent(Window).close();
  130. }
  131. }
  132. }