DrawStarSuccss.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. const DrawApi = require("../net/DrawApi");
  2. const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
  3. const GameModule = require("../utils/GameModule");
  4. const DWTool = require("../utils/DWTool");
  5. const lottery = require('../data/lottery');
  6. const TapTapTool = require("../utils/TapTapTool");
  7. cc.Class({
  8. extends: cc.Component,
  9. properties: {
  10. starNameLabel: cc.Label,
  11. bottomTitleLabel: cc.Label,
  12. starNode: cc.Node,
  13. againButton: cc.Button,
  14. againRichText: cc.RichText,
  15. againSprite: cc.Sprite,
  16. },
  17. // LIFE-CYCLE CALLBACKS:
  18. onLoad () {
  19. this._localDrawStarDatas = lottery;
  20. },
  21. start () {
  22. },
  23. init(drawData, typeId) {
  24. this.typeId = typeId;
  25. this.drawData = drawData;
  26. let drawSuccessData = drawData.drawSuccessData;
  27. let nameString = '获得';
  28. let desc = '';
  29. let starId = -1;
  30. /// 抽奖获得金币数
  31. if (drawSuccessData.type == 1) {
  32. let rate = TapTapTool.multiple(GameModule.skill.multiple, GameModule.userInfo.perpetualMt);
  33. rate = TapTapTool.multiple(rate, {'n': GameModule.shop.multiple, 'e': 0});
  34. let add = TapTapTool.multiple(rate, GameModule.userInfo.rateGold);
  35. add = TapTapTool.multiple(add, drawSuccessData.opt);
  36. GameModule.userInfo.gold = TapTapTool.add(GameModule.userInfo.gold, add);
  37. nameString += `金币 ${TapTapTool.parseToString(add)}`;
  38. ///抽奖获得金币 强制上报一次
  39. if (GameModule.userInfo) {
  40. GameModule.userInfo.doReport();
  41. }
  42. /// 如果是抽到了钻石
  43. } else if (drawSuccessData.type == 2) {
  44. GameModule.userInfo.diamond += drawSuccessData.opt;
  45. nameString += `钻石 ${drawSuccessData.opt}`;
  46. /// 如果是红包
  47. } else if (drawSuccessData.type == 4) {
  48. Global.userData.hb += drawSuccessData.hb;
  49. nameString += ` ${(drawSuccessData.hb / 100).toFixed(2)}元`;
  50. desc += '红包满十元可提现噢~';
  51. /// 如果抽中的是明星
  52. } else if (drawSuccessData.type == 3) {
  53. let starData = lottery.filter((n) => {
  54. return n.propId == drawSuccessData.starId;
  55. })[0];
  56. nameString = '获得 ' + starData.propName;
  57. desc = starData.propName + '加入你的明星图集';
  58. GameModule.userInfo.perpetualClickMt = TapTapTool.multiple(GameModule.userInfo.perpetualClickMt, {'n': starData.mt, 'e': 0});
  59. GameModule.userInfo.perpetualMt = TapTapTool.multiple(GameModule.userInfo.perpetualMt, {'n': starData.mt, 'e': 0});
  60. GameEvent.fire(GameNotificationKey.StarEnterRoom, starData.propId, drawSuccessData.roomId);
  61. starId = starData.propId;
  62. let imageId = 50000 + starId;
  63. let mul = parseInt(starData.mt * 100);
  64. let desc = `<color=#fe4e00>明星奖励</c><br/><br/><img src='skill_click_coin'/><color=#540904>每次点击产出金币提升${mul}%</c><br/><img src='userInfo_rate_coin'/><color=#540904>所有房间产出金币提升${mul}%</c>`;
  65. DWTool.loadResPrefab("./prefabs/common/commonAlert")
  66. .then((result) => {
  67. let alert = cc.instantiate(result);
  68. cc.find('Canvas').addChild(alert);
  69. alert.getComponent('commAlert').initBuyStar(imageId, desc, `${starData.propName}`);
  70. });
  71. }
  72. this.starNameLabel.string = nameString;
  73. this.bottomTitleLabel.string = desc;
  74. let backGroudId = 700000 + drawSuccessData.type;
  75. this.starNode.getComponent("DrawStarContent").init(backGroudId, starId);
  76. if (this.typeId == 1) {
  77. this._diamond = this.drawData.diamond1;
  78. } else if (this.typeId == 2) {
  79. this._diamond = this.drawData.diamond2;
  80. } else {
  81. this._diamond = this.drawData.diamond3;
  82. }
  83. this.againRichText.string = `<img src='skill_diamond'/><b><color=#ffffff> ${this._diamond}</c></b>`;
  84. if (GameModule.userInfo.diamond < this._diamond) {
  85. this.setUpUseBtnBg(false);
  86. }
  87. },
  88. // init(drawData, typeId, backGroudId) {
  89. // this.typeId = typeId;
  90. // this.drawData = drawData;
  91. // this.starNameLabel.string = '获得 ' + drawData.propName;
  92. // this.bottomTitleLabel.string = drawData.propName + '加入你的明星图集';
  93. // this.starNode.getComponent("DrawStarContent").init(backGroudId, drawData.propId);
  94. // if (this.typeId == 1) {
  95. // this._diamond = this.drawData.diamond1;
  96. // } else if (this.typeId == 2) {
  97. // this._diamond = this.drawData.diamond2;
  98. // } else {
  99. // this._diamond = this.drawData.diamond3;
  100. // }
  101. // this.againRichText.string = `<img src='skill_diamond'/><b><color=#ffffff> ${this._diamond}</c></b>`;
  102. // ////发通知 已经获取明星
  103. // GameEvent.fire(GameNotificationKey.StarEnterRoom, this.drawData.propId, this.drawData.roomId);
  104. // console.log(`抽奖获得明星 starid${this.drawData.propId} roomid${this.drawData.roomId}`);
  105. // if (GameModule.userInfo.diamond < this._diamond) {
  106. // this.setUpUseBtnBg(false);
  107. // }
  108. // },
  109. /// 设置签约的button是否能点击 type 123
  110. setUpUseBtnBg(isActive) {
  111. let path = isActive ? './textures/draw/draw_green_btn_bg' : './textures/draw/draw_gray_btn_bg';
  112. this.againButton.interactable = isActive;
  113. DWTool.loadResSpriteFrame(path)
  114. .then((spriteFrame) => {
  115. this.againSprite.spriteFrame = spriteFrame;
  116. });
  117. },
  118. dismissAction () {
  119. GameModule.audioMng.playClickButton();
  120. this.node.destroy();
  121. GameEvent.fire("draw_done_action");
  122. },
  123. scrollAgainAction() {
  124. GameModule.audioMng.playClickButton();
  125. this.againButton.interactable = false
  126. this.startDrawRequest(this.typeId).then((respondData) => {
  127. this.againButton.interactable = true;
  128. GameModule.userInfo.diamond -= this._diamond;
  129. this.node.destroy();
  130. GameEvent.fire("draw_again", respondData);
  131. }).catch(({code, msg}) => {
  132. this.againButton.interactable = true;
  133. cc.log(code, msg);
  134. });
  135. },
  136. startDrawRequest(typeId) {
  137. return new Promise((resolve, reject) => {
  138. ///开始抽奖
  139. DrawApi.startNewLottery(typeId, 1, (respondData) => {
  140. resolve(respondData);
  141. }, (code, msg) => {
  142. reject({code, msg});
  143. });
  144. })
  145. },
  146. // update (dt) {},
  147. });