GameShop.js 8.4 KB

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