GameShop.js 7.0 KB

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