var t = require; var e = module; var i = exports; var o = (this && this.__awaiter) || function (t, n, r, l) { return new (r = r || Promise)(function (i, e) { function s(t) { try { a(l.next(t)); } catch (t) { e(t); } } function o(t) { try { a(l.throw(t)); } catch (t) { e(t); } } function a(t) { var e; t.done ? i(t.value) : ((e = t.value) instanceof r ? e : new r(function (t) { t(e); }) ).then(s, o); } a((l = l.apply(t, n || [])).next()); }); }; Object.defineProperty(i, "__esModule", { value: !0 }); const a = t("App"), s = t("BaseController"), n = t("Toast"), r = t("ControllerConst"), l = t("NotificationConst"), h = (t("ViewConst"), t("LayerManager"), t("ADManageBase"), t("BagConst")), c = t("BagController"), d = t("CostumeController"), u = t("BuffMgr"), p = t("GameConst"), f = t("GlobalAttr"), g = t("CurrencyService"), m = t("SystemOpenConst"), _ = t("ShopConst"), y = t("ShopModle"); i.default = class extends s.default { constructor() { super(), (this.shopView = null), (this.shopBuffView = null), (this.shopBuffViewIcon = null), (this.shopOpenBoxView = null), (this.shopViewIcon = null), (this._model = null), (this.neddOpenCnt = 4), a.default.ViewManager.register(7, { dir: "shop", prefabName: "ShopView", zIndex: 100, controller: this }), a.default.ViewManager.register(28, { dir: "shop", prefabName: "ShopBuffView", zIndex: 100, controller: this }), a.default.ViewManager.register(29, { dir: "shop", prefabName: "ShopBuffViewIcon", zIndex: 50, controller: this }), a.default.ViewManager.register(30, { dir: "shop", prefabName: "ShopAdBoxLvTipView", zIndex: 100, controller: this }), a.default.ViewManager.register(32, { dir: "shop", prefabName: "ShopOpenBoxView", zIndex: 100, controller: this }), a.default.ViewManager.register(39, { dir: "shop", prefabName: "ShopViewIcon", zIndex: 50, controller: this }), // a.default.ViewManager.register(40, { // dir: "shop", // prefabName: "ShopFirstView", // zIndex: 100, // controller: this // }), a.default.ViewManager.register(41, { dir: "shop", prefabName: "ShopBankView", zIndex: 100, controller: this }), a.default.ViewManager.register(53, { dir: "shop", prefabName: "ShopRemoveAdView", zIndex: 100, controller: this }), (this._model = new y.default(this)), this._model.init(), this.initModleFunc(), this.initModleEvent(); } get model() { return this._model; } initModleFunc() { this.registerFunc(_.ShopConst.BUY, this.shopBuy, this), this.registerFunc(_.ShopConst.USE, this.shopUse, this), this.registerFunc(_.ShopConst.GET_FIRST_GIFT, this.getFirstGift, this), this.registerFunc(_.ShopConst.GET_ITEM_DATA_BY_TYPE, this.getItemConfigsBuytype, this), this.registerFunc(_.ShopConst.FIRST_GIFT_IS_FINISH, this.firstGiftIsFinish, this), this.registerFunc(_.ShopConst.IS_BUY_REMOVE_AD, this.isBuyRemoveAd, this), this.registerFunc(_.ShopConst.GET_BANK_DIAMOND, this.getBankDiamond, this), this.registerFunc(_.ShopConst.BUY_BANK, this.buyBank, this); this.Hide() } Hide() { console.error('默认隐藏首冲'); this.model.shopGiftDatas[_.ShopGiftType.FIRST_GIFT][0].buyCnt = 4 console.error('默认隐藏免广告'); this.model.shopGiftDatas[_.ShopGiftType.REMOVE_AD_GIFT][0].buyCnt = 1 } initModleEvent() { a.default.NotificationCenter.addListener(l.NotificationConst.INIT_GAME, this.onInitGame, this, 200), a.default.NotificationCenter.addListener(p.GameNotificationConst.UPDATE_BUFF, this.onUpdateBuff, this), a.default.NotificationCenter.addListener(p.GameNotificationConst.ADD_ITEM, this.onAddItem, this); } onStageUpgradeUpdate() { var t = f.default.ins.define; (this._model.savaData.bankDiamond += t.piggybank_get_count), this._model.savaData.bankDiamond > t.piggybank_full_count && (this._model.savaData.bankDiamond = t.piggybank_full_count); } onInitGame() { a.default.NotificationCenter.addListener(l.NotificationConst.SYS_OPEN, this.onCheckOpen, this); } onCheckOpen(t, e) { e && (t == m.OpenTypeConst.BUFF ? (a.default.ViewManager.open(29), this.neddOpenCnt--) : t == m.OpenTypeConst.SHOP ? (a.default.ViewManager.open(39), this.neddOpenCnt--) : t == m.OpenTypeConst.FIRST_GIFT ? (this.model.isFirstShowFirstGift() && a.default.ViewManager.open(40), this.neddOpenCnt--) : t == m.OpenTypeConst.BANK && (a.default.NotificationCenter.addListener( l.NotificationConst.STAGE_UPGRADE_UPDATE, this.onStageUpgradeUpdate, this ), this.neddOpenCnt--), this.neddOpenCnt || a.default.NotificationCenter.removeListener(l.NotificationConst.SYS_OPEN, this.onCheckOpen, this)); } onUpdateBuff() { const t = this._model.shopItemDatas[_.ShopType.BUFF]; for (const i of t) { const t = a.default.ControllerManager.applyFunc(r.ControllerConst.Item, h.BagConst.GET_ITEM, i.cfg.itemId); var e; !t.data.buff || ((e = u.default.ins.getGlobalBuffByIndex(t.data.buff.buffIndex)) && e.buffEndTime && this.shopBuffViewIcon && this.shopBuffViewIcon.updateBuffItem(t.getItemPic(), e)); } } onAddItem(t) { for (const e of this._model.shopItemDatas[_.ShopType.BOX]) if (t == e.cfg.itemId) { this.shopViewIcon && this.shopViewIcon.updateShowIndexs(); break; } } onOpenView(t) { switch (t.viewId) { case 29: this.onUpdateBuff(), this.startTime(); break; case 39: this.startTime(); } } onCloseView(t) { t.viewId; } getItemConfigsBuytype(t) { return this._model.shopItemDatas[t]; } shopBuy(i, s) { return o(this, void 0, void 0, function* () { let t = !1; var e; if ( (i.cfg.payId ? (t = yield a.default.Platform.buy(i.cfg.payId)) : i.cfg.ad ? (e = yield a.default.ControllerManager.applyFunc(r.ControllerConst.AD, 0, s)) && 0 === e.code && (t = !0) : (t = g.default.ins.diamondChange(-i.cfg.diamond)) || n.default.launch("钻石不足!"), t) ) { switch ((this.model.updateCnt(i), i.shopType)) { case _.ShopType.Diamond: this.buyDiamond(i); break; case _.ShopType.BUFF: this.buyBuff(i); break; case _.ShopType.BOX: this.buyBox(i); break; case _.ShopType.GIFT: this.buGift(i); } a.default.Platform.saveData(); } return t; }); } buyDiamond(t) { let e = 1; 1 === t.buyCnt //实际支付双倍 但是我们不双倍 // ? (g.default.ins.diamondChange(2 * t.cfg.diamond), (e = 2)) ? (g.default.ins.diamondChange(t.cfg.diamond), (e = 1)) : g.default.ins.diamondChange(t.cfg.diamond); const i = new p.CongratulationData(); (i.name = t.getName()), (i.iconUrl = t.getDiamondIconUrl()), a.default.ViewManager.open(31, i), this.shopView && this.shopView.playGetCoinAni(c.CostType.diamond, t.cfg.diamond * e); } buyBuff(t) { a.default.ControllerManager.applyFunc(r.ControllerConst.Item, h.BagConst.ADD_TIME, t.cfg.itemId, 1, 2), t.cfg.diamond && a.default.AnalyticMgr.recordDiamondCost(t.cfg.arg0, -t.cfg.diamond); } buyBox(t) { a.default.ControllerManager.applyFunc(r.ControllerConst.Item, h.BagConst.ADD_TIME, t.cfg.itemId, 1, 2); var e = a.default.ControllerManager.applyFunc(r.ControllerConst.Item, h.BagConst.USE_ITEM, t.cfg.itemId); this.shopOpenBoxView ? (this.shopOpenBoxView.openBox(e[0]), this.shopView.updateContentUI(_.ShopType.BOX)) : a.default.ViewManager.open(32, e[0], t), t.cfg.diamond && a.default.AnalyticMgr.recordDiamondCost(t.cfg.arg0, -t.cfg.diamond), this.shopViewIcon && this.shopViewIcon.updateShowIndexs(); } buGift(i) { if (i.cfg.shopGift.type != _.ShopGiftType.FIRST_GIFT) { var s, t = i; let e = []; for (s of t.items) { let t = new p.CongratulationData(); (t.data = s.id), (t.cnt = s.cnt), e.push(t), a.default.ControllerManager.applyFunc(r.ControllerConst.Item, h.BagConst.ADD_TIME, s.id, s.cnt); } if (i.cfg.diamond) { let t = new p.CongratulationData(); (t.iconUrl = "Texture/itemIcon/diamond_1"), (t.name = "钻石"), (t.cnt = i.cfg.diamond), e.push(t), g.default.ins.diamondChange(i.cfg.diamond); } if (t.costumeItemIds) for (var o of t.costumeItemIds) { let t = new p.CongratulationData(); (t.data = o), (t.cnt = 1), e.push(t), a.default.ControllerManager.applyFunc(r.ControllerConst.Item, h.BagConst.ADD_TIME, o, 1); } a.default.ViewManager.open(31, e); } this.shopView && (this.shopView.updateContentUI(_.ShopType.GIFT), this.shopView.updateContentUI(_.ShopType.BOX)); } buyBank() { return o(this, void 0, void 0, function* () { const t = yield a.default.Platform.buy("shop_bank"); if (t) { const t = this._model.savaData.bankDiamond; g.default.ins.diamondChange(t), (this._model.savaData.bankDiamond = 0); const e = new p.CongratulationData(); (e.iconUrl = "Texture/itemIcon/diamond_1"), (e.name = "钻石"), (e.cnt = t), a.default.ViewManager.open(31, e); } return t; }); } shopUse(t) { var e; t.shopType == _.ShopType.BOX && ((e = a.default.ControllerManager.applyFunc(r.ControllerConst.Item, h.BagConst.USE_ITEM, t.cfg.itemId)), this.shopOpenBoxView ? this.shopOpenBoxView.openBox(e[0]) : a.default.ViewManager.open(32, e[0], t), this.shopViewIcon && this.shopViewIcon.updateShowIndexs(), this.shopView.updateContentUI(_.ShopType.BOX)); } startTime() { a.default.TimerManager.isExists(this.countDownTime, this) || (a.default.TimerManager.doTimer(1e3, 0, this.countDownTime, this), this.countDownTime()); } countDownTime() { var t = a.default.DateUtils.Now(); this.shopBuffView && this.shopBuffView.updateTime(t), this.shopBuffViewIcon && this.shopBuffViewIcon.updateTime(t), this.shopViewIcon && this.shopViewIcon.updateBubble && this.shopViewIcon.updateBubble(t); } getFirstGift(t) { if (t.isCanGetFirstGift()) { if (1 === t.buyCnt) { var e = t.costumes[0]; d.default.ins.createNewCostume(e.cfg.idx, e.data.grade, e.data.lv), a.default.ViewManager.open(31, e, 1); } else if (2 === t.buyCnt) { g.default.ins.diamondChange(t.cfg.diamond); const i = new p.CongratulationData(); (i.iconUrl = t.getDiamondIconUrl()), (i.name = "钻石"), (i.cnt = t.cfg.diamond), a.default.ViewManager.open(31, i); } else 3 === t.buyCnt && (a.default.ControllerManager.applyFunc( r.ControllerConst.Item, h.BagConst.ADD_TIME, t.items[0].id, t.items[0].cnt ), a.default.ViewManager.open(31, t.items[0].id, t.items[0].cnt)); this._model.updateCnt(t); } } firstGiftIsFinish() { return this.model.shopGiftDatas[_.ShopGiftType.FIRST_GIFT][0].isHideGift(); } isBuyRemoveAd() { return this.model.shopGiftDatas[_.ShopGiftType.REMOVE_AD_GIFT][0].isBuyGift(); } getBankDiamond() { return this._model.savaData.bankDiamond; } };