WaiterAI.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. e =
  5. (this && this.__decorate) ||
  6. function (t, e, i, s) {
  7. var o,
  8. a = arguments.length,
  9. n = a < 3 ? e : null === s ? (s = Object.getOwnPropertyDescriptor(e, i)) : s;
  10. if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(t, e, i, s);
  11. else
  12. for (var r = t.length - 1; 0 <= r; r--)
  13. (o = t[r]) && (n = (a < 3 ? o(n) : 3 < a ? o(e, i, n) : o(e, i)) || n);
  14. return 3 < a && n && Object.defineProperty(e, i, n), n;
  15. };
  16. Object.defineProperty(i, "__esModule", {value: !0});
  17. const s = t("App"),
  18. o = t("SoundEffectConst"),
  19. a = t("GameConst"),
  20. n = t("DeskService"),
  21. r = t("MapService"),
  22. l = t("OrderService"),
  23. h = t("RoleService"),
  24. c = t("BaseMan"),
  25. d = t("ChefAI"),
  26. u = t("MoveComponent"),
  27. {ccclass: p} = cc._decorator;
  28. e = e(
  29. [p],
  30. (e = class extends d.default {
  31. constructor() {
  32. super(...arguments), (this.man = null);
  33. }
  34. onLoad() {
  35. (this.man = this.getComponent(c.default)),
  36. (this.move = this.getComponent(u.default)),
  37. (this.orderDataList = l.default.ins.orders[a.MachineType.type1]);
  38. }
  39. think() {
  40. if (n.default.ins.cookDatas.length)
  41. return (
  42. (this.cookData = n.default.ins.cookDatas.pop()),
  43. this.move.moveTo(this.cookData.passSectionData.waiter.pos),
  44. void (this.state = d.AI_STATE.MOVE_TO_SEND_FOOD)
  45. );
  46. if (this.orderDataList.hasEmp) {
  47. const t = (this.cookData = this.orderDataList.cookOrder());
  48. return (
  49. t.init(this.man), this.move.moveTo(t.slot.chefPos), void (this.state = d.AI_STATE.MOVE_TO_COOKING)
  50. );
  51. }
  52. if (l.default.ins.waitOrderList.length)
  53. return (
  54. (this.waitOrderData = l.default.ins.waitOrderList.pop()),
  55. this.move.moveTo(this.waitOrderData.pos),
  56. void (this.state = d.AI_STATE.MOVE_TO_ORDERING)
  57. );
  58. this.state !== d.AI_STATE.MOVE_TO_REST &&
  59. this.state !== d.AI_STATE.REST &&
  60. this.state !== d.AI_STATE.DEEP_REST &&
  61. (this.move.moveTo(this.man.basePos), (this.state = d.AI_STATE.MOVE_TO_REST));
  62. }
  63. update(t) {
  64. if (this.man.state === c.CharactorState.stand)
  65. switch (this.state) {
  66. case d.AI_STATE.NONE:
  67. this.think();
  68. break;
  69. case d.AI_STATE.DEEP_REST:
  70. this.think(),
  71. this.state !== d.AI_STATE.DEEP_REST &&
  72. h.default.ins.showLang(this.node, a.RoleLangType.WALK_UP);
  73. break;
  74. case d.AI_STATE.REST:
  75. if ((this.think(), this.state !== d.AI_STATE.REST)) break;
  76. (this.leftTime -= t),
  77. this.leftTime < 0 && (this.man.playAni("sleep2"), (this.state = d.AI_STATE.DEEP_REST));
  78. break;
  79. case d.AI_STATE.MOVE_TO_SEND_FOOD:
  80. this.move.moveTo(this.cookData.order.customer.posData.staff.pos),
  81. this.cookData.passSectionData.removeCookData(this.cookData),
  82. this.man.showFood(this.cookData.order.display.food.spriteFrame, this.cookData.foodValue),
  83. (this.state = d.AI_STATE.SEND_FOOD),
  84. (this.man.state = c.CharactorState.send_food);
  85. break;
  86. case d.AI_STATE.MOVE_TO_ORDERING:
  87. (this.man.direction = this.waitOrderData.direction),
  88. (this.maxTime = r.default.ins.define.crew_order_time),
  89. (this.leftTime = 0),
  90. (this.man.progress.progress = this.leftTime / this.maxTime),
  91. (this.man.progress.node.active = !0),
  92. (this.state = d.AI_STATE.ORDERING);
  93. break;
  94. case d.AI_STATE.MOVE_TO_COOKING:
  95. this.onMoveToCookingFinish();
  96. break;
  97. case d.AI_STATE.ORDERING:
  98. if (((this.leftTime += t), this.leftTime < this.maxTime)) {
  99. this.man.progress.progress = this.leftTime / this.maxTime;
  100. break;
  101. }
  102. (this.man.progress.node.active = !1),
  103. this.waitOrderData.cb.call(this.waitOrderData.target),
  104. (this.waitOrderData = null),
  105. (this.state = d.AI_STATE.NONE),
  106. s.default.SoundManager.playEffect(o.SoundsDefine.MIAOW),
  107. h.default.ins.showLang(this.node, a.RoleLangType.ORDER_FINISH);
  108. break;
  109. case d.AI_STATE.COOKING:
  110. this.onCooking(t);
  111. break;
  112. case d.AI_STATE.SEND_FOOD:
  113. this.cookData.finishOrder(),
  114. this.man.hideFood(),
  115. (this.cookData = null),
  116. (this.state = d.AI_STATE.NONE),
  117. s.default.SoundManager.playEffect("get_coin2");
  118. break;
  119. case d.AI_STATE.MOVE_TO_REST:
  120. this.moveToRest();
  121. }
  122. else this.man.state === c.CharactorState.run && this.state === d.AI_STATE.MOVE_TO_REST && this.think();
  123. }
  124. onCooking(t) {
  125. (this.leftTime += t),
  126. this.leftTime < this.maxTime
  127. ? (this.man.progress.progress = this.leftTime / this.maxTime)
  128. : (s.default.SoundManager.playEffect(o.SoundsDefine.COOK_FINISH),
  129. (this.man.progress.node.active = !1),
  130. (t = this.man.getPerfectDishRate()),
  131. this.cookData.finishCook(t && t > Math.random()),
  132. this.orderDataList.checkHasEmp(),
  133. this.move.moveTo(this.cookData.order.customer.posData.staff.pos),
  134. this.man.showFood(this.cookData.order.display.food.spriteFrame, this.cookData.foodValue),
  135. (this.man.state = c.CharactorState.send_food),
  136. (this.state = d.AI_STATE.SEND_FOOD),
  137. this.man.removeFire(),
  138. h.default.ins.showLang(this.node, a.RoleLangType.MACHINE_FINISH));
  139. }
  140. })
  141. );
  142. i.default = e;