GameShop.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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': 15 * 60 * 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. GameModule.userInfo.shop = this;
  39. let shops = Global.shops;
  40. this._mtArr = [];
  41. this._useTimeArr = [];
  42. this._diamondShopCoinTime = 0;
  43. if (shops == undefined || shops.length == 0) {
  44. return;
  45. }
  46. for (let i = 0; i < shops.length; ++ i) {
  47. let shop = shops[i];
  48. this.handelShop(shop);
  49. }
  50. this.updateTimeSchedule();
  51. },
  52. /// 看是否需要添加定时器
  53. updateTimeSchedule() {
  54. this._isTimer = false;
  55. if (this._useTimeArr.length > 0 || this._diamondShopCoinTime > 0) {
  56. this.schedule(this.timeAction, 1);
  57. this._isTimer = true;
  58. }
  59. },
  60. ///根据商品信息作出处理
  61. handelShop(shop) {
  62. /// 没有显示过 那么就显示弹窗
  63. if (shop.isAlert == 0) {
  64. let iconPath = './textures/store/' + shop.picId;
  65. let desc = shop.desc + '';
  66. let stringArr = desc.split('n');
  67. if (stringArr.length > 1) {
  68. desc = stringArr[0] + '<br/>' + stringArr[1];
  69. }
  70. AlertManager.showCommonAlert(iconPath, desc, shop.name);
  71. /// 如果商品id小于等于0什么都不做
  72. if (shop.shopId > 0) {
  73. this.reportShop(shop.shopId);
  74. }
  75. }
  76. /// 如果有时间并且有cd剩余时间
  77. if (shop.minuteTime > 0 && shop.cdTime > 0) {
  78. if(shop.shopId == 12) {
  79. this._diamondShopCoinTime = shop.cdTime / 1000;
  80. } else {
  81. this._useTimeArr.push(shop.cdTime / 1000);
  82. this._mtArr.push(shop.mt);
  83. }
  84. GameModule.userInfo.perpetualMt = TapTapTool.multiple(GameModule.userInfo.perpetualMt, {'e': 0, 'n': shop.mt});
  85. GameModule.userInfo.perpetualClickMt = TapTapTool.multiple(GameModule.userInfo.perpetualClickMt, {'e': 0, 'n': shop.mt});
  86. GameModule.skill.updateClickGold();
  87. GameModule.userInfo.refreshSecondText();
  88. }
  89. /// 说明是礼包类型
  90. if (shop.type == 4) {
  91. GameModule.userInfo.perpetualMt = TapTapTool.multiple(GameModule.userInfo.perpetualMt, {'e': 0, 'n': shop.mt});
  92. GameModule.userInfo.perpetualClickMt = TapTapTool.multiple(GameModule.userInfo.perpetualClickMt, {'e': 0, 'n': shop.mt});
  93. GameModule.skill.updateClickGold();
  94. GameModule.userInfo.refreshSecondText();
  95. }
  96. //// 如果是长按点击的商品
  97. if (shop.shopId == 4) {
  98. Global.isLongPressClick = true;
  99. }
  100. },
  101. /// 处理商品的信息流信息
  102. handleShpDataToMessageList(shopData) {
  103. /// 如果有时间并且有cd剩余时间
  104. if (shop.minuteTime > 0 && shop.cdTime > 0) {
  105. let desc = shop.desc + '';
  106. let stringArr = desc.split('n');
  107. if (stringArr.length > 1) {
  108. desc = stringArr[0] + stringArr[1];
  109. }
  110. let shopObjc = {'cdTime': shop.cdTime * 1000, 'desc': desc, 'icon': shop.icon, 'sId': shopData.shopId, 'type': 1};
  111. Global._timeInformations.push(shopObjc);
  112. GameEvent.fire(GameNotificationKey.GameUpdateMessageList, 1, true);
  113. /// 说明不是需要时间cd的
  114. } else {
  115. let shopObjc = {'cdTime': -6 * 1000, 'desc': '获得' + shop.name, 'icon': shop.icon, 'sId': shopData.shopId, 'type': 1};
  116. Global._fixInformations.push(shopObjc);
  117. GameEvent.fire(GameNotificationKey.GameUpdateMessageList, 1);
  118. }
  119. },
  120. timeAction () {
  121. let newArr = this._useTimeArr.filter((n) => {
  122. return n > 0;
  123. })
  124. if (newArr.length <= 0 && this._diamondShopCoinTime <= 0) {
  125. this.unschedule(this.timeAction, this);
  126. this._isTimer = false;
  127. return;
  128. }
  129. if (this._diamondShopCoinTime > 0) {
  130. this._diamondShopCoinTime -= 1;
  131. if (this._diamondShopCoinTime <= 0) {
  132. GameModule.userInfo.perpetualMt = TapTapTool.multiple(GameModule.userInfo.perpetualMt, {'e': 0, 'n': 0.5});
  133. GameModule.userInfo.perpetualClickMt = TapTapTool.multiple(GameModule.userInfo.perpetualClickMt, {'e': 0, 'n': 0.5});
  134. GameModule.skill.updateClickGold();
  135. GameModule.userInfo.refreshSecondText();
  136. }
  137. }
  138. for (let i = 0; i < newArr.length; ++i) {
  139. this._useTimeArr[i] -= 1;
  140. if (this._useTimeArr[0] <= 0) {
  141. GameModule.userInfo.perpetualMt = TapTapTool.division(GameModule.userInfo.perpetualMt, {'e': 0, 'n': this._mtArr[i]});
  142. GameModule.userInfo.perpetualClickMt = TapTapTool.division(GameModule.userInfo.perpetualClickMt, {'e': 0, 'n': this._mtArr[i]});
  143. GameModule.skill.updateClickGold();
  144. GameModule.userInfo.refreshSecondText();
  145. }
  146. }
  147. },
  148. reportShop(shopId) {
  149. return new Promise((resolve, reject) => {
  150. //// 购买明星
  151. StoreApi.reportShop(shopId, (respondData) => {
  152. resolve(respondData);
  153. }, (code, msg) => {
  154. reject({code, msg});
  155. });
  156. });
  157. },
  158. // update (dt) {},
  159. });