var t = require; var e = module; var i = exports; Object.defineProperty(i, "__esModule", {value: !0}), (i.CostType = void 0); const n = t("App"), s = t("BaseController"), o = t("NotificationConst"), r = t("GameConst"), a = t("CurrencyService"), l = t("BagConst"), h = t("BagModel"); let c = null; var d; (i.default = class extends s.default { constructor() { super(), (this._model = null), (c = this).initNotificationEvent(), this.setModel(new h.BagModel(this)); } static get ins() { return c; } initModuleEvent() { this.registerFunc(l.BagConst.USE_ITEM, this.useItem, this), this.registerFunc(l.BagConst.ADD_TIME, this.addItem, this), this.registerFunc(l.BagConst.USE_ITEM_ANI, this.useItemAni, this), this.registerFunc(l.BagConst.GET_ITEM, this.getItem, this), this.registerFunc(l.BagConst.GET_ITEMS_BY_TYPE, this.getItemType, this); } initNotificationEvent() { n.default.NotificationCenter.addListener(o.NotificationConst.INIT_GAME_FINISH, this.initGame, this); } initGame() { this.initModuleEvent(), n.default.NotificationCenter.removeListener(o.NotificationConst.INIT_GAME_FINISH, this.initGame, this), this._model.init(); } useItemAni(t, e, i = 0) {} onLoadView(t) {} onOpenView(t) {} useItem(t, e = 1, i, s) { let o = this._model.itmes[t]; if (o) { if (o.cnt >= e) { o.cnt -= e; var a = o.use(e); return n.default.NotificationCenter.dispatch(r.GameNotificationConst.USE_ITEM, t, e, a), a; } return ( Log.warn( `\u7269\u54c1\u6570\u91cf\u4e0d\u8db3, \u7269\u54c1id:${t}, \u7269\u54c1\u540d\u79f0:${o.getName()}` ), {result: -1} ); } return Log.error(`\u4e0d\u5b58\u5728\u7684\u7269\u54c1id:${t}`), {result: -2}; } addItem(e, i = 1, t) { if (e <= 1e4) { let t = this._model.itmes[e]; return t ? ((t.cnt += i), t.data.isNowUseItem ? this.useItem(e, i, !0, !0) : n.default.NotificationCenter.dispatch(r.GameNotificationConst.ADD_ITEM, e), !0) : (Log.error(`\u4e0d\u5b58\u5728\u7684\u7269\u54c1id:${e}`), !1); } this.addMoney(e, i); } addMoney(t, e) { switch (t) { case d.coin: a.default.ins.moneyChange(e); break; case d.diamond: a.default.ins.diamondChange(e); } } getItem(t) { return this._model.itmes[t]; } getItemType(t) { return this._model.itmeTypes[t]; } }), ((i = d = i.CostType || (i.CostType = {}))[(i.coin = 20001)] = "coin"), (i[(i.diamond = 20002)] = "diamond");