DrawStarSuccss.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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, GameModule.shop.multiple);
  34. let add = TapTapTool.multiple(rate, GameModule.userInfo.rateGold);
  35. // let add = TapTapTool.multiple(GameModule.userInfo.coinTap, drawSuccessData.opt)
  36. GameModule.userInfo.gold = TapTapTool.add(GameModule.userInfo.gold, add);
  37. nameString += `金币 ${TapTapTool.parseToString(add)}`;
  38. /// 如果是抽到了钻石
  39. } else if (drawSuccessData.type == 2) {
  40. GameModule.userInfo.diamond += drawSuccessData.opt;
  41. nameString += `钻石 ${drawSuccessData.opt}`;
  42. /// 如果是红包
  43. } else if (drawSuccessData.type == 4) {
  44. Global.userData.hb += drawSuccessData.hb;
  45. nameString += ` ${(drawSuccessData.hb / 100).toFixed(2)}元`;
  46. desc += '红包满十元可提现噢~';
  47. /// 如果抽中的是明星
  48. } else if (drawSuccessData.type == 3) {
  49. let starData = lottery.filter((n) => {
  50. return n.propId == drawSuccessData.starId;
  51. })[0];
  52. nameString = '获得 ' + starData.propName;
  53. desc = starData.propName + '加入你的明星图集';
  54. GameModule.userInfo.perpetualClickMt = TapTapTool.multiple(GameModule.userInfo.perpetualClickMt, {'n': starData.mt, 'e': 0});
  55. GameModule.userInfo.perpetualMt = TapTapTool.multiple(GameModule.userInfo.perpetualMt, {'n': starData.mt, 'e': 0});
  56. GameEvent.fire(GameNotificationKey.StarEnterRoom, starData.propId, drawSuccessData.roomId);
  57. starId = starData.propId;
  58. let imageId = 50000 + starId;
  59. let mul = starData.mt * 100;
  60. 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>`;
  61. DWTool.loadResPrefab("./prefabs/common/commonAlert")
  62. .then((result) => {
  63. let alert = cc.instantiate(result);
  64. cc.find('Canvas').addChild(alert);
  65. alert.getComponent('commAlert').initBuyStar(imageId, desc, `${starData.propName}`);
  66. });
  67. }
  68. this.starNameLabel.string = nameString;
  69. this.bottomTitleLabel.string = desc;
  70. let backGroudId = 700000 + drawSuccessData.type;
  71. this.starNode.getComponent("DrawStarContent").init(backGroudId, starId);
  72. if (this.typeId == 1) {
  73. this._diamond = this.drawData.diamond1;
  74. } else if (this.typeId == 2) {
  75. this._diamond = this.drawData.diamond2;
  76. } else {
  77. this._diamond = this.drawData.diamond3;
  78. }
  79. this.againRichText.string = `<img src='skill_diamond'/><b><color=#ffffff> ${this._diamond}</c></b>`;
  80. if (GameModule.userInfo.diamond < this._diamond) {
  81. this.setUpUseBtnBg(false);
  82. }
  83. },
  84. // init(drawData, typeId, backGroudId) {
  85. // this.typeId = typeId;
  86. // this.drawData = drawData;
  87. // this.starNameLabel.string = '获得 ' + drawData.propName;
  88. // this.bottomTitleLabel.string = drawData.propName + '加入你的明星图集';
  89. // this.starNode.getComponent("DrawStarContent").init(backGroudId, drawData.propId);
  90. // if (this.typeId == 1) {
  91. // this._diamond = this.drawData.diamond1;
  92. // } else if (this.typeId == 2) {
  93. // this._diamond = this.drawData.diamond2;
  94. // } else {
  95. // this._diamond = this.drawData.diamond3;
  96. // }
  97. // this.againRichText.string = `<img src='skill_diamond'/><b><color=#ffffff> ${this._diamond}</c></b>`;
  98. // ////发通知 已经获取明星
  99. // GameEvent.fire(GameNotificationKey.StarEnterRoom, this.drawData.propId, this.drawData.roomId);
  100. // console.log(`抽奖获得明星 starid${this.drawData.propId} roomid${this.drawData.roomId}`);
  101. // if (GameModule.userInfo.diamond < this._diamond) {
  102. // this.setUpUseBtnBg(false);
  103. // }
  104. // },
  105. /// 设置签约的button是否能点击 type 123
  106. setUpUseBtnBg(isActive) {
  107. let path = isActive ? './textures/draw/draw_green_btn_bg' : './textures/draw/draw_gray_btn_bg';
  108. this.againButton.interactable = isActive;
  109. DWTool.loadResSpriteFrame(path)
  110. .then((spriteFrame) => {
  111. this.againSprite.spriteFrame = spriteFrame;
  112. });
  113. },
  114. dismissAction () {
  115. GameModule.audioMng.playClickButton();
  116. this.node.destroy();
  117. GameEvent.fire("draw_done_action");
  118. },
  119. scrollAgainAction() {
  120. GameModule.audioMng.playClickButton();
  121. this.againButton.interactable = false
  122. this.startDrawRequest(this.typeId).then((respondData) => {
  123. this.againButton.interactable = true;
  124. GameModule.userInfo.diamond -= this._diamond;
  125. this.node.destroy();
  126. GameEvent.fire("draw_again", respondData);
  127. }).catch(({code, msg}) => {
  128. this.againButton.interactable = true;
  129. cc.log(code, msg);
  130. });
  131. },
  132. startDrawRequest(typeId) {
  133. return new Promise((resolve, reject) => {
  134. ///开始抽奖
  135. DrawApi.startNewLottery(typeId, 1, (respondData) => {
  136. resolve(respondData);
  137. }, (code, msg) => {
  138. reject({code, msg});
  139. });
  140. })
  141. },
  142. // update (dt) {},
  143. });