var t = require; var e = module; var i = exports; Object.defineProperty(i, "__esModule", {value: !0}); const h = t("App"), s = t("BaseController"), o = t("RedPointMgr"), a = t("Toast"), n = t("NotificationConst"), r = (t("ViewConst"), t("LayerManager"), t("PlatformBase"), t("GameConst")), c = t("GameUtils"), l = t("CurrencyService"), d = t("CostumeConst"), u = t("CostumeItem"), p = t("CostumeModel"); let f = null; (o.RedPointMgr.types.MergeCostume = "MergeCostume"), (o.RedPointMgr.types.RecommendCostume = "RecommendCostume"), (i.default = class extends s.default { constructor() { super(), (this._model = null), (this._recalMap = []), (this._parseFuncMap = null), (this.costumeBagView = null), (this.costumeInfoView = null), (this.costumeStatisticsView = null), (f = this).initNotificationEvent(), this.setModel(new p.CostumeModel(this)), h.default.ViewManager.register(25, { prefabName: "CostumeBagView", zIndex: 100, controller: this, dir: "costume" }), h.default.ViewManager.register(26, { prefabName: "CostumeInfoView", zIndex: 100, controller: this, dir: "costume" }), h.default.ViewManager.register(27, { prefabName: "CostumeMergeView", zIndex: 100, controller: this, dir: "costume" }), h.default.ViewManager.register(33, { prefabName: "CostumeRefundView", zIndex: 100, controller: this, dir: "costume" }), h.default.ViewManager.register(34, { prefabName: "CotumeUpgradView", zIndex: 100, controller: this, dir: "costume" }), h.default.ViewManager.register(35, { prefabName: "CostumeMergeTipView", zIndex: 100, controller: this, dir: "costume" }), h.default.ViewManager.register(46, { prefabName: "CostumeStatisticsView", zIndex: 100, controller: this, dir: "costume" }), h.default.ViewManager.register(47, { prefabName: "CostumeMergeAniView", zIndex: 100, controller: this, dir: "costume" }), h.default.ViewManager.register(49, { prefabName: "CostumeCoinReturnView", zIndex: 100, controller: this, dir: "costume" }); } static get ins() { return f; } initModuleEvent() {} initNotificationEvent() { h.default.NotificationCenter.addListener(n.NotificationConst.INIT_GAME_FINISH, this.initGame, this); } log(...t) { cc.log("Costume", ...t); } initGame() { this.initModuleEvent(), h.default.NotificationCenter.removeListener(n.NotificationConst.INIT_GAME_FINISH, this.initGame, this); const e = this._model; e.init(); var i = e.saveData.items; let s = i.length; for (let t = 0; t < s; t++) { const s = i[t], o = new u.default(), a = e.costumeCfg[s.id]; o.init(s, a, e.costumeUpgrade, e.costumeMergeCfg), e.addCostumeItem(o); } for (const h in e.saveData.equipItem) this.equipCostume(e.saveData.equipItem[h]); this.calEquipCostumeAttr(), this.checkRedpoint(); } test() { const t = this._model, e = t.equipItems; if (!e[d.CostumeParts.head]) { const e = t.getCostumeItemByParts(d.CostumeParts.head); e.length && this.equipCostume(e[0].data.uuid); } if (!e[d.CostumeParts.hand]) { const e = t.getCostumeItemByParts(d.CostumeParts.hand); e.length && this.equipCostume(e[0].data.uuid); } if (!e[d.CostumeParts.body]) { const e = t.getCostumeItemByParts(d.CostumeParts.body); e.length && this.equipCostume(e[0].data.uuid); } this.log("/-----当前装备:"); for (const i in this._model.equipItems) this.log(this._model.equipItems[i].toString()); this.log("当前装备-------/:"); } createNewCostume(t, e = 1, i = 1, s = !0) { const o = new u.default(), a = this._model, n = {id: t, lv: i, grade: e, uuid: a.saveData.uuid++}; return ( o.init(n, a.costumeCfg[t], a.costumeUpgrade, a.costumeMergeCfg), a.addCostumeItem(o), a.saveData.items.push(n), s && this.checkRedpoint(), o ); } getTempCostume(t, e = 1, i = 1) { const s = new u.default(), o = this._model, a = {id: t, lv: i, grade: e, uuid: null}; return s.init(a, o.costumeCfg[t], o.costumeUpgrade, o.costumeMergeCfg), s; } lvUp(t) { const e = this._model.getCostumeItemByUuid(t); if (e) { const t = e.cost; if (l.default.ins.checkDiamondEnough(t)) return ( e.lvUp(), l.default.ins.diamondChange(-t), e.isEquip && (this.record(d.CostumeAbilityType.base), this.calEquipCostumeAttr()), e.recommend || this.checkRecommand(), h.default.NotificationCenter.dispatch(r.GameNotificationConst.LV_UP_COSTUME, e), h.default.AnalyticMgr.recordDiamondCost(2, -t), !0 ); a.default.launch("钻石不足"); } else Log.error("装备不存在:", t); return !1; } upgradeGrade(t) { const e = this._model.getCostumeItemByUuid(t); if (e) { const t = e.gradeCfg.upgrade_cost; if (l.default.ins.checkDiamondEnough(t)) return ( e.gradeUp(), this.refundCostume(e), l.default.ins.diamondChange(-t), e.isEquip && (this.record(d.CostumeAbilityType.base), this.calEquipCostumeAttr()), e.recommend || this.checkRecommand(), this.checkRedpoint(!1), h.default.NotificationCenter.dispatch(r.GameNotificationConst.LV_UP_COSTUME, e), h.default.AnalyticMgr.recordDiamondCost(3, -t), !0 ); a.default.launch("钻石不足"); } else Log.error("装备不存在:", t); } equipCostume(t, e) { const i = this._model.getCostumeItemByUuid(t); if (i) { const t = this._model.equipItems[i.cfg.parts]; if ( ((i.isEquip = !0), (this._model.equipItems[i.cfg.parts] = i), (this._model.saveData.equipItem[i.cfg.parts] = i.data.uuid), t) ) { t.isEquip = !1; for (const e in t.attr) this.record(parseInt(e)); } for (const e in i.attr) this.record(parseInt(e)); e && (this.calEquipCostumeAttr(), this.checkRecommand()), h.default.NotificationCenter.dispatch(r.GameNotificationConst.EQUIP_COSTUME, i, t); } else Log.error("装备不存在:", t); } unequipCostume(t, e, i) { const s = this._model.equipItems[t]; if (s) { for (const t in s.attr) this.record(parseInt(t)); return ( delete this._model.equipItems[t], delete this._model.saveData.equipItem[t], (s.isEquip = !1), i && (this.calEquipCostumeAttr(), this.checkRecommand()), e && h.default.NotificationCenter.dispatch(r.GameNotificationConst.UNEQUIP_COSTUME, s), s ); } Log.error("这个位置没有装备物品:", t, d.CostumeParts[t]); } record(t) { this._recalMap.includes(t) || this._recalMap.push(t); } refundCostume(t) { if (1 < t.data.lv) { var e = t.getLvCost(t.data.lv); return ( t.refund(), l.default.ins.diamondChange(e), t.isEquip && (this.record(d.CostumeAbilityType.base), this.calEquipCostumeAttr()), t.recommend && this.checkRecommand(), h.default.NotificationCenter.dispatch(r.GameNotificationConst.REFUND_COSTUME, t), !0 ); } } checkItemIsRecommand(t) { var e = this._model.items; t.cfg.parts; for (const i of e) i.cfg.parts; } checkIsCanMerge(e, i) { var t = this._model.costumeMergeCfg[e.data.grade], s = i.length; if (s !== t.costume_count) return !1; for (let t = 0; t < s; t++) if (!e.checkIsCanMerge(i[t])) return !1; return !0; } mergeCostume(e, i) { if (!this.checkIsCanMerge(e, i)) return null; let s = e.getLvCost(e.data.lv), o = e.isEquip, a = i.length; for (let t = 0; t < a; t++) { const e = i[t]; (o = o || e.isEquip), (s += e.getLvCost(e.data.lv)), this.destoryCostumeItem(e); } return ( e.gradeUp(), o && this.calEquipCostumeAttr(), 0 < s && l.default.ins.diamondChange(s), this.checkRedpoint(), h.default.NotificationCenter.dispatch(r.GameNotificationConst.MERGE_COSTUME, e, i), {refundDiamond: s} ); } destoryCostumeItem(t) { t.isEquip && this.unequipCostume(t.cfg.parts), this._model.removeCostumeItem(t); } calEquipCostumeAttr() { const e = this._model.attr; for (let t = d.CostumeParts.head; t <= d.CostumeParts.hand; t++) { const i = this._model.equipItems[t], h = e.getAttrBute("costume" + t); i ? (h.addAttrDict("base", i.attr), h.claFinishAttr()) : h.reset(); } e.claFinishAttr(), h.default.NotificationCenter.dispatch( r.GameNotificationConst.UPDATE_EQUIP_COSTUME_ATTR, this._recalMap ), (this._recalMap.length = 0); } onLoadView(t) {} onOpenView(t) { 46 == t.viewId && this.updateCostumeStatisticInfo(); } checkRecommand() { const s = this._model, o = s.equipItems, a = s.items; a.sort(c.sortCostume); const n = s.recommendItems; for (const h in n) n[h] && ((n[h].recommend = !1), (n[h] = null)); let r = a.length; if (0 !== r) { let e = 0, i = !1; for (let t = 0; t < r; t++) { const s = a[t], r = s.cfg.parts; if (!n[r]) { var l = o[r]; if ( ((!l || s.data.grade > l.data.grade || (s.data.grade === l.data.grade && s.data.lv > l.data.lv)) && ((s.recommend = !0), l !== s && (i = !0), (n[r] = s), e++), 3 === e) ) break; } } h.default.RedPointMgr.next(h.default.RedPointMgr.types.RecommendCostume, i); } } checkRedpoint(i = !0) { var s = this._model.items; let o = s.length; const a = {}; let n = !1; for (let e = 0; e < o; e++) { const i = s[e], o = i.cfg.parts, r = i.getMergeCfg(); let t = 1e4 * o + 1e3 * i.data.grade; 1 === r.ingredient_costume_type && (t += i.cfg.idx), a[t] ? (a[t].list.push(i), a[t].list.length > r.costume_count && (n = !0)) : (a[t] = {list: [i], cfg: r}); } h.default.RedPointMgr.next(h.default.RedPointMgr.types.MergeCostume, n), i && this.checkRecommand(); } updateMergeInfo() { const i = this._model.items; let s = i.length; const o = {}; for (let e = 0; e < s; e++) { const s = i[e], a = s.cfg.parts, n = s.getMergeCfg(); let t = 1e4 * a + 1e3 * s.data.grade; 1 === n.ingredient_costume_type && (t += s.cfg.idx), o[t] ? o[t].list.push(s) : (o[t] = {list: [s], cfg: n}); } for (const t in o) { const i = o[t], s = i.list.length > i.cfg.costume_count; for (const o of i.list) o.canMerge = s; } } checkIsCanUpgrade(t) { t.getMergeCfg().ingredient_costume_type; } onCloseView(t) { (33 != t.viewId && 34 != t.viewId) || (this.costumeInfoView && this.costumeInfoView.isShow() && this.costumeInfoView.updateData()); } updateCostumeStatisticInfo() { let i = {}, s = []; for (let t = d.CostumeParts.head; t <= d.CostumeParts.hand; t++) { const n = this._model.equipItems[t]; if (n) { let e = d.getGradeIndexByGrade(n.data.grade); if ((3 == e && (e--, s.push(n.getSpecialAbilityStr4())), 0 < e)) for (let t = 0; t <= e; t++) { var o = n.cfg[`special_ability${t + 1}_type`], a = n.cfg[`special_ability${t + 1}_value`]; i[o] || (i[o] = {value: 0, gradeIndex: t}), (i[o].value += a); } } } var t; this.costumeStatisticsView && ((t = this._model.attr.getAttrValue(d.CostumeAbilityType.base, 0)), this.costumeStatisticsView.updateUI(i, s, t)); } });