MachineService.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. var s,
  5. e =
  6. (this && this.__decorate) ||
  7. function (t, e, i, s) {
  8. var o,
  9. a = arguments.length,
  10. n = a < 3 ? e : null === s ? (s = Object.getOwnPropertyDescriptor(e, i)) : s;
  11. if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(t, e, i, s);
  12. else
  13. for (var r = t.length - 1; 0 <= r; r--)
  14. (o = t[r]) && (n = (a < 3 ? o(n) : 3 < a ? o(e, i, n) : o(e, i)) || n);
  15. return 3 < a && n && Object.defineProperty(e, i, n), n;
  16. };
  17. Object.defineProperty(i, "__esModule", {value: !0});
  18. const l = t("App"),
  19. o = t("NodePool"),
  20. a = t("Toast"),
  21. n = t("ControllerConst"),
  22. r = t("NotificationConst"),
  23. h = t("LvUpBox"),
  24. c = t("MachineUnlockBox"),
  25. d = t("MachineData"),
  26. u = t("GameConst"),
  27. p = t("GlobalAttr"),
  28. f = t("BaseService"),
  29. g = t("CurrencyService"),
  30. m = t("MapService"),
  31. {ccclass: _, property: y} = cc._decorator;
  32. t = s = class extends f.default {
  33. constructor() {
  34. super(...arguments),
  35. (this.machineDatas = null),
  36. (this.machineUnlockBox = null),
  37. (this.lvUpBox = null),
  38. (this.isIdleRateChange = !0),
  39. (this.idleRate = 0),
  40. (this.buffAttr = null),
  41. (this.machineUnlockBtnPool = null),
  42. (this.saveData = null),
  43. (this.unlockMachines = null);
  44. }
  45. onLoad() {
  46. (this.machineUnlockBtnPool = new o.default()), (s.ins = this);
  47. }
  48. onUpdateMoney() {
  49. for (const t of this.machineDatas) t.updateMoney();
  50. }
  51. onUpdateEquipCostumeAttr() {
  52. this.isIdleRateChange = !0;
  53. }
  54. onDestroy() {
  55. l.default.NotificationCenter.removeAll(this);
  56. }
  57. parse(e) {
  58. l.default.NotificationCenter.addListener(
  59. u.GameNotificationConst.UPDATE_EQUIP_COSTUME_ATTR,
  60. this.onUpdateEquipCostumeAttr,
  61. this
  62. ),
  63. (this.machineUnlockBtnPool.prefab = m.default.ins.foodBundle.get("MachineUnlockBtn", cc.Prefab)),
  64. (this.machineDatas = []);
  65. const i = m.default.ins.layer,
  66. s = m.default.ins.curCfg.StageMachine,
  67. o = m.default.ins.machineMenu,
  68. a = e.children.concat(),
  69. n = m.default.ins.foodBundle;
  70. let r = a.length;
  71. for (let t = 0; t < r; t++) {
  72. const e = a[t],
  73. r = new d.default();
  74. (r.cfg = s[t]),
  75. r.parse(e, this.machineUnlockBtnPool.pop(), o[r.cfg.menu_idx]),
  76. (r.foodImg.spriteFrame = n.get("img/" + r.menu.icon, cc.SpriteFrame)),
  77. this.machineDatas.push(r),
  78. e.removeFromParent(!1),
  79. i.addChild(e);
  80. }
  81. }
  82. unlockMachine(t) {
  83. this.isIdleRateChange = !0;
  84. const e = this.machineDatas[t];
  85. e
  86. ? g.default.ins.checkMoneyEnough(e.attr.installCost)
  87. ? (e.unlock(),
  88. s.ins.unlockMachines.push(e),
  89. g.default.ins.moneyChange(-e.attr.installCost),
  90. l.default.NotificationCenter.dispatch(u.GameNotificationConst.UNLOCK_MACHINE, e))
  91. : a.default.launch("金币不足!")
  92. : Log.error("不存在的解锁序号:", t);
  93. }
  94. getIdleRate() {
  95. if (this.isIdleRateChange) {
  96. (this.isIdleRateChange = !1), (this.idleRate = 0);
  97. var e = this.machineDatas.length;
  98. for (let t = 0; t < e; t++)
  99. this.machineDatas[t].attr.isUnlock && (this.idleRate += this.machineDatas[t].attr.getIdleRate());
  100. this.idleRate *= p.default.ins.cookMoneyRate;
  101. }
  102. return this.idleRate;
  103. }
  104. calculateIdleMoney(t, e = !1) {
  105. let i = this.getIdleRate();
  106. return e && p.default.ins.offlineRevenue && (i *= p.default.ins.offlineRevenue), Math.floor(i * t);
  107. }
  108. lvUpkMachine(t) {
  109. const e = this.machineDatas[t];
  110. e
  111. // ? (e.lvUp() && (this.lvUpBox.playGetDiamond(), 1 < m.default.ins.curId && g.default.ins.diamondChange(2)),
  112. //不需要升级给钻石了
  113. ? (e.lvUp() && (this.lvUpBox.playGetDiamond(), 1 < m.default.ins.curId ),
  114. l.default.NotificationCenter.dispatch(r.NotificationConst.MACHINE_UPDATE, t),
  115. (this.isIdleRateChange = !0))
  116. : Log.error("不存在的解锁序号:", t);
  117. }
  118. reCalAllFoodValue() {
  119. for (const t of this.machineDatas) t.attr.calFoodRate(), t.attr.calFoodValue();
  120. this.isIdleRateChange = !0;
  121. }
  122. reCalAllFoodCost() {
  123. for (const t of this.machineDatas) t.attr.calCost(), t.updateMoney();
  124. }
  125. reCalFoodValue(t) {
  126. const e = this.machineDatas[t];
  127. e.attr.calFoodRate(), e.attr.calFoodValue(), (this.isIdleRateChange = !0);
  128. }
  129. init() {
  130. this.buffAttr = p.default.ins.buffAttr;
  131. const e = l.default.ControllerManager.getControllerModel(n.ControllerConst.Game);
  132. l.default.NotificationCenter.addListener(r.NotificationConst.UPDATE_MONEY, this.onUpdateMoney, this);
  133. const i = e.getCurMapData();
  134. (this.saveData = i.machines), (this.unlockMachines = []);
  135. var s = this.machineDatas.length;
  136. for (let t = 0; t < s; t++) {
  137. const e = this.machineDatas[t];
  138. i.machines[t] || (i.machines[t] = {lv: 0}),
  139. e.setMemento(i.machines[t]),
  140. e.attr.isUnlock && this.unlockMachines.push(e);
  141. }
  142. }
  143. destorySelf() {
  144. l.default.NotificationCenter.removeAll(this),
  145. this.lvUpBox.node.removeFromParent(!1),
  146. this.machineUnlockBox.node.removeFromParent(!1);
  147. }
  148. isAllMachineMax() {
  149. for (const t of this.machineDatas) if (!t.attr.isMaxLevel()) return !1;
  150. return !0;
  151. }
  152. getMachinProgress() {
  153. let t = 0,
  154. e = this.machineDatas.length * this.machineDatas[0].attr.maxLevel;
  155. for (const i of this.machineDatas) i.attr.data && i.attr.data.lv && (t += i.attr.data.lv);
  156. return t / e;
  157. }
  158. getMachinAllLvCnt() {
  159. let t = 0;
  160. for (const e of this.machineDatas) e.attr.data && e.attr.data.lv && (t += e.attr.data.lv);
  161. return t;
  162. }
  163. getCurMachineMaxLv() {
  164. let t = 0;
  165. for (const e of this.machineDatas) e.attr.data && e.attr.data.lv && t < e.attr.data.lv && (t = e.attr.data.lv);
  166. return t;
  167. }
  168. };
  169. e([y(c.default)], t.prototype, "machineUnlockBox", void 0),
  170. e([y(h.default)], t.prototype, "lvUpBox", void 0),
  171. (t = s = e([_], t)),
  172. (i.default = t = s);