var t = require; var e = module; var i = exports; var s, e = (this && this.__decorate) || function (t, e, i, s) { var o, a = arguments.length, n = a < 3 ? e : null === s ? (s = Object.getOwnPropertyDescriptor(e, i)) : s; if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(t, e, i, s); else for (var r = t.length - 1; 0 <= r; r--) (o = t[r]) && (n = (a < 3 ? o(n) : 3 < a ? o(e, i, n) : o(e, i)) || n); return 3 < a && n && Object.defineProperty(e, i, n), n; }; Object.defineProperty(i, "__esModule", {value: !0}); const l = t("App"), o = t("NodePool"), a = t("Toast"), n = t("ControllerConst"), r = t("NotificationConst"), h = t("LvUpBox"), c = t("MachineUnlockBox"), d = t("MachineData"), u = t("GameConst"), p = t("GlobalAttr"), f = t("BaseService"), g = t("CurrencyService"), m = t("MapService"), {ccclass: _, property: y} = cc._decorator; t = s = class extends f.default { constructor() { super(...arguments), (this.machineDatas = null), (this.machineUnlockBox = null), (this.lvUpBox = null), (this.isIdleRateChange = !0), (this.idleRate = 0), (this.buffAttr = null), (this.machineUnlockBtnPool = null), (this.saveData = null), (this.unlockMachines = null); } onLoad() { (this.machineUnlockBtnPool = new o.default()), (s.ins = this); } onUpdateMoney() { for (const t of this.machineDatas) t.updateMoney(); } onUpdateEquipCostumeAttr() { this.isIdleRateChange = !0; } onDestroy() { l.default.NotificationCenter.removeAll(this); } parse(e) { l.default.NotificationCenter.addListener( u.GameNotificationConst.UPDATE_EQUIP_COSTUME_ATTR, this.onUpdateEquipCostumeAttr, this ), (this.machineUnlockBtnPool.prefab = m.default.ins.foodBundle.get("MachineUnlockBtn", cc.Prefab)), (this.machineDatas = []); const i = m.default.ins.layer, s = m.default.ins.curCfg.StageMachine, o = m.default.ins.machineMenu, a = e.children.concat(), n = m.default.ins.foodBundle; let r = a.length; for (let t = 0; t < r; t++) { const e = a[t], r = new d.default(); (r.cfg = s[t]), r.parse(e, this.machineUnlockBtnPool.pop(), o[r.cfg.menu_idx]), (r.foodImg.spriteFrame = n.get("img/" + r.menu.icon, cc.SpriteFrame)), this.machineDatas.push(r), e.removeFromParent(!1), i.addChild(e); } } unlockMachine(t) { this.isIdleRateChange = !0; const e = this.machineDatas[t]; e ? g.default.ins.checkMoneyEnough(e.attr.installCost) ? (e.unlock(), s.ins.unlockMachines.push(e), g.default.ins.moneyChange(-e.attr.installCost), l.default.NotificationCenter.dispatch(u.GameNotificationConst.UNLOCK_MACHINE, e)) : a.default.launch("金币不足!") : Log.error("不存在的解锁序号:", t); } getIdleRate() { if (this.isIdleRateChange) { (this.isIdleRateChange = !1), (this.idleRate = 0); var e = this.machineDatas.length; for (let t = 0; t < e; t++) this.machineDatas[t].attr.isUnlock && (this.idleRate += this.machineDatas[t].attr.getIdleRate()); this.idleRate *= p.default.ins.cookMoneyRate; } return this.idleRate; } calculateIdleMoney(t, e = !1) { let i = this.getIdleRate(); return e && p.default.ins.offlineRevenue && (i *= p.default.ins.offlineRevenue), Math.floor(i * t); } lvUpkMachine(t) { const e = this.machineDatas[t]; e // ? (e.lvUp() && (this.lvUpBox.playGetDiamond(), 1 < m.default.ins.curId && g.default.ins.diamondChange(2)), //不需要升级给钻石了 ? (e.lvUp() && (this.lvUpBox.playGetDiamond(), 1 < m.default.ins.curId ), l.default.NotificationCenter.dispatch(r.NotificationConst.MACHINE_UPDATE, t), (this.isIdleRateChange = !0)) : Log.error("不存在的解锁序号:", t); } reCalAllFoodValue() { for (const t of this.machineDatas) t.attr.calFoodRate(), t.attr.calFoodValue(); this.isIdleRateChange = !0; } reCalAllFoodCost() { for (const t of this.machineDatas) t.attr.calCost(), t.updateMoney(); } reCalFoodValue(t) { const e = this.machineDatas[t]; e.attr.calFoodRate(), e.attr.calFoodValue(), (this.isIdleRateChange = !0); } init() { this.buffAttr = p.default.ins.buffAttr; const e = l.default.ControllerManager.getControllerModel(n.ControllerConst.Game); l.default.NotificationCenter.addListener(r.NotificationConst.UPDATE_MONEY, this.onUpdateMoney, this); const i = e.getCurMapData(); (this.saveData = i.machines), (this.unlockMachines = []); var s = this.machineDatas.length; for (let t = 0; t < s; t++) { const e = this.machineDatas[t]; i.machines[t] || (i.machines[t] = {lv: 0}), e.setMemento(i.machines[t]), e.attr.isUnlock && this.unlockMachines.push(e); } } destorySelf() { l.default.NotificationCenter.removeAll(this), this.lvUpBox.node.removeFromParent(!1), this.machineUnlockBox.node.removeFromParent(!1); } isAllMachineMax() { for (const t of this.machineDatas) if (!t.attr.isMaxLevel()) return !1; return !0; } getMachinProgress() { let t = 0, e = this.machineDatas.length * this.machineDatas[0].attr.maxLevel; for (const i of this.machineDatas) i.attr.data && i.attr.data.lv && (t += i.attr.data.lv); return t / e; } getMachinAllLvCnt() { let t = 0; for (const e of this.machineDatas) e.attr.data && e.attr.data.lv && (t += e.attr.data.lv); return t; } getCurMachineMaxLv() { let t = 0; for (const e of this.machineDatas) e.attr.data && e.attr.data.lv && t < e.attr.data.lv && (t = e.attr.data.lv); return t; } }; e([y(c.default)], t.prototype, "machineUnlockBox", void 0), e([y(h.default)], t.prototype, "lvUpBox", void 0), (t = s = e([_], t)), (i.default = t = s);