ChefAI.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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}), (i.AI_STATE = void 0);
  18. const o = t("GameConst"),
  19. a = t("OrderService"),
  20. n = t("RoleService"),
  21. r = t("BaseMan"),
  22. l = t("MoveComponent");
  23. ((t = s = i.AI_STATE || (i.AI_STATE = {}))[(t.NONE = 0)] = "NONE"),
  24. (t[(t.MOVE_TO_REST = 1)] = "MOVE_TO_REST"),
  25. (t[(t.REST = 2)] = "REST"),
  26. (t[(t.DEEP_REST = 3)] = "DEEP_REST"),
  27. (t[(t.ORDERING = 4)] = "ORDERING"),
  28. (t[(t.MOVE_TO_ORDERING = 5)] = "MOVE_TO_ORDERING"),
  29. (t[(t.COOKING = 6)] = "COOKING"),
  30. (t[(t.MOVE_TO_COOKING = 7)] = "MOVE_TO_COOKING"),
  31. (t[(t.SEND_FOOD = 8)] = "SEND_FOOD"),
  32. (t[(t.MOVE_TO_SEND_FOOD = 9)] = "MOVE_TO_SEND_FOOD");
  33. var {ccclass: t} = cc._decorator,
  34. t = e(
  35. [t],
  36. (t = class extends cc.Component {
  37. constructor() {
  38. super(...arguments),
  39. (this.man = null),
  40. (this.move = null),
  41. (this.waitOrderData = null),
  42. (this.leftTime = 0),
  43. (this.maxTime = 0),
  44. (this.orderDataList = null),
  45. (this.cookData = null),
  46. (this.state = s.NONE);
  47. }
  48. onLoad() {
  49. (this.man = this.getComponent(r.default)),
  50. (this.move = this.getComponent(l.default)),
  51. (this.orderDataList = a.default.ins.orders[o.MachineType.type2]);
  52. }
  53. think() {
  54. if (this.orderDataList.hasEmp) {
  55. const t = (this.cookData = this.orderDataList.cookOrder());
  56. return t.init(this.man), this.move.moveTo(t.slot.chefPos), void (this.state = s.MOVE_TO_COOKING);
  57. }
  58. this.state !== s.MOVE_TO_REST &&
  59. this.state !== s.REST &&
  60. this.state !== s.DEEP_REST &&
  61. (this.move.moveTo(this.man.basePos), (this.state = s.MOVE_TO_REST));
  62. }
  63. update(t) {
  64. if (this.man.state === r.CharactorState.stand)
  65. switch (this.state) {
  66. case s.NONE:
  67. this.think();
  68. break;
  69. case s.DEEP_REST:
  70. this.think(),
  71. this.state !== s.DEEP_REST && n.default.ins.showLang(this.node, o.RoleLangType.WALK_UP);
  72. break;
  73. case s.REST:
  74. if ((this.think(), this.state !== s.REST)) break;
  75. (this.leftTime -= t),
  76. this.leftTime < 0 && (this.man.playAni("sleep2"), (this.state = s.DEEP_REST));
  77. break;
  78. case s.MOVE_TO_COOKING:
  79. this.onMoveToCookingFinish();
  80. break;
  81. case s.COOKING:
  82. this.onCooking(t);
  83. break;
  84. case s.SEND_FOOD:
  85. this.cookData.passSectionData.addCookData(this.cookData),
  86. (this.man.direction = this.cookData.passSectionData.chef.direction),
  87. (this.cookData = null),
  88. this.man.hideFood(),
  89. (this.state = s.NONE);
  90. break;
  91. case s.MOVE_TO_REST:
  92. this.moveToRest();
  93. }
  94. else this.man.state === r.CharactorState.run && this.state === s.MOVE_TO_REST && this.think();
  95. }
  96. moveToRest() {
  97. (this.state = s.REST), (this.leftTime = 5), (this.man.direction = 2), this.man.playAni("sleep");
  98. }
  99. onMoveToCookingFinish() {
  100. var t = this.man.getInstaCompletedDishRate();
  101. t && t > Math.random()
  102. ? (this.man.showInstaCompletedDishEffect(), (this.maxTime = 0.3))
  103. : (this.maxTime = this.cookData.getCookTime()),
  104. (this.leftTime = 0),
  105. (this.man.progress.progress = this.leftTime / this.maxTime),
  106. (this.man.progress.node.active = !0),
  107. (this.state = s.COOKING),
  108. (this.man.direction = this.cookData.slot.direction),
  109. this.man.playAni("cook"),
  110. this.cookData.slot.playCookAni(),
  111. this.man.showFire();
  112. }
  113. onCooking(t) {
  114. (this.leftTime += t),
  115. this.leftTime < this.maxTime
  116. ? (this.man.progress.progress = this.leftTime / this.maxTime)
  117. : ((this.man.progress.node.active = !1),
  118. (t = this.man.getPerfectDishRate()),
  119. this.cookData.finishCook(t && t > Math.random()),
  120. this.orderDataList.checkHasEmp(),
  121. this.move.moveTo(this.cookData.passSectionData.chef.pos),
  122. (this.state = s.SEND_FOOD),
  123. this.man.showFood(this.cookData.order.display.food.spriteFrame, this.cookData.foodValue),
  124. (this.man.state = r.CharactorState.send_food),
  125. this.man.removeFire(),
  126. n.default.ins.showLang(this.node, o.RoleLangType.MACHINE_FINISH));
  127. }
  128. })
  129. );
  130. i.default = t;