ShopController.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. var o =
  5. (this && this.__awaiter) ||
  6. function (t, n, r, l) {
  7. return new (r = r || Promise)(function (i, e) {
  8. function s(t) {
  9. try {
  10. a(l.next(t));
  11. } catch (t) {
  12. e(t);
  13. }
  14. }
  15. function o(t) {
  16. try {
  17. a(l.throw(t));
  18. } catch (t) {
  19. e(t);
  20. }
  21. }
  22. function a(t) {
  23. var e;
  24. t.done
  25. ? i(t.value)
  26. : ((e = t.value) instanceof r
  27. ? e
  28. : new r(function (t) {
  29. t(e);
  30. })
  31. ).then(s, o);
  32. }
  33. a((l = l.apply(t, n || [])).next());
  34. });
  35. };
  36. Object.defineProperty(i, "__esModule", { value: !0 });
  37. const a = t("App"),
  38. s = t("BaseController"),
  39. n = t("Toast"),
  40. r = t("ControllerConst"),
  41. l = t("NotificationConst"),
  42. h = (t("ViewConst"), t("LayerManager"), t("ADManageBase"), t("BagConst")),
  43. c = t("BagController"),
  44. d = t("CostumeController"),
  45. u = t("BuffMgr"),
  46. p = t("GameConst"),
  47. f = t("GlobalAttr"),
  48. g = t("CurrencyService"),
  49. m = t("SystemOpenConst"),
  50. _ = t("ShopConst"),
  51. y = t("ShopModle");
  52. i.default = class extends s.default {
  53. constructor() {
  54. super(),
  55. (this.shopView = null),
  56. (this.shopBuffView = null),
  57. (this.shopBuffViewIcon = null),
  58. (this.shopOpenBoxView = null),
  59. (this.shopViewIcon = null),
  60. (this._model = null),
  61. (this.neddOpenCnt = 4),
  62. a.default.ViewManager.register(7, { dir: "shop", prefabName: "ShopView", zIndex: 100, controller: this }),
  63. a.default.ViewManager.register(28, {
  64. dir: "shop",
  65. prefabName: "ShopBuffView",
  66. zIndex: 100,
  67. controller: this
  68. }),
  69. a.default.ViewManager.register(29, {
  70. dir: "shop",
  71. prefabName: "ShopBuffViewIcon",
  72. zIndex: 50,
  73. controller: this
  74. }),
  75. a.default.ViewManager.register(30, {
  76. dir: "shop",
  77. prefabName: "ShopAdBoxLvTipView",
  78. zIndex: 100,
  79. controller: this
  80. }),
  81. a.default.ViewManager.register(32, {
  82. dir: "shop",
  83. prefabName: "ShopOpenBoxView",
  84. zIndex: 100,
  85. controller: this
  86. }),
  87. a.default.ViewManager.register(39, { dir: "shop", prefabName: "ShopViewIcon", zIndex: 50, controller: this }),
  88. // a.default.ViewManager.register(40, {
  89. // dir: "shop",
  90. // prefabName: "ShopFirstView",
  91. // zIndex: 100,
  92. // controller: this
  93. // }),
  94. a.default.ViewManager.register(41, {
  95. dir: "shop",
  96. prefabName: "ShopBankView",
  97. zIndex: 100,
  98. controller: this
  99. }),
  100. a.default.ViewManager.register(53, {
  101. dir: "shop",
  102. prefabName: "ShopRemoveAdView",
  103. zIndex: 100,
  104. controller: this
  105. }),
  106. (this._model = new y.default(this)),
  107. this._model.init(),
  108. this.initModleFunc(),
  109. this.initModleEvent();
  110. }
  111. get model() {
  112. return this._model;
  113. }
  114. initModleFunc() {
  115. this.registerFunc(_.ShopConst.BUY, this.shopBuy, this),
  116. this.registerFunc(_.ShopConst.USE, this.shopUse, this),
  117. this.registerFunc(_.ShopConst.GET_FIRST_GIFT, this.getFirstGift, this),
  118. this.registerFunc(_.ShopConst.GET_ITEM_DATA_BY_TYPE, this.getItemConfigsBuytype, this),
  119. this.registerFunc(_.ShopConst.FIRST_GIFT_IS_FINISH, this.firstGiftIsFinish, this),
  120. this.registerFunc(_.ShopConst.IS_BUY_REMOVE_AD, this.isBuyRemoveAd, this),
  121. this.registerFunc(_.ShopConst.GET_BANK_DIAMOND, this.getBankDiamond, this),
  122. this.registerFunc(_.ShopConst.BUY_BANK, this.buyBank, this);
  123. this.Hide()
  124. }
  125. Hide() {
  126. console.error('默认隐藏首冲');
  127. this.model.shopGiftDatas[_.ShopGiftType.FIRST_GIFT][0].buyCnt = 4
  128. console.error('默认隐藏免广告');
  129. this.model.shopGiftDatas[_.ShopGiftType.REMOVE_AD_GIFT][0].buyCnt = 1
  130. }
  131. initModleEvent() {
  132. a.default.NotificationCenter.addListener(l.NotificationConst.INIT_GAME, this.onInitGame, this, 200),
  133. a.default.NotificationCenter.addListener(p.GameNotificationConst.UPDATE_BUFF, this.onUpdateBuff, this),
  134. a.default.NotificationCenter.addListener(p.GameNotificationConst.ADD_ITEM, this.onAddItem, this);
  135. }
  136. onStageUpgradeUpdate() {
  137. var t = f.default.ins.define;
  138. (this._model.savaData.bankDiamond += t.piggybank_get_count),
  139. this._model.savaData.bankDiamond > t.piggybank_full_count &&
  140. (this._model.savaData.bankDiamond = t.piggybank_full_count);
  141. }
  142. onInitGame() {
  143. a.default.NotificationCenter.addListener(l.NotificationConst.SYS_OPEN, this.onCheckOpen, this);
  144. }
  145. onCheckOpen(t, e) {
  146. e &&
  147. (t == m.OpenTypeConst.BUFF
  148. ? (a.default.ViewManager.open(29), this.neddOpenCnt--)
  149. : t == m.OpenTypeConst.SHOP
  150. ? (a.default.ViewManager.open(39), this.neddOpenCnt--)
  151. : t == m.OpenTypeConst.FIRST_GIFT
  152. ? (this.model.isFirstShowFirstGift() && a.default.ViewManager.open(40), this.neddOpenCnt--)
  153. : t == m.OpenTypeConst.BANK &&
  154. (a.default.NotificationCenter.addListener(
  155. l.NotificationConst.STAGE_UPGRADE_UPDATE,
  156. this.onStageUpgradeUpdate,
  157. this
  158. ),
  159. this.neddOpenCnt--),
  160. this.neddOpenCnt ||
  161. a.default.NotificationCenter.removeListener(l.NotificationConst.SYS_OPEN, this.onCheckOpen, this));
  162. }
  163. onUpdateBuff() {
  164. const t = this._model.shopItemDatas[_.ShopType.BUFF];
  165. for (const i of t) {
  166. const t = a.default.ControllerManager.applyFunc(r.ControllerConst.Item, h.BagConst.GET_ITEM, i.cfg.itemId);
  167. var e;
  168. !t.data.buff ||
  169. ((e = u.default.ins.getGlobalBuffByIndex(t.data.buff.buffIndex)) &&
  170. e.buffEndTime &&
  171. this.shopBuffViewIcon &&
  172. this.shopBuffViewIcon.updateBuffItem(t.getItemPic(), e));
  173. }
  174. }
  175. onAddItem(t) {
  176. for (const e of this._model.shopItemDatas[_.ShopType.BOX])
  177. if (t == e.cfg.itemId) {
  178. this.shopViewIcon && this.shopViewIcon.updateShowIndexs();
  179. break;
  180. }
  181. }
  182. onOpenView(t) {
  183. switch (t.viewId) {
  184. case 29:
  185. this.onUpdateBuff(), this.startTime();
  186. break;
  187. case 39:
  188. this.startTime();
  189. }
  190. }
  191. onCloseView(t) {
  192. t.viewId;
  193. }
  194. getItemConfigsBuytype(t) {
  195. return this._model.shopItemDatas[t];
  196. }
  197. shopBuy(i, s) {
  198. return o(this, void 0, void 0, function* () {
  199. let t = !1;
  200. var e;
  201. if (
  202. (i.cfg.payId
  203. ? (t = yield a.default.Platform.buy(i.cfg.payId))
  204. : i.cfg.ad
  205. ? (e = yield a.default.ControllerManager.applyFunc(r.ControllerConst.AD, 0, s)) &&
  206. 0 === e.code &&
  207. (t = !0)
  208. : (t = g.default.ins.diamondChange(-i.cfg.diamond)) || n.default.launch("钻石不足!"),
  209. t)
  210. ) {
  211. switch ((this.model.updateCnt(i), i.shopType)) {
  212. case _.ShopType.Diamond:
  213. this.buyDiamond(i);
  214. break;
  215. case _.ShopType.BUFF:
  216. this.buyBuff(i);
  217. break;
  218. case _.ShopType.BOX:
  219. this.buyBox(i);
  220. break;
  221. case _.ShopType.GIFT:
  222. this.buGift(i);
  223. }
  224. a.default.Platform.saveData();
  225. }
  226. return t;
  227. });
  228. }
  229. buyDiamond(t) {
  230. let e = 1;
  231. 1 === t.buyCnt
  232. //实际支付双倍 但是我们不双倍
  233. // ? (g.default.ins.diamondChange(2 * t.cfg.diamond), (e = 2))
  234. ? (g.default.ins.diamondChange(t.cfg.diamond), (e = 1))
  235. : g.default.ins.diamondChange(t.cfg.diamond);
  236. const i = new p.CongratulationData();
  237. (i.name = t.getName()),
  238. (i.iconUrl = t.getDiamondIconUrl()),
  239. a.default.ViewManager.open(31, i),
  240. this.shopView && this.shopView.playGetCoinAni(c.CostType.diamond, t.cfg.diamond * e);
  241. }
  242. buyBuff(t) {
  243. a.default.ControllerManager.applyFunc(r.ControllerConst.Item, h.BagConst.ADD_TIME, t.cfg.itemId, 1, 2),
  244. t.cfg.diamond && a.default.AnalyticMgr.recordDiamondCost(t.cfg.arg0, -t.cfg.diamond);
  245. }
  246. buyBox(t) {
  247. a.default.ControllerManager.applyFunc(r.ControllerConst.Item, h.BagConst.ADD_TIME, t.cfg.itemId, 1, 2);
  248. var e = a.default.ControllerManager.applyFunc(r.ControllerConst.Item, h.BagConst.USE_ITEM, t.cfg.itemId);
  249. this.shopOpenBoxView
  250. ? (this.shopOpenBoxView.openBox(e[0]), this.shopView.updateContentUI(_.ShopType.BOX))
  251. : a.default.ViewManager.open(32, e[0], t),
  252. t.cfg.diamond && a.default.AnalyticMgr.recordDiamondCost(t.cfg.arg0, -t.cfg.diamond),
  253. this.shopViewIcon && this.shopViewIcon.updateShowIndexs();
  254. }
  255. buGift(i) {
  256. if (i.cfg.shopGift.type != _.ShopGiftType.FIRST_GIFT) {
  257. var s,
  258. t = i;
  259. let e = [];
  260. for (s of t.items) {
  261. let t = new p.CongratulationData();
  262. (t.data = s.id),
  263. (t.cnt = s.cnt),
  264. e.push(t),
  265. a.default.ControllerManager.applyFunc(r.ControllerConst.Item, h.BagConst.ADD_TIME, s.id, s.cnt);
  266. }
  267. if (i.cfg.diamond) {
  268. let t = new p.CongratulationData();
  269. (t.iconUrl = "Texture/itemIcon/diamond_1"),
  270. (t.name = "钻石"),
  271. (t.cnt = i.cfg.diamond),
  272. e.push(t),
  273. g.default.ins.diamondChange(i.cfg.diamond);
  274. }
  275. if (t.costumeItemIds)
  276. for (var o of t.costumeItemIds) {
  277. let t = new p.CongratulationData();
  278. (t.data = o),
  279. (t.cnt = 1),
  280. e.push(t),
  281. a.default.ControllerManager.applyFunc(r.ControllerConst.Item, h.BagConst.ADD_TIME, o, 1);
  282. }
  283. a.default.ViewManager.open(31, e);
  284. }
  285. this.shopView &&
  286. (this.shopView.updateContentUI(_.ShopType.GIFT), this.shopView.updateContentUI(_.ShopType.BOX));
  287. }
  288. buyBank() {
  289. return o(this, void 0, void 0, function* () {
  290. const t = yield a.default.Platform.buy("shop_bank");
  291. if (t) {
  292. const t = this._model.savaData.bankDiamond;
  293. g.default.ins.diamondChange(t), (this._model.savaData.bankDiamond = 0);
  294. const e = new p.CongratulationData();
  295. (e.iconUrl = "Texture/itemIcon/diamond_1"),
  296. (e.name = "钻石"),
  297. (e.cnt = t),
  298. a.default.ViewManager.open(31, e);
  299. }
  300. return t;
  301. });
  302. }
  303. shopUse(t) {
  304. var e;
  305. t.shopType == _.ShopType.BOX &&
  306. ((e = a.default.ControllerManager.applyFunc(r.ControllerConst.Item, h.BagConst.USE_ITEM, t.cfg.itemId)),
  307. this.shopOpenBoxView ? this.shopOpenBoxView.openBox(e[0]) : a.default.ViewManager.open(32, e[0], t),
  308. this.shopViewIcon && this.shopViewIcon.updateShowIndexs(),
  309. this.shopView.updateContentUI(_.ShopType.BOX));
  310. }
  311. startTime() {
  312. a.default.TimerManager.isExists(this.countDownTime, this) ||
  313. (a.default.TimerManager.doTimer(1e3, 0, this.countDownTime, this), this.countDownTime());
  314. }
  315. countDownTime() {
  316. var t = a.default.DateUtils.Now();
  317. this.shopBuffView && this.shopBuffView.updateTime(t),
  318. this.shopBuffViewIcon && this.shopBuffViewIcon.updateTime(t),
  319. this.shopViewIcon && this.shopViewIcon.updateBubble && this.shopViewIcon.updateBubble(t);
  320. }
  321. getFirstGift(t) {
  322. if (t.isCanGetFirstGift()) {
  323. if (1 === t.buyCnt) {
  324. var e = t.costumes[0];
  325. d.default.ins.createNewCostume(e.cfg.idx, e.data.grade, e.data.lv),
  326. a.default.ViewManager.open(31, e, 1);
  327. } else if (2 === t.buyCnt) {
  328. g.default.ins.diamondChange(t.cfg.diamond);
  329. const i = new p.CongratulationData();
  330. (i.iconUrl = t.getDiamondIconUrl()),
  331. (i.name = "钻石"),
  332. (i.cnt = t.cfg.diamond),
  333. a.default.ViewManager.open(31, i);
  334. } else
  335. 3 === t.buyCnt &&
  336. (a.default.ControllerManager.applyFunc(
  337. r.ControllerConst.Item,
  338. h.BagConst.ADD_TIME,
  339. t.items[0].id,
  340. t.items[0].cnt
  341. ),
  342. a.default.ViewManager.open(31, t.items[0].id, t.items[0].cnt));
  343. this._model.updateCnt(t);
  344. }
  345. }
  346. firstGiftIsFinish() {
  347. return this.model.shopGiftDatas[_.ShopGiftType.FIRST_GIFT][0].isHideGift();
  348. }
  349. isBuyRemoveAd() {
  350. return this.model.shopGiftDatas[_.ShopGiftType.REMOVE_AD_GIFT][0].isBuyGift();
  351. }
  352. getBankDiamond() {
  353. return this._model.savaData.bankDiamond;
  354. }
  355. };