MachineAttr.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. Object.defineProperty(i, "__esModule", {value: !0});
  5. const s = t("GlobalAttr"),
  6. n = t("MyBigLong"),
  7. o = t("StageUpgradeService");
  8. i.default = class {
  9. constructor() {
  10. (this.cfg = null),
  11. (this.baseValue = 0),
  12. (this.value = 0),
  13. (this.upgradeCost = 0),
  14. (this.baseUpgradeCost = 0),
  15. (this.installCost = 0),
  16. (this.foodRate = 1),
  17. (this.isUnlock = !1),
  18. (this.slotCnt = 0),
  19. (this.manufactureTime = 0),
  20. (this.maxLevel = 0),
  21. (this.maxSlot = 0),
  22. (this.data = null),
  23. (this._slotAddLv = null),
  24. (this._doubleupLv = null);
  25. }
  26. get level() {
  27. return this.data.lv;
  28. }
  29. init(e, i, t, s, o, a) {
  30. if (
  31. ((this.data = e),
  32. (this.maxLevel = t),
  33. (this.maxSlot = s),
  34. (this.cfg = i),
  35. (this.baseValue = this.value = n.default.unpackData(i.value)),
  36. (this.baseUpgradeCost = n.default.unpackData(i.upgrade_cost)),
  37. (this.installCost = n.default.unpackData(i.install_cost)),
  38. (this._slotAddLv = o),
  39. (this._doubleupLv = a),
  40. this.calFoodRate(),
  41. this.calFoodFinalTime(),
  42. this.calCost(),
  43. e.lv)
  44. ) {
  45. (this.isUnlock = !0), (this.slotCnt = 1);
  46. const i = e.lv;
  47. for (let t = (e.lv = 1); t < i; t++) this.levelUp();
  48. }
  49. }
  50. getIdleRate() {
  51. return (this.value * this.slotCnt) / (this.manufactureTime + 10);
  52. }
  53. calFoodRate() {
  54. this.foodRate = o.default.ins.menuprofitValue[this.cfg.machine_num] || 1;
  55. var t = o.default.ins.menuprofitValue[-1];
  56. t && (this.foodRate *= t);
  57. }
  58. calFoodValue() {
  59. this.value = Math.ceil(this.baseValue * this.foodRate);
  60. }
  61. calCost() {
  62. this.upgradeCost = Math.ceil(this.baseUpgradeCost * s.default.ins.menuItemUpgradeDiscount);
  63. }
  64. calFoodFinalTime() {
  65. this.manufactureTime = Math.ceil(
  66. this.cfg.manufacture_time * (o.default.ins.fastermenu[this.cfg.machine_num] || 1)
  67. );
  68. }
  69. isDoubleLevel(t) {
  70. return this._doubleupLv.includes(t);
  71. }
  72. isAddSlot(t) {
  73. return this._slotAddLv.includes(t);
  74. }
  75. getDoubleProgressRate() {
  76. var e = this._doubleupLv;
  77. let i = e.length;
  78. var s = this.data.lv;
  79. for (let t = 0; t < i; t++) {
  80. const i = e[t];
  81. if (i > s) return 0 === t ? s / i : (s - e[t - 1]) / (i - e[t - 1]);
  82. }
  83. }
  84. isMaxLevel() {
  85. return this.data.lv >= this.maxLevel;
  86. }
  87. unlockSelf() {
  88. (this.isUnlock = !0), (this.slotCnt = 1), (this.data.lv = 1);
  89. }
  90. levelUp() {
  91. this.data.lv++;
  92. var t = this.isDoubleLevel(this.data.lv);
  93. t && (this.baseValue *= 2);
  94. var e = Math.max(Math.floor(((this.cfg.value_increment - 1e3) * this.baseValue) / 1e3), 1);
  95. this.baseValue += e;
  96. e = Math.max(Math.floor(((this.cfg.cost_increment - 1e3) * this.baseUpgradeCost) / 1e3), 1);
  97. return (
  98. (this.baseUpgradeCost += e),
  99. this.slotCnt < this.maxSlot && this.isAddSlot(this.data.lv) && this.slotCnt++,
  100. this.calFoodValue(),
  101. this.calCost(),
  102. t
  103. );
  104. }
  105. getCurStarNum() {
  106. let t = 0;
  107. for (const e of this._doubleupLv) this.level >= e && t++;
  108. return t;
  109. }
  110. getMaxStarNum() {
  111. let t = 0;
  112. for (const e of this._doubleupLv) this.maxLevel >= e && t++;
  113. return t;
  114. }
  115. };