GameShop.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. const DWTool = require("../utils/DWTool");
  2. const AlertManager = require('../utils/AlertManager');
  3. const StoreApi = require('../net/StoreApi');
  4. const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
  5. const TapTapTool = require("../utils/TapTapTool");
  6. const GameModule = require("../utils/GameModule");
  7. cc.Class({
  8. extends: cc.Component,
  9. properties: {
  10. },
  11. // LIFE-CYCLE CALLBACKS:
  12. onLoad () {
  13. GameEvent.on('store_buy_coin_updateDiamond', this, () => {
  14. /// 说明前面没有这个商品
  15. if (this._diamondShopCoinTime === 0) {
  16. let objc2 = {'n': 2, 'e': 0};
  17. GameModule.userInfo.perpetualMt = TapTapTool.multiple(GameModule.userInfo.perpetualMt, objc2);
  18. GameModule.userInfo.perpetualClickMt = TapTapTool.multiple(GameModule.userInfo.perpetualClickMt, objc2);
  19. let objct = {'cdTime': this._diamondShopCoinTime * 1000, 'desc': '所有金币产量增加2倍,持续15分钟', 'icon': 900004, 'sId': 12, 'type': 1};
  20. Global._timeInformations.push(objct);
  21. GameEvent.fire(GameNotificationKey.GameUpdateMessageList, 1, true);
  22. GameModule.skill.updateClickGold();
  23. GameModule.userInfo.refreshSecondText();
  24. } else {
  25. for(let i = 0; i < Global._timeInformations.length; ++i) {
  26. let information = Global._timeInformations[i];
  27. if (information.type == 1 && information.sId == 12) {
  28. information.cdTime += 15 * 60 * 1000;
  29. break;
  30. }
  31. }
  32. }
  33. this._diamondShopCoinTime += 15 * 60;
  34. if (!this._isTimer) {
  35. this.schedule(this.timeAction, 1);
  36. }
  37. });
  38. let shops = Global.shops;
  39. this._mtArr = [];
  40. this._useTimeArr = [];
  41. this._diamondShopCoinTime = 0;
  42. if (shops == undefined || shops.length == 0) {
  43. return;
  44. }
  45. for (let i = 0; i < shops.length; ++ i) {
  46. let shop = shops[i];
  47. /// 没有显示过 那么就显示弹窗
  48. if (shop.isAlert == 0) {
  49. let iconPath = './textures/store/' + shop.picId;
  50. let desc = shop.desc + '';
  51. let stringArr = desc.split('n');
  52. if (stringArr.length > 1) {
  53. desc = stringArr[0] + '<br/>' + stringArr[1];
  54. }
  55. AlertManager.showCommonAlert(iconPath, desc, shop.name);
  56. /// 如果商品id小于等于0什么都不做
  57. if (shop.shopId > 0) {
  58. this.reportShop(shop.shopId);
  59. }
  60. }
  61. /// 如果有时间并且有cd剩余时间
  62. if (shop.minuteTime > 0 && shop.cdTime > 0) {
  63. if(shop.shopId == 12) {
  64. this._diamondShopCoinTime = shop.cdTime / 1000;
  65. } else {
  66. this._useTimeArr.push(shop.cdTime / 1000);
  67. this._mtArr.push(shop.mt);
  68. }
  69. GameModule.userInfo.perpetualMt = TapTapTool.multiple(GameModule.userInfo.perpetualMt, {'e': 0, 'n': shop.mt});
  70. GameModule.userInfo.perpetualClickMt = TapTapTool.multiple(GameModule.userInfo.perpetualClickMt, {'e': 0, 'n': shop.mt});
  71. GameModule.skill.updateClickGold();
  72. GameModule.userInfo.refreshSecondText();
  73. }
  74. /// 说明是礼包类型
  75. if (shop.type == 4) {
  76. GameModule.userInfo.perpetualMt = TapTapTool.multiple(GameModule.userInfo.perpetualMt, {'e': 0, 'n': shop.mt});
  77. GameModule.userInfo.perpetualClickMt = TapTapTool.multiple(GameModule.userInfo.perpetualClickMt, {'e': 0, 'n': shop.mt});
  78. GameModule.skill.updateClickGold();
  79. GameModule.userInfo.refreshSecondText();
  80. }
  81. //// 如果是长按点击的商品
  82. if (shop.shopId == 4) {
  83. Global.isLongPressClick = true;
  84. }
  85. }
  86. this._isTimer = false;
  87. if (this._useTimeArr.length > 0 || this._diamondShopCoinTime > 0) {
  88. this.schedule(this.timeAction, 1);
  89. this._isTimer = true;
  90. }
  91. },
  92. timeAction () {
  93. let newArr = this._useTimeArr.filter((n) => {
  94. return n > 0;
  95. })
  96. if (newArr.length <= 0 && this._diamondShopCoinTime <= 0) {
  97. this.unschedule(this.timeAction, this);
  98. this._isTimer = false;
  99. return;
  100. }
  101. if (this._diamondShopCoinTime > 0) {
  102. this._diamondShopCoinTime -= 1;
  103. if (this._diamondShopCoinTime <= 0) {
  104. GameModule.userInfo.perpetualMt = TapTapTool.multiple(GameModule.userInfo.perpetualMt, {'e': 0, 'n': 0.5});
  105. GameModule.userInfo.perpetualClickMt = TapTapTool.multiple(GameModule.userInfo.perpetualClickMt, {'e': 0, 'n': 0.5});
  106. GameModule.skill.updateClickGold();
  107. GameModule.userInfo.refreshSecondText();
  108. }
  109. }
  110. for (let i = 0; i < newArr.length; ++i) {
  111. this._useTimeArr[i] -= 1;
  112. if (this._useTimeArr[0] <= 0) {
  113. GameModule.userInfo.perpetualMt = TapTapTool.division(GameModule.userInfo.perpetualMt, {'e': 0, 'n': this._mtArr[i]});
  114. GameModule.userInfo.perpetualClickMt = TapTapTool.division(GameModule.userInfo.perpetualClickMt, {'e': 0, 'n': this._mtArr[i]});
  115. GameModule.skill.updateClickGold();
  116. GameModule.userInfo.refreshSecondText();
  117. }
  118. }
  119. },
  120. reportShop(shopId) {
  121. return new Promise((resolve, reject) => {
  122. //// 购买明星
  123. StoreApi.reportShop(shopId, (respondData) => {
  124. resolve(respondData);
  125. }, (code, msg) => {
  126. reject({code, msg});
  127. });
  128. });
  129. },
  130. // update (dt) {},
  131. });