GameShop.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. this.setUpNotification();
  14. this.handelUserShops();
  15. GameModule.userInfo.shop = this;
  16. },
  17. handelUserShops() {
  18. let shops = Global.shops;
  19. this._mtArr = [];
  20. this._useTimeArr = [];
  21. this._diamondShopCoinTime = 0;
  22. if (shops == undefined || shops.length == 0) {
  23. return;
  24. }
  25. for (let i = 0; i < shops.length; ++ i) {
  26. let shop = shops[i];
  27. this.handelShop(shop);
  28. }
  29. this.updateTimeSchedule();
  30. },
  31. /// 设置通知
  32. setUpNotification() {
  33. GameEvent.on('store_buy_coin_updateDiamond', this, () => {
  34. /// 说明前面没有这个商品
  35. if (this._diamondShopCoinTime === 0) {
  36. let objc2 = {'n': 2, 'e': 0};
  37. GameModule.userInfo.perpetualMt = TapTapTool.multiple(GameModule.userInfo.perpetualMt, objc2);
  38. GameModule.userInfo.perpetualClickMt = TapTapTool.multiple(GameModule.userInfo.perpetualClickMt, objc2);
  39. let objct = {'cdTime': 15 * 60 * 1000, 'desc': '所有金币产量增加2倍,持续15分钟', 'icon': 900004, 'sId': 12, 'type': 1};
  40. Global._timeInformations.push(objct);
  41. GameEvent.fire(GameNotificationKey.GameUpdateMessageList, 1, true);
  42. GameModule.skill.updateClickGold();
  43. GameModule.userInfo.refreshSecondText();
  44. } else {
  45. for(let i = 0; i < Global._timeInformations.length; ++i) {
  46. let information = Global._timeInformations[i];
  47. if (information.type == 1 && information.sId == 12) {
  48. information.cdTime += 15 * 60 * 1000;
  49. break;
  50. }
  51. }
  52. }
  53. this._diamondShopCoinTime += 15 * 60;
  54. if (!this._isTimer) {
  55. this.schedule(this.timeAction, 1);
  56. }
  57. });
  58. },
  59. /// 看是否需要添加定时器
  60. updateTimeSchedule() {
  61. this._isTimer = false;
  62. if (this._useTimeArr.length > 0 || this._diamondShopCoinTime > 0) {
  63. this.schedule(this.timeAction, 1);
  64. this._isTimer = true;
  65. }
  66. },
  67. ///根据商品信息作出处理
  68. handelShop(shop) {
  69. /// 没有显示过 那么就显示弹窗
  70. if (shop.isAlert == 0) {
  71. let iconPath = './textures/store/' + shop.picId;
  72. let desc = shop.desc + '';
  73. let stringArr = desc.split('n');
  74. if (stringArr.length > 1) {
  75. desc = stringArr[0] + '<br/>' + stringArr[1];
  76. }
  77. /// 如果是每天获取钻石的数量 那么点击确定之后才更新砖石数量
  78. if (shop.shopId === 0 && shop.diamond !== undefined && shop.diamond > 0) {
  79. AlertManager.showGetDiamondEveryDayAlert(iconPath, desc, shop.name, shop.diamond);
  80. } else {
  81. AlertManager.showCommonAlert(iconPath, desc, shop.name);
  82. }
  83. /// 如果商品id小于等于0什么都不做
  84. if (shop.shopId > 0) {
  85. this.reportShop(shop.shopId);
  86. }
  87. }
  88. /// 如果有时间并且有cd剩余时间
  89. if (shop.minuteTime > 0 && shop.cdTime > 0) {
  90. if(shop.shopId == 12) {
  91. this._diamondShopCoinTime = shop.cdTime / 1000;
  92. } else {
  93. this._useTimeArr.push(shop.cdTime / 1000);
  94. this._mtArr.push(shop.mt);
  95. }
  96. GameModule.userInfo.perpetualMt = TapTapTool.multiple(GameModule.userInfo.perpetualMt, {'e': 0, 'n': shop.mt});
  97. GameModule.userInfo.perpetualClickMt = TapTapTool.multiple(GameModule.userInfo.perpetualClickMt, {'e': 0, 'n': shop.mt});
  98. GameModule.skill.updateClickGold();
  99. GameModule.userInfo.refreshSecondText();
  100. }
  101. /// 说明是礼包类型
  102. if (shop.type == 4) {
  103. GameModule.userInfo.perpetualMt = TapTapTool.multiple(GameModule.userInfo.perpetualMt, {'e': 0, 'n': shop.mt});
  104. GameModule.userInfo.perpetualClickMt = TapTapTool.multiple(GameModule.userInfo.perpetualClickMt, {'e': 0, 'n': shop.mt});
  105. GameModule.skill.updateClickGold();
  106. GameModule.userInfo.refreshSecondText();
  107. }
  108. //// 如果是长按点击的商品
  109. if (shop.shopId == 4) {
  110. Global.isLongPressClick = true;
  111. }
  112. },
  113. /// 处理商品的信息流信息
  114. handleShpDataToMessageList(shopData) {
  115. /// 如果有时间并且有cd剩余时间
  116. if (shopData.minuteTime > 0 && shopData.cdTime > 0) {
  117. let desc = shopData.desc + '';
  118. let shopObjc = {'cdTime': shopData.cdTime * 1000, 'desc': desc, 'icon': shopData.icon, 'sId': shopData.shopId, 'type': 1};
  119. Global._timeInformations.push(shopObjc);
  120. GameEvent.fire(GameNotificationKey.GameUpdateMessageList, 1, true);
  121. /// 说明不是需要时间cd的
  122. } else {
  123. let shopObjc = {'cdTime': -6 * 1000, 'desc': '获得' + shopData.name, 'icon': shopData.icon, 'sId': shopData.shopId, 'type': 1};
  124. Global._fixInformations.push(shopObjc);
  125. GameEvent.fire(GameNotificationKey.GameUpdateMessageList, 1);
  126. }
  127. },
  128. timeAction () {
  129. let newArr = this._useTimeArr.filter((n) => {
  130. return n > 0;
  131. })
  132. if (newArr.length <= 0 && this._diamondShopCoinTime <= 0) {
  133. this.unschedule(this.timeAction, this);
  134. this._isTimer = false;
  135. return;
  136. }
  137. if (this._diamondShopCoinTime > 0) {
  138. this._diamondShopCoinTime -= 1;
  139. if (this._diamondShopCoinTime <= 0) {
  140. GameModule.userInfo.perpetualMt = TapTapTool.multiple(GameModule.userInfo.perpetualMt, {'e': 0, 'n': 0.5});
  141. GameModule.userInfo.perpetualClickMt = TapTapTool.multiple(GameModule.userInfo.perpetualClickMt, {'e': 0, 'n': 0.5});
  142. GameModule.skill.updateClickGold();
  143. GameModule.userInfo.refreshSecondText();
  144. }
  145. }
  146. for (let i = 0; i < newArr.length; ++i) {
  147. this._useTimeArr[i] -= 1;
  148. if (this._useTimeArr[0] <= 0) {
  149. GameModule.userInfo.perpetualMt = TapTapTool.division(GameModule.userInfo.perpetualMt, {'e': 0, 'n': this._mtArr[i]});
  150. GameModule.userInfo.perpetualClickMt = TapTapTool.division(GameModule.userInfo.perpetualClickMt, {'e': 0, 'n': this._mtArr[i]});
  151. GameModule.skill.updateClickGold();
  152. GameModule.userInfo.refreshSecondText();
  153. }
  154. }
  155. },
  156. reportShop(shopId) {
  157. return new Promise((resolve, reject) => {
  158. //// 购买明星
  159. StoreApi.reportShop(shopId, (respondData) => {
  160. resolve(respondData);
  161. }, (code, msg) => {
  162. reject({code, msg});
  163. });
  164. });
  165. },
  166. // update (dt) {},
  167. });