MachineData.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. Object.defineProperty(i, "__esModule", {value: !0});
  5. const o = t("App"),
  6. u = t("GameText"),
  7. a = t("Toast"),
  8. n = t("RedPoinAnim"),
  9. r = t("MachineLvUpAni"),
  10. l = t("RoleUnlockAni"),
  11. h = t("GameConst"),
  12. p = t("MachineAttr"),
  13. c = t("CurrencyService"),
  14. s = t("MachineService"),
  15. f = t("MapService"),
  16. g = t("SlotData");
  17. i.default = class {
  18. constructor() {
  19. (this.cfg = null),
  20. (this.menu = null),
  21. (this.unlockFrameBg = null),
  22. (this.foodBg = null),
  23. (this.slots = []),
  24. (this.unlockSlots = []),
  25. (this.unlockCnt = 0),
  26. (this.attr = null),
  27. (this.foodImg = null),
  28. (this.name = ""),
  29. (this.tipNode = null);
  30. }
  31. getPos() {
  32. const t = this.foodBg.node.position;
  33. return (t.x += this.foodBg.node.parent.x), (t.y += this.foodBg.node.parent.y + this.foodBg.node.height / 2), t;
  34. }
  35. updateMoney() {
  36. this.attr.isUnlock ? (this.tipNode.active = this.canLevelUp()) : (this.tipNode.active = this.canUnlock());
  37. }
  38. setMemento(e) {
  39. const i = (this.attr = new p.default()),
  40. s = f.default.ins.define,
  41. t = f.default.ins.curCfg;
  42. i.init(
  43. e,
  44. this.cfg,
  45. t.machine_max_lv,
  46. t.machine_slot_max,
  47. t.stage < 1e4 ? s.machine_slot_add_lv : s.event_machine_slot_add_lv,
  48. s.machine_value_doubleup_lv
  49. );
  50. var o = this.slots.length;
  51. for (let t = 0; t < o; t++) {
  52. const e = this.slots[t],
  53. s = i.slotCnt > t;
  54. s && ((this.unlockSlots[t] = e), (this.unlockCnt = t + 1)), e.setActive(s);
  55. }
  56. i.isUnlock ? (this.foodBg.spriteFrame = this.unlockFrameBg) : (this.foodImg.node.active = !1),
  57. this.foodBg.node.on(cc.Node.EventType.TOUCH_END, this.onTouchUnlock, this),
  58. this.updateMoney();
  59. }
  60. onTouchUnlock() {
  61. (this.attr.isUnlock ? s.default.ins.lvUpBox : s.default.ins.machineUnlockBox).showBox(this);
  62. }
  63. canUnlock() {
  64. return f.default.ins.mapSaveData.money >= this.attr.installCost;
  65. }
  66. canLevelUp() {
  67. return !this.attr.isMaxLevel() && f.default.ins.mapSaveData.money >= this.attr.upgradeCost;
  68. }
  69. unlockSlot(t) {
  70. const e = this.slots[t];
  71. this.unlockCnt = t + 1;
  72. const i = o.default.NodePoolMsr.cookUnlockAni.pop(),
  73. s = i.getComponent(l.default);
  74. (i.position = e.selfPos),
  75. f.default.ins.uiLayer.addChild(i),
  76. s.init(() => {
  77. e.unlock(), this.unlockSlots.push(e);
  78. for (const t of this.slots) t.updateSiblingIndex();
  79. o.default.NotificationCenter.dispatch(h.GameNotificationConst.UNLOCK_SLOT, e);
  80. }, this);
  81. }
  82. unlock() {
  83. this.attr.unlockSelf(),
  84. this.unlockSlot(0),
  85. (this.foodImg.node.active = !0),
  86. (this.foodBg.spriteFrame = this.unlockFrameBg);
  87. }
  88. lvUp() {
  89. if (!this.attr.isMaxLevel()) {
  90. var e = -this.attr.upgradeCost;
  91. if (c.default.ins.checkMoneyEnough(e)) {
  92. var i = this.attr.levelUp();
  93. this.attr.slotCnt > this.unlockCnt && this.unlockSlot(this.attr.slotCnt - 1),
  94. c.default.ins.moneyChange(e);
  95. const s = this.tipNode.parent;
  96. let t = o.default.NodePoolMsr.machineLvUpAni.pop();
  97. return s.addChild(t), t.getComponent(r.default).playAni(), i;
  98. }
  99. return a.default.launch("金币不足!"), !1;
  100. }
  101. a.default.launch("已经是最大等级!");
  102. }
  103. replacBtn(t, e) {
  104. let i = t.getChildByName("FoodOrder");
  105. (this.unlockFrameBg = i.getComponent(cc.Sprite).spriteFrame),
  106. i.parent.addChild(e),
  107. (e.x = i.x),
  108. (e.y = i.y),
  109. i.destroy();
  110. let s = i.children[0];
  111. s ? s.removeFromParent(!1) : (s = new cc.Node()), e.addChild(s);
  112. let o = s.getComponent(cc.Sprite);
  113. (o = o || s.addComponent(cc.Sprite)),
  114. (this.foodImg = o),
  115. (this.foodBg = e.getComponent(cc.Sprite)),
  116. (this.tipNode = e.getChildByName("arrow")),
  117. this.tipNode.getComponent(n.RedPoinAnim) || this.tipNode.addComponent(n.RedPoinAnim);
  118. }
  119. parse(e, i, s) {
  120. this.replacBtn(e, i),
  121. (this.menu = s),
  122. (this.name = u.GameText.getTextByStr(s.name)),
  123. (this.attr = new p.default());
  124. const o = e.getChildByName("slots"),
  125. a = e.x + o.x,
  126. n = e.y + o.y,
  127. r = -e.width * e.anchorX,
  128. l = e.width - e.width * e.anchorX,
  129. h = o.children,
  130. c = f.default.ins.layer;
  131. for (let t = h.length - 1; 0 <= t; t--) {
  132. const e = h[t],
  133. i = new g.default();
  134. i.machineData = this;
  135. const s = e.children[0];
  136. if (
  137. ((i.direction = parseInt(s.name.slice(5))),
  138. e.children[1] && ((i.ani = e.children[1].getComponent(cc.Animation)), i.ani && 6 === i.direction))
  139. ) {
  140. const e = i.ani.node;
  141. 1 < e.children.length ? (e.children[1].scaleX = -1) : (e.scaleX = -1);
  142. }
  143. (i.chefPos = cc.v2(s.x + a + e.x, s.y + n + e.y)), (i.selfPos = cc.v2(a + e.x, n + e.y)), s.destroy();
  144. const p = parseInt(e.name.split("_")[1]);
  145. (this.slots[p] = i), i.stopCook(), (i.node = e), (i.siblingIndex = t);
  146. var d = o.x + e.x;
  147. e.getComponent(cc.Sprite) && (d < r || l < d)
  148. ? (e.removeFromParent(!1), c.addChild(e), (e.x = a + e.x), (e.y = n + e.y), (i.parentNode = c))
  149. : (i.parentNode = e.parent);
  150. }
  151. }
  152. getEmpSlot() {
  153. for (const t of this.unlockSlots) if (!t.isWorking) return t;
  154. return null;
  155. }
  156. };