GameShop.js 8.3 KB

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