DrawStarSuccss.js 7.9 KB

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